From bf626559251a7f2f6c820e391918147ab5a3ea41 Mon Sep 17 00:00:00 2001 From: SuperRonanCraft Date: Wed, 22 Jul 2020 17:59:37 -0400 Subject: [PATCH] Full Cave support - 2.11.0 --- .../SuperRonanCraft/BetterRTP/player/RTP.java | 158 ++++++++++++------ .../player/commands/types/CmdHelp.java | 2 + .../player/commands/types/CmdInfo.java | 17 +- .../references/settings/Settings.java | 6 + .../references/worlds/RTP_WORLD_TYPE.java | 5 +- src/main/resources/config.yml | 9 +- src/main/resources/plugin.yml | 4 +- 7 files changed, 133 insertions(+), 68 deletions(-) diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/player/RTP.java b/src/main/java/me/SuperRonanCraft/BetterRTP/player/RTP.java index fa7447e..557d450 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/player/RTP.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/player/RTP.java @@ -25,12 +25,12 @@ public class RTP { //Cache public HashMap customWorlds = new HashMap<>(); public HashMap overriden = new HashMap<>(); - public me.SuperRonanCraft.BetterRTP.references.worlds.Default Default = new Default(); + public Default Default = new Default(); private Random rn = new Random(); private List disabledWorlds, blockList; private int maxAttempts, delayTime; private boolean cancelOnMove; - private HashMap world_type = new HashMap<>(); + public HashMap world_type = new HashMap<>(); public RTP(Main pl) { this.pl = pl; @@ -44,26 +44,66 @@ public class RTP { delayTime = config.getInt("Settings.Delay.Time"); cancelOnMove = config.getBoolean("Settings.Delay.CancelOnMove"); blockList = config.getStringList("BlacklistedBlocks"); + //OVER-RIDES try { - for (String s : config.getConfigurationSection("Override").getKeys(false)) - overriden.put(s, config.getString("Override." + s)); + overriden.clear(); + List> override_map = config.getMapList("Overrides"); + for (Map m : override_map) + for (Map.Entry entry : m.entrySet()) { + overriden.put(entry.getKey().toString(), entry.getValue().toString()); + if (pl.getSettings().debug) + pl.getLogger().info("- Override '" + entry.getKey() + "' -> '" + entry.getValue() + "' added"); + } + //for (String s : config.getConfigurationSection("Override").getKeys(false)) + // overriden.put(s, config.getString("Override." + s)); } catch (Exception e) { //No Overrides } - customWorlds.clear(); - List> map = config.getMapList("CustomWorlds"); - - //Find Custom World and cache values - for (Map m : map) - for (Map.Entry entry : m.entrySet()) - customWorlds.put(entry.getKey().toString(), new Custom(entry.getKey().toString())); + //CUSTOM WORLDS try { + customWorlds.clear(); + List> map = config.getMapList("CustomWorlds"); + for (Map m : map) + for (Map.Entry entry : m.entrySet()) { + customWorlds.put(entry.getKey().toString(), new Custom(entry.getKey().toString())); + if (pl.getSettings().debug) + pl.getLogger().info("- Custom World '" + entry.getKey() + "' registered"); + } + } catch (Exception e) { + //No Custom Worlds + } + + try { + world_type.clear(); + for (World world : Bukkit.getWorlds()) + world_type.put(world.getName(), RTP_WORLD_TYPE.NORMAL); List> world_map = config.getMapList("WorldType"); for (Map m : world_map) - for (Map.Entry entry : m.entrySet()) - world_type.put(entry.getKey().toString(), RTP_WORLD_TYPE.valueOf(entry.getKey().toString())); + for (Map.Entry entry : m.entrySet()) { + if (world_type.containsKey(entry.getKey())) { + try { + RTP_WORLD_TYPE type = RTP_WORLD_TYPE.valueOf(entry.getValue().toString().toUpperCase()); + world_type.put(entry.getKey().toString(), type); + } catch(IllegalArgumentException e) { + StringBuilder valids = new StringBuilder(); + for (RTP_WORLD_TYPE type : RTP_WORLD_TYPE.values()) + valids.append(type.name()).append(", "); + valids.replace(valids.length() - 2, valids.length(), ""); + pl.getLogger().severe("World Type for '" + entry.getKey() + "' is INVALID '" + entry.getValue() + + "'. Valid ID's are: " + valids.toString()); + //Wrong rtp world type + } + }/* else { + if (pl.getSettings().debug) + pl.getLogger().info("- World Type failed for '" + entry.getKey() + "' is it loaded?"); + }*/ + } + if (pl.getSettings().debug) + for (String world : world_type.keySet()) + pl.getLogger().info("- World Type for '" + world + "' set to '" + world_type.get(world) + "'"); } catch (Exception e) { + e.printStackTrace(); //No World Types } } @@ -184,7 +224,7 @@ public class RTP { p.playSound(p.getLocation(), sound, 1F, 1F); } - // Compressed code for MaxAttempts being meet + // Compressed code for MaxAttempts being met private void metMax(CommandSender sendi, Player p, int price) { if (p == sendi) pl.getText().getFailedNotSafe(sendi, maxAttempts); @@ -194,12 +234,13 @@ public class RTP { pl.getEco().unCharge(p, price); } + //Get a random location depending the world type private Location randomLoc(PlayerWorld pWorld) { int borderRad = pWorld.getMaxRad(); int minVal = pWorld.getMinRad(); int CenterX = pWorld.getCenterX(); int CenterZ = pWorld.getCenterZ(); - int posOrNeg = rn.nextInt(4); + int quadrant = rn.nextInt(4); Player p = pWorld.getPlayer(); World world = Bukkit.getWorld(pWorld.getWorld()); if (pWorld.getUseWorldborder()) { @@ -209,10 +250,10 @@ public class RTP { CenterZ = border.getCenter().getBlockZ(); } float yaw = p.getLocation().getYaw(), pitch = p.getLocation().getPitch(); - boolean normal; - try { + RTP_WORLD_TYPE world_type = RTP_WORLD_TYPE.NORMAL; //World rtp type + /*try { //1.13+ - normal = !world.getBiome(0, 0).equals(Biome.valueOf("NETHER")); + normal = !world.getBiome(0, 0).equals(Biome.valueOf("NETHER"))); } catch (Exception e) { //1.8-1.12 try { @@ -220,28 +261,33 @@ public class RTP { } catch (Exception e1) { normal = true; } - } + }*/ + if (this.world_type.containsKey(world.getName())) + world_type = this.world_type.get(world.getName()); for (int i = 0; i <= maxAttempts; i++) { // Get the y-coords from up top, then check if it's SAFE! - Location loc; + Location loc = null; if (borderRad <= minVal) { minVal = Default.getMinRad(); if (borderRad <= minVal) minVal = 0; } - if (normal) - loc = normal(borderRad, minVal, CenterX, CenterZ, posOrNeg, world, pWorld, yaw, pitch); - else - loc = nether(borderRad, minVal, CenterX, CenterZ, posOrNeg, world, pWorld, yaw, pitch); + switch (world_type) { + case NETHER: + loc = nether(borderRad, minVal, CenterX, CenterZ, quadrant, world, pWorld, yaw, pitch); break; + default: + loc = normal(borderRad, minVal, CenterX, CenterZ, quadrant, world, pWorld, yaw, pitch); + } pWorld.addAttempt(); if (loc != null && checkDepends(loc)) return loc; - posOrNeg = rn.nextInt(4); + quadrant = rn.nextInt(4); } return null; } - private Location normal(int borderRad, int minVal, int CenterX, int CenterZ, int posOrNeg, World world, + //NORMAL + private Location normal(int borderRad, int minVal, int CenterX, int CenterZ, int quadrant, World world, PlayerWorld pWorld, Float yaw, Float pitch) { int x, x2, z, z2; Location loc; @@ -253,18 +299,16 @@ public class RTP { // up for choosing up next x = rn.nextInt(borderRad - minVal) + CenterX + minVal; x2 = -rn.nextInt(borderRad - minVal) + CenterX - minVal; - if (posOrNeg == 0) - // Positive X and Z - loc = getLocAtNormal(x, z, world, yaw, pitch, pWorld); - else if (posOrNeg == 1) - // Negative X and Z - loc = getLocAtNormal(x2, z2, world, yaw, pitch, pWorld); - else if (posOrNeg == 2) - // Negative X and Positive Z - loc = getLocAtNormal(x2, z, world, yaw, pitch, pWorld); - else - // Positive X and Negative Z - loc = getLocAtNormal(x, z2, world, yaw, pitch, pWorld); + switch (quadrant) { + case 0: // Positive X and Z + loc = getLocAtNormal(x, z, world, yaw, pitch, pWorld); break; + case 1: // Negative X and Z + loc = getLocAtNormal(x2, z2, world, yaw, pitch, pWorld); break; + case 2: // Negative X and Positive Z + loc = getLocAtNormal(x2, z, world, yaw, pitch, pWorld); break; + default: // Positive X and Negative Z + loc = getLocAtNormal(x, z2, world, yaw, pitch, pWorld); + } return loc; } @@ -277,12 +321,13 @@ public class RTP { b = world.getBlockAt(x, y - 1, z); } //System.out.println(b.getType().isSolid() + " " + b.getType().name()); - if (!badBlock(b.getType().name(), x, z, pWorld.getWorld(), pWorld.getBiomes())) + if (b.getY() > 0 && !badBlock(b.getType().name(), x, z, pWorld.getWorld(), pWorld.getBiomes())) return new Location(world, (x + 0.5), b.getY() + 1, (z + 0.5), yaw, pitch); return null; } - private Location nether(int borderRad, int minVal, int CenterX, int CenterZ, int posOrNeg, World world, + //NETHER + private Location nether(int borderRad, int minVal, int CenterX, int CenterZ, int quadrant, World world, PlayerWorld pWorld, Float yaw, Float pitch) { int x, x2, z, z2; Location loc; @@ -294,28 +339,33 @@ public class RTP { // up for choosing up next x = rn.nextInt(borderRad - minVal) + CenterX + minVal; x2 = -rn.nextInt(borderRad - minVal) + CenterX - minVal; - if (posOrNeg == 0) - // Positive X and Z - loc = getLocAtNether(x, z, world, yaw, pitch, pWorld); - else if (posOrNeg == 1) - // Negative X and Z - loc = getLocAtNether(x2, z2, world, yaw, pitch, pWorld); - else if (posOrNeg == 2) - // Negative X and Positive Z - loc = getLocAtNether(x2, z, world, yaw, pitch, pWorld); - else - // Positive X and Negative Z - loc = getLocAtNether(x, z2, world, yaw, pitch, pWorld); + switch (quadrant) { + case 0: // Positive X and Z + loc = getLocAtNether(x, z, world, yaw, pitch, pWorld); break; + case 1: // Negative X and Z + loc = getLocAtNether(x2, z2, world, yaw, pitch, pWorld); break; + case 2: // Negative X and Positive Z + loc = getLocAtNether(x2, z, world, yaw, pitch, pWorld); break; + default: // Positive X and Negative Z + loc = getLocAtNether(x, z2, world, yaw, pitch, pWorld); + } return loc; } private Location getLocAtNether(int x, int z, World world, Float yaw, Float pitch, PlayerWorld pWorld) { - for (int y = 0; y < world.getMaxHeight(); y++) - if (world.getBlockAt(x, y, z).getType().equals(Material.AIR)) { + for (int y = 0; y < world.getMaxHeight(); y++) { + Block b = world.getBlockAt(x, y, z); + if (b.getType().equals(Material.AIR) || !b.getType().isSolid()) { String block = world.getBlockAt(x, y - 1, z).getType().name(); + if (!b.getType().isSolid()) { //Block is not a solid (ex: lava, water...) + String block_in = b.getType().name(); + if (badBlock(block_in, x, z, pWorld.getWorld(), pWorld.getBiomes())) + return null; + } if (!badBlock(block, x, z, pWorld.getWorld(), pWorld.getBiomes())) return new Location(world, (x + 0.5), y, (z + 0.5), yaw, pitch); } + } return null; } diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/player/commands/types/CmdHelp.java b/src/main/java/me/SuperRonanCraft/BetterRTP/player/commands/types/CmdHelp.java index 9144d9d..9c774b8 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/player/commands/types/CmdHelp.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/player/commands/types/CmdHelp.java @@ -21,6 +21,8 @@ public class CmdHelp implements RTPCommand { pl.getText().getHelpWorld(sendi, label); if (pl.getPerms().getReload(sendi)) pl.getText().getHelpReload(sendi, label); + //if (pl.getPerms().getInfo(sendi)) + // pl.getText().getHelpInfo(sendi); } public List tabComplete(CommandSender sendi, String[] args) { diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/player/commands/types/CmdInfo.java b/src/main/java/me/SuperRonanCraft/BetterRTP/player/commands/types/CmdInfo.java index 42e17f2..6d830c1 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/player/commands/types/CmdInfo.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/player/commands/types/CmdInfo.java @@ -3,6 +3,7 @@ package me.SuperRonanCraft.BetterRTP.player.commands.types; import me.SuperRonanCraft.BetterRTP.Main; import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommand; import me.SuperRonanCraft.BetterRTP.references.worlds.RTPWorld; +import me.SuperRonanCraft.BetterRTP.references.worlds.RTP_WORLD_TYPE; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.WorldBorder; @@ -15,25 +16,27 @@ public class CmdInfo implements RTPCommand { public void execute(CommandSender sendi, String label, String[] args) { List info = new ArrayList<>(); - info.add("&6BetterRTP Info"); + info.add("&e&m-----&6 BetterRTP Info &e&m-----"); + Main pl = Main.getInstance(); for (World w : Bukkit.getWorlds()) { info.add("&aWorld: &7" + w.getName()); - if (Main.getInstance().getRTP().getDisabledWorlds().contains(w.getName())) //DISABLED + if (pl.getRTP().getDisabledWorlds().contains(w.getName())) //DISABLED info.add("&7- &6Disabled: &bTrue"); else { info.add("&7- &6Disabled: &cFalse"); - if (Main.getInstance().getRTP().overriden.containsKey(w.getName())) + if (pl.getRTP().overriden.containsKey(w.getName())) info.add("&7- &6Overriden: &bTrue"); else { + info.add("&7- &7WorldType: " + pl.getRTP().world_type.getOrDefault(w.getName(), RTP_WORLD_TYPE.NORMAL).name()); info.add("&7- &6Overriden: &cFalse"); - RTPWorld _rtpworld = Main.getInstance().getRTP().Default; - for (RTPWorld __rtpworld : Main.getInstance().getRTP().customWorlds.values()) { + RTPWorld _rtpworld = pl.getRTP().Default; + for (RTPWorld __rtpworld : pl.getRTP().customWorlds.values()) { if (__rtpworld.getWorld().equals(w.getName())) { _rtpworld = __rtpworld; break; } } - if (_rtpworld == Main.getInstance().getRTP().Default) + if (_rtpworld == pl.getRTP().Default) info.add("&7- &6Custom: &cFalse"); else info.add("&7- &6Custom: &bTrue"); @@ -54,7 +57,7 @@ public class CmdInfo implements RTPCommand { } } info.forEach(str -> - info.set(info.indexOf(str), Main.getInstance().getText().color(str))); + info.set(info.indexOf(str), pl.getText().color(str))); sendi.sendMessage(info.toArray(new String[0])); } diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/references/settings/Settings.java b/src/main/java/me/SuperRonanCraft/BetterRTP/references/settings/Settings.java index bce23b1..e84e0dc 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/references/settings/Settings.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/references/settings/Settings.java @@ -1,11 +1,17 @@ package me.SuperRonanCraft.BetterRTP.references.settings; +import me.SuperRonanCraft.BetterRTP.Main; +import me.SuperRonanCraft.BetterRTP.references.file.FileBasics; + public class Settings { + public boolean debug = false; + private SoftDepends depends = new SoftDepends(); public void load() { //Load Settings depends.load(); + debug = Main.getInstance().getFiles().getType(FileBasics.FILETYPE.CONFIG).getBoolean("Settings.Debugger"); } public SoftDepends getsDepends() { diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/references/worlds/RTP_WORLD_TYPE.java b/src/main/java/me/SuperRonanCraft/BetterRTP/references/worlds/RTP_WORLD_TYPE.java index fc08461..76427ce 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/references/worlds/RTP_WORLD_TYPE.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/references/worlds/RTP_WORLD_TYPE.java @@ -1,7 +1,6 @@ package me.SuperRonanCraft.BetterRTP.references.worlds; public enum RTP_WORLD_TYPE { - NORMAL, //Default - NETHER, //Nether world has different conditions - //END //End world type, not supported yet + NORMAL, //Normal world type finds the tallest safe block + NETHER //Nether world types finds the lowest safe block } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 3a209c5..452b2cf 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -4,6 +4,8 @@ Language-File: 'en.yml' Settings: + ## Output to console some debugging info + Debugger: false ## Respect WorldGuard areas # IN-PROGRESS RespectWorldGuard: false ## Respect GriefPrevention areas # COMING SOON @@ -24,9 +26,10 @@ Settings: CancelOnMove: true DisableUpdater: false -WorldType: # Available types are NETHER, NORMAL +WorldType: # Available types are NORMAL, NETHER and END - world: NORMAL - world_nether: NETHER + - world_the_end: NORMAL Default: UseWorldBorder: true @@ -44,7 +47,9 @@ BlacklistedBlocks: - stationary_water - stationary_lava - water + - flowing_water - lava + - flowing_lava - cactus - leaves - leaves_2 @@ -77,7 +82,7 @@ CustomWorlds: - 'forest' ## Override a world and rtp a player executing the command in one world, to another -Override: +Overrides: #FORMAT : - world_nether: 'world' - creative: 'world' diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 44dcb4d..e53bfa3 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,9 +1,9 @@ main: me.SuperRonanCraft.BetterRTP.Main -version: 2.10.0 +version: 2.11.0 name: BetterRTP author: SuperRonanCraft softdepend: [Vault, WorldGuard, GriefPrevention, Factions] -api-version: 1.13 +api-version: '1.13' commands: betterrtp: