Prevent the instantiation of multiple SchedulerManager

This commit is contained in:
Felix Cravic 2020-08-09 15:16:05 +02:00
parent 1f2451f0b2
commit e84bcdb0a1
2 changed files with 15 additions and 0 deletions

View File

@ -23,10 +23,13 @@ public interface BlockModifier {
} }
default void setBlock(BlockPosition blockPosition, Block block) { default void setBlock(BlockPosition blockPosition, Block block) {
Check.notNull(blockPosition, "The block position cannot be null");
Check.notNull(block, "The block cannot be null");
setBlock(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ(), block); setBlock(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ(), block);
} }
default void setBlockStateId(BlockPosition blockPosition, short blockStateId) { default void setBlockStateId(BlockPosition blockPosition, short blockStateId) {
Check.notNull(blockPosition, "The block position cannot be null");
setBlockStateId(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ(), blockStateId); setBlockStateId(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ(), blockStateId);
} }
@ -49,6 +52,7 @@ public interface BlockModifier {
} }
default void setCustomBlock(BlockPosition blockPosition, String customBlockId) { default void setCustomBlock(BlockPosition blockPosition, String customBlockId) {
Check.notNull(blockPosition, "The block position cannot be null");
setCustomBlock(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ(), customBlockId); setCustomBlock(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ(), customBlockId);
} }
@ -58,4 +62,9 @@ public interface BlockModifier {
setSeparateBlocks(x, y, z, blockStateId, customBlockId, null); setSeparateBlocks(x, y, z, blockStateId, customBlockId, null);
} }
default void setSeparateBlocks(BlockPosition blockPosition, short blockStateId, short customBlockId) {
Check.notNull(blockPosition, "The block position cannot be null");
setSeparateBlocks(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ(), blockStateId, customBlockId, null);
}
} }

View File

@ -12,6 +12,7 @@ import java.util.concurrent.atomic.AtomicInteger;
*/ */
public class SchedulerManager { public class SchedulerManager {
private boolean instanced;
// A counter for all normal tasks // A counter for all normal tasks
private final AtomicInteger counter; private final AtomicInteger counter;
// A counter for all shutdown tasks // A counter for all shutdown tasks
@ -29,6 +30,11 @@ public class SchedulerManager {
* Default constructor * Default constructor
*/ */
public SchedulerManager() { public SchedulerManager() {
if (instanced) {
throw new IllegalStateException("You cannot instantiate a SchedulerManager," +
" use MinecraftServer.getSchedulerManager()");
}
this.instanced = true;
this.counter = new AtomicInteger(); this.counter = new AtomicInteger();
this.shutdownCounter = new AtomicInteger(); this.shutdownCounter = new AtomicInteger();