Skip to content

Commit

Permalink
MC 1.12.2-1.3.4
Browse files Browse the repository at this point in the history
This version fixes a lot of bugs with permissions and add some cool mini features. Here is a detailed change-log:
- Added new max tries message
- Added new permission (randomtp.cooldown.exempt) to ignore cooldown [DEFAULT: OP]
- Changed the default messages
- Fixed issues with placeholders
- Fixed issue with max tries
- Fixed minor issues
- Removed only_op options (Now permissions are fully controlled by nodes)

How to update:
1. Delete the old .jar file from the mods folder of the server root
2. Move the new .jar to the folder mods of the server root

Permissions:
randomtp.command.basic - Execute /randomtp [DEFAULT: ALL]
randomtp.command.interdim - Execute /randomtpdimension [DEFAULT: ALL]
randomtp.cooldown.exempt - Ignore cooldown [DEFAULT: OP]
  • Loading branch information
Picono435 authored Dec 23, 2020
1 parent 75aaa57 commit bf9528f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 47 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/gmail/picono435/randomtp/MainMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down
25 changes: 10 additions & 15 deletions src/main/java/com/gmail/picono435/randomtp/commands/RTPCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
Expand Down Expand Up @@ -99,16 +100,10 @@ public List<String> 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;
}
}

Expand All @@ -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) {
Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -131,16 +132,10 @@ public List<String> 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;
}
}

Expand All @@ -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);
}

Expand Down
16 changes: 4 additions & 12 deletions src/main/java/com/gmail/picono435/randomtp/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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? ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) ].");
}
}

0 comments on commit bf9528f

Please sign in to comment.