Loads of minor code smell fixes
Mostly replacing instanceof check and cast with e.g. 'instanceof Player player' Replaced some "switch" statements by "if" statements to increase readability. Used the primitive boolean check to avoid potential NPEs. Reordered field modifiers to comply with the Java Language Specification. Mainly @NonNull position.
This commit is contained in:
parent
056cff4b6f
commit
872940011a
|
@ -17,8 +17,10 @@ import world.bentobox.bentobox.database.objects.Island;
|
|||
*/
|
||||
public class NamePrompt extends StringPrompt {
|
||||
|
||||
private @NonNull final Island island;
|
||||
private @NonNull final User user;
|
||||
@NonNull
|
||||
private final Island island;
|
||||
@NonNull
|
||||
private final User user;
|
||||
private final String oldName;
|
||||
private final BentoBox plugin;
|
||||
|
||||
|
@ -30,7 +32,8 @@ public class NamePrompt extends StringPrompt {
|
|||
}
|
||||
|
||||
@Override
|
||||
public @NonNull String getPromptText(@NonNull ConversationContext context) {
|
||||
@NonNull
|
||||
public String getPromptText(@NonNull ConversationContext context) {
|
||||
return user.getTranslation("commands.island.renamehome.enter-new-name");
|
||||
}
|
||||
|
||||
|
|
|
@ -53,8 +53,8 @@ public class Flag implements Comparable<Flag> {
|
|||
*/
|
||||
WORLD_SETTING(Material.GRASS_BLOCK);
|
||||
|
||||
private @NonNull
|
||||
final Material icon;
|
||||
@NonNull
|
||||
private final Material icon;
|
||||
|
||||
Type(@NonNull Material icon) {
|
||||
this.icon = icon;
|
||||
|
|
|
@ -95,8 +95,8 @@ public abstract class FlagListener implements Listener {
|
|||
* @param string - translation reference
|
||||
*/
|
||||
public void noGo(@NonNull Event e, @NonNull Flag flag, boolean silent, String string) {
|
||||
if (e instanceof Cancellable) {
|
||||
((Cancellable)e).setCancelled(true);
|
||||
if (e instanceof Cancellable cancellable) {
|
||||
cancellable.setCancelled(true);
|
||||
}
|
||||
if (user != null && !silent) {
|
||||
user.notify(string, TextVariables.DESCRIPTION, user.getTranslation(flag.getHintReference()));
|
||||
|
|
|
@ -36,22 +36,22 @@ public class MetaDataValue {
|
|||
* @param value the value assigned to this metadata value
|
||||
*/
|
||||
public MetaDataValue(@NonNull Object value) {
|
||||
if (value instanceof Integer) {
|
||||
intValue = (int)value;
|
||||
} else if (value instanceof Float) {
|
||||
floatValue = (float)value;
|
||||
} else if (value instanceof Double) {
|
||||
doubleValue = (double)value;
|
||||
} else if (value instanceof Long) {
|
||||
longValue = (long)value;
|
||||
} else if (value instanceof Short) {
|
||||
shortValue = (short)value;
|
||||
} else if (value instanceof Byte) {
|
||||
byteValue = (byte)value;
|
||||
} else if (value instanceof Boolean) {
|
||||
booleanValue = (boolean)value;
|
||||
} else if (value instanceof String) {
|
||||
stringValue = (String)value;
|
||||
if (value instanceof Integer i) {
|
||||
intValue = i;
|
||||
} else if (value instanceof Float f) {
|
||||
floatValue = f;
|
||||
} else if (value instanceof Double d) {
|
||||
doubleValue = d;
|
||||
} else if (value instanceof Long l) {
|
||||
longValue = l;
|
||||
} else if (value instanceof Short s) {
|
||||
shortValue = s;
|
||||
} else if (value instanceof Byte b) {
|
||||
byteValue = b;
|
||||
} else if (value instanceof Boolean bo) {
|
||||
booleanValue = bo;
|
||||
} else if (value instanceof String st) {
|
||||
stringValue = st;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,8 +31,8 @@ public class TabbedPanel extends Panel implements PanelListener {
|
|||
private static final String PROTECTION_PANEL = "protection.panel.";
|
||||
private static final long ITEMS_PER_PAGE = 36;
|
||||
private final TabbedPanelBuilder tpb;
|
||||
private @NonNull
|
||||
final BentoBox plugin = BentoBox.getInstance();
|
||||
@NonNull
|
||||
private final BentoBox plugin = BentoBox.getInstance();
|
||||
private int activeTab;
|
||||
private int activePage;
|
||||
private boolean closed;
|
||||
|
|
|
@ -290,14 +290,14 @@ public class BlueprintClipboard {
|
|||
if (entity instanceof Colorable c && c.getColor() != null) {
|
||||
bpe.setColor(c.getColor());
|
||||
}
|
||||
if (entity instanceof Tameable) {
|
||||
bpe.setTamed(((Tameable)entity).isTamed());
|
||||
if (entity instanceof Tameable tameable) {
|
||||
bpe.setTamed(tameable.isTamed());
|
||||
}
|
||||
if (entity instanceof ChestedHorse) {
|
||||
bpe.setChest(((ChestedHorse)entity).isCarryingChest());
|
||||
if (entity instanceof ChestedHorse chestedHorse) {
|
||||
bpe.setChest(chestedHorse.isCarryingChest());
|
||||
}
|
||||
// Only set if child. Most animals are adults
|
||||
if (entity instanceof Ageable && !((Ageable)entity).isAdult()) {
|
||||
if (entity instanceof Ageable ageable && !ageable.isAdult()) {
|
||||
bpe.setAdult(false);
|
||||
}
|
||||
if (entity instanceof AbstractHorse horse) {
|
||||
|
|
|
@ -36,7 +36,7 @@ public class FlagBooleanSerializer implements AdapterInterface<Map<String, Integ
|
|||
{
|
||||
for (Entry<String, Boolean> en : ((Map<String, Boolean>) object).entrySet())
|
||||
{
|
||||
result.put(en.getKey(), en.getValue() ? 0 : -1);
|
||||
result.put(en.getKey(), Boolean.TRUE.equals(en.getValue()) ? 0 : -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ public class FlagSerializer2 implements AdapterInterface<Map<Flag, Integer>, Map
|
|||
}
|
||||
} else {
|
||||
for (Entry<String, Boolean> en : ((Map<String, Boolean>)object).entrySet()) {
|
||||
BentoBox.getInstance().getFlagsManager().getFlag(en.getKey()).ifPresent(flag -> result.put(flag, en.getValue() ? 0 : -1));
|
||||
BentoBox.getInstance().getFlagsManager().getFlag(en.getKey()).ifPresent(flag -> result.put(flag, Boolean.TRUE.equals(en.getValue()) ? 0 : -1));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
|
|
@ -37,7 +37,7 @@ public class SQLConfiguration
|
|||
// Set the table name
|
||||
this.oldTableName = plugin.getSettings().getDatabasePrefix() + type.getCanonicalName();
|
||||
this.tableName = plugin.getSettings().getDatabasePrefix() +
|
||||
(type.getAnnotation(Table.class) == null ? type.getCanonicalName() : type.getAnnotation(Table.class).name());
|
||||
(type.getAnnotation(Table.class) == null ? type.getCanonicalName() : type.getAnnotation(Table.class).name());
|
||||
// Only rename if there is a specific Table annotation
|
||||
this.renameRequired = !this.tableName.equals(this.oldTableName);
|
||||
this.schema("CREATE TABLE IF NOT EXISTS `[tableName]` (json JSON, uniqueId VARCHAR(255) GENERATED ALWAYS AS (json->\"$.uniqueId\"), UNIQUE INDEX i (uniqueId) )");
|
||||
|
@ -47,17 +47,17 @@ public class SQLConfiguration
|
|||
this.deleteObject("DELETE FROM `[tableName]` WHERE uniqueId = ?");
|
||||
this.objectExists("SELECT IF ( EXISTS( SELECT * FROM `[tableName]` WHERE `uniqueId` = ?), 1, 0)");
|
||||
this.renameTable("SELECT Count(*) INTO @exists " +
|
||||
"FROM information_schema.tables " +
|
||||
"WHERE table_schema = '" + plugin.getSettings().getDatabaseName() + "' " +
|
||||
"AND table_type = 'BASE TABLE' " +
|
||||
"AND table_name = '[oldTableName]'; " +
|
||||
"SET @query = If(@exists=1,'RENAME TABLE `[oldTableName]` TO `[tableName]`','SELECT \\'nothing to rename\\' status'); " +
|
||||
"PREPARE stmt FROM @query;" +
|
||||
"EXECUTE stmt;");
|
||||
"FROM information_schema.tables " +
|
||||
"WHERE table_schema = '" + plugin.getSettings().getDatabaseName() + "' " +
|
||||
"AND table_type = 'BASE TABLE' " +
|
||||
"AND table_name = '[oldTableName]'; " +
|
||||
"SET @query = If(@exists=1,'RENAME TABLE `[oldTableName]` TO `[tableName]`','SELECT \\'nothing to rename\\' status'); " +
|
||||
"PREPARE stmt FROM @query;" +
|
||||
"EXECUTE stmt;");
|
||||
}
|
||||
|
||||
|
||||
private final String TABLE_NAME = "\\[tableName]";
|
||||
private static final String TABLE_NAME = "\\[tableName]";
|
||||
|
||||
/**
|
||||
* By default, use quotes around the unique ID in the SQL statement
|
||||
|
|
|
@ -25,8 +25,6 @@ import org.bukkit.configuration.InvalidConfigurationException;
|
|||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.database.DatabaseConnector;
|
||||
|
||||
|
@ -126,7 +124,7 @@ public class YamlDatabaseConnector implements DatabaseConnector {
|
|||
if (!tableFolder.exists()) {
|
||||
tableFolder.mkdirs();
|
||||
}
|
||||
try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), Charsets.UTF_8)) {
|
||||
try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) {
|
||||
writer.write(data);
|
||||
} catch (IOException e) {
|
||||
plugin.logError("Could not save yml file: " + tableName + " " + fileName + " " + e.getMessage());
|
||||
|
|
|
@ -316,9 +316,9 @@ public class YamlDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||
// There could be more than one argument, so step through them
|
||||
for (Type genericParameterType : genericParameterTypes) {
|
||||
// If the argument is a parameter, then do something - this should always be true if the parameter is a collection
|
||||
if(genericParameterType instanceof ParameterizedType ) {
|
||||
if(genericParameterType instanceof ParameterizedType pt) {
|
||||
// Get the actual type arguments of the parameter
|
||||
Type[] parameters = ((ParameterizedType)genericParameterType).getActualTypeArguments();
|
||||
Type[] parameters = pt.getActualTypeArguments();
|
||||
result.addAll(Arrays.asList(parameters));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -438,9 +438,9 @@ public class PortalTeleportationListener implements Listener {
|
|||
}
|
||||
}
|
||||
// From standard nether or end
|
||||
else if (e.getEntity() instanceof Player){
|
||||
else if (e.getEntity() instanceof Player player){
|
||||
e.setCancelled(true);
|
||||
plugin.getIslands().homeTeleportAsync(overWorld, (Player)e.getEntity());
|
||||
plugin.getIslands().homeTeleportAsync(overWorld, player);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,18 +35,18 @@ public class BlockInteractionListener extends FlagListener
|
|||
* These cover materials in another server version. This avoids run time errors due to unknown enum values, at the
|
||||
* expense of a string comparison
|
||||
*/
|
||||
private final static Map<String, String> stringFlags;
|
||||
private static final Map<String, String> stringFlags;
|
||||
|
||||
static
|
||||
{
|
||||
stringFlags = Map.of(
|
||||
"ACACIA_CHEST_BOAT", "CHEST",
|
||||
"BIRCH_CHEST_BOAT", "CHEST",
|
||||
"JUNGLE_CHEST_BOAT", "CHEST",
|
||||
"DARK_OAK_CHEST_BOAT", "CHEST",
|
||||
"MANGROVE_CHEST_BOAT", "CHEST",
|
||||
"OAK_CHEST_BOAT", "CHEST",
|
||||
"SPRUCE_CHEST_BOAT", "CHEST");
|
||||
"ACACIA_CHEST_BOAT", "CHEST",
|
||||
"BIRCH_CHEST_BOAT", "CHEST",
|
||||
"JUNGLE_CHEST_BOAT", "CHEST",
|
||||
"DARK_OAK_CHEST_BOAT", "CHEST",
|
||||
"MANGROVE_CHEST_BOAT", "CHEST",
|
||||
"OAK_CHEST_BOAT", "CHEST",
|
||||
"SPRUCE_CHEST_BOAT", "CHEST");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -92,7 +92,7 @@ public class BlockInteractionListener extends FlagListener
|
|||
|
||||
// Check if player is clicking on water or waterlogged block with a bottle.
|
||||
if (targetedBlock != null && (Material.WATER.equals(targetedBlock.getType()) ||
|
||||
targetedBlock.getBlockData() instanceof Waterlogged))
|
||||
targetedBlock.getBlockData() instanceof Waterlogged))
|
||||
{
|
||||
this.checkIsland(e, e.getPlayer(), e.getClickedBlock().getLocation(), Flags.BREWING);
|
||||
}
|
||||
|
@ -165,79 +165,79 @@ public class BlockInteractionListener extends FlagListener
|
|||
|
||||
switch (type)
|
||||
{
|
||||
case BEACON -> this.checkIsland(e, player, loc, Flags.BEACON);
|
||||
case BREWING_STAND -> this.checkIsland(e, player, loc, Flags.BREWING);
|
||||
case BEEHIVE, BEE_NEST -> this.checkIsland(e, player, loc, Flags.HIVE);
|
||||
case BARREL -> this.checkIsland(e, player, loc, Flags.BARREL);
|
||||
case CHEST, CHEST_MINECART -> this.checkIsland(e, player, loc, Flags.CHEST);
|
||||
case TRAPPED_CHEST -> this.checkIsland(e, player, loc, Flags.TRAPPED_CHEST);
|
||||
case FLOWER_POT -> this.checkIsland(e, player, loc, Flags.FLOWER_POT);
|
||||
case COMPOSTER -> this.checkIsland(e, player, loc, Flags.COMPOSTER);
|
||||
case DISPENSER -> this.checkIsland(e, player, loc, Flags.DISPENSER);
|
||||
case DROPPER -> this.checkIsland(e, player, loc, Flags.DROPPER);
|
||||
case HOPPER, HOPPER_MINECART -> this.checkIsland(e, player, loc, Flags.HOPPER);
|
||||
case BLAST_FURNACE, CAMPFIRE, FURNACE_MINECART, FURNACE, SMOKER ->
|
||||
this.checkIsland(e, player, loc, Flags.FURNACE);
|
||||
case ENCHANTING_TABLE -> this.checkIsland(e, player, loc, Flags.ENCHANTING);
|
||||
case ENDER_CHEST -> this.checkIsland(e, player, loc, Flags.ENDER_CHEST);
|
||||
case JUKEBOX -> this.checkIsland(e, player, loc, Flags.JUKEBOX);
|
||||
case NOTE_BLOCK -> this.checkIsland(e, player, loc, Flags.NOTE_BLOCK);
|
||||
case CRAFTING_TABLE, CARTOGRAPHY_TABLE, GRINDSTONE, STONECUTTER, LOOM ->
|
||||
this.checkIsland(e, player, loc, Flags.CRAFTING);
|
||||
case LEVER -> this.checkIsland(e, player, loc, Flags.LEVER);
|
||||
case REDSTONE_WIRE, REPEATER, COMPARATOR, DAYLIGHT_DETECTOR -> this.checkIsland(e, player, loc, Flags.REDSTONE);
|
||||
case DRAGON_EGG -> this.checkIsland(e, player, loc, Flags.DRAGON_EGG);
|
||||
case END_PORTAL_FRAME, RESPAWN_ANCHOR -> this.checkIsland(e, player, loc, Flags.PLACE_BLOCKS);
|
||||
case GLOW_ITEM_FRAME, ITEM_FRAME -> this.checkIsland(e, player, loc, Flags.ITEM_FRAME);
|
||||
case SWEET_BERRY_BUSH, CAVE_VINES -> this.checkIsland(e, player, loc, Flags.BREAK_BLOCKS);
|
||||
case CAKE -> this.checkIsland(e, player, loc, Flags.CAKE);
|
||||
case LAVA_CAULDRON ->
|
||||
case BEACON -> this.checkIsland(e, player, loc, Flags.BEACON);
|
||||
case BREWING_STAND -> this.checkIsland(e, player, loc, Flags.BREWING);
|
||||
case BEEHIVE, BEE_NEST -> this.checkIsland(e, player, loc, Flags.HIVE);
|
||||
case BARREL -> this.checkIsland(e, player, loc, Flags.BARREL);
|
||||
case CHEST, CHEST_MINECART -> this.checkIsland(e, player, loc, Flags.CHEST);
|
||||
case TRAPPED_CHEST -> this.checkIsland(e, player, loc, Flags.TRAPPED_CHEST);
|
||||
case FLOWER_POT -> this.checkIsland(e, player, loc, Flags.FLOWER_POT);
|
||||
case COMPOSTER -> this.checkIsland(e, player, loc, Flags.COMPOSTER);
|
||||
case DISPENSER -> this.checkIsland(e, player, loc, Flags.DISPENSER);
|
||||
case DROPPER -> this.checkIsland(e, player, loc, Flags.DROPPER);
|
||||
case HOPPER, HOPPER_MINECART -> this.checkIsland(e, player, loc, Flags.HOPPER);
|
||||
case BLAST_FURNACE, CAMPFIRE, FURNACE_MINECART, FURNACE, SMOKER ->
|
||||
this.checkIsland(e, player, loc, Flags.FURNACE);
|
||||
case ENCHANTING_TABLE -> this.checkIsland(e, player, loc, Flags.ENCHANTING);
|
||||
case ENDER_CHEST -> this.checkIsland(e, player, loc, Flags.ENDER_CHEST);
|
||||
case JUKEBOX -> this.checkIsland(e, player, loc, Flags.JUKEBOX);
|
||||
case NOTE_BLOCK -> this.checkIsland(e, player, loc, Flags.NOTE_BLOCK);
|
||||
case CRAFTING_TABLE, CARTOGRAPHY_TABLE, GRINDSTONE, STONECUTTER, LOOM ->
|
||||
this.checkIsland(e, player, loc, Flags.CRAFTING);
|
||||
case LEVER -> this.checkIsland(e, player, loc, Flags.LEVER);
|
||||
case REDSTONE_WIRE, REPEATER, COMPARATOR, DAYLIGHT_DETECTOR -> this.checkIsland(e, player, loc, Flags.REDSTONE);
|
||||
case DRAGON_EGG -> this.checkIsland(e, player, loc, Flags.DRAGON_EGG);
|
||||
case END_PORTAL_FRAME, RESPAWN_ANCHOR -> this.checkIsland(e, player, loc, Flags.PLACE_BLOCKS);
|
||||
case GLOW_ITEM_FRAME, ITEM_FRAME -> this.checkIsland(e, player, loc, Flags.ITEM_FRAME);
|
||||
case SWEET_BERRY_BUSH, CAVE_VINES -> this.checkIsland(e, player, loc, Flags.BREAK_BLOCKS);
|
||||
case CAKE -> this.checkIsland(e, player, loc, Flags.CAKE);
|
||||
case LAVA_CAULDRON ->
|
||||
{
|
||||
if (BlockInteractionListener.holds(player, Material.BUCKET))
|
||||
{
|
||||
if (BlockInteractionListener.holds(player, Material.BUCKET))
|
||||
{
|
||||
this.checkIsland(e, player, loc, Flags.COLLECT_LAVA);
|
||||
}
|
||||
this.checkIsland(e, player, loc, Flags.COLLECT_LAVA);
|
||||
}
|
||||
case WATER_CAULDRON ->
|
||||
}
|
||||
case WATER_CAULDRON ->
|
||||
{
|
||||
if (BlockInteractionListener.holds(player, Material.BUCKET))
|
||||
{
|
||||
if (BlockInteractionListener.holds(player, Material.BUCKET))
|
||||
{
|
||||
this.checkIsland(e, player, loc, Flags.COLLECT_WATER);
|
||||
}
|
||||
else if (BlockInteractionListener.holds(player, Material.GLASS_BOTTLE) ||
|
||||
this.checkIsland(e, player, loc, Flags.COLLECT_WATER);
|
||||
}
|
||||
else if (BlockInteractionListener.holds(player, Material.GLASS_BOTTLE) ||
|
||||
BlockInteractionListener.holds(player, Material.POTION))
|
||||
{
|
||||
this.checkIsland(e, player, loc, Flags.BREWING);
|
||||
}
|
||||
}
|
||||
case POWDER_SNOW_CAULDRON ->
|
||||
{
|
||||
if (BlockInteractionListener.holds(player, Material.BUCKET))
|
||||
{
|
||||
this.checkIsland(e, player, loc, Flags.COLLECT_POWDERED_SNOW);
|
||||
}
|
||||
this.checkIsland(e, player, loc, Flags.BREWING);
|
||||
}
|
||||
case CAULDRON ->
|
||||
}
|
||||
case POWDER_SNOW_CAULDRON ->
|
||||
{
|
||||
if (BlockInteractionListener.holds(player, Material.BUCKET))
|
||||
{
|
||||
if (BlockInteractionListener.holds(player, Material.WATER_BUCKET) ||
|
||||
this.checkIsland(e, player, loc, Flags.COLLECT_POWDERED_SNOW);
|
||||
}
|
||||
}
|
||||
case CAULDRON ->
|
||||
{
|
||||
if (BlockInteractionListener.holds(player, Material.WATER_BUCKET) ||
|
||||
BlockInteractionListener.holds(player, Material.LAVA_BUCKET) ||
|
||||
BlockInteractionListener.holds(player, Material.POWDER_SNOW_BUCKET))
|
||||
{
|
||||
this.checkIsland(e, player, loc, Flags.BUCKET);
|
||||
}
|
||||
else if (BlockInteractionListener.holds(player, Material.POTION))
|
||||
{
|
||||
this.checkIsland(e, player, loc, Flags.BREWING);
|
||||
}
|
||||
}
|
||||
default ->
|
||||
{
|
||||
if (stringFlags.containsKey(type.name()))
|
||||
{
|
||||
Optional<Flag> f = BentoBox.getInstance().getFlagsManager().getFlag(stringFlags.get(type.name()));
|
||||
f.ifPresent(flag -> this.checkIsland(e, player, loc, flag));
|
||||
}
|
||||
this.checkIsland(e, player, loc, Flags.BUCKET);
|
||||
}
|
||||
else if (BlockInteractionListener.holds(player, Material.POTION))
|
||||
{
|
||||
this.checkIsland(e, player, loc, Flags.BREWING);
|
||||
}
|
||||
}
|
||||
default ->
|
||||
{
|
||||
if (stringFlags.containsKey(type.name()))
|
||||
{
|
||||
Optional<Flag> f = BentoBox.getInstance().getFlagsManager().getFlag(stringFlags.get(type.name()));
|
||||
f.ifPresent(flag -> this.checkIsland(e, player, loc, flag));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -291,6 +291,6 @@ public class BlockInteractionListener extends FlagListener
|
|||
private static boolean holds(Player player, Material material)
|
||||
{
|
||||
return player.getInventory().getItemInMainHand().getType().equals(material) ||
|
||||
player.getInventory().getItemInOffHand().getType().equals(material);
|
||||
player.getInventory().getItemInOffHand().getType().equals(material);
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@ package world.bentobox.bentobox.listeners.flags.protection;
|
|||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -36,7 +36,7 @@ public class BreedingListener extends FlagListener {
|
|||
*/
|
||||
private static final Map<EntityType, List<Material>> BREEDING_ITEMS;
|
||||
static {
|
||||
Map<EntityType, List<Material>> bi = new HashMap<>();
|
||||
Map<EntityType, List<Material>> bi = new EnumMap<>(EntityType.class);
|
||||
|
||||
bi.put(EntityType.HORSE, Arrays.asList(Material.GOLDEN_APPLE, Material.GOLDEN_CARROT));
|
||||
bi.put(EntityType.DONKEY, Arrays.asList(Material.GOLDEN_APPLE, Material.GOLDEN_CARROT));
|
||||
|
@ -58,9 +58,9 @@ public class BreedingListener extends FlagListener {
|
|||
bi.put(EntityType.FOX, Collections.singletonList(Material.SWEET_BERRIES));
|
||||
// 1.15+
|
||||
bi.put(EntityType.BEE, Arrays.asList(Material.SUNFLOWER, Material.ORANGE_TULIP, Material.PINK_TULIP,
|
||||
Material.RED_TULIP, Material.WHITE_TULIP, Material.ALLIUM,
|
||||
Material.AZURE_BLUET, Material.BLUE_ORCHID, Material.CORNFLOWER,
|
||||
Material.DANDELION, Material.OXEYE_DAISY, Material.PEONY, Material.POPPY));
|
||||
Material.RED_TULIP, Material.WHITE_TULIP, Material.ALLIUM,
|
||||
Material.AZURE_BLUET, Material.BLUE_ORCHID, Material.CORNFLOWER,
|
||||
Material.DANDELION, Material.OXEYE_DAISY, Material.PEONY, Material.POPPY));
|
||||
// 1.16+
|
||||
bi.put(EntityType.HOGLIN, Collections.singletonList(Material.CRIMSON_FUNGUS));
|
||||
bi.put(EntityType.STRIDER, Collections.singletonList(Material.WARPED_FUNGUS));
|
||||
|
|
|
@ -74,10 +74,10 @@ public class HurtingListener extends FlagListener {
|
|||
*/
|
||||
private void respond(EntityDamageByEntityEvent e, Entity damager, Flag flag) {
|
||||
// Get the attacker
|
||||
if (damager instanceof Player) {
|
||||
checkIsland(e, (Player)damager, damager.getLocation(), flag);
|
||||
if (damager instanceof Player player) {
|
||||
checkIsland(e, player, player.getLocation(), flag);
|
||||
} else if (damager instanceof Projectile p && // Find out who fired the projectile
|
||||
p.getShooter() instanceof Player player && !checkIsland(e, player, damager.getLocation(), flag)) {
|
||||
p.getShooter() instanceof Player player && !checkIsland(e, player, player.getLocation(), flag)) {
|
||||
e.getEntity().setFireTicks(0);
|
||||
}
|
||||
}
|
||||
|
@ -164,9 +164,9 @@ public class HurtingListener extends FlagListener {
|
|||
public void onLingeringPotionSplash(final LingeringPotionSplashEvent e) {
|
||||
// Try to get the shooter
|
||||
Projectile projectile = e.getEntity();
|
||||
if (projectile.getShooter() instanceof Player) {
|
||||
if (projectile.getShooter() instanceof Player player) {
|
||||
// Store it and remove it when the effect is gone
|
||||
thrownPotions.put(e.getAreaEffectCloud().getEntityId(), (Player)projectile.getShooter());
|
||||
thrownPotions.put(e.getAreaEffectCloud().getEntityId(), player);
|
||||
getPlugin().getServer().getScheduler().runTaskLater(getPlugin(), () -> thrownPotions.remove(e.getAreaEffectCloud().getEntityId()), e.getAreaEffectCloud().getDuration());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,8 +27,8 @@ public class ItemDropPickUpListener extends FlagListener {
|
|||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onPickup(EntityPickupItemEvent e) {
|
||||
if (e.getEntity() instanceof Player) {
|
||||
checkIsland(e, (Player)e.getEntity(), e.getItem().getLocation(), Flags.ITEM_PICKUP);
|
||||
if (e.getEntity() instanceof Player player) {
|
||||
checkIsland(e, player, e.getItem().getLocation(), Flags.ITEM_PICKUP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ public class LockAndBanListener extends FlagListener {
|
|||
return;
|
||||
}
|
||||
// For each Player in the vehicle
|
||||
e.getVehicle().getPassengers().stream().filter(en -> en instanceof Player).map(en -> (Player)en).forEach(p -> {
|
||||
e.getVehicle().getPassengers().stream().filter(Player.class::isInstance).map(Player.class::cast).forEach(p -> {
|
||||
if (!checkAndNotify(p, e.getTo()).equals(CheckResult.OPEN)) {
|
||||
p.leaveVehicle();
|
||||
p.teleport(e.getFrom());
|
||||
|
@ -114,21 +114,21 @@ public class LockAndBanListener extends FlagListener {
|
|||
|
||||
// See if the island is locked to non-members or player is banned
|
||||
return this.getIslands().getProtectedIslandAt(loc).
|
||||
map(is ->
|
||||
{
|
||||
if (is.isBanned(player.getUniqueId()))
|
||||
map(is ->
|
||||
{
|
||||
return player.hasPermission(getIWM().getPermissionPrefix(loc.getWorld()) + "mod.bypassban") ?
|
||||
CheckResult.OPEN : CheckResult.BANNED;
|
||||
}
|
||||
if (!is.isAllowed(User.getInstance(player), Flags.LOCK))
|
||||
{
|
||||
return player.hasPermission(getIWM().getPermissionPrefix(loc.getWorld()) + "mod.bypasslock") ?
|
||||
CheckResult.OPEN : CheckResult.LOCKED;
|
||||
}
|
||||
return CheckResult.OPEN;
|
||||
}).
|
||||
orElse(CheckResult.OPEN);
|
||||
if (is.isBanned(player.getUniqueId()))
|
||||
{
|
||||
return player.hasPermission(getIWM().getPermissionPrefix(loc.getWorld()) + "mod.bypassban") ?
|
||||
CheckResult.OPEN : CheckResult.BANNED;
|
||||
}
|
||||
if (!is.isAllowed(User.getInstance(player), Flags.LOCK))
|
||||
{
|
||||
return player.hasPermission(getIWM().getPermissionPrefix(loc.getWorld()) + "mod.bypasslock") ?
|
||||
CheckResult.OPEN : CheckResult.LOCKED;
|
||||
}
|
||||
return CheckResult.OPEN;
|
||||
}).
|
||||
orElse(CheckResult.OPEN);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -140,13 +140,11 @@ public class LockAndBanListener extends FlagListener {
|
|||
private CheckResult checkAndNotify(@NonNull Player player, Location loc)
|
||||
{
|
||||
CheckResult result = this.check(player, loc);
|
||||
|
||||
switch (result)
|
||||
{
|
||||
case BANNED -> User.getInstance(player).notify("commands.island.ban.you-are-banned");
|
||||
case LOCKED -> User.getInstance(player).notify("protection.locked");
|
||||
if (result == CheckResult.BANNED) {
|
||||
User.getInstance(player).notify("commands.island.ban.you-are-banned");
|
||||
} else if (result == CheckResult.LOCKED) {
|
||||
User.getInstance(player).notify("protection.locked");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package world.bentobox.bentobox.listeners.flags.protection;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
|
@ -38,11 +39,10 @@ public class PhysicalInteractionListener extends FlagListener
|
|||
this.checkIsland(e, e.getPlayer(), e.getPlayer().getLocation(), Flags.PRESSURE_PLATE);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (e.getClickedBlock().getType())
|
||||
{
|
||||
case FARMLAND -> this.checkIsland(e, e.getPlayer(), e.getPlayer().getLocation(), Flags.CROP_TRAMPLE);
|
||||
case TURTLE_EGG -> this.checkIsland(e, e.getPlayer(), e.getPlayer().getLocation(), Flags.TURTLE_EGGS);
|
||||
if (e.getClickedBlock().getType() == Material.FARMLAND) {
|
||||
this.checkIsland(e, e.getPlayer(), e.getPlayer().getLocation(), Flags.CROP_TRAMPLE);
|
||||
} else if (e.getClickedBlock().getType() == Material.TURTLE_EGG) {
|
||||
this.checkIsland(e, e.getPlayer(), e.getPlayer().getLocation(), Flags.TURTLE_EGGS);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,18 +59,18 @@ public class PhysicalInteractionListener extends FlagListener
|
|||
return;
|
||||
}
|
||||
|
||||
if (p.getShooter() instanceof Player)
|
||||
if (p.getShooter() instanceof Player player)
|
||||
{
|
||||
if (Tag.WOODEN_BUTTONS.isTagged(e.getBlock().getType()))
|
||||
{
|
||||
this.checkIsland(e, (Player) p.getShooter(), e.getBlock().getLocation(), Flags.BUTTON);
|
||||
this.checkIsland(e, player, e.getBlock().getLocation(), Flags.BUTTON);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Tag.PRESSURE_PLATES.isTagged(e.getBlock().getType()))
|
||||
{
|
||||
// Pressure plates
|
||||
this.checkIsland(e, (Player) p.getShooter(), e.getBlock().getLocation(), Flags.PRESSURE_PLATE);
|
||||
this.checkIsland(e, player, e.getBlock().getLocation(), Flags.PRESSURE_PLATE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,9 +29,9 @@ public class PlaceBlocksListener extends FlagListener
|
|||
public void onBlockPlace(final BlockPlaceEvent e)
|
||||
{
|
||||
if (e.getBlock().getType().equals(Material.FIRE) ||
|
||||
e.getItemInHand() == null || // Note that this should never happen officially, but it's possible for other plugins to cause it to happen
|
||||
e.getItemInHand().getType().equals(Material.WRITABLE_BOOK) ||
|
||||
e.getItemInHand().getType().equals(Material.WRITTEN_BOOK))
|
||||
e.getItemInHand() == null || // Note that this should never happen officially, but it's possible for other plugins to cause it to happen
|
||||
e.getItemInHand().getType().equals(Material.WRITABLE_BOOK) ||
|
||||
e.getItemInHand().getType().equals(Material.WRITTEN_BOOK))
|
||||
{
|
||||
// Books can only be placed on lecterns and as such are protected by the LECTERN flag.
|
||||
return;
|
||||
|
@ -62,7 +62,7 @@ public class PlaceBlocksListener extends FlagListener
|
|||
public void onPlayerHitItemFrame(PlayerInteractEntityEvent e)
|
||||
{
|
||||
if (e.getRightClicked().getType().equals(EntityType.ITEM_FRAME) ||
|
||||
e.getRightClicked().getType().equals(EntityType.GLOW_ITEM_FRAME))
|
||||
e.getRightClicked().getType().equals(EntityType.GLOW_ITEM_FRAME))
|
||||
{
|
||||
if (!this.checkIsland(e, e.getPlayer(), e.getRightClicked().getLocation(), Flags.PLACE_BLOCKS))
|
||||
{
|
||||
|
@ -90,36 +90,36 @@ public class PlaceBlocksListener extends FlagListener
|
|||
|
||||
switch (e.getClickedBlock().getType())
|
||||
{
|
||||
case FIREWORK_ROCKET -> this.checkIsland(e, e.getPlayer(), e.getClickedBlock().getLocation(), Flags.PLACE_BLOCKS);
|
||||
case RAIL, POWERED_RAIL, DETECTOR_RAIL, ACTIVATOR_RAIL ->
|
||||
{
|
||||
if (e.getMaterial() == Material.MINECART ||
|
||||
case FIREWORK_ROCKET -> this.checkIsland(e, e.getPlayer(), e.getClickedBlock().getLocation(), Flags.PLACE_BLOCKS);
|
||||
case RAIL, POWERED_RAIL, DETECTOR_RAIL, ACTIVATOR_RAIL ->
|
||||
{
|
||||
if (e.getMaterial() == Material.MINECART ||
|
||||
e.getMaterial() == Material.CHEST_MINECART ||
|
||||
e.getMaterial() == Material.HOPPER_MINECART ||
|
||||
e.getMaterial() == Material.TNT_MINECART ||
|
||||
e.getMaterial() == Material.FURNACE_MINECART)
|
||||
{
|
||||
this.checkIsland(e, e.getPlayer(), e.getClickedBlock().getLocation(), Flags.MINECART);
|
||||
}
|
||||
}
|
||||
default ->
|
||||
{
|
||||
// Check in-hand items
|
||||
if (e.getMaterial() == Material.FIREWORK_ROCKET ||
|
||||
this.checkIsland(e, e.getPlayer(), e.getClickedBlock().getLocation(), Flags.MINECART);
|
||||
}
|
||||
}
|
||||
default ->
|
||||
{
|
||||
// Check in-hand items
|
||||
if (e.getMaterial() == Material.FIREWORK_ROCKET ||
|
||||
e.getMaterial() == Material.ARMOR_STAND ||
|
||||
e.getMaterial() == Material.END_CRYSTAL ||
|
||||
e.getMaterial() == Material.ITEM_FRAME ||
|
||||
e.getMaterial() == Material.GLOW_ITEM_FRAME ||
|
||||
e.getMaterial() == Material.CHEST ||
|
||||
e.getMaterial() == Material.TRAPPED_CHEST)
|
||||
{
|
||||
this.checkIsland(e, e.getPlayer(), e.getPlayer().getLocation(), Flags.PLACE_BLOCKS);
|
||||
}
|
||||
else if (e.getMaterial().name().contains("BOAT"))
|
||||
{
|
||||
this.checkIsland(e, e.getPlayer(), e.getPlayer().getLocation(), Flags.BOAT);
|
||||
}
|
||||
{
|
||||
this.checkIsland(e, e.getPlayer(), e.getPlayer().getLocation(), Flags.PLACE_BLOCKS);
|
||||
}
|
||||
else if (e.getMaterial().name().contains("BOAT"))
|
||||
{
|
||||
this.checkIsland(e, e.getPlayer(), e.getPlayer().getLocation(), Flags.BOAT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,9 +132,9 @@ public class PlaceBlocksListener extends FlagListener
|
|||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onBlockForm(EntityBlockFormEvent e)
|
||||
{
|
||||
if (e.getNewState().getType().equals(Material.FROSTED_ICE) && e.getEntity() instanceof Player)
|
||||
if (e.getNewState().getType().equals(Material.FROSTED_ICE) && e.getEntity() instanceof Player player)
|
||||
{
|
||||
this.checkIsland(e, (Player) e.getEntity(), e.getBlock().getLocation(), Flags.FROST_WALKER);
|
||||
this.checkIsland(e, player, e.getBlock().getLocation(), Flags.FROST_WALKER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,11 +23,11 @@ public class ThrowingListener extends FlagListener {
|
|||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onPlayerThrowPotion(ProjectileLaunchEvent e) {
|
||||
if (e.getEntity().getShooter() instanceof Player && (e.getEntity() instanceof ThrownPotion)) {
|
||||
if (e.getEntity().getShooter() instanceof Player player && (e.getEntity() instanceof ThrownPotion)) {
|
||||
if (e.getEntity() instanceof ThrownPotion) {
|
||||
checkIsland(e, (Player) e.getEntity().getShooter(), e.getEntity().getLocation(), Flags.POTION_THROWING);
|
||||
checkIsland(e, player, e.getEntity().getLocation(), Flags.POTION_THROWING);
|
||||
} else if (e.getEntity() instanceof ThrownExpBottle) {
|
||||
checkIsland(e, (Player) e.getEntity().getShooter(), e.getEntity().getLocation(), Flags.EXPERIENCE_BOTTLE_THROWING);
|
||||
checkIsland(e, player, e.getEntity().getLocation(), Flags.EXPERIENCE_BOTTLE_THROWING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,8 +51,8 @@ public class MobSpawnListener extends FlagListener
|
|||
|
||||
Optional<Island> island = getIslands().getIslandAt(event.getPlayer().getLocation());
|
||||
|
||||
if (island.map(i -> !i.isAllowed(Flags.MONSTER_NATURAL_SPAWN)).orElseGet(
|
||||
() -> !Flags.MONSTER_NATURAL_SPAWN.isSetForWorld(event.getWorld())))
|
||||
if (Boolean.TRUE.equals(island.map(i -> !i.isAllowed(Flags.MONSTER_NATURAL_SPAWN)).orElseGet(
|
||||
() -> !Flags.MONSTER_NATURAL_SPAWN.isSetForWorld(event.getWorld()))))
|
||||
{
|
||||
// Monster spawning is disabled on island or world. Cancel the raid.
|
||||
event.setCancelled(true);
|
||||
|
@ -75,8 +75,8 @@ public class MobSpawnListener extends FlagListener
|
|||
|
||||
Optional<Island> island = getIslands().getIslandAt(event.getRaid().getLocation());
|
||||
|
||||
if (island.map(i -> !i.isAllowed(Flags.MONSTER_NATURAL_SPAWN)).orElseGet(
|
||||
() -> !Flags.MONSTER_NATURAL_SPAWN.isSetForWorld(event.getWorld())))
|
||||
if (Boolean.TRUE.equals(island.map(i -> !i.isAllowed(Flags.MONSTER_NATURAL_SPAWN)).orElseGet(
|
||||
() -> !Flags.MONSTER_NATURAL_SPAWN.isSetForWorld(event.getWorld()))))
|
||||
{
|
||||
// CHEATERS. PUNISH THEM.
|
||||
event.getWinners().forEach(player ->
|
||||
|
@ -104,25 +104,28 @@ public class MobSpawnListener extends FlagListener
|
|||
|
||||
switch (e.getSpawnReason())
|
||||
{
|
||||
// Natural
|
||||
case DEFAULT, DROWNED, JOCKEY, LIGHTNING, MOUNT, NATURAL, NETHER_PORTAL, OCELOT_BABY, PATROL,
|
||||
RAID, REINFORCEMENTS, SILVERFISH_BLOCK, TRAP, VILLAGE_DEFENSE, VILLAGE_INVASION ->
|
||||
{
|
||||
boolean cancelNatural = this.shouldCancel(e.getEntity(),
|
||||
// Natural
|
||||
case DEFAULT, DROWNED, JOCKEY, LIGHTNING, MOUNT, NATURAL, NETHER_PORTAL, OCELOT_BABY, PATROL,
|
||||
RAID, REINFORCEMENTS, SILVERFISH_BLOCK, TRAP, VILLAGE_DEFENSE, VILLAGE_INVASION ->
|
||||
{
|
||||
boolean cancelNatural = this.shouldCancel(e.getEntity(),
|
||||
e.getLocation(),
|
||||
Flags.ANIMAL_NATURAL_SPAWN,
|
||||
Flags.MONSTER_NATURAL_SPAWN);
|
||||
e.setCancelled(cancelNatural);
|
||||
}
|
||||
// Spawners
|
||||
case SPAWNER ->
|
||||
{
|
||||
boolean cancelSpawners = this.shouldCancel(e.getEntity(),
|
||||
e.setCancelled(cancelNatural);
|
||||
}
|
||||
// Spawners
|
||||
case SPAWNER ->
|
||||
{
|
||||
boolean cancelSpawners = this.shouldCancel(e.getEntity(),
|
||||
e.getLocation(),
|
||||
Flags.ANIMAL_SPAWNERS_SPAWN,
|
||||
Flags.MONSTER_SPAWNERS_SPAWN);
|
||||
e.setCancelled(cancelSpawners);
|
||||
}
|
||||
e.setCancelled(cancelSpawners);
|
||||
}
|
||||
default -> {
|
||||
// Nothing to do
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,12 +145,12 @@ public class MobSpawnListener extends FlagListener
|
|||
if (Util.isHostileEntity(entity) && !(entity instanceof PufferFish))
|
||||
{
|
||||
return island.map(i -> !i.isAllowed(monsterSpawnFlag)).
|
||||
orElseGet(() -> !monsterSpawnFlag.isSetForWorld(entity.getWorld()));
|
||||
orElseGet(() -> !monsterSpawnFlag.isSetForWorld(entity.getWorld()));
|
||||
}
|
||||
else if (Util.isPassiveEntity(entity) || entity instanceof PufferFish)
|
||||
{
|
||||
return island.map(i -> !i.isAllowed(animalSpawnFlag)).
|
||||
orElseGet(() -> !animalSpawnFlag.isSetForWorld(entity.getWorld()));
|
||||
orElseGet(() -> !animalSpawnFlag.isSetForWorld(entity.getWorld()));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -84,13 +84,13 @@ public class PVPListener extends FlagListener {
|
|||
*/
|
||||
private void respond(Cancellable e, Entity damager, Entity hurtEntity, Flag flag) {
|
||||
// Get the attacker
|
||||
if (damager instanceof Player) {
|
||||
if (damager instanceof Player player) {
|
||||
User user = User.getInstance(damager);
|
||||
if (!checkIsland((Event)e, (Player)damager, damager.getLocation(), flag)) {
|
||||
user.notify(getFlag(damager.getWorld()).getHintReference());
|
||||
if (!checkIsland((Event)e, player, player.getLocation(), flag)) {
|
||||
user.notify(getFlag(player.getWorld()).getHintReference());
|
||||
e.setCancelled(true);
|
||||
}
|
||||
} else if (damager instanceof Projectile p && ((Projectile)damager).getShooter() instanceof Player shooter) {
|
||||
} else if (damager instanceof Projectile && ((Projectile)damager).getShooter() instanceof Player shooter) {
|
||||
// Find out who fired the arrow
|
||||
processDamage(e, damager, shooter, hurtEntity, flag);
|
||||
} else if (damager instanceof Firework && firedFireworks.containsKey(damager)) {
|
||||
|
@ -194,9 +194,9 @@ public class PVPListener extends FlagListener {
|
|||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
|
||||
public void onLingeringPotionSplash(final LingeringPotionSplashEvent e) {
|
||||
// Try to get the shooter
|
||||
if (e.getEntity().getShooter() instanceof Player && getPlugin().getIWM().inWorld(e.getEntity().getWorld())) {
|
||||
if (e.getEntity().getShooter() instanceof Player player && getPlugin().getIWM().inWorld(e.getEntity().getWorld())) {
|
||||
// Store it and remove it when the effect is gone (Entity ID, UUID of throwing player)
|
||||
thrownPotions.put(e.getAreaEffectCloud().getEntityId(), ((Player)e.getEntity().getShooter()).getUniqueId());
|
||||
thrownPotions.put(e.getAreaEffectCloud().getEntityId(), player.getUniqueId());
|
||||
Bukkit.getScheduler().runTaskLater(getPlugin(), () -> thrownPotions.remove(e.getAreaEffectCloud().getEntityId()), e.getAreaEffectCloud().getDuration());
|
||||
}
|
||||
}
|
||||
|
@ -213,8 +213,8 @@ public class PVPListener extends FlagListener {
|
|||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled=true)
|
||||
public void onPlayerShootFireworkEvent(final EntityShootBowEvent e) {
|
||||
// Only care about players shooting fireworks
|
||||
if (e.getEntity() instanceof Player && (e.getProjectile() instanceof Firework)) {
|
||||
firedFireworks.put(e.getProjectile(), (Player)e.getEntity());
|
||||
if (e.getEntity() instanceof Player player && (e.getProjectile() instanceof Firework)) {
|
||||
firedFireworks.put(e.getProjectile(), player);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -67,8 +67,8 @@ public class GeoLimitMobsListener extends FlagListener {
|
|||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onProjectileExplode(final ExplosionPrimeEvent e) {
|
||||
if (e.getEntity() instanceof Projectile && getIWM().inWorld(e.getEntity().getLocation())) {
|
||||
ProjectileSource source = ((Projectile)e.getEntity()).getShooter();
|
||||
if (e.getEntity() instanceof Projectile projectile && getIWM().inWorld(e.getEntity().getLocation())) {
|
||||
ProjectileSource source = projectile.getShooter();
|
||||
if (source instanceof Entity shooter
|
||||
&& mobSpawnTracker.containsKey(shooter)
|
||||
&& !mobSpawnTracker.get(shooter).onIsland(e.getEntity().getLocation())) {
|
||||
|
|
|
@ -35,8 +35,8 @@ public class ItemFrameListener extends FlagListener {
|
|||
&& getIWM().inWorld(entity.getLocation())
|
||||
&& !Flags.ITEM_FRAME_DAMAGE.isSetForWorld(entity.getWorld())
|
||||
&& !(damager instanceof Player)) {
|
||||
if (damager instanceof Projectile) {
|
||||
if (!(((Projectile) damager).getShooter() instanceof Player)) {
|
||||
if (damager instanceof Projectile projectile) {
|
||||
if (!(projectile.getShooter() instanceof Player)) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -172,15 +172,13 @@ public enum GameModePlaceholder {
|
|||
* Returns the name of the island the player is standing on.
|
||||
* @since 1.5.2
|
||||
*/
|
||||
VISITED_ISLAND_NAME("visited_island_name", (addon, user, island) -> {
|
||||
return getVisitedIsland(addon, user).map(is -> {
|
||||
if (is.getName() != null) {
|
||||
return is.getName();
|
||||
} else {
|
||||
return user.getTranslation(is.getWorld(), "protection.flags.ENTER_EXIT_MESSAGES.island", TextVariables.NAME, addon.getPlayers().getName(is.getOwner()));
|
||||
}
|
||||
}).orElse("");
|
||||
}),
|
||||
VISITED_ISLAND_NAME("visited_island_name", (addon, user, island) -> getVisitedIsland(addon, user).map(is -> {
|
||||
if (is.getName() != null) {
|
||||
return is.getName();
|
||||
} else {
|
||||
return user.getTranslation(is.getWorld(), "protection.flags.ENTER_EXIT_MESSAGES.island", TextVariables.NAME, addon.getPlayers().getName(is.getOwner()));
|
||||
}
|
||||
}).orElse("")),
|
||||
/**
|
||||
* Returns the coordinates of the center of the island the player is standing on.
|
||||
* @since 1.5.2
|
||||
|
|
|
@ -69,10 +69,10 @@ public class AddonsManager {
|
|||
@NonNull
|
||||
private final Map<String, Class<?>> classes;
|
||||
private final BentoBox plugin;
|
||||
private @NonNull
|
||||
final Map<@NonNull String, @Nullable GameModeAddon> worldNames;
|
||||
private @NonNull
|
||||
final Map<@NonNull Addon, @NonNull List<Listener>> listeners;
|
||||
@NonNull
|
||||
private final Map<@NonNull String, @Nullable GameModeAddon> worldNames;
|
||||
@NonNull
|
||||
private final Map<@NonNull Addon, @NonNull List<Listener>> listeners;
|
||||
|
||||
private final PluginLoader pluginLoader;
|
||||
|
||||
|
@ -165,11 +165,11 @@ public class AddonsManager {
|
|||
try {
|
||||
|
||||
Plugin pladdon = pluginLoader.loadPlugin(f);
|
||||
if (pladdon instanceof Pladdon) {
|
||||
addon = ((Pladdon) pladdon).getAddon();
|
||||
if (pladdon instanceof Pladdon pl) {
|
||||
addon = pl.getAddon();
|
||||
addon.setDescription(AddonClassLoader.asDescription(data));
|
||||
// Mark pladdon as enabled.
|
||||
((Pladdon) pladdon).setEnabled();
|
||||
pl.setEnabled();
|
||||
pladdons.put(addon, pladdon);
|
||||
} else {
|
||||
plugin.logError("Could not load pladdon!");
|
||||
|
|
|
@ -60,8 +60,8 @@ public class BlueprintsManager {
|
|||
private static final String BLUEPRINT_BUNDLE_SUFFIX = ".json";
|
||||
public static final String BLUEPRINT_SUFFIX = ".blu";
|
||||
public static final String DEFAULT_BUNDLE_NAME = "default";
|
||||
|
||||
public static final @NonNull String FOLDER_NAME = "blueprints";
|
||||
@NonNull
|
||||
public static final String FOLDER_NAME = "blueprints";
|
||||
private static final String FOR = "' for ";
|
||||
|
||||
/**
|
||||
|
@ -69,15 +69,15 @@ public class BlueprintsManager {
|
|||
* Inner map's key is the uniqueId of the blueprint bundle so it's
|
||||
* easy to get from a UI
|
||||
*/
|
||||
private @NonNull
|
||||
final Map<GameModeAddon, List<BlueprintBundle>> blueprintBundles;
|
||||
@NonNull
|
||||
private final Map<GameModeAddon, List<BlueprintBundle>> blueprintBundles;
|
||||
|
||||
/**
|
||||
* Map of blueprints. There can be many blueprints per game mode addon
|
||||
* Inner map's key is the blueprint's name so it's easy to get from a UI
|
||||
*/
|
||||
private @NonNull
|
||||
final Map<GameModeAddon, List<Blueprint>> blueprints;
|
||||
@NonNull
|
||||
private final Map<GameModeAddon, List<Blueprint>> blueprints;
|
||||
|
||||
/**
|
||||
* Gson used for serializing/deserializing the bundle class
|
||||
|
@ -86,8 +86,8 @@ public class BlueprintsManager {
|
|||
|
||||
private final @NonNull BentoBox plugin;
|
||||
|
||||
private @NonNull
|
||||
final Set<GameModeAddon> blueprintsLoaded;
|
||||
@NonNull
|
||||
private final Set<GameModeAddon> blueprintsLoaded;
|
||||
|
||||
|
||||
public BlueprintsManager(@NonNull BentoBox plugin) {
|
||||
|
@ -225,7 +225,7 @@ public class BlueprintsManager {
|
|||
}
|
||||
|
||||
for (File file : bundles) {
|
||||
|
||||
|
||||
try (FileReader fileReader = new FileReader(file, StandardCharsets.UTF_8))
|
||||
{
|
||||
if (!file.getName().equals(Util.sanitizeInput(file.getName())))
|
||||
|
|
|
@ -23,8 +23,8 @@ import world.bentobox.bentobox.lists.Flags;
|
|||
*/
|
||||
public class FlagsManager {
|
||||
|
||||
private @NonNull
|
||||
final BentoBox plugin;
|
||||
@NonNull
|
||||
private final BentoBox plugin;
|
||||
private final Map<@NonNull Flag, @Nullable Addon> flags = new HashMap<>();
|
||||
|
||||
/**
|
||||
|
|
|
@ -1075,11 +1075,11 @@ public class IslandsManager {
|
|||
// Check if the player is a passenger in a boat
|
||||
if (player.isInsideVehicle()) {
|
||||
Entity boat = player.getVehicle();
|
||||
if (boat instanceof Boat) {
|
||||
if (boat instanceof Boat boaty) {
|
||||
player.leaveVehicle();
|
||||
// Remove the boat so they don't lie around everywhere
|
||||
boat.remove();
|
||||
player.getInventory().addItem(new ItemStack(TREE_TO_BOAT.getOrDefault(((Boat) boat).getBoatType(), Material.OAK_BOAT)));
|
||||
player.getInventory().addItem(new ItemStack(TREE_TO_BOAT.getOrDefault(boaty.getBoatType(), Material.OAK_BOAT)));
|
||||
player.updateInventory();
|
||||
}
|
||||
}
|
||||
|
@ -1199,11 +1199,11 @@ public class IslandsManager {
|
|||
// Check if the player is a passenger in a boat
|
||||
if (player.isInsideVehicle()) {
|
||||
Entity boat = player.getVehicle();
|
||||
if (boat instanceof Boat) {
|
||||
if (boat instanceof Boat boaty) {
|
||||
player.leaveVehicle();
|
||||
// Remove the boat so they don't lie around everywhere
|
||||
boat.remove();
|
||||
Material boatMat = Material.getMaterial(((Boat) boat).getType() + "_BOAT");
|
||||
Material boatMat = Material.getMaterial(boaty.getType() + "_BOAT");
|
||||
if (boatMat == null) {
|
||||
boatMat = Material.OAK_BOAT;
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ public class PlaceholdersManager {
|
|||
*/
|
||||
@NonNull
|
||||
private Optional<PlaceholderAPIHook> getPlaceholderAPIHook() {
|
||||
return plugin.getHooks().getHook("PlaceholderAPI").map(hook -> (PlaceholderAPIHook) hook);
|
||||
return plugin.getHooks().getHook("PlaceholderAPI").map(PlaceholderAPIHook.class::cast);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -33,15 +33,16 @@ import world.bentobox.bentobox.web.credits.Contributor;
|
|||
*/
|
||||
public class WebManager {
|
||||
|
||||
private @NonNull
|
||||
final BentoBox plugin;
|
||||
private @Nullable GitHubWebAPI gitHub;
|
||||
private @NonNull
|
||||
final List<CatalogEntry> addonsCatalog;
|
||||
private @NonNull
|
||||
final List<CatalogEntry> gamemodesCatalog;
|
||||
private @NonNull
|
||||
final Map<String, List<Contributor>> contributors;
|
||||
@NonNull
|
||||
private final BentoBox plugin;
|
||||
@Nullable
|
||||
private GitHubWebAPI gitHub;
|
||||
@NonNull
|
||||
private final List<CatalogEntry> addonsCatalog;
|
||||
@NonNull
|
||||
private final List<CatalogEntry> gamemodesCatalog;
|
||||
@NonNull
|
||||
private final Map<String, List<Contributor>> contributors;
|
||||
|
||||
public WebManager(@NonNull BentoBox plugin) {
|
||||
this.plugin = plugin;
|
||||
|
@ -136,7 +137,7 @@ public class WebManager {
|
|||
// Register the tags translations in the locales
|
||||
if (!tagsContent.isEmpty()) {
|
||||
try {
|
||||
JsonObject tags = new JsonParser().parse(tagsContent).getAsJsonObject();
|
||||
JsonObject tags = JsonParser.parseString(tagsContent).getAsJsonObject();
|
||||
tags.entrySet().forEach(entry -> plugin.getLocalesManager().getLanguages().values().forEach(locale -> {
|
||||
JsonElement translation = entry.getValue().getAsJsonObject().get(locale.toLanguageTag());
|
||||
if (translation != null) {
|
||||
|
@ -153,7 +154,7 @@ public class WebManager {
|
|||
// Register the topics translations in the locales
|
||||
if (!topicsContent.isEmpty()) {
|
||||
try {
|
||||
JsonObject topics = new JsonParser().parse(topicsContent).getAsJsonObject();
|
||||
JsonObject topics = JsonParser.parseString(topicsContent).getAsJsonObject();
|
||||
topics.entrySet().forEach(entry -> plugin.getLocalesManager().getLanguages().values().forEach(locale -> {
|
||||
JsonElement translation = entry.getValue().getAsJsonObject().get(locale.toLanguageTag());
|
||||
if (translation != null) {
|
||||
|
@ -170,7 +171,7 @@ public class WebManager {
|
|||
// Register the catalog data
|
||||
if (!catalogContent.isEmpty()) {
|
||||
try {
|
||||
JsonObject catalog = new JsonParser().parse(catalogContent).getAsJsonObject();
|
||||
JsonObject catalog = JsonParser.parseString(catalogContent).getAsJsonObject();
|
||||
|
||||
this.addonsCatalog.clear();
|
||||
this.gamemodesCatalog.clear();
|
||||
|
|
|
@ -86,10 +86,10 @@ public abstract class SimpleWorldRegenerator implements WorldRegenerator {
|
|||
private CompletableFuture<Void> regenerateChunk(GameModeAddon gm, IslandDeletion di, World world, int chunkX, int chunkZ) {
|
||||
CompletableFuture<Chunk> chunkFuture = PaperLib.getChunkAtAsync(world, chunkX, chunkZ);
|
||||
CompletableFuture<Void> invFuture = chunkFuture.thenAccept(chunk ->
|
||||
Arrays.stream(chunk.getTileEntities()).filter(InventoryHolder.class::isInstance)
|
||||
.filter(te -> di.inBounds(te.getLocation().getBlockX(), te.getLocation().getBlockZ()))
|
||||
.forEach(te -> ((InventoryHolder) te).getInventory().clear())
|
||||
);
|
||||
Arrays.stream(chunk.getTileEntities()).filter(InventoryHolder.class::isInstance)
|
||||
.filter(te -> di.inBounds(te.getLocation().getBlockX(), te.getLocation().getBlockZ()))
|
||||
.forEach(te -> ((InventoryHolder) te).getInventory().clear())
|
||||
);
|
||||
CompletableFuture<Void> entitiesFuture = chunkFuture.thenAccept(chunk -> {
|
||||
for (Entity e : chunk.getEntities()) {
|
||||
if (!(e instanceof Player)) {
|
||||
|
@ -108,13 +108,13 @@ public abstract class SimpleWorldRegenerator implements WorldRegenerator {
|
|||
}
|
||||
return chunk;
|
||||
});
|
||||
CompletableFuture<Void> postCopyFuture = copyFuture.thenAccept(chunk -> {
|
||||
// Remove all entities in chunk, including any dropped items as a result of clearing the blocks above
|
||||
Arrays.stream(chunk.getEntities()).filter(e -> !(e instanceof Player) && di.inBounds(e.getLocation().getBlockX(), e.getLocation().getBlockZ())).forEach(Entity::remove);
|
||||
});
|
||||
CompletableFuture<Void> postCopyFuture = copyFuture.thenAccept(chunk ->
|
||||
// Remove all entities in chunk, including any dropped items as a result of clearing the blocks above
|
||||
Arrays.stream(chunk.getEntities()).filter(e -> !(e instanceof Player) && di.inBounds(e.getLocation().getBlockX(), e.getLocation().getBlockZ())).forEach(Entity::remove));
|
||||
return CompletableFuture.allOf(invFuture, entitiesFuture, postCopyFuture);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void copyChunkDataToChunk(Chunk chunk, ChunkGenerator.ChunkData chunkData, ChunkGenerator.BiomeGrid biomeGrid, BoundingBox limitBox) {
|
||||
double baseX = chunk.getX() << 4;
|
||||
double baseZ = chunk.getZ() << 4;
|
||||
|
|
|
@ -170,8 +170,8 @@ public class ItemParser {
|
|||
|
||||
ItemMeta meta = durability.getItemMeta();
|
||||
|
||||
if (meta instanceof Damageable) {
|
||||
((Damageable) meta).setDamage(Integer.parseInt(part[1]));
|
||||
if (meta instanceof Damageable damageable) {
|
||||
damageable.setDamage(Integer.parseInt(part[1]));
|
||||
durability.setItemMeta(meta);
|
||||
}
|
||||
|
||||
|
|
|
@ -782,7 +782,7 @@ public class ClosestSafeSpotTeleport
|
|||
* - the smallest z value
|
||||
* - the smallest y value
|
||||
*/
|
||||
private final static Comparator<PositionData> POSITION_COMPARATOR = Comparator.comparingDouble(PositionData::distance).
|
||||
private static final Comparator<PositionData> POSITION_COMPARATOR = Comparator.comparingDouble(PositionData::distance).
|
||||
thenComparingInt(position -> position.vector().getBlockX()).
|
||||
thenComparingInt(position -> position.vector().getBlockZ()).
|
||||
thenComparingInt(position -> position.vector().getBlockY());
|
||||
|
|
|
@ -17,18 +17,18 @@ public class CatalogEntry {
|
|||
/**
|
||||
* Defaults to {@link Material#PAPER}.
|
||||
*/
|
||||
private @NonNull
|
||||
final Material icon;
|
||||
private @NonNull
|
||||
final String name;
|
||||
private @NonNull
|
||||
final String description;
|
||||
private @Nullable
|
||||
final String topic;
|
||||
private @Nullable
|
||||
final String tag;
|
||||
private @NonNull
|
||||
final String repository;
|
||||
@NonNull
|
||||
private final Material icon;
|
||||
@NonNull
|
||||
private final String name;
|
||||
@NonNull
|
||||
private final String description;
|
||||
@NonNull
|
||||
private final String topic;
|
||||
@NonNull
|
||||
private final String tag;
|
||||
@NonNull
|
||||
private final String repository;
|
||||
|
||||
public CatalogEntry(@NonNull JsonObject object) {
|
||||
this.slot = object.get("slot").getAsInt();
|
||||
|
|
|
@ -9,8 +9,8 @@ import org.eclipse.jdt.annotation.NonNull;
|
|||
*/
|
||||
public class Contributor {
|
||||
|
||||
private @NonNull
|
||||
final String name;
|
||||
@NonNull
|
||||
private final String name;
|
||||
private final int commits;
|
||||
|
||||
public Contributor(@NonNull String name, int commits) {
|
||||
|
|
Loading…
Reference in New Issue