mirror of
https://github.com/RonanPlugins/BetterRTP.git
synced 2025-08-17 00:55:45 +00:00
permission groups total recode
This commit is contained in:
parent
8fc4824190
commit
c91226266d
@ -446,7 +446,7 @@ public class CmdEdit implements RTPCommand, RTPCommandHelpable { //Edit a worlds
|
||||
}
|
||||
|
||||
enum RTP_CMD_EDIT {
|
||||
CUSTOMWORLD, LOCATION, DEFAULT, WORLD_TYPE, OVERRIDE, BLACKLISTEDBLOCKS
|
||||
CUSTOMWORLD, /*LOCATION,*/ DEFAULT, WORLD_TYPE, OVERRIDE, BLACKLISTEDBLOCKS
|
||||
}
|
||||
|
||||
enum RTP_CMD_EDIT_SUB { //Only for World and Default
|
||||
|
@ -141,7 +141,7 @@ public class CmdInfo implements RTPCommand, RTPCommandHelpable {
|
||||
info.add("&7- &6Price&7: &f" + _rtpworld.getPrice() + getInfo(_rtpworld, worldDefault, "price"));
|
||||
info.add("&7- &eBiomes&7: &f" + _rtpworld.getBiomes().toString());
|
||||
info.add("&7- &6Shape&7: &f" + _rtpworld.getShape().toString() + getInfo(_rtpworld, worldDefault, "shape"));
|
||||
info.add("&7- &ePermission Group&7: " + (_rtpworld.getConfig() != null ? "&e" + _rtpworld.getConfig().name : "&cN/A"));
|
||||
info.add("&7- &ePermission Group&7: " + (_rtpworld.getConfig() != null ? "&e" + _rtpworld.getConfig().getGroupName() : "&cN/A"));
|
||||
}
|
||||
}
|
||||
return info;
|
||||
|
@ -5,6 +5,7 @@ import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
||||
import me.SuperRonanCraft.BetterRTP.references.customEvents.RTP_SettingUpEvent;
|
||||
import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
|
||||
import me.SuperRonanCraft.BetterRTP.references.helpers.HelperRTP;
|
||||
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.PermissionGroup;
|
||||
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
@ -17,16 +18,18 @@ public class RTP {
|
||||
|
||||
final RTPTeleport teleport = new RTPTeleport();
|
||||
final RTPPluginValidation softDepends = new RTPPluginValidation();
|
||||
public final RTPPermissionGroup permConfig = new RTPPermissionGroup();
|
||||
//public final WorldPermissionGroup permConfig = new WorldPermissionGroup();
|
||||
//Cache
|
||||
public final HashMap<String, RTPWorld> customWorlds = new HashMap<>();
|
||||
public final HashMap<String, String> overriden = new HashMap<>();
|
||||
public final WorldDefault defaultWorld = new WorldDefault();
|
||||
@Getter List<String> disabledWorlds, blockList;
|
||||
int maxAttempts, delayTime;
|
||||
boolean cancelOnMove, cancelOnDamage;
|
||||
public final HashMap<String, WORLD_TYPE> world_type = new HashMap<>();
|
||||
//Worlds
|
||||
public final HashMap<String, RTPWorld> customWorlds = new HashMap<>();
|
||||
public final HashMap<String, RTPWorld> worldLocations = new HashMap<>();
|
||||
public final HashMap<String, PermissionGroup> worldPermissionGroups = new HashMap<>();
|
||||
|
||||
public RTPTeleport getTeleport() {
|
||||
return teleport;
|
||||
@ -48,8 +51,10 @@ public class RTP {
|
||||
RTPLoader.loadWorlds(defaultWorld, customWorlds);
|
||||
//Locations
|
||||
RTPLoader.loadLocations(worldLocations);
|
||||
//Permissions
|
||||
RTPLoader.loadPermissionGroups(worldPermissionGroups);
|
||||
teleport.load(); //Load teleporting stuff
|
||||
permConfig.load(); //Load permission configs
|
||||
//permConfig.load(); //Load permission configs
|
||||
}
|
||||
|
||||
public void loadWorlds() { //Keeping this here because of the edit command
|
||||
|
@ -10,20 +10,32 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class RTPLoader {
|
||||
|
||||
static void loadWorlds(@NotNull WorldDefault defaultWorld, @NotNull HashMap<String, RTPWorld> customWorlds) {
|
||||
defaultWorld.load();
|
||||
customWorlds.clear();
|
||||
BetterRTP.debug("Loading Custom Worlds...");
|
||||
try {
|
||||
FileBasics.FILETYPE config = FileBasics.FILETYPE.CONFIG;
|
||||
List<Map<?, ?>> map = config.getMapList("CustomWorlds");
|
||||
for (Map<?, ?> m : map)
|
||||
for (Map.Entry<?, ?> entry : m.entrySet()) {
|
||||
customWorlds.put(entry.getKey().toString(), new WorldCustom(entry.getKey().toString()));
|
||||
if (getPl().getSettings().isDebug())
|
||||
BetterRTP.debug("- Custom World '" + entry.getKey() + "' registered");
|
||||
String world = entry.getKey().toString();
|
||||
customWorlds.put(world, new WorldCustom(world));
|
||||
AtomicBoolean exists = new AtomicBoolean(false);
|
||||
Bukkit.getWorlds().forEach(w -> {
|
||||
if (w.getName().equals(world))
|
||||
exists.set(true);
|
||||
});
|
||||
if (getPl().getSettings().isDebug()) {
|
||||
if (exists.get())
|
||||
BetterRTP.debug("- Custom World '" + world + "' successfully registered");
|
||||
else
|
||||
BetterRTP.debug("[WARN] - Custom World '" + world + "' registered but world does NOT exist");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
//No Custom Worlds
|
||||
@ -31,6 +43,7 @@ public class RTPLoader {
|
||||
}
|
||||
|
||||
static void loadOverrides(@NotNull HashMap<String, String> overriden) {
|
||||
BetterRTP.debug("Loading Overrides...");
|
||||
overriden.clear();
|
||||
try {
|
||||
FileBasics.FILETYPE config = FileBasics.FILETYPE.CONFIG;
|
||||
@ -49,6 +62,7 @@ public class RTPLoader {
|
||||
}
|
||||
|
||||
static void loadWorldTypes(@NotNull HashMap<String, WORLD_TYPE> world_type) {
|
||||
BetterRTP.debug("Loading World Types...");
|
||||
world_type.clear();
|
||||
try {
|
||||
FileBasics.FILETYPE config = FileBasics.FILETYPE.CONFIG;
|
||||
@ -89,6 +103,7 @@ public class RTPLoader {
|
||||
FileBasics.FILETYPE config = FileBasics.FILETYPE.LOCATIONS;
|
||||
if (!config.getBoolean("Enabled"))
|
||||
return;
|
||||
BetterRTP.debug("Loading Locations...");
|
||||
List<Map<?, ?>> map = config.getMapList("Locations");
|
||||
for (Map<?, ?> m : map)
|
||||
for (Map.Entry<?, ?> entry : m.entrySet()) {
|
||||
@ -100,6 +115,24 @@ public class RTPLoader {
|
||||
}
|
||||
}
|
||||
|
||||
static void loadPermissionGroups(@NotNull HashMap<String, RTPWorld> permissionGroup) {
|
||||
permissionGroup.clear();
|
||||
FileBasics.FILETYPE config = FileBasics.FILETYPE.CONFIG;
|
||||
if (!config.getBoolean("PermissionGroup.Enabled"))
|
||||
return;
|
||||
BetterRTP.debug("Loading Permission Groups...");
|
||||
try {
|
||||
List<Map<?, ?>> map = config.getMapList("PermissionGroup.Groups");
|
||||
for (Map<?, ?> m : map)
|
||||
for (Map.Entry<?, ?> entry : m.entrySet()) {
|
||||
String group = entry.getKey().toString();
|
||||
permissionGroup.put(group, new WorldPermissionGroup(group));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
//No Custom Worlds
|
||||
}
|
||||
}
|
||||
|
||||
private static BetterRTP getPl() {
|
||||
return BetterRTP.getInstance();
|
||||
}
|
||||
|
@ -1,117 +0,0 @@
|
||||
package me.SuperRonanCraft.BetterRTP.player.rtp;
|
||||
|
||||
import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
|
||||
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class RTPPermissionGroup {
|
||||
private final List<RTPPermConfiguration> groups = new ArrayList<>();
|
||||
|
||||
public RTPPermConfiguration getGroup(CommandSender p) {
|
||||
for (RTPPermConfiguration group : groups)
|
||||
if (BetterRTP.getInstance().getPerms().getPermissionGroup(p, group.name))
|
||||
return group;
|
||||
return null;
|
||||
}
|
||||
|
||||
public void load() {
|
||||
for (RTPPermConfiguration group : groups)
|
||||
group.worlds.clear();
|
||||
groups.clear();
|
||||
YamlConfiguration config = BetterRTP.getInstance().getFiles().getType(FileBasics.FILETYPE.CONFIG).getConfig();
|
||||
if (!config.getBoolean("PermissionGroup.Enabled")) return;
|
||||
List<Map<?, ?>> list = config.getMapList("PermissionGroup.Groups");
|
||||
for (Map<?, ?> m : list)
|
||||
for (Map.Entry<?, ?> entry : m.entrySet()) {
|
||||
RTPPermConfiguration group = new RTPPermConfiguration(entry);
|
||||
if (group.isValid()) {
|
||||
groups.add(group);
|
||||
BetterRTP.debug("- Group " + group.name + " has " + group.worlds.size() + " worlds setup, permission: 'betterrtp.group." + group.name + "'");
|
||||
for (RTPPermConfigurationWorld world : group.worlds) {
|
||||
BetterRTP.debug(" - World '" + world.name + "' MaxRad = " + world.maxRad + ", MinRad = " + world.minRad);
|
||||
}
|
||||
} else {
|
||||
BetterRTP.debug("ERROR! Group " + group.name + " was not setup correctly!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class RTPPermConfiguration {
|
||||
|
||||
boolean valid;
|
||||
public String name;
|
||||
public List<RTPPermConfigurationWorld> 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
|
||||
BetterRTP.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;
|
||||
|
||||
public int maxRad = -1;
|
||||
public int minRad = -1;
|
||||
public int price = -1;
|
||||
public int centerx = -1;
|
||||
public int centerz = -1;
|
||||
public Object useworldborder = null;
|
||||
|
||||
public 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());
|
||||
} else if (field.equalsIgnoreCase("UseWorldBorder")) { //UseWorldBorder
|
||||
useworldborder = Boolean.valueOf(hash3.getValue().toString());
|
||||
} else if (field.equalsIgnoreCase("CenterX")) { //Center X
|
||||
centerx = getInt(hash3.getValue().toString());
|
||||
} else if (field.equalsIgnoreCase("CenterZ")) { //Center Z
|
||||
centerz = 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package me.SuperRonanCraft.BetterRTP.references.rtpinfo;
|
||||
|
||||
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.WorldPermissionGroup;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class PermissionGroup {
|
||||
|
||||
String groupName;
|
||||
HashMap<String, WorldPermissionGroup> worlds = new HashMap<>();
|
||||
|
||||
public PermissionGroup(String group) {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -30,16 +30,19 @@ public interface RTPWorld_Defaulted {
|
||||
void setMaxY(int value);
|
||||
|
||||
default void setupDefaults() {
|
||||
WorldDefault worldDefault = BetterRTP.getInstance().getRTP().defaultWorld;
|
||||
setMaxRadius(worldDefault.getMaxRadius());
|
||||
setMinRadius(worldDefault.getMinRadius());
|
||||
setUseWorldBorder(worldDefault.getUseWorldborder());
|
||||
setCenterX(worldDefault.getCenterX());
|
||||
setCenterZ(worldDefault.getCenterZ());
|
||||
setPrice(worldDefault.getPrice());
|
||||
setBiomes(worldDefault.getBiomes());
|
||||
setShape(worldDefault.getShape());
|
||||
setMinY(worldDefault.getMinY());
|
||||
setMaxY(worldDefault.getMaxY());
|
||||
setAllFrom(BetterRTP.getInstance().getRTP().defaultWorld);
|
||||
}
|
||||
|
||||
default void setAllFrom(RTPWorld rtpWorld) {
|
||||
setMaxRadius(rtpWorld.getMaxRadius());
|
||||
setMinRadius(rtpWorld.getMinRadius());
|
||||
setUseWorldBorder(rtpWorld.getUseWorldborder());
|
||||
setCenterX(rtpWorld.getCenterX());
|
||||
setCenterZ(rtpWorld.getCenterZ());
|
||||
setPrice(rtpWorld.getPrice());
|
||||
setBiomes(rtpWorld.getBiomes());
|
||||
setShape(rtpWorld.getShape());
|
||||
setMinY(rtpWorld.getMinY());
|
||||
setMaxY(rtpWorld.getMaxY());
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class WorldDefault implements RTPWorld {
|
||||
private boolean useWorldborder;
|
||||
@ -19,6 +20,7 @@ public class WorldDefault implements RTPWorld {
|
||||
private RTP_SHAPE shape;
|
||||
|
||||
public void load() {
|
||||
BetterRTP.debug("Loading Defaults...");
|
||||
//Setups
|
||||
String pre = "Default";
|
||||
FileBasics.FILETYPE config = BetterRTP.getInstance().getFiles().getType(FileBasics.FILETYPE.CONFIG);
|
||||
@ -69,6 +71,18 @@ public class WorldDefault implements RTPWorld {
|
||||
maxy = 320;
|
||||
BetterRTP.getInstance().getLogger().warning("Warning! Default MaxY value is below water level (64)! Reset to default 320!");
|
||||
}
|
||||
//Debugger
|
||||
if (BetterRTP.getInstance().getSettings().isDebug()) {
|
||||
Logger log = BetterRTP.getInstance().getLogger();
|
||||
log.info("- UseWorldBorder: " + this.useWorldborder);
|
||||
log.info("- CenterX: " + this.CenterX);
|
||||
log.info("- CenterZ: " + this.CenterZ);
|
||||
log.info("- MaxRadius: " + this.maxBorderRad);
|
||||
log.info("- MinRadius: " + this.minBorderRad);
|
||||
log.info("- Price: " + this.price);
|
||||
log.info("- MinY: " + this.miny);
|
||||
log.info("- MaxY: " + this.maxy);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,315 @@
|
||||
package me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import me.SuperRonanCraft.BetterRTP.player.rtp.RTP_SHAPE;
|
||||
import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
|
||||
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class WorldPermissionGroup implements RTPWorld, RTPWorld_Defaulted {
|
||||
private boolean useWorldborder;
|
||||
private int centerX, centerZ, maxRad, minRad, price, miny, maxy;
|
||||
private List<String> biomes;
|
||||
private String world;
|
||||
private RTP_SHAPE shape;
|
||||
@Getter private int priority;
|
||||
|
||||
/*public RTPPermConfiguration getGroup(CommandSender p) {
|
||||
for (RTPPermConfiguration group : groups)
|
||||
if (BetterRTP.getInstance().getPerms().getPermissionGroup(p, group.name))
|
||||
return group;
|
||||
return null;
|
||||
}*/
|
||||
|
||||
public WorldPermissionGroup(String group) {
|
||||
FileBasics.FILETYPE config = BetterRTP.getInstance().getFiles().getType(FileBasics.FILETYPE.LOCATIONS);
|
||||
List<Map<?, ?>> map = config.getMapList("PermissionGroup.Groups");
|
||||
|
||||
setupDefaults();
|
||||
|
||||
this.priority = 0;
|
||||
//Find Location and cache its values
|
||||
for (Map<?, ?> m : map) {
|
||||
for (Map.Entry<?, ?> entry : m.entrySet()) {
|
||||
String key = entry.getKey().toString();
|
||||
if (!key.equals(group))
|
||||
continue;
|
||||
Map<?, ?> test = ((Map<?, ?>) m.get(key));
|
||||
if (test == null)
|
||||
continue;
|
||||
if (test.get("Priority") != null) {
|
||||
if (test.get("Priority").getClass() == Integer.class)
|
||||
priority = Integer.parseInt((test.get("Priority")).toString());
|
||||
}
|
||||
if (test.get("World") != null) {
|
||||
if (test.get("World").getClass() == String.class)
|
||||
world = test.get("World").toString();
|
||||
} else {
|
||||
BetterRTP.getInstance().getLogger().warning("Group `" + group + "` does NOT have a World specified!");
|
||||
return;
|
||||
}
|
||||
if (test.get("UseWorldBorder") != null) {
|
||||
if (test.get("UseWorldBorder").getClass() == Boolean.class)
|
||||
useWorldborder = Boolean.parseBoolean(test.get("UseWorldBorder").toString());
|
||||
}
|
||||
if (test.get("CenterX") != null) {
|
||||
if (test.get("CenterX").getClass() == Integer.class)
|
||||
centerX = Integer.parseInt((test.get("CenterX")).toString());
|
||||
}
|
||||
if (test.get("CenterZ") != null) {
|
||||
if (test.get("CenterZ").getClass() == Integer.class) {
|
||||
centerZ = Integer.parseInt((test.get("CenterZ")).toString());
|
||||
}
|
||||
}
|
||||
if (test.get("MaxRadius") != null) {
|
||||
if (test.get("MaxRadius").getClass() == Integer.class)
|
||||
maxRad = Integer.parseInt((test.get("MaxRadius")).toString());
|
||||
if (maxRad <= 0) {
|
||||
BetterRTP.getInstance().getText().sms(Bukkit.getConsoleSender(),
|
||||
"WARNING! Group '" + group + "' Maximum radius of '" + maxRad + "' is not allowed! Set to default value!");
|
||||
maxRad = BetterRTP.getInstance().getRTP().defaultWorld.getMaxRadius();
|
||||
}
|
||||
}
|
||||
if (test.get("MinRadius") != null) {
|
||||
if (test.get("MinRadius").getClass() == Integer.class)
|
||||
minRad = Integer.parseInt((test.get("MinRadius")).toString());
|
||||
if (minRad < 0 || minRad >= maxRad) {
|
||||
BetterRTP.getInstance().getText().sms(Bukkit.getConsoleSender(),
|
||||
"WARNING! Group '" + group + "' Minimum radius of '" + minRad + "' is not allowed! Set to default value!");
|
||||
minRad = BetterRTP.getInstance().getRTP().defaultWorld.getMinRadius();
|
||||
if (minRad >= maxRad)
|
||||
maxRad = BetterRTP.getInstance().getRTP().defaultWorld.getMaxRadius();
|
||||
}
|
||||
}
|
||||
if (test.get("Biomes") != null) {
|
||||
if (test.get("Biomes").getClass() == ArrayList.class)
|
||||
this.biomes = new ArrayList<String>((ArrayList) test.get("Biomes"));
|
||||
}
|
||||
if (BetterRTP.getInstance().getFiles().getType(FileBasics.FILETYPE.ECO).getBoolean("Economy.Enabled"))
|
||||
if (test.get("Price") != null) {
|
||||
if (test.get("Price").getClass() == Integer.class)
|
||||
this.price = Integer.parseInt(test.get("Price").toString());
|
||||
//else
|
||||
// price = worldDefault.getPrice(world);
|
||||
} //else
|
||||
//price = worldDefault.getPrice(world);
|
||||
if (test.get("Shape") != null) {
|
||||
if (test.get("Shape").getClass() == String.class) {
|
||||
try {
|
||||
this.shape = RTP_SHAPE.valueOf(test.get("Shape").toString().toUpperCase());
|
||||
} catch (Exception e) {
|
||||
//Invalid shape
|
||||
}
|
||||
}
|
||||
}
|
||||
if (test.get("UseWorldBorder") != null) {
|
||||
if (test.get("UseWorldBorder").getClass() == Boolean.class) {
|
||||
try {
|
||||
this.useWorldborder = Boolean.parseBoolean(test.get("UseWorldBorder").toString());
|
||||
} catch (Exception e) {
|
||||
//No UseWorldBorder
|
||||
}
|
||||
}
|
||||
}
|
||||
if (test.get("MinY") != null)
|
||||
if (test.get("MinY").getClass() == Integer.class)
|
||||
this.miny = Integer.parseInt(test.get("MinY").toString());
|
||||
if (test.get("MaxY") != null)
|
||||
if (test.get("MaxY").getClass() == Integer.class)
|
||||
this.maxy = Integer.parseInt(test.get("MaxY").toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getUseWorldborder() {
|
||||
return useWorldborder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCenterX() {
|
||||
return centerX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCenterZ() {
|
||||
return centerZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxRadius() {
|
||||
return maxRad;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinRadius() {
|
||||
return minRad;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getBiomes() {
|
||||
return biomes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull World getWorld() {
|
||||
return Bukkit.getWorld(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RTP_SHAPE getShape() {
|
||||
return shape;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinY() {
|
||||
return miny;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxY() {
|
||||
return maxy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUseWorldBorder(boolean value) {
|
||||
this.useWorldborder = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCenterX(int value) {
|
||||
this.centerX = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCenterZ(int value) {
|
||||
this.centerZ = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxRadius(int value) {
|
||||
this.maxRad = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMinRadius(int value) {
|
||||
this.minRad = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPrice(int value) {
|
||||
this.price = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBiomes(List<String> value) {
|
||||
this.biomes = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWorld(String value) {
|
||||
this.world = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShape(RTP_SHAPE value) {
|
||||
this.shape = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMinY(int value) {
|
||||
this.miny = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxY(int value) {
|
||||
this.maxy = value;
|
||||
}
|
||||
|
||||
/*public static class RTPPermConfiguration {
|
||||
|
||||
boolean valid;
|
||||
public String name;
|
||||
public List<RTPPermConfigurationWorld> 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
|
||||
BetterRTP.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;
|
||||
|
||||
public int maxRad = -1;
|
||||
public int minRad = -1;
|
||||
public int price = -1;
|
||||
public int centerx = -1;
|
||||
public int centerz = -1;
|
||||
public Object useworldborder = null;
|
||||
|
||||
public 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());
|
||||
} else if (field.equalsIgnoreCase("UseWorldBorder")) { //UseWorldBorder
|
||||
useworldborder = Boolean.valueOf(hash3.getValue().toString());
|
||||
} else if (field.equalsIgnoreCase("CenterX")) { //Center X
|
||||
centerx = getInt(hash3.getValue().toString());
|
||||
} else if (field.equalsIgnoreCase("CenterZ")) { //Center Z
|
||||
centerz = 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;
|
||||
}
|
||||
}*/
|
||||
}
|
@ -2,27 +2,27 @@ package me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.SuperRonanCraft.BetterRTP.player.commands.RTP_SETUP_TYPE;
|
||||
import me.SuperRonanCraft.BetterRTP.player.rtp.RTPPermissionGroup;
|
||||
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
||||
import me.SuperRonanCraft.BetterRTP.player.rtp.RTP;
|
||||
import me.SuperRonanCraft.BetterRTP.player.rtp.RTP_SHAPE;
|
||||
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.PermissionGroup;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldBorder;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.*;
|
||||
|
||||
public class WorldPlayer implements RTPWorld {
|
||||
public class WorldPlayer implements RTPWorld, RTPWorld_Defaulted {
|
||||
private boolean useWorldborder;
|
||||
private int CenterX, CenterZ, maxRad, minRad, price, min_y, max_y;
|
||||
private List<String> Biomes;
|
||||
@Getter private final Player player;
|
||||
private final World world;
|
||||
private WORLD_TYPE world_type;
|
||||
private RTPPermissionGroup.RTPPermConfiguration config = null;
|
||||
private WorldPermissionGroup config = null;
|
||||
private RTP_SHAPE shape;
|
||||
public RTP_SETUP_TYPE setup_type = RTP_SETUP_TYPE.DEFAULT;
|
||||
public String setup_name;
|
||||
@ -41,11 +41,11 @@ public class WorldPlayer implements RTPWorld {
|
||||
} else if (world instanceof WorldCustom)
|
||||
setup_type = RTP_SETUP_TYPE.CUSTOM_WORLD;
|
||||
this.setup_name = setup_name;
|
||||
setUseWorldborder(world.getUseWorldborder());
|
||||
setUseWorldBorder(world.getUseWorldborder());
|
||||
setCenterX(world.getCenterX());
|
||||
setCenterZ(world.getCenterZ());
|
||||
setMaxRad(world.getMaxRadius());
|
||||
setMinRad(world.getMinRadius());
|
||||
setMaxRadius(world.getMaxRadius());
|
||||
setMinRadius(world.getMinRadius());
|
||||
setShape(world.getShape());
|
||||
if (world instanceof WorldDefault)
|
||||
setPrice(((WorldDefault) world).getPrice(getWorld().getName()));
|
||||
@ -58,19 +58,19 @@ public class WorldPlayer implements RTPWorld {
|
||||
}
|
||||
setBiomes(list);
|
||||
if (personal)
|
||||
setupGroup(BetterRTP.getInstance().getRTP().permConfig);
|
||||
setupGroup();
|
||||
//Make sure our borders will not cause an invalid integer
|
||||
if (getMaxRadius() <= getMinRadius()) {
|
||||
setMinRad(BetterRTP.getInstance().getRTP().defaultWorld.getMinRadius());
|
||||
setMinRadius(BetterRTP.getInstance().getRTP().defaultWorld.getMinRadius());
|
||||
if (getMaxRadius() <= getMinRadius())
|
||||
setMinRad(0);
|
||||
setMinRadius(0);
|
||||
}
|
||||
//World border protection
|
||||
if (getUseWorldborder()) {
|
||||
WorldBorder border = getWorld().getWorldBorder();
|
||||
int _borderRad = (int) border.getSize() / 2;
|
||||
if (getMaxRadius() > _borderRad)
|
||||
setMaxRad(_borderRad);
|
||||
setMaxRadius(_borderRad);
|
||||
setCenterX(border.getCenter().getBlockX());
|
||||
setCenterZ(border.getCenter().getBlockZ());
|
||||
}
|
||||
@ -81,28 +81,16 @@ public class WorldPlayer implements RTPWorld {
|
||||
setup = true;
|
||||
}
|
||||
|
||||
private void setupGroup(RTPPermissionGroup permConfig) {
|
||||
RTPPermissionGroup.RTPPermConfiguration config = permConfig.getGroup(player);
|
||||
if (config != null) {
|
||||
for (RTPPermissionGroup.RTPPermConfigurationWorld world : config.worlds) {
|
||||
if (getWorld().getName().equals(world.name)) {
|
||||
if (world.maxRad != -1)
|
||||
setMaxRad(world.maxRad);
|
||||
if (world.minRad != -1)
|
||||
setMinRad(world.minRad);
|
||||
if (world.price != -1)
|
||||
setPrice(world.price);
|
||||
if (world.centerx != -1)
|
||||
setCenterX(world.centerx);
|
||||
if (world.centerz != -1)
|
||||
setCenterZ(world.centerz);
|
||||
if (world.useworldborder != null)
|
||||
setUseWorldborder((Boolean) world.useworldborder);
|
||||
this.config = config;
|
||||
break;
|
||||
private void setupGroup() {
|
||||
for (Map.Entry<String, PermissionGroup> group : BetterRTP.getInstance().getRTP().worldPermissionGroups.entrySet())
|
||||
if (BetterRTP.getInstance().getPerms().getPermissionGroup(player, group.getKey()))
|
||||
if (getWorld().getName().equals(group.getValue().getWorld().getName())) {
|
||||
if (this.config != null)
|
||||
if (this.config.getPriority() < ((WorldPermissionGroup) group).getPriority())
|
||||
continue;
|
||||
this.config = (WorldPermissionGroup) group.getValue();
|
||||
setAllFrom(this.config);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean checkIsValid(Location loc) { //Will check if a previously given location is valid
|
||||
@ -224,36 +212,44 @@ public class WorldPlayer implements RTPWorld {
|
||||
return shape;
|
||||
}
|
||||
|
||||
private void setUseWorldborder(boolean bool) {
|
||||
@Override
|
||||
public void setUseWorldBorder(boolean bool) {
|
||||
useWorldborder = bool;
|
||||
}
|
||||
|
||||
private void setCenterX(int x) {
|
||||
@Override
|
||||
public void setCenterX(int x) {
|
||||
CenterX = x;
|
||||
}
|
||||
|
||||
private void setCenterZ(int z) {
|
||||
@Override
|
||||
public void setCenterZ(int z) {
|
||||
CenterZ = z;
|
||||
}
|
||||
|
||||
//Modifiable
|
||||
private void setMaxRad(int max) {
|
||||
public void setMaxRadius(int max) {
|
||||
maxRad = max;
|
||||
}
|
||||
|
||||
private void setMinRad(int min) {
|
||||
public void setMinRadius(int min) {
|
||||
minRad = min;
|
||||
}
|
||||
|
||||
private void setPrice(int price) {
|
||||
public void setPrice(int price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
//
|
||||
private void setBiomes(List<String> biomes) {
|
||||
public void setBiomes(List<String> biomes) {
|
||||
this.Biomes = biomes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWorld(String value) {
|
||||
|
||||
}
|
||||
|
||||
//Custom World type
|
||||
public void setWorldtype(WORLD_TYPE type) {
|
||||
this.world_type = type;
|
||||
@ -271,7 +267,7 @@ public class WorldPlayer implements RTPWorld {
|
||||
this.max_y = value;
|
||||
}
|
||||
|
||||
public RTPPermissionGroup.RTPPermConfiguration getConfig() {
|
||||
public WorldPermissionGroup getConfig() {
|
||||
return this.config;
|
||||
}
|
||||
|
||||
|
@ -127,10 +127,12 @@ PermissionGroup: #Player requires "betterrtp.group.<world_name>" to trigger thes
|
||||
Groups:
|
||||
- vip: # permission: betterrtp.group.vip
|
||||
- Build_World: #World named "Build_World"
|
||||
Priority: 0 #Lower the more prioritized
|
||||
MaxRadius: 10000
|
||||
MinRadius: 1000
|
||||
Price: 100
|
||||
- Survival_World:
|
||||
Priority: 10 #Higher the less prioritized
|
||||
UseWorldBorder: false
|
||||
MaxRadius: 5000
|
||||
MinRadius: 1000
|
||||
|
Loading…
x
Reference in New Issue
Block a user