mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 10:12:53 +00:00
Use direct types
This commit is contained in:
parent
e3a5da64a5
commit
c3b1d6735e
@ -31,7 +31,7 @@ import java.util.function.Supplier;
|
||||
|
||||
public class IrisAPI
|
||||
{
|
||||
private static final AtomicCache<RegistryHolder<BlockData>> customBlock = new AtomicCache<>();
|
||||
private static final AtomicCache<RegistryHolder<Supplier<BlockData>>> customBlock = new AtomicCache<>();
|
||||
|
||||
/**
|
||||
* Checks if the given world is an Iris World
|
||||
@ -56,14 +56,19 @@ public class IrisAPI
|
||||
* Used for registering ids into custom blocks
|
||||
* @return the registry
|
||||
*/
|
||||
public static RegistryHolder<BlockData> getCustomBlockRegistry()
|
||||
public static RegistryHolder<Supplier<BlockData>> getCustomBlockRegistry()
|
||||
{
|
||||
return customBlock.aquire(RegistryHolder::new);
|
||||
return customBlock.aquire(() -> new RegistryHolder<>(() -> Iris.service(RegistrySVC.class).getCustomBlockRegistry()));
|
||||
}
|
||||
|
||||
public static class RegistryHolder<T>
|
||||
{
|
||||
private Supplier<PluginRegistryGroup<T>> registry;
|
||||
private final Supplier<PluginRegistryGroup<T>> registry;
|
||||
|
||||
public RegistryHolder(Supplier<PluginRegistryGroup<T>> registry)
|
||||
{
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister a node
|
||||
@ -72,8 +77,7 @@ public class IrisAPI
|
||||
*/
|
||||
public void unregister(String namespace, String id)
|
||||
{
|
||||
Iris.service(RegistrySVC.class).getCustomBlockRegistry()
|
||||
.getRegistry(namespace).unregister(id);
|
||||
registry.get().getRegistry(namespace).unregister(id);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,8 +86,7 @@ public class IrisAPI
|
||||
*/
|
||||
public void unregisterAll(String namespace)
|
||||
{
|
||||
Iris.service(RegistrySVC.class).getCustomBlockRegistry()
|
||||
.getRegistry(namespace).unregisterAll();
|
||||
registry.get().getRegistry(namespace).unregisterAll();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -95,10 +98,9 @@ public class IrisAPI
|
||||
* @param id the identifier for this node (ruby_ore)
|
||||
* @param block the provider for this node data (always return a new instance!)
|
||||
*/
|
||||
public void register(String namespace, String id, Supplier<BlockData> block)
|
||||
public void register(String namespace, String id, T block)
|
||||
{
|
||||
Iris.service(RegistrySVC.class).getCustomBlockRegistry()
|
||||
.getRegistry(namespace).register(id, block);
|
||||
registry.get().getRegistry(namespace).register(id, block);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -108,8 +110,7 @@ public class IrisAPI
|
||||
*/
|
||||
public List<String> getRegsitries(String namespace)
|
||||
{
|
||||
return Iris.service(RegistrySVC.class).getCustomBlockRegistry()
|
||||
.getRegistry(namespace).getRegistries();
|
||||
return registry.get().getRegistry(namespace).getRegistries();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,9 +23,11 @@ import com.volmit.iris.util.plugin.PluginRegistryGroup;
|
||||
import lombok.Data;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Data
|
||||
public class RegistrySVC implements IrisService {
|
||||
private PluginRegistryGroup<BlockData> customBlockRegistry;
|
||||
private PluginRegistryGroup<Supplier<BlockData>> customBlockRegistry;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
@ -40,6 +40,7 @@ import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.bukkit.Material.*;
|
||||
@ -448,7 +449,12 @@ public class B {
|
||||
if(ix.contains(":"))
|
||||
{
|
||||
String[] v = ix.toLowerCase().split("\\Q:\\E");
|
||||
bx = Iris.service(RegistrySVC.class).getCustomBlockRegistry().resolve(v[0], v[1]);
|
||||
Supplier<BlockData> b = Iris.service(RegistrySVC.class).getCustomBlockRegistry().resolve(v[0], v[1]);
|
||||
|
||||
if(b != null)
|
||||
{
|
||||
bx = b.get();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,18 +18,14 @@
|
||||
|
||||
package com.volmit.iris.util.plugin;
|
||||
|
||||
import com.volmit.iris.engine.object.annotations.Required;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class PluginRegistry<T> {
|
||||
private final KMap<String, Supplier<T>> registry = new KMap<>();
|
||||
private final KMap<String, T> registry = new KMap<>();
|
||||
@Getter
|
||||
private final String namespace;
|
||||
|
||||
@ -50,10 +46,10 @@ public class PluginRegistry<T> {
|
||||
return null;
|
||||
}
|
||||
|
||||
return registry.get(s).get();
|
||||
return registry.get(s);
|
||||
}
|
||||
|
||||
public void register(String s, Supplier<T> t)
|
||||
public void register(String s, T t)
|
||||
{
|
||||
registry.put(s, t);
|
||||
}
|
||||
@ -69,13 +65,6 @@ public class PluginRegistry<T> {
|
||||
return null;
|
||||
}
|
||||
|
||||
Supplier<T> m = registry.get(id);
|
||||
|
||||
if(m == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return m.get();
|
||||
return registry.get(id);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user