Permission Groups added + '/rtp info world <player>' personalizes info page

This commit is contained in:
SuperRonanCraft 2020-09-23 22:17:54 -04:00
parent c8a00751fa
commit c5d7705d54
9 changed files with 176 additions and 132 deletions

View File

@ -157,12 +157,12 @@ public class Commands {
return false;
} else {
//Reset timer, but allow them to tp
cooldowns.add(id);
//cooldowns.add(id);
return true;
}
}
} else
cooldowns.add(id);
} //else
//cooldowns.add(id);
}
return true;
}

View File

@ -5,6 +5,7 @@ import me.SuperRonanCraft.BetterRTP.player.rtp.RTPParticles;
import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommand;
import me.SuperRonanCraft.BetterRTP.references.worlds.RTPWorld;
import me.SuperRonanCraft.BetterRTP.references.worlds.WORLD_TYPE;
import me.SuperRonanCraft.BetterRTP.references.worlds.WorldPlayer;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.WorldBorder;
@ -27,8 +28,19 @@ public class CmdInfo implements RTPCommand {
else if (args[1].equalsIgnoreCase(CmdInfoSub.POTION_EFFECTS.name()))
infoEffects(sendi);
else if (args[1].equalsIgnoreCase(CmdInfoSub.WORLD.name())) {
if (sendi instanceof Player) {
sendInfoWorld(sendi, infoGetWorld(((Player) sendi).getWorld()));
if (sendi instanceof Player) { //Personalize with permission groups
World world = null;
boolean personal = false;
if (args.length > 2) {
Player player = Bukkit.getPlayer(args[2]);
if (player != null) {
world = player.getWorld();
personal = true;
}
}
if (world == null)
world = ((Player) sendi).getWorld();
sendInfoWorld(sendi, infoGetWorld(sendi, world, personal));
} else
infoWorld(sendi);
}
@ -88,47 +100,34 @@ public class CmdInfo implements RTPCommand {
private void infoWorld(CommandSender sendi) { //All worlds
List<String> info = new ArrayList<>();
for (World w : Bukkit.getWorlds())
info.addAll(infoGetWorld(w));
info.addAll(infoGetWorld(sendi, w, false));
sendInfoWorld(sendi, info);
}
private List<String> infoGetWorld(World w) { //Specific world
private List<String> infoGetWorld(CommandSender sendi, World w, boolean personal) { //Specific world
List<String> info = new ArrayList<>();
Main pl = Main.getInstance();
info.add("&aWorld: &7" + w.getName());
String _true = "&aTrue", _false = "&bFalse";
info.add("&eWorld: &7" + w.getName() + (personal ? " &7(personalized)" : ""));
if (personal)
info.add("&7- &6Allowed: " + (pl.getPerms().getAWorld(sendi, w.getName()) ? _true : _false));
if (pl.getRTP().getDisabledWorlds().contains(w.getName())) //DISABLED
info.add("&7- &6Disabled: &bTrue");
info.add("&7- &6Disabled: " + _true);
else {
info.add("&7- &6Disabled: &cFalse");
info.add("&7- &6Disabled: " + _false);
if (pl.getRTP().overriden.containsKey(w.getName()))
info.add("&7- &6Overriden: &bTrue");
info.add("&7- &6Overriden: " + _true);
else {
info.add("&7- &6WorldType: &f" + pl.getRTP().world_type.getOrDefault(w.getName(), WORLD_TYPE.NORMAL).name());
info.add("&7- &6Overriden: &cFalse");
RTPWorld _rtpworld = pl.getRTP().defaultWorld;
for (RTPWorld __rtpworld : pl.getRTP().customWorlds.values()) {
if (__rtpworld.getWorld() != null && __rtpworld.getWorld().getName().equals(w.getName())) {
_rtpworld = __rtpworld;
break;
}
}
if (_rtpworld == pl.getRTP().defaultWorld)
info.add("&7- &6Custom: &cFalse");
else
info.add("&7- &6Custom: &bTrue");
if (_rtpworld.getUseWorldborder()) {
info.add("&7- &6UseWorldborder: &bTrue");
WorldBorder border = w.getWorldBorder();
info.add("&7- &6Center X: &7" + border.getCenter().getBlockX());
info.add("&7- &6Center Z: &7" + border.getCenter().getBlockZ());
info.add("&7- &6MaxRad: &7" + (border.getSize() / 2));
} else {
info.add("&7- &6UseWorldborder: &cFalse");
info.add("&7- &6Center X: &7" + _rtpworld.getCenterX());
info.add("&7- &6Center Z: &7" + _rtpworld.getCenterZ());
info.add("&7- &6MaxRad: &7" + _rtpworld.getMaxRad());
}
info.add("&7- &6MinRad: &7" + _rtpworld.getMinRad());
info.add("&7- &6Overriden: " + _false);
WorldPlayer _rtpworld = Main.getInstance().getRTP().getPlayerWorld(sendi, w.getName(), null, personal);
info.add("&7- &6Custom: " + (Main.getInstance().getRTP().customWorlds.containsKey(w.getName()) ? _true : _false));
info.add("&7- &6UseWorldBorder: " + (_rtpworld.getUseWorldborder() ? _true : _false));
info.add("&7- &6Permission Group: " + (_rtpworld.getConfig() != null ? "&e" + _rtpworld.getConfig().name : "&cN/A"));
info.add("&7- &6Center X: &f" + _rtpworld.getCenterX());
info.add("&7- &6Center Z: &f" + _rtpworld.getCenterZ());
info.add("&7- &6MaxRad: &f" + _rtpworld.getMaxRad());
info.add("&7- &6MinRad: &f" + _rtpworld.getMinRad());
}
}
return info;
@ -158,6 +157,13 @@ public class CmdInfo implements RTPCommand {
for (CmdInfoSub cmd : CmdInfoSub.values())
if (cmd.name().toLowerCase().startsWith(args[1].toLowerCase()))
info.add(cmd.name().toLowerCase());
} else if (args.length == 3) {
if (CmdInfoSub.WORLD.name().toLowerCase().startsWith(args[1].toLowerCase())) {
for (Player p : Bukkit.getOnlinePlayers()) {
if (p.getName().toLowerCase().startsWith(args[2].toLowerCase()))
info.add(p.getName());
}
}
}
return info;
}

View File

@ -21,7 +21,7 @@ public class RTP {
private final RTPTeleport teleport = new RTPTeleport();
private final RTPPluginValidation softDepends = new RTPPluginValidation();
private final RTPPermConfigs permConfig = new RTPPermConfigs();
public final RTPPermissionGroup permConfig = new RTPPermissionGroup();
//Cache
public HashMap<String, RTPWorld> customWorlds = new HashMap<>();
public HashMap<String, String> overriden = new HashMap<>();
@ -121,6 +121,22 @@ public class RTP {
return disabledWorlds;
}
public WorldPlayer getPlayerWorld(CommandSender p, String worldName, List<String> biomes, boolean personal) {
WorldPlayer pWorld = new WorldPlayer(p, Bukkit.getWorld(worldName));
// Set all methods
if (customWorlds.containsKey(worldName)) {
RTPWorld cWorld = customWorlds.get(pWorld.getWorld().getName());
pWorld.setup(cWorld, cWorld.getPrice(), biomes, personal);
} else
pWorld.setup(defaultWorld, defaultWorld.getPrice(), biomes, personal);
//World type
WORLD_TYPE world_type = WORLD_TYPE.NORMAL; //World rtp type
if (this.world_type.containsKey(worldName))
world_type = this.world_type.get(worldName);
pWorld.setWorldtype(world_type);
return pWorld;
}
public void start(Player p, CommandSender sendi, String worldName, List<String> biomes, boolean delay) {
// Check overrides
if (worldName == null)
@ -129,53 +145,30 @@ public class RTP {
worldName = overriden.get(worldName);
// Not forced and has 'betterrtp.world.<world>'
if (sendi == p && !getPl().getPerms().getAWorld(sendi, worldName)) {
getPl().getCmd().cooldowns.remove(p.getUniqueId());
//getPl().getCmd().cooldowns.remove(p.getUniqueId());
getPl().getText().getNoPermissionWorld(p, worldName);
return;
}
// Check disabled worlds
if (disabledWorlds.contains(worldName)) {
getPl().getText().getDisabledWorld(sendi, worldName);
getPl().getCmd().cooldowns.remove(p.getUniqueId());
//getPl().getCmd().cooldowns.remove(p.getUniqueId());
return;
}
// Check if nulled or world doesnt exist
if (Bukkit.getWorld(worldName) == null) {
getPl().getText().getNotExist(sendi, worldName);
getPl().getCmd().cooldowns.remove(p.getUniqueId());
//getPl().getCmd().cooldowns.remove(p.getUniqueId());
return;
}
WorldPlayer pWorld = new WorldPlayer(p, Bukkit.getWorld(worldName));
// Set all methods
if (customWorlds.containsKey(worldName)) {
RTPWorld cWorld = customWorlds.get(pWorld.getWorld().getName());
pWorld.setup(cWorld, cWorld.getPrice(), biomes);
} else
pWorld.setup(defaultWorld, defaultWorld.getPrice(), biomes);
//World type
WORLD_TYPE world_type = WORLD_TYPE.NORMAL; //World rtp type
if (this.world_type.containsKey(worldName))
world_type = this.world_type.get(worldName);
pWorld.setWorldtype(world_type);
WorldPlayer pWorld = getPlayerWorld(p, worldName, biomes, true);
// Economy
if (!getPl().getEco().charge(p, pWorld.getPrice())) {
getPl().getCmd().cooldowns.remove(p.getUniqueId());
//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);
}
}
}
//Cooldown
getPl().getCmd().cooldowns.add(p.getUniqueId());
// 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) {

View File

@ -12,7 +12,7 @@ import java.util.UUID;
public class RTPCooldown {
private HashMap<UUID, Long> cooldowns = new HashMap<>(); //Cooldown timer for each player
private final HashMap<UUID, Long> cooldowns = new HashMap<>(); //Cooldown timer for each player
private HashMap<UUID, Integer> locked = null; //Players locked from rtp'ing ever again
public boolean enabled;
private int

View File

@ -1,21 +1,20 @@
package me.SuperRonanCraft.BetterRTP.player.rtp;
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.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import java.util.*;
@SuppressWarnings("rawtypes")
public class RTPPermConfigs {
private List<RTPPermConfiguration> groups = new ArrayList<>();
public class RTPPermissionGroup {
private final List<RTPPermConfiguration> groups = new ArrayList<>();
public RTPPermConfiguration getGroup(Player p) {
public RTPPermConfiguration getGroup(CommandSender p) {
for (RTPPermConfiguration group : groups)
if (Main.getInstance().getPerms().getConfig(p, group.name))
if (Main.getInstance().getPerms().getPermissionGroup(p, group.name))
return group;
return null;
}
@ -25,13 +24,14 @@ public class RTPPermConfigs {
group.worlds.clear();
groups.clear();
YamlConfiguration config = Main.getInstance().getFiles().getType(FileBasics.FILETYPE.CONFIG).getConfig();
List<Map<?, ?>> list = config.getMapList("PermissionConfigs");
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);
Main.debug("- Group " + group.name + " has " + group.worlds.size() + " worlds setup, permission: 'betterrtp.config." + group.name + "'");
Main.debug("- Group " + group.name + " has " + group.worlds.size() + " worlds setup, permission: 'betterrtp.group." + group.name + "'");
for (RTPPermConfigurationWorld world : group.worlds) {
Main.debug(" - World '" + world.name + "' MaxRad = " + world.maxRad + ", MinRad = " + world.minRad);
}
@ -44,8 +44,8 @@ public class RTPPermConfigs {
public static class RTPPermConfiguration {
boolean valid;
String name;
List<RTPPermConfigurationWorld> worlds = new ArrayList<>();
public String name;
public List<RTPPermConfigurationWorld> worlds = new ArrayList<>();
RTPPermConfiguration(Map.Entry<?, ?> fields) {
String group = fields.getKey().toString();
@ -70,12 +70,16 @@ public class RTPPermConfigs {
public static class RTPPermConfigurationWorld {
boolean valid = true;
boolean valid;
int maxRad = -1;
int minRad = -1;
int price = -1;
String name;
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;
@ -90,6 +94,12 @@ public class RTPPermConfigs {
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);

View File

@ -87,8 +87,8 @@ public class Permissions {
return perm(pre + "edit", sendi);
}
public boolean getConfig(CommandSender sendi, String group) {
return perm(pre + "config." + group, sendi);
public boolean getPermissionGroup(CommandSender sendi, String group) {
return perm(pre + "group." + group, sendi);
}
private boolean perm(String str, CommandSender sendi) {

View File

@ -1,8 +1,11 @@
package me.SuperRonanCraft.BetterRTP.references.worlds;
import me.SuperRonanCraft.BetterRTP.Main;
import me.SuperRonanCraft.BetterRTP.player.rtp.RTPPermissionGroup;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.WorldBorder;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
@ -13,16 +16,17 @@ public class WorldPlayer implements RTPWorld {
private boolean useWorldborder;
private int CenterX, CenterZ, maxBorderRad, minBorderRad, price, attempts;
private List<String> Biomes;
private final Player p;
private final CommandSender p;
private final World world;
private WORLD_TYPE world_type;
private RTPPermissionGroup.RTPPermConfiguration config = null;
public WorldPlayer(Player p, World world) {
public WorldPlayer(CommandSender p, World world) {
this.p = p;
this.world = world;
}
public void setup(RTPWorld world, int price, List<String> biomes) {
public void setup(RTPWorld world, int price, List<String> biomes, boolean personal) {
setUseWorldborder(world.getUseWorldborder());
setCenterX(world.getCenterX());
setCenterZ(world.getCenterZ());
@ -33,33 +37,56 @@ public class WorldPlayer implements RTPWorld {
if (biomes != null)
list.addAll(biomes);
setBiomes(list);
if (personal)
setupGroup(Main.getInstance().getRTP().permConfig);
//Make sure our borders will not cause an invalid integer
if (getMaxRad() <= getMinRad()) {
setMinRad(Main.getInstance().getRTP().defaultWorld.getMinRad());
if (getMaxRad() <= getMinRad())
setMinRad(0);
}
//World border protection
if (getUseWorldborder()) {
WorldBorder border = getWorld().getWorldBorder();
int _borderRad = (int) border.getSize() / 2;
if (getMaxRad() > _borderRad)
setMaxRad(_borderRad);
setCenterX(border.getCenter().getBlockX());
setCenterZ(border.getCenter().getBlockZ());
}
}
private void setupGroup(RTPPermissionGroup permConfig) {
RTPPermissionGroup.RTPPermConfiguration config = permConfig.getGroup(p);
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;
}
}
}
}
public Player getPlayer() {
return p;
return (Player) p;
}
public Location generateRandomXZ(WorldDefault defaultWorld) {
int borderRad = getMaxRad();
int minVal = getMinRad();
int CenterX = getCenterX();
int CenterZ = getCenterZ();
World world = getWorld();
if (getUseWorldborder()) {
WorldBorder border = world.getWorldBorder();
int _borderRad = (int) border.getSize() / 2;
if (borderRad > _borderRad)
borderRad = _borderRad;
CenterX = border.getCenter().getBlockX();
CenterZ = border.getCenter().getBlockZ();
}
//Make sure our borders will not cause an invalid integer
if (borderRad <= minVal) {
minVal = defaultWorld.getMinRad();
if (borderRad <= minVal)
minVal = 0;
}
//Generate a random X and Z based off the quadrant selected
int max = borderRad - minVal;
@ -79,11 +106,11 @@ public class WorldPlayer implements RTPWorld {
x = new Random().nextInt(max) + minVal;
z = -(new Random().nextInt(max) + minVal); break;
}
x += CenterX;
z += CenterZ;
x += getCenterX();
z += getCenterZ();
addAttempt();
//System.out.println(quadrant);
return new Location(world, x, 0, z);
return new Location(getWorld(), x, 0, z);
}
@Override
@ -141,15 +168,15 @@ public class WorldPlayer implements RTPWorld {
}
//Modifiable
public void setMaxRad(int max) {
private void setMaxRad(int max) {
maxBorderRad = max;
}
public void setMinRad(int min) {
private void setMinRad(int min) {
minBorderRad = min;
}
public void setPrice(int price) {
private void setPrice(int price) {
this.price = price;
}
@ -167,6 +194,10 @@ public class WorldPlayer implements RTPWorld {
this.world_type = type;
}
public RTPPermissionGroup.RTPPermConfiguration getConfig() {
return this.config;
}
public WORLD_TYPE getWorldtype() {
return this.world_type;
}

View File

@ -76,6 +76,7 @@ CustomWorlds:
MinRadius: 100
CenterX: 0
CenterZ: 0
Price: 75
- other_custom_world:
MaxRadius: 100000
MinRadius: 1000
@ -97,22 +98,23 @@ WorldType: # Available types are NORMAL, NETHER
- world_nether: NETHER
- world_the_end: NORMAL
PermissionConfigs: #Player requires "betterrtp.config.<world_name>" to trigger these configs
- vip: #betterrtp.config.vip
- 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
Price: 20
PermissionGroup: #Player requires "betterrtp.group.<world_name>" to trigger these configs
Enabled: false
Groups:
- vip: #betterrtp.config.vip
- Build_World: #World named "Build_World"
MaxRadius: 10000
MinRadius: 1000
Price: 100
- Survival_World:
UseWorldBorder: false
MaxRadius: 5000
MinRadius: 1000
CenterX: 10
CenterZ: 10
Price: 10
- vip2:
- Build_World:
MaxRadius: 25000
MinRadius: 10000
Price: 15

View File

@ -36,6 +36,8 @@ permissions:
description: RTP another player
betterrtp.biome:
description: RTP to specific biomes
betterrtp.group.*:
description: Use a permission group to rtp with different restrictions
betterrtp.sign:
description: Ability to create an RTP sign
betterrtp.bypass.cooldown: