diff --git a/build.gradle b/build.gradle index 852bfdc..0a725e3 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,7 @@ apply plugin: 'net.minecraftforge.gradle' apply plugin: 'eclipse' apply plugin: 'maven-publish' -version = 'MC1.15.2-3.1.1' +version = 'MC1.15.2-3.1.2' 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 3c9a9b2..fc41577 100644 --- a/src/main/java/com/gmail/picono435/randomtp/MainMod.java +++ b/src/main/java/com/gmail/picono435/randomtp/MainMod.java @@ -26,9 +26,6 @@ @Mod("randomtp") public class MainMod { - public static final String MODID = "randomtp"; - public static final String NAME = "Random Teleport Mod"; - public static final String NEW_LINE; public static Logger logger; @@ -71,7 +68,8 @@ 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"); } } \ No newline at end of file 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 842439e..5da86eb 100644 --- a/src/main/java/com/gmail/picono435/randomtp/commands/RTPCommand.java +++ b/src/main/java/com/gmail/picono435/randomtp/commands/RTPCommand.java @@ -44,8 +44,7 @@ private static int runCommand(PlayerEntity p) { World world = p.getEntityWorld(); WorldBorder border = world.getWorldBorder(); MinecraftServer server = MainMod.server; - StringTextComponent succefull = new StringTextComponent(Messages.succefully.get().replaceAll("\\{playerName\\}", p.getName().getString()).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); StringTextComponent cooldownmes = new StringTextComponent(Messages.cooldown.get().replaceAll("\\{secondsLeft\\}", Long.toString(secondsLeft)).replaceAll("\\{playerName\\}", p.getName().getString()).replaceAll("&", "§")); p.sendMessage(cooldownmes); @@ -61,9 +60,11 @@ private static int runCommand(PlayerEntity p) { String maxDistance = num.toPlainString(); if(Config.max_distance.get() == 0) { server.getCommandManager().handleCommand(server.getCommandSource(), "spreadplayers " + border.getCenterX() + " " + border.getCenterZ() + " " + Config.min_distance.get() + " " + maxDistance + " false " + p.getName().getString().toLowerCase()); + StringTextComponent succefull = new StringTextComponent(Messages.succefully.get().replaceAll("\\{playerName\\}", p.getName().getString()).replaceAll("\\{blockX\\}", "" + (int)p.getPositionVec().x).replaceAll("\\{blockY\\}", "" + (int)p.getPositionVec().y).replaceAll("\\{blockZ\\}", "" + (int)p.getPositionVec().z).replaceAll("&", "§")); p.sendMessage(succefull); } else { server.getCommandManager().handleCommand(server.getCommandSource(), "spreadplayers " + border.getCenterX() + " " + border.getCenterZ() + " " + Config.min_distance.get() + " " + Config.max_distance.get() + " false " + p.getName().getString().toLowerCase()); + StringTextComponent succefull = new StringTextComponent(Messages.succefully.get().replaceAll("\\{playerName\\}", p.getName().getString()).replaceAll("\\{blockX\\}", "" + (int)p.getPositionVec().x).replaceAll("\\{blockY\\}", "" + (int)p.getPositionVec().y).replaceAll("\\{blockZ\\}", "" + (int)p.getPositionVec().z).replaceAll("&", "§")); p.sendMessage(succefull); } cooldowns.put(p.getName().getString(), System.currentTimeMillis()); @@ -124,14 +125,14 @@ private static void randomTeleport(PlayerEntity p) { maxTries--; } if(maxTries == 0) { - StringTextComponent msg = new StringTextComponent("Error, please try again."); + StringTextComponent msg = new StringTextComponent(Messages.maxTries.get().replaceAll("\\{playerName\\}", p.getName().getString()).replaceAll("&", "§")); p.sendMessage(msg); return; } } p.setPositionAndUpdate(x, y, z); - StringTextComponent succefull = new StringTextComponent(Messages.succefully.get().replaceAll("\\{playerName\\}", p.getName().getString()).replaceAll("\\{blockZ\\}", "" + p.getPositionVec().z).replaceAll("\\{blockX\\}", "" + p.getPositionVec().x).replaceAll("&", "§")); + StringTextComponent succefull = new StringTextComponent(Messages.succefully.get().replaceAll("\\{playerName\\}", p.getName().getString()).replaceAll("\\{blockX\\}", "" + (int)p.getPositionVec().x).replaceAll("\\{blockY\\}", "" + (int)p.getPositionVec().y).replaceAll("\\{blockZ\\}", "" + (int)p.getPositionVec().z).replaceAll("&", "§")); p.sendMessage(succefull); } catch(Exception ex) { MainMod.logger.info("Error executing command."); 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 37f7c04..4f00539 100644 --- a/src/main/java/com/gmail/picono435/randomtp/commands/RTPDCommand.java +++ b/src/main/java/com/gmail/picono435/randomtp/commands/RTPDCommand.java @@ -58,8 +58,7 @@ private static int runCommand(PlayerEntity p, DimensionType dim) { World world = p.getEntityWorld(); WorldBorder border = world.getWorldBorder(); MinecraftServer server = MainMod.server; - StringTextComponent succefull = new StringTextComponent(Messages.succefully.get().replaceAll("\\{playerName\\}", p.getName().getString()).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); StringTextComponent cooldownmes = new StringTextComponent(Messages.cooldown.get().replaceAll("\\{secondsLeft\\}", Long.toString(secondsLeft)).replaceAll("\\{playerName\\}", p.getName().getString()).replaceAll("&", "§")); p.sendMessage(cooldownmes); @@ -82,9 +81,11 @@ private static int runCommand(PlayerEntity p, DimensionType dim) { } if(Config.max_distance.get() == 0) { server.getCommandManager().handleCommand(server.getCommandSource(), "spreadplayers " + border.getCenterX() + " " + border.getCenterZ() + " " + Config.min_distance.get() + " " + maxDistance + " false " + p.getName().getString().toLowerCase()); + StringTextComponent succefull = new StringTextComponent(Messages.succefully.get().replaceAll("\\{playerName\\}", p.getName().getString()).replaceAll("\\{blockX\\}", "" + (int)p.getPositionVec().x).replaceAll("\\{blockY\\}", "" + (int)p.getPositionVec().y).replaceAll("\\{blockZ\\}", "" + (int)p.getPositionVec().z).replaceAll("&", "§")); p.sendMessage(succefull); } else { server.getCommandManager().handleCommand(server.getCommandSource(), "spreadplayers " + border.getCenterX() + " " + border.getCenterZ() + " " + Config.min_distance.get() + " " + Config.max_distance.get() + " false " + p.getName().getString().toLowerCase()); + StringTextComponent succefull = new StringTextComponent(Messages.succefully.get().replaceAll("\\{playerName\\}", p.getName().getString()).replaceAll("\\{blockX\\}", "" + (int)p.getPositionVec().x).replaceAll("\\{blockY\\}", "" + (int)p.getPositionVec().y).replaceAll("\\{blockZ\\}", "" + (int)p.getPositionVec().z).replaceAll("&", "§")); p.sendMessage(succefull); } cooldowns.put(p.getName().getString(), System.currentTimeMillis()); @@ -125,7 +126,7 @@ public static boolean inWhitelist(String dimension) { private static boolean hasPermission(CommandSource source) { try { - return PermissionAPI.hasPermission(source.asPlayer(), "randomtp.command.basic"); + return PermissionAPI.hasPermission(source.asPlayer(), "randomtp.command.interdim"); } catch (CommandSyntaxException e) { return false; } @@ -155,14 +156,14 @@ private static void randomTeleport(PlayerEntity p) { maxTries--; } if(maxTries == 0) { - StringTextComponent msg = new StringTextComponent("Error, please try again."); + StringTextComponent msg = new StringTextComponent(Messages.maxTries.get().replaceAll("\\{playerName\\}", p.getName().getString()).replaceAll("&", "§")); p.sendMessage(msg); return; } } p.setPositionAndUpdate(x, y, z); - StringTextComponent succefull = new StringTextComponent(Messages.succefully.get().replaceAll("\\{playerName\\}", p.getName().getString()).replaceAll("\\{blockZ\\}", "" + p.getPositionVec().z).replaceAll("\\{blockX\\}", "" + p.getPositionVec().x).replaceAll("&", "§")); + StringTextComponent succefull = new StringTextComponent(Messages.succefully.get().replaceAll("\\{playerName\\}", p.getName().getString()).replaceAll("\\{blockX\\}", "" + (int)p.getPositionVec().x).replaceAll("\\{blockY\\}", "" + (int)p.getPositionVec().y).replaceAll("\\{blockZ\\}", "" + (int)p.getPositionVec().z).replaceAll("&", "§")); p.sendMessage(succefull); } catch(Exception ex) { MainMod.logger.info("Error executing command."); 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 5206151..ee96d25 100644 --- a/src/main/java/com/gmail/picono435/randomtp/config/Config.java +++ b/src/main/java/com/gmail/picono435/randomtp/config/Config.java @@ -9,10 +9,7 @@ public class Config { public static ForgeConfigSpec.ConfigValue max_distance; public static ForgeConfigSpec.ConfigValue min_distance; - - public static ForgeConfigSpec.ConfigValue only_op_basic; - public static ForgeConfigSpec.ConfigValue only_op_dim; - + public static ForgeConfigSpec.ConfigValue cooldown; public static ForgeConfigSpec.ConfigValue useOriginal; public static ForgeConfigSpec.ConfigValue maxTries; @@ -59,14 +56,5 @@ public static void initConfig(ForgeConfigSpec.Builder config) { maxTries = config .comment("The amount of tries to find a safe location (original system) [-1 = infinite]") .define("others.max-tries", -1); - - //PERMISSION CATEGORY - only_op_basic = config - .comment("If you want only op players or with the required permission node to execute the basic /rtp command. (Permission node: randomtp.command.basic) [default: true]") - .define("permission.only_op_basic", true); - - only_op_dim = config - .comment("If you want only op players or with the required permission node to execute the inter dimension /rtpd command. (Permission node: randomtp.command.interdim) [default: true])") - .define("permission.only_op_dim", true); } } 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 f6e09c2..9afb3a0 100644 --- a/src/main/java/com/gmail/picono435/randomtp/config/Messages.java +++ b/src/main/java/com/gmail/picono435/randomtp/config/Messages.java @@ -7,13 +7,14 @@ public class Messages { public static ForgeConfigSpec.ConfigValue succefully; public static ForgeConfigSpec.ConfigValue cooldown; public static ForgeConfigSpec.ConfigValue dimensionNotAllowed; + public static ForgeConfigSpec.ConfigValue maxTries; public static void initConfig(ForgeConfigSpec.Builder config) { config.comment("Configuration file"); succefully = config .comment("Message that you want to appier when the command is succefully made. [ placeholders: {playerName} {blockZ} {blockY}, color codes: & + letter (example: &c) ] [default: &aSuccefully teleported you to a random location.]") - .define("command.succefully", "&aSuccefully teleported you to a random location."); + .define("command.succefully", "&aYou have been teleported to the coordinates &e{blockX}, {blockY}, {blockZ}&a."); cooldown = config .comment("Message that you want to appier when the command is on cooldown. [ placeholders: {playerName}, color codes: & + letter (example: &c) ] [default: &cWait more {secondsLeft} seconds for execute the command again.]") @@ -22,5 +23,9 @@ public static void initConfig(ForgeConfigSpec.Builder config) { dimensionNotAllowed = config .comment("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) ]. [default: &cYou cannot random teleport to that dimension!]") .define("command.dimensionNotAllowed", "&cYou cannot random teleport to that dimension!"); + + maxTries = config + .comment("Message that you want to appier when the max tries of finding a safe location is reached [ placeholders: {playerName}, color codes: & + letter (example: &c) ].") + .define("command.max-tries", "&cTimed out trying to find a safe location to warp to."); } } \ No newline at end of file