Permission config (framework)

This commit is contained in:
SuperRonanCraft 2020-09-23 11:59:53 -04:00
parent afcb76bfd7
commit 82cba7cef6
9 changed files with 54 additions and 42 deletions

View File

@ -4,7 +4,7 @@ import me.SuperRonanCraft.BetterRTP.Main;
import me.SuperRonanCraft.BetterRTP.player.rtp.RTPParticles; import me.SuperRonanCraft.BetterRTP.player.rtp.RTPParticles;
import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommand; import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommand;
import me.SuperRonanCraft.BetterRTP.references.worlds.RTPWorld; import me.SuperRonanCraft.BetterRTP.references.worlds.RTPWorld;
import me.SuperRonanCraft.BetterRTP.references.worlds.RTP_WORLD_TYPE; import me.SuperRonanCraft.BetterRTP.references.worlds.WORLD_TYPE;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.WorldBorder; import org.bukkit.WorldBorder;
@ -103,7 +103,7 @@ public class CmdInfo implements RTPCommand {
if (pl.getRTP().overriden.containsKey(w.getName())) if (pl.getRTP().overriden.containsKey(w.getName()))
info.add("&7- &6Overriden: &bTrue"); info.add("&7- &6Overriden: &bTrue");
else { else {
info.add("&7- &6WorldType: &f" + pl.getRTP().world_type.getOrDefault(w.getName(), RTP_WORLD_TYPE.NORMAL).name()); info.add("&7- &6WorldType: &f" + pl.getRTP().world_type.getOrDefault(w.getName(), WORLD_TYPE.NORMAL).name());
info.add("&7- &6Overriden: &cFalse"); info.add("&7- &6Overriden: &cFalse");
RTPWorld _rtpworld = pl.getRTP().defaultWorld; RTPWorld _rtpworld = pl.getRTP().defaultWorld;
for (RTPWorld __rtpworld : pl.getRTP().customWorlds.values()) { for (RTPWorld __rtpworld : pl.getRTP().customWorlds.values()) {

View File

@ -24,11 +24,11 @@ public class RTP {
//Cache //Cache
public HashMap<String, RTPWorld> customWorlds = new HashMap<>(); public HashMap<String, RTPWorld> customWorlds = new HashMap<>();
public HashMap<String, String> overriden = new HashMap<>(); public HashMap<String, String> overriden = new HashMap<>();
public Default defaultWorld = new Default(); public WorldDefault defaultWorld = new WorldDefault();
private List<String> disabledWorlds, blockList; private List<String> disabledWorlds, blockList;
private int maxAttempts, delayTime; private int maxAttempts, delayTime;
private boolean cancelOnMove, cancelOnDamage; private boolean cancelOnMove, cancelOnDamage;
public HashMap<String, RTP_WORLD_TYPE> world_type = new HashMap<>(); public HashMap<String, WORLD_TYPE> world_type = new HashMap<>();
public RTPTeleport getTeleport() { public RTPTeleport getTeleport() {
return teleport; return teleport;
@ -59,17 +59,17 @@ public class RTP {
try { try {
world_type.clear(); world_type.clear();
for (World world : Bukkit.getWorlds()) for (World world : Bukkit.getWorlds())
world_type.put(world.getName(), RTP_WORLD_TYPE.NORMAL); world_type.put(world.getName(), WORLD_TYPE.NORMAL);
List<Map<?, ?>> world_map = config.getMapList("WorldType"); List<Map<?, ?>> world_map = config.getMapList("WorldType");
for (Map<?, ?> m : world_map) for (Map<?, ?> m : world_map)
for (Map.Entry<?, ?> entry : m.entrySet()) { for (Map.Entry<?, ?> entry : m.entrySet()) {
if (world_type.containsKey(entry.getKey())) { if (world_type.containsKey(entry.getKey())) {
try { try {
RTP_WORLD_TYPE type = RTP_WORLD_TYPE.valueOf(entry.getValue().toString().toUpperCase()); WORLD_TYPE type = WORLD_TYPE.valueOf(entry.getValue().toString().toUpperCase());
world_type.put(entry.getKey().toString(), type); world_type.put(entry.getKey().toString(), type);
} catch(IllegalArgumentException e) { } catch(IllegalArgumentException e) {
StringBuilder valids = new StringBuilder(); StringBuilder valids = new StringBuilder();
for (RTP_WORLD_TYPE type : RTP_WORLD_TYPE.values()) for (WORLD_TYPE type : WORLD_TYPE.values())
valids.append(type.name()).append(", "); valids.append(type.name()).append(", ");
valids.replace(valids.length() - 2, valids.length(), ""); valids.replace(valids.length() - 2, valids.length(), "");
getPl().getLogger().severe("World Type for '" + entry.getKey() + "' is INVALID '" + entry.getValue() + getPl().getLogger().severe("World Type for '" + entry.getKey() + "' is INVALID '" + entry.getValue() +
@ -103,7 +103,7 @@ public class RTP {
List<Map<?, ?>> map = config.getMapList("CustomWorlds"); List<Map<?, ?>> map = config.getMapList("CustomWorlds");
for (Map<?, ?> m : map) for (Map<?, ?> m : map)
for (Map.Entry<?, ?> entry : m.entrySet()) { for (Map.Entry<?, ?> entry : m.entrySet()) {
customWorlds.put(entry.getKey().toString(), new Custom(entry.getKey().toString())); customWorlds.put(entry.getKey().toString(), new WorldCustom(entry.getKey().toString()));
if (getPl().getSettings().debug) if (getPl().getSettings().debug)
getPl().getLogger().info("- Custom World '" + entry.getKey() + "' registered"); getPl().getLogger().info("- Custom World '" + entry.getKey() + "' registered");
} }
@ -144,7 +144,7 @@ public class RTP {
getPl().getCmd().cooldowns.remove(p.getUniqueId()); getPl().getCmd().cooldowns.remove(p.getUniqueId());
return; return;
} }
PlayerWorld pWorld = new PlayerWorld(p, Bukkit.getWorld(worldName)); WorldPlayer pWorld = new WorldPlayer(p, Bukkit.getWorld(worldName));
// Set all methods // Set all methods
if (customWorlds.containsKey(worldName)) { if (customWorlds.containsKey(worldName)) {
RTPWorld cWorld = customWorlds.get(pWorld.getWorld().getName()); RTPWorld cWorld = customWorlds.get(pWorld.getWorld().getName());
@ -152,7 +152,7 @@ public class RTP {
} else } else
pWorld.setup(defaultWorld, defaultWorld.getPrice(), biomes); pWorld.setup(defaultWorld, defaultWorld.getPrice(), biomes);
//World type //World type
RTP_WORLD_TYPE world_type = RTP_WORLD_TYPE.NORMAL; //World rtp type WORLD_TYPE world_type = WORLD_TYPE.NORMAL; //World rtp type
if (this.world_type.containsKey(worldName)) if (this.world_type.containsKey(worldName))
world_type = this.world_type.get(worldName); world_type = this.world_type.get(worldName);
pWorld.setWorldtype(world_type); pWorld.setWorldtype(world_type);
@ -171,7 +171,7 @@ public class RTP {
} }
} }
void findSafeLocation(CommandSender sendi, PlayerWorld pWorld) { void findSafeLocation(CommandSender sendi, WorldPlayer pWorld) {
if (pWorld.getAttempts() >= maxAttempts) //Cancel out, too many tried if (pWorld.getAttempts() >= maxAttempts) //Cancel out, too many tried
metMax(sendi, pWorld.getPlayer(), pWorld.getPrice()); metMax(sendi, pWorld.getPlayer(), pWorld.getPrice());
else { //Try again to find a safe location else { //Try again to find a safe location
@ -207,7 +207,7 @@ public class RTP {
getPl().getCmd().rtping.put(p.getUniqueId(), false); getPl().getCmd().rtping.put(p.getUniqueId(), false);
} }
private Location getLocAtNormal(int x, int z, World world, Float yaw, Float pitch, PlayerWorld pWorld) { private Location getLocAtNormal(int x, int z, World world, Float yaw, Float pitch, WorldPlayer pWorld) {
Block b = world.getHighestBlockAt(x, z); Block b = world.getHighestBlockAt(x, z);
if (b.getType().toString().endsWith("AIR")) //1.15.1 or less if (b.getType().toString().endsWith("AIR")) //1.15.1 or less
b = world.getBlockAt(x, b.getY() - 1, z); b = world.getBlockAt(x, b.getY() - 1, z);
@ -224,7 +224,7 @@ public class RTP {
return null; return null;
} }
private Location getLocAtNether(int x, int z, World world, Float yaw, Float pitch, PlayerWorld pWorld) { private Location getLocAtNether(int x, int z, World world, Float yaw, Float pitch, WorldPlayer pWorld) {
//System.out.println("-----------"); //System.out.println("-----------");
for (int y = 1; y < world.getMaxHeight(); y++) { for (int y = 1; y < world.getMaxHeight(); y++) {
// System.out.println("--"); // System.out.println("--");

View File

@ -1,6 +1,6 @@
package me.SuperRonanCraft.BetterRTP.player.rtp; package me.SuperRonanCraft.BetterRTP.player.rtp;
import me.SuperRonanCraft.BetterRTP.references.worlds.PlayerWorld; import me.SuperRonanCraft.BetterRTP.references.worlds.WorldPlayer;
import me.SuperRonanCraft.BetterRTP.Main; import me.SuperRonanCraft.BetterRTP.Main;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -13,10 +13,10 @@ import org.bukkit.event.player.PlayerMoveEvent;
class RTPDelay implements Listener { class RTPDelay implements Listener {
private int run; private int run;
private final PlayerWorld pWorld; private final WorldPlayer pWorld;
private final boolean cancelOnMove, cancelOnDamage; private final boolean cancelOnMove, cancelOnDamage;
RTPDelay(CommandSender sendi, PlayerWorld pWorld, int delay, boolean cancelOnMove, boolean cancelOnDamage) { RTPDelay(CommandSender sendi, WorldPlayer pWorld, int delay, boolean cancelOnMove, boolean cancelOnDamage) {
this.pWorld = pWorld; this.pWorld = pWorld;
this.cancelOnMove = cancelOnMove; this.cancelOnMove = cancelOnMove;
this.cancelOnDamage = cancelOnDamage; this.cancelOnDamage = cancelOnDamage;

View File

@ -0,0 +1,12 @@
package me.SuperRonanCraft.BetterRTP.player.rtp;
import java.util.ArrayList;
import java.util.List;
public class RTPPermConfigs {
private List<String> groups = new ArrayList<>();
public void load() {
}
}

View File

@ -1,6 +1,6 @@
package me.SuperRonanCraft.BetterRTP.references.worlds; package me.SuperRonanCraft.BetterRTP.references.worlds;
public enum RTP_WORLD_TYPE { public enum WORLD_TYPE {
NORMAL, //Normal world type finds the tallest safe block NORMAL, //Normal world type finds the tallest safe block
NETHER //Nether world types finds the lowest safe block NETHER //Nether world types finds the lowest safe block
} }

View File

@ -9,13 +9,13 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class Custom implements RTPWorld { public class WorldCustom implements RTPWorld {
public String world, world_type; public String world;
private boolean useWorldborder = false; private boolean useWorldborder = false;
private int CenterX, CenterZ, maxBorderRad, minBorderRad, price; private int CenterX, CenterZ, maxBorderRad, minBorderRad, price;
private List<String> Biomes; private List<String> Biomes;
public Custom(String world) { public WorldCustom(String world) {
String pre = "CustomWorlds."; String pre = "CustomWorlds.";
FileBasics.FILETYPE config = Main.getInstance().getFiles().getType(FileBasics.FILETYPE.CONFIG); FileBasics.FILETYPE config = Main.getInstance().getFiles().getType(FileBasics.FILETYPE.CONFIG);
List<Map<?, ?>> map = config.getMapList("CustomWorlds"); List<Map<?, ?>> map = config.getMapList("CustomWorlds");

View File

@ -9,7 +9,7 @@ import org.bukkit.World;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
public class Default implements RTPWorld { public class WorldDefault implements RTPWorld {
private boolean useWorldborder; private boolean useWorldborder;
private int CenterX, CenterZ, maxBorderRad, minBorderRad, price; private int CenterX, CenterZ, maxBorderRad, minBorderRad, price;
private List<String> Biomes; private List<String> Biomes;

View File

@ -9,15 +9,15 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
public class PlayerWorld implements RTPWorld { public class WorldPlayer implements RTPWorld {
private boolean useWorldborder; private boolean useWorldborder;
private int CenterX, CenterZ, maxBorderRad, minBorderRad, price, attempts; private int CenterX, CenterZ, maxBorderRad, minBorderRad, price, attempts;
private List<String> Biomes; private List<String> Biomes;
private final Player p; private final Player p;
private final World world; private final World world;
private RTP_WORLD_TYPE world_type; private WORLD_TYPE world_type;
public PlayerWorld(Player p, World world) { public WorldPlayer(Player p, World world) {
this.p = p; this.p = p;
this.world = world; this.world = world;
} }
@ -39,7 +39,7 @@ public class PlayerWorld implements RTPWorld {
return p; return p;
} }
public Location generateRandomXZ(Default defaultWorld) { public Location generateRandomXZ(WorldDefault defaultWorld) {
int borderRad = getMaxRad(); int borderRad = getMaxRad();
int minVal = getMinRad(); int minVal = getMinRad();
int CenterX = getCenterX(); int CenterX = getCenterX();
@ -159,11 +159,11 @@ public class PlayerWorld implements RTPWorld {
} }
//Custom World type //Custom World type
public void setWorldtype(RTP_WORLD_TYPE type) { public void setWorldtype(WORLD_TYPE type) {
this.world_type = type; this.world_type = type;
} }
public RTP_WORLD_TYPE getWorldtype() { public WORLD_TYPE getWorldtype() {
return this.world_type; return this.world_type;
} }
} }

View File

@ -97,18 +97,18 @@ WorldType: # Available types are NORMAL, NETHER
- world_nether: NETHER - world_nether: NETHER
- world_the_end: NORMAL - world_the_end: NORMAL
#PermissionConfigs: #Player requires "betterrtp.config.<world_name>" to trigger these configs PermissionConfigs: #Player requires "betterrtp.config.<world_name>" to trigger these configs
#- vip: #betterrtp.config.vip - vip: #betterrtp.config.vip
# - Build_World: #World named "Build_World" - Build_World: #World named "Build_World"
# MaxRadius: 10000 MaxRadius: 10000
# MinRadius: 1000 MinRadius: 1000
# - Survival_World: - Survival_World:
# MaxRadius: 5000 MaxRadius: 5000
# MinRadius: 1000 MinRadius: 1000
#- vip2: - vip2:
# - Build_World: - Build_World:
# MaxRadius: 25000 MaxRadius: 25000
# MinRadius: 10000 MinRadius: 10000
# - Survival_World: - Survival_World:
# MaxRadius: 15000 MaxRadius: 15000
# MinRadius: 1000 MinRadius: 1000