diff --git a/build.gradle b/build.gradle index 28815cc..8fe4359 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ apply plugin: 'net.minecraftforge.gradle' apply plugin: 'eclipse' apply plugin: 'maven-publish' -version = 'MC1.12.2-1.3.2' +version = 'MC1.12.2-1.3.4' group = 'com.gmail.picono435.randomtp' // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = 'RandomTP' diff --git a/src/main/java/com/gmail/picono435/randomtp/MainMod.java b/src/main/java/com/gmail/picono435/randomtp/MainMod.java index e0fdd7a..f536d7f 100644 --- a/src/main/java/com/gmail/picono435/randomtp/MainMod.java +++ b/src/main/java/com/gmail/picono435/randomtp/MainMod.java @@ -23,7 +23,7 @@ public class MainMod { public static final String MODID = "randomtp"; public static final String NAME = "Random Teleport Mod"; - public static final String VERSION = "1.3"; + public static final String VERSION = "MC1.12.2-1.3.4"; public static final String NEW_LINE; @@ -71,8 +71,9 @@ public void init(FMLServerStartingEvent event) logger.info("Configs files loaded."); - PermissionAPI.registerNode("randomtp.command.basic", DefaultPermissionLevel.OP, "The permission to execute the command /randomtp"); - PermissionAPI.registerNode("randomtp.command.interdim", DefaultPermissionLevel.OP, "The permission to execute the command /randomtp"); + PermissionAPI.registerNode("randomtp.command.basic", DefaultPermissionLevel.ALL, "The permission to execute the command /randomtp"); + PermissionAPI.registerNode("randomtp.command.interdim", DefaultPermissionLevel.ALL, "The permission to execute the command /randomtpdimension"); + PermissionAPI.registerNode("randomtp.cooldown.exempt", DefaultPermissionLevel.OP, "The permission used to be exempt from the cooldown"); } public void preInit(FMLPostInitializationEvent event) diff --git a/src/main/java/com/gmail/picono435/randomtp/commands/RTPCommand.java b/src/main/java/com/gmail/picono435/randomtp/commands/RTPCommand.java index 3cf31b5..09652f9 100644 --- a/src/main/java/com/gmail/picono435/randomtp/commands/RTPCommand.java +++ b/src/main/java/com/gmail/picono435/randomtp/commands/RTPCommand.java @@ -36,8 +36,7 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] para World world = getCommandSenderAsPlayer(sender).getEntityWorld(); WorldBorder border = world.getWorldBorder(); EntityPlayer p = getCommandSenderAsPlayer(sender); - TextComponentString succefull = new TextComponentString(Messages.succefully.replaceAll("\\{playerName\\}", p.getName()).replaceAll("\\{blockZ\\}", "" + p.getPositionVector().z).replaceAll("\\{blockX\\}", "" + p.getPositionVector().x).replaceAll("&", "§")); - if(!checkCooldown(p)) { + if(!checkCooldown(p) && !PermissionAPI.hasPermission(p, "randomtp.cooldown.exempt")) { long secondsLeft = getCooldownLeft(p); TextComponentString cooldownmes = new TextComponentString(Messages.cooldown.replaceAll("\\{secondsLeft\\}", Long.toString(secondsLeft)).replaceAll("\\{playerName\\}", p.getName()).replaceAll("&", "§")); p.sendMessage(cooldownmes); @@ -50,9 +49,11 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] para } if(Config.max_distance == 0) { server.getCommandManager().executeCommand(server, "spreadplayers " + border.getCenterX() + " " + border.getCenterZ() + " " + Config.min_distance + " " + border.getDiameter()/2 + " false " + p.getDisplayNameString()); + TextComponentString succefull = new TextComponentString(Messages.succefully.replaceAll("\\{playerName\\}", p.getName()).replaceAll("\\{blockX\\}", "" + (int)p.getPositionVector().x).replaceAll("\\{blockY\\}", "" + (int)p.getPositionVector().y).replaceAll("\\{blockZ\\}", "" + (int)p.getPositionVector().z).replaceAll("&", "§")); p.sendMessage(succefull); } else { server.getCommandManager().executeCommand(server, "spreadplayers " + border.getCenterX() + " " + border.getCenterZ() + " " + Config.min_distance + " " + Config.max_distance + " false " + p.getDisplayNameString()); + TextComponentString succefull = new TextComponentString(Messages.succefully.replaceAll("\\{playerName\\}", p.getName()).replaceAll("\\{blockX\\}", "" + (int)p.getPositionVector().x).replaceAll("\\{blockY\\}", "" + (int)p.getPositionVector().y).replaceAll("\\{blockZ\\}", "" + (int)p.getPositionVector().z).replaceAll("&", "§")); p.sendMessage(succefull); } cooldowns.put(sender.getName(), System.currentTimeMillis()); @@ -99,16 +100,10 @@ public List getAliases() @Override public boolean checkPermission(MinecraftServer server, ICommandSender sender) { if(!(sender instanceof EntityPlayer)) return true; - if(Config.only_op_basic) { - EntityPlayer p; - try { - p = getCommandSenderAsPlayer(sender); - } catch (PlayerNotFoundException e) { - return true; - } - return PermissionAPI.hasPermission(p, "randomtp.command.basic"); - } else { - return true; + try { + return PermissionAPI.hasPermission(getCommandSenderAsPlayer(sender), "randomtp.command.basic"); + } catch (PlayerNotFoundException e) { + return false; } } @@ -123,7 +118,7 @@ private void randomTeleport(EntityPlayer p) { int x = r.nextInt(high-low) + low; int y = 50; int z = r.nextInt(high-low) + low; - int maxTries = -1; + int maxTries = Config.maxTries; while (!isSafe(p, x, y, z) && (maxTries == -1 || maxTries > 0)) { y++; if(y >= 120) { @@ -136,14 +131,14 @@ private void randomTeleport(EntityPlayer p) { maxTries--; } if(maxTries == 0) { - TextComponentString msg = new TextComponentString("Error, please try again."); + TextComponentString msg = new TextComponentString(Messages.maxTries.replaceAll("\\{playerName\\}", p.getName()).replaceAll("&", "§")); p.sendMessage(msg); return; } } p.setPositionAndUpdate(x, y, z); - TextComponentString succefull = new TextComponentString(Messages.succefully.replaceAll("\\{playerName\\}", p.getName()).replaceAll("\\{blockZ\\}", "" + p.getPositionVector().z).replaceAll("\\{blockX\\}", "" + p.getPositionVector().x).replaceAll("&", "§")); + TextComponentString succefull = new TextComponentString(Messages.succefully.replaceAll("\\{playerName\\}", p.getName()).replaceAll("\\{blockX\\}", "" + (int)p.getPositionVector().x).replaceAll("\\{blockY\\}", "" + (int)p.getPositionVector().y).replaceAll("\\{blockZ\\}", "" + (int)p.getPositionVector().z).replaceAll("&", "§")); p.sendMessage(succefull); } diff --git a/src/main/java/com/gmail/picono435/randomtp/commands/RTPDCommand.java b/src/main/java/com/gmail/picono435/randomtp/commands/RTPDCommand.java index 8b30807..5a2fc43 100644 --- a/src/main/java/com/gmail/picono435/randomtp/commands/RTPDCommand.java +++ b/src/main/java/com/gmail/picono435/randomtp/commands/RTPDCommand.java @@ -40,8 +40,7 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] para p.sendMessage(new TextComponentString(Messages.invalidArgs.replaceAll("\\{playerName\\}", p.getName()).replace('&', '§'))); return; } - TextComponentString succefull = new TextComponentString(Messages.succefully.replaceAll("\\{playerName\\}", p.getName()).replaceAll("\\{blockZ\\}", "" + p.getPositionVector().z).replaceAll("\\{blockX\\}", "" + p.getPositionVector().x).replace('&', '§')); - if(!checkCooldown(p)) { + if(!checkCooldown(p) && !PermissionAPI.hasPermission(p, "randomtp.cooldown.exempt")) { long secondsLeft = getCooldownLeft(p); TextComponentString cooldownmes = new TextComponentString(Messages.cooldown.replaceAll("\\{secondsLeft\\}", Long.toString(secondsLeft)).replaceAll("\\{playerName\\}", p.getName()).replace('&', '§')); p.sendMessage(cooldownmes); @@ -72,9 +71,11 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] para } if(Config.max_distance == 0) { server.getCommandManager().executeCommand(server, "spreadplayers " + border.getCenterX() + " " + border.getCenterZ() + " " + Config.min_distance + " " + border.getDiameter()/2 + " false " + p.getDisplayNameString()); - p.sendMessage(succefull); + TextComponentString succefull = new TextComponentString(Messages.succefully.replaceAll("\\{playerName\\}", p.getName()).replaceAll("\\{blockX\\}", "" + (int)p.getPositionVector().x).replaceAll("\\{blockY\\}", "" + (int)p.getPositionVector().y).replaceAll("\\{blockZ\\}", "" + (int)p.getPositionVector().z).replaceAll("&", "§")); + p.sendMessage(succefull); } else { server.getCommandManager().executeCommand(server, "spreadplayers " + border.getCenterX() + " " + border.getCenterZ() + " " + Config.min_distance + " " + Config.max_distance + " false " + p.getDisplayNameString()); + TextComponentString succefull = new TextComponentString(Messages.succefully.replaceAll("\\{playerName\\}", p.getName()).replaceAll("\\{blockX\\}", "" + (int)p.getPositionVector().x).replaceAll("\\{blockY\\}", "" + (int)p.getPositionVector().y).replaceAll("\\{blockZ\\}", "" + (int)p.getPositionVector().z).replaceAll("&", "§")); p.sendMessage(succefull); } cooldowns.put(sender.getName(), System.currentTimeMillis()); @@ -131,16 +132,10 @@ public List getAliases() @Override public boolean checkPermission(MinecraftServer server, ICommandSender sender) { if(!(sender instanceof EntityPlayer)) return true; - if(Config.only_op_dim) { - EntityPlayer p; - try { - p = getCommandSenderAsPlayer(sender); - } catch (PlayerNotFoundException e) { - return true; - } - return PermissionAPI.hasPermission(p, "randomtp.command.interdim"); - } else { - return true; + try { + return PermissionAPI.hasPermission(getCommandSenderAsPlayer(sender), "randomtp.command.interdim"); + } catch (PlayerNotFoundException e) { + return false; } } @@ -167,14 +162,14 @@ private void randomTeleport(EntityPlayer p) { maxTries--; } if(maxTries == 0) { - TextComponentString msg = new TextComponentString("Error, please try again."); + TextComponentString msg = new TextComponentString(Messages.maxTries.replaceAll("\\{playerName\\}", p.getName()).replaceAll("&", "§")); p.sendMessage(msg); return; } } p.setPositionAndUpdate(x, y, z); - TextComponentString succefull = new TextComponentString(Messages.succefully.replaceAll("\\{playerName\\}", p.getName()).replaceAll("\\{blockZ\\}", "" + p.getPositionVector().z).replaceAll("\\{blockX\\}", "" + p.getPositionVector().x).replaceAll("&", "§")); + TextComponentString succefull = new TextComponentString(Messages.succefully.replaceAll("\\{playerName\\}", p.getName()).replaceAll("\\{blockX\\}", "" + (int)p.getPositionVector().x).replaceAll("\\{blockY\\}", "" + (int)p.getPositionVector().y).replaceAll("\\{blockZ\\}", "" + (int)p.getPositionVector().z).replaceAll("&", "§")); p.sendMessage(succefull); } diff --git a/src/main/java/com/gmail/picono435/randomtp/config/Config.java b/src/main/java/com/gmail/picono435/randomtp/config/Config.java index efc4968..1d7ff85 100644 --- a/src/main/java/com/gmail/picono435/randomtp/config/Config.java +++ b/src/main/java/com/gmail/picono435/randomtp/config/Config.java @@ -6,23 +6,19 @@ public class Config { private static final String CATEGORY_DISTANCE = "Distance"; - private static final String CATEGORY_PERMISSION = "Permission"; private static final String CATEGORY_INTERDIM = "Inter-Dimensions-Command"; private static final String CATEGORY_OTHERS = "Others"; - + public static int max_distance = 0; public static int min_distance = 1; - public static boolean only_op_basic = true; - public static boolean only_op_dim = true; + public static int cooldown = 0; + public static boolean useOriginal = true; + public static int maxTries = -1; public static boolean dim = true; public static boolean useWhitelist = true; public static String[] allowedDimensions = {"1", "-1"}; - - public static int cooldown = 0; - public static boolean useOriginal = true; - public static int maxTries = -1; public static void readConfig() { Configuration cfg = MainMod.config; @@ -43,10 +39,6 @@ public static void initGeneralConfig(Configuration cfg) { max_distance = cfg.getInt("max_distance", CATEGORY_DISTANCE, max_distance, 0, Integer.MAX_VALUE, "Max distance that you want to a person be teleported. (auto = world border size / 2)"); min_distance = cfg.getInt("min_distance", CATEGORY_DISTANCE, min_distance, 1, Integer.MAX_VALUE, "Minimum distance that you want to a person be teleported."); - cfg.addCustomCategoryComment(CATEGORY_PERMISSION, "Permission configuration settings for RandomTP!"); - only_op_basic = cfg.getBoolean("only_op_basic_command", CATEGORY_PERMISSION, only_op_basic, "If you want only op players or with the required permission node to execute the basic /rtp command. (Permission node: randomtp.command.basic)"); - only_op_dim = cfg.getBoolean("only_op_dim_command", CATEGORY_PERMISSION, only_op_dim, "If you want only op players or with the required permission node to execute the inter dimension /rtpd command. (Permission node: randomtp.command.interdim)"); - cfg.addCustomCategoryComment(CATEGORY_INTERDIM, "Configuration settings for the inter dimensions command for RandomTP"); dim = cfg.getBoolean("inter-dim", CATEGORY_INTERDIM, dim, "Do you want to the command /rtpd be allowed? (This commands adds a inter-dimension RTP)"); useWhitelist = cfg.getBoolean("use-whitelist", CATEGORY_INTERDIM, useWhitelist, "Do you want to use the whitelist or blacklist dimension? "); diff --git a/src/main/java/com/gmail/picono435/randomtp/config/Messages.java b/src/main/java/com/gmail/picono435/randomtp/config/Messages.java index d6c344c..414cbeb 100644 --- a/src/main/java/com/gmail/picono435/randomtp/config/Messages.java +++ b/src/main/java/com/gmail/picono435/randomtp/config/Messages.java @@ -7,11 +7,12 @@ public class Messages { private static final String CATEGORY_COMMAND = "Command"; - public static String succefully = "&aSuccefully teleported you to a random location."; + public static String succefully = "&aYou have been teleported to the coordinates &e{blockX}, {blockY}, {blockZ}&a."; public static String cooldown = "&cWait more {secondsLeft} seconds for execute the command again."; public static String invalidArgs = "&cPlease use /rtpd (dimension)."; public static String invalidDimension = "&cPlease put a valid dimension (e.g: -1)."; public static String dimensionNotAllowed = "&cYou cannot random teleport to that dimension!"; + public static String maxTries = "&cTimed out trying to find a safe location to warp to."; public static void readConfig() { Configuration cfg = MainMod.messages; @@ -34,5 +35,6 @@ public static void initGeneralConfig(Configuration cfg) { invalidArgs = cfg.getString("invalid-args", CATEGORY_COMMAND, invalidArgs, "Message that you want to appier when you execute /rtpd without args. [ placeholders: {playerName}, color codes: & + letter (example: &c) ]"); invalidDimension = cfg.getString("invalid-dimension", CATEGORY_COMMAND, invalidDimension, "Message that you want to appier when you execute /rtpd with a invalid dimension [ placeholders: {playerName} {dimensionId}, color codes: & + letter (example: &c) ]."); dimensionNotAllowed = cfg.getString("blacklist-dimension", CATEGORY_COMMAND, dimensionNotAllowed, "Message that you want to appier when you execute /rtpd with a dimension that is in the blacklist [ placeholders: {playerName} {dimensionId}, color codes: & + letter (example: &c) ]."); + maxTries = cfg.getString("max-tries", CATEGORY_COMMAND, dimensionNotAllowed, "Message that you want to appier when the max tries of finding a safe location is reached [ placeholders: {playerName}, color codes: & + letter (example: &c) ]."); } } \ No newline at end of file