diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/Managers/AntiCopyBlockManager.java b/src/main/lombok/nl/SBDeveloper/V10Lift/Managers/AntiCopyBlockManager.java index e362f02..0807967 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/Managers/AntiCopyBlockManager.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/Managers/AntiCopyBlockManager.java @@ -3,13 +3,14 @@ package nl.SBDeveloper.V10Lift.Managers; import nl.SBDeveloper.V10Lift.Utils.XMaterial; import org.bukkit.Material; -import java.util.ArrayList; +import java.util.HashSet; public class AntiCopyBlockManager { - private ArrayList antiCopy = new ArrayList<>(); + private HashSet antiCopy = new HashSet<>(); public AntiCopyBlockManager() { //TODO Add more anti copy materials + //TODO Add to config antiCopy.add(XMaterial.REDSTONE_TORCH); antiCopy.add(XMaterial.REDSTONE_WALL_TORCH); antiCopy.add(XMaterial.REPEATER); @@ -56,6 +57,26 @@ public class AntiCopyBlockManager { antiCopy.add(XMaterial.DETECTOR_RAIL); antiCopy.add(XMaterial.ACTIVATOR_RAIL); antiCopy.add(XMaterial.LADDER); + + /* Because of datatypes */ + antiCopy.add(XMaterial.BEEHIVE); + antiCopy.add(XMaterial.BELL); + antiCopy.add(XMaterial.BREWING_STAND); + antiCopy.add(XMaterial.BUBBLE_COLUMN); + antiCopy.add(XMaterial.CAKE); + antiCopy.add(XMaterial.CAMPFIRE); + antiCopy.add(XMaterial.COCOA); + antiCopy.add(XMaterial.COMMAND_BLOCK); + antiCopy.add(XMaterial.CHAIN_COMMAND_BLOCK); + antiCopy.add(XMaterial.REPEATING_COMMAND_BLOCK); + antiCopy.add(XMaterial.DAYLIGHT_DETECTOR); + antiCopy.add(XMaterial.DISPENSER); + antiCopy.add(XMaterial.END_PORTAL_FRAME); + antiCopy.add(XMaterial.FARMLAND); + antiCopy.add(XMaterial.FIRE); + antiCopy.add(XMaterial.FURNACE); + antiCopy.add(XMaterial.HOPPER); + antiCopy.add(XMaterial.JUKEBOX); } public boolean isAntiCopy(Material mat) { diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/Managers/ForbiddenBlockManager.java b/src/main/lombok/nl/SBDeveloper/V10Lift/Managers/ForbiddenBlockManager.java index ed82a1b..2deabc7 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/Managers/ForbiddenBlockManager.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/Managers/ForbiddenBlockManager.java @@ -3,20 +3,14 @@ package nl.SBDeveloper.V10Lift.Managers; import nl.SBDeveloper.V10Lift.Utils.XMaterial; import org.bukkit.Material; -import java.util.ArrayList; +import java.util.HashSet; public class ForbiddenBlockManager { - private ArrayList forbidden = new ArrayList<>(); + private HashSet forbidden = new HashSet<>(); public ForbiddenBlockManager() { //TODO Add more forbidden materials - /*forbidden.add(XMaterial.ACACIA_DOOR); - forbidden.add(XMaterial.BIRCH_DOOR); - forbidden.add(XMaterial.DARK_OAK_DOOR); - forbidden.add(XMaterial.IRON_DOOR); - forbidden.add(XMaterial.JUNGLE_DOOR); - forbidden.add(XMaterial.OAK_DOOR); - forbidden.add(XMaterial.SPRUCE_DOOR);*/ + //TODO Add to config forbidden.add(XMaterial.BLACK_BED); forbidden.add(XMaterial.BLUE_BED); forbidden.add(XMaterial.BROWN_BED); diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/Utils/ConfigUtil.java b/src/main/lombok/nl/SBDeveloper/V10Lift/Utils/ConfigUtil.java index c7a005e..b826ac9 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/Utils/ConfigUtil.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/Utils/ConfigUtil.java @@ -32,14 +32,18 @@ public class ConfigUtil { * @param path The path to look for */ public static void sendMessage(CommandSender p, @Nonnull String path) { - String fileMessage = V10LiftPlugin.getMessages().getFile().getString(path); - if (fileMessage == null) { + if (V10LiftPlugin.getMessages().getFile().get(path) == null) { throw new NullPointerException("Message " + path + " not found in messages.yml!"); } - String[] messages = fileMessage.split("\n"); - for (String message : messages) { - p.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); + if (V10LiftPlugin.getMessages().getFile().isList(path)) { + //Multi line message + for (String message : V10LiftPlugin.getMessages().getFile().getStringList(path)) { + p.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); + } + } else { + //Single line message + p.sendMessage(ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(V10LiftPlugin.getMessages().getFile().getString(path)))); } } @@ -51,33 +55,43 @@ public class ConfigUtil { * @param replacement The replacements -> key: %Name% = value: TheName */ public static void sendMessage(CommandSender p, @Nonnull String path, Map replacement) { - String fileMessage = V10LiftPlugin.getMessages().getFile().getString(path); - if (fileMessage == null) { + if (V10LiftPlugin.getMessages().getFile().get(path) == null) { throw new NullPointerException("Message " + path + " not found in messages.yml!"); } + if (V10LiftPlugin.getMessages().getFile().isList(path)) { + //Multi line message + for (String message : V10LiftPlugin.getMessages().getFile().getStringList(path)) { + p.sendMessage(formatMessage(message, replacement)); + } + } else { + //Single line message + String message = V10LiftPlugin.getMessages().getFile().getString(path); + p.sendMessage(formatMessage(message, replacement)); + } + } + + @Nonnull + private static String formatMessage(String message, @Nonnull Map replacement) { Map fixedMap = new HashMap<>(); for (Map.Entry ent : replacement.entrySet()) { fixedMap.put(ent.getKey().replaceAll("%", ""), ent.getValue()); } - String[] messages = fileMessage.split("\n"); - for (String message : messages) { - Pattern pattern = Pattern.compile("%(.*?)%"); - Matcher matcher = pattern.matcher(message); - StringBuilder builder = new StringBuilder(); - int i = 0; - while (matcher.find()) { - String repl = fixedMap.get(matcher.group(1)); - builder.append(message, i, matcher.start()); - if (repl == null) - builder.append(matcher.group(0)); - else - builder.append(repl); - i = matcher.end(); - } - builder.append(message.substring(i)); - p.sendMessage(ChatColor.translateAlternateColorCodes('&', builder.toString())); + Pattern pattern = Pattern.compile("%(.*?)%"); + Matcher matcher = pattern.matcher(Objects.requireNonNull(message)); + StringBuilder builder = new StringBuilder(); + int i = 0; + while (matcher.find()) { + String repl = fixedMap.get(matcher.group(1)); + builder.append(message, i, matcher.start()); + if (repl == null) + builder.append(matcher.group(0)); + else + builder.append(repl); + i = matcher.end(); } + builder.append(message.substring(i)); + return ChatColor.translateAlternateColorCodes('&', builder.toString()); } } diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index 8c36b1b..3476ad9 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -1,155 +1,143 @@ General: #General - NoPermission: "&cYou don't have the permission to do this." - PlayerOnly: "&cYou have to be a player to do this." - IncorrectUsage: "&cPlease use %Command%" - InternalError: "&cInternal error!" + NoPermission: '&cYou don''t have the permission to do this.' + PlayerOnly: '&cOnly players can do this.' + IncorrectUsage: '&cPlease use %Command% instead' + InternalError: '&cSomething went wrong internally.' - #General lift - DoesntExists: "&cA lift with that name doesn't exists." - AlreadyExists: "&cA lift with that name already exists." - SwitchOnEdit: "&cFirst switch on the editor mode!" - DetectionFailed: "&cAutomatic floor detection failed!" - FloorDoesntExists: "&cThe floor %Name% doesn't exists!" + #Lift general + DoesntExists: '&cThere are no lifts with that name.' + AlreadyExists: '&cA lift with that name already exists.' + SwitchOnEdit: '&cEnable editor mode before doing this.' + DetectionFailed: '&cAutomatic floor detection failed!' + FloorDoesntExists: '&cThe floor %Name% doesn''t exists!' - #Control lift - NoWhitelistPermission: "&cYou can't go to that floor!" - NoFloors: "&cThis elevator has no floors!" - - #Anti break - RemoveLiftFirst: "&cYou can't do this! Remove the lift first." - RemoveRopeFirst: "&cYou can't do this! Remove the rope first." - RemoveDoorFirst: "&cYou can't do this! Remove the door first." + #Lift control + NoWhitelistPermission: '&cYou can''t go to that floor!' + NoFloors: '&cThis elevator has no floors!' + #Protection + RemoveLiftFirst: '&cYou can''t do this! Remove the lift first.' + RemoveRopeFirst: '&cYou can''t do this! Remove the rope first.' + RemoveDoorFirst: '&cYou can''t do this! Remove the door first.' Create: - AddBlocks: "&aOkay, now add all the blocks from the cab by right-clicking on the blocks.\n&aThen type: /v10lift create " - NoBlocks: "&cAdd blocks first." - Created: "&aThe lift %Name% is successfully created." - + AddBlocks: |- + &aOkay, now add all the blocks from the cab by right-clicking them. + &awhen finished, type: /v10lift create + NoBlocks: '&cYou must add blocks first.' + Created: '&aSuccessfully created lift %Name%.' Delete: - NotRemoved: "&cThe lift %Name% couldn't be removed." - Removed: "&aThe lift %Name% is successfully removed." - + NotRemoved: '&cThe lift %Name% couldn''t be removed.' + Removed: '&aSuccessfully removed lift %Name%.' Rename: - Renamed: "&aLift successfully renamed!" - + Renamed: '&aLift successfully renamed!' Edit: - StillInEditMode: "&cYou are still in editor mode." - TurnedOn: "&aEditor turned on." - TurnedOff: "&aEditor turned off." - + StillInEditMode: '&cYou are still in editor mode.' + TurnedOn: '&aEnabled editor.' + TurnedOff: '&aDisabled editor.' Floor: - ToHigh: "&cThat floor is too high!" - AlreadyExists: "&cThat floor already exists!" - DoesntExists: "&cThat floor doesn't exists!" - Added: "&aFloor successfully added!" - Removed: "&aFloor successfully removed!" - Renamed: "&aFloor successfully renamed!" - + ToHigh: '&cThat floor is too high!' + AlreadyExists: '&cThat floor already exists!' + DoesntExists: '&cThat floor doesn''t exists!' + Added: '&aFloor successfully added!' + Removed: '&aFloor successfully removed!' + Renamed: '&aFloor successfully renamed!' Input: - StillAdjusting: "&cYou are still adjusting an input!" - NothingToRemove: "&cThere is no input to remove!" - AlreadyAdded: "&cThis block has already been chosen as an input. Choose another block!" - NoInput: "&cThis block is not an input. Choose another block!" - RightClick: "&aNow right click on the input block!" - Created: "&aInput created!" - Removed: "&aInput removed!" - + StillAdjusting: '&cYou are still adjusting an input!' + NothingToRemove: '&cThere is no input to remove!' + AlreadyAdded: '&cThis block has already been chosen as an input. Choose another + block!' + NoInput: '&cThis block is not an input. Choose another block!' + RightClick: '&aNow right click on the input block!' + Created: '&aInput created!' + Removed: '&aInput removed!' OfflineInput: - StillAdjusting: "&cYou are still adjusting an offline input!" - NothingToRemove: "&cThere is no offline input to remove!" - AlreadyAdded: "&cThis block has already been chosen as an offline input. Choose another block!" - NoInput: "&cThis block is not an offline input. Choose another block!" - RightClick: "&aNow right click on the offline input block!" - Created: "&aOffline input created!" - Removed: "&aOffline input removed!" - + StillAdjusting: '&cYou are still adjusting an offline input!' + NothingToRemove: '&cThere is no offline input to remove!' + AlreadyAdded: '&cThis block has already been chosen as an offline input. Choose + another block!' + NoInput: '&cThis block is not an offline input. Choose another block!' + RightClick: '&aNow right click on the offline input block!' + Created: '&aOffline input created!' + Removed: '&aOffline input removed!' Build: - Disabled: "&aConstruction mode disabled!" - Enabled: "&aNow right-click on the elevator blocks!\n&aThen do /v10lift build to save it!" - BlockAdded: "&aBlock added to the elevator." - BlockRemoved: "&6Block removed from the elevator." - BlacklistedMaterial: "&cThe material %Name% cannot be used!" - + Disabled: '&aConstruction mode disabled!' + Enabled: |- + &aNow right-click on the elevator blocks! + &aThen do /v10lift build to save it! + BlockAdded: '&aBlock added to the elevator.' + BlockRemoved: '&6Block removed from the elevator.' + BlacklistedMaterial: '&cThe material %Name% cannot be used!' Rope: - StillAdjusting: "&cYou are still adjusting a rope." - OnlyUp: "&cA rope can only go up!" - OnlyOneMaterial: "&cThe rope must be of the same material!" - AlreadyARope: "&cPart of the rope is already part of another rope!" - NotARope: "&cThis block is not part of the rope." - BlacklistedMaterial: "&cThe rope is build of blacklisted blocks!" - Add: "&aNow right-click on the beginning and the end of the rope." - Delete: "&aNow right-click on the rope." - ClickOnEnd: "&6Now right-click on the end of the rope!" - PartRemoved: "&6Start removed!\n&6Now right-click on the end of the rope!" - Created: "&aRope created." - Removed: "&aRope removed." - + StillAdjusting: '&cYou are still adjusting a rope.' + OnlyUp: '&cA rope can only go up!' + OnlyOneMaterial: '&cThe rope must be of the same material!' + AlreadyARope: '&cPart of the rope is already part of another rope!' + NotARope: '&cThis block is not part of the rope.' + BlacklistedMaterial: '&cThe rope is build of blacklisted blocks!' + Add: '&aNow right-click on the beginning and the end of the rope.' + Delete: '&aNow right-click on the rope.' + ClickOnEnd: '&6Now right-click on the end of the rope!' + PartRemoved: |- + &6Start removed! + &6Now right-click on the end of the rope! + Created: '&aRope created.' + Removed: '&aRope removed.' Door: - BlacklistedMaterial: "&cThe material %Name% is currently not supported!" - Disabled: "&aDoor editor mode disabled!" - Enabled: "&aNow right-click on the door blocks! (If it are real doors, click on the bottom block)\n&aThen do /v10lift door to save it." - Created: "&aDoor created." - Removed: "&6Door removed." - + BlacklistedMaterial: '&cThe material %Name% is currently not supported!' + Disabled: '&aDoor editor mode disabled!' + Enabled: |- + &aNow right-click on the door blocks! (If it are real doors, click on the bottom block) + &aThen do /v10lift door to save it. + Created: '&aDoor created.' + Removed: '&6Door removed.' Whitelist: Group: - VaultNotFound: "&cYou can't add a group when Vault is not found." - NotFound: "&cThe group %Name% is not found." - AlreadyContains: "&cWhitelist already contains this group!" - DoesntContains: "&cWhitelist doesn't contain this group!" - Added: "&aGroup added to whitelist!" - Removed: "&aGroup removed from whitelist!" + VaultNotFound: '&cYou can''t add a group when Vault is not found.' + NotFound: '&cThe group %Name% is not found.' + AlreadyContains: '&cThe whitelist already contains this group!' + DoesntContains: '&cThe whitelist doesn''t contain this group!' + Added: '&aGroup added to whitelist!' + Removed: '&aGroup removed from whitelist!' Player: - NotFound: "&cThe player %Name% is not found." - AlreadyContains: "Whitelist already contains this user!" - DoesntContains: "&cWhitelist doesn't contain this user!" - Added: "&aUser added to whitelist!" - Removed: "&aUser removed from whitelist!" - + NotFound: '&cThe player %Name% could not be found.' + AlreadyContains: '&cThis user is already on the whitelist' + DoesntContains: '&cThis user isn''t on the whitelist' + Added: '&aUser added to whitelist!' + Removed: '&aUser removed from whitelist!' Whois: - UseWithoutName: "&cYou need to be a player to use this command without name." - NotALift: "&cThis block is not part of a lift." - WithoutName: "&aNow right-click on the block you want to check." - + UseWithoutName: '&cYou need to be a player to use this command without name.' + NotALift: '&cThis block is not part of a lift.' + WithoutName: '&aNow right-click on the block you want to check.' Speed: - WrongSpeed: "&cThe speed %Speed% is incorrect." - Changed: "&aLift speed changed!" - + WrongSpeed: '&cThe speed %Speed% is incorrect.' + Changed: '&aUpdated lift speed!' Sound: - TurnedOn: "&aSound mode turned on!" - TurnedOff: "&aSound mode turned off!" - + TurnedOn: '&aSounds are now turned on!' + TurnedOff: '&aSounds are now turned off!' Realistic: - TurnedOn: "&aRealistic mode turned on!" - TurnedOff: "&aRealistic mode turned off!" - + TurnedOn: '&aRealistic mode turned on!' + TurnedOff: '&aRealistic mode turned off!' Disable: - AlreadyDefective: "&cThis lift is already defective!" - Disabled: "&aLift disabled!" - + AlreadyDefective: '&cThis lift is already defective!' + Disabled: '&aLift disabled!' Repair: - NotDefective: "&cThis lift isn't defective!" - ItemsNeeded: "&cYou need %Amount%x %ItemName%!" - Repaired: "&aLift repaired!" - + NotDefective: '&cThis lift isn''t defective!' + ItemsNeeded: '&cYou need %Amount%x %ItemName%!' + Repaired: '&aYou successfully repaired the lift!' Abort: - NothingToCancel: "&cOops! You can't cancel anything." - Cancelled: "&6Cancelled." - + NothingToCancel: '&cOops! You can''t cancel anything.' + Cancelled: '&6Cancelled.' Reload: - Reloaded: "&6Plugin reloaded successfully!" - + Reloaded: '&6Plugin reloaded successfully!' Start: - NonPlayer: "&cPlease give a name as non-player!" - Started: "&aLift %Name% started." - + NonPlayer: '&cPlease give a name as non-player!' + Started: '&aLift %Name% started.' Stop: - NonPlayer: "&cPlease give a name as non-player!" - NoMovingTasks: "&cLift %Name% doesn't contain any movingtasks!" - Started: "&aLift %Name% stopped." - + NonPlayer: '&cPlease give a name as non-player!' + NoMovingTasks: '&cLift %Name% doesn''t contain any movingtasks!' + Started: '&aLift %Name% stopped.' LiftSign: - NoName: "&cNo lift name given!" - Created: "&aLift sign created!" - Removed: "&6Lift sign removed!" \ No newline at end of file + NoName: '&cNo lift name given!' + Created: '&aLift sign created!' + Removed: '&6Lift sign removed!'