mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-01 05:58:00 +01:00
It is now possible to extends InstanceContainer/SharedInstance to make your own
This commit is contained in:
parent
ab71133b55
commit
a63693b82b
@ -431,6 +431,9 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
|
||||
if (instance == null)
|
||||
throw new IllegalArgumentException("instance cannot be null!");
|
||||
|
||||
if (!MinecraftServer.getInstanceManager().getInstances().contains(instance))
|
||||
throw new IllegalStateException("Instances need to be registered with InstanceManager#createInstanceContainer or InstanceManager#createSharedInstance");
|
||||
|
||||
if (this.instance != null) {
|
||||
this.instance.removeEntity(this);
|
||||
}
|
||||
|
@ -18,10 +18,14 @@ public class InstanceManager {
|
||||
private Set<Instance> instances = Collections.synchronizedSet(new HashSet<>());
|
||||
private UpdateType updateType = UpdateType.PER_INSTANCE;
|
||||
|
||||
public InstanceContainer createInstanceContainer(InstanceContainer instanceContainer) {
|
||||
this.instances.add(instanceContainer);
|
||||
return instanceContainer;
|
||||
}
|
||||
|
||||
public InstanceContainer createInstanceContainer(Dimension dimension, StorageFolder storageFolder) {
|
||||
InstanceContainer instance = new InstanceContainer(UUID.randomUUID(), dimension, storageFolder);
|
||||
this.instances.add(instance);
|
||||
return instance;
|
||||
return createInstanceContainer(instance);
|
||||
}
|
||||
|
||||
public InstanceContainer createInstanceContainer(StorageFolder storageFolder) {
|
||||
@ -36,16 +40,24 @@ public class InstanceManager {
|
||||
return createInstanceContainer(Dimension.OVERWORLD);
|
||||
}
|
||||
|
||||
public SharedInstance createSharedInstance(InstanceContainer instanceContainer) {
|
||||
public SharedInstance createSharedInstance(SharedInstance sharedInstance) {
|
||||
InstanceContainer instanceContainer = sharedInstance.getInstanceContainer();
|
||||
if (instanceContainer == null)
|
||||
throw new IllegalArgumentException("Instance container cannot be null when creating a Shared instance!");
|
||||
throw new NullPointerException("SharedInstance needs to have an InstanceContainer to be created!");
|
||||
|
||||
SharedInstance sharedInstance = new SharedInstance(UUID.randomUUID(), instanceContainer);
|
||||
instanceContainer.addSharedInstance(sharedInstance);
|
||||
this.instances.add(sharedInstance);
|
||||
return sharedInstance;
|
||||
}
|
||||
|
||||
public SharedInstance createSharedInstance(InstanceContainer instanceContainer) {
|
||||
if (instanceContainer == null)
|
||||
throw new IllegalArgumentException("Instance container cannot be null when creating a SharedInstance!");
|
||||
|
||||
SharedInstance sharedInstance = new SharedInstance(UUID.randomUUID(), instanceContainer);
|
||||
return createSharedInstance(sharedInstance);
|
||||
}
|
||||
|
||||
public void updateBlocks() {
|
||||
if (instances.isEmpty())
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user