Migrate left over occurrences to enhanced switches (#3979)

* Migrate left-overs to enhanced switches

* More
This commit is contained in:
Alexander Brandes 2023-03-06 10:25:02 +01:00 committed by GitHub
parent 42e146b8c7
commit 89031447f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 243 additions and 418 deletions

View File

@ -101,50 +101,26 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
this.noGravity = true; this.noGravity = true;
} }
switch (entity.getType().toString()) { switch (entity.getType().toString()) {
case "BOAT": case "BOAT" -> {
Boat boat = (Boat) entity; Boat boat = (Boat) entity;
this.dataByte = getOrdinal(TreeSpecies.values(), boat.getWoodType()); this.dataByte = getOrdinal(TreeSpecies.values(), boat.getWoodType());
return; return;
case "ARROW": }
case "EGG": case "ARROW", "EGG", "ENDER_CRYSTAL", "ENDER_PEARL", "ENDER_SIGNAL", "EXPERIENCE_ORB", "FALLING_BLOCK", "FIREBALL",
case "ENDER_CRYSTAL": "FIREWORK", "FISHING_HOOK", "LEASH_HITCH", "LIGHTNING", "MINECART", "MINECART_COMMAND", "MINECART_MOB_SPAWNER",
case "ENDER_PEARL": "MINECART_TNT", "PLAYER", "PRIMED_TNT", "SLIME", "SMALL_FIREBALL", "SNOWBALL", "MINECART_FURNACE", "SPLASH_POTION",
case "ENDER_SIGNAL": "THROWN_EXP_BOTTLE", "WITHER_SKULL", "UNKNOWN", "SPECTRAL_ARROW", "SHULKER_BULLET", "DRAGON_FIREBALL", "AREA_EFFECT_CLOUD",
case "EXPERIENCE_ORB": "TRIDENT", "LLAMA_SPIT" -> {
case "FALLING_BLOCK":
case "FIREBALL":
case "FIREWORK":
case "FISHING_HOOK":
case "LEASH_HITCH":
case "LIGHTNING":
case "MINECART":
case "MINECART_COMMAND":
case "MINECART_MOB_SPAWNER":
case "MINECART_TNT":
case "PLAYER":
case "PRIMED_TNT":
case "SLIME":
case "SMALL_FIREBALL":
case "SNOWBALL":
case "MINECART_FURNACE":
case "SPLASH_POTION":
case "THROWN_EXP_BOTTLE":
case "WITHER_SKULL":
case "UNKNOWN":
case "SPECTRAL_ARROW":
case "SHULKER_BULLET":
case "DRAGON_FIREBALL":
case "AREA_EFFECT_CLOUD":
case "TRIDENT":
case "LLAMA_SPIT":
// Do this stuff later // Do this stuff later
return; return;
}
// MISC // // MISC //
case "DROPPED_ITEM": case "DROPPED_ITEM" -> {
Item item = (Item) entity; Item item = (Item) entity;
this.stack = item.getItemStack(); this.stack = item.getItemStack();
return; return;
case "ITEM_FRAME": }
case "ITEM_FRAME" -> {
this.x = Math.floor(this.getX()); this.x = Math.floor(this.getX());
this.y = Math.floor(this.getY()); this.y = Math.floor(this.getY());
this.z = Math.floor(this.getZ()); this.z = Math.floor(this.getZ());
@ -152,7 +128,8 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
this.dataByte = getOrdinal(Rotation.values(), itemFrame.getRotation()); this.dataByte = getOrdinal(Rotation.values(), itemFrame.getRotation());
this.stack = itemFrame.getItem().clone(); this.stack = itemFrame.getItem().clone();
return; return;
case "PAINTING": }
case "PAINTING" -> {
this.x = Math.floor(this.getX()); this.x = Math.floor(this.getX());
this.y = Math.floor(this.getY()); this.y = Math.floor(this.getY());
this.z = Math.floor(this.getZ()); this.z = Math.floor(this.getZ());
@ -165,20 +142,17 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
} }
this.dataString = art.name(); this.dataString = art.name();
return; return;
}
// END MISC // // END MISC //
// INVENTORY HOLDER // // INVENTORY HOLDER //
case "MINECART_CHEST": case "MINECART_CHEST", "MINECART_HOPPER" -> {
case "MINECART_HOPPER":
storeInventory((InventoryHolder) entity); storeInventory((InventoryHolder) entity);
return; return;
}
// START LIVING ENTITY // // START LIVING ENTITY //
// START AGEABLE // // START AGEABLE //
// START TAMEABLE // // START TAMEABLE //
case "HORSE": case "HORSE", "DONKEY", "LLAMA", "MULE", "SKELETON_HORSE" -> {
case "DONKEY":
case "LLAMA":
case "MULE":
case "SKELETON_HORSE":
AbstractHorse horse = (AbstractHorse) entity; AbstractHorse horse = (AbstractHorse) entity;
this.horse = new HorseStats(); this.horse = new HorseStats();
this.horse.jump = horse.getJumpStrength(); this.horse.jump = horse.getJumpStrength();
@ -194,16 +168,17 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
storeLiving(horse); storeLiving(horse);
storeInventory(horse); storeInventory(horse);
return; return;
}
// END INVENTORY HOLDER // // END INVENTORY HOLDER //
case "WOLF": case "WOLF", "OCELOT" -> {
case "OCELOT":
storeTameable((Tameable) entity); storeTameable((Tameable) entity);
storeAgeable((Ageable) entity); storeAgeable((Ageable) entity);
storeLiving((LivingEntity) entity); storeLiving((LivingEntity) entity);
return; return;
}
// END TAMEABLE // // END TAMEABLE //
//todo fix sheep //todo fix sheep
case "SHEEP": case "SHEEP" -> {
Sheep sheep = (Sheep) entity; Sheep sheep = (Sheep) entity;
if (sheep.isSheared()) { if (sheep.isSheared()) {
this.dataByte = (byte) 1; this.dataByte = (byte) 1;
@ -214,23 +189,20 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
storeAgeable(sheep); storeAgeable(sheep);
storeLiving(sheep); storeLiving(sheep);
return; return;
case "VILLAGER": }
case "CHICKEN": case "VILLAGER", "CHICKEN", "COW", "MUSHROOM_COW", "PIG", "TURTLE", "POLAR_BEAR" -> {
case "COW":
case "MUSHROOM_COW":
case "PIG":
case "TURTLE":
case "POLAR_BEAR":
storeAgeable((Ageable) entity); storeAgeable((Ageable) entity);
storeLiving((LivingEntity) entity); storeLiving((LivingEntity) entity);
return; return;
case "RABBIT": }
case "RABBIT" -> {
this.dataByte = getOrdinal(Rabbit.Type.values(), ((Rabbit) entity).getRabbitType()); this.dataByte = getOrdinal(Rabbit.Type.values(), ((Rabbit) entity).getRabbitType());
storeAgeable((Ageable) entity); storeAgeable((Ageable) entity);
storeLiving((LivingEntity) entity); storeLiving((LivingEntity) entity);
return; return;
}
// END AGEABLE // // END AGEABLE //
case "ARMOR_STAND": case "ARMOR_STAND" -> {
ArmorStand stand = (ArmorStand) entity; ArmorStand stand = (ArmorStand) entity;
this.inventory = this.inventory =
new ItemStack[]{stand.getItemInHand().clone(), stand.getHelmet().clone(), new ItemStack[]{stand.getItemInHand().clone(), stand.getHelmet().clone(),
@ -238,37 +210,30 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
stand.getBoots().clone()}; stand.getBoots().clone()};
storeLiving(stand); storeLiving(stand);
this.stand = new ArmorStandStats(); this.stand = new ArmorStandStats();
EulerAngle head = stand.getHeadPose(); EulerAngle head = stand.getHeadPose();
this.stand.head[0] = (float) head.getX(); this.stand.head[0] = (float) head.getX();
this.stand.head[1] = (float) head.getY(); this.stand.head[1] = (float) head.getY();
this.stand.head[2] = (float) head.getZ(); this.stand.head[2] = (float) head.getZ();
EulerAngle body = stand.getBodyPose(); EulerAngle body = stand.getBodyPose();
this.stand.body[0] = (float) body.getX(); this.stand.body[0] = (float) body.getX();
this.stand.body[1] = (float) body.getY(); this.stand.body[1] = (float) body.getY();
this.stand.body[2] = (float) body.getZ(); this.stand.body[2] = (float) body.getZ();
EulerAngle leftLeg = stand.getLeftLegPose(); EulerAngle leftLeg = stand.getLeftLegPose();
this.stand.leftLeg[0] = (float) leftLeg.getX(); this.stand.leftLeg[0] = (float) leftLeg.getX();
this.stand.leftLeg[1] = (float) leftLeg.getY(); this.stand.leftLeg[1] = (float) leftLeg.getY();
this.stand.leftLeg[2] = (float) leftLeg.getZ(); this.stand.leftLeg[2] = (float) leftLeg.getZ();
EulerAngle rightLeg = stand.getRightLegPose(); EulerAngle rightLeg = stand.getRightLegPose();
this.stand.rightLeg[0] = (float) rightLeg.getX(); this.stand.rightLeg[0] = (float) rightLeg.getX();
this.stand.rightLeg[1] = (float) rightLeg.getY(); this.stand.rightLeg[1] = (float) rightLeg.getY();
this.stand.rightLeg[2] = (float) rightLeg.getZ(); this.stand.rightLeg[2] = (float) rightLeg.getZ();
EulerAngle leftArm = stand.getLeftArmPose(); EulerAngle leftArm = stand.getLeftArmPose();
this.stand.leftArm[0] = (float) leftArm.getX(); this.stand.leftArm[0] = (float) leftArm.getX();
this.stand.leftArm[1] = (float) leftArm.getY(); this.stand.leftArm[1] = (float) leftArm.getY();
this.stand.leftArm[2] = (float) leftArm.getZ(); this.stand.leftArm[2] = (float) leftArm.getZ();
EulerAngle rightArm = stand.getRightArmPose(); EulerAngle rightArm = stand.getRightArmPose();
this.stand.rightArm[0] = (float) rightArm.getX(); this.stand.rightArm[0] = (float) rightArm.getX();
this.stand.rightArm[1] = (float) rightArm.getY(); this.stand.rightArm[1] = (float) rightArm.getY();
this.stand.rightArm[2] = (float) rightArm.getZ(); this.stand.rightArm[2] = (float) rightArm.getZ();
if (stand.hasArms()) { if (stand.hasArms()) {
this.stand.arms = true; this.stand.arms = true;
} }
@ -282,53 +247,38 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
this.stand.small = true; this.stand.small = true;
} }
return; return;
case "ENDERMITE": }
case "ENDERMITE" -> {
return; return;
case "BAT": }
case "BAT" -> {
if (((Bat) entity).isAwake()) { if (((Bat) entity).isAwake()) {
this.dataByte = (byte) 1; this.dataByte = (byte) 1;
} else { } else {
this.dataByte = (byte) 0; this.dataByte = (byte) 0;
} }
return; return;
case "ENDER_DRAGON": }
case "ENDER_DRAGON" -> {
EnderDragon entity1 = (EnderDragon) entity; EnderDragon entity1 = (EnderDragon) entity;
this.dataByte = (byte) entity1.getPhase().ordinal(); this.dataByte = (byte) entity1.getPhase().ordinal();
return; return;
case "SKELETON": }
case "WITHER_SKELETON": case "SKELETON", "WITHER_SKELETON", "GUARDIAN", "ELDER_GUARDIAN", "GHAST", "MAGMA_CUBE", "SQUID", "PIG_ZOMBIE", "HOGLIN",
case "GUARDIAN": "ZOMBIFIED_PIGLIN", "PIGLIN", "PIGLIN_BRUTE", "ZOMBIE", "WITHER", "WITCH", "SPIDER", "CAVE_SPIDER", "SILVERFISH",
case "ELDER_GUARDIAN": "GIANT", "ENDERMAN", "CREEPER", "BLAZE", "SHULKER", "SNOWMAN" -> {
case "GHAST":
case "MAGMA_CUBE":
case "SQUID":
case "PIG_ZOMBIE":
case "HOGLIN":
case "ZOMBIFIED_PIGLIN":
case "PIGLIN":
case "PIGLIN_BRUTE":
case "ZOMBIE":
case "WITHER":
case "WITCH":
case "SPIDER":
case "CAVE_SPIDER":
case "SILVERFISH":
case "GIANT":
case "ENDERMAN":
case "CREEPER":
case "BLAZE":
case "SHULKER":
case "SNOWMAN":
storeLiving((LivingEntity) entity); storeLiving((LivingEntity) entity);
return; return;
case "IRON_GOLEM": }
case "IRON_GOLEM" -> {
if (((IronGolem) entity).isPlayerCreated()) { if (((IronGolem) entity).isPlayerCreated()) {
this.dataByte = (byte) 1; this.dataByte = (byte) 1;
} else { } else {
this.dataByte = (byte) 0; this.dataByte = (byte) 0;
} }
storeLiving((LivingEntity) entity); storeLiving((LivingEntity) entity);
// END LIVING // }
// END LIVING //
} }
} }
@ -465,20 +415,15 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
} }
Entity entity; Entity entity;
switch (this.getType().toString()) { switch (this.getType().toString()) {
case "DROPPED_ITEM": case "DROPPED_ITEM" -> {
return world.dropItem(location, this.stack); return world.dropItem(location, this.stack);
case "PLAYER": }
case "LEASH_HITCH": case "PLAYER", "LEASH_HITCH" -> {
return null; return null;
case "ITEM_FRAME": }
entity = world.spawn(location, ItemFrame.class); case "ITEM_FRAME" -> entity = world.spawn(location, ItemFrame.class);
break; case "PAINTING" -> entity = world.spawn(location, Painting.class);
case "PAINTING": default -> entity = world.spawnEntity(location, this.getType());
entity = world.spawn(location, Painting.class);
break;
default:
entity = world.spawnEntity(location, this.getType());
break;
} }
if (this.depth == 0) { if (this.depth == 0) {
return entity; return entity;
@ -506,72 +451,46 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
entity.setGravity(false); entity.setGravity(false);
} }
switch (entity.getType().toString()) { switch (entity.getType().toString()) {
case "BOAT": case "BOAT" -> {
Boat boat = (Boat) entity; Boat boat = (Boat) entity;
boat.setWoodType(TreeSpecies.values()[dataByte]); boat.setWoodType(TreeSpecies.values()[dataByte]);
return entity; return entity;
case "SLIME": }
case "SLIME" -> {
((Slime) entity).setSize(this.dataByte); ((Slime) entity).setSize(this.dataByte);
return entity; return entity;
case "ARROW": }
case "EGG": case "ARROW", "EGG", "ENDER_CRYSTAL", "ENDER_PEARL", "ENDER_SIGNAL", "DROPPED_ITEM", "EXPERIENCE_ORB", "FALLING_BLOCK",
case "ENDER_CRYSTAL": "FIREBALL", "FIREWORK", "FISHING_HOOK", "LEASH_HITCH", "LIGHTNING", "MINECART", "MINECART_COMMAND",
case "ENDER_PEARL": "MINECART_MOB_SPAWNER", "MINECART_TNT", "PLAYER", "PRIMED_TNT", "SMALL_FIREBALL", "SNOWBALL",
case "ENDER_SIGNAL": "SPLASH_POTION", "THROWN_EXP_BOTTLE", "SPECTRAL_ARROW", "SHULKER_BULLET", "AREA_EFFECT_CLOUD",
case "DROPPED_ITEM": "DRAGON_FIREBALL", "WITHER_SKULL", "MINECART_FURNACE", "LLAMA_SPIT", "TRIDENT", "UNKNOWN" -> {
case "EXPERIENCE_ORB":
case "FALLING_BLOCK":
case "FIREBALL":
case "FIREWORK":
case "FISHING_HOOK":
case "LEASH_HITCH":
case "LIGHTNING":
case "MINECART":
case "MINECART_COMMAND":
case "MINECART_MOB_SPAWNER":
case "MINECART_TNT":
case "PLAYER":
case "PRIMED_TNT":
case "SMALL_FIREBALL":
case "SNOWBALL":
case "SPLASH_POTION":
case "THROWN_EXP_BOTTLE":
case "SPECTRAL_ARROW":
case "SHULKER_BULLET":
case "AREA_EFFECT_CLOUD":
case "DRAGON_FIREBALL":
case "WITHER_SKULL":
case "MINECART_FURNACE":
case "LLAMA_SPIT":
case "TRIDENT":
case "UNKNOWN":
// Do this stuff later // Do this stuff later
return entity; return entity;
}
// MISC // // MISC //
case "ITEM_FRAME": case "ITEM_FRAME" -> {
ItemFrame itemframe = (ItemFrame) entity; ItemFrame itemframe = (ItemFrame) entity;
itemframe.setRotation(Rotation.values()[this.dataByte]); itemframe.setRotation(Rotation.values()[this.dataByte]);
itemframe.setItem(this.stack); itemframe.setItem(this.stack);
return entity; return entity;
case "PAINTING": }
case "PAINTING" -> {
Painting painting = (Painting) entity; Painting painting = (Painting) entity;
painting.setFacingDirection(BlockFace.values()[this.dataByte], true); painting.setFacingDirection(BlockFace.values()[this.dataByte], true);
painting.setArt(Art.getByName(this.dataString), true); painting.setArt(Art.getByName(this.dataString), true);
return entity; return entity;
}
// END MISC // // END MISC //
// INVENTORY HOLDER // // INVENTORY HOLDER //
case "MINECART_CHEST": case "MINECART_CHEST", "MINECART_HOPPER" -> {
case "MINECART_HOPPER":
restoreInventory((InventoryHolder) entity); restoreInventory((InventoryHolder) entity);
return entity; return entity;
}
// START LIVING ENTITY // // START LIVING ENTITY //
// START AGEABLE // // START AGEABLE //
// START TAMEABLE // // START TAMEABLE //
case "HORSE": case "HORSE", "LLAMA", "SKELETON_HORSE", "DONKEY", "MULE" -> {
case "LLAMA":
case "SKELETON_HORSE":
case "DONKEY":
case "MULE":
AbstractHorse horse = (AbstractHorse) entity; AbstractHorse horse = (AbstractHorse) entity;
horse.setJumpStrength(this.horse.jump); horse.setJumpStrength(this.horse.jump);
if (horse instanceof ChestedHorse) { if (horse instanceof ChestedHorse) {
@ -586,15 +505,16 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
restoreLiving(horse); restoreLiving(horse);
restoreInventory(horse); restoreInventory(horse);
return entity; return entity;
}
// END INVENTORY HOLDER // // END INVENTORY HOLDER //
case "WOLF": case "WOLF", "OCELOT" -> {
case "OCELOT":
restoreTameable((Tameable) entity); restoreTameable((Tameable) entity);
restoreAgeable((Ageable) entity); restoreAgeable((Ageable) entity);
restoreLiving((LivingEntity) entity); restoreLiving((LivingEntity) entity);
return entity; return entity;
}
// END AGEABLE // // END AGEABLE //
case "SHEEP": case "SHEEP" -> {
Sheep sheep = (Sheep) entity; Sheep sheep = (Sheep) entity;
if (this.dataByte == 1) { if (this.dataByte == 1) {
sheep.setSheared(true); sheep.setSheared(true);
@ -605,25 +525,22 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
restoreAgeable(sheep); restoreAgeable(sheep);
restoreLiving(sheep); restoreLiving(sheep);
return sheep; return sheep;
case "VILLAGER": }
case "CHICKEN": case "VILLAGER", "CHICKEN", "COW", "TURTLE", "POLAR_BEAR", "MUSHROOM_COW", "PIG" -> {
case "COW":
case "TURTLE":
case "POLAR_BEAR":
case "MUSHROOM_COW":
case "PIG":
restoreAgeable((Ageable) entity); restoreAgeable((Ageable) entity);
restoreLiving((LivingEntity) entity); restoreLiving((LivingEntity) entity);
return entity; return entity;
}
// END AGEABLE // // END AGEABLE //
case "RABBIT": case "RABBIT" -> {
if (this.dataByte != 0) { if (this.dataByte != 0) {
((Rabbit) entity).setRabbitType(Rabbit.Type.values()[this.dataByte]); ((Rabbit) entity).setRabbitType(Rabbit.Type.values()[this.dataByte]);
} }
restoreAgeable((Ageable) entity); restoreAgeable((Ageable) entity);
restoreLiving((LivingEntity) entity); restoreLiving((LivingEntity) entity);
return entity; return entity;
case "ARMOR_STAND": }
case "ARMOR_STAND" -> {
// CHECK positions // CHECK positions
ArmorStand stand = (ArmorStand) entity; ArmorStand stand = (ArmorStand) entity;
if (this.inventory[0] != null) { if (this.inventory[0] != null) {
@ -693,56 +610,38 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
} }
restoreLiving(stand); restoreLiving(stand);
return stand; return stand;
case "BAT": }
case "BAT" -> {
if (this.dataByte != 0) { if (this.dataByte != 0) {
((Bat) entity).setAwake(true); ((Bat) entity).setAwake(true);
} }
restoreLiving((LivingEntity) entity); restoreLiving((LivingEntity) entity);
return entity; return entity;
case "ENDER_DRAGON": }
case "ENDER_DRAGON" -> {
if (this.dataByte != 0) { if (this.dataByte != 0) {
((EnderDragon) entity).setPhase(EnderDragon.Phase.values()[this.dataByte]); ((EnderDragon) entity).setPhase(EnderDragon.Phase.values()[this.dataByte]);
} }
restoreLiving((LivingEntity) entity); restoreLiving((LivingEntity) entity);
return entity; return entity;
case "ENDERMITE": }
case "GHAST": case "ENDERMITE", "GHAST", "MAGMA_CUBE", "SQUID", "PIG_ZOMBIE", "HOGLIN", "PIGLIN", "ZOMBIFIED_PIGLIN", "PIGLIN_BRUTE", "ZOMBIE", "WITHER", "WITCH", "SPIDER", "CAVE_SPIDER", "SILVERFISH", "GIANT", "ENDERMAN", "CREEPER", "BLAZE", "SNOWMAN", "SHULKER", "GUARDIAN", "ELDER_GUARDIAN", "SKELETON", "WITHER_SKELETON" -> {
case "MAGMA_CUBE":
case "SQUID":
case "PIG_ZOMBIE":
case "HOGLIN":
case "PIGLIN":
case "ZOMBIFIED_PIGLIN":
case "PIGLIN_BRUTE":
case "ZOMBIE":
case "WITHER":
case "WITCH":
case "SPIDER":
case "CAVE_SPIDER":
case "SILVERFISH":
case "GIANT":
case "ENDERMAN":
case "CREEPER":
case "BLAZE":
case "SNOWMAN":
case "SHULKER":
case "GUARDIAN":
case "ELDER_GUARDIAN":
case "SKELETON":
case "WITHER_SKELETON":
restoreLiving((LivingEntity) entity); restoreLiving((LivingEntity) entity);
return entity; return entity;
case "IRON_GOLEM": }
case "IRON_GOLEM" -> {
if (this.dataByte != 0) { if (this.dataByte != 0) {
((IronGolem) entity).setPlayerCreated(true); ((IronGolem) entity).setPlayerCreated(true);
} }
restoreLiving((LivingEntity) entity); restoreLiving((LivingEntity) entity);
return entity; return entity;
default: }
default -> {
if (Settings.DEBUG) { if (Settings.DEBUG) {
LOGGER.info("Could not identify entity: {}", entity.getType()); LOGGER.info("Could not identify entity: {}", entity.getType());
} }
return entity; return entity;
}
// END LIVING // END LIVING
} }
} }

View File

@ -145,54 +145,37 @@ public class EntityEventListener implements Listener {
} }
CreatureSpawnEvent.SpawnReason reason = event.getSpawnReason(); CreatureSpawnEvent.SpawnReason reason = event.getSpawnReason();
switch (reason.toString()) { switch (reason.toString()) {
case "DISPENSE_EGG": case "DISPENSE_EGG", "EGG", "OCELOT_BABY", "SPAWNER_EGG" -> {
case "EGG":
case "OCELOT_BABY":
case "SPAWNER_EGG":
if (!area.isSpawnEggs()) { if (!area.isSpawnEggs()) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
break; }
case "REINFORCEMENTS": case "REINFORCEMENTS", "NATURAL", "MOUNT", "PATROL", "RAID", "SHEARED", "SILVERFISH_BLOCK", "ENDER_PEARL",
case "NATURAL": "TRAP", "VILLAGE_DEFENSE", "VILLAGE_INVASION", "BEEHIVE", "CHUNK_GEN" -> {
case "MOUNT":
case "PATROL":
case "RAID":
case "SHEARED":
case "SILVERFISH_BLOCK":
case "ENDER_PEARL":
case "TRAP":
case "VILLAGE_DEFENSE":
case "VILLAGE_INVASION":
case "BEEHIVE":
case "CHUNK_GEN":
if (!area.isMobSpawning()) { if (!area.isMobSpawning()) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
break; }
case "BREEDING": case "BREEDING" -> {
if (!area.isSpawnBreeding()) { if (!area.isSpawnBreeding()) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
break; }
case "BUILD_IRONGOLEM": case "BUILD_IRONGOLEM", "BUILD_SNOWMAN", "BUILD_WITHER", "CUSTOM" -> {
case "BUILD_SNOWMAN":
case "BUILD_WITHER":
case "CUSTOM":
if (!area.isSpawnCustom() && entity.getType() != EntityType.ARMOR_STAND) { if (!area.isSpawnCustom() && entity.getType() != EntityType.ARMOR_STAND) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
break; }
case "SPAWNER": case "SPAWNER" -> {
if (!area.isMobSpawnerSpawning()) { if (!area.isMobSpawnerSpawning()) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
break; }
} }
Plot plot = area.getOwnedPlotAbs(location); Plot plot = area.getOwnedPlotAbs(location);
if (plot == null) { if (plot == null) {

View File

@ -178,59 +178,41 @@ public class PaperListener implements Listener {
} }
CreatureSpawnEvent.SpawnReason reason = event.getReason(); CreatureSpawnEvent.SpawnReason reason = event.getReason();
switch (reason.toString()) { switch (reason.toString()) {
case "DISPENSE_EGG": case "DISPENSE_EGG", "EGG", "OCELOT_BABY", "SPAWNER_EGG" -> {
case "EGG":
case "OCELOT_BABY":
case "SPAWNER_EGG":
if (!area.isSpawnEggs()) { if (!area.isSpawnEggs()) {
event.setShouldAbortSpawn(true); event.setShouldAbortSpawn(true);
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
break; }
case "REINFORCEMENTS": case "REINFORCEMENTS", "NATURAL", "MOUNT", "PATROL", "RAID", "SHEARED", "SILVERFISH_BLOCK", "ENDER_PEARL", "TRAP", "VILLAGE_DEFENSE", "VILLAGE_INVASION", "BEEHIVE", "CHUNK_GEN" -> {
case "NATURAL":
case "MOUNT":
case "PATROL":
case "RAID":
case "SHEARED":
case "SILVERFISH_BLOCK":
case "ENDER_PEARL":
case "TRAP":
case "VILLAGE_DEFENSE":
case "VILLAGE_INVASION":
case "BEEHIVE":
case "CHUNK_GEN":
if (!area.isMobSpawning()) { if (!area.isMobSpawning()) {
event.setShouldAbortSpawn(true); event.setShouldAbortSpawn(true);
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
break; }
case "BREEDING": case "BREEDING" -> {
if (!area.isSpawnBreeding()) { if (!area.isSpawnBreeding()) {
event.setShouldAbortSpawn(true); event.setShouldAbortSpawn(true);
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
break; }
case "BUILD_IRONGOLEM": case "BUILD_IRONGOLEM", "BUILD_SNOWMAN", "BUILD_WITHER", "CUSTOM" -> {
case "BUILD_SNOWMAN":
case "BUILD_WITHER":
case "CUSTOM":
if (!area.isSpawnCustom() && event.getType() != EntityType.ARMOR_STAND) { if (!area.isSpawnCustom() && event.getType() != EntityType.ARMOR_STAND) {
event.setShouldAbortSpawn(true); event.setShouldAbortSpawn(true);
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
break; }
case "SPAWNER": case "SPAWNER" -> {
if (!area.isMobSpawnerSpawning()) { if (!area.isMobSpawnerSpawning()) {
event.setShouldAbortSpawn(true); event.setShouldAbortSpawn(true);
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
break; }
} }
Plot plot = location.getOwnedPlotAbs(); Plot plot = location.getOwnedPlotAbs();
if (plot == null) { if (plot == null) {

View File

@ -273,8 +273,7 @@ public class PlayerEventListener implements Listener {
Plot plot = plotPlayer.getCurrentPlot(); Plot plot = plotPlayer.getCurrentPlot();
// Check WorldEdit // Check WorldEdit
switch (parts[0]) { switch (parts[0]) {
case "up": case "up", "worldedit:up" -> {
case "worldedit:up":
if (plot == null || (!plot.isAdded(plotPlayer.getUUID()) && !plotPlayer.hasPermission( if (plot == null || (!plot.isAdded(plotPlayer.getUUID()) && !plotPlayer.hasPermission(
Permission.PERMISSION_ADMIN_BUILD_OTHER, Permission.PERMISSION_ADMIN_BUILD_OTHER,
true true
@ -282,6 +281,7 @@ public class PlayerEventListener implements Listener {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
}
} }
if (plot == null && !area.isRoadFlags()) { if (plot == null && !area.isRoadFlags()) {
return; return;
@ -1114,13 +1114,13 @@ public class PlayerEventListener implements Listener {
Location location = BukkitUtil.adapt(block.getLocation()); Location location = BukkitUtil.adapt(block.getLocation());
Action action = event.getAction(); Action action = event.getAction();
switch (action) { switch (action) {
case PHYSICAL: { case PHYSICAL -> {
eventType = PlayerBlockEventType.TRIGGER_PHYSICAL; eventType = PlayerBlockEventType.TRIGGER_PHYSICAL;
blocktype1 = BukkitAdapter.asBlockType(block.getType()); blocktype1 = BukkitAdapter.asBlockType(block.getType());
break;
} }
//todo rearrange the right click code. it is all over the place. //todo rearrange the right click code. it is all over the place.
case RIGHT_CLICK_BLOCK: { case RIGHT_CLICK_BLOCK -> {
Material blockType = block.getType(); Material blockType = block.getType();
eventType = PlayerBlockEventType.INTERACT_BLOCK; eventType = PlayerBlockEventType.INTERACT_BLOCK;
blocktype1 = BukkitAdapter.asBlockType(block.getType()); blocktype1 = BukkitAdapter.asBlockType(block.getType());
@ -1142,21 +1142,16 @@ public class PlayerEventListener implements Listener {
// in the following, lb needs to have the material of the item in hand i.e. type // in the following, lb needs to have the material of the item in hand i.e. type
switch (type.toString()) { switch (type.toString()) {
case "REDSTONE": case "REDSTONE", "STRING", "PUMPKIN_SEEDS", "MELON_SEEDS", "COCOA_BEANS", "WHEAT_SEEDS", "BEETROOT_SEEDS",
case "STRING": "SWEET_BERRIES", "GLOW_BERRIES" -> {
case "PUMPKIN_SEEDS":
case "MELON_SEEDS":
case "COCOA_BEANS":
case "WHEAT_SEEDS":
case "BEETROOT_SEEDS":
case "SWEET_BERRIES":
case "GLOW_BERRIES":
return; return;
default: }
default -> {
//eventType = PlayerBlockEventType.PLACE_BLOCK; //eventType = PlayerBlockEventType.PLACE_BLOCK;
if (type.isBlock()) { if (type.isBlock()) {
return; return;
} }
}
} }
if (PaperLib.isPaper()) { if (PaperLib.isPaper()) {
if (MaterialTags.SPAWN_EGGS.isTagged(type) || Material.EGG.equals(type)) { if (MaterialTags.SPAWN_EGGS.isTagged(type) || Material.EGG.equals(type)) {
@ -1189,9 +1184,8 @@ public class PlayerEventListener implements Listener {
eventType = PlayerBlockEventType.READ; eventType = PlayerBlockEventType.READ;
break; break;
} }
break;
} }
case LEFT_CLICK_BLOCK: { case LEFT_CLICK_BLOCK -> {
Material blockType = block.getType(); Material blockType = block.getType();
// todo: when the code above is rearranged, it would be great to beautify this as well. // todo: when the code above is rearranged, it would be great to beautify this as well.
@ -1202,10 +1196,10 @@ public class PlayerEventListener implements Listener {
eventType = PlayerBlockEventType.INTERACT_BLOCK; eventType = PlayerBlockEventType.INTERACT_BLOCK;
blocktype1 = BukkitAdapter.asBlockType(block.getType()); blocktype1 = BukkitAdapter.asBlockType(block.getType());
break;
} }
default: default -> {
return; return;
}
} }
if (this.worldEdit != null && pp.getAttribute("worldedit")) { if (this.worldEdit != null && pp.getAttribute("worldedit")) {
if (event.getMaterial() == Material.getMaterial(this.worldEdit.getConfiguration().wandItem)) { if (event.getMaterial() == Material.getMaterial(this.worldEdit.getConfiguration().wandItem)) {

View File

@ -107,37 +107,35 @@ public class Clear extends Command {
} }
BackupManager.backup(player, plot, () -> { BackupManager.backup(player, plot, () -> {
final long start = System.currentTimeMillis(); final long start = System.currentTimeMillis();
boolean result = plot.getPlotModificationManager().clear(true, false, player, () -> { boolean result = plot.getPlotModificationManager().clear(true, false, player, () -> TaskManager.runTask(() -> {
TaskManager.runTask(() -> { plot.removeRunning();
plot.removeRunning(); // If the state changes, then mark it as no longer done
// If the state changes, then mark it as no longer done if (DoneFlag.isDone(plot)) {
if (DoneFlag.isDone(plot)) { PlotFlag<?, ?> plotFlag =
PlotFlag<?, ?> plotFlag = plot.getFlagContainer().getFlag(DoneFlag.class);
plot.getFlagContainer().getFlag(DoneFlag.class); PlotFlagRemoveEvent event = this.eventDispatcher
PlotFlagRemoveEvent event = this.eventDispatcher .callFlagRemove(plotFlag, plot);
.callFlagRemove(plotFlag, plot); if (event.getEventResult() != Result.DENY) {
if (event.getEventResult() != Result.DENY) { plot.removeFlag(event.getFlag());
plot.removeFlag(event.getFlag());
}
} }
if (!plot.getFlag(AnalysisFlag.class).isEmpty()) { }
PlotFlag<?, ?> plotFlag = if (!plot.getFlag(AnalysisFlag.class).isEmpty()) {
plot.getFlagContainer().getFlag(AnalysisFlag.class); PlotFlag<?, ?> plotFlag =
PlotFlagRemoveEvent event = this.eventDispatcher plot.getFlagContainer().getFlag(AnalysisFlag.class);
.callFlagRemove(plotFlag, plot); PlotFlagRemoveEvent event = this.eventDispatcher
if (event.getEventResult() != Result.DENY) { .callFlagRemove(plotFlag, plot);
plot.removeFlag(event.getFlag()); if (event.getEventResult() != Result.DENY) {
} plot.removeFlag(event.getFlag());
} }
player.sendMessage( }
TranslatableCaption.of("working.clearing_done"), player.sendMessage(
TagResolver.builder() TranslatableCaption.of("working.clearing_done"),
.tag("amount", Tag.inserting(Component.text(System.currentTimeMillis() - start))) TagResolver.builder()
.tag("plot", Tag.inserting(Component.text(plot.getId().toString()))) .tag("amount", Tag.inserting(Component.text(System.currentTimeMillis() - start)))
.build() .tag("plot", Tag.inserting(Component.text(plot.getId().toString())))
); .build()
}); );
}); }));
if (!result) { if (!result) {
player.sendMessage(TranslatableCaption.of("errors.wait_for_timer")); player.sendMessage(TranslatableCaption.of("errors.wait_for_timer"));
} else { } else {

View File

@ -46,6 +46,7 @@ import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
@ -77,8 +78,7 @@ public class Cluster extends SubCommand {
} }
String sub = args[0].toLowerCase(); String sub = args[0].toLowerCase();
switch (sub) { switch (sub) {
case "l": case "l", "list" -> {
case "list": {
if (!player.hasPermission(Permission.PERMISSION_CLUSTER_LIST)) { if (!player.hasPermission(Permission.PERMISSION_CLUSTER_LIST)) {
player.sendMessage( player.sendMessage(
TranslatableCaption.of("permission.no_permission"), TranslatableCaption.of("permission.no_permission"),
@ -133,8 +133,7 @@ public class Cluster extends SubCommand {
} }
return true; return true;
} }
case "c": case "c", "create" -> {
case "create": {
if (!player.hasPermission(Permission.PERMISSION_CLUSTER_CREATE)) { if (!player.hasPermission(Permission.PERMISSION_CLUSTER_CREATE)) {
player.sendMessage( player.sendMessage(
TranslatableCaption.of("permission.no_permission"), TranslatableCaption.of("permission.no_permission"),
@ -269,9 +268,7 @@ public class Cluster extends SubCommand {
); );
return true; return true;
} }
case "disband": case "disband", "del", "delete" -> {
case "del":
case "delete": {
if (!player.hasPermission(Permission.PERMISSION_CLUSTER_DELETE)) { if (!player.hasPermission(Permission.PERMISSION_CLUSTER_DELETE)) {
player.sendMessage( player.sendMessage(
TranslatableCaption.of("permission.no_permission"), TranslatableCaption.of("permission.no_permission"),
@ -330,8 +327,7 @@ public class Cluster extends SubCommand {
)); ));
return true; return true;
} }
case "res": case "res", "resize" -> {
case "resize": {
if (!player.hasPermission(Permission.PERMISSION_CLUSTER_RESIZE)) { if (!player.hasPermission(Permission.PERMISSION_CLUSTER_RESIZE)) {
player.sendMessage( player.sendMessage(
TranslatableCaption.of("permission.no_permission"), TranslatableCaption.of("permission.no_permission"),
@ -452,9 +448,7 @@ public class Cluster extends SubCommand {
player.sendMessage(TranslatableCaption.of("cluster.cluster_resized")); player.sendMessage(TranslatableCaption.of("cluster.cluster_resized"));
return true; return true;
} }
case "add": case "add", "inv", "invite" -> {
case "inv":
case "invite": {
if (!player.hasPermission(Permission.PERMISSION_CLUSTER_INVITE)) { if (!player.hasPermission(Permission.PERMISSION_CLUSTER_INVITE)) {
player.sendMessage( player.sendMessage(
TranslatableCaption.of("permission.no_permission"), TranslatableCaption.of("permission.no_permission"),
@ -523,9 +517,7 @@ public class Cluster extends SubCommand {
}); });
return true; return true;
} }
case "k": case "k", "remove", "kick" -> {
case "remove":
case "kick": {
if (!player.hasPermission(Permission.PERMISSION_CLUSTER_KICK)) { if (!player.hasPermission(Permission.PERMISSION_CLUSTER_KICK)) {
player.sendMessage( player.sendMessage(
TranslatableCaption.of("permission.no_permission"), TranslatableCaption.of("permission.no_permission"),
@ -605,8 +597,7 @@ public class Cluster extends SubCommand {
}); });
return true; return true;
} }
case "quit": case "quit", "leave" -> {
case "leave": {
if (!player.hasPermission(Permission.PERMISSION_CLUSTER_LEAVE)) { if (!player.hasPermission(Permission.PERMISSION_CLUSTER_LEAVE)) {
player.sendMessage( player.sendMessage(
TranslatableCaption.of("permission.no_permission"), TranslatableCaption.of("permission.no_permission"),
@ -667,7 +658,7 @@ public class Cluster extends SubCommand {
removePlayerPlots(cluster, uuid, player.getLocation().getWorldName()); removePlayerPlots(cluster, uuid, player.getLocation().getWorldName());
return true; return true;
} }
case "members": { case "members" -> {
if (!player.hasPermission(Permission.PERMISSION_CLUSTER_HELPERS)) { if (!player.hasPermission(Permission.PERMISSION_CLUSTER_HELPERS)) {
player.sendMessage( player.sendMessage(
TranslatableCaption.of("permission.no_permission"), TranslatableCaption.of("permission.no_permission"),
@ -728,9 +719,7 @@ public class Cluster extends SubCommand {
}); });
return true; return true;
} }
case "spawn": case "spawn", "home", "tp" -> {
case "home":
case "tp": {
if (!player.hasPermission(Permission.PERMISSION_CLUSTER_TP)) { if (!player.hasPermission(Permission.PERMISSION_CLUSTER_TP)) {
player.sendMessage( player.sendMessage(
TranslatableCaption.of("permission.no_permission"), TranslatableCaption.of("permission.no_permission"),
@ -778,10 +767,7 @@ public class Cluster extends SubCommand {
player.sendMessage(TranslatableCaption.of("cluster.cluster_teleporting")); player.sendMessage(TranslatableCaption.of("cluster.cluster_teleporting"));
return true; return true;
} }
case "i": case "i", "info", "show", "information" -> {
case "info":
case "show":
case "information": {
if (!player.hasPermission(Permission.PERMISSION_CLUSTER_INFO)) { if (!player.hasPermission(Permission.PERMISSION_CLUSTER_INFO)) {
player.sendMessage( player.sendMessage(
TranslatableCaption.of("permission.no_permission"), TranslatableCaption.of("permission.no_permission"),
@ -828,11 +814,7 @@ public class Cluster extends SubCommand {
player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout")); player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout"));
} else { } else {
final String owner; final String owner;
if (username == null) { owner = Objects.requireNonNullElse(username, "unknown");
owner = "unknown";
} else {
owner = username;
}
String name = cluster.getName(); String name = cluster.getName();
String size = (cluster.getP2().getX() - cluster.getP1().getX() + 1) + "x" + ( String size = (cluster.getP2().getX() - cluster.getP1().getX() + 1) + "x" + (
cluster.getP2().getY() - cluster.getP1().getY() + 1); cluster.getP2().getY() - cluster.getP1().getY() + 1);
@ -850,9 +832,7 @@ public class Cluster extends SubCommand {
}); });
return true; return true;
} }
case "sh": case "sh", "setspawn", "sethome" -> {
case "setspawn":
case "sethome": {
if (!player.hasPermission(Permission.PERMISSION_CLUSTER_SETHOME)) { if (!player.hasPermission(Permission.PERMISSION_CLUSTER_SETHOME)) {
player.sendMessage( player.sendMessage(
TranslatableCaption.of("permission.no_permission"), TranslatableCaption.of("permission.no_permission"),

View File

@ -559,9 +559,10 @@ public abstract class Command {
public Collection<Command> tab(PlotPlayer<?> player, String[] args, boolean space) { public Collection<Command> tab(PlotPlayer<?> player, String[] args, boolean space) {
switch (args.length) { switch (args.length) {
case 0: case 0 -> {
return this.allCommands; return this.allCommands;
case 1: }
case 1 -> {
String arg = args[0].toLowerCase(); String arg = args[0].toLowerCase();
if (space) { if (space) {
Command cmd = getCommand(arg); Command cmd = getCommand(arg);
@ -580,13 +581,15 @@ public abstract class Command {
} }
return commands; return commands;
} }
default: }
default -> {
Command cmd = getCommand(args[0]); Command cmd = getCommand(args[0]);
if (cmd != null) { if (cmd != null) {
return cmd.tab(player, Arrays.copyOfRange(args, 1, args.length), space); return cmd.tab(player, Arrays.copyOfRange(args, 1, args.length), space);
} else { } else {
return null; return null;
} }
}
} }
} }

View File

@ -75,16 +75,19 @@ public class DebugRoadRegen extends SubCommand {
} }
String kind = args[0].toLowerCase(); String kind = args[0].toLowerCase();
switch (kind) { switch (kind) {
case "plot": case "plot" -> {
return regenPlot(player); return regenPlot(player);
case "region": }
case "region" -> {
return regenRegion(player, Arrays.copyOfRange(args, 1, args.length)); return regenRegion(player, Arrays.copyOfRange(args, 1, args.length));
default: }
default -> {
player.sendMessage( player.sendMessage(
TranslatableCaption.of("commandconfig.command_syntax"), TranslatableCaption.of("commandconfig.command_syntax"),
TagResolver.resolver("value", Tag.inserting(Component.text(DebugRoadRegen.USAGE))) TagResolver.resolver("value", Tag.inserting(Component.text(DebugRoadRegen.USAGE)))
); );
return false; return false;
}
} }
} }

View File

@ -60,9 +60,10 @@ public class Help extends Command {
RunnableVal2<Command, CommandResult> whenDone RunnableVal2<Command, CommandResult> whenDone
) { ) {
switch (args.length) { switch (args.length) {
case 0: case 0 -> {
return displayHelp(player, null, 0); return displayHelp(player, null, 0);
case 1: }
case 1 -> {
if (MathMan.isInteger(args[0])) { if (MathMan.isInteger(args[0])) {
try { try {
return displayHelp(player, null, Integer.parseInt(args[0])); return displayHelp(player, null, Integer.parseInt(args[0]));
@ -72,7 +73,8 @@ public class Help extends Command {
} else { } else {
return displayHelp(player, args[0], 1); return displayHelp(player, args[0], 1);
} }
case 2: }
case 2 -> {
if (MathMan.isInteger(args[1])) { if (MathMan.isInteger(args[1])) {
try { try {
return displayHelp(player, args[0], Integer.parseInt(args[1])); return displayHelp(player, args[0], Integer.parseInt(args[1]));
@ -81,8 +83,8 @@ public class Help extends Command {
} }
} }
return CompletableFuture.completedFuture(false); return CompletableFuture.completedFuture(false);
default: }
sendUsage(player); default -> sendUsage(player);
} }
return CompletableFuture.completedFuture(true); return CompletableFuture.completedFuture(true);
} }

View File

@ -190,7 +190,7 @@ public class Inbox extends SubCommand {
final int page; final int page;
if (args.length > 1) { if (args.length > 1) {
switch (args[1].toLowerCase()) { switch (args[1].toLowerCase()) {
case "delete": case "delete" -> {
if (!inbox.canModify(plot, player)) { if (!inbox.canModify(plot, player)) {
player.sendMessage(TranslatableCaption.of("comment.no_perm_inbox_modify")); player.sendMessage(TranslatableCaption.of("comment.no_perm_inbox_modify"));
return false; return false;
@ -225,7 +225,6 @@ public class Inbox extends SubCommand {
); );
return false; return false;
} }
if (!inbox.getComments(plot, new RunnableVal<>() { if (!inbox.getComments(plot, new RunnableVal<>() {
@Override @Override
public void run(List<PlotComment> value) { public void run(List<PlotComment> value) {
@ -254,7 +253,8 @@ public class Inbox extends SubCommand {
return false; return false;
} }
return true; return true;
case "clear": }
case "clear" -> {
if (!inbox.canModify(plot, player)) { if (!inbox.canModify(plot, player)) {
player.sendMessage(TranslatableCaption.of("comment.no_perm_inbox_modify")); player.sendMessage(TranslatableCaption.of("comment.no_perm_inbox_modify"));
} }
@ -268,13 +268,15 @@ public class Inbox extends SubCommand {
plot.getPlotCommentContainer().removeComments(comments); plot.getPlotCommentContainer().removeComments(comments);
} }
return true; return true;
default: }
default -> {
try { try {
page = Integer.parseInt(args[1]); page = Integer.parseInt(args[1]);
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
sendUsage(player); sendUsage(player);
return false; return false;
} }
}
} }
} else { } else {
page = 1; page = 1;

View File

@ -90,12 +90,8 @@ public class Purge extends SubCommand {
return false; return false;
} }
switch (split[0].toLowerCase()) { switch (split[0].toLowerCase()) {
case "world": case "world", "w" -> world = split[1];
case "w": case "area", "a" -> {
world = split[1];
break;
case "area":
case "a":
area = this.plotAreaManager.getPlotAreaByString(split[1]); area = this.plotAreaManager.getPlotAreaByString(split[1]);
if (area == null) { if (area == null) {
player.sendMessage( player.sendMessage(
@ -104,9 +100,8 @@ public class Purge extends SubCommand {
); );
return false; return false;
} }
break; }
case "plotid": case "plotid", "id" -> {
case "id":
try { try {
id = PlotId.fromString(split[1]); id = PlotId.fromString(split[1]);
} catch (IllegalArgumentException ignored) { } catch (IllegalArgumentException ignored) {
@ -116,9 +111,8 @@ public class Purge extends SubCommand {
); );
return false; return false;
} }
break; }
case "owner": case "owner", "o" -> {
case "o":
UUIDMapping ownerMapping = PlotSquared.get().getImpromptuUUIDPipeline().getImmediately(split[1]); UUIDMapping ownerMapping = PlotSquared.get().getImpromptuUUIDPipeline().getImmediately(split[1]);
if (ownerMapping == null) { if (ownerMapping == null) {
player.sendMessage( player.sendMessage(
@ -128,9 +122,8 @@ public class Purge extends SubCommand {
return false; return false;
} }
owner = ownerMapping.uuid(); owner = ownerMapping.uuid();
break; }
case "shared": case "shared", "s" -> {
case "s":
UUIDMapping addedMapping = PlotSquared.get().getImpromptuUUIDPipeline().getImmediately(split[1]); UUIDMapping addedMapping = PlotSquared.get().getImpromptuUUIDPipeline().getImmediately(split[1]);
if (addedMapping == null) { if (addedMapping == null) {
player.sendMessage( player.sendMessage(
@ -140,22 +133,13 @@ public class Purge extends SubCommand {
return false; return false;
} }
added = addedMapping.uuid(); added = addedMapping.uuid();
break; }
case "clear": case "clear", "c", "delete", "d", "del" -> clear = Boolean.parseBoolean(split[1]);
case "c": case "unknown", "?", "u" -> unknown = Boolean.parseBoolean(split[1]);
case "delete": default -> {
case "d":
case "del":
clear = Boolean.parseBoolean(split[1]);
break;
case "unknown":
case "?":
case "u":
unknown = Boolean.parseBoolean(split[1]);
break;
default:
sendUsage(player); sendUsage(player);
return false; return false;
}
} }
} }
final HashSet<Plot> toDelete = new HashSet<>(); final HashSet<Plot> toDelete = new HashSet<>();
@ -236,9 +220,8 @@ public class Purge extends SubCommand {
try { try {
ids.add(plot.temp); ids.add(plot.temp);
if (finalClear) { if (finalClear) {
plot.getPlotModificationManager().clear(false, true, player, () -> { plot.getPlotModificationManager().clear(false, true, player,
LOGGER.info("Plot {} cleared by purge", plot.getId()); () -> LOGGER.info("Plot {} cleared by purge", plot.getId()));
});
} else { } else {
plot.getPlotModificationManager().removeSign(); plot.getPlotModificationManager().removeSign();
} }

View File

@ -185,30 +185,38 @@ public abstract class SquarePlotManager extends GridPlotManager {
return null; return null;
} }
switch (hash) { switch (hash) {
case 8: case 8 -> {
// north // north
return plot.isMerged(Direction.NORTH) ? id : null; return plot.isMerged(Direction.NORTH) ? id : null;
case 4: }
case 4 -> {
// east // east
return plot.isMerged(Direction.EAST) ? id : null; return plot.isMerged(Direction.EAST) ? id : null;
case 2: }
case 2 -> {
// south // south
return plot.isMerged(Direction.SOUTH) ? id : null; return plot.isMerged(Direction.SOUTH) ? id : null;
case 1: }
case 1 -> {
// west // west
return plot.isMerged(Direction.WEST) ? id : null; return plot.isMerged(Direction.WEST) ? id : null;
case 12: }
case 12 -> {
// northeast // northeast
return plot.isMerged(Direction.NORTHEAST) ? id : null; return plot.isMerged(Direction.NORTHEAST) ? id : null;
case 6: }
case 6 -> {
// southeast // southeast
return plot.isMerged(Direction.SOUTHEAST) ? id : null; return plot.isMerged(Direction.SOUTHEAST) ? id : null;
case 3: }
case 3 -> {
// southwest // southwest
return plot.isMerged(Direction.SOUTHWEST) ? id : null; return plot.isMerged(Direction.SOUTHWEST) ? id : null;
case 9: }
case 9 -> {
// northwest // northwest
return plot.isMerged(Direction.NORTHWEST) ? id : null; return plot.isMerged(Direction.NORTHWEST) ? id : null;
}
} }
} catch (Exception ignored) { } catch (Exception ignored) {
LOGGER.error("Invalid plot / road width in settings.yml for world: {}", squarePlotWorld.getWorldName()); LOGGER.error("Invalid plot / road width in settings.yml for world: {}", squarePlotWorld.getWorldName());

View File

@ -57,24 +57,15 @@ public class DenyTeleportFlag extends PlotFlag<DenyTeleportFlag.DeniedGroup, Den
} }
final boolean result; final boolean result;
switch (value) { switch (value) {
case TRUSTED: case TRUSTED -> result = !plot.getTrusted().contains(player.getUUID());
result = !plot.getTrusted().contains(player.getUUID()); case MEMBERS -> result = !plot.getMembers().contains(player.getUUID());
break; case NONMEMBERS -> result = plot.isAdded(player.getUUID());
case MEMBERS: case NONTRUSTED -> result =
result = !plot.getMembers().contains(player.getUUID()); plot.getTrusted().contains(player.getUUID()) || plot.isOwner(player.getUUID());
break; case NONOWNERS -> result = plot.isOwner(player.getUUID());
case NONMEMBERS: default -> {
result = plot.isAdded(player.getUUID());
break;
case NONTRUSTED:
result =
plot.getTrusted().contains(player.getUUID()) || plot.isOwner(player.getUUID());
break;
case NONOWNERS:
result = plot.isOwner(player.getUUID());
break;
default:
return true; return true;
}
} }
return result || player.hasPermission("plots.admin.entry.denied"); return result || player.hasPermission("plots.admin.entry.denied");
} }

View File

@ -68,14 +68,11 @@ public class FlyFlag extends PlotFlag<FlyFlag.FlyStatus, FlyFlag> {
@Override @Override
protected FlyFlag flagOf(final @NonNull FlyStatus value) { protected FlyFlag flagOf(final @NonNull FlyStatus value) {
switch (value) { return switch (value) {
case ENABLED: case ENABLED -> FLIGHT_FLAG_ENABLED;
return FLIGHT_FLAG_ENABLED; case DISABLED -> FLIGHT_FLAG_DISABLED;
case DISABLED: default -> FLIGHT_FLAG_DEFAULT;
return FLIGHT_FLAG_DISABLED; };
default:
return FLIGHT_FLAG_DEFAULT;
}
} }
@Override @Override

View File

@ -36,6 +36,7 @@ import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
/** /**
@ -92,11 +93,7 @@ public class DefaultProgressSubscriber implements ProgressSubscriber {
this.actor = actor; this.actor = actor;
this.interval = TaskTime.ms(interval); this.interval = TaskTime.ms(interval);
this.wait = TaskTime.ms(wait); this.wait = TaskTime.ms(wait);
if (caption == null) { this.caption = Objects.requireNonNullElseGet(caption, () -> TranslatableCaption.of("working.progress"));
this.caption = TranslatableCaption.of("working.progress");
} else {
this.caption = caption;
}
} }
@Override @Override

View File

@ -359,11 +359,13 @@ public class EventDispatcher {
} }
} }
switch (type) { switch (type) {
case TELEPORT_OBJECT: case TELEPORT_OBJECT -> {
return false; return false;
case READ: }
case READ -> {
return true; return true;
case INTERACT_BLOCK: { }
case INTERACT_BLOCK -> {
if (plot == null) { if (plot == null) {
final List<BlockTypeWrapper> use = area.getRoadFlag(UseFlag.class); final List<BlockTypeWrapper> use = area.getRoadFlag(UseFlag.class);
for (final BlockTypeWrapper blockTypeWrapper : use) { for (final BlockTypeWrapper blockTypeWrapper : use) {
@ -398,7 +400,7 @@ public class EventDispatcher {
} }
return false; return false;
} }
case TRIGGER_PHYSICAL: { case TRIGGER_PHYSICAL -> {
if (plot == null) { if (plot == null) {
final List<BlockTypeWrapper> use = area.getRoadFlag(UseFlag.class); final List<BlockTypeWrapper> use = area.getRoadFlag(UseFlag.class);
for (final BlockTypeWrapper blockTypeWrapper : use) { for (final BlockTypeWrapper blockTypeWrapper : use) {
@ -430,7 +432,7 @@ public class EventDispatcher {
false false
); );
} }
case SPAWN_MOB: { case SPAWN_MOB -> {
if (plot == null) { if (plot == null) {
return player.hasPermission( return player.hasPermission(
Permission.PERMISSION_ADMIN_INTERACT_ROAD.toString(), notifyPerms Permission.PERMISSION_ADMIN_INTERACT_ROAD.toString(), notifyPerms
@ -472,7 +474,7 @@ public class EventDispatcher {
} }
return false; return false;
} }
case PLACE_MISC: { case PLACE_MISC -> {
if (plot == null) { if (plot == null) {
return player.hasPermission( return player.hasPermission(
Permission.PERMISSION_ADMIN_INTERACT_ROAD.toString(), notifyPerms Permission.PERMISSION_ADMIN_INTERACT_ROAD.toString(), notifyPerms
@ -514,7 +516,7 @@ public class EventDispatcher {
} }
return false; return false;
} }
case PLACE_VEHICLE: case PLACE_VEHICLE -> {
if (plot == null) { if (plot == null) {
return player.hasPermission( return player.hasPermission(
Permission.PERMISSION_ADMIN_INTERACT_ROAD.toString(), notifyPerms Permission.PERMISSION_ADMIN_INTERACT_ROAD.toString(), notifyPerms
@ -526,8 +528,9 @@ public class EventDispatcher {
); );
} }
return plot.getFlag(VehiclePlaceFlag.class); return plot.getFlag(VehiclePlaceFlag.class);
default: }
break; default -> {
}
} }
return true; return true;
} }