mirror of
https://github.com/Minestom/Minestom.git
synced 2025-03-02 11:21:15 +01:00
Use the Contract annotation to prevent useless NPE warnings
This commit is contained in:
parent
8b99fb6f09
commit
06f2ed6065
@ -338,6 +338,7 @@ public class Player extends LivingEntity implements CommandSender {
|
|||||||
final Chunk chunk = instance.getChunkAt(targetBlockPosition);
|
final Chunk chunk = instance.getChunkAt(targetBlockPosition);
|
||||||
final int entityId = targetCustomBlock.getBreakEntityId(this);
|
final int entityId = targetCustomBlock.getBreakEntityId(this);
|
||||||
final BlockBreakAnimationPacket blockBreakAnimationPacket = new BlockBreakAnimationPacket(entityId, targetBlockPosition, targetStage);
|
final BlockBreakAnimationPacket blockBreakAnimationPacket = new BlockBreakAnimationPacket(entityId, targetBlockPosition, targetStage);
|
||||||
|
Check.notNull(chunk, "Tried to interact with an unloaded chunk.");
|
||||||
chunk.sendPacketToViewers(blockBreakAnimationPacket);
|
chunk.sendPacketToViewers(blockBreakAnimationPacket);
|
||||||
|
|
||||||
refreshBreakDelay(targetBreakers);
|
refreshBreakDelay(targetBreakers);
|
||||||
@ -374,6 +375,8 @@ public class Player extends LivingEntity implements CommandSender {
|
|||||||
triggerStatus((byte) 9); // Mark item use as finished
|
triggerStatus((byte) 9); // Mark item use as finished
|
||||||
ItemUpdateStateEvent itemUpdateStateEvent = callItemUpdateStateEvent(true);
|
ItemUpdateStateEvent itemUpdateStateEvent = callItemUpdateStateEvent(true);
|
||||||
|
|
||||||
|
Check.notNull(itemUpdateStateEvent, "#callItemUpdateStateEvent returned null.");
|
||||||
|
|
||||||
// Refresh hand
|
// Refresh hand
|
||||||
final boolean isOffHand = itemUpdateStateEvent.getHand() == Player.Hand.OFF;
|
final boolean isOffHand = itemUpdateStateEvent.getHand() == Player.Hand.OFF;
|
||||||
refreshActiveHand(false, isOffHand, false);
|
refreshActiveHand(false, isOffHand, false);
|
||||||
@ -780,7 +783,7 @@ public class Player extends LivingEntity implements CommandSender {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plays a sound from an identifier (represents a custom sound in a resource pack)
|
* Plays a sound from an identifier (represents a custom sound in a resource pack).
|
||||||
*
|
*
|
||||||
* @param identifier the identifier of the sound to play
|
* @param identifier the identifier of the sound to play
|
||||||
* @param soundCategory the sound category
|
* @param soundCategory the sound category
|
||||||
@ -1299,7 +1302,9 @@ public class Player extends LivingEntity implements CommandSender {
|
|||||||
{
|
{
|
||||||
// Send new chunks
|
// Send new chunks
|
||||||
final BlockPosition pos = position.toBlockPosition();
|
final BlockPosition pos = position.toBlockPosition();
|
||||||
onChunkChange(instance.getChunk(pos.getX() >> 4, pos.getZ() >> 4));
|
final Chunk chunk = instance.getChunk(pos.getX() >> 4, pos.getZ() >> 4);
|
||||||
|
Check.notNull(chunk, "Tried to interact with an unloaded chunk.");
|
||||||
|
onChunkChange(chunk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ public class DamageType implements DataContainer {
|
|||||||
* @return the death message, null to do not send anything.
|
* @return the death message, null to do not send anything.
|
||||||
* Can be for instance, of type {@link ColoredText} or {@link RichMessage}.
|
* Can be for instance, of type {@link ColoredText} or {@link RichMessage}.
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@Nullable
|
||||||
public JsonMessage buildDeathMessage(@NotNull Player killed) {
|
public JsonMessage buildDeathMessage(@NotNull Player killed) {
|
||||||
return ColoredText.of("{@death." + identifier + "," + killed.getUsername() + "}");
|
return ColoredText.of("{@death." + identifier + "," + killed.getUsername() + "}");
|
||||||
}
|
}
|
||||||
@ -109,7 +109,7 @@ public class DamageType implements DataContainer {
|
|||||||
* @param killed the player who has been killed
|
* @param killed the player who has been killed
|
||||||
* @return the death screen text, null to do not send anything
|
* @return the death screen text, null to do not send anything
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@Nullable
|
||||||
public ColoredText buildDeathScreenText(@NotNull Player killed) {
|
public ColoredText buildDeathScreenText(@NotNull Player killed) {
|
||||||
return ColoredText.of("{@death." + identifier + "}");
|
return ColoredText.of("{@death." + identifier + "}");
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import java.io.*;
|
|||||||
/**
|
/**
|
||||||
* Handles loading and configuration of loot tables
|
* Handles loading and configuration of loot tables
|
||||||
*/
|
*/
|
||||||
public class LootTableManager {
|
public final class LootTableManager {
|
||||||
|
|
||||||
private NamespaceIDHashMap<JsonDeserializer<? extends Condition>> conditionDeserializers = new NamespaceIDHashMap<>();
|
private NamespaceIDHashMap<JsonDeserializer<? extends Condition>> conditionDeserializers = new NamespaceIDHashMap<>();
|
||||||
private NamespaceIDHashMap<LootTableType> tableTypes = new NamespaceIDHashMap<>();
|
private NamespaceIDHashMap<LootTableType> tableTypes = new NamespaceIDHashMap<>();
|
||||||
|
@ -9,6 +9,8 @@ import net.minestom.server.instance.block.BlockManager;
|
|||||||
import net.minestom.server.instance.block.CustomBlock;
|
import net.minestom.server.instance.block.CustomBlock;
|
||||||
import net.minestom.server.utils.BlockPosition;
|
import net.minestom.server.utils.BlockPosition;
|
||||||
import net.minestom.server.utils.validate.Check;
|
import net.minestom.server.utils.validate.Check;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an element which can place blocks at position.
|
* Represents an element which can place blocks at position.
|
||||||
@ -30,7 +32,7 @@ public interface BlockModifier {
|
|||||||
* @param blockStateId the block state id
|
* @param blockStateId the block state id
|
||||||
* @param data the block {@link Data}, can be null
|
* @param data the block {@link Data}, can be null
|
||||||
*/
|
*/
|
||||||
void setBlockStateId(int x, int y, int z, short blockStateId, Data data);
|
void setBlockStateId(int x, int y, int z, short blockStateId, @Nullable Data data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a {@link CustomBlock} at a position.
|
* Sets a {@link CustomBlock} at a position.
|
||||||
@ -43,7 +45,7 @@ public interface BlockModifier {
|
|||||||
* @param customBlockId the custom block id
|
* @param customBlockId the custom block id
|
||||||
* @param data the block {@link Data}, can be null
|
* @param data the block {@link Data}, can be null
|
||||||
*/
|
*/
|
||||||
void setCustomBlock(int x, int y, int z, short customBlockId, Data data);
|
void setCustomBlock(int x, int y, int z, short customBlockId, @Nullable Data data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a {@link CustomBlock} at a position with a custom state id.
|
* Sets a {@link CustomBlock} at a position with a custom state id.
|
||||||
@ -58,17 +60,17 @@ public interface BlockModifier {
|
|||||||
* @param customBlockId the custom block id
|
* @param customBlockId the custom block id
|
||||||
* @param data the block {@link Data}, can be null
|
* @param data the block {@link Data}, can be null
|
||||||
*/
|
*/
|
||||||
void setSeparateBlocks(int x, int y, int z, short blockStateId, short customBlockId, Data data);
|
void setSeparateBlocks(int x, int y, int z, short blockStateId, short customBlockId, @Nullable Data data);
|
||||||
|
|
||||||
default void setBlockStateId(int x, int y, int z, short blockStateId) {
|
default void setBlockStateId(int x, int y, int z, short blockStateId) {
|
||||||
setBlockStateId(x, y, z, blockStateId, null);
|
setBlockStateId(x, y, z, blockStateId, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
default void setBlock(int x, int y, int z, Block block) {
|
default void setBlock(int x, int y, int z, @NotNull Block block) {
|
||||||
setBlockStateId(x, y, z, block.getBlockId(), null);
|
setBlockStateId(x, y, z, block.getBlockId(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
default void setBlock(BlockPosition blockPosition, Block block) {
|
default void setBlock(@NotNull BlockPosition blockPosition, @NotNull Block block) {
|
||||||
Check.notNull(blockPosition, "The block position cannot be null");
|
Check.notNull(blockPosition, "The block position cannot be null");
|
||||||
Check.notNull(block, "The block 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);
|
||||||
@ -83,18 +85,18 @@ public interface BlockModifier {
|
|||||||
setCustomBlock(x, y, z, customBlockId, null);
|
setCustomBlock(x, y, z, customBlockId, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
default void setCustomBlock(int x, int y, int z, String customBlockId, Data data) {
|
default void setCustomBlock(int x, int y, int z, @NotNull String customBlockId, @Nullable Data data) {
|
||||||
CustomBlock customBlock = BLOCK_MANAGER.getCustomBlock(customBlockId);
|
CustomBlock customBlock = BLOCK_MANAGER.getCustomBlock(customBlockId);
|
||||||
Check.notNull(customBlock, "The CustomBlock " + customBlockId + " is not registered");
|
Check.notNull(customBlock, "The CustomBlock " + customBlockId + " is not registered");
|
||||||
|
|
||||||
setCustomBlock(x, y, z, customBlock.getCustomBlockId(), data);
|
setCustomBlock(x, y, z, customBlock.getCustomBlockId(), data);
|
||||||
}
|
}
|
||||||
|
|
||||||
default void setCustomBlock(int x, int y, int z, String customBlockId) {
|
default void setCustomBlock(int x, int y, int z, @NotNull String customBlockId) {
|
||||||
setCustomBlock(x, y, z, customBlockId, null);
|
setCustomBlock(x, y, z, customBlockId, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
default void setCustomBlock(BlockPosition blockPosition, String customBlockId) {
|
default void setCustomBlock(@NotNull BlockPosition blockPosition, @NotNull String customBlockId) {
|
||||||
Check.notNull(blockPosition, "The block position cannot be null");
|
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);
|
||||||
}
|
}
|
||||||
@ -103,7 +105,7 @@ 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) {
|
default void setSeparateBlocks(@NotNull BlockPosition blockPosition, short blockStateId, short customBlockId) {
|
||||||
Check.notNull(blockPosition, "The block position cannot be null");
|
Check.notNull(blockPosition, "The block position cannot be null");
|
||||||
setSeparateBlocks(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ(), blockStateId, customBlockId, null);
|
setSeparateBlocks(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ(), blockStateId, customBlockId, null);
|
||||||
}
|
}
|
||||||
|
@ -886,6 +886,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
|||||||
|
|
||||||
// Remove the entity from cache
|
// Remove the entity from cache
|
||||||
final Chunk chunk = getChunkAt(entity.getPosition());
|
final Chunk chunk = getChunkAt(entity.getPosition());
|
||||||
|
Check.notNull(chunk, "Tried to interact with an unloaded chunk.");
|
||||||
removeEntityFromChunk(entity, chunk);
|
removeEntityFromChunk(entity, chunk);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -931,15 +932,13 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
|||||||
*/
|
*/
|
||||||
public void removeEntityFromChunk(@NotNull Entity entity, @NotNull Chunk chunk) {
|
public void removeEntityFromChunk(@NotNull Entity entity, @NotNull Chunk chunk) {
|
||||||
synchronized (chunkEntities) {
|
synchronized (chunkEntities) {
|
||||||
if (chunk != null) {
|
final long chunkIndex = ChunkUtils.getChunkIndex(chunk.getChunkX(), chunk.getChunkZ());
|
||||||
final long chunkIndex = ChunkUtils.getChunkIndex(chunk.getChunkX(), chunk.getChunkZ());
|
Set<Entity> entities = getEntitiesInChunk(chunkIndex);
|
||||||
Set<Entity> entities = getEntitiesInChunk(chunkIndex);
|
entities.remove(entity);
|
||||||
entities.remove(entity);
|
if (entities.isEmpty()) {
|
||||||
if (entities.isEmpty()) {
|
this.chunkEntities.remove(chunkIndex);
|
||||||
this.chunkEntities.remove(chunkIndex);
|
} else {
|
||||||
} else {
|
this.chunkEntities.put(chunkIndex, entities);
|
||||||
this.chunkEntities.put(chunkIndex, entities);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.entities.remove(entity);
|
this.entities.remove(entity);
|
||||||
|
@ -4,6 +4,8 @@ import net.minestom.server.MinecraftServer;
|
|||||||
import net.minestom.server.storage.StorageLocation;
|
import net.minestom.server.storage.StorageLocation;
|
||||||
import net.minestom.server.utils.validate.Check;
|
import net.minestom.server.utils.validate.Check;
|
||||||
import net.minestom.server.world.DimensionType;
|
import net.minestom.server.world.DimensionType;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -25,7 +27,7 @@ public final class InstanceManager {
|
|||||||
*
|
*
|
||||||
* @param instance the {@link Instance} to register
|
* @param instance the {@link Instance} to register
|
||||||
*/
|
*/
|
||||||
public void registerInstance(Instance instance) {
|
public void registerInstance(@NotNull Instance instance) {
|
||||||
Check.stateCondition(instance instanceof SharedInstance,
|
Check.stateCondition(instance instanceof SharedInstance,
|
||||||
"Please use InstanceManager#registerSharedInstance to register a shared instance");
|
"Please use InstanceManager#registerSharedInstance to register a shared instance");
|
||||||
UNSAFE_registerInstance(instance);
|
UNSAFE_registerInstance(instance);
|
||||||
@ -39,7 +41,8 @@ public final class InstanceManager {
|
|||||||
* @param storageLocation the {@link StorageLocation} of the instance, can be null
|
* @param storageLocation the {@link StorageLocation} of the instance, can be null
|
||||||
* @return the created {@link InstanceContainer}
|
* @return the created {@link InstanceContainer}
|
||||||
*/
|
*/
|
||||||
public InstanceContainer createInstanceContainer(DimensionType dimensionType, StorageLocation storageLocation) {
|
@NotNull
|
||||||
|
public InstanceContainer createInstanceContainer(@NotNull DimensionType dimensionType, @Nullable StorageLocation storageLocation) {
|
||||||
final InstanceContainer instanceContainer = new InstanceContainer(UUID.randomUUID(), dimensionType, storageLocation);
|
final InstanceContainer instanceContainer = new InstanceContainer(UUID.randomUUID(), dimensionType, storageLocation);
|
||||||
registerInstance(instanceContainer);
|
registerInstance(instanceContainer);
|
||||||
return instanceContainer;
|
return instanceContainer;
|
||||||
@ -51,7 +54,8 @@ public final class InstanceManager {
|
|||||||
* @param storageLocation the {@link StorageLocation} of the instance, can be null
|
* @param storageLocation the {@link StorageLocation} of the instance, can be null
|
||||||
* @return the created {@link InstanceContainer}
|
* @return the created {@link InstanceContainer}
|
||||||
*/
|
*/
|
||||||
public InstanceContainer createInstanceContainer(StorageLocation storageLocation) {
|
@NotNull
|
||||||
|
public InstanceContainer createInstanceContainer(@Nullable StorageLocation storageLocation) {
|
||||||
return createInstanceContainer(DimensionType.OVERWORLD, storageLocation);
|
return createInstanceContainer(DimensionType.OVERWORLD, storageLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +65,8 @@ public final class InstanceManager {
|
|||||||
* @param dimensionType the {@link DimensionType} of the instance
|
* @param dimensionType the {@link DimensionType} of the instance
|
||||||
* @return the created {@link InstanceContainer}
|
* @return the created {@link InstanceContainer}
|
||||||
*/
|
*/
|
||||||
public InstanceContainer createInstanceContainer(DimensionType dimensionType) {
|
@NotNull
|
||||||
|
public InstanceContainer createInstanceContainer(@NotNull DimensionType dimensionType) {
|
||||||
return createInstanceContainer(dimensionType, null);
|
return createInstanceContainer(dimensionType, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,6 +75,7 @@ public final class InstanceManager {
|
|||||||
*
|
*
|
||||||
* @return the created {@link InstanceContainer}
|
* @return the created {@link InstanceContainer}
|
||||||
*/
|
*/
|
||||||
|
@NotNull
|
||||||
public InstanceContainer createInstanceContainer() {
|
public InstanceContainer createInstanceContainer() {
|
||||||
return createInstanceContainer(DimensionType.OVERWORLD);
|
return createInstanceContainer(DimensionType.OVERWORLD);
|
||||||
}
|
}
|
||||||
@ -83,7 +89,8 @@ public final class InstanceManager {
|
|||||||
* @return the registered {@link SharedInstance}
|
* @return the registered {@link SharedInstance}
|
||||||
* @throws NullPointerException if {@code sharedInstance} doesn't have an {@link InstanceContainer} assigned to it
|
* @throws NullPointerException if {@code sharedInstance} doesn't have an {@link InstanceContainer} assigned to it
|
||||||
*/
|
*/
|
||||||
public SharedInstance registerSharedInstance(SharedInstance sharedInstance) {
|
@NotNull
|
||||||
|
public SharedInstance registerSharedInstance(@NotNull SharedInstance sharedInstance) {
|
||||||
final InstanceContainer instanceContainer = sharedInstance.getInstanceContainer();
|
final InstanceContainer instanceContainer = sharedInstance.getInstanceContainer();
|
||||||
Check.notNull(instanceContainer, "SharedInstance needs to have an InstanceContainer to be created!");
|
Check.notNull(instanceContainer, "SharedInstance needs to have an InstanceContainer to be created!");
|
||||||
|
|
||||||
@ -99,7 +106,8 @@ public final class InstanceManager {
|
|||||||
* @return the created {@link SharedInstance}
|
* @return the created {@link SharedInstance}
|
||||||
* @throws IllegalStateException if {@code instanceContainer} is not registered
|
* @throws IllegalStateException if {@code instanceContainer} is not registered
|
||||||
*/
|
*/
|
||||||
public SharedInstance createSharedInstance(InstanceContainer instanceContainer) {
|
@NotNull
|
||||||
|
public SharedInstance createSharedInstance(@NotNull InstanceContainer instanceContainer) {
|
||||||
Check.notNull(instanceContainer, "Instance container cannot be null when creating a SharedInstance!");
|
Check.notNull(instanceContainer, "Instance container cannot be null when creating a SharedInstance!");
|
||||||
Check.stateCondition(!instanceContainer.isRegistered(), "The container needs to be register in the InstanceManager");
|
Check.stateCondition(!instanceContainer.isRegistered(), "The container needs to be register in the InstanceManager");
|
||||||
|
|
||||||
@ -114,8 +122,8 @@ public final class InstanceManager {
|
|||||||
*
|
*
|
||||||
* @param instance the {@link Instance} to unregister
|
* @param instance the {@link Instance} to unregister
|
||||||
*/
|
*/
|
||||||
public void unregisterInstance(Instance instance) {
|
public void unregisterInstance(@NotNull Instance instance) {
|
||||||
Check.stateCondition(!instance.getPlayers().isEmpty(), "You cannot unregister an instance with players");
|
Check.stateCondition(!instance.getPlayers().isEmpty(), "You cannot unregister an instance with players inside.");
|
||||||
|
|
||||||
synchronized (instance) {
|
synchronized (instance) {
|
||||||
// Unload all chunks
|
// Unload all chunks
|
||||||
@ -136,6 +144,7 @@ public final class InstanceManager {
|
|||||||
*
|
*
|
||||||
* @return an unmodifiable {@link Set} containing all the registered instances
|
* @return an unmodifiable {@link Set} containing all the registered instances
|
||||||
*/
|
*/
|
||||||
|
@NotNull
|
||||||
public Set<Instance> getInstances() {
|
public Set<Instance> getInstances() {
|
||||||
return Collections.unmodifiableSet(instances);
|
return Collections.unmodifiableSet(instances);
|
||||||
}
|
}
|
||||||
@ -147,7 +156,7 @@ public final class InstanceManager {
|
|||||||
*
|
*
|
||||||
* @param instance the {@link Instance} to register
|
* @param instance the {@link Instance} to register
|
||||||
*/
|
*/
|
||||||
private void UNSAFE_registerInstance(Instance instance) {
|
private void UNSAFE_registerInstance(@NotNull Instance instance) {
|
||||||
instance.setRegistered(true);
|
instance.setRegistered(true);
|
||||||
this.instances.add(instance);
|
this.instances.add(instance);
|
||||||
MinecraftServer.getUpdateManager().signalInstanceCreate(instance);
|
MinecraftServer.getUpdateManager().signalInstanceCreate(instance);
|
||||||
|
@ -23,7 +23,7 @@ public class SharedInstance extends Instance {
|
|||||||
|
|
||||||
private final InstanceContainer instanceContainer;
|
private final InstanceContainer instanceContainer;
|
||||||
|
|
||||||
public SharedInstance(UUID uniqueId, InstanceContainer instanceContainer) {
|
public SharedInstance(@NotNull UUID uniqueId, @NotNull InstanceContainer instanceContainer) {
|
||||||
super(uniqueId, instanceContainer.getDimensionType());
|
super(uniqueId, instanceContainer.getDimensionType());
|
||||||
this.instanceContainer = instanceContainer;
|
this.instanceContainer = instanceContainer;
|
||||||
}
|
}
|
||||||
@ -154,6 +154,7 @@ public class SharedInstance extends Instance {
|
|||||||
*
|
*
|
||||||
* @return the associated {@link InstanceContainer}
|
* @return the associated {@link InstanceContainer}
|
||||||
*/
|
*/
|
||||||
|
@NotNull
|
||||||
public InstanceContainer getInstanceContainer() {
|
public InstanceContainer getInstanceContainer() {
|
||||||
return instanceContainer;
|
return instanceContainer;
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@ import net.minestom.server.network.packet.server.play.BlockBreakAnimationPacket;
|
|||||||
import net.minestom.server.utils.BlockPosition;
|
import net.minestom.server.utils.BlockPosition;
|
||||||
import net.minestom.server.utils.time.UpdateOption;
|
import net.minestom.server.utils.time.UpdateOption;
|
||||||
import net.minestom.server.utils.validate.Check;
|
import net.minestom.server.utils.validate.Check;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -24,7 +26,7 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the handler of a custom block type.
|
* Represents the handler of a custom block type which can be registered with {@link BlockManager#registerCustomBlock(CustomBlock)}.
|
||||||
* <p>
|
* <p>
|
||||||
* There should be only one instance of this class for each custom block type,
|
* There should be only one instance of this class for each custom block type,
|
||||||
* every individual blocks will execute the callbacks present there. Each of which contains the
|
* every individual blocks will execute the callbacks present there. Each of which contains the
|
||||||
@ -55,12 +57,12 @@ public abstract class CustomBlock {
|
|||||||
* @param defaultBlockStateId the default block state id
|
* @param defaultBlockStateId the default block state id
|
||||||
* @param identifier the custom block identifier
|
* @param identifier the custom block identifier
|
||||||
*/
|
*/
|
||||||
public CustomBlock(short defaultBlockStateId, String identifier) {
|
public CustomBlock(short defaultBlockStateId, @NotNull String identifier) {
|
||||||
this.defaultBlockStateId = defaultBlockStateId;
|
this.defaultBlockStateId = defaultBlockStateId;
|
||||||
this.identifier = identifier;
|
this.identifier = identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CustomBlock(Block block, String identifier) {
|
public CustomBlock(@NotNull Block block, @NotNull String identifier) {
|
||||||
this(block.getBlockId(), identifier);
|
this(block.getBlockId(), identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +75,7 @@ public abstract class CustomBlock {
|
|||||||
* @throws UnsupportedOperationException if {@link #getUpdateOption()}
|
* @throws UnsupportedOperationException if {@link #getUpdateOption()}
|
||||||
* is not null but the update method is not overridden
|
* is not null but the update method is not overridden
|
||||||
*/
|
*/
|
||||||
public void update(Instance instance, BlockPosition blockPosition, Data data) {
|
public void update(@NotNull Instance instance, @NotNull BlockPosition blockPosition, @Nullable Data data) {
|
||||||
throw new UnsupportedOperationException("Update method not overridden, check #getUpdateOption()");
|
throw new UnsupportedOperationException("Update method not overridden, check #getUpdateOption()");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,6 +88,7 @@ public abstract class CustomBlock {
|
|||||||
*
|
*
|
||||||
* @return the update option of the block
|
* @return the update option of the block
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public UpdateOption getUpdateOption() {
|
public UpdateOption getUpdateOption() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -97,7 +100,7 @@ public abstract class CustomBlock {
|
|||||||
* @param blockPosition the position of the block
|
* @param blockPosition the position of the block
|
||||||
* @param data the data associated with the block
|
* @param data the data associated with the block
|
||||||
*/
|
*/
|
||||||
public abstract void onPlace(Instance instance, BlockPosition blockPosition, Data data);
|
public abstract void onPlace(@NotNull Instance instance, @NotNull BlockPosition blockPosition, @Nullable Data data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a custom block has been destroyed or replaced.
|
* Called when a custom block has been destroyed or replaced.
|
||||||
@ -106,7 +109,7 @@ public abstract class CustomBlock {
|
|||||||
* @param blockPosition the position of the block
|
* @param blockPosition the position of the block
|
||||||
* @param data the data associated with the block
|
* @param data the data associated with the block
|
||||||
*/
|
*/
|
||||||
public abstract void onDestroy(Instance instance, BlockPosition blockPosition, Data data);
|
public abstract void onDestroy(@NotNull Instance instance, @NotNull BlockPosition blockPosition, @Nullable Data data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles interactions with this block. Can also block normal item use (containers should block when opening the
|
* Handles interactions with this block. Can also block normal item use (containers should block when opening the
|
||||||
@ -118,7 +121,8 @@ public abstract class CustomBlock {
|
|||||||
* @param data the data at this position
|
* @param data the data at this position
|
||||||
* @return true if this block blocks normal item use, false otherwise
|
* @return true if this block blocks normal item use, false otherwise
|
||||||
*/
|
*/
|
||||||
public abstract boolean onInteract(Player player, Player.Hand hand, BlockPosition blockPosition, Data data);
|
public abstract boolean onInteract(@NotNull Player player, @NotNull Player.Hand hand,
|
||||||
|
@NotNull BlockPosition blockPosition, @Nullable Data data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This id can be serialized in chunk file, meaning no duplicate should exist
|
* This id can be serialized in chunk file, meaning no duplicate should exist
|
||||||
@ -139,7 +143,7 @@ public abstract class CustomBlock {
|
|||||||
* negative value allow to skip stages (-2 will skip 2 stages per tick)
|
* negative value allow to skip stages (-2 will skip 2 stages per tick)
|
||||||
* @see #enableCustomBreakDelay() to enable/disable it
|
* @see #enableCustomBreakDelay() to enable/disable it
|
||||||
*/
|
*/
|
||||||
public int getBreakDelay(Player player, BlockPosition position, byte stage, Set<Player> breakers) {
|
public int getBreakDelay(@NotNull Player player, @NotNull BlockPosition position, byte stage, Set<Player> breakers) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,7 +190,7 @@ public abstract class CustomBlock {
|
|||||||
* @param position the position at which the block is
|
* @param position the position at which the block is
|
||||||
* @param touching the entity currently touching the block
|
* @param touching the entity currently touching the block
|
||||||
*/
|
*/
|
||||||
public void handleContact(Instance instance, BlockPosition position, Entity touching) {
|
public void handleContact(@NotNull Instance instance, @NotNull BlockPosition position, @NotNull Entity touching) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -208,6 +212,7 @@ public abstract class CustomBlock {
|
|||||||
*
|
*
|
||||||
* @return the custom block identifier
|
* @return the custom block identifier
|
||||||
*/
|
*/
|
||||||
|
@NotNull
|
||||||
public String getIdentifier() {
|
public String getIdentifier() {
|
||||||
return identifier;
|
return identifier;
|
||||||
}
|
}
|
||||||
@ -219,7 +224,8 @@ public abstract class CustomBlock {
|
|||||||
* @param data data given to 'setBlock', can be null
|
* @param data data given to 'setBlock', can be null
|
||||||
* @return Data for this block. Can be null, 'data', or a new object
|
* @return Data for this block. Can be null, 'data', or a new object
|
||||||
*/
|
*/
|
||||||
public Data createData(Instance instance, BlockPosition blockPosition, Data data) {
|
@Nullable
|
||||||
|
public Data createData(@NotNull Instance instance, @NotNull BlockPosition blockPosition, @Nullable Data data) {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,7 +237,8 @@ public abstract class CustomBlock {
|
|||||||
* @param neighborPosition the neighboring block which triggered the update
|
* @param neighborPosition the neighboring block which triggered the update
|
||||||
* @param directNeighbor is the neighbor directly connected to this block? (No diagonals)
|
* @param directNeighbor is the neighbor directly connected to this block? (No diagonals)
|
||||||
*/
|
*/
|
||||||
public void updateFromNeighbor(Instance instance, BlockPosition thisPosition, BlockPosition neighborPosition, boolean directNeighbor) {
|
public void updateFromNeighbor(@NotNull Instance instance, @NotNull BlockPosition thisPosition,
|
||||||
|
@NotNull BlockPosition neighborPosition, boolean directNeighbor) {
|
||||||
if (directNeighbor && hasUpdate()) {
|
if (directNeighbor && hasUpdate()) {
|
||||||
update(instance, thisPosition, instance.getBlockData(thisPosition));
|
update(instance, thisPosition, instance.getBlockData(thisPosition));
|
||||||
}
|
}
|
||||||
@ -244,7 +251,7 @@ public abstract class CustomBlock {
|
|||||||
* @param position the position of the block
|
* @param position the position of the block
|
||||||
* @param blockData the data of the block
|
* @param blockData the data of the block
|
||||||
*/
|
*/
|
||||||
public void scheduledUpdate(Instance instance, BlockPosition position, Data blockData) {
|
public void scheduledUpdate(@NotNull Instance instance, @NotNull BlockPosition position, @Nullable Data blockData) {
|
||||||
update(instance, position, blockData);
|
update(instance, position, blockData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,7 +262,7 @@ public abstract class CustomBlock {
|
|||||||
*
|
*
|
||||||
* @return the drag of this block
|
* @return the drag of this block
|
||||||
*/
|
*/
|
||||||
public float getDrag(Instance instance, BlockPosition blockPosition) {
|
public float getDrag(@NotNull Instance instance, @NotNull BlockPosition blockPosition) {
|
||||||
return 0.5f;
|
return 0.5f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,8 +273,9 @@ public abstract class CustomBlock {
|
|||||||
*
|
*
|
||||||
* @param position position of the block
|
* @param position position of the block
|
||||||
* @param blockData equivalent to <pre>instance.getBlockData(position)</pre>
|
* @param blockData equivalent to <pre>instance.getBlockData(position)</pre>
|
||||||
|
* @param nbt the nbt to write in the {@link net.minestom.server.network.packet.server.play.ChunkDataPacket}
|
||||||
*/
|
*/
|
||||||
public void writeBlockEntity(BlockPosition position, Data blockData, NBTCompound nbt) {
|
public void writeBlockEntity(@NotNull BlockPosition position, @Nullable Data blockData, @NotNull NBTCompound nbt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -278,7 +286,7 @@ public abstract class CustomBlock {
|
|||||||
* @return 'true' if the explosion should happen on this block, 'false' to cancel the destruction.
|
* @return 'true' if the explosion should happen on this block, 'false' to cancel the destruction.
|
||||||
* Returning true does NOT block the explosion rays, ie it does not change the block explosion resistance
|
* Returning true does NOT block the explosion rays, ie it does not change the block explosion resistance
|
||||||
*/
|
*/
|
||||||
public boolean onExplode(Instance instance, BlockPosition position, Data lootTableArguments) {
|
public boolean onExplode(@NotNull Instance instance, @NotNull BlockPosition position, Data lootTableArguments) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,7 +296,8 @@ public abstract class CustomBlock {
|
|||||||
* @param tableManager the loot table manager
|
* @param tableManager the loot table manager
|
||||||
* @return the loot table associated to this block
|
* @return the loot table associated to this block
|
||||||
*/
|
*/
|
||||||
public LootTable getLootTable(LootTableManager tableManager) {
|
@Nullable
|
||||||
|
public LootTable getLootTable(@NotNull LootTableManager tableManager) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,7 +311,7 @@ public abstract class CustomBlock {
|
|||||||
* @param blockPosition the position of the block
|
* @param blockPosition the position of the block
|
||||||
* @param player the player who started digging
|
* @param player the player who started digging
|
||||||
*/
|
*/
|
||||||
public void startDigging(Instance instance, BlockPosition blockPosition, Player player) {
|
public void startDigging(@NotNull Instance instance, @NotNull BlockPosition blockPosition, @NotNull Player player) {
|
||||||
// Stay null if multi player breaking is disabled
|
// Stay null if multi player breaking is disabled
|
||||||
Set<Player> breakers = null;
|
Set<Player> breakers = null;
|
||||||
|
|
||||||
@ -339,7 +348,7 @@ public abstract class CustomBlock {
|
|||||||
* @param blockPosition the position of the block
|
* @param blockPosition the position of the block
|
||||||
* @param player the player who stopped digging
|
* @param player the player who stopped digging
|
||||||
*/
|
*/
|
||||||
public void stopDigging(Instance instance, BlockPosition blockPosition, Player player) {
|
public void stopDigging(@NotNull Instance instance, @NotNull BlockPosition blockPosition, @NotNull Player player) {
|
||||||
if (enableMultiPlayerBreaking()) {
|
if (enableMultiPlayerBreaking()) {
|
||||||
// Remove cache data
|
// Remove cache data
|
||||||
if (instanceBreakDataMap.containsKey(instance)) {
|
if (instanceBreakDataMap.containsKey(instance)) {
|
||||||
@ -355,6 +364,7 @@ public abstract class CustomBlock {
|
|||||||
final int entityId = instanceBreakData.breakIdMap.getInt(blockPosition);
|
final int entityId = instanceBreakData.breakIdMap.getInt(blockPosition);
|
||||||
|
|
||||||
final Chunk chunk = instance.getChunkAt(blockPosition);
|
final Chunk chunk = instance.getChunkAt(blockPosition);
|
||||||
|
Check.notNull(chunk, "Tried to interact with an unloaded chunk.");
|
||||||
chunk.sendPacketToViewers(new BlockBreakAnimationPacket(entityId, blockPosition, (byte) -1));
|
chunk.sendPacketToViewers(new BlockBreakAnimationPacket(entityId, blockPosition, (byte) -1));
|
||||||
|
|
||||||
// Clear cache
|
// Clear cache
|
||||||
@ -367,6 +377,7 @@ public abstract class CustomBlock {
|
|||||||
// Stop the breaking animation for the specific player id
|
// Stop the breaking animation for the specific player id
|
||||||
final Chunk chunk = instance.getChunkAt(blockPosition);
|
final Chunk chunk = instance.getChunkAt(blockPosition);
|
||||||
final int entityId = getBreakEntityId(player);
|
final int entityId = getBreakEntityId(player);
|
||||||
|
Check.notNull(chunk, "Tried to interact with an unloaded chunk.");
|
||||||
chunk.sendPacketToViewers(new BlockBreakAnimationPacket(entityId, blockPosition, (byte) -1));
|
chunk.sendPacketToViewers(new BlockBreakAnimationPacket(entityId, blockPosition, (byte) -1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -382,7 +393,8 @@ public abstract class CustomBlock {
|
|||||||
* @return true if the block can continue being digged
|
* @return true if the block can continue being digged
|
||||||
* @throws IllegalStateException if {@link #enableMultiPlayerBreaking()} is disabled
|
* @throws IllegalStateException if {@link #enableMultiPlayerBreaking()} is disabled
|
||||||
*/
|
*/
|
||||||
public synchronized boolean processStage(Instance instance, BlockPosition blockPosition, Player player, byte stageIncrease) {
|
public synchronized boolean processStage(@NotNull Instance instance, @NotNull BlockPosition blockPosition,
|
||||||
|
@NotNull Player player, byte stageIncrease) {
|
||||||
Check.stateCondition(!enableMultiPlayerBreaking(),
|
Check.stateCondition(!enableMultiPlayerBreaking(),
|
||||||
"CustomBlock#processState requires having the multi player breaking feature enabled");
|
"CustomBlock#processState requires having the multi player breaking feature enabled");
|
||||||
|
|
||||||
@ -400,6 +412,7 @@ public abstract class CustomBlock {
|
|||||||
|
|
||||||
// Send the block break animation
|
// Send the block break animation
|
||||||
final Chunk chunk = instance.getChunkAt(blockPosition);
|
final Chunk chunk = instance.getChunkAt(blockPosition);
|
||||||
|
Check.notNull(chunk, "Tried to interact with an unloaded chunk.");
|
||||||
chunk.sendPacketToViewers(new BlockBreakAnimationPacket(entityId, blockPosition, stage));
|
chunk.sendPacketToViewers(new BlockBreakAnimationPacket(entityId, blockPosition, stage));
|
||||||
|
|
||||||
// Refresh the stage
|
// Refresh the stage
|
||||||
@ -411,7 +424,7 @@ public abstract class CustomBlock {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeDiggingInformation(Instance instance, BlockPosition blockPosition) {
|
public void removeDiggingInformation(@NotNull Instance instance, @NotNull BlockPosition blockPosition) {
|
||||||
if (!enableMultiPlayerBreaking()) {
|
if (!enableMultiPlayerBreaking()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -431,7 +444,8 @@ public abstract class CustomBlock {
|
|||||||
* @return the {@link Set} of breakers of a block
|
* @return the {@link Set} of breakers of a block
|
||||||
* @throws IllegalStateException if {@link #enableMultiPlayerBreaking()} is disabled
|
* @throws IllegalStateException if {@link #enableMultiPlayerBreaking()} is disabled
|
||||||
*/
|
*/
|
||||||
public Set<Player> getBreakers(Instance instance, BlockPosition blockPosition) {
|
@Nullable
|
||||||
|
public Set<Player> getBreakers(@NotNull Instance instance, @NotNull BlockPosition blockPosition) {
|
||||||
Check.stateCondition(!enableMultiPlayerBreaking(),
|
Check.stateCondition(!enableMultiPlayerBreaking(),
|
||||||
"CustomBlock#getBreakers requires having the multi player breaking feature enabled");
|
"CustomBlock#getBreakers requires having the multi player breaking feature enabled");
|
||||||
|
|
||||||
@ -450,7 +464,7 @@ public abstract class CustomBlock {
|
|||||||
* @param blockPosition the position of the custom block
|
* @param blockPosition the position of the custom block
|
||||||
* @return the break stage at the position. Can also be 0 when nonexistent
|
* @return the break stage at the position. Can also be 0 when nonexistent
|
||||||
*/
|
*/
|
||||||
public byte getBreakStage(Instance instance, BlockPosition blockPosition) {
|
public byte getBreakStage(@NotNull Instance instance, @NotNull BlockPosition blockPosition) {
|
||||||
Check.stateCondition(!enableMultiPlayerBreaking(),
|
Check.stateCondition(!enableMultiPlayerBreaking(),
|
||||||
"CustomBlock#getBreakStage requires having the multi player breaking feature enabled");
|
"CustomBlock#getBreakStage requires having the multi player breaking feature enabled");
|
||||||
|
|
||||||
@ -472,7 +486,7 @@ public abstract class CustomBlock {
|
|||||||
// Contains the entity id used by the block break packet
|
// Contains the entity id used by the block break packet
|
||||||
private final Object2IntMap<BlockPosition> breakIdMap = new Object2IntOpenHashMap<>();
|
private final Object2IntMap<BlockPosition> breakIdMap = new Object2IntOpenHashMap<>();
|
||||||
|
|
||||||
private void clear(BlockPosition blockPosition) {
|
private void clear(@NotNull BlockPosition blockPosition) {
|
||||||
this.breakersMap.remove(blockPosition);
|
this.breakersMap.remove(blockPosition);
|
||||||
this.breakStageMap.removeByte(blockPosition);
|
this.breakStageMap.removeByte(blockPosition);
|
||||||
this.breakIdMap.removeInt(blockPosition);
|
this.breakIdMap.removeInt(blockPosition);
|
||||||
|
@ -1,27 +1,35 @@
|
|||||||
package net.minestom.server.utils.validate;
|
package net.minestom.server.utils.validate;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenient class to check for common exceptions types.
|
||||||
|
*/
|
||||||
public final class Check {
|
public final class Check {
|
||||||
|
|
||||||
private Check() {
|
private Check() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Contract("null, _ -> fail")
|
||||||
public static void notNull(@Nullable Object object, @NotNull String reason) {
|
public static void notNull(@Nullable Object object, @NotNull String reason) {
|
||||||
if (Objects.isNull(object)) {
|
if (Objects.isNull(object)) {
|
||||||
throw new NullPointerException(reason);
|
throw new NullPointerException(reason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Contract("true, _ -> fail")
|
||||||
public static void argCondition(boolean condition, @NotNull String reason) {
|
public static void argCondition(boolean condition, @NotNull String reason) {
|
||||||
if (condition) {
|
if (condition) {
|
||||||
throw new IllegalArgumentException(reason);
|
throw new IllegalArgumentException(reason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Contract("true, _ -> fail")
|
||||||
public static void stateCondition(boolean condition, @NotNull String reason) {
|
public static void stateCondition(boolean condition, @NotNull String reason) {
|
||||||
if (condition) {
|
if (condition) {
|
||||||
throw new IllegalStateException(reason);
|
throw new IllegalStateException(reason);
|
||||||
|
@ -19,7 +19,6 @@ import net.minestom.server.instance.InstanceContainer;
|
|||||||
import net.minestom.server.instance.block.Block;
|
import net.minestom.server.instance.block.Block;
|
||||||
import net.minestom.server.inventory.Inventory;
|
import net.minestom.server.inventory.Inventory;
|
||||||
import net.minestom.server.inventory.InventoryType;
|
import net.minestom.server.inventory.InventoryType;
|
||||||
import net.minestom.server.item.Enchantment;
|
|
||||||
import net.minestom.server.item.ItemStack;
|
import net.minestom.server.item.ItemStack;
|
||||||
import net.minestom.server.item.Material;
|
import net.minestom.server.item.Material;
|
||||||
import net.minestom.server.network.ConnectionManager;
|
import net.minestom.server.network.ConnectionManager;
|
||||||
@ -43,7 +42,7 @@ public class PlayerInit {
|
|||||||
StorageLocation storageLocation = MinecraftServer.getStorageManager().getLocation("instance_data", new StorageOptions().setCompression(true));
|
StorageLocation storageLocation = MinecraftServer.getStorageManager().getLocation("instance_data", new StorageOptions().setCompression(true));
|
||||||
ChunkGeneratorDemo chunkGeneratorDemo = new ChunkGeneratorDemo();
|
ChunkGeneratorDemo chunkGeneratorDemo = new ChunkGeneratorDemo();
|
||||||
NoiseTestGenerator noiseTestGenerator = new NoiseTestGenerator();
|
NoiseTestGenerator noiseTestGenerator = new NoiseTestGenerator();
|
||||||
instanceContainer = MinecraftServer.getInstanceManager().createInstanceContainer(DimensionType.OVERWORLD);
|
instanceContainer = MinecraftServer.getInstanceManager().createInstanceContainer(DimensionType.OVERWORLD, storageLocation);
|
||||||
instanceContainer.enableAutoChunkLoad(true);
|
instanceContainer.enableAutoChunkLoad(true);
|
||||||
instanceContainer.setChunkGenerator(noiseTestGenerator);
|
instanceContainer.setChunkGenerator(noiseTestGenerator);
|
||||||
|
|
||||||
@ -113,7 +112,7 @@ public class PlayerInit {
|
|||||||
final Block block = Block.fromStateId(event.getBlockStateId());
|
final Block block = Block.fromStateId(event.getBlockStateId());
|
||||||
|
|
||||||
if (block == Block.STONE) {
|
if (block == Block.STONE) {
|
||||||
event.setCustomBlock((short) 2); // custom stone block
|
event.setCustomBlock("custom_block");
|
||||||
System.out.println("custom stone");
|
System.out.println("custom stone");
|
||||||
}
|
}
|
||||||
if (block == Block.TORCH) {
|
if (block == Block.TORCH) {
|
||||||
@ -154,9 +153,6 @@ public class PlayerInit {
|
|||||||
player.addEventCallback(PlayerLoginEvent.class, event -> {
|
player.addEventCallback(PlayerLoginEvent.class, event -> {
|
||||||
|
|
||||||
event.setSpawningInstance(instanceContainer);
|
event.setSpawningInstance(instanceContainer);
|
||||||
player.setEnableRespawnScreen(false);
|
|
||||||
|
|
||||||
player.setPermissionLevel(4);
|
|
||||||
|
|
||||||
player.getInventory().addInventoryCondition((p, slot, clickType, inventoryConditionResult) -> {
|
player.getInventory().addInventoryCondition((p, slot, clickType, inventoryConditionResult) -> {
|
||||||
if (slot == -999)
|
if (slot == -999)
|
||||||
@ -168,29 +164,6 @@ public class PlayerInit {
|
|||||||
}
|
}
|
||||||
System.out.println("slot player: " + slot + " : " + itemStack.getMaterial() + " : " + (itemStack.getData() != null));
|
System.out.println("slot player: " + slot + " : " + itemStack.getMaterial() + " : " + (itemStack.getData() != null));
|
||||||
});
|
});
|
||||||
|
|
||||||
{
|
|
||||||
/*AdvancementManager advancementManager = MinecraftServer.getAdvancementManager();
|
|
||||||
AdvancementRoot root = new AdvancementRoot(ColoredText.of("title"), ColoredText.of(ChatColor.BLUE + "description"),
|
|
||||||
Material.APPLE, FrameType.TASK, 0, 0,
|
|
||||||
"minecraft:textures/block/red_wool.png");
|
|
||||||
root.setAchieved(true);
|
|
||||||
AdvancementTab tab = advancementManager.createTab("root", root);
|
|
||||||
Advancement advancement = new Advancement(ColoredText.of("adv"), ColoredText.of("desc"),
|
|
||||||
Material.WOODEN_AXE, FrameType.CHALLENGE, 1, 0)
|
|
||||||
.showToast(true).setHidden(false);
|
|
||||||
tab.createAdvancement("second", advancement, root);
|
|
||||||
|
|
||||||
tab.addViewer(player);
|
|
||||||
|
|
||||||
root.setTitle(ColoredText.of("test ttlechange"));
|
|
||||||
|
|
||||||
Advancement advancement2 = new Advancement(ColoredText.of(ChatColor.BLUE + "Title"),
|
|
||||||
ColoredText.of("description of the advancement"),
|
|
||||||
Material.GOLD_BLOCK, FrameType.CHALLENGE, 3, 0)
|
|
||||||
.showToast(true).setHidden(false);
|
|
||||||
tab.createAdvancement("second2", advancement2, root);*/
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
player.addEventCallback(PlayerSpawnEvent.class, event -> {
|
player.addEventCallback(PlayerSpawnEvent.class, event -> {
|
||||||
@ -199,10 +172,10 @@ public class PlayerInit {
|
|||||||
|
|
||||||
Data data = new DataImpl();
|
Data data = new DataImpl();
|
||||||
data.set("test", 5, Integer.class);
|
data.set("test", 5, Integer.class);
|
||||||
ItemStack itemStack = new ItemStack(Material.NETHERITE_PICKAXE, (byte) 1);
|
ItemStack itemStack = new ItemStack(Material.DIAMOND_PICKAXE, (byte) 1);
|
||||||
itemStack.setEnchantment(Enchantment.EFFICIENCY, (short) 5);
|
|
||||||
itemStack.setData(data);
|
itemStack.setData(data);
|
||||||
player.getInventory().addItemStack(itemStack);
|
player.getInventory().addItemStack(itemStack);
|
||||||
|
//player.getInventory().addItemStack(new ItemStack(Material.STONE, (byte)64));
|
||||||
});
|
});
|
||||||
|
|
||||||
player.addEventCallback(PlayerRespawnEvent.class, event -> {
|
player.addEventCallback(PlayerRespawnEvent.class, event -> {
|
||||||
|
@ -9,6 +9,7 @@ import net.minestom.server.instance.Instance;
|
|||||||
import net.minestom.server.instance.block.Block;
|
import net.minestom.server.instance.block.Block;
|
||||||
import net.minestom.server.instance.block.CustomBlock;
|
import net.minestom.server.instance.block.CustomBlock;
|
||||||
import net.minestom.server.utils.BlockPosition;
|
import net.minestom.server.utils.BlockPosition;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom block which burns entities that touch it
|
* Custom block which burns entities that touch it
|
||||||
@ -19,7 +20,7 @@ public class BurningTorchBlock extends CustomBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleContact(Instance instance, BlockPosition position, Entity touching) {
|
public void handleContact(@NotNull Instance instance, @NotNull BlockPosition position, @NotNull Entity touching) {
|
||||||
System.out.println("touching " + touching);
|
System.out.println("touching " + touching);
|
||||||
if (touching instanceof LivingEntity) {
|
if (touching instanceof LivingEntity) {
|
||||||
((LivingEntity) touching).damage(DamageType.GRAVITY, 0.1f);
|
((LivingEntity) touching).damage(DamageType.GRAVITY, 0.1f);
|
||||||
@ -27,17 +28,17 @@ public class BurningTorchBlock extends CustomBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlace(Instance instance, BlockPosition blockPosition, Data data) {
|
public void onPlace(@NotNull Instance instance, @NotNull BlockPosition blockPosition, Data data) {
|
||||||
System.out.println(blockPosition);
|
System.out.println(blockPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy(Instance instance, BlockPosition blockPosition, Data data) {
|
public void onDestroy(@NotNull Instance instance, @NotNull BlockPosition blockPosition, Data data) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onInteract(Player player, Player.Hand hand, BlockPosition blockPosition, Data data) {
|
public boolean onInteract(@NotNull Player player, @NotNull Player.Hand hand, @NotNull BlockPosition blockPosition, Data data) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,22 +6,23 @@ import net.minestom.server.instance.Instance;
|
|||||||
import net.minestom.server.instance.block.Block;
|
import net.minestom.server.instance.block.Block;
|
||||||
import net.minestom.server.instance.block.CustomBlock;
|
import net.minestom.server.instance.block.CustomBlock;
|
||||||
import net.minestom.server.utils.BlockPosition;
|
import net.minestom.server.utils.BlockPosition;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class StoneBlock extends CustomBlock {
|
public class StoneBlock extends CustomBlock {
|
||||||
|
|
||||||
public StoneBlock() {
|
public StoneBlock() {
|
||||||
super(Block.STONE, "custom_block");
|
super(Block.GOLD_BLOCK, "custom_block");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlace(Instance instance, BlockPosition blockPosition, Data data) {
|
public void onPlace(@NotNull Instance instance, @NotNull BlockPosition blockPosition, Data data) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy(Instance instance, BlockPosition blockPosition, Data data) {
|
public void onDestroy(@NotNull Instance instance, @NotNull BlockPosition blockPosition, Data data) {
|
||||||
BlockPosition above = blockPosition.clone().add(0, 1, 0);
|
BlockPosition above = blockPosition.clone().add(0, 1, 0);
|
||||||
CustomBlock blockAbove = instance.getCustomBlock(above);
|
CustomBlock blockAbove = instance.getCustomBlock(above);
|
||||||
if (blockAbove == this) {
|
if (blockAbove == this) {
|
||||||
@ -31,17 +32,17 @@ public class StoneBlock extends CustomBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateFromNeighbor(Instance instance, BlockPosition thisPosition, BlockPosition neighborPosition, boolean directNeighbor) {
|
public void updateFromNeighbor(@NotNull Instance instance, @NotNull BlockPosition thisPosition, @NotNull BlockPosition neighborPosition, boolean directNeighbor) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onInteract(Player player, Player.Hand hand, BlockPosition blockPosition, Data data) {
|
public boolean onInteract(@NotNull Player player, @NotNull Player.Hand hand, @NotNull BlockPosition blockPosition, Data data) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBreakDelay(Player player, BlockPosition position, byte stage, Set<Player> breakers) {
|
public int getBreakDelay(@NotNull Player player, @NotNull BlockPosition position, byte stage, Set<Player> breakers) {
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import net.minestom.server.instance.block.CustomBlock;
|
|||||||
import net.minestom.server.utils.BlockPosition;
|
import net.minestom.server.utils.BlockPosition;
|
||||||
import net.minestom.server.utils.time.TimeUnit;
|
import net.minestom.server.utils.time.TimeUnit;
|
||||||
import net.minestom.server.utils.time.UpdateOption;
|
import net.minestom.server.utils.time.UpdateOption;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -20,22 +21,22 @@ public class UpdatableBlockDemo extends CustomBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Instance instance, BlockPosition blockPosition, Data data) {
|
public void update(@NotNull Instance instance, @NotNull BlockPosition blockPosition, Data data) {
|
||||||
System.out.println("BLOCK UPDATE");
|
System.out.println("BLOCK UPDATE");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlace(Instance instance, BlockPosition blockPosition, Data data) {
|
public void onPlace(@NotNull Instance instance, @NotNull BlockPosition blockPosition, Data data) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy(Instance instance, BlockPosition blockPosition, Data data) {
|
public void onDestroy(@NotNull Instance instance, @NotNull BlockPosition blockPosition, Data data) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onInteract(Player player, Player.Hand hand, BlockPosition blockPosition, Data data) {
|
public boolean onInteract(@NotNull Player player, @NotNull Player.Hand hand, @NotNull BlockPosition blockPosition, Data data) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +46,7 @@ public class UpdatableBlockDemo extends CustomBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBreakDelay(Player player, BlockPosition position, byte stage, Set<Player> breakers) {
|
public int getBreakDelay(@NotNull Player player, @NotNull BlockPosition position, byte stage, Set<Player> breakers) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,10 +6,12 @@ import net.minestom.server.command.CommandSender;
|
|||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
import net.minestom.server.instance.Instance;
|
import net.minestom.server.instance.Instance;
|
||||||
import net.minestom.server.world.DimensionType;
|
import net.minestom.server.world.DimensionType;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class DimensionCommand implements CommandProcessor {
|
public class DimensionCommand implements CommandProcessor {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String getCommandName() {
|
public String getCommandName() {
|
||||||
return "dimensiontest";
|
return "dimensiontest";
|
||||||
@ -21,7 +23,7 @@ public class DimensionCommand implements CommandProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean process(CommandSender sender, String command, String[] args) {
|
public boolean process(@NotNull CommandSender sender, @NotNull String command, @NotNull String[] args) {
|
||||||
|
|
||||||
if (!sender.isPlayer())
|
if (!sender.isPlayer())
|
||||||
return false;
|
return false;
|
||||||
@ -48,7 +50,7 @@ public class DimensionCommand implements CommandProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasAccess(Player player) {
|
public boolean hasAccess(@NotNull Player player) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,14 @@ import net.minestom.server.MinecraftServer;
|
|||||||
import net.minestom.server.command.CommandProcessor;
|
import net.minestom.server.command.CommandProcessor;
|
||||||
import net.minestom.server.command.CommandSender;
|
import net.minestom.server.command.CommandSender;
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple shutdown command.
|
* A simple shutdown command.
|
||||||
*/
|
*/
|
||||||
public class ShutdownCommand implements CommandProcessor {
|
public class ShutdownCommand implements CommandProcessor {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String getCommandName() {
|
public String getCommandName() {
|
||||||
return "shutdown";
|
return "shutdown";
|
||||||
@ -21,13 +23,13 @@ public class ShutdownCommand implements CommandProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean process(CommandSender sender, String command, String[] args) {
|
public boolean process(@NotNull CommandSender sender, @NotNull String command, @NotNull String[] args) {
|
||||||
MinecraftServer.stopCleanly();
|
MinecraftServer.stopCleanly();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasAccess(Player player) {
|
public boolean hasAccess(@NotNull Player player) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,10 @@ package demo.commands;
|
|||||||
import net.minestom.server.command.CommandProcessor;
|
import net.minestom.server.command.CommandProcessor;
|
||||||
import net.minestom.server.command.CommandSender;
|
import net.minestom.server.command.CommandSender;
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class SimpleCommand implements CommandProcessor {
|
public class SimpleCommand implements CommandProcessor {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String getCommandName() {
|
public String getCommandName() {
|
||||||
return "test";
|
return "test";
|
||||||
@ -16,11 +18,11 @@ public class SimpleCommand implements CommandProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean process(CommandSender sender, String command, String[] args) {
|
public boolean process(@NotNull CommandSender sender, @NotNull String command, @NotNull String[] args) {
|
||||||
if (!sender.isPlayer())
|
if (!sender.isPlayer())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
//sender.asPlayer().getInstance().saveChunksToStorage(() -> System.out.println("END SAVE"));
|
sender.asPlayer().getInstance().saveChunksToStorage(() -> System.out.println("END SAVE"));
|
||||||
|
|
||||||
System.gc();
|
System.gc();
|
||||||
|
|
||||||
@ -28,7 +30,7 @@ public class SimpleCommand implements CommandProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasAccess(Player player) {
|
public boolean hasAccess(@NotNull Player player) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,7 +40,7 @@ public class SimpleCommand implements CommandProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] onWrite(String text) {
|
public String[] onWrite(@NotNull String text) {
|
||||||
return new String[]{"Complete1", "Complete2"};
|
return new String[]{"Complete1", "Complete2"};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user