diff --git a/src/main/java/me/vik1395/ProtectionStones/ListenerClass.java b/src/main/java/me/vik1395/ProtectionStones/ListenerClass.java index 9b992afa..665f7e0f 100644 --- a/src/main/java/me/vik1395/ProtectionStones/ListenerClass.java +++ b/src/main/java/me/vik1395/ProtectionStones/ListenerClass.java @@ -316,18 +316,8 @@ public void onBlockBreak(BlockBreakEvent e) { // return protection stone if no drop option is off if (!blockOptions.noDrop()) { - ItemStack oreblock = new ItemStack(pb.getType(), 1, pb.getData()); - int freeSpace = 0; - for (ItemStack i : p.getInventory()) { - if (i == null) { - freeSpace += oreblock.getType().getMaxStackSize(); - } else if (i.getType() == oreblock.getType()) { - freeSpace += i.getType().getMaxStackSize() - i.getAmount(); - } - } - if (freeSpace >= 1) { - p.getInventory().addItem(oreblock); - } else { + if (!p.getInventory().addItem(new ItemStack(pb.getType(), 1)).isEmpty()) { + // method will return not empty if item couldn't be added p.sendMessage(PSL.NO_ROOM_IN_INVENTORY.msg()); e.setCancelled(true); return; diff --git a/src/main/java/me/vik1395/ProtectionStones/PSL.java b/src/main/java/me/vik1395/ProtectionStones/PSL.java index 6a74cc0c..3d8b16c6 100644 --- a/src/main/java/me/vik1395/ProtectionStones/PSL.java +++ b/src/main/java/me/vik1395/ProtectionStones/PSL.java @@ -35,9 +35,9 @@ public enum PSL { COMMAND_REQUIRES_PLAYER_NAME("command_requires_player_name", ChatColor.RED + "This command requires a player name."), - NO_PERMISSION_TOGGLE("no_permission_toggle", ChatColor.DARK_GRAY + "Missing permission: " + ChatColor.AQUA + "protectionstones.toggle"), - NO_PERMISSION_CREATE("no_permission_create", ChatColor.RED + "You don't have permission to place a protection stone."), - NO_PERMISSION_DESTROY("no_permission_destroy", ChatColor.RED + "You don't have permission to destroy a protection stone."), + NO_PERMISSION_TOGGLE("no_permission_toggle", ChatColor.RED + "You don't have permission to use the toggle command."), + NO_PERMISSION_CREATE("no_permission_create", ChatColor.RED + "You don't have permission to place a protection block."), + NO_PERMISSION_DESTROY("no_permission_destroy", ChatColor.RED + "You don't have permission to destroy a protection block."), NO_PERMISSION_MEMBERS("no_permission_members", ChatColor.RED + "You don't have permission to use member commands."), NO_PERMISSION_OWNERS("no_permission_owners", ChatColor.RED + "You don't have permission to use owner commands."), NO_PERMISSION_ADMIN("no_permission_admin", ChatColor.RED + "You do not have permission to use that command."), @@ -45,18 +45,18 @@ public enum PSL { NO_PERMISSION_COUNT_OTHERS("no_permission_count_others", ChatColor.RED + "You do not have permission to use that command."), NO_PERMISSION_FLAGS("no_permission_flags", ChatColor.RED + "You do not have permission to use flag commands."), NO_PERMISSION_PER_FLAG("no_permission_per_flag", ChatColor.RED + "You do not have permission to use that flag."), - NO_PERMISSION_UNHIDE("no_permission_unhide", ChatColor.RED + "You do not have permission to unhide protection stones."), - NO_PERMISSION_HIDE("no_permission_hide", ChatColor.RED + " You do not have permission to hide protection stones."), + NO_PERMISSION_UNHIDE("no_permission_unhide", ChatColor.RED + "You do not have permission to unhide protection blocks."), + NO_PERMISSION_HIDE("no_permission_hide", ChatColor.RED + " You do not have permission to hide protection blocks."), NO_PERMISSION_INFO("no_permission_info", ChatColor.RED + "You do not have permission to use the region info command."), NO_PERMISSION_PRIORITY("no_permission_priority", ChatColor.RED + "You do not have permission to use the priority command."), NO_PERMISSION_REGION("no_permission_region", ChatColor.RED + "You do not have permission to use region commands."), - NO_PERMISSION_TP("no_permission_tp", ChatColor.RED + "You do not have permission to teleport to other players' protection stones."), - NO_PERMISSION_HOME("no_permission_home", ChatColor.RED + "You do not have permission to teleport to your protection stones."), + NO_PERMISSION_TP("no_permission_tp", ChatColor.RED + "You do not have permission to teleport to other players' protection blocks."), + NO_PERMISSION_HOME("no_permission_home", ChatColor.RED + "You do not have permission to teleport to your protection blocks."), NO_PERMISSION_UNCLAIM("no_permission_unclaim", ChatColor.RED + "You do not have permission to use the unclaim command."), NO_PERMISSION_VIEW("no_permission_view", ChatColor.RED + "You do not have permission to use the view command."), - ADDED_TO_REGION("psregion.added_to_region", ChatColor.YELLOW + "%player% has been added to this region."), - REMOVED_FROM_REGION("psregion.removed_from_region", ChatColor.YELLOW + "%player% has been removed from region."), + ADDED_TO_REGION("psregion.added_to_region", ChatColor.AQUA + "%player%" + ChatColor.GRAY + " has been added to this region."), + REMOVED_FROM_REGION("psregion.removed_from_region", ChatColor.AQUA + "%player%" + ChatColor.GRAY + " has been removed from region."), NOT_IN_REGION("psregion.not_in_region", ChatColor.RED + "You are not in a protection stone region!"), PLAYER_NOT_FOUND("psregion.player_not_found", ChatColor.RED + "Player not found."), NOT_PS_REGION("psregion.not_ps_region", ChatColor.RED + "Not a protection stones region."), @@ -68,56 +68,59 @@ public enum PSL { CANT_PROTECT_THAT("psregion.cant_protect_that", ChatColor.RED + "You can't protect that area."), REACHED_REGION_LIMIT("psregion.reached_region_limit", ChatColor.RED + "You can not create any more protected regions."), WORLD_DENIED_CREATE("psregion.world_denied_create", ChatColor.RED + "You can not create protections in this world."), - REGION_OVERLAP("psregion.region_overlap", ChatColor.RED + "You can not place a protection here as it overlaps another region."), + REGION_OVERLAP("psregion.region_overlap", ChatColor.RED + "You can not place a protection block here as it overlaps another region."), // ps toggle TOGGLE_HELP("toggle.help", ChatColor.AQUA + "> " + ChatColor.GRAY + "/ps toggle"), TOGGLE_HELP_DESC("toggle.help_desc", "Use this command to turn on or off placement of protection blocks."), - TOGGLE_ON("toggle.toggle_on", ChatColor.YELLOW + "Protection block placement turned on."), - TOGGLE_OFF("toggle.toggle_off", ChatColor.YELLOW + "Protection block placement turned off."), + TOGGLE_ON("toggle.toggle_on", ChatColor.AQUA + "Protection block placement turned on."), + TOGGLE_OFF("toggle.toggle_off", ChatColor.AQUA + "Protection block placement turned off."), // ps count COUNT_HELP("count.count_help", ChatColor.AQUA + "> " + ChatColor.GRAY + "/ps count [player (optional)]"), COUNT_HELP_DESC("count.count_help_desc", "Count the number of regions you own or another player."), - PERSONAL_REGION_COUNT("count.personal_region_count", ChatColor.YELLOW + "Your region count in this world: %num%"), - OTHER_REGION_COUNT("count.other_region_count", ChatColor.YELLOW + "%player%'s region count in this world: %num%"), + PERSONAL_REGION_COUNT("count.personal_region_count", ChatColor.GRAY + "Your region count in this world: " + ChatColor.AQUA + "%num%"), + OTHER_REGION_COUNT("count.other_region_count", ChatColor.GRAY + "%player%'s region count in this world: " + ChatColor.AQUA + "%num%"), // ps flag FLAG_HELP("flag.help", ChatColor.AQUA + "> " + ChatColor.GRAY + "/ps flag [flagname] [value|null]"), FLAG_HELP_DESC("flag.help_desc", "Use this command to set a flag in your protected region."), - FLAG_SET("flag.flag_set", ChatColor.YELLOW + "%flag% flag has been set."), - FLAG_NOT_SET("flag.flag_not_set", ChatColor.YELLOW + "%flag% flag has " + ChatColor.RED + "not" + ChatColor.YELLOW + " been set."), + FLAG_SET("flag.flag_set", ChatColor.AQUA + "%flag%" + ChatColor.GRAY + " flag has been set."), + FLAG_NOT_SET("flag.flag_not_set", ChatColor.AQUA + "%flag%" + ChatColor.GRAY + " flag has " + ChatColor.RED + "not" + ChatColor.GRAY + " been set."), // ps hide/unhide VISIBILITY_HIDE_HELP("visibility.hide_help", ChatColor.AQUA + "> " + ChatColor.GRAY + "/ps hide"), VISIBILITY_HIDE_HELP_DESC("visibility.hide_help_desc", "Use this command to hide or unhide your protection block."), VISIBILITY_UNHIDE_HELP("visibility.unhide_help", ChatColor.AQUA + "> " + ChatColor.GRAY + "/ps unhide"), VISIBILITY_UNHIDE_HELP_DESC("visibility.unhide_help_desc", "Use this command to hide or unhide your protection block."), - ALREADY_NOT_HIDDEN("visibility.already_not_hidden", ChatColor.YELLOW + "The protection stone doesn't appear hidden..."), - ALREADY_HIDDEN("visibility.already_hidden", ChatColor.YELLOW + "The protection stone appears to already be hidden..."), + ALREADY_NOT_HIDDEN("visibility.already_not_hidden", ChatColor.GRAY + "The protection stone doesn't appear hidden..."), + ALREADY_HIDDEN("visibility.already_hidden", ChatColor.GRAY + "The protection stone appears to already be hidden..."), // ps info INFO_HELP("info.help", ChatColor.AQUA + "> " + ChatColor.GRAY + "/ps info members|owners|flags"), INFO_HELP_DESC("info.help_desc", "Use this command inside a ps region to see more information about it."), - INFO_HEADER("info.info_header", ChatColor.GRAY + "================ PS Info ================"), - INFO_MEMBERS("info.info_members", ChatColor.BLUE + "Members:"), - INFO_NO_MEMBERS("info.info_no_members", ChatColor.RED + "(no members)"), - INFO_OWNERS("info.info_owners", ChatColor.BLUE + "Owners:"), - INFO_NO_OWNERS("info.info_no_owners", ChatColor.RED + "(no owners)"), - INFO_FLAGS("info.info_flags", ChatColor.BLUE + "Flags: " + ChatColor.YELLOW), + INFO_HEADER("info.header", ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "=====" + ChatColor.RESET + " PS Info " + ChatColor.DARK_GRAY + ChatColor.STRIKETHROUGH + "====="), + INFO_MEMBERS("info.members", ChatColor.BLUE + "Members: " + ChatColor.GRAY), + INFO_NO_MEMBERS("info.no_members", ChatColor.RED + "(no members)"), + INFO_OWNERS("info.owners", ChatColor.BLUE + "Owners: " + ChatColor.GRAY), + INFO_NO_OWNERS("info.no_owners", ChatColor.RED + "(no owners)"), + INFO_FLAGS("info.flags", ChatColor.BLUE + "Flags: " + ChatColor.GRAY), + INFO_REGION("info.region", ChatColor.BLUE + "Region: " + ChatColor.AQUA), + INFO_PRIORITY("info.priority", ChatColor.BLUE + "Priority: " + ChatColor.AQUA), + INFO_BOUNDS("info.bounds", ChatColor.BLUE + "Bounds: " + ChatColor.AQUA), // ps priority PRIORITY_HELP("priority.help", ChatColor.AQUA + "> " + ChatColor.GRAY + "/ps priority [number|null]"), PRIORITY_HELP_DESC("priority.help_desc", "Use this command to set your region's priority."), - PRIORITY_INFO("priority.priority_info", ChatColor.YELLOW + "Priority: %priority%"), - PRIORITY_SET("priority.priority_set", ChatColor.YELLOW + "Priority has been set."), - PRIORITY_ERROR("priority.priority_error", ChatColor.RED + "Error parsing input, check it again?"), + PRIORITY_INFO("priority.info", ChatColor.GRAY + "Priority: %priority%"), + PRIORITY_SET("priority.set", ChatColor.YELLOW + "Priority has been set."), + PRIORITY_ERROR("priority.error", ChatColor.RED + "Error parsing input, check it again?"), // ps region REGION_HELP("region.help", ChatColor.AQUA + "> " + ChatColor.GRAY + "/ps region [count|list|remove|disown] [playername]"), REGION_HELP_DESC("region.help_desc", "Use this command to find information or edit other players' (or your own) protected regions."), - REGION_NOT_FOUND_FOR_PLAYER("region.not_found_for_player", ChatColor.YELLOW + "No regions found for %player% in this world."), - REGION_LIST("region.list", ChatColor.YELLOW + "%player%'s regions in this world: %regions%"), + REGION_NOT_FOUND_FOR_PLAYER("region.not_found_for_player", ChatColor.GRAY + "No regions found for %player% in this world."), + REGION_LIST("region.list", ChatColor.GRAY + "%player%'s regions in this world: " + ChatColor.AQUA + "%regions%"), REGION_REMOVE("region.remove", ChatColor.YELLOW + "%player%'s regions have been removed in this world."), REGION_ERROR_SEARCH("region.error_search", ChatColor.RED + "Error while searching for %player%'s regions. Please make sure you have entered the correct name."), @@ -138,19 +141,19 @@ public enum PSL { // ps unclaim UNCLAIM_HELP("unclaim.help", ChatColor.AQUA + "> " + ChatColor.GRAY + "/ps unclaim"), UNCLAIM_HELP_DESC("unclaim.help_desc", "Use this command to pickup a placed protection stone and remove the region."), - UNCLAIM_CANT_FIND("unclaim.cant_find", ChatColor.RED + "We can't seem to find the protection stone! Please ask an admin to remove the region manually."), + UNCLAIM_CANT_FIND("unclaim.cant_find", ChatColor.RED + "We can't seem to find the protection block! Please ask an admin to remove the region manually."), // ps view VIEW_HELP("view.help", ChatColor.AQUA + "> " + ChatColor.GRAY + "/ps view"), VIEW_HELP_DESC("view.help_desc", "Use this command to view the borders of a protected region."), - VIEW_GENERATING("view.generating", ChatColor.YELLOW + "Generating border..."), + VIEW_GENERATING("view.generating", ChatColor.GRAY + "Generating border..."), VIEW_GENERATE_DONE("view.generate_done", ChatColor.GREEN + "Done! The border will disappear after 30 seconds!"), - VIEW_REMOVING("view.removing", ChatColor.YELLOW + "Removing border...\n" + ChatColor.GREEN + "If you still see ghost blocks, relog!"), + VIEW_REMOVING("view.removing", ChatColor.AQUA + "Removing border...\n" + ChatColor.GREEN + "If you still see ghost blocks, relog!"), // ps admin ADMIN_HELP("admin.help", ChatColor.AQUA + "> " + ChatColor.GRAY + "/ps admin { version | settings | hide | unhide |\n" + ChatColor.GRAY + " cleanup | lastlogon | lastlogons | stats }"), ADMIN_HELP_DESC("admin.help_desc", "This is an admin command showing different stats and allowing to override other player's regions."), - ADMIN_CLEANUP_HELP("admin.cleanup_help", ChatColor.YELLOW + "/ps admin cleanup [remove|disown] [days]"), + ADMIN_CLEANUP_HELP("admin.cleanup_help", ChatColor.AQUA + "> " + ChatColor.GRAY + "/ps admin cleanup [remove|disown] [days]"), ADMIN_CLEANUP_HEADER("admin.cleanup_header", ChatColor.YELLOW + "Cleanup %arg% %days% days\n================"), ADMIN_CLEANUP_FOOTER("admin.cleanup_footer", ChatColor.YELLOW + "================\nCompleted %arg% cleanup."), ADMIN_HIDE_TOGGLED("admin.hide_toggled", ChatColor.YELLOW + "All protection stones have been %message% in this world."), diff --git a/src/main/java/me/vik1395/ProtectionStones/commands/ArgAdmin.java b/src/main/java/me/vik1395/ProtectionStones/commands/ArgAdmin.java index a88df7fb..f95d46bd 100644 --- a/src/main/java/me/vik1395/ProtectionStones/commands/ArgAdmin.java +++ b/src/main/java/me/vik1395/ProtectionStones/commands/ArgAdmin.java @@ -37,8 +37,7 @@ public static boolean argumentAdmin(Player p, String[] args) { } if (args.length < 2) { - p.sendMessage(ChatColor.RED + "/ps admin {version|settings|hide|unhide|"); - p.sendMessage(ChatColor.RED + " cleanup|lastlogon|lastlogons|stats}"); + p.sendMessage(PSL.ADMIN_HELP.msg()); return true; } diff --git a/src/main/java/me/vik1395/ProtectionStones/commands/ArgInfo.java b/src/main/java/me/vik1395/ProtectionStones/commands/ArgInfo.java index d1b6629a..6a84737f 100644 --- a/src/main/java/me/vik1395/ProtectionStones/commands/ArgInfo.java +++ b/src/main/java/me/vik1395/ProtectionStones/commands/ArgInfo.java @@ -59,7 +59,7 @@ public static boolean argumentInfo(Player p, String[] args, String psID) { } p.sendMessage(PSL.INFO_HEADER.msg()); - p.sendMessage(ChatColor.BLUE + "Region: " + ChatColor.YELLOW + psID + ChatColor.BLUE + ", Priority: " + ChatColor.YELLOW + rgm.getRegion(psID).getPriority()); + p.sendMessage(PSL.INFO_REGION.msg() + psID + ", " + PSL.INFO_PRIORITY.msg() + rgm.getRegion(psID).getPriority()); displayFlags(p, region); @@ -68,7 +68,7 @@ public static boolean argumentInfo(Player p, String[] args, String psID) { BlockVector3 min = region.getMinimumPoint(); BlockVector3 max = region.getMaximumPoint(); - p.sendMessage(ChatColor.BLUE + "Bounds: " + ChatColor.YELLOW + "(" + min.getBlockX() + "," + min.getBlockY() + "," + min.getBlockZ() + ") -> (" + max.getBlockX() + "," + max.getBlockY() + "," + max.getBlockZ() + ")"); + p.sendMessage(PSL.INFO_BOUNDS.msg() + "(" + min.getBlockX() + "," + min.getBlockY() + "," + min.getBlockZ() + ") -> (" + max.getBlockX() + "," + max.getBlockY() + "," + max.getBlockZ() + ")"); } else if (args.length == 2) { // get specific information on current region @@ -130,12 +130,11 @@ private static void displayFlags(Player p, ProtectedRegion region) { private static void displayOwners(Player p, ProtectedRegion region) { DefaultDomain owners = region.getOwners(); - StringBuilder send = new StringBuilder(PSL.INFO_OWNERS.msg() + " "); + StringBuilder send = new StringBuilder(PSL.INFO_OWNERS.msg()); if (owners.size() == 0) { send.append(PSL.INFO_NO_OWNERS.msg()); p.sendMessage(send.toString()); } else { - send.append(ChatColor.YELLOW); for (UUID uuid : owners.getUniqueIds()) { String name = ProtectionStones.uuidToName.get(uuid); if (name == null) name = Bukkit.getOfflinePlayer(uuid).getName(); @@ -150,12 +149,11 @@ private static void displayOwners(Player p, ProtectedRegion region) { private static void displayMembers(Player p, ProtectedRegion region) { DefaultDomain members = region.getMembers(); - StringBuilder send = new StringBuilder(PSL.INFO_MEMBERS.msg() + " "); + StringBuilder send = new StringBuilder(PSL.INFO_MEMBERS.msg()); if (members.size() == 0) { send.append(PSL.INFO_NO_MEMBERS.msg()); p.sendMessage(send.toString()); } else { - send.append(ChatColor.YELLOW); for (UUID uuid : members.getUniqueIds()) { String name = ProtectionStones.uuidToName.get(uuid); if (name == null) name = uuid.toString(); diff --git a/src/main/java/me/vik1395/ProtectionStones/commands/ArgUnclaim.java b/src/main/java/me/vik1395/ProtectionStones/commands/ArgUnclaim.java index 4230da5a..2e11fc02 100644 --- a/src/main/java/me/vik1395/ProtectionStones/commands/ArgUnclaim.java +++ b/src/main/java/me/vik1395/ProtectionStones/commands/ArgUnclaim.java @@ -99,19 +99,9 @@ public static boolean argumentUnclaim(Player p, String[] args, String psID) { // if (!ProtectionStones.getProtectStoneOptions(type).noDrop()) { - boolean freeSpace = false; - for (ItemStack is : p.getInventory().getContents()) { - if (is == null) { - freeSpace = true; - break; - } - } - // return protection stone - if (freeSpace) { - PlayerInventory inventory = p.getInventory(); - inventory.addItem(new ItemStack(blockToUnhide.getType())); - } else { + if (!p.getInventory().addItem(new ItemStack(blockToUnhide.getType())).isEmpty()) { + // method will return not empty if item couldn't be added p.sendMessage(PSL.NO_ROOM_IN_INVENTORY.msg()); return true; }