diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/API/Runnables/MoveLift.java b/src/main/lombok/nl/SBDeveloper/V10Lift/API/Runnables/MoveLift.java index c9b3d0e..5a21545 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/API/Runnables/MoveLift.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/API/Runnables/MoveLift.java @@ -2,6 +2,7 @@ package nl.SBDeveloper.V10Lift.API.Runnables; import nl.SBDeveloper.V10Lift.API.Objects.*; import nl.SBDeveloper.V10Lift.Managers.DataManager; +import nl.SBDeveloper.V10Lift.Utils.ConfigUtil; import nl.SBDeveloper.V10Lift.Utils.DirectionUtil; import nl.SBDeveloper.V10Lift.Utils.XMaterial; import nl.SBDeveloper.V10Lift.Utils.XSound; @@ -283,7 +284,7 @@ public class MoveLift implements Runnable { } sign = (Sign) bs; if (ls.getType() == 0) { - sign.setLine(3, ChatColor.GREEN + "up"); + sign.setLine(3, ConfigUtil.getConfigText("UpText")); } else { sign.setLine(3, ChatColor.GRAY + ChatColor.stripColor(sign.getLine(3))); } @@ -397,7 +398,7 @@ public class MoveLift implements Runnable { } sign = (Sign) bs; if (ls.getType() == 0) { - sign.setLine(3, ChatColor.GREEN + "down"); + sign.setLine(3, ConfigUtil.getConfigText("DownText")); } else { sign.setLine(3, ChatColor.GRAY + ChatColor.stripColor(sign.getLine(3))); } diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java b/src/main/lombok/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java index b83b78a..923c230 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java @@ -37,209 +37,209 @@ public class V10LiftCommand implements CommandExecutor { } else if (args[0].equalsIgnoreCase("create") && (args.length == 1 || args.length == 2)) { //v10lift create || v10lift create if (!(sender instanceof Player)) { - sender.sendMessage(ChatColor.RED + "You have to be a player to do this."); + ConfigUtil.sendMessage(sender, "General.PlayerOnly"); return true; } if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) { return createCommand(sender, args); } else { - sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!"); + ConfigUtil.sendMessage(sender, "General.NoPermission"); } } else if (args[0].equalsIgnoreCase("delete") && args.length == 2) { //v10lift delete if (!(sender instanceof Player)) { - sender.sendMessage(ChatColor.RED + "You have to be a player to do this."); + ConfigUtil.sendMessage(sender, "General.PlayerOnly"); return true; } if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) { return deleteCommand(sender, args); } else { - sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!"); + ConfigUtil.sendMessage(sender, "General.NoPermission"); } } else if (args[0].equalsIgnoreCase("edit") && (args.length == 1 || args.length == 2)) { //v10lift edit if (!(sender instanceof Player)) { - sender.sendMessage(ChatColor.RED + "You have to be a player to do this."); + ConfigUtil.sendMessage(sender, "General.PlayerOnly"); return true; } if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) { return editCommand(sender, args); } else { - sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!"); + ConfigUtil.sendMessage(sender, "General.NoPermission"); } } else if (args[0].equalsIgnoreCase("floor") && (args.length == 3 || args.length == 4)) { //v10lift floor add || v10lift floor del || v10lift floor rename if (!(sender instanceof Player)) { - sender.sendMessage(ChatColor.RED + "You have to be a player to do this."); + ConfigUtil.sendMessage(sender, "General.PlayerOnly"); return true; } if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) { return floorCommand(sender, args); } else { - sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!"); + ConfigUtil.sendMessage(sender, "General.NoPermission"); } } else if (args[0].equalsIgnoreCase("input") && (args.length == 2 || args.length == 3)) { //v10lift input add || v10lift input del if (!(sender instanceof Player)) { - sender.sendMessage(ChatColor.RED + "You have to be a player to do this."); + ConfigUtil.sendMessage(sender, "General.PlayerOnly"); return true; } if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) { return inputCommand(sender, args); } else { - sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!"); + ConfigUtil.sendMessage(sender, "General.NoPermission"); } } else if (args[0].equalsIgnoreCase("offline") && args.length == 2) { //v10lift offline add || v10lift offline del if (!(sender instanceof Player)) { - sender.sendMessage(ChatColor.RED + "You have to be a player to do this."); + ConfigUtil.sendMessage(sender, "General.PlayerOnly"); return true; } if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) { return offlineCommand(sender, args); } else { - sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!"); + ConfigUtil.sendMessage(sender, "General.NoPermission"); } } else if (args[0].equalsIgnoreCase("rename") && args.length == 2) { //v10lift rename if (!(sender instanceof Player)) { - sender.sendMessage(ChatColor.RED + "You have to be a player to do this."); + ConfigUtil.sendMessage(sender, "General.PlayerOnly"); return true; } if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) { return renameCommand(sender, args); } else { - sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!"); + ConfigUtil.sendMessage(sender, "General.NoPermission"); } } else if (args[0].equalsIgnoreCase("build") && args.length == 1) { //v10lift build if (!(sender instanceof Player)) { - sender.sendMessage(ChatColor.RED + "You have to be a player to do this."); + ConfigUtil.sendMessage(sender, "General.PlayerOnly"); return true; } if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) { return buildCommand(sender); } else { - sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!"); + ConfigUtil.sendMessage(sender, "General.NoPermission"); } } else if (args[0].equalsIgnoreCase("rope") && args.length == 2) { //v10lift rope add || v10lift rope del if (!(sender instanceof Player)) { - sender.sendMessage(ChatColor.RED + "You have to be a player to do this."); + ConfigUtil.sendMessage(sender, "General.PlayerOnly"); return true; } if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) { return ropeCommand(sender, args); } else { - sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!"); + ConfigUtil.sendMessage(sender, "General.NoPermission"); } } else if (args[0].equalsIgnoreCase("door") && (args.length == 1 || args.length == 2)) { //v10lift door || v10lift door if (!(sender instanceof Player)) { - sender.sendMessage(ChatColor.RED + "You have to be a player to do this."); + ConfigUtil.sendMessage(sender, "General.PlayerOnly"); return true; } if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) { return doorCommand(sender, args); } else { - sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!"); + ConfigUtil.sendMessage(sender, "General.NoPermission"); } } else if (args[0].equalsIgnoreCase("whitelist") && (args.length == 3 || args.length == 4)) { //v10lift whitelist add || v10lift whitelist del if (!(sender instanceof Player)) { - sender.sendMessage(ChatColor.RED + "You have to be a player to do this."); + ConfigUtil.sendMessage(sender, "General.PlayerOnly"); return true; } if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) { return whitelistCommand(sender, args); } else { - sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!"); + ConfigUtil.sendMessage(sender, "General.NoPermission"); } } else if (args[0].equalsIgnoreCase("whois") && (args.length == 1 || args.length == 2)) { //v10lift whois || v10lift whois if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) { return whoisCommand(sender, args); } else { - sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!"); + ConfigUtil.sendMessage(sender, "General.NoPermission"); } } else if (args[0].equalsIgnoreCase("speed") && args.length == 2) { //v10lift speed if (!(sender instanceof Player)) { - sender.sendMessage(ChatColor.RED + "You have to be a player to do this."); + ConfigUtil.sendMessage(sender, "General.PlayerOnly"); return true; } if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) { return speedCommand(sender, args); } else { - sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!"); + ConfigUtil.sendMessage(sender, "General.NoPermission"); } } else if (args[0].equalsIgnoreCase("sound") && args.length == 1) { //v10lift sound if (!(sender instanceof Player)) { - sender.sendMessage(ChatColor.RED + "You have to be a player to do this."); + ConfigUtil.sendMessage(sender, "General.PlayerOnly"); return true; } if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) { return soundCommand(sender); } else { - sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!"); + ConfigUtil.sendMessage(sender, "General.NoPermission"); } } else if (args[0].equalsIgnoreCase("realistic") && args.length == 1) { //v10lift realistic if (!(sender instanceof Player)) { - sender.sendMessage(ChatColor.RED + "You have to be a player to do this."); + ConfigUtil.sendMessage(sender, "General.PlayerOnly"); return true; } if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) { return realisticCommand(sender); } else { - sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!"); + ConfigUtil.sendMessage(sender, "General.NoPermission"); } } else if (args[0].equalsIgnoreCase("abort") && args.length == 1) { //v10lift abort if (!(sender instanceof Player)) { - sender.sendMessage(ChatColor.RED + "You have to be a player to do this."); + ConfigUtil.sendMessage(sender, "General.PlayerOnly"); return true; } if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) { return abortCommand(sender); } else { - sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!"); + ConfigUtil.sendMessage(sender, "General.NoPermission"); } } else if (args[0].equalsIgnoreCase("reload") && args.length == 1) { //v10lift reload if (sender.hasPermission("v10lift.reload") || sender.hasPermission("v10lift.admin")) { return reloadCommand(sender); } else { - sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!"); + ConfigUtil.sendMessage(sender, "General.NoPermission"); } } else if (args[0].equalsIgnoreCase("repair") && args.length == 2) { //v10lift repair if (sender.hasPermission("v10lift.repair") || sender.hasPermission("v10lift.admin")) { return repairCommand(sender, args); } else { - sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!"); + ConfigUtil.sendMessage(sender, "General.NoPermission"); } } else if (args[0].equalsIgnoreCase("disable") && args.length == 2) { //v10lift disable if (sender.hasPermission("v10lift.disable") || sender.hasPermission("v10lift.admin")) { return disableCommand(sender, args); } else { - sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!"); + ConfigUtil.sendMessage(sender, "General.NoPermission"); } } else if (args[0].equalsIgnoreCase("start")) { //v10lift start if (sender.hasPermission("v10lift.start") || sender.hasPermission("v10lift.admin")) { return startCommand(sender, args); } else { - sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!"); + ConfigUtil.sendMessage(sender, "General.NoPermission"); } } else if (args[0].equalsIgnoreCase("stop")) { //v10lift stop if (sender.hasPermission("v10lift.stop") || sender.hasPermission("v10lift.admin")) { return stopCommand(sender, args); } else { - sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!"); + ConfigUtil.sendMessage(sender, "General.NoPermission"); } } else { return helpCommand(sender); @@ -250,19 +250,19 @@ public class V10LiftCommand implements CommandExecutor { private boolean disableCommand(CommandSender sender, @Nonnull String[] args) { String liftName = args[1]; if (!DataManager.containsLift(liftName)) { - sender.sendMessage(ChatColor.RED + "Lift " + args[1] + " doesn't exists!"); + ConfigUtil.sendMessage(sender, "General.DoesntExists"); return true; } Lift lift = DataManager.getLift(liftName); if (lift.isDefective()) { - sender.sendMessage(ChatColor.RED + "This lift is already defective!"); + ConfigUtil.sendMessage(sender, "Disable.AlreadyDefective"); return true; } V10LiftPlugin.getAPI().setDefective(liftName, true); - sender.sendMessage(ChatColor.GREEN + "Lift disabled!"); + ConfigUtil.sendMessage(sender, "Disable.Disabled"); return true; } @@ -273,14 +273,14 @@ public class V10LiftCommand implements CommandExecutor { Player p = (Player) sender; liftName = V10LiftPlugin.getAPI().getLiftByLocation(p.getLocation()); } else if (args.length == 1) { - sender.sendMessage(ChatColor.RED + "Please give a name as non-player!"); + ConfigUtil.sendMessage(sender, "Stop.NonPlayer"); return true; } else { liftName = args[1]; } if (liftName == null || !DataManager.containsLift(liftName)) { - sender.sendMessage(ChatColor.RED + "Lift doesn't exists!"); + ConfigUtil.sendMessage(sender, "General.DoesntExists"); return true; } @@ -288,13 +288,13 @@ public class V10LiftCommand implements CommandExecutor { if (!lift.getQueue().isEmpty()) lift.getQueue().clear(); if (!DataManager.containsMovingTask(liftName)) { - sender.sendMessage(ChatColor.RED + "Lift " + liftName + " doesn't contain any movingtasks!"); + ConfigUtil.sendMessage(sender, "Stop.NoMovingTasks", Collections.singletonMap("%Name%", liftName)); return true; } Bukkit.getScheduler().cancelTask(DataManager.getMovingTask(liftName)); DataManager.removeMovingTask(liftName); - sender.sendMessage(ChatColor.GREEN + "Lift " + liftName + " stopped!"); + ConfigUtil.sendMessage(sender, "Stop.Stopped", Collections.singletonMap("%Name%", liftName)); return true; } @@ -305,14 +305,14 @@ public class V10LiftCommand implements CommandExecutor { Player p = (Player) sender; liftName = V10LiftPlugin.getAPI().getLiftByLocation(p.getLocation()); } else if (args.length == 1) { - sender.sendMessage(ChatColor.RED + "Please give a name as non-player!"); + ConfigUtil.sendMessage(sender, "Start.NonPlayer"); return true; } else { liftName = args[1]; } if (liftName == null || !DataManager.containsLift(liftName)) { - sender.sendMessage(ChatColor.RED + "Lift doesn't exists!"); + ConfigUtil.sendMessage(sender, "General.DoesntExists"); return true; } @@ -335,13 +335,14 @@ public class V10LiftCommand implements CommandExecutor { } if (floorName == null || !lift.getFloors().containsKey(floorName)) { - sender.sendMessage(ChatColor.RED + "Lift " + liftName + " doesn't contain this floor!"); + if (floorName == null) floorName = "null"; + ConfigUtil.sendMessage(sender, "Start.FloorDoesntExists", Collections.singletonMap("%Name%", floorName)); return true; } Floor f = lift.getFloors().get(floorName); V10LiftPlugin.getAPI().addToQueue(liftName, f, floorName); - sender.sendMessage(ChatColor.GREEN + "Lift " + liftName + " started!"); + ConfigUtil.sendMessage(sender, "Start.Started", Collections.singletonMap("%Name%", liftName)); return true; } @@ -365,7 +366,7 @@ public class V10LiftCommand implements CommandExecutor { e.printStackTrace(); } - sender.sendMessage(ChatColor.YELLOW + "Plugin reloaded successfully!"); + ConfigUtil.sendMessage(sender, "Reload.Reloaded"); return true; } @@ -425,9 +426,9 @@ public class V10LiftCommand implements CommandExecutor { } if (abort) { - p.sendMessage(ChatColor.GOLD + "Cancelled."); + ConfigUtil.sendMessage(sender, "Abort.Cancelled"); } else { - p.sendMessage(ChatColor.RED + "Oops! You can't cancel anything."); + ConfigUtil.sendMessage(sender, "Abort.NothingToCancel"); } return true; } @@ -435,14 +436,14 @@ public class V10LiftCommand implements CommandExecutor { private boolean repairCommand(CommandSender sender, @Nonnull String[] args) { String liftName = args[1]; if (!DataManager.containsLift(liftName)) { - sender.sendMessage(ChatColor.RED + "Lift " + args[1] + " doesn't exists!"); + ConfigUtil.sendMessage(sender, "General.DoesntExists"); return true; } Lift lift = DataManager.getLift(liftName); if (!lift.isDefective()) { - sender.sendMessage(ChatColor.RED + "This lift isn't defective!"); + ConfigUtil.sendMessage(sender, "Repair.NotDefective"); return true; } @@ -462,7 +463,10 @@ public class V10LiftCommand implements CommandExecutor { } if (p.getGameMode() != GameMode.CREATIVE && masterAmount > 0) { if (!p.getInventory().contains(masterItem)) { - sender.sendMessage(ChatColor.RED + "You need " + masterAmount + "x " + masterItem.toString().toLowerCase() + "!"); + Map replacements = new HashMap<>(); + replacements.put("%Amount%", String.valueOf(masterAmount)); + replacements.put("%ItemName%", masterItem.toString().toLowerCase()); + ConfigUtil.sendMessage(sender, "Repair.ItemsNeeded", replacements); return true; } p.getInventory().remove(new ItemStack(masterItem, masterAmount)); @@ -470,40 +474,48 @@ public class V10LiftCommand implements CommandExecutor { } } V10LiftPlugin.getAPI().setDefective(liftName, false); - sender.sendMessage(ChatColor.GREEN + "Lift repaired!"); + ConfigUtil.sendMessage(sender, "Repair.Repaired"); return true; } private boolean realisticCommand(CommandSender sender) { Player p = (Player) sender; if (!DataManager.containsEditPlayer(p.getUniqueId())) { - sender.sendMessage(ChatColor.RED + "First switch on the editor mode!"); + ConfigUtil.sendMessage(sender, "General.SwitchOnEdit"); return true; } Lift lift = DataManager.getLift(DataManager.getEditPlayer(p.getUniqueId())); lift.setRealistic(!lift.isRealistic()); - sender.sendMessage(ChatColor.GREEN + "Realistic mode turned " + (lift.isSound() ? "on" : "off") + "!"); + if (lift.isRealistic()) { + ConfigUtil.sendMessage(sender, "Realistic.TurnedOn"); + } else { + ConfigUtil.sendMessage(sender, "Realistic.TurnedOff"); + } return true; } private boolean soundCommand(CommandSender sender) { Player p = (Player) sender; if (!DataManager.containsEditPlayer(p.getUniqueId())) { - sender.sendMessage(ChatColor.RED + "First switch on the editor mode!"); + ConfigUtil.sendMessage(sender, "General.SwitchOnEdit"); return true; } Lift lift = DataManager.getLift(DataManager.getEditPlayer(p.getUniqueId())); lift.setSound(!lift.isSound()); - sender.sendMessage(ChatColor.GREEN + "Sound mode turned " + (lift.isSound() ? "on" : "off") + "!"); + if (lift.isSound()) { + ConfigUtil.sendMessage(sender, "Sound.TurnedOn"); + } else { + ConfigUtil.sendMessage(sender, "Sound.TurnedOff"); + } return true; } private boolean speedCommand(CommandSender sender, String[] args) { Player p = (Player) sender; if (!DataManager.containsEditPlayer(p.getUniqueId())) { - sender.sendMessage(ChatColor.RED + "First switch on the editor mode!"); + ConfigUtil.sendMessage(sender, "General.SwitchOnEdit"); return true; } @@ -512,9 +524,9 @@ public class V10LiftCommand implements CommandExecutor { int speed = Integer.parseInt(args[1]); lift.setSpeed(speed); if (lift.getSpeed() < 1) lift.setSpeed(1); - sender.sendMessage(ChatColor.GREEN + "Lift speed changed!"); + ConfigUtil.sendMessage(sender, "Speed.Changed"); } catch (NumberFormatException e) { - sender.sendMessage(ChatColor.RED + "Wrong speed: " + args[1]); + ConfigUtil.sendMessage(sender, "Speed.WrongSpeed", Collections.singletonMap("%Speed%", args[1])); } return true; } @@ -522,18 +534,18 @@ public class V10LiftCommand implements CommandExecutor { private boolean whoisCommand(CommandSender sender, @Nonnull String[] args) { if (args.length < 2) { if (!(sender instanceof Player)) { - sender.sendMessage(ChatColor.RED + "You need to be a player to use this command without name."); + ConfigUtil.sendMessage(sender, "Whois.UseWithoutName"); return true; } //Without name Player p = (Player) sender; DataManager.addWhoisREQPlayer(p.getUniqueId()); - sender.sendMessage(ChatColor.GREEN + "Now right-click on the block you want to check."); + ConfigUtil.sendMessage(sender, "Whois.WithoutName"); } else { String liftName = args[1]; if (!DataManager.containsLift(liftName)) { - sender.sendMessage(ChatColor.RED + "Lift " + liftName + " not found!"); + ConfigUtil.sendMessage(sender, "Whois.DoesntExists"); } else { V10LiftPlugin.getAPI().sendLiftInfo(sender, liftName); } @@ -544,7 +556,7 @@ public class V10LiftCommand implements CommandExecutor { private boolean whitelistCommand(CommandSender sender, @Nonnull String[] args) { Player p = (Player) sender; if (!DataManager.containsEditPlayer(p.getUniqueId())) { - sender.sendMessage(ChatColor.RED + "First switch on the editor mode!"); + ConfigUtil.sendMessage(sender, "General.SwitchOnEdit"); return true; } @@ -554,20 +566,20 @@ public class V10LiftCommand implements CommandExecutor { UUID wpu = null; if (args[2].startsWith("g:")) { if (!V10LiftPlugin.isVaultEnabled()) { - sender.sendMessage(ChatColor.RED + "You can't add a group when Vault is not found."); + ConfigUtil.sendMessage(sender, "Whitelist.Group.VaultNotFound"); return true; } isGroup = true; wgn = args[2].replace("g:", ""); if (!VaultManager.isGroup(wgn)) { - sender.sendMessage(ChatColor.RED + "Group " + wgn + " not found!"); + ConfigUtil.sendMessage(sender, "Whitelist.Group.NotFound", Collections.singletonMap("%Name%", wgn)); return true; } } else { OfflinePlayer wp = Bukkit.getOfflinePlayer(args[2]); wpu = wp.getUniqueId(); if (!wp.hasPlayedBefore()) { - sender.sendMessage(ChatColor.RED + "Player " + args[2] + " not found!"); + ConfigUtil.sendMessage(sender, "Whitelist.Player.NotFound", Collections.singletonMap("%Name%", args[2])); return true; } } @@ -577,7 +589,7 @@ public class V10LiftCommand implements CommandExecutor { Block b = p.getLocation().getBlock(); Floor f = new Floor(b.getY() - 1, Objects.requireNonNull(b.getWorld(), "World was null at whitelistCommand").getName()); if (!lift.getFloors().containsValue(f)) { - sender.sendMessage(ChatColor.RED + "Automatic floor detection failed!"); + ConfigUtil.sendMessage(sender, "General.DetectionFailed"); return true; } for (Map.Entry e : lift.getFloors().entrySet()) { @@ -590,7 +602,7 @@ public class V10LiftCommand implements CommandExecutor { } else { floor = args[3]; if (!lift.getFloors().containsKey(floor)) { - sender.sendMessage(ChatColor.RED + "Floor " + args[3] + " not found!"); + ConfigUtil.sendMessage(sender, "General.FloorDoesntExists", Collections.singletonMap("%Name%", args[3])); return true; } } @@ -599,33 +611,33 @@ public class V10LiftCommand implements CommandExecutor { if (args[1].equalsIgnoreCase("add")) { if (isGroup) { if (f.getGroupWhitelist().contains(wgn)) { - sender.sendMessage(ChatColor.RED + "Whitelist already contains this group!"); + ConfigUtil.sendMessage(sender, "Whitelist.Group.AlreadyContains"); } else { f.getGroupWhitelist().add(wgn); - sender.sendMessage(ChatColor.GREEN + "Group added to whitelist!"); + ConfigUtil.sendMessage(sender, "Whitelist.Player.Added"); } } else { if (f.getUserWhitelist().contains(wpu)) { - sender.sendMessage(ChatColor.RED + "Whitelist already contains this user!"); + ConfigUtil.sendMessage(sender, "Whitelist.Group.AlreadyContains"); } else { f.getUserWhitelist().add(wpu); - sender.sendMessage(ChatColor.GREEN + "User added to whitelist!"); + ConfigUtil.sendMessage(sender, "Whitelist.Player.Added"); } } } else if (args[1].equalsIgnoreCase("del")) { if (isGroup) { if (!f.getGroupWhitelist().contains(wgn)) { - sender.sendMessage(ChatColor.RED + "Whitelist doesn't contain this group!"); + ConfigUtil.sendMessage(sender, "Whitelist.Group.DoesntContains"); } else { f.getGroupWhitelist().remove(wgn); - sender.sendMessage(ChatColor.GREEN + "Group removed from whitelist!"); + ConfigUtil.sendMessage(sender, "Whitelist.Group.Removed"); } } else { if (!f.getUserWhitelist().contains(wpu)) { - sender.sendMessage(ChatColor.RED + "Whitelist doesn't contain this user!"); + ConfigUtil.sendMessage(sender, "Whitelist.Player.DoesntContains"); } else { f.getUserWhitelist().remove(wpu); - sender.sendMessage(ChatColor.GREEN + "User removed from whitelist!"); + ConfigUtil.sendMessage(sender, "Whitelist.User.Removed"); } } } else { @@ -637,13 +649,13 @@ public class V10LiftCommand implements CommandExecutor { private boolean doorCommand(CommandSender sender, String[] args) { Player p = (Player) sender; if (!DataManager.containsEditPlayer(p.getUniqueId())) { - sender.sendMessage(ChatColor.RED + "First switch on the editor mode!"); + ConfigUtil.sendMessage(sender, "General.SwitchOnEdit"); return true; } if (DataManager.containsDoorEditPlayer(p.getUniqueId())) { DataManager.removeDoorEditPlayer(p.getUniqueId()); - sender.sendMessage(ChatColor.RED + "Door editor mode disabled!"); + ConfigUtil.sendMessage(sender, "Door.Disabled"); return true; } @@ -653,7 +665,7 @@ public class V10LiftCommand implements CommandExecutor { Location loc = p.getLocation(); Floor f = new Floor(loc.getBlockY() - 1, Objects.requireNonNull(loc.getWorld(), "World was null at doorCommand").getName()); if (!lift.getFloors().containsValue(f)) { - sender.sendMessage(ChatColor.RED + "Automatic floor detection failed!"); + ConfigUtil.sendMessage(sender, "General.DetectionFailed"); return true; } for (Map.Entry e : lift.getFloors().entrySet()) { @@ -666,37 +678,36 @@ public class V10LiftCommand implements CommandExecutor { } else { floor = args[2]; if (!lift.getFloors().containsKey(floor)) { - sender.sendMessage(ChatColor.RED + "The floor " + args[2] + " doesn't exists!"); + ConfigUtil.sendMessage(sender, "General.FloorDoesntExists", Collections.singletonMap("%Name", args[2])); return true; } } DataManager.addDoorEditPlayer(p.getUniqueId(), floor); - sender.sendMessage(ChatColor.GREEN + "Now right-click on the door blocks! (If it are real doors/gates, click on the bottom block)"); - sender.sendMessage(ChatColor.GREEN + "Then do /v10lift door to save it."); + ConfigUtil.sendMessage(sender, "Door.Enabled"); return true; } private boolean ropeCommand(CommandSender sender, String[] args) { Player p = (Player) sender; if (!DataManager.containsEditPlayer(p.getUniqueId())) { - sender.sendMessage(ChatColor.RED + "First switch on the editor mode!"); + ConfigUtil.sendMessage(sender, "General.SwitchOnEdit"); return true; } if (args[1].equalsIgnoreCase("add")) { if (DataManager.containsRopeEditPlayer(p.getUniqueId()) || DataManager.containsRopeRemovesPlayer(p.getUniqueId())) { - sender.sendMessage(ChatColor.RED + "You're still adjusting the emergency stairs."); + ConfigUtil.sendMessage(sender, "Rope.StillAdjusting"); return true; } DataManager.addRopeEditPlayer(p.getUniqueId(), null); - sender.sendMessage(ChatColor.GREEN + "Now right-click on the beginning and the end of the emergency stairs."); + ConfigUtil.sendMessage(sender, "Rope.Add"); } else if (args[1].equalsIgnoreCase("del")) { if (DataManager.containsRopeEditPlayer(p.getUniqueId()) || DataManager.containsRopeRemovesPlayer(p.getUniqueId())) { - sender.sendMessage(ChatColor.RED + "You're still adjusting the emergency stairs."); + ConfigUtil.sendMessage(sender, "Rope.StillAdjusting"); return true; } DataManager.addRopeRemovesPlayer(p.getUniqueId()); - sender.sendMessage(ChatColor.GREEN + "Now right-click on the the emergency stairs."); + ConfigUtil.sendMessage(sender, "Rope.Delete"); } return true; } @@ -704,18 +715,17 @@ public class V10LiftCommand implements CommandExecutor { private boolean buildCommand(CommandSender sender) { Player p = (Player) sender; if (!DataManager.containsEditPlayer(p.getUniqueId())) { - sender.sendMessage(ChatColor.RED + "First switch on the editor mode!"); + ConfigUtil.sendMessage(sender, "General.SwitchOnEdit"); return true; } if (DataManager.containsBuilderPlayer(p.getUniqueId())) { DataManager.removeBuilderPlayer(p.getUniqueId()); V10LiftPlugin.getAPI().sortLiftBlocks(DataManager.getEditPlayer(p.getUniqueId())); - sender.sendMessage(ChatColor.GREEN + "Construction mode disabled!"); + ConfigUtil.sendMessage(sender, "Build.Disabled"); } else { DataManager.addBuilderPlayer(p.getUniqueId()); - sender.sendMessage(ChatColor.GREEN + "Now right-click on the elevator blocks!"); - sender.sendMessage(ChatColor.GREEN + "Then do /v10lift build to save it!"); + ConfigUtil.sendMessage(sender, "Build.Enabled"); } return true; } @@ -723,13 +733,13 @@ public class V10LiftCommand implements CommandExecutor { private boolean renameCommand(CommandSender sender, String[] args) { Player p = (Player) sender; if (!DataManager.containsEditPlayer(p.getUniqueId())) { - sender.sendMessage(ChatColor.RED + "First switch on the editor mode!"); + ConfigUtil.sendMessage(sender, "General.SwitchOnEdit"); return true; } String liftName = DataManager.getEditPlayer(p.getUniqueId()); if (!DataManager.containsLift(liftName)) { - sender.sendMessage(ChatColor.RED + "That lift doesn't exists."); + ConfigUtil.sendMessage(sender, "General.DoesntExists"); return true; } @@ -737,45 +747,45 @@ public class V10LiftCommand implements CommandExecutor { V10LiftPlugin.getAPI().renameLift(liftName, args[1]); Bukkit.dispatchCommand(sender, "v10lift edit " + args[1]); - sender.sendMessage(ChatColor.GREEN + "Lift successfully renamed!"); + ConfigUtil.sendMessage(sender, "Rename.Renamed"); return true; } private boolean offlineCommand(CommandSender sender, String[] args) { Player p = (Player) sender; if (!DataManager.containsEditPlayer(p.getUniqueId())) { - sender.sendMessage(ChatColor.RED + "First switch on the editor mode!"); + ConfigUtil.sendMessage(sender, "General.SwitchOnEdit"); return true; } String liftName = DataManager.getEditPlayer(p.getUniqueId()); if (!DataManager.containsLift(liftName)) { - sender.sendMessage(ChatColor.RED + "That lift doesn't exists."); + ConfigUtil.sendMessage(sender, "General.DoesntExists"); return true; } Lift lift = DataManager.getLift(liftName); if (args[1].equalsIgnoreCase("add")) { if (DataManager.containsOfflineEditsPlayer(p.getUniqueId()) || DataManager.containsOfflineRemovesPlayer(p.getUniqueId())) { - sender.sendMessage(ChatColor.RED + "You are still adjusting an input!"); + ConfigUtil.sendMessage(sender, "OfflineInput.StillAdjusting"); return true; } DataManager.addOfflineEditsPlayer(p.getUniqueId()); - sender.sendMessage(ChatColor.GREEN + "Now right click on the offline input block!"); + ConfigUtil.sendMessage(sender, "OfflineInput.RightClick"); } else if (args[1].equalsIgnoreCase("del")) { if (lift.getOfflineInputs().isEmpty()) { - sender.sendMessage(ChatColor.RED + "There is no input to remove!"); + ConfigUtil.sendMessage(sender, "OfflineInput.NothingToRemove"); return true; } if (DataManager.containsOfflineEditsPlayer(p.getUniqueId()) || DataManager.containsOfflineRemovesPlayer(p.getUniqueId())) { - sender.sendMessage(ChatColor.RED + "You are still adjusting an input!"); + ConfigUtil.sendMessage(sender, "OfflineInput.StillAdjusting"); return true; } DataManager.addOfflineRemovesPlayer(p.getUniqueId()); - sender.sendMessage(ChatColor.GREEN + "Now right click on the offline input block!"); + ConfigUtil.sendMessage(sender, "OfflineInput.RightClick"); } else { return helpCommand(sender); } @@ -785,13 +795,13 @@ public class V10LiftCommand implements CommandExecutor { private boolean inputCommand(CommandSender sender, String[] args) { Player p = (Player) sender; if (!DataManager.containsEditPlayer(p.getUniqueId())) { - sender.sendMessage(ChatColor.RED + "First switch on the editor mode!"); + ConfigUtil.sendMessage(sender, "General.SwitchOnEdit"); return true; } String liftName = DataManager.getEditPlayer(p.getUniqueId()); if (!DataManager.containsLift(liftName)) { - sender.sendMessage(ChatColor.RED + "That lift doesn't exists."); + ConfigUtil.sendMessage(sender, "General.DoesntExists"); return true; } @@ -802,7 +812,7 @@ public class V10LiftCommand implements CommandExecutor { Block b = p.getLocation().getBlock(); Floor f = new Floor(b.getY() - 1, b.getWorld().getName()); if (!lift.getFloors().containsValue(f)) { - sender.sendMessage(ChatColor.RED + "Automatic floor detection failed!"); + ConfigUtil.sendMessage(sender, "General.DetectionFailed"); return true; } @@ -817,25 +827,25 @@ public class V10LiftCommand implements CommandExecutor { } if (DataManager.containsInputEditsPlayer(p.getUniqueId()) || DataManager.containsInputRemovesPlayer(p.getUniqueId())) { - sender.sendMessage(ChatColor.RED + "You are still adjusting an input!"); + ConfigUtil.sendMessage(sender, "Input.StillAdjusting"); return true; } DataManager.addInputEditsPlayer(p.getUniqueId(), Objects.requireNonNull(floor, "Floor is null at input add command")); - sender.sendMessage(ChatColor.GREEN + "Now right click on the input block!"); + ConfigUtil.sendMessage(sender, "Input.RightClick"); } else if (args[1].equalsIgnoreCase("del")) { if (lift.getInputs().isEmpty()) { - sender.sendMessage(ChatColor.RED + "There is no input to remove!"); + ConfigUtil.sendMessage(sender, "Input.NothingToRemove"); return true; } if (DataManager.containsInputEditsPlayer(p.getUniqueId()) || DataManager.containsInputRemovesPlayer(p.getUniqueId())) { - sender.sendMessage(ChatColor.RED + "You are still adjusting an input!"); + ConfigUtil.sendMessage(sender, "Input.StillAdjusting"); return true; } DataManager.addInputRemovesPlayer(p.getUniqueId()); - sender.sendMessage(ChatColor.GREEN + "Now right click on the input block!"); + ConfigUtil.sendMessage(sender, "Input.RightClick"); } else { return helpCommand(sender); } @@ -845,13 +855,13 @@ public class V10LiftCommand implements CommandExecutor { private boolean floorCommand(CommandSender sender, String[] args) { Player p = (Player) sender; if (!DataManager.containsEditPlayer(p.getUniqueId())) { - sender.sendMessage(ChatColor.RED + "First switch on the editor mode!"); + ConfigUtil.sendMessage(sender, "General.SwitchOnEdit"); return true; } String liftName = DataManager.getEditPlayer(p.getUniqueId()); if (!DataManager.containsLift(liftName)) { - sender.sendMessage(ChatColor.RED + "That lift doesn't exists."); + ConfigUtil.sendMessage(sender, "General.DoesntExists"); return true; } if (args[1].equalsIgnoreCase("add")) { @@ -860,28 +870,28 @@ public class V10LiftCommand implements CommandExecutor { int response = V10LiftPlugin.getAPI().addFloor(liftName, floorName, new Floor(b.getY() - 1, b.getWorld().getName())); switch (response) { case 0: - sender.sendMessage(ChatColor.GREEN + "Floor successfully added!"); + ConfigUtil.sendMessage(sender, "Floor.Added"); break; case -2: - sender.sendMessage(ChatColor.RED + "That floor is too high!"); + ConfigUtil.sendMessage(sender, "Floor.ToHigh"); break; case -3: - sender.sendMessage(ChatColor.RED + "That floor already exists!"); + ConfigUtil.sendMessage(sender, "Floor.AlreadyExists"); break; default: - sender.sendMessage(ChatColor.RED + "Internal error!"); + ConfigUtil.sendMessage(sender, "General.InternalError"); break; } } else if (args[1].equalsIgnoreCase("del")) { String floorName = args[2]; if (!V10LiftPlugin.getAPI().removeFloor(liftName, floorName)) { - sender.sendMessage(ChatColor.RED + "Internal error!"); + ConfigUtil.sendMessage(sender, "General.InternalError"); } else { - sender.sendMessage(ChatColor.GREEN + "Floor successfully removed!"); + ConfigUtil.sendMessage(sender, "Floor.Removed"); } } else if (args[1].equalsIgnoreCase("rename")) { if (args.length < 4) { - sender.sendMessage(ChatColor.RED + "Please use: /v10lift floor rename "); + ConfigUtil.sendMessage(sender, "General.IncorrectUsage", Collections.singletonMap("%Command%", "/v10lift floor rename ")); return true; } @@ -890,16 +900,16 @@ public class V10LiftCommand implements CommandExecutor { int response = V10LiftPlugin.getAPI().renameFloor(liftName, floorName, newFloorName); switch (response) { case 0: - sender.sendMessage(ChatColor.GREEN + "Floor successfully renamed!"); + ConfigUtil.sendMessage(sender, "Floor.Renamed"); break; case -2: - sender.sendMessage(ChatColor.RED + "That floor doesn't exists!"); + ConfigUtil.sendMessage(sender, "Floor.DoesntExists"); break; case -3: - sender.sendMessage(ChatColor.RED + "That floor already exists!"); + ConfigUtil.sendMessage(sender, "Floor.AlreadyExists"); break; default: - sender.sendMessage(ChatColor.RED + "Internal error!"); + ConfigUtil.sendMessage(sender, "General.InternalError"); break; } } else { @@ -916,7 +926,7 @@ public class V10LiftCommand implements CommandExecutor { if (args.length < 2) { String liftName = DataManager.getEditPlayer(p.getUniqueId()); if (!DataManager.containsLift(liftName)) { - sender.sendMessage(ChatColor.RED + "That lift doesn't exists."); + ConfigUtil.sendMessage(sender, "General.DoesntExists"); return true; } @@ -961,26 +971,27 @@ public class V10LiftCommand implements CommandExecutor { sign.update(); ls.setOldText(null); } - sender.sendMessage(ChatColor.GREEN + "Editor turned off!"); + ConfigUtil.sendMessage(sender, "Edit.TurnedOff"); } else { - sender.sendMessage(ChatColor.RED + "You are still in editor mode."); + ConfigUtil.sendMessage(sender, "Edit.StillInEditMode"); return true; } } else { //TURN ON if (args.length < 2) { - sender.sendMessage(ChatColor.RED + "Please use /v10lift edit "); + ConfigUtil.sendMessage(sender, "General.IncorrectUsage", Collections.singletonMap("%Command%", "/v10lift edit ")); return true; } if (!DataManager.containsLift(args[1])) { - sender.sendMessage(ChatColor.RED + "That lift doesn't exists."); + ConfigUtil.sendMessage(sender, "General.DoesntExists"); return true; } Lift lift = DataManager.getLift(args[1]); if (!lift.getOwners().contains(p.getUniqueId()) && !p.hasPermission("v10lift.admin")) { - sender.sendMessage(ChatColor.RED + "You don't have the permission to remove that lift."); + ConfigUtil.sendMessage(sender, "General.NoPermission"); + return true; } DataManager.addEditPlayer(p.getUniqueId(), args[1]); @@ -991,7 +1002,7 @@ public class V10LiftCommand implements CommandExecutor { if (!(bs instanceof Sign)) continue; sign = (Sign) bs; if (!sign.getLine(0).equalsIgnoreCase(ConfigUtil.getConfigText("SignText"))) continue; - sign.setLine(3, ChatColor.RED + "Maintenance"); + sign.setLine(3, ConfigUtil.getConfigText("MaintenanceText")); sign.update(); } @@ -1009,7 +1020,7 @@ public class V10LiftCommand implements CommandExecutor { sign.setLine(3, ConfigUtil.getConfigText("MaintenanceText")); sign.update(); } - sender.sendMessage(ChatColor.GREEN + "Editor turned on!"); + ConfigUtil.sendMessage(sender, "Edit.TurnedOn"); } return true; } @@ -1017,21 +1028,22 @@ public class V10LiftCommand implements CommandExecutor { private boolean deleteCommand(@Nonnull CommandSender sender, @Nonnull String[] args) { Player p = (Player) sender; if (!DataManager.containsLift(args[1])) { - sender.sendMessage(ChatColor.RED + "That lift doesn't exists."); + ConfigUtil.sendMessage(sender, "General.DoesntExists"); return true; } Lift lift = DataManager.getLift(args[1]); if (!lift.getOwners().contains(p.getUniqueId()) && !p.hasPermission("v10lift.admin")) { - sender.sendMessage(ChatColor.RED + "You don't have the permission to remove that lift."); - } - - if (!V10LiftPlugin.getAPI().removeLift(args[1])) { - sender.sendMessage(ChatColor.RED + "The lift " + args[1] + " couldn't be removed!"); + ConfigUtil.sendMessage(sender, "General.NoPermission"); return true; } - sender.sendMessage(ChatColor.GREEN + "The lift " + args[1] + " is removed successfully!"); + if (!V10LiftPlugin.getAPI().removeLift(args[1])) { + ConfigUtil.sendMessage(sender, "Delete.NotRemoved", Collections.singletonMap("%Name%", args[1])); + return true; + } + + ConfigUtil.sendMessage(sender, "Delete.Removed", Collections.singletonMap("%Name%", args[1])); return true; } @@ -1040,18 +1052,19 @@ public class V10LiftCommand implements CommandExecutor { if (DataManager.containsPlayer(p.getUniqueId())) { //Already building!! if (args.length < 2) { - sender.sendMessage(ChatColor.RED + "Please use /v10lift create "); + ConfigUtil.sendMessage(sender, "General.IncorrectUsage", Collections.singletonMap("%Command%", "/v10lift create ")); return true; } TreeSet blocks = DataManager.getPlayer(p.getUniqueId()); if (blocks.isEmpty()) { - sender.sendMessage(ChatColor.RED + "Add blocks first!"); + ConfigUtil.sendMessage(sender, "Create.NoBlocks"); return true; } if (!V10LiftPlugin.getAPI().createLift(p, args[1])) { - sender.sendMessage(ChatColor.RED + "A lift with that name already exists."); + ConfigUtil.sendMessage(sender, "General.AlreadyExists"); + return true; } TreeSet blcks = DataManager.getLift(args[1]).getBlocks(); @@ -1059,13 +1072,12 @@ public class V10LiftCommand implements CommandExecutor { blocks.forEach(block -> V10LiftPlugin.getAPI().addBlockToLift(blcks, block)); V10LiftPlugin.getAPI().sortLiftBlocks(args[1]); DataManager.removePlayer(p.getUniqueId()); - sender.sendMessage(ChatColor.GREEN + "The lift " + args[1] + " is created successfully!"); + ConfigUtil.sendMessage(p, "Create.Created", Collections.singletonMap("%Name%", args[1])); p.performCommand("v10lift edit " + args[1]); } else { //Not building yet!! DataManager.addPlayer(p.getUniqueId()); - sender.sendMessage(ChatColor.GREEN + "Okay, now add all the blocks from the cab by right-clicking on the blocks."); - sender.sendMessage(ChatColor.GREEN + "Then type: /v10lift create "); + ConfigUtil.sendMessage(p, "Create.AddBlocks"); } return true; } diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/Listeners/BlockBreakListener.java b/src/main/lombok/nl/SBDeveloper/V10Lift/Listeners/BlockBreakListener.java index 3f40e59..6f2f240 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/Listeners/BlockBreakListener.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/Listeners/BlockBreakListener.java @@ -4,9 +4,9 @@ import nl.SBDeveloper.V10Lift.API.Objects.Floor; import nl.SBDeveloper.V10Lift.API.Objects.Lift; import nl.SBDeveloper.V10Lift.API.Objects.LiftBlock; import nl.SBDeveloper.V10Lift.Managers.DataManager; +import nl.SBDeveloper.V10Lift.Utils.ConfigUtil; import nl.SBDeveloper.V10Lift.Utils.DoorUtil; import nl.SBDeveloper.V10Lift.V10LiftPlugin; -import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.block.Sign; @@ -23,7 +23,7 @@ public class BlockBreakListener implements Listener { public void onBlockBreak(BlockBreakEvent e) { Block b = e.getBlock(); if (V10LiftPlugin.getAPI().isRope(b)) { - e.getPlayer().sendMessage(ChatColor.RED + "You can't do this! Remove the rope first."); + ConfigUtil.sendMessage(e.getPlayer(), "General.RemoveRopeFirst"); e.setCancelled(true); return; } @@ -32,14 +32,14 @@ public class BlockBreakListener implements Listener { for (Map.Entry entry : DataManager.getLifts().entrySet()) { Lift lift = entry.getValue(); if (lift.getBlocks().contains(tlb)) { - e.getPlayer().sendMessage(ChatColor.RED + "You can't do this! Remove the lift first."); + ConfigUtil.sendMessage(e.getPlayer(), "General.RemoveLiftFirst"); e.setCancelled(true); return; } for (Floor f : lift.getFloors().values()) { if (f.getDoorBlocks().contains(tlb)) { - e.getPlayer().sendMessage(ChatColor.RED + "You can't do this! Remove the door first."); + ConfigUtil.sendMessage(e.getPlayer(), "General.RemoveDoorFirst"); e.setCancelled(true); return; } @@ -50,7 +50,7 @@ public class BlockBreakListener implements Listener { && lb.getX() == loc.getBlockX() && lb.getY() == loc.getBlockY() && lb.getZ() == loc.getBlockZ()) { - e.getPlayer().sendMessage(ChatColor.RED + "You can't do this! Remove the door first."); + ConfigUtil.sendMessage(e.getPlayer(), "General.RemoveDoorFirst"); e.setCancelled(true); return; } @@ -62,11 +62,11 @@ public class BlockBreakListener implements Listener { if (!lift.getSigns().contains(tlb)) continue; if (!lift.getOwners().contains(e.getPlayer().getUniqueId()) && !e.getPlayer().hasPermission("v10lift.admin")) { - e.getPlayer().sendMessage(ChatColor.RED + "You can't do this!"); + ConfigUtil.sendMessage(e.getPlayer(), "General.NoPermission"); e.setCancelled(true); } else { lift.getSigns().remove(tlb); - e.getPlayer().sendMessage(ChatColor.YELLOW + "Lift sign removed!"); + ConfigUtil.sendMessage(e.getPlayer(), "LiftSign.Removed"); } } } diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/Listeners/PlayerInteractListener.java b/src/main/lombok/nl/SBDeveloper/V10Lift/Listeners/PlayerInteractListener.java index ffc606a..0207813 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/Listeners/PlayerInteractListener.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/Listeners/PlayerInteractListener.java @@ -110,19 +110,19 @@ public class PlayerInteractListener implements Listener { String f = ChatColor.stripColor(sign.getLine(3)); if (!lift.getFloors().containsKey(f)) { - p.sendMessage(ChatColor.RED + "Floor not found!"); + ConfigUtil.sendMessage(e.getPlayer(), "General.FloorDoesntExists"); return; } Floor floor = lift.getFloors().get(f); if (!floor.getUserWhitelist().isEmpty() && !floor.getUserWhitelist().contains(p.getUniqueId()) && !p.hasPermission("v10lift.admin")) { - p.sendMessage(ChatColor.RED + "You can't go to that floor!"); + ConfigUtil.sendMessage(e.getPlayer(), "General.NoWhitelistPermission"); e.setCancelled(true); return; } if (!floor.getGroupWhitelist().isEmpty() && !VaultManager.userHasAnyGroup(p, floor.getGroupWhitelist()) && !p.hasPermission("v10lift.admin")) { - p.sendMessage(ChatColor.RED + "You can't go to that floor!"); + ConfigUtil.sendMessage(e.getPlayer(), "General.NoWhitelistPermission"); e.setCancelled(true); return; } @@ -143,16 +143,16 @@ public class PlayerInteractListener implements Listener { int res = V10LiftPlugin.getAPI().switchBlockAtLift(DataManager.getPlayer(p.getUniqueId()), e.getClickedBlock()); switch (res) { case 0: - p.sendMessage(ChatColor.GREEN + "Block added to the elevator."); + ConfigUtil.sendMessage(e.getPlayer(), "Build.BlockAdded"); break; case 1: - p.sendMessage(ChatColor.GOLD + "Block removed from the elevator."); + ConfigUtil.sendMessage(e.getPlayer(), "Build.BlockRemoved"); break; case -2: - p.sendMessage(ChatColor.RED + "The material " + e.getClickedBlock().getType().toString() + " cannot be used!"); + ConfigUtil.sendMessage(e.getPlayer(), "Build.BlacklistedMaterial", Collections.singletonMap("%Name%", e.getClickedBlock().getType().toString().toLowerCase())); break; default: - p.sendMessage(ChatColor.RED + "Internal error."); + ConfigUtil.sendMessage(e.getPlayer(), "General.InternalError"); break; } } else if (DataManager.containsInputEditsPlayer(p.getUniqueId())) { @@ -162,12 +162,12 @@ public class PlayerInteractListener implements Listener { Lift lift = DataManager.getLift(DataManager.getEditPlayer(p.getUniqueId())); e.setCancelled(true); if (lift.getInputs().contains(tlb)) { - p.sendMessage(ChatColor.RED + "This block has already been chosen as an input. Choose another block!"); + ConfigUtil.sendMessage(e.getPlayer(), "Input.AlreadyAdded"); return; } lift.getInputs().add(tlb); DataManager.removeInputEditsPlayer(p.getUniqueId()); - p.sendMessage(ChatColor.GREEN + "Input created!"); + ConfigUtil.sendMessage(e.getPlayer(), "Input.Created"); } else if (DataManager.containsOfflineEditsPlayer(p.getUniqueId())) { if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return; Block block = e.getClickedBlock(); @@ -175,12 +175,12 @@ public class PlayerInteractListener implements Listener { Lift lift = DataManager.getLift(DataManager.getEditPlayer(p.getUniqueId())); e.setCancelled(true); if (lift.getOfflineInputs().contains(tlb)) { - p.sendMessage(ChatColor.RED + "This block has already been chosen as an input. Choose another block!"); + ConfigUtil.sendMessage(e.getPlayer(), "OfflineInput.AlreadyAdded"); return; } lift.getOfflineInputs().add(tlb); DataManager.removeOfflineEditsPlayer(p.getUniqueId()); - p.sendMessage(ChatColor.GREEN + "Offline input created!"); + ConfigUtil.sendMessage(e.getPlayer(), "OfflineInput.Created"); } else if (DataManager.containsInputRemovesPlayer(p.getUniqueId())) { if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return; Block block = e.getClickedBlock(); @@ -190,10 +190,10 @@ public class PlayerInteractListener implements Listener { if (lift.getInputs().contains(tlb)) { lift.getInputs().remove(tlb); DataManager.removeInputRemovesPlayer(p.getUniqueId()); - p.sendMessage(ChatColor.GREEN + "Input removed!"); + ConfigUtil.sendMessage(e.getPlayer(), "Input.Removed"); return; } - p.sendMessage(ChatColor.RED + "This block is not an input. Choose another block!"); + ConfigUtil.sendMessage(e.getPlayer(), "Input.NoInput"); } else if (DataManager.containsOfflineRemovesPlayer(p.getUniqueId())) { if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return; Block block = e.getClickedBlock(); @@ -203,26 +203,26 @@ public class PlayerInteractListener implements Listener { if (lift.getOfflineInputs().contains(tlb)) { lift.getOfflineInputs().remove(tlb); DataManager.removeOfflineRemovesPlayer(p.getUniqueId()); - p.sendMessage(ChatColor.GREEN + "Offline input removed!"); + ConfigUtil.sendMessage(e.getPlayer(), "OfflineInput.Removed"); return; } - p.sendMessage(ChatColor.RED + "This block is not an offline input. Choose another block!"); + ConfigUtil.sendMessage(e.getPlayer(), "OfflineInput.NoInput"); } else if (DataManager.containsBuilderPlayer(p.getUniqueId())) { if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return; e.setCancelled(true); int res = V10LiftPlugin.getAPI().switchBlockAtLift(DataManager.getEditPlayer(p.getUniqueId()), e.getClickedBlock()); switch (res) { case 0: - p.sendMessage(ChatColor.GREEN + "Block added to the elevator."); + ConfigUtil.sendMessage(e.getPlayer(), "Build.BlockAdded"); break; case 1: - p.sendMessage(ChatColor.GOLD + "Block removed from the elevator."); + ConfigUtil.sendMessage(e.getPlayer(), "Build.BlockRemoved"); break; case -2: - p.sendMessage(ChatColor.RED + "The material " + e.getClickedBlock().getType().toString() + " cannot be used!"); + ConfigUtil.sendMessage(e.getPlayer(), "Build.BlacklistedMaterial", Collections.singletonMap("%Name%", e.getClickedBlock().getType().toString().toLowerCase())); break; default: - p.sendMessage(ChatColor.RED + "Internal error."); + ConfigUtil.sendMessage(e.getPlayer(), "General.InternalError"); break; } } else if (DataManager.containsRopeEditPlayer(p.getUniqueId())) { @@ -231,33 +231,32 @@ public class PlayerInteractListener implements Listener { LiftBlock start = DataManager.getRopeEditPlayer(p.getUniqueId()); Block now = e.getClickedBlock(); if (start == null) { - p.sendMessage(ChatColor.GOLD + "Now right-click on the end of the rope!"); + ConfigUtil.sendMessage(e.getPlayer(), "Rope.Delete"); DataManager.addRopeEditPlayer(p.getUniqueId(), new LiftBlock(now.getWorld().getName(), now.getX(), now.getY(), now.getZ(), (String) null)); } else if (start.equals(new LiftBlock(now.getWorld().getName(), now.getX(), now.getY(), now.getZ(), (String) null))) { DataManager.addRopeEditPlayer(p.getUniqueId(), null); - p.sendMessage(ChatColor.GOLD + "Start removed!"); - p.sendMessage(ChatColor.GOLD + "Now right-click on the end of the rope!"); + ConfigUtil.sendMessage(e.getPlayer(), "Rope.PartRemoved"); } else { if (start.getX() != now.getX() || start.getZ() != now.getZ()) { - p.sendMessage(ChatColor.RED + "A rope can only go up!"); + ConfigUtil.sendMessage(e.getPlayer(), "Rope.OnlyUp"); return; } int res = V10LiftPlugin.getAPI().addRope(DataManager.getEditPlayer(p.getUniqueId()), now.getWorld(), start.getX(), now.getY(), start.getY(), start.getZ()); switch (res) { case 0: - p.sendMessage(ChatColor.GREEN + "Rope created."); + ConfigUtil.sendMessage(e.getPlayer(), "Rope.Created"); break; case -2: - p.sendMessage(ChatColor.RED + "The rope must be of the same material!"); + ConfigUtil.sendMessage(e.getPlayer(), "Rope.OnlyOneMaterial"); break; case -3: - p.sendMessage(ChatColor.RED + "Part of the rope is already part of another rope!"); + ConfigUtil.sendMessage(e.getPlayer(), "Rope.AlreadyARope"); break; case -4: - p.sendMessage(ChatColor.RED + "The rope is build of blacklisted blocks!"); + ConfigUtil.sendMessage(e.getPlayer(), "Rope.BlacklistedMaterial"); break; default: - p.sendMessage(ChatColor.RED + "Internal error."); + ConfigUtil.sendMessage(e.getPlayer(), "General.InternalError"); break; } DataManager.removeRopeEditPlayer(p.getUniqueId()); @@ -268,18 +267,18 @@ public class PlayerInteractListener implements Listener { Block block = e.getClickedBlock(); String liftName = DataManager.getEditPlayer(p.getUniqueId()); if (!V10LiftPlugin.getAPI().containsRope(liftName, block)) { - p.sendMessage(ChatColor.RED + "This block is not part of the rope."); + ConfigUtil.sendMessage(e.getPlayer(), "Rope.NotARope"); return; } V10LiftPlugin.getAPI().removeRope(liftName, block); DataManager.removeRopeRemovesPlayer(p.getUniqueId()); - p.sendMessage(ChatColor.GREEN + "Rope removed."); + ConfigUtil.sendMessage(e.getPlayer(), "Rope.Removed"); } else if (DataManager.containsDoorEditPlayer(p.getUniqueId())) { if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return; e.setCancelled(true); Block block = e.getClickedBlock(); if (V10LiftPlugin.getAPI().getFBM().isForbidden(block.getType())) { - p.sendMessage(ChatColor.RED + "The material " + e.getClickedBlock().getType().toString() + " is currently not supported!"); + ConfigUtil.sendMessage(e.getPlayer(), "Door.BlacklistedMaterial", Collections.singletonMap("%Name%", e.getClickedBlock().getType().toString().toLowerCase())); return; } LiftBlock lb; @@ -293,19 +292,19 @@ public class PlayerInteractListener implements Listener { if (DoorUtil.isOpenable(block)) { if (floor.getRealDoorBlocks().contains(lb)) { floor.getRealDoorBlocks().remove(lb); - p.sendMessage(ChatColor.GOLD + "Door removed."); + ConfigUtil.sendMessage(e.getPlayer(), "Door.Removed"); return; } floor.getRealDoorBlocks().add(lb); } else { if (floor.getDoorBlocks().contains(lb)) { floor.getDoorBlocks().remove(lb); - p.sendMessage(ChatColor.GOLD + "Door removed."); + ConfigUtil.sendMessage(e.getPlayer(), "Door.Removed"); return; } floor.getDoorBlocks().add(lb); } - p.sendMessage(ChatColor.GREEN + "Door created."); + ConfigUtil.sendMessage(e.getPlayer(), "Door.Created"); } else if (DataManager.containsWhoisREQPlayer(p.getUniqueId())) { if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return; e.setCancelled(true); @@ -319,7 +318,7 @@ public class PlayerInteractListener implements Listener { return; } } - p.sendMessage(ChatColor.RED + "This block is not part of a lift."); + ConfigUtil.sendMessage(e.getPlayer(), "Whois.NotALift"); } else { Action a = e.getAction(); if (a != Action.RIGHT_CLICK_BLOCK && a != Action.LEFT_CLICK_BLOCK) return; @@ -353,7 +352,10 @@ public class PlayerInteractListener implements Listener { } if (p.getGameMode() != GameMode.CREATIVE && masterAmount > 0) { if (!p.getInventory().contains(masterItem)) { - p.sendMessage(ChatColor.RED + "You need " + masterAmount + "x " + masterItem.toString().toLowerCase() + "!"); + Map replacements = new HashMap<>(); + replacements.put("%Amount%", String.valueOf(masterAmount)); + replacements.put("%ItemName%", masterItem.toString().toLowerCase()); + ConfigUtil.sendMessage(e.getPlayer(), "Repair.ItemsNeeded", replacements); return; } p.getInventory().remove(new ItemStack(masterItem, masterAmount)); @@ -373,7 +375,7 @@ public class PlayerInteractListener implements Listener { Iterator iter = lift.getFloors().keySet().iterator(); if (!lift.getFloors().containsKey(f)) { if (!iter.hasNext()) { - p.sendMessage(ChatColor.RED + "This elevator has no floors!"); + ConfigUtil.sendMessage(e.getPlayer(), "General.NoFloors"); return; } f = iter.next(); @@ -397,19 +399,19 @@ public class PlayerInteractListener implements Listener { sign.update(); } else { if (!lift.getFloors().containsKey(f)) { - p.sendMessage(ChatColor.RED + "Floor not found!"); + ConfigUtil.sendMessage(e.getPlayer(), "General.FloorDoesntExists"); return; } Floor floor = lift.getFloors().get(f); if (!floor.getUserWhitelist().isEmpty() && !floor.getUserWhitelist().contains(p.getUniqueId()) && !p.hasPermission("v10lift.admin")) { - p.sendMessage(ChatColor.RED + "You can't go to that floor!"); + ConfigUtil.sendMessage(e.getPlayer(), "General.NoWhitelistPermission"); e.setCancelled(true); return; } if (!floor.getGroupWhitelist().isEmpty() && !VaultManager.userHasAnyGroup(p, floor.getGroupWhitelist()) && !p.hasPermission("v10lift.admin")) { - p.sendMessage(ChatColor.RED + "You can't go to that floor!"); + ConfigUtil.sendMessage(e.getPlayer(), "General.NoWhitelistPermission"); e.setCancelled(true); return; } diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/Listeners/SignChangeListener.java b/src/main/lombok/nl/SBDeveloper/V10Lift/Listeners/SignChangeListener.java index 2723d3e..5552c2c 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/Listeners/SignChangeListener.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/Listeners/SignChangeListener.java @@ -3,6 +3,7 @@ package nl.SBDeveloper.V10Lift.Listeners; import nl.SBDeveloper.V10Lift.API.Objects.Lift; import nl.SBDeveloper.V10Lift.API.Objects.LiftSign; import nl.SBDeveloper.V10Lift.Managers.DataManager; +import nl.SBDeveloper.V10Lift.Utils.ConfigUtil; import org.bukkit.ChatColor; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -20,18 +21,18 @@ public class SignChangeListener implements Listener { Player p = e.getPlayer(); if (lines[1].isEmpty()) { - p.sendMessage(ChatColor.RED + "No lift name given!"); + ConfigUtil.sendMessage(e.getPlayer(), "LiftSign.NoName"); return; } if (!DataManager.containsLift(lines[1])) { - p.sendMessage(ChatColor.RED + "Lift " + lines[1] + " doesn't exists!"); + ConfigUtil.sendMessage(e.getPlayer(), "General.DoesntExists"); return; } Lift lift = DataManager.getLift(lines[1]); if (!lift.getOwners().contains(p.getUniqueId()) && !p.hasPermission("v10lift.admin")) { - p.sendMessage(ChatColor.RED + "You can't do this!"); + ConfigUtil.sendMessage(e.getPlayer(), "General.NoPermission"); e.setCancelled(true); return; } @@ -47,7 +48,7 @@ public class SignChangeListener implements Listener { Block b = e.getBlock(); lift.getSigns().add(new LiftSign(b.getWorld().getName(), b.getX(), b.getY(), b.getZ(), type, (byte) 0)); - p.sendMessage(ChatColor.GREEN + "Lift sign created!"); + ConfigUtil.sendMessage(e.getPlayer(), "LiftSign.Created"); } } diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/Utils/ConfigUtil.java b/src/main/lombok/nl/SBDeveloper/V10Lift/Utils/ConfigUtil.java index d2c6bd5..8fffed7 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/Utils/ConfigUtil.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/Utils/ConfigUtil.java @@ -5,7 +5,7 @@ import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import javax.annotation.Nonnull; -import java.util.HashMap; +import java.util.Map; import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -48,9 +48,8 @@ public class ConfigUtil { * @param p The commandsender to send it to * @param path The path to look for * @param replacement The replacements -> key: %Name% = value: TheName - * @return The message with replacements */ - public static void sendMessage(CommandSender p, @Nonnull String path, HashMap replacement) { + public static void sendMessage(CommandSender p, @Nonnull String path, Map replacement) { String fileMessage = V10LiftPlugin.getMessages().getFile().getString(path); if (fileMessage == null) { throw new NullPointerException("Message " + path + " not found in messages.yml!"); diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index 6ef810b..8c36b1b 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -108,6 +108,7 @@ 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."