From c8a00751fae8c548d47a3b9192a766d8d47ec15e Mon Sep 17 00:00:00 2001 From: SuperRonanCraft Date: Wed, 23 Sep 2020 17:41:04 -0400 Subject: [PATCH] Permission based world configs added + UseWorldBorder slightly ignores maxRadius --- pom.xml | 2 +- .../me/SuperRonanCraft/BetterRTP/Main.java | 5 + .../BetterRTP/player/rtp/RTP.java | 21 +++- .../BetterRTP/player/rtp/RTPPermConfigs.java | 102 +++++++++++++++++- .../BetterRTP/references/Permissions.java | 4 + .../references/worlds/WorldPlayer.java | 12 ++- src/main/resources/config.yml | 8 +- src/main/resources/plugin.yml | 2 +- 8 files changed, 142 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index f60ddbd..7c68ccc 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.SuperRonanCraft BetterRTP - 2.13.1 + 2.13.2 1.8 diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/Main.java b/src/main/java/me/SuperRonanCraft/BetterRTP/Main.java index 8c08aac..8980a99 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/Main.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/Main.java @@ -116,4 +116,9 @@ public class Main extends JavaPlugin { eco.load(); perms.register(); } + + public static void debug(String str) { + if (getInstance().getSettings().debug) + getInstance().getLogger().info(str); + } } diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTP.java b/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTP.java index 3c29e03..5762b85 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTP.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTP.java @@ -21,6 +21,7 @@ public class RTP { private final RTPTeleport teleport = new RTPTeleport(); private final RTPPluginValidation softDepends = new RTPPluginValidation(); + private final RTPPermConfigs permConfig = new RTPPermConfigs(); //Cache public HashMap customWorlds = new HashMap<>(); public HashMap overriden = new HashMap<>(); @@ -83,15 +84,15 @@ public class RTP { } if (getPl().getSettings().debug) for (String world : world_type.keySet()) - getPl().getLogger().info("- World Type for '" + world + "' set to '" + world_type.get(world) + "'"); + Main.debug("- World Type for '" + world + "' set to '" + world_type.get(world) + "'"); } catch (Exception e) { e.printStackTrace(); //No World Types } loadWorldSettings(); - teleport.load(); //Load teleporting stuff + permConfig.load(); //Load permission configs } public void loadWorldSettings() { @@ -105,7 +106,7 @@ public class RTP { for (Map.Entry entry : m.entrySet()) { customWorlds.put(entry.getKey().toString(), new WorldCustom(entry.getKey().toString())); if (getPl().getSettings().debug) - getPl().getLogger().info("- Custom World '" + entry.getKey() + "' registered"); + Main.debug("- Custom World '" + entry.getKey() + "' registered"); } } catch (Exception e) { //No Custom Worlds @@ -161,6 +162,20 @@ public class RTP { getPl().getCmd().cooldowns.remove(p.getUniqueId()); return; } + // Permission Configs + RTPPermConfigs.RTPPermConfiguration config = permConfig.getGroup(p); + if (config != null) { + for (RTPPermConfigs.RTPPermConfigurationWorld world : config.worlds) { + if (pWorld.getWorld().getName().equals(world.name)) { + if (world.maxRad != -1) + pWorld.setMinRad(world.maxRad); + if (world.minRad != -1) + pWorld.setMinRad(world.minRad); + if (world.price != -1) + pWorld.setPrice(world.price); + } + } + } // Delaying? Else, just go getPl().getCmd().rtping.put(p.getUniqueId(), true); //Cache player so they cant run '/rtp' again while rtp'ing if (getPl().getSettings().delayEnabled && delay) { diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTPPermConfigs.java b/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTPPermConfigs.java index 502c6b0..2a3068e 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTPPermConfigs.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTPPermConfigs.java @@ -1,12 +1,108 @@ package me.SuperRonanCraft.BetterRTP.player.rtp; -import java.util.ArrayList; -import java.util.List; +import com.sun.org.apache.xerces.internal.xs.StringList; +import me.SuperRonanCraft.BetterRTP.Main; +import me.SuperRonanCraft.BetterRTP.references.file.FileBasics; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; +import java.util.*; + +@SuppressWarnings("rawtypes") public class RTPPermConfigs { - private List groups = new ArrayList<>(); + private List groups = new ArrayList<>(); + + public RTPPermConfiguration getGroup(Player p) { + for (RTPPermConfiguration group : groups) + if (Main.getInstance().getPerms().getConfig(p, group.name)) + return group; + return null; + } public void load() { + for (RTPPermConfiguration group : groups) + group.worlds.clear(); + groups.clear(); + YamlConfiguration config = Main.getInstance().getFiles().getType(FileBasics.FILETYPE.CONFIG).getConfig(); + List> list = config.getMapList("PermissionConfigs"); + for (Map m : list) + for (Map.Entry entry : m.entrySet()) { + RTPPermConfiguration group = new RTPPermConfiguration(entry); + if (group.isValid()) { + groups.add(group); + Main.debug("- Group " + group.name + " has " + group.worlds.size() + " worlds setup, permission: 'betterrtp.config." + group.name + "'"); + for (RTPPermConfigurationWorld world : group.worlds) { + Main.debug(" - World '" + world.name + "' MaxRad = " + world.maxRad + ", MinRad = " + world.minRad); + } + } else { + Main.debug("ERROR! Group " + group.name + " was not setup correctly!"); + } + } + } + public static class RTPPermConfiguration { + + boolean valid; + String name; + List worlds = new ArrayList<>(); + + RTPPermConfiguration(Map.Entry fields) { + String group = fields.getKey().toString(); + Object value = fields.getValue(); + for (Object worlds : ((ArrayList) value)) { + for (Object hash : ((HashMap) worlds).entrySet()) { + RTPPermConfigurationWorld worldConfig = new RTPPermConfigurationWorld(hash, group); + if (worldConfig.isValid()) + this.worlds.add(worldConfig); + else + Main.debug("ERROR! Group " + group + " world " + worldConfig.name + " was not setup correctly!"); + } + } + this.name = group; + valid = worlds.size() > 0 && group != null; + } + + boolean isValid() { + return valid; + } + } + + public static class RTPPermConfigurationWorld { + + boolean valid = true; + + int maxRad = -1; + int minRad = -1; + int price = -1; + String name; + + RTPPermConfigurationWorld(Object hash, String group) { + Map.Entry world = (Map.Entry) hash; + this.name = world.getKey().toString(); + //Main.getInstance().getLogger().info("World added to '" + group +"': '" + world.getKey() + "'"); + for (Object hash2 : ((HashMap) world.getValue()).entrySet()) { + Map.Entry hash3 = (Map.Entry) hash2; + String field = hash3.getKey().toString(); + if (field.equalsIgnoreCase("MaxRadius")) { //MaxRadius + maxRad = getInt(hash3.getValue().toString()); + } else if (field.equalsIgnoreCase("MinRadius")) { //MinRadius + minRad = getInt(hash3.getValue().toString()); + } else if (field.equalsIgnoreCase("Price")) { //MinRadius + price = getInt(hash3.getValue().toString()); + } + } + //Main.getInstance().getLogger().info("World MaxRad '" + world.getKey() + "' is " + maxRad); + //Main.getInstance().getLogger().info("World MinRad '" + world.getKey() + "' is " + minRad); + valid = this.name != null && (minRad != -1 || maxRad != -1); + } + + private int getInt(String input) { + return Integer.parseInt(input); + } + + boolean isValid() { + return valid; + } } } diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/references/Permissions.java b/src/main/java/me/SuperRonanCraft/BetterRTP/references/Permissions.java index ace75bb..a94c8c7 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/references/Permissions.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/references/Permissions.java @@ -87,6 +87,10 @@ public class Permissions { return perm(pre + "edit", sendi); } + public boolean getConfig(CommandSender sendi, String group) { + return perm(pre + "config." + group, sendi); + } + private boolean perm(String str, CommandSender sendi) { return depPerms.hasPerm(str, sendi); } diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/references/worlds/WorldPlayer.java b/src/main/java/me/SuperRonanCraft/BetterRTP/references/worlds/WorldPlayer.java index e88c9c8..da4e353 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/references/worlds/WorldPlayer.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/references/worlds/WorldPlayer.java @@ -47,7 +47,9 @@ public class WorldPlayer implements RTPWorld { World world = getWorld(); if (getUseWorldborder()) { WorldBorder border = world.getWorldBorder(); - borderRad = (int) border.getSize() / 2; + int _borderRad = (int) border.getSize() / 2; + if (borderRad > _borderRad) + borderRad = _borderRad; CenterX = border.getCenter().getBlockX(); CenterZ = border.getCenter().getBlockZ(); } @@ -138,15 +140,16 @@ public class WorldPlayer implements RTPWorld { CenterZ = z; } - private void setMaxRad(int max) { + //Modifiable + public void setMaxRad(int max) { maxBorderRad = max; } - private void setMinRad(int min) { + public void setMinRad(int min) { minBorderRad = min; } - private void setPrice(int price) { + public void setPrice(int price) { this.price = price; } @@ -154,6 +157,7 @@ public class WorldPlayer implements RTPWorld { this.attempts++; } + // private void setBiomes(List biomes) { this.Biomes = biomes; } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index bd472e5..7122dcf 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -42,7 +42,7 @@ Default: Biomes: [] MaxRadius: 1000 MinRadius: 10 - ## If "UseWorldBorder" is set to true above, these values WILL be ignored! Except Biomes! # + ## If "UseWorldBorder" is set to true above, Center X and Z will be ignored! # CenterX: 0 CenterZ: 0 @@ -102,13 +102,17 @@ PermissionConfigs: #Player requires "betterrtp.config." to trigger t - Build_World: #World named "Build_World" MaxRadius: 10000 MinRadius: 1000 + Price: 100 - Survival_World: MaxRadius: 5000 MinRadius: 1000 + Price: 10 - vip2: - Build_World: MaxRadius: 25000 MinRadius: 10000 + Price: 15 - Survival_World: MaxRadius: 15000 - MinRadius: 1000 \ No newline at end of file + MinRadius: 1000 + Price: 20 \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 8f75052..bd154c8 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ main: me.SuperRonanCraft.BetterRTP.Main -version: '2.13.1' +version: '2.13.2' name: BetterRTP author: SuperRonanCraft softdepend: [Vault, WorldGuard, GriefPrevention, Towny, Factions, RedProtect]