diff --git a/src/main/java/us/tastybento/bskyblock/BSkyBlock.java b/src/main/java/us/tastybento/bskyblock/BSkyBlock.java index fc5e2d822..03112e422 100755 --- a/src/main/java/us/tastybento/bskyblock/BSkyBlock.java +++ b/src/main/java/us/tastybento/bskyblock/BSkyBlock.java @@ -45,7 +45,7 @@ public class BSkyBlock extends JavaPlugin{ private static BSkyBlock plugin; - private HashMap locales = new HashMap(); + private HashMap locales = new HashMap<>(); // Databases private PlayersManager playersManager; @@ -165,7 +165,7 @@ public class BSkyBlock extends JavaPlugin{ plugin = null; } - private void registerCustomCharts(){ + private void registerCustomCharts(){ metrics.addCustomChart(new Metrics.SingleLineChart("islands_count") { @Override @@ -293,7 +293,7 @@ public class BSkyBlock extends JavaPlugin{ } } // Store all the locales available - for (String language : localeDir.list(ymlFilter)) { + for (String language : localeDir.list(ymlFilter)) { try { BSBLocale locale = new BSBLocale(this, language); locales.put(locale.getLocaleId(), locale); diff --git a/src/main/java/us/tastybento/bskyblock/api/commands/AbstractCommand.java b/src/main/java/us/tastybento/bskyblock/api/commands/AbstractCommand.java index b80b030a1..767ccb705 100644 --- a/src/main/java/us/tastybento/bskyblock/api/commands/AbstractCommand.java +++ b/src/main/java/us/tastybento/bskyblock/api/commands/AbstractCommand.java @@ -53,7 +53,7 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter { this.label = label; this.aliases = aliases; this.help = help; - this.teamMembers = new HashSet(); + this.teamMembers = new HashSet<>(); // Register the help argument if needed if (help) { @@ -120,8 +120,8 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter { String[] usage = argumentsMap.get(command).usage(sender); if (usage == null) usage = new String[2]; - msg = msg.replace("[args]", (usage != null && usage[0] != null) ? usage[0] : "") - .replace("[info]", (usage != null && usage[1] != null) ? usage[1] : ""); + msg = msg.replace("[args]", (usage[0] != null) ? usage[0] : "") + .replace("[info]", (usage[1] != null) ? usage[1] : ""); return msg; } @@ -150,8 +150,7 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter { } public boolean isAlias(String argument) { - if (aliasesMap.containsValue(argument)) return true; - return false; + return aliasesMap.containsValue(argument); } public void addAliases(String parent, String... aliases) { @@ -220,7 +219,7 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter { @Override public List onTabComplete(CommandSender sender, Command command, String label, String[] args){ - List options = new ArrayList(); + List options = new ArrayList<>(); checkForPlayer(sender); String lastArg = (args.length != 0 ? args[args.length - 1] : ""); if (canUse(sender).isAllowed()) { @@ -243,11 +242,11 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter { } private static String[] clean(final String[] v) { - List list = new ArrayList(Arrays.asList(v)); + List list = new ArrayList<>(Arrays.asList(v)); list.removeAll(Collections.singleton("")); return list.toArray(new String[list.size()]); } - + /** * Sets some variables and flags if this is a player * @param sender @@ -269,9 +268,9 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter { } else { inTeam = false; } - + } - + /** * Response class for the canUse check * @author tastybento @@ -280,7 +279,7 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter { public class CanUseResp { private boolean allowed; private String errorResponse; // May be shown if required - + /** * Cannot use situation * @param errorResponse - error response @@ -289,7 +288,7 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter { this.allowed = false; this.errorResponse = errorResponse; } - + /** * Can or cannot use situation, no error response. * @param b @@ -321,7 +320,7 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter { */ public void setErrorResponse(String errorResponse) { this.errorResponse = errorResponse; - } + } } // These methods below just neaten up the code in the commands so "plugin." isn't always used /** diff --git a/src/main/java/us/tastybento/bskyblock/api/events/BSkyBlockReadyEvent.java b/src/main/java/us/tastybento/bskyblock/api/events/BSkyBlockReadyEvent.java index 8b4d16d1b..aa7a91ccb 100644 --- a/src/main/java/us/tastybento/bskyblock/api/events/BSkyBlockReadyEvent.java +++ b/src/main/java/us/tastybento/bskyblock/api/events/BSkyBlockReadyEvent.java @@ -5,7 +5,7 @@ import org.bukkit.event.HandlerList; /** * Fired when BSkyBlock is ready to play and all files are loaded - * + * * @author tastybento * @since 1.0 */ diff --git a/src/main/java/us/tastybento/bskyblock/api/events/IslandEvent.java b/src/main/java/us/tastybento/bskyblock/api/events/IslandEvent.java index ece66e32e..4f8192f71 100644 --- a/src/main/java/us/tastybento/bskyblock/api/events/IslandEvent.java +++ b/src/main/java/us/tastybento/bskyblock/api/events/IslandEvent.java @@ -14,23 +14,23 @@ import us.tastybento.bskyblock.database.objects.Island; public class IslandEvent extends Event implements Cancellable{ private static final HandlerList handlers = new HandlerList(); private boolean cancelled; - + private final Island island; - + /** * @param island */ public IslandEvent(Island island){ this.island = island; } - + /** * @return the island involved in this event */ public Island getIsland(){ return this.island; } - + @Override public HandlerList getHandlers() { return handlers; @@ -39,7 +39,7 @@ public class IslandEvent extends Event implements Cancellable{ public static HandlerList getHandlerList() { return handlers; } - + @Override public boolean isCancelled() { return cancelled; diff --git a/src/main/java/us/tastybento/bskyblock/api/events/island/IslandChangeOwnerEvent.java b/src/main/java/us/tastybento/bskyblock/api/events/island/IslandChangeOwnerEvent.java index 05cd7820e..a7387936d 100644 --- a/src/main/java/us/tastybento/bskyblock/api/events/island/IslandChangeOwnerEvent.java +++ b/src/main/java/us/tastybento/bskyblock/api/events/island/IslandChangeOwnerEvent.java @@ -7,7 +7,7 @@ import us.tastybento.bskyblock.database.objects.Island; /** * Fired when the owner of an island changes - * + * * @author Poslovitch * @version 1.0 */ diff --git a/src/main/java/us/tastybento/bskyblock/api/events/island/IslandEnterEvent.java b/src/main/java/us/tastybento/bskyblock/api/events/island/IslandEnterEvent.java index ea56f75fa..8b8aea920 100644 --- a/src/main/java/us/tastybento/bskyblock/api/events/island/IslandEnterEvent.java +++ b/src/main/java/us/tastybento/bskyblock/api/events/island/IslandEnterEvent.java @@ -9,7 +9,7 @@ import us.tastybento.bskyblock.database.objects.Island; /** * Fired when a player enters an island's area - * + * * @author tastybento * @since 1.0 */ diff --git a/src/main/java/us/tastybento/bskyblock/api/events/island/IslandExitEvent.java b/src/main/java/us/tastybento/bskyblock/api/events/island/IslandExitEvent.java index cda3e334d..9f9456990 100644 --- a/src/main/java/us/tastybento/bskyblock/api/events/island/IslandExitEvent.java +++ b/src/main/java/us/tastybento/bskyblock/api/events/island/IslandExitEvent.java @@ -9,7 +9,7 @@ import us.tastybento.bskyblock.database.objects.Island; /** * Fired when a player exits an island's protected area - * + * * @author tastybento * @since 1.0 */ diff --git a/src/main/java/us/tastybento/bskyblock/api/events/island/IslandJoinEvent.java b/src/main/java/us/tastybento/bskyblock/api/events/island/IslandJoinEvent.java index 75cbf064e..445da4cc0 100644 --- a/src/main/java/us/tastybento/bskyblock/api/events/island/IslandJoinEvent.java +++ b/src/main/java/us/tastybento/bskyblock/api/events/island/IslandJoinEvent.java @@ -7,7 +7,7 @@ import us.tastybento.bskyblock.database.objects.Island; /** * Fired when a player joins an existing island. - * + * * @author tastybento * @since 1.0 */ diff --git a/src/main/java/us/tastybento/bskyblock/api/events/island/IslandLeaveEvent.java b/src/main/java/us/tastybento/bskyblock/api/events/island/IslandLeaveEvent.java index f3fc06e70..141e4fbcc 100644 --- a/src/main/java/us/tastybento/bskyblock/api/events/island/IslandLeaveEvent.java +++ b/src/main/java/us/tastybento/bskyblock/api/events/island/IslandLeaveEvent.java @@ -7,7 +7,7 @@ import us.tastybento.bskyblock.database.objects.Island; /** * Fired when a player leaves an existing island. - * + * * @author tastybento * @since 1.0 */ diff --git a/src/main/java/us/tastybento/bskyblock/api/events/island/IslandLockEvent.java b/src/main/java/us/tastybento/bskyblock/api/events/island/IslandLockEvent.java index 2eac3a9df..5038e1c62 100755 --- a/src/main/java/us/tastybento/bskyblock/api/events/island/IslandLockEvent.java +++ b/src/main/java/us/tastybento/bskyblock/api/events/island/IslandLockEvent.java @@ -9,7 +9,7 @@ import us.tastybento.bskyblock.database.objects.Island; * This event is fired when an island is going to be locked. *

* Cancelling this event will result in keeping the island unlocked. - * + * * @author Poslovitch * @since 1.0 */ diff --git a/src/main/java/us/tastybento/bskyblock/api/events/island/IslandResetEvent.java b/src/main/java/us/tastybento/bskyblock/api/events/island/IslandResetEvent.java index 6ef8f5ce5..4cdde2cf7 100644 --- a/src/main/java/us/tastybento/bskyblock/api/events/island/IslandResetEvent.java +++ b/src/main/java/us/tastybento/bskyblock/api/events/island/IslandResetEvent.java @@ -7,7 +7,7 @@ import us.tastybento.bskyblock.database.objects.Island; /** * This event is fired when a player resets an island - * + * * @author tastybento * @since 1.0 */ diff --git a/src/main/java/us/tastybento/bskyblock/api/events/island/IslandUnlockEvent.java b/src/main/java/us/tastybento/bskyblock/api/events/island/IslandUnlockEvent.java index 0ed97f2f0..640c5968d 100755 --- a/src/main/java/us/tastybento/bskyblock/api/events/island/IslandUnlockEvent.java +++ b/src/main/java/us/tastybento/bskyblock/api/events/island/IslandUnlockEvent.java @@ -9,7 +9,7 @@ import us.tastybento.bskyblock.database.objects.Island; * This event is fired when an island is going to be unlocked. *

* Cancelling this event will result in keeping the island locked. - * + * * @author Poslovitch * @since 1.0 */ diff --git a/src/main/java/us/tastybento/bskyblock/api/events/island/SettingChangeEvent.java b/src/main/java/us/tastybento/bskyblock/api/events/island/SettingChangeEvent.java index 9e1bf5f34..4315807c6 100644 --- a/src/main/java/us/tastybento/bskyblock/api/events/island/SettingChangeEvent.java +++ b/src/main/java/us/tastybento/bskyblock/api/events/island/SettingChangeEvent.java @@ -10,7 +10,7 @@ import us.tastybento.bskyblock.database.objects.Island.SettingsFlag; * This event is fired when a player changes a setting on his island *

* Canceling this event will result in canceling the change. - * + * * @author Poslovitch * @since 1.0 */ diff --git a/src/main/java/us/tastybento/bskyblock/api/events/purge/PurgeDeleteIslandEvent.java b/src/main/java/us/tastybento/bskyblock/api/events/purge/PurgeDeleteIslandEvent.java index 2c02fb1aa..7b61b394d 100644 --- a/src/main/java/us/tastybento/bskyblock/api/events/purge/PurgeDeleteIslandEvent.java +++ b/src/main/java/us/tastybento/bskyblock/api/events/purge/PurgeDeleteIslandEvent.java @@ -6,7 +6,7 @@ import us.tastybento.bskyblock.database.objects.Island; /** * This event is fired before an island is going to be purged. * Canceling this event will prevent the plugin to remove the island. - * + * * @author Poslovitch * @since 1.0 */ diff --git a/src/main/java/us/tastybento/bskyblock/api/events/purge/PurgeStartEvent.java b/src/main/java/us/tastybento/bskyblock/api/events/purge/PurgeStartEvent.java index a4d2d6530..9f4a131bb 100644 --- a/src/main/java/us/tastybento/bskyblock/api/events/purge/PurgeStartEvent.java +++ b/src/main/java/us/tastybento/bskyblock/api/events/purge/PurgeStartEvent.java @@ -11,7 +11,7 @@ import org.bukkit.event.HandlerList; * This event is fired when islands to remove have been chosen and before starting to remove them. * You can remove or add islands to remove. * Canceling this event will cancel the purge - * + * * @author Poslovitch * @since 1.0 */ diff --git a/src/main/java/us/tastybento/bskyblock/api/events/team/CoopJoinEvent.java b/src/main/java/us/tastybento/bskyblock/api/events/team/CoopJoinEvent.java index b11ad417f..42043b628 100644 --- a/src/main/java/us/tastybento/bskyblock/api/events/team/CoopJoinEvent.java +++ b/src/main/java/us/tastybento/bskyblock/api/events/team/CoopJoinEvent.java @@ -7,7 +7,7 @@ import us.tastybento.bskyblock.database.objects.Island; /** * Fired when a player joins an island team as a coop member - * + * * @author tastybento * @since 1.0 */ @@ -24,7 +24,7 @@ public class CoopJoinEvent extends IslandEvent { this.player = player; this.inviter = inviter; } - + /** * The UUID of the player who were coop'd * @return the coop'd @@ -32,7 +32,7 @@ public class CoopJoinEvent extends IslandEvent { public UUID getPlayer() { return player; } - + /** * The UUID of the player who invited the player to join the island * @return the inviter diff --git a/src/main/java/us/tastybento/bskyblock/api/events/team/CoopLeaveEvent.java b/src/main/java/us/tastybento/bskyblock/api/events/team/CoopLeaveEvent.java index 3a09a18d9..1c6f9a73a 100644 --- a/src/main/java/us/tastybento/bskyblock/api/events/team/CoopLeaveEvent.java +++ b/src/main/java/us/tastybento/bskyblock/api/events/team/CoopLeaveEvent.java @@ -7,7 +7,7 @@ import us.tastybento.bskyblock.database.objects.Island; /** * Fired when a player leaves an island coop - * + * * @author tastybento * @since 1.0 */ @@ -26,7 +26,7 @@ public class CoopLeaveEvent extends IslandEvent { this.player = player; this.expeller = expeller; } - + /** * The UUID of the player who left * @return the player who left the coop @@ -34,7 +34,7 @@ public class CoopLeaveEvent extends IslandEvent { public UUID getPlayer() { return player; } - + /** * @return the expelling player */ diff --git a/src/main/java/us/tastybento/bskyblock/api/events/team/PlayerAcceptInviteEvent.java b/src/main/java/us/tastybento/bskyblock/api/events/team/PlayerAcceptInviteEvent.java index f35597760..faea7244e 100644 --- a/src/main/java/us/tastybento/bskyblock/api/events/team/PlayerAcceptInviteEvent.java +++ b/src/main/java/us/tastybento/bskyblock/api/events/team/PlayerAcceptInviteEvent.java @@ -11,29 +11,29 @@ import org.bukkit.event.HandlerList; * @since 1.0 */ public class PlayerAcceptInviteEvent extends Event { - private static final HandlerList handlers = new HandlerList(); + private static final HandlerList handlers = new HandlerList(); private final Player player; - + /** * @param player */ public PlayerAcceptInviteEvent(Player player) { this.player = player; } - + /** * @return the player */ public Player getPlayer() { return this.player; } - - @Override - public HandlerList getHandlers() { - return handlers; - } - public static HandlerList getHandlerList() { - return handlers; - } + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } } diff --git a/src/main/java/us/tastybento/bskyblock/api/events/team/PlayerRejectInviteEvent.java b/src/main/java/us/tastybento/bskyblock/api/events/team/PlayerRejectInviteEvent.java index 1c811361d..345cc7a97 100644 --- a/src/main/java/us/tastybento/bskyblock/api/events/team/PlayerRejectInviteEvent.java +++ b/src/main/java/us/tastybento/bskyblock/api/events/team/PlayerRejectInviteEvent.java @@ -28,29 +28,29 @@ import org.bukkit.event.HandlerList; * @since 1.0 */ public class PlayerRejectInviteEvent extends Event { - private static final HandlerList handlers = new HandlerList(); + private static final HandlerList handlers = new HandlerList(); private final Player player; - + /** * @param player */ public PlayerRejectInviteEvent(Player player) { this.player = player; } - + /** * @return the player */ public Player getPlayer() { return this.player; } - - @Override - public HandlerList getHandlers() { - return handlers; - } - public static HandlerList getHandlerList() { - return handlers; - } + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } } diff --git a/src/main/java/us/tastybento/bskyblock/api/events/team/TeamChatEvent.java b/src/main/java/us/tastybento/bskyblock/api/events/team/TeamChatEvent.java index 27ca5e195..6134b619d 100644 --- a/src/main/java/us/tastybento/bskyblock/api/events/team/TeamChatEvent.java +++ b/src/main/java/us/tastybento/bskyblock/api/events/team/TeamChatEvent.java @@ -7,14 +7,14 @@ import us.tastybento.bskyblock.database.objects.Island; /** * This event is fired when a player talks in TeamChat - * + * * @author Poslovitch * @since 1.0 */ public class TeamChatEvent extends IslandEvent { private final UUID player; - private String message; - + private String message; + /** * @param island * @param player @@ -25,14 +25,14 @@ public class TeamChatEvent extends IslandEvent { this.player = player; this.message = message; } - + /** * @return the player who talked */ public UUID getPlayer() { - return player; + return player; } - + /** * Gets the message that the player is attempting to send. * @return the message @@ -40,10 +40,10 @@ public class TeamChatEvent extends IslandEvent { public String getMessage() { return this.message; } - + /** * Sets the message that the player will send. - * @param the message to send + * @param message the message to send */ public void setMessage(String message) { this.message = message; diff --git a/src/main/java/us/tastybento/bskyblock/commands/AdminCommand.java b/src/main/java/us/tastybento/bskyblock/commands/AdminCommand.java index b93a870a9..764fd5aec 100755 --- a/src/main/java/us/tastybento/bskyblock/commands/AdminCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/AdminCommand.java @@ -9,7 +9,7 @@ import us.tastybento.bskyblock.api.commands.AbstractCommand; import us.tastybento.bskyblock.config.Settings; public class AdminCommand extends AbstractCommand { - + BSkyBlock plugin; public AdminCommand(BSkyBlock plugin) { @@ -26,7 +26,6 @@ public class AdminCommand extends AbstractCommand { @Override public CanUseResp canUse(CommandSender sender) { - // TODO Auto-generated method stub return new CanUseResp(true); } @@ -37,7 +36,6 @@ public class AdminCommand extends AbstractCommand { @Override public Set tabComplete(CommandSender sender, String[] args) { - // TODO Auto-generated method stub return null; } @@ -46,19 +44,18 @@ public class AdminCommand extends AbstractCommand { return new String[] {null, plugin.getLocale(sender).get("help.admin.delete")}; } }); - + } @Override public CanUseResp canUse(CommandSender sender) { - // TODO Auto-generated method stub return new CanUseResp(true); } @Override public void execute(CommandSender sender, String[] args) { - + } } diff --git a/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java b/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java index c0b2ff024..7438dbd02 100755 --- a/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java @@ -43,15 +43,15 @@ public class IslandCommand extends AbstractCommand { */ private final BiMap inviteList = HashBiMap.create(); // The time a player has to wait until they can reset their island again - private HashMap resetWaitTime = new HashMap(); - protected Set leavingPlayers = new HashSet(); + private HashMap resetWaitTime = new HashMap<>(); + protected Set leavingPlayers = new HashSet<>(); public IslandCommand(BSkyBlock plugin) { super(plugin, Settings.ISLANDCOMMAND, new String[]{"is"}, true); plugin.getCommand(Settings.ISLANDCOMMAND).setExecutor(this); plugin.getCommand(Settings.ISLANDCOMMAND).setTabCompleter(this); this.plugin = plugin; - } + } @Override public CanUseResp canUse(CommandSender sender) { @@ -466,9 +466,7 @@ public class IslandCommand extends AbstractCommand { } } // Do some sanity checking - if (maxSize < 1) { - maxSize = 1; - } + if (maxSize < 1) maxSize = 1; } if (teamMembers.size() < maxSize) { Util.sendMessage(player, ChatColor.GREEN + getLocale(sender).get("invite.youCanInvite").replace("[number]", String.valueOf(maxSize - teamMembers.size()))); @@ -513,7 +511,7 @@ public class IslandCommand extends AbstractCommand { if (!getPlayers().hasIsland(playerUUID)) { // If the player is in a team, they are not the leader if (getPlayers().inTeam(playerUUID)) { - return new CanUseResp(ChatColor.RED + getLocale(sender).get("general.errors.not-leader")); + return new CanUseResp(ChatColor.RED + getLocale(sender).get("general.errors.not-leader")); } return new CanUseResp(ChatColor.RED + getLocale(sender).get("invite.error.YouMustHaveIslandToInvite")); } @@ -580,9 +578,7 @@ public class IslandCommand extends AbstractCommand { } } // Do some sanity checking - if (maxSize < 1) { - maxSize = 1; - } + if (maxSize < 1) maxSize = 1; } if (teamMembers.size() < maxSize) { // If that player already has an invite out then retract it. @@ -648,7 +644,6 @@ public class IslandCommand extends AbstractCommand { } else { Util.sendMessage(player, ChatColor.RED + getLocale(sender).get("island.help.invite")); } - return; } @Override @@ -687,18 +682,15 @@ public class IslandCommand extends AbstractCommand { if (Settings.leaveConfirmation && !leavingPlayers.contains(playerUUID)) { leavingPlayers.add(playerUUID); Util.sendMessage(player, ChatColor.RED + getLocale(sender).get("leave.Warning")); - new BukkitRunnable() { - @Override - public void run() { - // If the player is still on the list, remove them and cancel the leave - if (leavingPlayers.contains(playerUUID)) { - leavingPlayers.remove(playerUUID); - Util.sendMessage(player, ChatColor.RED + getLocale(sender).get("leave.Canceled")); - } + plugin.getServer().getScheduler().runTaskLater(plugin, () -> { + // If the player is still on the list, remove them and cancel the leave + if (leavingPlayers.contains(playerUUID)) { + leavingPlayers.remove(playerUUID); + Util.sendMessage(player, ChatColor.RED + getLocale(sender).get("leave.Canceled")); } + }, Settings.leaveConfirmWait * 20L); - }.runTaskLater(plugin, Settings.leaveConfirmWait * 20L); return; } // Remove from confirmation list @@ -804,7 +796,7 @@ public class IslandCommand extends AbstractCommand { if (!getIslands().hasIsland(prospectiveTeamLeaderUUID)) { Util.sendMessage(player, ChatColor.RED + getLocale(sender).get("invite.error.InvalidInvite")); inviteList.remove(playerUUID); - return; + return; } if (DEBUG) plugin.getLogger().info("DEBUG: Invite is valid"); @@ -831,7 +823,7 @@ public class IslandCommand extends AbstractCommand { setResetWaitTime(player); if (Settings.teamJoinDeathReset) { - getPlayers().setDeaths(player.getUniqueId(), 0); + getPlayers().setDeaths(playerUUID, 0); } if (DEBUG) plugin.getLogger().info("DEBUG: Setting home. team leader's home is " + getPlayers().getHomeLocation(prospectiveTeamLeaderUUID)); @@ -1404,7 +1396,7 @@ public class IslandCommand extends AbstractCommand { * @param player */ private void setResetWaitTime(final Player player) { - resetWaitTime.put(player.getUniqueId(), Long.valueOf(Calendar.getInstance().getTimeInMillis() + Settings.resetWait * 1000)); + resetWaitTime.put(player.getUniqueId(), Calendar.getInstance().getTimeInMillis() + Settings.resetWait * 1000); } /** diff --git a/src/main/java/us/tastybento/bskyblock/config/BSBLocale.java b/src/main/java/us/tastybento/bskyblock/config/BSBLocale.java index 5290380c6..88652d232 100644 --- a/src/main/java/us/tastybento/bskyblock/config/BSBLocale.java +++ b/src/main/java/us/tastybento/bskyblock/config/BSBLocale.java @@ -68,33 +68,33 @@ public class BSBLocale { plugin.getLogger().severe(reference + " not found in " + languageTag + " or default lang " + Settings.defaultLanguage); return reference; // Return reference for debug purposes, like for the mods. } - + /** * Returns the locale language * @return the locale language */ public String getLanguageName(){ if(localeObject == null) return "unknown"; - + return localeObject.getDisplayLanguage(localeObject); } - + /** * Returns the locale country * @return the locale country */ public String getCountryName(){ if(localeObject == null) return "unknown"; - + return localeObject.getDisplayCountry(localeObject); } - + /** * Returns the locale identifier (e.g: en-GB) * @return the locale ID */ public String getLocaleId(){ - return this.localeObject.toLanguageTag(); + return this.localeObject.toLanguageTag(); } } diff --git a/src/main/java/us/tastybento/bskyblock/config/NotSetup.java b/src/main/java/us/tastybento/bskyblock/config/NotSetup.java index f086856ad..357966d80 100644 --- a/src/main/java/us/tastybento/bskyblock/config/NotSetup.java +++ b/src/main/java/us/tastybento/bskyblock/config/NotSetup.java @@ -11,7 +11,7 @@ import us.tastybento.bskyblock.BSkyBlock; /** * This class runs when the config file is not set up enough, or is unsafe. * It provides useful information to the admin on what is wrong. - * + * * @author Tastybento * @author Poslovitch */ @@ -30,7 +30,7 @@ public class NotSetup implements CommandExecutor{ ISLAND_HEIGHT_TOO_LOW(3, 304), NETHER_SPAWN_RADIUS_TOO_LOW(3, 305), NETHER_SPAWN_RADIUS_TOO_HIGH(3, 306); - + /* * Priority: * 0 - CRITICAL @@ -45,7 +45,7 @@ public class NotSetup implements CommandExecutor{ this.priority = priority; this.id = id; } - + public static ConfigError getById(int id){ for(ConfigError e : ConfigError.values()){ if(e.id == id) return e; @@ -53,13 +53,13 @@ public class NotSetup implements CommandExecutor{ return null; } } - + private BSkyBlock plugin; private List errors; - + /** * Handles plugin operation if a critical config-related issue happened - * + * * @param plugin * @param errors */ @@ -67,10 +67,10 @@ public class NotSetup implements CommandExecutor{ this.plugin = plugin; this.errors = errors; } - + @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - + return true; } } diff --git a/src/main/java/us/tastybento/bskyblock/config/PluginConfig.java b/src/main/java/us/tastybento/bskyblock/config/PluginConfig.java index b0bbf425e..7e4336f49 100755 --- a/src/main/java/us/tastybento/bskyblock/config/PluginConfig.java +++ b/src/main/java/us/tastybento/bskyblock/config/PluginConfig.java @@ -25,7 +25,7 @@ public class PluginConfig { plugin.saveDefaultConfig(); // Initialize the errors list - HashMap errors = new HashMap(); + HashMap errors = new HashMap<>(); //TODO config version @@ -116,8 +116,8 @@ public class PluginConfig { // TODO: add to config Settings.endGenerate = true; Settings.endIslands = false; - Settings.limitedBlocks = new HashMap(); - Settings.defaultWorldSettings = new HashMap(); + Settings.limitedBlocks = new HashMap<>(); + Settings.defaultWorldSettings = new HashMap<>(); for (SettingsFlag flag: SettingsFlag.values()) { Settings.defaultWorldSettings.put(flag, false); } diff --git a/src/main/java/us/tastybento/bskyblock/config/YamlResourceBundle.java b/src/main/java/us/tastybento/bskyblock/config/YamlResourceBundle.java index 5b27cff01..3d9a2db36 100644 --- a/src/main/java/us/tastybento/bskyblock/config/YamlResourceBundle.java +++ b/src/main/java/us/tastybento/bskyblock/config/YamlResourceBundle.java @@ -14,7 +14,6 @@ */ package us.tastybento.bskyblock.config; - import static java.util.Arrays.asList; import static java.util.Collections.enumeration; import static java.util.Collections.unmodifiableList; @@ -86,14 +85,14 @@ public class YamlResourceBundle extends ResourceBundle { e -> e.getKey(), e -> e.getValue(), (oldValue, newValue) -> newValue - )); + )); } /** * Flatten yaml tree structure. * * @param entry {@link Entry} of yaml tree. - * @return {@link Stream} of entries. + * @return {@link Stream} of entries */ private static Stream> flattenYamlTree(Entry entry) { String key = entry.getKey().toString(); @@ -110,8 +109,8 @@ public class YamlResourceBundle extends ResourceBundle { return Stream.concat( Stream.of(new SimpleImmutableEntry<>(key, value)), valueAsList.stream() - .map(v -> new SimpleImmutableEntry<>(key + "[" + index.getAndIncrement() + "]", v)) - ); + .map(v -> new SimpleImmutableEntry<>(key + "[" + index.getAndIncrement() + "]", v)) + ); } return Stream.of(new SimpleImmutableEntry<>(key, value)); } @@ -159,8 +158,8 @@ public class YamlResourceBundle extends ResourceBundle { /** {@inheritDoc} */ @Override public ResourceBundle newBundle(String baseName, - Locale locale, String format, ClassLoader loader, boolean reload) - throws IllegalAccessException, InstantiationException, IOException { + Locale locale, String format, ClassLoader loader, boolean reload) + throws IllegalAccessException, InstantiationException, IOException { if (!getFormats(baseName).contains(format)) { return null; } diff --git a/src/main/java/us/tastybento/bskyblock/database/BSBDatabase.java b/src/main/java/us/tastybento/bskyblock/database/BSBDatabase.java index b85ee3206..239185b42 100755 --- a/src/main/java/us/tastybento/bskyblock/database/BSBDatabase.java +++ b/src/main/java/us/tastybento/bskyblock/database/BSBDatabase.java @@ -12,7 +12,7 @@ public abstract class BSBDatabase { /** * Gets the type of database being used. Currently supported options are - * FLATFILE, MYSQL and SQLITE. Default is FLATFILE + * FLATFILE and MYSQL. Default is FLATFILE * @return Database type */ public static BSBDatabase getDatabase(){ diff --git a/src/main/java/us/tastybento/bskyblock/database/DatabaseConnecter.java b/src/main/java/us/tastybento/bskyblock/database/DatabaseConnecter.java index 0e1a8a858..726b20924 100644 --- a/src/main/java/us/tastybento/bskyblock/database/DatabaseConnecter.java +++ b/src/main/java/us/tastybento/bskyblock/database/DatabaseConnecter.java @@ -6,15 +6,15 @@ import java.sql.SQLException; import org.bukkit.configuration.file.YamlConfiguration; /** - * + * * Creates a connection to a database. - * + * */ public interface DatabaseConnecter { /** * Establishes a new connection to the database - * + * * @return A new connection to the database * @throws SQLException */ @@ -22,18 +22,18 @@ public interface DatabaseConnecter { /** * Returns the connection url - * + * * @return */ public String getConnectionUrl(); /** * Looks through the database (or files) and returns a known unique key - * @param tableName + * @param tableName * @return a unique key for this record */ public String getUniqueId(String tableName); - + /** * Check if a key exists in the database in this table or not * @param simpleName diff --git a/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabaseConnecter.java b/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabaseConnecter.java index 4b96a6aff..b1df81e24 100644 --- a/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabaseConnecter.java +++ b/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabaseConnecter.java @@ -26,14 +26,12 @@ public class FlatFileDatabaseConnecter implements DatabaseConnecter { @Override public Connection createConnection() throws SQLException { - // TODO Auto-generated method stub - return null; + return null; // Not used } @Override public String getConnectionUrl() { - // TODO Auto-generated method stub - return null; + return null; // Not used } /** diff --git a/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabaseHandler.java b/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabaseHandler.java index 59ace12d5..3967eb46c 100644 --- a/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabaseHandler.java +++ b/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabaseHandler.java @@ -29,9 +29,9 @@ import us.tastybento.bskyblock.util.Util; /** * Class that creates a list of s filled with values from the corresponding * database-table. - * + * * @author tastybento - * + * * @param */ public class FlatFileDatabaseHandler extends AbstractDatabaseHandler { @@ -51,27 +51,27 @@ public class FlatFileDatabaseHandler extends AbstractDatabaseHandler { } @Override protected String createDeleteQuery() { - // TODO Auto-generated method stub - return null; + return ""; // Not used } + /** * Creates a filled with values from the corresponding * database file - * + * * @return filled with values from the corresponding database file - * @throws IntrospectionException - * @throws InvocationTargetException - * @throws IllegalArgumentException - * @throws IllegalAccessException - * @throws InstantiationException - * @throws ClassNotFoundException + * @throws IntrospectionException + * @throws InvocationTargetException + * @throws IllegalArgumentException + * @throws IllegalAccessException + * @throws InstantiationException + * @throws ClassNotFoundException */ @Override public T loadObject(String key) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, IntrospectionException, ClassNotFoundException { YamlConfiguration config = databaseConnecter.loadYamlFile(type.getSimpleName(), key); return createObject(config); } - + @Override public boolean objectExits(String key) { return databaseConnecter.uniqueIdExists(type.getSimpleName(), key); @@ -85,7 +85,7 @@ public class FlatFileDatabaseHandler extends AbstractDatabaseHandler { * @throws IllegalArgumentException * @throws InvocationTargetException * @throws IntrospectionException - * @throws ClassNotFoundException + * @throws ClassNotFoundException */ @Override public List loadObjects() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, IntrospectionException, ClassNotFoundException { @@ -114,19 +114,19 @@ public class FlatFileDatabaseHandler extends AbstractDatabaseHandler { return list; } /** - * + * * Creates a list of s filled with values from the provided ResultSet - * + * * @param config - YAML config file - * + * * @return filled with values - * + * * @throws InstantiationException * @throws IllegalAccessException * @throws IntrospectionException * @throws IllegalArgumentException * @throws InvocationTargetException - * @throws ClassNotFoundException + * @throws ClassNotFoundException */ private T createObject(YamlConfiguration config) throws InstantiationException, IllegalAccessException, IntrospectionException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException { T instance = type.newInstance(); @@ -202,7 +202,7 @@ public class FlatFileDatabaseHandler extends AbstractDatabaseHandler { /** * Inserts T into the corresponding database-table - * + * * @param instance that should be inserted into the database * @throws IllegalAccessException * @throws IllegalArgumentException @@ -300,7 +300,7 @@ public class FlatFileDatabaseHandler extends AbstractDatabaseHandler { return object; } - private Object deserialize(Object value, Class clazz) { + private Object deserialize(Object value, Class clazz) { //plugin.getLogger().info("DEBUG: deserialize - class is " + clazz.getCanonicalName()); if (value instanceof String && value.equals("null")) { // If the value is null as a string, return null @@ -353,7 +353,7 @@ public class FlatFileDatabaseHandler extends AbstractDatabaseHandler { if (tableFolder.exists()) { File file = new File(tableFolder, fileName); file.delete(); - } + } } } diff --git a/src/main/java/us/tastybento/bskyblock/database/managers/AbstractDatabaseHandler.java b/src/main/java/us/tastybento/bskyblock/database/managers/AbstractDatabaseHandler.java index 97e373dba..23a4c2856 100644 --- a/src/main/java/us/tastybento/bskyblock/database/managers/AbstractDatabaseHandler.java +++ b/src/main/java/us/tastybento/bskyblock/database/managers/AbstractDatabaseHandler.java @@ -11,10 +11,7 @@ import us.tastybento.bskyblock.database.DatabaseConnecter; /** * An abstract class that handles insert/select-operations into/from a database - * - * @param - */ -/** + * * @author tastybento * * @param @@ -44,7 +41,7 @@ public abstract class AbstractDatabaseHandler { /** * Constructor - * + * * @param type * The type of the objects that should be created and filled with * values from the database or inserted into the database @@ -71,7 +68,7 @@ public abstract class AbstractDatabaseHandler { protected abstract String createDeleteQuery(); /** - * + * * Creates a comma-separated-String with the names of the variables in this * class * Not used in Flat File database. @@ -108,9 +105,9 @@ public abstract class AbstractDatabaseHandler { * @throws IllegalArgumentException * @throws InvocationTargetException * @throws IntrospectionException - * @throws SecurityException - * @throws SQLException - * @throws ClassNotFoundException + * @throws SecurityException + * @throws SQLException + * @throws ClassNotFoundException */ protected abstract List loadObjects() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, IntrospectionException, SQLException, SecurityException, ClassNotFoundException; @@ -119,42 +116,42 @@ public abstract class AbstractDatabaseHandler { * database file * @param uniqueId * @return - * @throws IntrospectionException - * @throws InvocationTargetException - * @throws IllegalArgumentException - * @throws IllegalAccessException - * @throws InstantiationException - * @throws SQLException - * @throws ClassNotFoundException - * @throws SecurityException + * @throws IntrospectionException + * @throws InvocationTargetException + * @throws IllegalArgumentException + * @throws IllegalAccessException + * @throws InstantiationException + * @throws SQLException + * @throws ClassNotFoundException + * @throws SecurityException */ protected abstract T loadObject(String uniqueId) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, IntrospectionException, SQLException, SecurityException, ClassNotFoundException; /** * Save T into the corresponding database - * + * * @param instance that should be inserted into the database * @throws IllegalAccessException * @throws IllegalArgumentException * @throws InvocationTargetException * @throws IntrospectionException - * @throws InstantiationException - * @throws SecurityException - * @throws SQLException - * @throws NoSuchMethodException + * @throws InstantiationException + * @throws SecurityException + * @throws SQLException + * @throws NoSuchMethodException */ protected abstract void saveObject(T instance) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, IntrospectionException, SQLException, SecurityException, InstantiationException, NoSuchMethodException; /** * Deletes the object with the unique id from the database * @param instance - * @throws InvocationTargetException - * @throws IllegalArgumentException - * @throws IllegalAccessException - * @throws IntrospectionException - * @throws SQLException - * @throws SecurityException - * @throws NoSuchMethodException + * @throws InvocationTargetException + * @throws IllegalArgumentException + * @throws IllegalAccessException + * @throws IntrospectionException + * @throws SQLException + * @throws SecurityException + * @throws NoSuchMethodException */ public abstract void deleteObject(T instance) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, IntrospectionException, SQLException, NoSuchMethodException, SecurityException; diff --git a/src/main/java/us/tastybento/bskyblock/database/managers/IslandsManager.java b/src/main/java/us/tastybento/bskyblock/database/managers/IslandsManager.java index 9e551eb7a..486ea483d 100644 --- a/src/main/java/us/tastybento/bskyblock/database/managers/IslandsManager.java +++ b/src/main/java/us/tastybento/bskyblock/database/managers/IslandsManager.java @@ -60,18 +60,19 @@ public class IslandsManager { */ private HashMap islandsByUUID; // 2D islandGrid of islands, x,z - private TreeMap> islandGrid = new TreeMap>(); + private TreeMap> islandGrid = new TreeMap<>(); /** * One island can be spawn, this is the one - otherwise, this value is null */ private Island spawn; - // Metrics data - private int metrics_createdcount = 0; private AbstractDatabaseHandler handler; private Location last; + // Metrics data + private int metrics_createdcount = 0; + @SuppressWarnings("unchecked") public IslandsManager(BSkyBlock plugin){ this.plugin = plugin; @@ -79,7 +80,7 @@ public class IslandsManager { // Set up the database handler to store and retrieve Island classes handler = (AbstractDatabaseHandler) database.getHandler(plugin, Island.class); islandsByLocation = HashBiMap.create(); - islandsByUUID = new HashMap(); + islandsByUUID = new HashMap<>(); spawn = null; } @@ -100,36 +101,24 @@ public class IslandsManager { addToGrid(island); } } catch (Exception e) { - // TODO Auto-generated catch block e.printStackTrace(); } } public void save(boolean async){ - if(async){ - plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() { - - @Override - public void run() { - for(Island island : islandsByLocation.values()){ - try { - handler.saveObject(island); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } - }); - } else { + Runnable save = () -> { for(Island island : islandsByLocation.values()){ try { handler.saveObject(island); } catch (Exception e) { - // TODO Auto-generated catch block e.printStackTrace(); - } + } } + }; + if(async){ + plugin.getServer().getScheduler().runTaskAsynchronously(plugin, save); + } else { + save.run(); } } @@ -147,10 +136,6 @@ public class IslandsManager { return islandsByLocation.get(location) != null; } - public Island getIsland(Location location){ - return islandsByLocation.get(location); - } - /** * Gets the island for this player. If they are in a team, the team island is returned * @param uuid @@ -234,7 +219,7 @@ public class IslandsManager { /** * Deletes an island from the database. Does not remove blocks - * @param location + * @param island */ public void deleteIslandFromCache(Island island) { islandsByLocation.inverse().remove(island); @@ -296,7 +281,6 @@ public class IslandsManager { try { handler.deleteObject(island); } catch (Exception e) { - // TODO Auto-generated catch block e.printStackTrace(); } // Remove blocks from world @@ -314,16 +298,6 @@ public class IslandsManager { return spawn; } - // Metrics-related methods // - - public int metrics_getCreatedCount(){ - return metrics_createdcount; - } - - public void metrics_setCreatedCount(int count){ - this.metrics_createdcount = count; - } - /** * Removes this player from any and all islands * @param playerUUID @@ -353,7 +327,6 @@ public class IslandsManager { * Puts a player in a team. Removes them from their old island if required. * @param playerUUID * @param teamLeader - * @param islandLocation * @return true if successful, false if not */ public boolean setJoinTeam(UUID playerUUID, UUID teamLeader) { @@ -409,7 +382,7 @@ public class IslandsManager { } // Save the database save(false); - + return true; } @@ -446,7 +419,7 @@ public class IslandsManager { /** * Returns a set of island member UUID's for the island of playerUUID - * + * * @param playerUUID * @return Set of team UUIDs */ @@ -471,9 +444,9 @@ public class IslandsManager { /** * Returns the island at the location or null if there is none. * This includes the full island space, not just the protected area - * + * * @param location - * @return PlayerIsland object + * @return Island object */ public Island getIslandAt(Location location) { if (location == null) { @@ -496,10 +469,10 @@ public class IslandsManager { /** * Returns the island at the x,z location or null if there is none. * This includes the full island space, not just the protected area. - * + * * @param x * @param z - * @return PlayerIsland or null + * @return Island or null */ public Island getIslandAt(int x, int z) { if (DEBUG2) { @@ -540,7 +513,7 @@ public class IslandsManager { /** * Returns the player's island location. * Returns an island location OR a team island location - * + * * @param playerUUID * @return Location of player's island or null if one does not exist */ @@ -557,7 +530,7 @@ public class IslandsManager { public Set getBanList(UUID playerUUID) { // Get player's island Island island = getIsland(playerUUID); - return island == null ? new HashSet(): island.getBanned(); + return island == null ? new HashSet<>(): island.getBanned(); } /** @@ -566,7 +539,7 @@ public class IslandsManager { */ public boolean isOwner(UUID uniqueId) { if (hasIsland(uniqueId)) { - return getIsland(uniqueId).getOwner().equals(uniqueId) ? true : false; + return getIsland(uniqueId).getOwner().equals(uniqueId); } return false; } @@ -574,7 +547,7 @@ public class IslandsManager { /** * This teleports player to their island. If not safe place can be found * then the player is sent to spawn via /spawn command - * + * * @param player * @return true if the home teleport is successful */ @@ -589,7 +562,7 @@ public class IslandsManager { * @return true if successful, false if not */ public boolean homeTeleport(final Player player, int number) { - Location home = null; + Location home; if (DEBUG) plugin.getLogger().info("home teleport called for #" + number); home = getSafeHomeLocation(player.getUniqueId(), number); @@ -628,13 +601,12 @@ public class IslandsManager { player.setGameMode(GameMode.SURVIVAL); } return true; - } /** * Determines a safe teleport spot on player's island or the team island * they belong to. - * + * * @param playerUUID UUID of player * @param number - starting home location e.g., 1 * @return Location of a safe teleport spot or null if one cannot be found @@ -821,7 +793,7 @@ public class IslandsManager { } //plugin.getLogger().info("DEBUG: Radii " + minXradius + "," + minYradius + "," + minZradius + // "," + maxXradius + "," + maxYradius + "," + maxZradius); - } while (minXradius < i || maxXradius < i || minZradius < i || maxZradius < i || minYradius < depth + } while (minXradius < i || maxXradius < i || minZradius < i || maxZradius < i || minYradius < depth || maxYradius < height); // Nothing worked return null; @@ -831,7 +803,7 @@ public class IslandsManager { * Checks if this location is safe for a player to teleport to. Used by * warps and boat exits Unsafe is any liquid or air and also if there's no * space - * + * * @param l * - Location to be checked * @return true if safe, otherwise false @@ -916,7 +888,7 @@ public class IslandsManager { * @param schematic */ public void newIsland(Player player, Schematic schematic) { - newIsland(player, schematic, null); + newIsland(player, schematic, null); } /** @@ -1004,7 +976,7 @@ public class IslandsManager { } } } - } + } // Start the reset cooldown @@ -1013,7 +985,7 @@ public class IslandsManager { //} // Set the custom protection range if appropriate // Dynamic island range sizes with permissions - int range = Settings.islandProtectionRange; + int range = Settings.islandProtectionRange; for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) { if (perms.getPermission().startsWith(Settings.PERMPREFIX + "island.range.")) { if (perms.getPermission().contains(Settings.PERMPREFIX + "island.range.*")) { @@ -1098,7 +1070,7 @@ public class IslandsManager { /** * Finds the next free island spot based off the last known island Uses * island_distance setting from the config file Builds up in a grid fashion - * + * * @param lastIsland * @return Location of next free island */ @@ -1136,7 +1108,7 @@ public class IslandsManager { * This removes players from an island overworld and nether - used when reseting or deleting an island * Mobs are killed when the chunks are refreshed. * @param island to remove players from - * @param uuid + * @param uuid */ public void removePlayersFromIsland(final Island island, UUID uuid) { // Teleport players away @@ -1180,9 +1152,9 @@ public class IslandsManager { /** * Returns the island being public at the location or null if there is none - * + * * @param location - * @return PlayerIsland object + * @return Island object */ public Island getProtectedIslandAt(Location location) { //plugin.getLogger().info("DEBUG: getProtectedIslandAt " + location); @@ -1208,7 +1180,7 @@ public class IslandsManager { /** * Indicates whether a player is at the island spawn or not - * + * * @param playerLoc * @return true if they are, false if they are not, or spawn does not exist */ @@ -1222,7 +1194,7 @@ public class IslandsManager { /** * Checks if a specific location is within the protected range of an island * owned by the player - * + * * @param player * @param loc * @return true if location is on island of player @@ -1281,7 +1253,7 @@ public class IslandsManager { /** * Checks if an online player is in the protected area of their island, a team island or a * coop island - * + * * @param player * @return true if on valid island, false if not */ @@ -1316,7 +1288,7 @@ public class IslandsManager { if (Settings.netherGenerate && Settings.netherIslands && IslandWorld.getNetherWorld() != null) { islandTestLocations.add(netherIsland(plugin.getIslands().getIslandLocation(player.getUniqueId()))); } - } + } // TODO: Check coop locations /* if (coop) { @@ -1370,7 +1342,7 @@ public class IslandsManager { if (islandsByUUID.containsKey(owner)) { Island island = islandsByUUID.get(owner); if (!island.getName().isEmpty()) { - result = island.getName(); + result = island.getName(); } } return ChatColor.translateAlternateColorCodes('&', result) + ChatColor.RESET; @@ -1398,4 +1370,13 @@ public class IslandsManager { return spawn.getSpawnPoint(); } + // Metrics-related methods // + + public int metrics_getCreatedCount(){ + return metrics_createdcount; + } + + public void metrics_setCreatedCount(int count){ + this.metrics_createdcount = count; + } } diff --git a/src/main/java/us/tastybento/bskyblock/database/managers/OfflineHistoryMessages.java b/src/main/java/us/tastybento/bskyblock/database/managers/OfflineHistoryMessages.java index 728859322..05d833705 100644 --- a/src/main/java/us/tastybento/bskyblock/database/managers/OfflineHistoryMessages.java +++ b/src/main/java/us/tastybento/bskyblock/database/managers/OfflineHistoryMessages.java @@ -22,7 +22,7 @@ public class OfflineHistoryMessages { private BSBDatabase database; // Offline Messages - private HashMap> messages = new HashMap>(); + private HashMap> messages = new HashMap<>(); public OfflineHistoryMessages(BSkyBlock plugin){ this.plugin = plugin; @@ -34,16 +34,14 @@ public class OfflineHistoryMessages { } public void save(boolean async){ - if(async){ - plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() { - - @Override - public void run() { - //database.saveOfflineHistoryMessages(messages); - } - }); - } else { + Runnable save = () -> { //database.saveOfflineHistoryMessages(messages); + }; + + if(async){ + plugin.getServer().getScheduler().runTaskAsynchronously(plugin, save); + } else { + save.run(); } } @@ -63,7 +61,7 @@ public class OfflineHistoryMessages { TEAM, ISLAND, DEATH, - PERSONAL; + PERSONAL } /** @@ -115,7 +113,7 @@ public class OfflineHistoryMessages { if (playerMessages != null) { playerMessages.add(message); } else { - playerMessages = new ArrayList(Arrays.asList(message)); + playerMessages = new ArrayList<>(Arrays.asList(message)); } messages.put(playerUUID, playerMessages); } diff --git a/src/main/java/us/tastybento/bskyblock/database/managers/PlayersManager.java b/src/main/java/us/tastybento/bskyblock/database/managers/PlayersManager.java index 296d2fe41..e0d41c491 100644 --- a/src/main/java/us/tastybento/bskyblock/database/managers/PlayersManager.java +++ b/src/main/java/us/tastybento/bskyblock/database/managers/PlayersManager.java @@ -33,7 +33,7 @@ public class PlayersManager{ * Provides a memory cache of online player information * This is the one-stop-shop of player info * If the player is not cached, then a request is made to Players to obtain it - * + * * @param plugin */ @SuppressWarnings("unchecked") @@ -42,8 +42,8 @@ public class PlayersManager{ database = BSBDatabase.getDatabase(); // Set up the database handler to store and retrieve Players classes handler = (AbstractDatabaseHandler) database.getHandler(plugin, Players.class); - playerCache = new HashMap(); - inTeleport = new HashSet(); + playerCache = new HashMap<>(); + inTeleport = new HashSet<>(); } /** @@ -57,7 +57,6 @@ public class PlayersManager{ playerCache.put(player.getPlayerUUID(), player); } } catch (Exception e) { - // TODO Auto-generated catch block e.printStackTrace(); } } @@ -67,30 +66,20 @@ public class PlayersManager{ * @param async - if true, save async */ public void save(boolean async){ - if(async){ - plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() { - - @Override - public void run() { - for(Players player : playerCache.values()){ - try { - handler.saveObject(player); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } - }); - } else { + Runnable save = () -> { for(Players player : playerCache.values()){ try { handler.saveObject(player); } catch (Exception e) { - // TODO Auto-generated catch block e.printStackTrace(); - } + } } + }; + + if(async){ + plugin.getServer().getScheduler().runTaskAsynchronously(plugin, save); + } else { + save.run(); } } @@ -119,7 +108,7 @@ public class PlayersManager{ if (playerUUID == null) return null; if (DEBUG) - plugin.getLogger().info("DEBUG: adding player " + playerUUID); + plugin.getLogger().info("DEBUG: adding player " + playerUUID); if (!playerCache.containsKey(playerUUID)) { if (DEBUG) plugin.getLogger().info("DEBUG: player not in cache"); @@ -149,9 +138,9 @@ public class PlayersManager{ /** * Stores the player's info and removes the player from the cache - * + * * @param player - UUID of player - * + * */ public void removeOnlinePlayer(final UUID player) { // plugin.getLogger().info("Removing player from cache: " + player); @@ -163,7 +152,6 @@ public class PlayersManager{ | InvocationTargetException | SecurityException | InstantiationException | NoSuchMethodException | IntrospectionException | SQLException e) { - // TODO Auto-generated catch block e.printStackTrace(); } } @@ -185,11 +173,11 @@ public class PlayersManager{ /** * Checks if the player is known or not - * + * * @param uniqueID * @return true if player is know, otherwise false */ - public boolean isAKnownPlayer(final UUID uniqueID) { + public boolean isKnown(final UUID uniqueID) { if (uniqueID == null) { return false; } @@ -204,7 +192,7 @@ public class PlayersManager{ /** * Returns the player object for the named player - * + * * @param playerUUID * - String name of player * @return - player object @@ -216,7 +204,7 @@ public class PlayersManager{ /** * Checks if player has an island. - * + * * @param playerUUID * - string name of player * @return true if player has island @@ -228,18 +216,18 @@ public class PlayersManager{ /** * Checks if player is in a Team from cache if available - * + * * @param playerUUID * @return true if player in a team */ public boolean inTeam(final UUID playerUUID) { addPlayer(playerUUID); - return plugin.getIslands().getMembers(playerUUID).size() > 1 ? true: false; + return plugin.getIslands().getMembers(playerUUID).size() > 1; } /** * Clears player home locations - * + * * @param playerUUID */ public void clearPlayerHomes(UUID playerUUID) { @@ -283,9 +271,9 @@ public class PlayersManager{ /** * Returns the home location, or null if none - * + * * @param playerUUID - * @param number + * @param number * @return Home location or null if none */ public Location getHomeLocation(UUID playerUUID, int number) { @@ -333,7 +321,7 @@ public class PlayersManager{ // Look in the database if it ready // TODO: finish this! return Bukkit.getOfflinePlayer(string).getUniqueId(); - + //return database.getUUID(string, adminCheck); } @@ -351,7 +339,7 @@ public class PlayersManager{ /** * Obtains the name of the player from their UUID * Player must have logged into the game before - * + * * @param playerUUID * @return String - playerName */ @@ -365,7 +353,7 @@ public class PlayersManager{ /** * Reverse lookup - returns the owner of an island from the location - * + * * @param loc * @return UUID of owner of island */ @@ -382,7 +370,7 @@ public class PlayersManager{ /** * Gets how many island resets the player has left - * + * * @param playerUUID * @return number of resets */ @@ -393,7 +381,7 @@ public class PlayersManager{ /** * Sets how many resets the player has left - * + * * @param playerUUID * @param resets */ @@ -405,7 +393,7 @@ public class PlayersManager{ /** * Returns how long the player must wait before they can be invited to an * island with the location - * + * * @param playerUUID * @param location * @return time to wait in minutes/hours @@ -419,7 +407,7 @@ public class PlayersManager{ * Starts the timer for the player for this location before which they can * be invited * Called when they are kicked from an island or leave. - * + * * @param playerUUID * @param location */ @@ -435,9 +423,7 @@ public class PlayersManager{ */ public String getLocale(UUID playerUUID) { addPlayer(playerUUID); - if (playerUUID == null) { - return ""; - } + if (playerUUID == null) return ""; return playerCache.get(playerUUID).getLocale(); } @@ -472,9 +458,9 @@ public class PlayersManager{ * Unban target from player's island * @param playerUUID * @param targetUUID - * @return + * @return */ - public boolean unBan(UUID playerUUID, UUID targetUUID) { + public boolean unban(UUID playerUUID, UUID targetUUID) { addPlayer(playerUUID); addPlayer(targetUUID); Island island = plugin.getIslands().getIsland(playerUUID); @@ -517,7 +503,7 @@ public class PlayersManager{ public void clearResets(int resetLimit) { for (Players player : playerCache.values()) { player.setResetsLeft(resetLimit); - } + } } /** @@ -575,7 +561,7 @@ public class PlayersManager{ * @param uniqueId */ public void setInTeleport(UUID uniqueId) { - inTeleport.add(uniqueId); + inTeleport.add(uniqueId); } /** @@ -583,7 +569,7 @@ public class PlayersManager{ * @param uniqueId */ public void removeInTeleport(UUID uniqueId) { - inTeleport.remove(uniqueId); + inTeleport.remove(uniqueId); } /** @@ -591,7 +577,7 @@ public class PlayersManager{ * @return true if a player is mid-teleport */ public boolean isInTeleport(UUID uniqueId) { - return inTeleport.contains(uniqueId); + return inTeleport.contains(uniqueId); } /** @@ -618,7 +604,6 @@ public class PlayersManager{ | InvocationTargetException | SecurityException | InstantiationException | NoSuchMethodException | IntrospectionException | SQLException e) { - // TODO Auto-generated catch block e.printStackTrace(); } } else { diff --git a/src/main/java/us/tastybento/bskyblock/database/mysql/MySQLDatabaseConnecter.java b/src/main/java/us/tastybento/bskyblock/database/mysql/MySQLDatabaseConnecter.java index 554208573..1bf9df8b3 100644 --- a/src/main/java/us/tastybento/bskyblock/database/mysql/MySQLDatabaseConnecter.java +++ b/src/main/java/us/tastybento/bskyblock/database/mysql/MySQLDatabaseConnecter.java @@ -10,11 +10,11 @@ import us.tastybento.bskyblock.database.DatabaseConnecter; import us.tastybento.bskyblock.database.DatabaseConnectionSettingsImpl; public class MySQLDatabaseConnecter implements DatabaseConnecter { - + private String connectionUrl; private DatabaseConnectionSettingsImpl dbSettings; private Connection connection = null; - + /** * Class for MySQL database connections using the settings provided * @param dbSettings @@ -57,7 +57,7 @@ public class MySQLDatabaseConnecter implements DatabaseConnecter { @Override public void saveYamlFile(YamlConfiguration yamlFile, String tableName, String fileName) { // Not used - + } @Override diff --git a/src/main/java/us/tastybento/bskyblock/database/mysql/MySQLDatabaseHandler.java b/src/main/java/us/tastybento/bskyblock/database/mysql/MySQLDatabaseHandler.java index ba1028f2f..d07fff865 100644 --- a/src/main/java/us/tastybento/bskyblock/database/mysql/MySQLDatabaseHandler.java +++ b/src/main/java/us/tastybento/bskyblock/database/mysql/MySQLDatabaseHandler.java @@ -36,11 +36,11 @@ import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler; import us.tastybento.bskyblock.util.Util; /** - * + * * Class that inserts a into the corresponding database-table. - * + * * @author tastybento - * + * * @param */ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { @@ -54,7 +54,7 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { */ private static HashMap mySQLmapping; { - mySQLmapping = new HashMap(); + mySQLmapping = new HashMap<>(); mySQLmapping.put(boolean.class.getTypeName(), "BOOL"); mySQLmapping.put(byte.class.getTypeName(), "TINYINT"); mySQLmapping.put(short.class.getTypeName(), "SMALLINT"); @@ -106,10 +106,8 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { try { createSchema(); } catch (IntrospectionException e) { - // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { - // TODO Auto-generated catch block e.printStackTrace(); } } @@ -169,7 +167,7 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { sql += " PRIMARY KEY (uniqueId))"; //plugin.getLogger().info("DEBUG: SQL string = " + sql); // Prepare and execute the database statements - pstmt = connection.prepareStatement(sql.toString()); + pstmt = connection.prepareStatement(sql); pstmt.executeUpdate(); } catch (Exception e) { e.printStackTrace(); @@ -293,12 +291,12 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { @Override protected String createDeleteQuery() { - return "DELETE FROM [table_name] WHERE uniqueId = ?"; + return "DELETE FROM [table_name] WHERE uniqueId = ?"; } /** * Inserts a into the corresponding database-table - * + * * @param instance that should be inserted into the corresponding database-table. Must extend DataObject. * @throws SQLException * @throws SecurityException @@ -307,16 +305,16 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { * @throws IllegalAccessException * @throws IntrospectionException * @throws InvocationTargetException - * @throws NoSuchMethodException + * @throws NoSuchMethodException */ /* (non-Javadoc) * @see us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler#insertObject(java.lang.Object) */ @Override public void saveObject(T instance) throws SQLException, - SecurityException, IllegalArgumentException, - InstantiationException, IllegalAccessException, - IntrospectionException, InvocationTargetException, NoSuchMethodException { + SecurityException, IllegalArgumentException, + InstantiationException, IllegalAccessException, + IntrospectionException, InvocationTargetException, NoSuchMethodException { Connection connection = null; PreparedStatement preparedStatement = null; @@ -437,7 +435,7 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { * @param clazz - the known class of value * @return the object to write to the database */ - private Object serialize(Object value, Class clazz) { + private Object serialize(Object value, Class clazz) { //plugin.getLogger().info("DEBUG: serialize - class is " + clazz.getTypeName()); if (value == null) { // If the value is null to start, return null as a string @@ -446,22 +444,22 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { // Types that need to be serialized // TODO - add others, like Date, Timestamp, etc. if (clazz.equals(UUID.class)) { - value = ((UUID)value).toString(); - } + value = value.toString(); + } else // Bukkit Types if (clazz.equals(Location.class)) { // Serialize value = Util.getStringLocation(((Location)value)); } else - if (clazz.equals(World.class)) { - // Serialize - get the name - value = ((World)value).getName(); - } else - if (clazz.getSuperclass() != null && clazz.getSuperclass().equals(Enum.class)) { - //Custom enums are a child of the Enum class. Just get the names of each one. - value = ((Enum)value).name(); - } + if (clazz.equals(World.class)) { + // Serialize - get the name + value = ((World)value).getName(); + } else + if (clazz.getSuperclass() != null && clazz.getSuperclass().equals(Enum.class)) { + //Custom enums are a child of the Enum class. Just get the names of each one. + value = ((Enum)value).name(); + } if (value == null) { // The value could become null from the above checks return "null"; @@ -473,10 +471,10 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { /** * Creates a list of s filled with values from the corresponding * database-table - * + * * @return List of s filled with values from the corresponding * database-table - * + * * @throws SQLException * @throws SecurityException * @throws IllegalArgumentException @@ -484,13 +482,13 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { * @throws IllegalAccessException * @throws IntrospectionException * @throws InvocationTargetException - * @throws ClassNotFoundException + * @throws ClassNotFoundException */ @Override public List loadObjects() throws SQLException, - SecurityException, IllegalArgumentException, - InstantiationException, IllegalAccessException, - IntrospectionException, InvocationTargetException, ClassNotFoundException { + SecurityException, IllegalArgumentException, + InstantiationException, IllegalAccessException, + IntrospectionException, InvocationTargetException, ClassNotFoundException { Connection connection = null; Statement statement = null; @@ -515,8 +513,8 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { */ @Override protected T loadObject(String uniqueId) throws InstantiationException, - IllegalAccessException, IllegalArgumentException, - InvocationTargetException, IntrospectionException, SQLException, SecurityException, ClassNotFoundException { + IllegalAccessException, IllegalArgumentException, + InvocationTargetException, IntrospectionException, SQLException, SecurityException, ClassNotFoundException { Connection connection = null; Statement statement = null; ResultSet resultSet = null; @@ -543,15 +541,15 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { /** - * + * * Creates a list of s filled with values from the provided ResultSet - * + * * @param resultSet * ResultSet that contains the result of the * database-select-query - * + * * @return List of s filled with values from the provided ResultSet - * + * * @throws SecurityException * @throws IllegalArgumentException * @throws SQLException @@ -559,7 +557,7 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { * @throws IllegalAccessException * @throws IntrospectionException * @throws InvocationTargetException - * @throws ClassNotFoundException + * @throws ClassNotFoundException */ @SuppressWarnings("unchecked") private List createObjects(ResultSet resultSet) @@ -608,7 +606,7 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { // Set the unique ID collStatement.setObject(1, uniqueId); //plugin.getLogger().info("DEBUG: collStatement = " + collStatement.toString()); - ResultSet collectionResultSet = collStatement.executeQuery(); + ResultSet collectionResultSet = collStatement.executeQuery(); //plugin.getLogger().info("DEBUG: collectionResultSet = " + collectionResultSet.toString()); // Do single dimension types (set and list) if (propertyDescriptor.getPropertyType().equals(Set.class)) { @@ -689,7 +687,7 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { * @return the deserialized value */ @SuppressWarnings({ "unchecked", "rawtypes" }) - private Object deserialize(Object value, Class clazz) { + private Object deserialize(Object value, Class clazz) { //plugin.getLogger().info("DEBUG: deserialize - class is " + clazz.getTypeName()); if (value instanceof String && value.equals("null")) { // If the value is null as a string, return null @@ -777,7 +775,7 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { } finally { // Close properly MySQLDatabaseResourceCloser.close(preparedStatement); - } + } } @@ -797,7 +795,6 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { resultSet = preparedStatement.executeQuery(); return resultSet.next(); } catch (SQLException e) { - // TODO Auto-generated catch block e.printStackTrace(); } finally { MySQLDatabaseResourceCloser.close(resultSet); diff --git a/src/main/java/us/tastybento/bskyblock/database/mysql/MySQLDatabaseResourceCloser.java b/src/main/java/us/tastybento/bskyblock/database/mysql/MySQLDatabaseResourceCloser.java index 2d3f74c36..125f64184 100644 --- a/src/main/java/us/tastybento/bskyblock/database/mysql/MySQLDatabaseResourceCloser.java +++ b/src/main/java/us/tastybento/bskyblock/database/mysql/MySQLDatabaseResourceCloser.java @@ -9,7 +9,7 @@ public class MySQLDatabaseResourceCloser { /** * Closes the provided ResultSets - * + * * @param resultSets * ResultSets that should be closed */ @@ -18,19 +18,21 @@ public class MySQLDatabaseResourceCloser { if (resultSets == null) return; - for (ResultSet resultSet : resultSets) - if (resultSet != null) + for (ResultSet resultSet : resultSets) { + if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { /* Do some exception-logging here. */ e.printStackTrace(); } + } + } } /** * Closes the provided Statements - * + * * @param statements * Statements that should be closed */ @@ -43,35 +45,38 @@ public class MySQLDatabaseResourceCloser { if (statements == null) return; - for (Statement statement : statements) - if (statement != null) + for (Statement statement : statements) { + if (statement != null) { try { statement.close(); } catch (SQLException e) { /* Do some exception-logging here. */ e.printStackTrace(); } + } + } } /** * Closes the provided Connections - * + * * @param connections * Connections that should be closed */ public static void close(Connection... connections) { - if (connections == null) return; - for (Connection connection : connections) - if (connection != null) + for (Connection connection : connections) { + if (connection != null) { try { connection.close(); } catch (SQLException e) { /* Do some exception-logging here. */ e.printStackTrace(); } + } + } } } diff --git a/src/main/java/us/tastybento/bskyblock/database/objects/Island.java b/src/main/java/us/tastybento/bskyblock/database/objects/Island.java index 739826819..b5a4903c2 100755 --- a/src/main/java/us/tastybento/bskyblock/database/objects/Island.java +++ b/src/main/java/us/tastybento/bskyblock/database/objects/Island.java @@ -22,7 +22,7 @@ import us.tastybento.bskyblock.util.Util; * Stores all the info about an island * Managed by IslandsManager * Responsible for team information as well. - * + * * @author Tastybento * @author Poslovitch */ @@ -42,19 +42,18 @@ public class Island extends DataObject { @Override public void setUniqueId(String uniqueId) { this.uniqueId = uniqueId; - } /** * Island Guard Settings flags * Covers island, spawn and system settings - * + * * @author Tastybento */ public enum SettingsFlag{ - + ACID_DAMAGE, - + // Can use Anvil ANVIL, @@ -78,7 +77,7 @@ public class Island extends DataObject { // Can use buttons BUTTON, - + // Can empty or fill buckets BUCKET, @@ -108,7 +107,7 @@ public class Island extends DataObject { // Can open doors DOOR, - + // Can open trapdoors, iron or wood TRAPDOOR, @@ -144,7 +143,7 @@ public class Island extends DataObject { // Can open gates GATE, - + // Can hurt animals (e.g. cows) - Villagers excluded HURT_ANIMALS, @@ -207,16 +206,16 @@ public class Island extends DataObject { // Can activate pressure plates PRESSURE_PLATE, - + // Can do PvP in the overworld PVP_OVERWORLD, // Can do PvP in the nether PVP_NETHER, - + // Can do PvP in the end PVP_END, - + // Can interact with redstone items (repeaters, comparators) REDSTONE, @@ -240,7 +239,7 @@ public class Island extends DataObject { // Can throw splash potions THROW_SPLASH_POTIONS, - + // Can throw lingering potions THROW_LINGERING_POTIONS, @@ -249,10 +248,10 @@ public class Island extends DataObject { // Allow TNT to destroy blocks TNT_GRIEFING, - + // Allow TNTs to blow up any chest or inventory block (only if TNT_griefing is enabled) TNT_BLOW_UP_CHEST, - + // Can trade with villagers VILLAGER_TRADING } @@ -285,7 +284,6 @@ public class Island extends DataObject { // Time parameters private long createdDate; - private long updatedDate; //// Team //// @@ -293,27 +291,27 @@ public class Island extends DataObject { private UUID owner; // Members (use set because each value must be unique) - private Set members = new HashSet(); + private Set members = new HashSet<>(); // Trustees - private Set trustees = new HashSet(); + private Set trustees = new HashSet<>(); // Coops - private Set coops = new HashSet(); + private Set coops = new HashSet<>(); // Banned players - private Set banned = new HashSet(); + private Set banned = new HashSet<>(); //// State //// private boolean locked = false; private boolean spawn = false; private boolean purgeProtected = false; //// Protection //// - private HashMap flags = new HashMap(); + private HashMap flags = new HashMap<>(); private int levelHandicap; private Location spawnPoint; - public Island() {}; + public Island() {} public Island(Location location, UUID owner, int protectionRange) { this.members.add(owner); @@ -336,8 +334,8 @@ public class Island extends DataObject { public void addMember(UUID playerUUID) { members.add(playerUUID); banned.remove(playerUUID); - } + /** * Adds target to a list of banned players for this island. May be blocked by the event being cancelled. * If the player is a member, coop or trustee, they will be removed from those lists. @@ -365,25 +363,28 @@ public class Island extends DataObject { public Set getBanned() { return banned; } + /** * @return the center Location */ public Location getCenter(){ return center; } + /** * @return the coop players of the island */ public Set getCoops(){ return coops; } + /** * @return the date when the island was created */ public long getCreatedDate(){ return createdDate; } - + /** * Get the Island Guard flag status * @param flag @@ -408,15 +409,17 @@ public class Island extends DataObject { public HashMap getFlags() { return flags; } + /** * @return the members of the island (owner included) */ public Set getMembers(){ if (members == null) { - members = new HashSet(); + members = new HashSet<>(); } return members; } + /** * @return the minProtectedX */ @@ -449,15 +452,15 @@ public class Island extends DataObject { * @return the island display name or the owner's name if none is set */ public String getName() { - if (name != null) { - return name; - } - if (owner != null) { - OfflinePlayer player = Bukkit.getServer().getOfflinePlayer(owner); - name = player.getName(); - return player.getName(); - } - return ""; + if (name != null) { + return name; + } + if (owner != null) { + OfflinePlayer player = Bukkit.getServer().getOfflinePlayer(owner); + name = player.getName(); + return player.getName(); + } + return ""; } /** @@ -569,7 +572,7 @@ public class Island extends DataObject { /** * Checks if a location is within this island's protected area - * + * * @param target * @return true if it is, false if not */ @@ -789,7 +792,7 @@ public class Island extends DataObject { */ public void toggleFlag(SettingsFlag flag){ if(flags.containsKey(flag)) { - flags.put(flag, (flags.get(flag)) ? false : true); + flags.put(flag, (flags.get(flag))); } } @@ -827,7 +830,7 @@ public class Island extends DataObject { * a tile entity. */ public int getTileEntityCount(Material material, World world) { - int result = 0; + int result = 0; for (int x = getMinProtectedX() /16; x <= (getMinProtectedX() + getProtectionRange() - 1)/16; x++) { for (int z = getMinProtectedZ() /16; z <= (getMinProtectedZ() + getProtectionRange() - 1)/16; z++) { for (BlockState holder : world.getChunkAt(x, z).getTileEntities()) { @@ -860,7 +863,7 @@ public class Island extends DataObject { result++; } } - } + } } return result; } @@ -882,6 +885,6 @@ public class Island extends DataObject { } public void removeMember(UUID playerUUID) { - this.members.remove(playerUUID); + this.members.remove(playerUUID); } } \ No newline at end of file diff --git a/src/main/java/us/tastybento/bskyblock/database/objects/Players.java b/src/main/java/us/tastybento/bskyblock/database/objects/Players.java index 5abfae3b8..0df819822 100755 --- a/src/main/java/us/tastybento/bskyblock/database/objects/Players.java +++ b/src/main/java/us/tastybento/bskyblock/database/objects/Players.java @@ -13,7 +13,7 @@ import us.tastybento.bskyblock.config.Settings; /** * Tracks the following info on the player - * + * * @author tastybento */ public class Players extends DataObject { @@ -34,16 +34,16 @@ public class Players extends DataObject { /** * @param uniqueId * Constructor - initializes the state variables - * + * */ public Players(final UUID uniqueId) { this.uniqueId = uniqueId; - this.homeLocations = new HashMap(); + this.homeLocations = new HashMap<>(); this.playerName = ""; this.resetsLeft = Settings.resetLimit; this.locale = ""; this.useControlPanel = Settings.useControlPanel; - this.kickedList = new HashMap(); + this.kickedList = new HashMap<>(); this.playerName = Bukkit.getServer().getOfflinePlayer(uniqueId).getName(); } @@ -70,7 +70,7 @@ public class Players extends DataObject { if (number == en.getKey()) Bukkit.getLogger().info("DEBUG: key = number"); }*/ - return homeLocations.get(Integer.valueOf(number)); + return homeLocations.get(number); } /** @@ -156,7 +156,7 @@ public class Players extends DataObject { /** * Stores the home location of the player in a String format - * + * * @param l * a Bukkit location */ @@ -251,7 +251,7 @@ public class Players extends DataObject { /** * Can invite or still waiting for cool down to end - * + * * @param location * to check * @return number of mins/hours left until cool down ends diff --git a/src/main/java/us/tastybento/bskyblock/database/sqlite/SQLiteDatabase.java b/src/main/java/us/tastybento/bskyblock/database/sqlite/SQLiteDatabase.java index 69518c744..caa6f3827 100755 --- a/src/main/java/us/tastybento/bskyblock/database/sqlite/SQLiteDatabase.java +++ b/src/main/java/us/tastybento/bskyblock/database/sqlite/SQLiteDatabase.java @@ -8,9 +8,8 @@ public class SQLiteDatabase extends BSBDatabase{ @Override public AbstractDatabaseHandler getHandler(BSkyBlock plugin, Class type) { - // return new SQLLiteDatabaseHandler(plugin, Island.class, new FlatFileDatabaseConnecter(plugin, null)); + // return new SQLLiteDatabaseHandler(plugin, Island.class, new FlatFileDatabaseConnecter(plugin, null)); return null; } - } diff --git a/src/main/java/us/tastybento/bskyblock/generators/ChunkGeneratorWorld.java b/src/main/java/us/tastybento/bskyblock/generators/ChunkGeneratorWorld.java index c97c96407..57d9ae2c9 100644 --- a/src/main/java/us/tastybento/bskyblock/generators/ChunkGeneratorWorld.java +++ b/src/main/java/us/tastybento/bskyblock/generators/ChunkGeneratorWorld.java @@ -1,4 +1,4 @@ - package us.tastybento.bskyblock.generators; +package us.tastybento.bskyblock.generators; import java.util.Arrays; import java.util.List; @@ -35,7 +35,7 @@ public class ChunkGeneratorWorld extends ChunkGenerator { for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { for (int y = 0; y < Settings.seaHeight; y++) { - setBlock(result, x, y, z, (byte) Material.STATIONARY_WATER.getId()); + setBlock(result, x, y, z, (byte) Material.STATIONARY_WATER.getId()); } } } @@ -111,33 +111,33 @@ public class ChunkGeneratorWorld extends ChunkGenerator { if (r > 0.5D) { // Have blobs of glowstone switch (random.nextInt(4)) { - case 1: - // Single block - setBlock(result, x, (maxHeight - 8), z, (byte) Material.GLOWSTONE.getId()); - if (x < 14 && z < 14) { - setBlock(result, x + 1, (maxHeight - 8), z + 1, (byte) Material.GLOWSTONE.getId()); - setBlock(result, x + 2, (maxHeight - 8), z + 2, (byte) Material.GLOWSTONE.getId()); - setBlock(result, x + 1, (maxHeight - 8), z + 2, (byte) Material.GLOWSTONE.getId()); - setBlock(result, x + 1, (maxHeight - 8), z + 2, (byte) Material.GLOWSTONE.getId()); - } - break; - case 2: - // Stalatite - for (int i = 0; i < random.nextInt(10); i++) { - setBlock(result, x, (maxHeight - 8 - i), z, (byte) Material.GLOWSTONE.getId()); - } - case 3: - setBlock(result, x, (maxHeight - 8), z, (byte) Material.GLOWSTONE.getId()); - if (x > 3 && z > 3) { - for (int xx = 0; xx < 3; xx++) { - for (int zz = 0; zz < 3; zz++) { - setBlock(result, x - xx, (maxHeight - 8 - random.nextInt(2)), z - xx, (byte) Material.GLOWSTONE.getId()); + case 1: + // Single block + setBlock(result, x, (maxHeight - 8), z, (byte) Material.GLOWSTONE.getId()); + if (x < 14 && z < 14) { + setBlock(result, x + 1, (maxHeight - 8), z + 1, (byte) Material.GLOWSTONE.getId()); + setBlock(result, x + 2, (maxHeight - 8), z + 2, (byte) Material.GLOWSTONE.getId()); + setBlock(result, x + 1, (maxHeight - 8), z + 2, (byte) Material.GLOWSTONE.getId()); + setBlock(result, x + 1, (maxHeight - 8), z + 2, (byte) Material.GLOWSTONE.getId()); + } + break; + case 2: + // Stalatite + for (int i = 0; i < random.nextInt(10); i++) { + setBlock(result, x, (maxHeight - 8 - i), z, (byte) Material.GLOWSTONE.getId()); + } + case 3: + setBlock(result, x, (maxHeight - 8), z, (byte) Material.GLOWSTONE.getId()); + if (x > 3 && z > 3) { + for (int xx = 0; xx < 3; xx++) { + for (int zz = 0; zz < 3; zz++) { + setBlock(result, x - xx, (maxHeight - 8 - random.nextInt(2)), z - xx, (byte) Material.GLOWSTONE.getId()); + } } } - } - break; - default: - setBlock(result, x, (maxHeight - 8), z, (byte) Material.GLOWSTONE.getId()); + break; + default: + setBlock(result, x, (maxHeight - 8), z, (byte) Material.GLOWSTONE.getId()); } setBlock(result, x, (maxHeight - 8), z, (byte) Material.GLOWSTONE.getId()); } else { diff --git a/src/main/java/us/tastybento/bskyblock/generators/IslandWorld.java b/src/main/java/us/tastybento/bskyblock/generators/IslandWorld.java index 47744781f..96c6834fb 100644 --- a/src/main/java/us/tastybento/bskyblock/generators/IslandWorld.java +++ b/src/main/java/us/tastybento/bskyblock/generators/IslandWorld.java @@ -16,10 +16,7 @@ public class IslandWorld { private static World endWorld; /** - * Returns the World object for the island world named in config.yml. - * If the world does not exist then it is created. - * - * @return Bukkit World object for the BSkyBlock overworld + * Generates the Skyblock worlds. */ public IslandWorld(BSkyBlock plugin) { if (Settings.useOwnGenerator) { diff --git a/src/main/java/us/tastybento/bskyblock/generators/NetherPopulator.java b/src/main/java/us/tastybento/bskyblock/generators/NetherPopulator.java index b7d9367ea..089774df2 100644 --- a/src/main/java/us/tastybento/bskyblock/generators/NetherPopulator.java +++ b/src/main/java/us/tastybento/bskyblock/generators/NetherPopulator.java @@ -18,7 +18,7 @@ import org.bukkit.inventory.ItemStack; /** * @author tastybento * Populates the Nether with appropriate blocks - * + * */ public class NetherPopulator extends BlockPopulator { @@ -32,17 +32,17 @@ public class NetherPopulator extends BlockPopulator { if (b.getType().equals(Material.MOB_SPAWNER)) { CreatureSpawner cs = (CreatureSpawner) b.getState(); switch (random.nextInt(3)) { - case 0: - cs.setSpawnedType(EntityType.BLAZE); - break; - case 1: - cs.setSpawnedType(EntityType.SKELETON); - break; - case 2: - cs.setSpawnedType(EntityType.MAGMA_CUBE); - break; - default: - cs.setSpawnedType(EntityType.BLAZE); + case 0: + cs.setSpawnedType(EntityType.BLAZE); + break; + case 1: + cs.setSpawnedType(EntityType.SKELETON); + break; + case 2: + cs.setSpawnedType(EntityType.MAGMA_CUBE); + break; + default: + cs.setSpawnedType(EntityType.BLAZE); } } else if (b.getType().equals(Material.OBSIDIAN)) { b.setType(Material.CHEST); diff --git a/src/main/java/us/tastybento/bskyblock/listeners/JoinLeaveListener.java b/src/main/java/us/tastybento/bskyblock/listeners/JoinLeaveListener.java index 188acab45..c9b52ca4e 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/JoinLeaveListener.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/JoinLeaveListener.java @@ -41,7 +41,7 @@ public class JoinLeaveListener implements Listener { if (playerUUID == null) { return; } - if (plugin.getPlayers().isAKnownPlayer(playerUUID)) { + if (plugin.getPlayers().isKnown(playerUUID)) { if (DEBUG) plugin.getLogger().info("DEBUG: known player"); // Load player diff --git a/src/main/java/us/tastybento/bskyblock/listeners/NetherPortals.java b/src/main/java/us/tastybento/bskyblock/listeners/NetherPortals.java index cf993fda2..003d00f8c 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/NetherPortals.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/NetherPortals.java @@ -37,7 +37,7 @@ public class NetherPortals implements Listener { /** * This handles non-player portal use * Currently disables portal use by entities - * + * * @param event */ @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @@ -85,7 +85,7 @@ public class NetherPortals implements Listener { } // Vehicles if (event.getEntity() instanceof Vehicle) { - Vehicle vehicle = (Vehicle)event.getEntity(); + Vehicle vehicle = (Vehicle)event.getEntity(); vehicle.eject(); } new SafeSpotTeleport(plugin, event.getEntity(), dest); @@ -112,7 +112,7 @@ public class NetherPortals implements Listener { // Check if player has permission Island island = plugin.getIslands().getIslandAt(currentLocation); // TODO: if ((island == null && !Settings.defaultWorldSettings.get(SettingsFlag.PORTAL)) - if (island == null + if (island == null || (island != null && !(island.getFlag(SettingsFlag.PORTAL) || island.getMembers().contains(event.getPlayer().getUniqueId())))) { // Portals use is not allowed if (DEBUG) @@ -125,131 +125,131 @@ public class NetherPortals implements Listener { } // Determine what portal it is switch (event.getCause()) { - case END_PORTAL: - if (DEBUG) - plugin.getLogger().info("DEBUG: End portal"); - // Same action for all worlds except the end itself - if (!event.getFrom().getWorld().getEnvironment().equals(Environment.THE_END)) { - if (plugin.getServer().getWorld(Settings.worldName + "_the_end") != null) { - // The end exists - event.setCancelled(true); - Location end_place = plugin.getServer().getWorld(Settings.worldName + "_the_end").getSpawnLocation(); - if (IslandsManager.isSafeLocation(end_place)) { - event.getPlayer().teleport(end_place); - // event.getPlayer().sendBlockChange(end_place, - // end_place.getBlock().getType(),end_place.getBlock().getData()); - return; - } else { - Util.sendMessage(event.getPlayer(), ChatColor.RED + plugin.getLocale(event.getPlayer().getUniqueId()).get("warps.error.NotSafe")); - plugin.getIslands().homeTeleport(event.getPlayer()); - return; - } - } - } else { - event.setCancelled(true); - plugin.getIslands().homeTeleport(event.getPlayer()); - } - break; - case NETHER_PORTAL: - if (DEBUG) - plugin.getLogger().info("DEBUG: nether portal"); - // Get the home world of this player - World homeWorld = IslandWorld.getIslandWorld(); - Location home = plugin.getPlayers().getHomeLocation(event.getPlayer().getUniqueId()); - if (home != null) { - homeWorld = home.getWorld(); - } - if (!Settings.netherIslands) { - // Legacy action - if (event.getFrom().getWorld().getEnvironment().equals(Environment.NORMAL)) { - // Going to Nether - if (homeWorld.getEnvironment().equals(Environment.NORMAL)) { - // Home world is over world - event.setTo(IslandWorld.getNetherWorld().getSpawnLocation()); - event.useTravelAgent(true); - } else { - // Home world is nether - going home - event.useTravelAgent(false); - Location dest = plugin.getIslands().getSafeHomeLocation(playerUUID,1); - if (dest != null) { - event.setTo(dest); + case END_PORTAL: + if (DEBUG) + plugin.getLogger().info("DEBUG: End portal"); + // Same action for all worlds except the end itself + if (!event.getFrom().getWorld().getEnvironment().equals(Environment.THE_END)) { + if (plugin.getServer().getWorld(Settings.worldName + "_the_end") != null) { + // The end exists + event.setCancelled(true); + Location end_place = plugin.getServer().getWorld(Settings.worldName + "_the_end").getSpawnLocation(); + if (IslandsManager.isSafeLocation(end_place)) { + event.getPlayer().teleport(end_place); + // event.getPlayer().sendBlockChange(end_place, + // end_place.getBlock().getType(),end_place.getBlock().getData()); + return; } else { - event.setCancelled(true); - new SafeSpotTeleport(plugin, event.getPlayer(), plugin.getIslands().getIslandLocation(playerUUID), 1); - } + Util.sendMessage(event.getPlayer(), ChatColor.RED + plugin.getLocale(event.getPlayer().getUniqueId()).get("warps.error.NotSafe")); + plugin.getIslands().homeTeleport(event.getPlayer()); + return; + } } } else { - // Going to Over world - if (homeWorld.getEnvironment().equals(Environment.NORMAL)) { - // Home world is over world - event.useTravelAgent(false); - Location dest = plugin.getIslands().getSafeHomeLocation(playerUUID,1); - if (dest != null) { - event.setTo(dest); - } else { - event.setCancelled(true); - new SafeSpotTeleport(plugin, event.getPlayer(), plugin.getIslands().getIslandLocation(playerUUID), 1); - } - } else { - // Home world is nether - event.setTo(IslandWorld.getIslandWorld().getSpawnLocation()); - event.useTravelAgent(true); - } - } - } else { - // Island Nether - if (DEBUG) - plugin.getLogger().info("DEBUG: Island nether"); - // Get location of the island where the player is at - if (island == null) { - if (DEBUG) - plugin.getLogger().info("DEBUG: island is null"); event.setCancelled(true); - return; + plugin.getIslands().homeTeleport(event.getPlayer()); } - // Can go both ways now - Location overworldIsland = island.getCenter().toVector().toLocation(IslandWorld.getIslandWorld()); - Location netherIsland = island.getCenter().toVector().toLocation(IslandWorld.getNetherWorld()); - //Location dest = event.getFrom().toVector().toLocation(IslandWorld.getIslandWorld()); - if (event.getFrom().getWorld().getEnvironment().equals(Environment.NORMAL)) { - // Going to Nether - // Check that there is a nether island there. Due to legacy reasons it may not exist - if (DEBUG) - plugin.getLogger().info("DEBUG: island center = " + island.getCenter()); - if (netherIsland.getBlock().getType() != Material.BEDROCK) { - // Check to see if there is anything there - if (plugin.getIslands().bigScan(netherIsland, 20) == null) { - if (DEBUG) - plugin.getLogger().info("DEBUG: big scan is null"); - plugin.getLogger().warning("Creating nether island for " + event.getPlayer().getName() + " using default nether schematic"); - Schematic nether = plugin.getSchematics().getSchematic("nether"); - if (nether != null) { - if (DEBUG) - plugin.getLogger().info("DEBUG: pasting at " + island.getCenter().toVector()); - nether.pasteSchematic(netherIsland, event.getPlayer(), false, PasteReason.PARTNER, island); + break; + case NETHER_PORTAL: + if (DEBUG) + plugin.getLogger().info("DEBUG: nether portal"); + // Get the home world of this player + World homeWorld = IslandWorld.getIslandWorld(); + Location home = plugin.getPlayers().getHomeLocation(event.getPlayer().getUniqueId()); + if (home != null) { + homeWorld = home.getWorld(); + } + if (!Settings.netherIslands) { + // Legacy action + if (event.getFrom().getWorld().getEnvironment().equals(Environment.NORMAL)) { + // Going to Nether + if (homeWorld.getEnvironment().equals(Environment.NORMAL)) { + // Home world is over world + event.setTo(IslandWorld.getNetherWorld().getSpawnLocation()); + event.useTravelAgent(true); + } else { + // Home world is nether - going home + event.useTravelAgent(false); + Location dest = plugin.getIslands().getSafeHomeLocation(playerUUID,1); + if (dest != null) { + event.setTo(dest); } else { - plugin.getLogger().severe("Cannot teleport player to nether because there is no nether schematic"); event.setCancelled(true); - Util.sendMessage(event.getPlayer(), ChatColor.RED + plugin.getLocale(event.getPlayer().getUniqueId()).get("warps.error.NotSafe")); - return; + new SafeSpotTeleport(plugin, event.getPlayer(), plugin.getIslands().getIslandLocation(playerUUID), 1); } } + } else { + // Going to Over world + if (homeWorld.getEnvironment().equals(Environment.NORMAL)) { + // Home world is over world + event.useTravelAgent(false); + Location dest = plugin.getIslands().getSafeHomeLocation(playerUUID,1); + if (dest != null) { + event.setTo(dest); + } else { + event.setCancelled(true); + new SafeSpotTeleport(plugin, event.getPlayer(), plugin.getIslands().getIslandLocation(playerUUID), 1); + } + } else { + // Home world is nether + event.setTo(IslandWorld.getIslandWorld().getSpawnLocation()); + event.useTravelAgent(true); + } } + } else { + // Island Nether if (DEBUG) - plugin.getLogger().info("DEBUG: Teleporting to " + event.getFrom().toVector().toLocation(IslandWorld.getNetherWorld())); + plugin.getLogger().info("DEBUG: Island nether"); + // Get location of the island where the player is at + if (island == null) { + if (DEBUG) + plugin.getLogger().info("DEBUG: island is null"); + event.setCancelled(true); + return; + } + // Can go both ways now + Location overworldIsland = island.getCenter().toVector().toLocation(IslandWorld.getIslandWorld()); + Location netherIsland = island.getCenter().toVector().toLocation(IslandWorld.getNetherWorld()); + //Location dest = event.getFrom().toVector().toLocation(IslandWorld.getIslandWorld()); + if (event.getFrom().getWorld().getEnvironment().equals(Environment.NORMAL)) { + // Going to Nether + // Check that there is a nether island there. Due to legacy reasons it may not exist + if (DEBUG) + plugin.getLogger().info("DEBUG: island center = " + island.getCenter()); + if (netherIsland.getBlock().getType() != Material.BEDROCK) { + // Check to see if there is anything there + if (plugin.getIslands().bigScan(netherIsland, 20) == null) { + if (DEBUG) + plugin.getLogger().info("DEBUG: big scan is null"); + plugin.getLogger().warning("Creating nether island for " + event.getPlayer().getName() + " using default nether schematic"); + Schematic nether = plugin.getSchematics().getSchematic("nether"); + if (nether != null) { + if (DEBUG) + plugin.getLogger().info("DEBUG: pasting at " + island.getCenter().toVector()); + nether.pasteSchematic(netherIsland, event.getPlayer(), false, PasteReason.PARTNER, island); + } else { + plugin.getLogger().severe("Cannot teleport player to nether because there is no nether schematic"); + event.setCancelled(true); + Util.sendMessage(event.getPlayer(), ChatColor.RED + plugin.getLocale(event.getPlayer().getUniqueId()).get("warps.error.NotSafe")); + return; + } + } + } + if (DEBUG) + plugin.getLogger().info("DEBUG: Teleporting to " + event.getFrom().toVector().toLocation(IslandWorld.getNetherWorld())); + event.setCancelled(true); + // Teleport using the new safeSpot teleport + new SafeSpotTeleport(plugin, event.getPlayer(), netherIsland); + return; + } + // Going to the over world - if there isn't an island, do nothing event.setCancelled(true); // Teleport using the new safeSpot teleport - new SafeSpotTeleport(plugin, event.getPlayer(), netherIsland); - return; + new SafeSpotTeleport(plugin, event.getPlayer(), overworldIsland); } - // Going to the over world - if there isn't an island, do nothing - event.setCancelled(true); - // Teleport using the new safeSpot teleport - new SafeSpotTeleport(plugin, event.getPlayer(), overworldIsland); - } - break; - default: - break; + break; + default: + break; } } diff --git a/src/main/java/us/tastybento/bskyblock/listeners/protection/FlyingMobEvents.java b/src/main/java/us/tastybento/bskyblock/listeners/protection/FlyingMobEvents.java index 470a0c90f..6410896d6 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/protection/FlyingMobEvents.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/protection/FlyingMobEvents.java @@ -25,7 +25,7 @@ import us.tastybento.bskyblock.util.Util; /** * This class manages flying mobs. If they exist the spawned island's limits they will be removed. - * + * * @author tastybento * */ @@ -39,38 +39,35 @@ public class FlyingMobEvents implements Listener { */ public FlyingMobEvents(BSkyBlock plugin) { this.plugin = plugin; - this.mobSpawnInfo = new WeakHashMap(); - new BukkitRunnable() { + this.mobSpawnInfo = new WeakHashMap<>(); - public void run() { - //Bukkit.getLogger().info("DEBUG: checking - mobspawn size = " + mobSpawnInfo.size()); - Iterator> it = mobSpawnInfo.entrySet().iterator(); - while (it.hasNext()) { - Entry entry = it.next(); - if (entry.getKey() == null) { - //Bukkit.getLogger().info("DEBUG: removing null entity"); - it.remove(); - } else { - if (entry.getKey() instanceof LivingEntity) { - if (!entry.getValue().inIslandSpace(entry.getKey().getLocation())) { - //Bukkit.getLogger().info("DEBUG: removing entity outside of island"); - it.remove(); - // Kill mob - LivingEntity mob = (LivingEntity)entry.getKey(); - mob.setHealth(0); - entry.getKey().remove(); - } else { - //Bukkit.getLogger().info("DEBUG: entity " + entry.getKey().getName() + " is in island space"); - } - } else { - // Not living entity + plugin.getServer().getScheduler().runTaskTimer(plugin, () -> { + //Bukkit.getLogger().info("DEBUG: checking - mobspawn size = " + mobSpawnInfo.size()); + Iterator> it = mobSpawnInfo.entrySet().iterator(); + while (it.hasNext()) { + Entry entry = it.next(); + if (entry.getKey() == null) { + //Bukkit.getLogger().info("DEBUG: removing null entity"); + it.remove(); + } else { + if (entry.getKey() instanceof LivingEntity) { + if (!entry.getValue().inIslandSpace(entry.getKey().getLocation())) { + //Bukkit.getLogger().info("DEBUG: removing entity outside of island"); it.remove(); + // Kill mob + LivingEntity mob = (LivingEntity)entry.getKey(); + mob.setHealth(0); + entry.getKey().remove(); + } else { + //Bukkit.getLogger().info("DEBUG: entity " + entry.getKey().getName() + " is in island space"); } + } else { + // Not living entity + it.remove(); } - } + } } - - }.runTaskTimer(plugin, 20L, 20L); + }, 20L, 20L); } /** @@ -108,12 +105,12 @@ public class FlyingMobEvents implements Listener { if (e.getEntity() == null || !Util.inWorld(e.getEntity())) { return; } - if (mobSpawnInfo.containsKey(e.getEntity().getUniqueId())) { + if (mobSpawnInfo.containsKey(e.getEntity())) { // We know about this mob if (DEBUG) { plugin.getLogger().info("DEBUG: We know about this mob"); } - if (!mobSpawnInfo.get(e.getEntity().getUniqueId()).inIslandSpace(e.getLocation())) { + if (!mobSpawnInfo.get(e.getEntity()).inIslandSpace(e.getLocation())) { // Cancel the explosion and block damage if (DEBUG) { plugin.getLogger().info("DEBUG: cancel flying mob explosion"); @@ -140,7 +137,7 @@ public class FlyingMobEvents implements Listener { if (e.getEntityType() == EntityType.WITHER) { //plugin.getLogger().info("DEBUG: Wither"); // Check the location - if (mobSpawnInfo.containsKey(e.getEntity().getUniqueId())) { + if (mobSpawnInfo.containsKey(e.getEntity())) { // We know about this wither if (DEBUG) { plugin.getLogger().info("DEBUG: We know about this wither"); @@ -163,12 +160,12 @@ public class FlyingMobEvents implements Listener { //plugin.getLogger().info("DEBUG: shooter is wither"); Wither wither = (Wither)projectile.getShooter(); // Check the location - if (mobSpawnInfo.containsKey(wither.getUniqueId())) { + if (mobSpawnInfo.containsKey(wither)) { // We know about this wither if (DEBUG) { plugin.getLogger().info("DEBUG: We know about this wither"); } - if (!mobSpawnInfo.get(wither.getUniqueId()).inIslandSpace(e.getEntity().getLocation())) { + if (!mobSpawnInfo.get(wither).inIslandSpace(e.getEntity().getLocation())) { // Cancel the explosion if (DEBUG) { plugin.getLogger().info("DEBUG: cancel wither skull explosion"); diff --git a/src/main/java/us/tastybento/bskyblock/listeners/protection/InventorySave.java b/src/main/java/us/tastybento/bskyblock/listeners/protection/InventorySave.java index 51ae20537..799c40aa6 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/protection/InventorySave.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/protection/InventorySave.java @@ -9,9 +9,9 @@ import us.tastybento.bskyblock.BSkyBlock; /** * Stashes inventories when required for a player - * + * * @author tastybento - * + * */ public class InventorySave { private static InventorySave instance = new InventorySave(BSkyBlock.getPlugin()); @@ -21,7 +21,7 @@ public class InventorySave { * Saves the inventory of a player */ public InventorySave(BSkyBlock plugin) { - inventories = new HashMap(); + inventories = new HashMap<>(); } /** Save player's inventory @@ -43,7 +43,7 @@ public class InventorySave { } /** * Load the player's inventory - * + * * @param player */ public void loadPlayerInventory(Player player) { diff --git a/src/main/java/us/tastybento/bskyblock/listeners/protection/InventoryStore.java b/src/main/java/us/tastybento/bskyblock/listeners/protection/InventoryStore.java index e91fde830..55526c0d1 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/protection/InventoryStore.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/protection/InventoryStore.java @@ -4,7 +4,7 @@ import org.bukkit.inventory.ItemStack; /** * Where the inventory data is stored - * + * * @author tastybento */ public class InventoryStore { diff --git a/src/main/java/us/tastybento/bskyblock/listeners/protection/IslandGuard.java b/src/main/java/us/tastybento/bskyblock/listeners/protection/IslandGuard.java index e8f017447..8f13f4226 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/protection/IslandGuard.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/protection/IslandGuard.java @@ -96,16 +96,14 @@ public class IslandGuard implements Listener { private final BSkyBlock plugin; private final static boolean DEBUG = false; private static final boolean DEBUG2 = false; - private HashMap onPlate = new HashMap(); - private Set tntBlocks = new HashSet(); - private Set litCreeper = new HashSet(); + private HashMap onPlate = new HashMap<>(); + private Set tntBlocks = new HashSet<>(); + private Set litCreeper = new HashSet<>(); public IslandGuard(final BSkyBlock plugin) { this.plugin = plugin; - } - /** * Prevents visitors picking items from riding horses or other inventories * @param event @@ -124,11 +122,10 @@ public class IslandGuard implements Listener { if (event.getInventory().getHolder() instanceof Animals) { if (actionAllowed((Player)event.getWhoClicked(), event.getWhoClicked().getLocation(), SettingsFlag.MOUNT_INVENTORY)) { return; - } + } // Elsewhere - not allowed Util.sendMessage(event.getWhoClicked(), ChatColor.RED + plugin.getLocale(event.getWhoClicked().getUniqueId()).get("island.protected")); event.setCancelled(true); - return; } } @@ -174,19 +171,6 @@ public class IslandGuard implements Listener { return false; } - /* - * For testing only - * @EventHandler() - * void testEvent(ChallengeLevelCompleteEvent e) { - * plugin.getLogger().info(e.getEventName()); - * plugin.getLogger().info("DEBUG: challenge level complete!"); - * } - * @EventHandler() - * void testEvent(ChallengeCompleteEvent e) { - * plugin.getLogger().info(e.getEventName()); - * plugin.getLogger().info("DEBUG: challenge complete!"); - * } - */ // Vehicle damage @EventHandler(priority = EventPriority.LOW, ignoreCancelled=true) public void onVehicleDamageEvent(VehicleDamageEvent e) { @@ -216,7 +200,6 @@ public class IslandGuard implements Listener { return; } - Entity passenger = e.getVehicle().getPassenger(); if (passenger == null || !(passenger instanceof Player)) { return; @@ -484,7 +467,6 @@ public class IslandGuard implements Listener { if (DEBUG2) plugin.getLogger().info("Natural animal spawn cancelled."); e.setCancelled(true); - return; } } } @@ -509,18 +491,18 @@ public class IslandGuard implements Listener { e.blockList().clear(); } else { if (!Settings.allowChestDamage) { - List toberemoved = new ArrayList(); + List toberemoved = new ArrayList<>(); // Save the chest blocks in a list for (Block b : e.blockList()) { switch (b.getType()) { - case CHEST: - case ENDER_CHEST: - case STORAGE_MINECART: - case TRAPPED_CHEST: - toberemoved.add(b); - break; - default: - break; + case CHEST: + case ENDER_CHEST: + case STORAGE_MINECART: + case TRAPPED_CHEST: + toberemoved.add(b); + break; + default: + break; } } // Now delete them @@ -541,86 +523,86 @@ public class IslandGuard implements Listener { return; } switch (exploding) { - case CREEPER: - if (!Settings.allowCreeperDamage) { - // plugin.getLogger().info("Creeper block damage prevented"); - e.blockList().clear(); - } else { - // Check if creeper griefing is allowed - if (!Settings.allowCreeperGriefing) { - // Find out who the creeper was targeting - Creeper creeper = (Creeper)e.getEntity(); - if (creeper.getTarget() instanceof Player) { - Player target = (Player)creeper.getTarget(); - // Check if the target is on their own island or not - if (!plugin.getIslands().locationIsOnIsland(target, e.getLocation())) { - // They are a visitor tsk tsk - // Stop the blocks from being damaged, but allow hurt still - e.blockList().clear(); + case CREEPER: + if (!Settings.allowCreeperDamage) { + // plugin.getLogger().info("Creeper block damage prevented"); + e.blockList().clear(); + } else { + // Check if creeper griefing is allowed + if (!Settings.allowCreeperGriefing) { + // Find out who the creeper was targeting + Creeper creeper = (Creeper)e.getEntity(); + if (creeper.getTarget() instanceof Player) { + Player target = (Player)creeper.getTarget(); + // Check if the target is on their own island or not + if (!plugin.getIslands().locationIsOnIsland(target, e.getLocation())) { + // They are a visitor tsk tsk + // Stop the blocks from being damaged, but allow hurt still + e.blockList().clear(); + } + } + // Check if this creeper was lit by a visitor + if (litCreeper.contains(creeper.getUniqueId())) { + if (DEBUG) { + plugin.getLogger().info("DBEUG: preventing creeper from damaging"); + } + litCreeper.remove(creeper.getUniqueId()); + e.setCancelled(true); + return; } } - // Check if this creeper was lit by a visitor - if (litCreeper.contains(creeper.getUniqueId())) { - if (DEBUG) { - plugin.getLogger().info("DBEUG: preventing creeper from damaging"); + if (!Settings.allowChestDamage) { + List toberemoved = new ArrayList(); + // Save the chest blocks in a list + for (Block b : e.blockList()) { + switch (b.getType()) { + case CHEST: + case ENDER_CHEST: + case STORAGE_MINECART: + case TRAPPED_CHEST: + toberemoved.add(b); + break; + default: + break; + } + } + // Now delete them + for (Block b : toberemoved) { + e.blockList().remove(b); } - litCreeper.remove(creeper.getUniqueId()); - e.setCancelled(true); - return; } } - if (!Settings.allowChestDamage) { - List toberemoved = new ArrayList(); - // Save the chest blocks in a list - for (Block b : e.blockList()) { - switch (b.getType()) { - case CHEST: - case ENDER_CHEST: - case STORAGE_MINECART: - case TRAPPED_CHEST: - toberemoved.add(b); - break; - default: - break; + break; + case PRIMED_TNT: + case MINECART_TNT: + if (!Settings.allowTNTDamage) { + // plugin.getLogger().info("TNT block damage prevented"); + e.blockList().clear(); + } else { + if (!Settings.allowChestDamage) { + List toberemoved = new ArrayList<>(); + // Save the chest blocks in a list + for (Block b : e.blockList()) { + switch (b.getType()) { + case CHEST: + case ENDER_CHEST: + case STORAGE_MINECART: + case TRAPPED_CHEST: + toberemoved.add(b); + break; + default: + break; + } + } + // Now delete them + for (Block b : toberemoved) { + e.blockList().remove(b); } } - // Now delete them - for (Block b : toberemoved) { - e.blockList().remove(b); - } } - } - break; - case PRIMED_TNT: - case MINECART_TNT: - if (!Settings.allowTNTDamage) { - // plugin.getLogger().info("TNT block damage prevented"); - e.blockList().clear(); - } else { - if (!Settings.allowChestDamage) { - List toberemoved = new ArrayList(); - // Save the chest blocks in a list - for (Block b : e.blockList()) { - switch (b.getType()) { - case CHEST: - case ENDER_CHEST: - case STORAGE_MINECART: - case TRAPPED_CHEST: - toberemoved.add(b); - break; - default: - break; - } - } - // Now delete them - for (Block b : toberemoved) { - e.blockList().remove(b); - } - } - } - break; - default: - break; + break; + default: + break; } } @@ -783,7 +765,7 @@ public class IslandGuard implements Listener { inNether = true; } // Stop TNT damage if it is disallowed - if (!Settings.allowTNTDamage && (e.getDamager().getType().equals(EntityType.PRIMED_TNT) + if (!Settings.allowTNTDamage && (e.getDamager().getType().equals(EntityType.PRIMED_TNT) || e.getDamager().getType().equals(EntityType.FIREWORK) || e.getDamager().getType().equals(EntityType.FIREBALL))) { if (DEBUG) @@ -944,16 +926,13 @@ public class IslandGuard implements Listener { // Players being hurt PvP if (e.getEntity() instanceof Player) { - if (pvp) { - return; - } else { + if (!pvp) { Util.sendMessage(attacker, ChatColor.RED + plugin.getLocale(attacker.getUniqueId()).get("targetInPVPArea")); if (flamingArrow) e.getEntity().setFireTicks(0); if (projectile) e.getDamager().remove(); e.setCancelled(true); - return; } } } @@ -1013,7 +992,6 @@ public class IslandGuard implements Listener { Util.sendMessage(e.getPlayer(), ChatColor.RED + (plugin.getLocale(e.getPlayer().getUniqueId()).get("moblimits.entity").replace("[entity]", Util.prettifyText(type))).replace("[number]", String.valueOf(Settings.limitedBlocks.get(type)))); e.setCancelled(true); - return; } } } @@ -1101,7 +1079,6 @@ public class IslandGuard implements Listener { if (!actionAllowed(e.getPlayer(), e.getBlock().getLocation(), SettingsFlag.LEASH)) { Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); e.setCancelled(true); - return; } } } @@ -1145,7 +1122,6 @@ public class IslandGuard implements Listener { Util.sendMessage(e.getPlayer(), ChatColor.RED + (plugin.getLocale(e.getPlayer().getUniqueId()).get("moblimits.entity").replace("[entity]", Util.prettifyText(type))).replace("[number]", String.valueOf(Settings.limitedBlocks.get(type)))); e.setCancelled(true); - return; } } } @@ -1442,7 +1418,6 @@ public class IslandGuard implements Listener { // Not allowed Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); e.setCancelled(true); - return; } } @@ -1525,7 +1500,7 @@ public class IslandGuard implements Listener { // To catch at block iterator exceptions that can happen in the void or at the very top of blocks if (DEBUG) { plugin.getLogger().info("DEBUG: block iterator error"); - ex.printStackTrace(); + ex.printStackTrace(); } } // Handle Shulker Boxes @@ -1533,7 +1508,7 @@ public class IslandGuard implements Listener { if (island == null) { if (!Settings.defaultWorldSettings.get(SettingsFlag.OPEN_CHESTS)) { Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); - e.setCancelled(true); + e.setCancelled(true); } } else if (!island.getFlag(SettingsFlag.OPEN_CHESTS)) { Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); @@ -1546,352 +1521,352 @@ public class IslandGuard implements Listener { if (island == null) { if (!Settings.defaultWorldSettings.get(SettingsFlag.PLACE_BLOCKS)) { Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); - e.setCancelled(true); + e.setCancelled(true); } } else if (!island.getFlag(SettingsFlag.PLACE_BLOCKS)) { Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); e.setCancelled(true); } - return; + return; } if (DEBUG) plugin.getLogger().info("DEBUG: clicked block = " + e.getClickedBlock().getType()); switch (e.getClickedBlock().getType()) { - case WOODEN_DOOR: - case SPRUCE_DOOR: - case ACACIA_DOOR: - case DARK_OAK_DOOR: - case BIRCH_DOOR: - case JUNGLE_DOOR: - case TRAP_DOOR: - if (island == null) { - if (Settings.defaultWorldSettings.get(SettingsFlag.DOOR)) { - return; - } else { + case WOODEN_DOOR: + case SPRUCE_DOOR: + case ACACIA_DOOR: + case DARK_OAK_DOOR: + case BIRCH_DOOR: + case JUNGLE_DOOR: + case TRAP_DOOR: + if (island == null) { + if (Settings.defaultWorldSettings.get(SettingsFlag.DOOR)) { + return; + } else { + Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); + e.setCancelled(true); + return; + } + } + if (!island.getFlag(SettingsFlag.DOOR)) { Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); e.setCancelled(true); return; } - } - if (!island.getFlag(SettingsFlag.DOOR)) { - Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); - e.setCancelled(true); - return; - } - break; - case FENCE_GATE: - case SPRUCE_FENCE_GATE: - case ACACIA_FENCE_GATE: - case DARK_OAK_FENCE_GATE: - case BIRCH_FENCE_GATE: - case JUNGLE_FENCE_GATE: - if (island == null) { - if (Settings.defaultWorldSettings.get(SettingsFlag.GATE)) { - return; - } else { + break; + case FENCE_GATE: + case SPRUCE_FENCE_GATE: + case ACACIA_FENCE_GATE: + case DARK_OAK_FENCE_GATE: + case BIRCH_FENCE_GATE: + case JUNGLE_FENCE_GATE: + if (island == null) { + if (Settings.defaultWorldSettings.get(SettingsFlag.GATE)) { + return; + } else { + Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); + e.setCancelled(true); + return; + } + } + if (!island.getFlag(SettingsFlag.GATE)) { Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); e.setCancelled(true); return; } - } - if (!island.getFlag(SettingsFlag.GATE)) { - Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); - e.setCancelled(true); - return; - } - break; - case ENDER_CHEST: - break; - case CHEST: - case TRAPPED_CHEST: - case DISPENSER: - case DROPPER: - case HOPPER: - case HOPPER_MINECART: - case STORAGE_MINECART: - if (island == null) { - if (Settings.defaultWorldSettings.get(SettingsFlag.OPEN_CHESTS)) { - return; - } else { + break; + case ENDER_CHEST: + break; + case CHEST: + case TRAPPED_CHEST: + case DISPENSER: + case DROPPER: + case HOPPER: + case HOPPER_MINECART: + case STORAGE_MINECART: + if (island == null) { + if (Settings.defaultWorldSettings.get(SettingsFlag.OPEN_CHESTS)) { + return; + } else { + Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); + e.setCancelled(true); + return; + } + } + if (!island.getFlag(SettingsFlag.OPEN_CHESTS)) { Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); e.setCancelled(true); return; } - } - if (!island.getFlag(SettingsFlag.OPEN_CHESTS)) { - Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); - e.setCancelled(true); - return; - } - break; - case SOIL: - if (island == null) { - if (Settings.defaultWorldSettings.get(SettingsFlag.CROP_TRAMPLE)) { - return; - } else { + break; + case SOIL: + if (island == null) { + if (Settings.defaultWorldSettings.get(SettingsFlag.CROP_TRAMPLE)) { + return; + } else { + Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); + e.setCancelled(true); + return; + } + } + if (!island.getFlag(SettingsFlag.CROP_TRAMPLE)) { Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); e.setCancelled(true); return; } - } - if (!island.getFlag(SettingsFlag.CROP_TRAMPLE)) { - Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); - e.setCancelled(true); - return; - } - break; - case BREWING_STAND: - case CAULDRON: - if (island == null) { - if (Settings.defaultWorldSettings.get(SettingsFlag.BREWING)) { - return; - } else { + break; + case BREWING_STAND: + case CAULDRON: + if (island == null) { + if (Settings.defaultWorldSettings.get(SettingsFlag.BREWING)) { + return; + } else { + Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); + e.setCancelled(true); + return; + } + } + if (!island.getFlag(SettingsFlag.BREWING)) { Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); e.setCancelled(true); return; } - } - if (!island.getFlag(SettingsFlag.BREWING)) { - Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); - e.setCancelled(true); - return; - } - break; - case DIODE: - case DIODE_BLOCK_OFF: - case DIODE_BLOCK_ON: - case REDSTONE_COMPARATOR_ON: - case REDSTONE_COMPARATOR_OFF: - case DAYLIGHT_DETECTOR: - case DAYLIGHT_DETECTOR_INVERTED: - if (island == null) { - if (Settings.defaultWorldSettings.get(SettingsFlag.REDSTONE)) { - return; - } else { + break; + case DIODE: + case DIODE_BLOCK_OFF: + case DIODE_BLOCK_ON: + case REDSTONE_COMPARATOR_ON: + case REDSTONE_COMPARATOR_OFF: + case DAYLIGHT_DETECTOR: + case DAYLIGHT_DETECTOR_INVERTED: + if (island == null) { + if (Settings.defaultWorldSettings.get(SettingsFlag.REDSTONE)) { + return; + } else { + Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); + e.setCancelled(true); + return; + } + } + if (!island.getFlag(SettingsFlag.REDSTONE)) { Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); e.setCancelled(true); return; } - } - if (!island.getFlag(SettingsFlag.REDSTONE)) { - Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); - e.setCancelled(true); - return; - } - break; - case ENCHANTMENT_TABLE: - if (island == null) { - if (Settings.defaultWorldSettings.get(SettingsFlag.ENCHANTING)) { - return; - } else { + break; + case ENCHANTMENT_TABLE: + if (island == null) { + if (Settings.defaultWorldSettings.get(SettingsFlag.ENCHANTING)) { + return; + } else { + Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); + e.setCancelled(true); + return; + } + } + if (!island.getFlag(SettingsFlag.ENCHANTING)) { Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); e.setCancelled(true); return; } - } - if (!island.getFlag(SettingsFlag.ENCHANTING)) { - Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); - e.setCancelled(true); - return; - } - break; - case FURNACE: - case BURNING_FURNACE: - if (island == null) { - if (Settings.defaultWorldSettings.get(SettingsFlag.FURNACE)) { - return; - } else { + break; + case FURNACE: + case BURNING_FURNACE: + if (island == null) { + if (Settings.defaultWorldSettings.get(SettingsFlag.FURNACE)) { + return; + } else { + Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); + e.setCancelled(true); + return; + } + } + if (!island.getFlag(SettingsFlag.FURNACE)) { Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); e.setCancelled(true); return; } - } - if (!island.getFlag(SettingsFlag.FURNACE)) { - Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); - e.setCancelled(true); - return; - } - break; - case ICE: - break; - case ITEM_FRAME: - break; - case JUKEBOX: - if (DEBUG) - plugin.getLogger().info("DEBUG: Jukebox"); - case NOTE_BLOCK: - if (island == null) { - if (DEBUG) - plugin.getLogger().info("DEBUG: Jukebox island = null"); - if (Settings.defaultWorldSettings.get(SettingsFlag.MUSIC)) { - return; - } else { - if (DEBUG) + break; + case ICE: + break; + case ITEM_FRAME: + break; + case JUKEBOX: + if (DEBUG) + plugin.getLogger().info("DEBUG: Jukebox"); + case NOTE_BLOCK: + if (island == null) { + if (DEBUG) + plugin.getLogger().info("DEBUG: Jukebox island = null"); + if (Settings.defaultWorldSettings.get(SettingsFlag.MUSIC)) { + return; + } else { + if (DEBUG) + plugin.getLogger().info("DEBUG: Jukebox not allowed"); + Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); + e.setCancelled(true); + return; + } + } + if (!island.getFlag(SettingsFlag.MUSIC)) { + if (DEBUG) plugin.getLogger().info("DEBUG: Jukebox not allowed"); Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); e.setCancelled(true); return; } - } - if (!island.getFlag(SettingsFlag.MUSIC)) { - if (DEBUG) - plugin.getLogger().info("DEBUG: Jukebox not allowed"); - Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); - e.setCancelled(true); - return; - } - break; - case PACKED_ICE: - break; - case STONE_BUTTON: - case WOOD_BUTTON: - case LEVER: - if (island == null) { - // TODO: BUTTON? - if (Settings.defaultWorldSettings.get(SettingsFlag.LEVER)) { - return; - } else { + break; + case PACKED_ICE: + break; + case STONE_BUTTON: + case WOOD_BUTTON: + case LEVER: + if (island == null) { + // TODO: BUTTON? + if (Settings.defaultWorldSettings.get(SettingsFlag.LEVER)) { + return; + } else { + Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); + e.setCancelled(true); + return; + } + } + if (!island.getFlag(SettingsFlag.LEVER)) { Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); e.setCancelled(true); return; } - } - if (!island.getFlag(SettingsFlag.LEVER)) { - Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); - e.setCancelled(true); - return; - } - break; - case TNT: - break; - case WORKBENCH: - if (island == null) { - if (Settings.defaultWorldSettings.get(SettingsFlag.CRAFTING)) { - return; - } else { + break; + case TNT: + break; + case WORKBENCH: + if (island == null) { + if (Settings.defaultWorldSettings.get(SettingsFlag.CRAFTING)) { + return; + } else { + Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); + e.setCancelled(true); + return; + } + } + if (!island.getFlag(SettingsFlag.CRAFTING)) { Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); e.setCancelled(true); return; } - } - if (!island.getFlag(SettingsFlag.CRAFTING)) { - Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); - e.setCancelled(true); - return; - } - break; - case ANVIL: - if (island == null) { - if (Settings.defaultWorldSettings.get(SettingsFlag.ANVIL)) { - return; - } else { + break; + case ANVIL: + if (island == null) { + if (Settings.defaultWorldSettings.get(SettingsFlag.ANVIL)) { + return; + } else { + Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); + e.setCancelled(true); + return; + } + } + if (!island.getFlag(SettingsFlag.ANVIL)) { Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); e.setCancelled(true); return; } - } - if (!island.getFlag(SettingsFlag.ANVIL)) { - Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); - e.setCancelled(true); - return; - } - break; - case RAILS: - case POWERED_RAIL: - case DETECTOR_RAIL: - case ACTIVATOR_RAIL: - // If they are not on an island, it's protected - if (island == null) { - if (!Settings.defaultWorldSettings.get(SettingsFlag.PLACE_BLOCKS)) { - Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); - e.setCancelled(true); - } - return; - } - if (!island.getFlag(SettingsFlag.PLACE_BLOCKS)) { - if (e.getMaterial() == Material.MINECART || e.getMaterial() == Material.STORAGE_MINECART || e.getMaterial() == Material.HOPPER_MINECART - || e.getMaterial() == Material.EXPLOSIVE_MINECART || e.getMaterial() == Material.POWERED_MINECART) { - e.setCancelled(true); - Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); - e.getPlayer().updateInventory(); + break; + case RAILS: + case POWERED_RAIL: + case DETECTOR_RAIL: + case ACTIVATOR_RAIL: + // If they are not on an island, it's protected + if (island == null) { + if (!Settings.defaultWorldSettings.get(SettingsFlag.PLACE_BLOCKS)) { + Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); + e.setCancelled(true); + } return; } - } - case BEACON: - if (island == null) { - if (Settings.defaultWorldSettings.get(SettingsFlag.BEACON)) { - return; - } else { + if (!island.getFlag(SettingsFlag.PLACE_BLOCKS)) { + if (e.getMaterial() == Material.MINECART || e.getMaterial() == Material.STORAGE_MINECART || e.getMaterial() == Material.HOPPER_MINECART + || e.getMaterial() == Material.EXPLOSIVE_MINECART || e.getMaterial() == Material.POWERED_MINECART) { + e.setCancelled(true); + Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); + e.getPlayer().updateInventory(); + return; + } + } + case BEACON: + if (island == null) { + if (Settings.defaultWorldSettings.get(SettingsFlag.BEACON)) { + return; + } else { + Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); + e.setCancelled(true); + return; + } + } + if (!island.getFlag(SettingsFlag.BEACON)) { Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); e.setCancelled(true); return; } - } - if (!island.getFlag(SettingsFlag.BEACON)) { - Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); - e.setCancelled(true); - return; - } - break; - case CAKE_BLOCK: - if (island == null) { - if (Settings.defaultWorldSettings.get(SettingsFlag.BREAK_BLOCKS)) { - return; - } else { + break; + case CAKE_BLOCK: + if (island == null) { + if (Settings.defaultWorldSettings.get(SettingsFlag.BREAK_BLOCKS)) { + return; + } else { + Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); + e.getPlayer().setFoodLevel(e.getPlayer().getFoodLevel() - 2); + e.setCancelled(true); + return; + } + } + if (!island.getFlag(SettingsFlag.BREAK_BLOCKS)) { Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); e.getPlayer().setFoodLevel(e.getPlayer().getFoodLevel() - 2); e.setCancelled(true); return; } - } - if (!island.getFlag(SettingsFlag.BREAK_BLOCKS)) { - Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); - e.getPlayer().setFoodLevel(e.getPlayer().getFoodLevel() - 2); - e.setCancelled(true); - return; - } - break; - case DRAGON_EGG: - if (island == null) { - if (Settings.defaultWorldSettings.get(SettingsFlag.BREAK_BLOCKS)) { - return; - } else { + break; + case DRAGON_EGG: + if (island == null) { + if (Settings.defaultWorldSettings.get(SettingsFlag.BREAK_BLOCKS)) { + return; + } else { + Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); + e.setCancelled(true); + return; + } + } + if (!island.getFlag(SettingsFlag.BREAK_BLOCKS)) { Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); e.setCancelled(true); return; } - } - if (!island.getFlag(SettingsFlag.BREAK_BLOCKS)) { - Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); - e.setCancelled(true); - return; - } - break; - case MOB_SPAWNER: - if (island == null) { - if (Settings.defaultWorldSettings.get(SettingsFlag.BREAK_BLOCKS)) { - return; - } else { + break; + case MOB_SPAWNER: + if (island == null) { + if (Settings.defaultWorldSettings.get(SettingsFlag.BREAK_BLOCKS)) { + return; + } else { + Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); + e.setCancelled(true); + return; + } + } + if (!island.getFlag(SettingsFlag.BREAK_BLOCKS)) { Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); e.setCancelled(true); return; } - } - if (!island.getFlag(SettingsFlag.BREAK_BLOCKS)) { - Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); - e.setCancelled(true); - return; - } - break; - case BED_BLOCK: - if (e.getPlayer().getWorld().getEnvironment().equals(Environment.NETHER)) { - // Prevent explosions - Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); - e.setCancelled(true); - return; - } - default: - break; + break; + case BED_BLOCK: + if (e.getPlayer().getWorld().getEnvironment().equals(Environment.NETHER)) { + // Prevent explosions + Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); + e.setCancelled(true); + return; + } + default: + break; } } // Check for disallowed in-hand items @@ -1909,7 +1884,6 @@ public class IslandGuard implements Listener { Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); e.setCancelled(true); e.getPlayer().updateInventory(); - return; } } else if (e.getMaterial().name().contains("BOAT") && (e.getClickedBlock() != null && !e.getClickedBlock().isLiquid())) { // Trying to put a boat on non-liquid @@ -1917,7 +1891,6 @@ public class IslandGuard implements Listener { || (island !=null && !island.getFlag(SettingsFlag.PLACE_BLOCKS))) { Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); e.setCancelled(true); - return; } } else if (e.getMaterial().equals(Material.ENDER_PEARL)) { if ((island == null && Settings.defaultWorldSettings.get(SettingsFlag.THROW_ENDERPEARLS)) @@ -1925,7 +1898,6 @@ public class IslandGuard implements Listener { Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); e.setCancelled(true); } - return; } else if (e.getMaterial().equals(Material.FLINT_AND_STEEL)) { plugin.getLogger().info("DEBUG: flint & steel"); if (e.getClickedBlock() != null) { @@ -1938,7 +1910,6 @@ public class IslandGuard implements Listener { e.setCancelled(true); } } - return; } else if (e.getMaterial().equals(Material.MONSTER_EGG)) { if (DEBUG) plugin.getLogger().info("DEBUG: allowMonsterEggs = " + island.getFlag(SettingsFlag.SPAWN_EGGS)); @@ -1946,7 +1917,6 @@ public class IslandGuard implements Listener { Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); e.setCancelled(true); } - return; } else if (e.getMaterial().equals(Material.POTION) && e.getItem().getDurability() != 0) { // Potion // plugin.getLogger().info("DEBUG: potion"); @@ -1960,7 +1930,7 @@ public class IslandGuard implements Listener { } // Check PVP if (island == null) { - if ((inNether && Settings.defaultWorldSettings.get(SettingsFlag.PVP_NETHER) + if ((inNether && Settings.defaultWorldSettings.get(SettingsFlag.PVP_NETHER) || (!inNether && Settings.defaultWorldSettings.get(SettingsFlag.PVP_OVERWORLD)))) { return; } @@ -2111,66 +2081,66 @@ public class IslandGuard implements Listener { } } switch (e.getRightClicked().getType()) { - case CREEPER: - // This seems to be called when the player is in Creative mode... - if (!Settings.allowCreeperGriefing) { - for (ItemStack item : Util.getPlayerInHandItems(e.getPlayer())) { - if (item != null && item.getType().equals(Material.FLINT_AND_STEEL)) { - if (!island.getMembers().contains(e.getPlayer().getUniqueId())) { - // Visitor - litCreeper.add(e.getRightClicked().getUniqueId()); - if (DEBUG) { - plugin.getLogger().info("DEBUG: visitor lit creeper"); + case CREEPER: + // This seems to be called when the player is in Creative mode... + if (!Settings.allowCreeperGriefing) { + for (ItemStack item : Util.getPlayerInHandItems(e.getPlayer())) { + if (item != null && item.getType().equals(Material.FLINT_AND_STEEL)) { + if (!island.getMembers().contains(e.getPlayer().getUniqueId())) { + // Visitor + litCreeper.add(e.getRightClicked().getUniqueId()); + if (DEBUG) { + plugin.getLogger().info("DEBUG: visitor lit creeper"); + } } } } } - } - break; - case LLAMA: - case SKELETON_HORSE: - case ZOMBIE_HORSE: - case HORSE: - //plugin.getLogger().info("Horse riding"); - if (island == null && !Settings.defaultWorldSettings.get(SettingsFlag.MOUNT_RIDING)) { - Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); - e.setCancelled(true); - } - if (island != null && !island.getFlag(SettingsFlag.MOUNT_RIDING)) { - Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); - e.setCancelled(true); - } - break; - case ITEM_FRAME: - // This is to place items in an item frame - if (island == null && !Settings.defaultWorldSettings.get(SettingsFlag.PLACE_BLOCKS)) { - Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); - e.setCancelled(true); - } - if (island != null) { - if (!island.getFlag(SettingsFlag.PLACE_BLOCKS)) { + break; + case LLAMA: + case SKELETON_HORSE: + case ZOMBIE_HORSE: + case HORSE: + //plugin.getLogger().info("Horse riding"); + if (island == null && !Settings.defaultWorldSettings.get(SettingsFlag.MOUNT_RIDING)) { Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); e.setCancelled(true); } - } - break; - case MINECART_CHEST: - case MINECART_FURNACE: - case MINECART_HOPPER: - //plugin.getLogger().info("Minecarts"); - if (island == null && !Settings.defaultWorldSettings.get(SettingsFlag.OPEN_CHESTS)) { - Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); - e.setCancelled(true); - } - if (island != null) { - if (!island.getFlag(SettingsFlag.OPEN_CHESTS)) { + if (island != null && !island.getFlag(SettingsFlag.MOUNT_RIDING)) { Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); e.setCancelled(true); } - } - break; - default: - break; + break; + case ITEM_FRAME: + // This is to place items in an item frame + if (island == null && !Settings.defaultWorldSettings.get(SettingsFlag.PLACE_BLOCKS)) { + Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); + e.setCancelled(true); + } + if (island != null) { + if (!island.getFlag(SettingsFlag.PLACE_BLOCKS)) { + Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); + e.setCancelled(true); + } + } + break; + case MINECART_CHEST: + case MINECART_FURNACE: + case MINECART_HOPPER: + //plugin.getLogger().info("Minecarts"); + if (island == null && !Settings.defaultWorldSettings.get(SettingsFlag.OPEN_CHESTS)) { + Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); + e.setCancelled(true); + } + if (island != null) { + if (!island.getFlag(SettingsFlag.OPEN_CHESTS)) { + Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); + e.setCancelled(true); + } + } + break; + default: + break; } } } @@ -2236,72 +2206,67 @@ public class IslandGuard implements Listener { if (DEBUG) plugin.getLogger().info("DEBUG: ignite cause = " + e.getCause()); switch (e.getCause()) { - case ENDER_CRYSTAL: - case EXPLOSION: - case FIREBALL: - case LIGHTNING: - if (!actionAllowed(e.getBlock().getLocation(), SettingsFlag.FIRE)) { - if (DEBUG) - plugin.getLogger().info("DEBUG: canceling fire"); - e.setCancelled(true); - } - break; - case FLINT_AND_STEEL: - Set transparent = new HashSet(); - transparent.add(Material.AIR); - if (DEBUG) { - plugin.getLogger().info("DEBUG: block = " + e.getBlock()); - //plugin.getLogger().info("DEBUG: target block = " + e.getPlayer().getTargetBlock(transparent, 10)); - } - // Check if this is allowed - if (e.getPlayer() != null && (e.getPlayer().isOp() || VaultHelper.hasPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypass"))) { - return; - } - if (!actionAllowed(e.getBlock().getLocation(), SettingsFlag.FIRE)) { - if (DEBUG) - plugin.getLogger().info("DEBUG: canceling fire"); - // If this was not a player, just stop it - if (e.getPlayer() == null) { + case ENDER_CRYSTAL: + case EXPLOSION: + case FIREBALL: + case LIGHTNING: + if (!actionAllowed(e.getBlock().getLocation(), SettingsFlag.FIRE)) { + if (DEBUG) + plugin.getLogger().info("DEBUG: canceling fire"); e.setCancelled(true); - break; } - // Get target block - Block targetBlock = e.getPlayer().getTargetBlock(transparent, 10); - if (targetBlock.getType().equals(Material.OBSIDIAN)) { - final MaterialData md = new MaterialData(e.getBlock().getType(), e.getBlock().getData()); - new BukkitRunnable() { - - @Override - public void run() { + break; + case FLINT_AND_STEEL: + Set transparent = new HashSet<>(); + transparent.add(Material.AIR); + if (DEBUG) { + plugin.getLogger().info("DEBUG: block = " + e.getBlock()); + //plugin.getLogger().info("DEBUG: target block = " + e.getPlayer().getTargetBlock(transparent, 10)); + } + // Check if this is allowed + if (e.getPlayer() != null && (e.getPlayer().isOp() || VaultHelper.hasPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypass"))) { + return; + } + if (!actionAllowed(e.getBlock().getLocation(), SettingsFlag.FIRE)) { + if (DEBUG) + plugin.getLogger().info("DEBUG: canceling fire"); + // If this was not a player, just stop it + if (e.getPlayer() == null) { + e.setCancelled(true); + break; + } + // Get target block + Block targetBlock = e.getPlayer().getTargetBlock(transparent, 10); + if (targetBlock.getType().equals(Material.OBSIDIAN)) { + final MaterialData md = new MaterialData(e.getBlock().getType(), e.getBlock().getData()); + plugin.getServer().getScheduler().runTask(plugin, () -> { if (e.getBlock().getType().equals(Material.FIRE)) { e.getBlock().setType(md.getItemType()); e.getBlock().setData(md.getData()); } + }); + } else { + e.setCancelled(true); + } + } + break; - } - }.runTask(plugin); - } else { + case LAVA: + case SPREAD: + // Check if this is a portal lighting + if (e.getBlock() != null && e.getBlock().getType().equals(Material.OBSIDIAN)) { + if (DEBUG) + plugin.getLogger().info("DEBUG: obsidian lighting"); + return; + } + if (!actionAllowed(e.getBlock().getLocation(), SettingsFlag.FIRE_SPREAD)) { + if (DEBUG) + plugin.getLogger().info("DEBUG: canceling fire spread"); e.setCancelled(true); } - } - break; - - case LAVA: - case SPREAD: - // Check if this is a portal lighting - if (e.getBlock() != null && e.getBlock().getType().equals(Material.OBSIDIAN)) { - if (DEBUG) - plugin.getLogger().info("DEBUG: obsidian lighting"); - return; - } - if (!actionAllowed(e.getBlock().getLocation(), SettingsFlag.FIRE_SPREAD)) { - if (DEBUG) - plugin.getLogger().info("DEBUG: canceling fire spread"); - e.setCancelled(true); - } - break; - default: - break; + break; + default: + break; } } } @@ -2339,7 +2304,6 @@ public class IslandGuard implements Listener { onPlate.put(playerUUID, new Vector(v.getBlockX(), v.getBlockY(), v.getBlockZ())); } e.setCancelled(true); - return; } /** @@ -2405,8 +2369,6 @@ public class IslandGuard implements Listener { Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected")); //e.getPlayer().updateInventory(); } - - return; } /** @@ -2489,17 +2451,11 @@ public class IslandGuard implements Listener { if (!tntBlocks.contains(e.getBlock().getLocation())) { Util.sendMessage(shooter, ChatColor.RED + plugin.getLocale(shooter.getUniqueId()).get("island.protected")); tntBlocks.add(e.getBlock().getLocation()); - plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() { - - @Override - public void run() { - tntBlocks.remove(e.getBlock().getLocation()); - }}, 20L); + plugin.getServer().getScheduler().runTaskLater(plugin, () -> tntBlocks.remove(e.getBlock().getLocation()), 20L); } // Remove the arrow projectile.remove(); e.setCancelled(true); - return; } } } @@ -2530,46 +2486,25 @@ public class IslandGuard implements Listener { } @EventHandler(priority=EventPriority.LOW) - public void onEvent(BlockPistonExtendEvent event) - { + public void onEvent(BlockPistonExtendEvent event) { if (!Settings.allowTNTPushing) { // Check world - if (!Util.inWorld(event.getBlock())) { - return; - } + if (!Util.inWorld(event.getBlock())) return; - for (Block block: event.getBlocks()) { - if (block.getType() == Material.TNT) { - event.setCancelled(true); - break; - } - } + if (event.getBlocks().stream().anyMatch(it -> it.getType() == Material.TNT)) + event.setCancelled(true); } - /* JAVA 8 - if (event.getBlocks()..stream().anyMatch(it->it.getType()==Material.TNT)) - event.setCancelled(true); - */ } @EventHandler(priority=EventPriority.LOW) - public void onEvent(BlockPistonRetractEvent event) - { + public void onEvent(BlockPistonRetractEvent event) { if (!Settings.allowTNTPushing) { // Check world - if (!Util.inWorld(event.getBlock())) { - return; - } - for (Block block: event.getBlocks()) { - if (block.getType() == Material.TNT) { - event.setCancelled(true); - break; - } - } + if (!Util.inWorld(event.getBlock())) return; + + if (event.getBlocks().stream().anyMatch(it -> it.getType() == Material.TNT)) + event.setCancelled(true); } - /* JAVA 8 - if (event.getBlocks().stream().anyMatch(it->it.getType()==Material.TNT)) - event.setCancelled(true); - */ } /** @@ -2612,7 +2547,7 @@ public class IslandGuard implements Listener { // Monsters being hurt if (entity instanceof Monster || entity instanceof Slime || entity instanceof Squid) { // Normal island check - if (island != null && island.getMembers().contains(attacker)) { + if (island != null && island.getMembers().contains(attacker.getUniqueId())) { // Members always allowed continue; } @@ -2628,7 +2563,7 @@ public class IslandGuard implements Listener { // Mobs being hurt if (entity instanceof Animals || entity instanceof IronGolem || entity instanceof Snowman || entity instanceof Villager) { - if (island != null && (island.getFlag(SettingsFlag.HURT_ANIMALS) || island.getMembers().contains(attacker))) { + if (island != null && (island.getFlag(SettingsFlag.HURT_ANIMALS) || island.getMembers().contains(attacker.getUniqueId()))) { continue; } if (DEBUG) @@ -2647,10 +2582,7 @@ public class IslandGuard implements Listener { // Players being hurt PvP if (entity instanceof Player) { - if (pvp) { - if (DEBUG) plugin.getLogger().info("DEBUG: PVP allowed"); - continue; - } else { + if (!pvp) { if (DEBUG) plugin.getLogger().info("DEBUG: PVP not allowed"); Util.sendMessage(attacker, ChatColor.RED + plugin.getLocale(attacker.getUniqueId()).get("targetInPVPArea")); e.setCancelled(true); diff --git a/src/main/java/us/tastybento/bskyblock/listeners/protection/IslandGuard1_8.java b/src/main/java/us/tastybento/bskyblock/listeners/protection/IslandGuard1_8.java index ba975ddca..eaf8019a9 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/protection/IslandGuard1_8.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/protection/IslandGuard1_8.java @@ -37,7 +37,6 @@ public class IslandGuard1_8 implements Listener { } - /** * Checks if action is allowed for player in location for flag * @param player @@ -64,7 +63,7 @@ public class IslandGuard1_8 implements Listener { /** * Handle interaction with armor stands V1.8 * Note - some armor stand protection is done in IslandGuard.java, e.g. against projectiles. - * + * * @param e */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled=true) @@ -88,7 +87,7 @@ public class IslandGuard1_8 implements Listener { * Handle V1.8 blocks that need special treatment * Tilling of coarse dirt into dirt * Usually prevented because it could lead to an endless supply of dirt with gravel - * + * * @param e */ @SuppressWarnings("deprecation") diff --git a/src/main/java/us/tastybento/bskyblock/listeners/protection/IslandGuard1_9.java b/src/main/java/us/tastybento/bskyblock/listeners/protection/IslandGuard1_9.java index 6376ac4b7..313ca2b11 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/protection/IslandGuard1_9.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/protection/IslandGuard1_9.java @@ -54,7 +54,7 @@ public class IslandGuard1_9 implements Listener { public IslandGuard1_9(final BSkyBlock plugin) { this.plugin = plugin; - this.thrownPotions = new HashMap(); + this.thrownPotions = new HashMap<>(); } /** @@ -96,7 +96,7 @@ public class IslandGuard1_9 implements Listener { /** * Handle interaction with end crystals 1.9 - * + * * @param e */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled=true) @@ -217,7 +217,7 @@ public class IslandGuard1_9 implements Listener { plugin.getLogger().info("1.9 " +"Damager is a projectile shot by " + p.getName()); } } - if (p != null) { + if (p != null) { if (p.isOp() || VaultHelper.hasPerm(p, Settings.PERMPREFIX + "mod.bypassprotect")) { if (DEBUG) { plugin.getLogger().info("1.9 " +"Bypassing protection"); @@ -274,18 +274,18 @@ public class IslandGuard1_9 implements Listener { e.blockList().clear(); } else { if (!Settings.allowChestDamage) { - List toberemoved = new ArrayList(); + List toberemoved = new ArrayList<>(); // Save the chest blocks in a list for (Block b : e.blockList()) { switch (b.getType()) { - case CHEST: - case ENDER_CHEST: - case STORAGE_MINECART: - case TRAPPED_CHEST: - toberemoved.add(b); - break; - default: - break; + case CHEST: + case ENDER_CHEST: + case STORAGE_MINECART: + case TRAPPED_CHEST: + toberemoved.add(b); + break; + default: + break; } } // Now delete them @@ -306,7 +306,7 @@ public class IslandGuard1_9 implements Listener { * Handle blocks that need special treatment * Tilling of coarse dirt into dirt using off-hand (regular hand is in 1.8) * Usually prevented because it could lead to an endless supply of dirt with gravel - * + * * @param e */ @SuppressWarnings("deprecation") @@ -359,21 +359,13 @@ public class IslandGuard1_9 implements Listener { return; } // Try to get the shooter - Projectile projectile = (Projectile) e.getEntity(); + Projectile projectile = e.getEntity(); plugin.getLogger().info("shooter = " + projectile.getShooter()); if (projectile.getShooter() != null && projectile.getShooter() instanceof Player) { UUID uuid = ((Player)projectile.getShooter()).getUniqueId(); // Store it and remove it when the effect is gone thrownPotions.put(e.getAreaEffectCloud().getEntityId(), uuid); - plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() { - - @Override - public void run() { - if (DEBUG) - plugin.getLogger().info("DEBUG: Effect finished"); - thrownPotions.remove(e.getAreaEffectCloud().getEntityId()); - - }}, e.getAreaEffectCloud().getDuration()); + plugin.getServer().getScheduler().runTaskLater(plugin, () -> thrownPotions.remove(e.getAreaEffectCloud().getEntityId()), e.getAreaEffectCloud().getDuration()); } } @@ -441,18 +433,14 @@ public class IslandGuard1_9 implements Listener { // Players being hurt PvP if (e.getEntity() instanceof Player) { - if (pvp) { - if (DEBUG) plugin.getLogger().info("DEBUG: PVP allowed"); - return; - } else { + if (!pvp) { if (DEBUG) plugin.getLogger().info("DEBUG: PVP not allowed"); e.setCancelled(true); - return; } } } } - + /** * Checks if action is allowed for player in location for flag * @param uuid @@ -478,7 +466,7 @@ public class IslandGuard1_9 implements Listener { } return false; } - + /** * Action allowed in this location * @param location diff --git a/src/main/java/us/tastybento/bskyblock/listeners/protection/NetherEvents.java b/src/main/java/us/tastybento/bskyblock/listeners/protection/NetherEvents.java index ffd96a3ab..8a675a64c 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/protection/NetherEvents.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/protection/NetherEvents.java @@ -36,7 +36,7 @@ public class NetherEvents implements Listener { /** * This handles non-player portal use * Currently disables portal use by entities - * + * * @param event */ @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @@ -84,7 +84,7 @@ public class NetherEvents implements Listener { } // Vehicles if (event.getEntity() instanceof Vehicle) { - Vehicle vehicle = (Vehicle)event.getEntity(); + Vehicle vehicle = (Vehicle)event.getEntity(); vehicle.eject(); } new SafeSpotTeleport(plugin, event.getEntity(), dest); @@ -95,23 +95,19 @@ public class NetherEvents implements Listener { /** * Function to check proximity to nether spawn location - * + * * @param player * @return true if in the spawn area, false if not */ private boolean awayFromSpawn(Player player) { Vector p = player.getLocation().toVector().multiply(new Vector(1, 0, 1)); Vector spawn = player.getWorld().getSpawnLocation().toVector().multiply(new Vector(1, 0, 1)); - if (spawn.distanceSquared(p) < (Settings.netherSpawnRadius * Settings.netherSpawnRadius)) { - return false; - } else { - return true; - } + return spawn.distanceSquared(p) < (Settings.netherSpawnRadius * Settings.netherSpawnRadius); } /** * Prevents blocks from being broken - * + * * @param e */ @EventHandler(priority = EventPriority.LOW) @@ -136,7 +132,7 @@ public class NetherEvents implements Listener { /** * Prevents placing of blocks - * + * * @param e */ @EventHandler(priority = EventPriority.LOW) @@ -175,7 +171,7 @@ public class NetherEvents implements Listener { /** * Prevent the Nether spawn from being blown up - * + * * @param e */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @@ -203,7 +199,7 @@ public class NetherEvents implements Listener { /** * Converts trees to gravel and glowstone - * + * * @param e */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) diff --git a/src/main/java/us/tastybento/bskyblock/schematics/BannerBlock.java b/src/main/java/us/tastybento/bskyblock/schematics/BannerBlock.java index e385a430a..b8340977f 100644 --- a/src/main/java/us/tastybento/bskyblock/schematics/BannerBlock.java +++ b/src/main/java/us/tastybento/bskyblock/schematics/BannerBlock.java @@ -19,9 +19,9 @@ import us.tastybento.org.jnbt.Tag; /** * This class describes banners and is used in schematic importing - * + * * @author tastybento - * + * */ public class BannerBlock { private DyeColor bannerBaseColor; @@ -33,7 +33,7 @@ public class BannerBlock { // ss, tt static { - patternKey = new HashMap(); + patternKey = new HashMap<>(); patternKey.put("", PatternType.BASE); patternKey.put("bo", PatternType.BORDER); patternKey.put("bri", PatternType.BRICKS); @@ -101,7 +101,7 @@ public class BannerBlock { // baseColor green = 10 bannerBaseColor = DyeColor.getByDyeData((byte) baseColor); // Do the patterns (no idea if this will work or not) - bannerPattern = new ArrayList(); + bannerPattern = new ArrayList<>(); ListTag patterns = (ListTag) tileData.get("Patterns"); if (patterns != null) { for (Tag pattern : patterns.getValue()) { diff --git a/src/main/java/us/tastybento/bskyblock/schematics/EntityObject.java b/src/main/java/us/tastybento/bskyblock/schematics/EntityObject.java index 191bfa230..e7420c9c5 100644 --- a/src/main/java/us/tastybento/bskyblock/schematics/EntityObject.java +++ b/src/main/java/us/tastybento/bskyblock/schematics/EntityObject.java @@ -33,7 +33,7 @@ public class EntityObject { // Items informations private Byte count = null; private Short damage = null; - private String id = null; + private String id = null; /** * @return the type diff --git a/src/main/java/us/tastybento/bskyblock/schematics/IslandBlock.java b/src/main/java/us/tastybento/bskyblock/schematics/IslandBlock.java index 76692f265..8759fe567 100644 --- a/src/main/java/us/tastybento/bskyblock/schematics/IslandBlock.java +++ b/src/main/java/us/tastybento/bskyblock/schematics/IslandBlock.java @@ -44,9 +44,9 @@ public class IslandBlock { private BannerBlock banner; private EntityType spawnerBlockType; // Chest contents - private HashMap chestContents = new HashMap(); - public static final HashMap WEtoM = new HashMap(); - public static final HashMap WEtoME = new HashMap(); + private HashMap chestContents = new HashMap<>(); + public static final HashMap WEtoM = new HashMap<>(); + public static final HashMap WEtoME = new HashMap<>(); static { // Establish the World Edit to Material look up @@ -201,7 +201,7 @@ public class IslandBlock { signText = null; banner = null; spawnerBlockType = null; - chestContents = new HashMap(); + chestContents = new HashMap<>(); } /** * @return the type @@ -265,7 +265,7 @@ public class IslandBlock { */ public void setSpawnerType(Map tileData) { //Bukkit.getLogger().info("DEBUG: " + tileData.toString()); - String creatureType = ""; + String creatureType = ""; if (tileData.containsKey("EntityId")) { creatureType = ((StringTag) tileData.get("EntityId")).getValue().toUpperCase(); } else if (tileData.containsKey("SpawnData")) { @@ -298,8 +298,8 @@ public class IslandBlock { * @param tileData */ public void setSign(Map tileData) { - signText = new ArrayList(); - List text = new ArrayList(); + signText = new ArrayList<>(); + List text = new ArrayList<>(); for (int i = 1; i < 5; i++) { String line = ((StringTag) tileData.get("Text" + String.valueOf(i))).getValue(); // This value can actually be a string that says null sometimes. @@ -374,7 +374,7 @@ public class IslandBlock { Bukkit.getLogger().warning("Unknown format " + value +" in sign when pasting schematic, skipping..."); } } - } + } } } else { // This is unformatted text. It is included in "". A reset is required to clear @@ -382,7 +382,7 @@ public class IslandBlock { if (format.length()>1) { lineText += ChatColor.RESET + format.substring(format.indexOf('"')+1,format.lastIndexOf('"')); } - } + } } } else { // No extra tag diff --git a/src/main/java/us/tastybento/bskyblock/schematics/Schematic.java b/src/main/java/us/tastybento/bskyblock/schematics/Schematic.java index 0b6c53bb3..bd4550804 100644 --- a/src/main/java/us/tastybento/bskyblock/schematics/Schematic.java +++ b/src/main/java/us/tastybento/bskyblock/schematics/Schematic.java @@ -87,7 +87,7 @@ public class Schematic { private String description; private int rating; private boolean useDefaultChest; - private Material icon; + private Material icon; private Biome biome; private boolean usePhysics; private boolean pasteEntities; @@ -142,7 +142,7 @@ public class Schematic { perm = ""; icon = Material.MAP; rating = 50; - useDefaultChest = true; + useDefaultChest = true; biome = Settings.defaultBiome; usePhysics = Settings.usePhysics; file = null; @@ -269,7 +269,7 @@ public class Schematic { attachable.add(Material.BIRCH_DOOR.getId()); attachable.add(Material.SPRUCE_DOOR.getId()); attachable.add(Material.DARK_OAK_DOOR.getId()); - attachable.add(Material.JUNGLE_DOOR.getId()); + attachable.add(Material.JUNGLE_DOOR.getId()); } // Entities @@ -380,7 +380,7 @@ public class Schematic { ent.setType(type); break; } - } + } } } @@ -478,7 +478,7 @@ public class Schematic { if (itemEntry.getValue() instanceof StringTag){ ent.setId(((StringTag) itemEntry.getValue()).getValue()); } - } + } } } } else if (entry.getKey().equals("TileX")){ @@ -583,7 +583,7 @@ public class Schematic { } else if (blocks[index] == 2) { // Grass grassBlocks.add(new Vector(x,y,z)); - } + } } } } @@ -762,8 +762,8 @@ public class Schematic { * This method pastes a schematic. * @param loc * @param player - * @param oldIsland - * @param partner + * @param oldIsland + * @param partner */ public void pasteSchematic(final Location loc, final Player player, boolean teleport, final PasteReason reason, Island oldIsland) { // If this is not a file schematic, paste the default island @@ -895,7 +895,7 @@ public class Schematic { spawned.setVelocity(ent.getMotion()); if (ent.getType() == EntityType.SHEEP) { Sheep sheep = (Sheep)spawned; - if (ent.isSheared()) { + if (ent.isSheared()) { sheep.setSheared(true); } DyeColor[] set = DyeColor.values(); @@ -951,7 +951,7 @@ public class Schematic { grass = gr; } else { grass = null; - } + } //Bukkit.getLogger().info("DEBUG cow location " + grass); Block blockToChange = null; @@ -1088,7 +1088,7 @@ public class Schematic { //IslandCmd.runCommands(Settings.resetCommands, player); } } - + // Delete the old island if required if (oldIsland != null) { plugin.getLogger().info("DEBUG: Deleting old island"); @@ -1237,7 +1237,7 @@ public class Schematic { public void setIcon(Material icon, int damage) { this.icon = icon; - this.durability = damage; + this.durability = damage; } /** * @param icon the icon to set @@ -1302,7 +1302,7 @@ public class Schematic { * Creates the AcidIsland default island block by block * @param islandLoc * @param player - * @param reason + * @param reason */ @SuppressWarnings("deprecation") public void generateIslandBlocks(final Location islandLoc, final Player player, PasteReason reason) { @@ -1476,7 +1476,7 @@ public class Schematic { //plugin.getLogger().info("DEBUG: Reset"); if (!player.hasPermission(Settings.PERMPREFIX + "command.resetexempt")) { //plugin.getLogger().info("DEBUG: Executing reset island commands"); - // IslandCmd.runCommands(Settings.resetCommands, player); + // IslandCmd.runCommands(Settings.resetCommands, player); } } if (!islandCompanion.isEmpty()) { @@ -1490,7 +1490,7 @@ public class Schematic { } /** * Get child tag of a NBT structure. - * + * * @param items * The parent tag map * @param key @@ -1529,7 +1529,7 @@ public class Schematic { //plugin.getLogger().info("DEBUG: name is " + name); companion.setCustomName(name); companion.setCustomNameVisible(true); - } + } } } } diff --git a/src/main/java/us/tastybento/bskyblock/schematics/SchematicsMgr.java b/src/main/java/us/tastybento/bskyblock/schematics/SchematicsMgr.java index 29a0cf66d..8aff7bee4 100644 --- a/src/main/java/us/tastybento/bskyblock/schematics/SchematicsMgr.java +++ b/src/main/java/us/tastybento/bskyblock/schematics/SchematicsMgr.java @@ -29,7 +29,7 @@ public class SchematicsMgr { this.plugin = plugin; loadSchematics(); } - + /** * Loads schematics. If the default * island is not included, it will be made @@ -90,7 +90,7 @@ public class SchematicsMgr { } catch (IOException e) { plugin.getLogger().severe("Could not load default nether schematic!"); e.printStackTrace(); - } + } } else { plugin.getLogger().severe("Could not find default nether schematic!"); } @@ -130,7 +130,7 @@ public class SchematicsMgr { schematics.get("nether").setUseDefaultChest(false); } } - + // TODO: Load other settings from config.yml } @@ -142,7 +142,7 @@ public class SchematicsMgr { public Schematic getSchematic(String name) { return schematics.get(name); } - + /** * List schematics this player can access. If @param ignoreNoPermission is true, then only * schematics with a specific permission set will be checked. I.e., no common schematics will @@ -152,7 +152,7 @@ public class SchematicsMgr { * @return List of schematics this player can use based on their permission level */ public List getSchematics(Player player, boolean ignoreNoPermission) { - List result = new ArrayList(); + List result = new ArrayList<>(); // Find out what schematics this player can choose from //Bukkit.getLogger().info("DEBUG: Checking schematics for " + player.getName()); for (Schematic schematic : schematics.values()) { @@ -175,14 +175,7 @@ public class SchematicsMgr { } } // Sort according to order - Collections.sort(result, new Comparator() { - - @Override - public int compare(Schematic o1, Schematic o2) { - return ((o2.getOrder() < o1.getOrder()) ? 1 : -1); - } - - }); + Collections.sort(result, (s1, s2) -> (s2.getOrder() < s1.getOrder()) ? 1 : -1); return result; } diff --git a/src/main/java/us/tastybento/bskyblock/util/DeleteIslandBlocks.java b/src/main/java/us/tastybento/bskyblock/util/DeleteIslandBlocks.java index 77a1ca3e8..5adcb554c 100644 --- a/src/main/java/us/tastybento/bskyblock/util/DeleteIslandBlocks.java +++ b/src/main/java/us/tastybento/bskyblock/util/DeleteIslandBlocks.java @@ -21,13 +21,13 @@ import us.tastybento.bskyblock.util.nms.NMSAbstraction; /** * Deletes islands fast using chunk regeneration - * + * * @author tastybento - * + * */ public class DeleteIslandBlocks { protected static final int CLEAN_RATE = 2; - private Set chunksToClear = new HashSet(); + private Set chunksToClear = new HashSet<>(); //private HashMap blocksToClear = new HashMap(); private NMSAbstraction nms = null; @@ -133,7 +133,7 @@ public class DeleteIslandBlocks { public void run() { Iterator it = chunksToClear.iterator(); int count = 0; - while (it.hasNext() && count++ < CLEAN_RATE) { + while (it.hasNext() && count++ < CLEAN_RATE) { Pair pair = it.next(); //plugin.getLogger().info("DEBUG: There are " + chunksToClear.size() + " chunks that need to be cleared up"); //plugin.getLogger().info("DEBUG: Deleting chunk " + pair.getLeft() + ", " + pair.getRight()); @@ -142,12 +142,12 @@ public class DeleteIslandBlocks { for (int z = 0; z < 16; z ++) { int xCoord = pair.getLeft() * 16 + x; int zCoord = pair.getRight() * 16 + z; - if (island.inIslandSpace(xCoord, zCoord)) { + if (island.inIslandSpace(xCoord, zCoord)) { //plugin.getLogger().info(xCoord + "," + zCoord + " is in island space - deleting column"); // Delete all the blocks here for (int y = 0; y < IslandWorld.getIslandWorld().getMaxHeight(); y ++) { // Overworld - Block b = IslandWorld.getIslandWorld().getBlockAt(xCoord, y, zCoord); + Block b = IslandWorld.getIslandWorld().getBlockAt(xCoord, y, zCoord); Material bt = b.getType(); Material setTo = Material.AIR; // Split depending on below or above water line @@ -157,57 +157,57 @@ public class DeleteIslandBlocks { // Grab anything out of containers (do that it is // destroyed) switch (bt) { - case CHEST: - case TRAPPED_CHEST: - case FURNACE: - case DISPENSER: - case HOPPER: - final InventoryHolder ih = ((InventoryHolder)b.getState()); - ih.getInventory().clear(); - b.setType(setTo); - break; - case AIR: - if (setTo.equals(Material.STATIONARY_WATER)) { + case CHEST: + case TRAPPED_CHEST: + case FURNACE: + case DISPENSER: + case HOPPER: + final InventoryHolder ih = ((InventoryHolder)b.getState()); + ih.getInventory().clear(); + b.setType(setTo); + break; + case AIR: + if (setTo.equals(Material.STATIONARY_WATER)) { + nms.setBlockSuperFast(b, setTo.getId(), (byte)0, false); + } + case STATIONARY_WATER: + if (setTo.equals(Material.AIR)) { + nms.setBlockSuperFast(b, setTo.getId(), (byte)0, false); + } + default: nms.setBlockSuperFast(b, setTo.getId(), (byte)0, false); - } - case STATIONARY_WATER: - if (setTo.equals(Material.AIR)) { - nms.setBlockSuperFast(b, setTo.getId(), (byte)0, false); - } - default: - nms.setBlockSuperFast(b, setTo.getId(), (byte)0, false); - break; + break; } // Nether, if it exists if (Settings.netherIslands && Settings.netherGenerate && y < IslandWorld.getNetherWorld().getMaxHeight() - 8) { - b = IslandWorld.getNetherWorld().getBlockAt(xCoord, y, zCoord); + b = IslandWorld.getNetherWorld().getBlockAt(xCoord, y, zCoord); bt = b.getType(); - if (!b.equals(Material.AIR)) { - setTo = Material.AIR; + if (!bt.equals(Material.AIR)) { + setTo = Material.AIR; // Grab anything out of containers (do that it is // destroyed) switch (bt) { - case CHEST: - case TRAPPED_CHEST: - case FURNACE: - case DISPENSER: - case HOPPER: - final InventoryHolder ih = ((InventoryHolder)b.getState()); - ih.getInventory().clear(); - b.setType(setTo); - break; - default: - nms.setBlockSuperFast(b, setTo.getId(), (byte)0, false); - break; + case CHEST: + case TRAPPED_CHEST: + case FURNACE: + case DISPENSER: + case HOPPER: + final InventoryHolder ih = ((InventoryHolder)b.getState()); + ih.getInventory().clear(); + b.setType(setTo); + break; + default: + nms.setBlockSuperFast(b, setTo.getId(), (byte)0, false); + break; } } } } - } + } } } - it.remove(); - } + it.remove(); + } if (chunksToClear.isEmpty()){ plugin.getLogger().info("Finished island deletion"); this.cancel(); @@ -217,7 +217,7 @@ public class DeleteIslandBlocks { } } - + /** * Class that pairs two ints together * @author tastybento diff --git a/src/main/java/us/tastybento/bskyblock/util/FileLister.java b/src/main/java/us/tastybento/bskyblock/util/FileLister.java index e53ca9999..82c0a123d 100755 --- a/src/main/java/us/tastybento/bskyblock/util/FileLister.java +++ b/src/main/java/us/tastybento/bskyblock/util/FileLister.java @@ -35,27 +35,16 @@ public class FileLister{ * @throws IOException */ public List list(String folderPath, boolean checkJar) throws IOException { - List result = new ArrayList(); + List result = new ArrayList<>(); // Check if the folder exists File localeDir = new File(plugin.getDataFolder(), folderPath); if (localeDir.exists()) { - FilenameFilter ymlFilter = new FilenameFilter() { - @Override - public boolean accept(File dir, String name) { - String lowercaseName = name.toLowerCase(); - //plugin.getLogger().info("DEBUG: filename = " + name); - if (lowercaseName.endsWith(".yml")) { - return true; - } else { - return false; - } - } - }; + FilenameFilter ymlFilter = (File dir, String name) -> name.toLowerCase().endsWith(".yml"); return Arrays.asList(localeDir.list(ymlFilter)); } else if (checkJar) { // Else look in the JAR - File jarfile = null; + File jarfile; /** * Get the jar file from the plugin. @@ -98,9 +87,9 @@ public class FileLister{ } public List listJar(String folderPath) throws IOException { - List result = new ArrayList(); + List result = new ArrayList<>(); // Look in the JAR - File jarfile = null; + File jarfile; /** * Get the jar file from the plugin. diff --git a/src/main/java/us/tastybento/bskyblock/util/SafeSpotTeleport.java b/src/main/java/us/tastybento/bskyblock/util/SafeSpotTeleport.java index f064d4c43..550ea404f 100644 --- a/src/main/java/us/tastybento/bskyblock/util/SafeSpotTeleport.java +++ b/src/main/java/us/tastybento/bskyblock/util/SafeSpotTeleport.java @@ -20,7 +20,7 @@ import us.tastybento.bskyblock.database.objects.Island; /** * A class that calculates finds a safe spot asynchronously and then teleports the player there. * @author tastybento - * + * */ public class SafeSpotTeleport { @@ -56,7 +56,7 @@ public class SafeSpotTeleport { */ public SafeSpotTeleport(final BSkyBlock plugin, final Entity player, final Location l) { new SafeSpotTeleport(plugin, player, l, 1, "", false); - } + } /** * Teleport to a safe spot on an island @@ -88,7 +88,7 @@ public class SafeSpotTeleport { for (int z = island.getMinProtectedZ() /16; z <= (island.getMinProtectedZ() + island.getProtectionRange() - 1)/16; z++) { // This includes the center spots again, so is not as efficient... chunkSnapshot.add(world.getChunkAt(x, z).getChunkSnapshot()); - } + } } //plugin.getLogger().info("DEBUG: size of chunk ss = " + chunkSnapshot.size()); final List finalChunk = chunkSnapshot; @@ -223,23 +223,20 @@ public class SafeSpotTeleport { if (player.getGameMode().equals(GameMode.SPECTATOR)) { player.setGameMode(GameMode.SURVIVAL); } - } + } }}); } else { // We did not find a spot - plugin.getServer().getScheduler().runTask(plugin, new Runnable() { - - @Override - public void run() { - //plugin.getLogger().info("DEBUG: safe spot not found"); - if (entity instanceof Player) { - if (!failureMessage.isEmpty()) { - Util.sendMessage(((Player)entity), failureMessage); - } else { - Util.sendMessage(((Player)entity), ChatColor.RED + "Warp not safe"); - } + plugin.getServer().getScheduler().runTask(plugin, () -> { + //plugin.getLogger().info("DEBUG: safe spot not found"); + if (entity instanceof Player) { + if (!failureMessage.isEmpty()) { + Util.sendMessage(entity, failureMessage); + } else { + Util.sendMessage(entity, ChatColor.RED + "Warp not safe"); } - }}); + } + }); } } @@ -249,7 +246,7 @@ public class SafeSpotTeleport { * @param x * @param y * @param z - * @param worldHeight + * @param worldHeight * @return */ @SuppressWarnings("deprecation") @@ -262,44 +259,44 @@ public class SafeSpotTeleport { // Now there is a chance that this is a safe spot // Check for safe ground Material mat = Material.getMaterial(type); - if (!mat.toString().contains("FENCE") + if (!mat.toString().contains("FENCE") && !mat.toString().contains("DOOR") && !mat.toString().contains("GATE") && !mat.toString().contains("PLATE")) { switch (mat) { - // Unsafe - case ANVIL: - case BARRIER: - case BOAT: - case CACTUS: - case DOUBLE_PLANT: - case ENDER_PORTAL: - case FIRE: - case FLOWER_POT: - case LADDER: - case LAVA: - case LEVER: - case LONG_GRASS: - case PISTON_EXTENSION: - case PISTON_MOVING_PIECE: - case PORTAL: - case SIGN_POST: - case SKULL: - case STANDING_BANNER: - case STATIONARY_LAVA: - case STATIONARY_WATER: - case STONE_BUTTON: - case TORCH: - case TRIPWIRE: - case WATER: - case WEB: - case WOOD_BUTTON: - //System.out.println("Block is dangerous " + mat.toString()); - break; - default: - // Safe - // System.out.println("Block is safe " + mat.toString()); - return true; + // Unsafe + case ANVIL: + case BARRIER: + case BOAT: + case CACTUS: + case DOUBLE_PLANT: + case ENDER_PORTAL: + case FIRE: + case FLOWER_POT: + case LADDER: + case LAVA: + case LEVER: + case LONG_GRASS: + case PISTON_EXTENSION: + case PISTON_MOVING_PIECE: + case PORTAL: + case SIGN_POST: + case SKULL: + case STANDING_BANNER: + case STATIONARY_LAVA: + case STATIONARY_WATER: + case STONE_BUTTON: + case TORCH: + case TRIPWIRE: + case WATER: + case WEB: + case WOOD_BUTTON: + //System.out.println("Block is dangerous " + mat.toString()); + break; + default: + // Safe + // System.out.println("Block is safe " + mat.toString()); + return true; } } } @@ -308,40 +305,4 @@ public class SafeSpotTeleport { }}); } } - - /** - * Checks what version the server is running and picks the appropriate NMS handler, or fallback - * @return NMSAbstraction class - * @throws ClassNotFoundException - * @throws IllegalArgumentException - * @throws SecurityException - * @throws InstantiationException - * @throws IllegalAccessException - * @throws InvocationTargetException - * @throws NoSuchMethodException - */ - /* - private NMSAbstraction checkVersion() throws ClassNotFoundException, IllegalArgumentException, - SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, - NoSuchMethodException { - String serverPackageName = plugin.getServer().getClass().getPackage().getName(); - String pluginPackageName = plugin.getClass().getPackage().getName(); - String version = serverPackageName.substring(serverPackageName.lastIndexOf('.') + 1); - Class clazz; - try { - //plugin.getLogger().info("DEBUG: Trying " + pluginPackageName + ".nms." + version + ".NMSHandler"); - clazz = Class.forName(pluginPackageName + ".nms." + version + ".NMSHandler"); - } catch (Exception e) { - plugin.getLogger().info("No NMS Handler found, falling back to Bukkit API."); - clazz = Class.forName(pluginPackageName + ".nms.fallback.NMSHandler"); - } - //plugin.getLogger().info("DEBUG: " + serverPackageName); - //plugin.getLogger().info("DEBUG: " + pluginPackageName); - // Check if we have a NMSAbstraction implementing class at that location. - if (NMSAbstraction.class.isAssignableFrom(clazz)) { - return (NMSAbstraction) clazz.getConstructor().newInstance(); - } else { - throw new IllegalStateException("Class " + clazz.getName() + " does not implement NMSAbstraction"); - } - }*/ } \ No newline at end of file diff --git a/src/main/java/us/tastybento/bskyblock/util/Util.java b/src/main/java/us/tastybento/bskyblock/util/Util.java index 3e79be40a..dc59c1977 100755 --- a/src/main/java/us/tastybento/bskyblock/util/Util.java +++ b/src/main/java/us/tastybento/bskyblock/util/Util.java @@ -27,7 +27,7 @@ import us.tastybento.bskyblock.util.placeholders.PlaceholderHandler; /** * A set of utility methods - * + * * @author Tastybento * @author Poslovitch */ @@ -36,7 +36,7 @@ public class Util { public static void sendMessage(CommandSender receiver, String message){ message = PlaceholderHandler.replacePlaceholders(receiver, message); - + if (!ChatColor.stripColor(message).trim().isEmpty()) { for(String part : message.split("\n")){ receiver.sendMessage(part); @@ -56,8 +56,8 @@ public class Util { * @throws NoSuchMethodException */ public static NMSAbstraction getNMSHandler() throws ClassNotFoundException, IllegalArgumentException, - SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, - NoSuchMethodException { + SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, + NoSuchMethodException { String serverPackageName = plugin.getServer().getClass().getPackage().getName(); String pluginPackageName = plugin.getClass().getPackage().getName(); String version = serverPackageName.substring(serverPackageName.lastIndexOf('.') + 1); @@ -79,13 +79,13 @@ public class Util { /** * Converts a serialized location to a Location. Returns null if string is * empty - * + * * @param s * - serialized location in format "world:x:y:z" * @return Location */ static public Location getLocationString(final String s) { - if (s == null || s.trim() == "") { + if (s == null || s.trim().equals("")) { return null; } final String[] parts = s.split(":"); @@ -116,7 +116,7 @@ public class Util { /** * Converts a location to a simple string representation * If location is null, returns empty string - * + * * @param location * @return String of location */ @@ -126,14 +126,14 @@ public class Util { } return location.getWorld().getName() + ":" + location.getBlockX() + ":" + location.getBlockY() + ":" + location.getBlockZ() + ":" + Float.floatToIntBits(location.getYaw()) + ":" + Float.floatToIntBits(location.getPitch()); } - + /** * Get a list of parameter types for the collection argument in this method * @param writeMethod * @return */ public static List getCollectionParameterTypes(Method writeMethod) { - List result = new ArrayList(); + List result = new ArrayList<>(); // Get the return type // This uses a trick to extract what the arguments are of the writeMethod of the field. // In this way, we can deduce what type needs to be written at runtime. @@ -164,7 +164,7 @@ public class Util { public static List getPlayerInHandItems(Player player) { List result = new ArrayList(2); if (plugin.getServer().getVersion().contains("(MC: 1.7") - || plugin.getServer().getVersion().contains("(MC: 1.8")) { + || plugin.getServer().getVersion().contains("(MC: 1.8")) { if (player.getItemInHand() != null) result.add(player.getItemInHand()); return result; @@ -178,11 +178,11 @@ public class Util { /** * Converts a name like IRON_INGOT into Iron Ingot to improve readability - * + * * @param ugly * The string such as IRON_INGOT * @return A nicer version, such as Iron Ingot - * + * * Credits to mikenon on GitHub! */ public static String prettifyText(String ugly) { @@ -214,7 +214,7 @@ public class Util { @SuppressWarnings("deprecation") public static boolean playerIsHolding(Player player, Material type) { if (plugin.getServer().getVersion().contains("(MC: 1.7") - || plugin.getServer().getVersion().contains("(MC: 1.8")) { + || plugin.getServer().getVersion().contains("(MC: 1.8")) { if (player.getItemInHand() != null && player.getItemInHand().getType().equals(type)) { return true; } @@ -228,7 +228,7 @@ public class Util { } return false; } - + /** * Display message to player in action bar (1.11+ or chat) * @param player @@ -246,7 +246,7 @@ public class Util { plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), "minecraft:title " + player.getName() + " actionbar {\"text\":\"" + ChatColor.stripColor(message) + "\"}"); } - + /** * Determines if a location is in the island world or not or * in the new nether if it is activated @@ -267,7 +267,7 @@ public class Util { } return true; } - + /** * Determines if an entity is in the island world or not or * in the new nether if it is activated @@ -293,27 +293,27 @@ public class Util { * @return */ public static List getOnlinePlayerList(Player player) { - final List returned = new ArrayList(); + final List returned = new ArrayList<>(); for (Player p : Bukkit.getServer().getOnlinePlayers()) { if (player == null) { returned.add(p.getName()); } else if (player.canSee(p)) { - returned.add(p.getName()); + returned.add(p.getName()); } } return returned; } - + /** * Returns all of the items that begin with the given start, * ignoring case. Intended for tabcompletion. - * + * * @param list * @param start * @return List of items that start with the letters */ public static List tabLimit(final List list, final String start) { - final List returned = new ArrayList(); + final List returned = new ArrayList<>(); for (String s : list) { if (s == null) continue; diff --git a/src/main/java/us/tastybento/bskyblock/util/VaultHelper.java b/src/main/java/us/tastybento/bskyblock/util/VaultHelper.java index 13c17603e..c64a9c095 100755 --- a/src/main/java/us/tastybento/bskyblock/util/VaultHelper.java +++ b/src/main/java/us/tastybento/bskyblock/util/VaultHelper.java @@ -17,7 +17,7 @@ public class VaultHelper { /** * Sets up the economy instance - * + * * @return true if successful */ public static boolean setupEconomy() { @@ -31,7 +31,7 @@ public class VaultHelper { /** * Sets up the permissions instance - * + * * @return true if successful */ public static boolean setupPermissions() { @@ -45,7 +45,7 @@ public class VaultHelper { /** * Checks permission of player in the world the player is in now - * + * * @param player * @param perm * @return true if the player has the perm @@ -56,7 +56,7 @@ public class VaultHelper { /** * Checks permission of player in world - * + * * @param player * @param perm * @param world @@ -68,14 +68,14 @@ public class VaultHelper { /** * Adds permission to player - * + * * @param player * @param perm */ public static void addPerm(final Player player, final String perm) { permission.playerAdd(player, perm); } - + /** * Add permission to player in world * @param player @@ -88,7 +88,7 @@ public class VaultHelper { /** * Removes a player's permission - * + * * @param player * @param perm */ @@ -98,7 +98,7 @@ public class VaultHelper { /** * Removes a player's permission in world - * + * * @param player * @param perm * @param world