custom world price fix

This commit is contained in:
SuperRonanCraft 2020-12-11 16:51:27 -05:00
parent 17a574866b
commit 2f218707a5
9 changed files with 84 additions and 33 deletions

View File

@ -7,7 +7,7 @@
<groupId>me.SuperRonanCraft</groupId> <groupId>me.SuperRonanCraft</groupId>
<artifactId>BetterRTP</artifactId> <artifactId>BetterRTP</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>3.0.2</version> <version>3.0.3</version>
<properties> <properties>
<maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>

View File

@ -3,6 +3,7 @@ package me.SuperRonanCraft.BetterRTP.player.commands.types;
import me.SuperRonanCraft.BetterRTP.BetterRTP; import me.SuperRonanCraft.BetterRTP.BetterRTP;
import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommandHelpable; import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommandHelpable;
import me.SuperRonanCraft.BetterRTP.player.rtp.RTPParticles; import me.SuperRonanCraft.BetterRTP.player.rtp.RTPParticles;
import me.SuperRonanCraft.BetterRTP.references.worlds.WorldDefault;
import me.SuperRonanCraft.BetterRTP.references.worlds.WorldPlayer; import me.SuperRonanCraft.BetterRTP.references.worlds.WorldPlayer;
import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommand; import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommand;
import me.SuperRonanCraft.BetterRTP.references.worlds.WORLD_TYPE; import me.SuperRonanCraft.BetterRTP.references.worlds.WORLD_TYPE;
@ -125,18 +126,39 @@ public class CmdInfo implements RTPCommand, RTPCommandHelpable {
info.add("&7- &6WorldType: &f" + pl.getRTP().world_type.getOrDefault(w.getName(), WORLD_TYPE.NORMAL).name()); info.add("&7- &6WorldType: &f" + pl.getRTP().world_type.getOrDefault(w.getName(), WORLD_TYPE.NORMAL).name());
info.add("&7- &6Overriden: " + _false); info.add("&7- &6Overriden: " + _false);
WorldPlayer _rtpworld = BetterRTP.getInstance().getRTP().getPlayerWorld(sendi, w.getName(), null, personal); WorldPlayer _rtpworld = BetterRTP.getInstance().getRTP().getPlayerWorld(sendi, w.getName(), null, personal);
WorldDefault worldDefault = BetterRTP.getInstance().getRTP().defaultWorld;
info.add("&7- &6Custom: " + (BetterRTP.getInstance().getRTP().customWorlds.containsKey(w.getName()) ? _true : _false)); info.add("&7- &6Custom: " + (BetterRTP.getInstance().getRTP().customWorlds.containsKey(w.getName()) ? _true : _false));
info.add("&7- &6UseWorldBorder: " + (_rtpworld.getUseWorldborder() ? _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- &6Permission Group: " + (_rtpworld.getConfig() != null ? "&e" + _rtpworld.getConfig().name : "&cN/A"));
info.add("&7- &6Center X: &f" + _rtpworld.getCenterX()); info.add("&7- &6Center X: &f" + _rtpworld.getCenterX() + getInfo(_rtpworld, worldDefault, "centerx"));
info.add("&7- &6Center Z: &f" + _rtpworld.getCenterZ()); info.add("&7- &6Center Z: &f" + _rtpworld.getCenterZ() + getInfo(_rtpworld, worldDefault, "centerz"));
info.add("&7- &6MaxRad: &f" + _rtpworld.getMaxRad()); info.add("&7- &6MaxRad: &f" + _rtpworld.getMaxRad() + getInfo(_rtpworld, worldDefault, "max"));
info.add("&7- &6MinRad: &f" + _rtpworld.getMinRad()); info.add("&7- &6MinRad: &f" + _rtpworld.getMinRad() + getInfo(_rtpworld, worldDefault, "min"));
info.add("&7- &6Price: &f" + _rtpworld.getPrice() + getInfo(_rtpworld, worldDefault, "price"));
info.add("&7- &6World Type: &f" + _rtpworld.getWorldtype().name());
info.add("&7- &6Biomes: &f" + _rtpworld.getBiomes().toString());
} }
} }
return info; return info;
} }
//Janky, but it works
private String getInfo(WorldPlayer worldPlayer, WorldDefault worldDefault, String type) {
switch (type) {
case "centerx":
return worldPlayer.getUseWorldborder() || worldPlayer.getCenterX() != worldDefault.getCenterX() ? worldPlayer.getUseWorldborder() ? " &8(worldborder)" : "&a*" : "";
case "centerz":
return worldPlayer.getUseWorldborder() || worldPlayer.getCenterX() != worldDefault.getCenterZ() ? worldPlayer.getUseWorldborder() ? " &8(worldborder)" : "&a*" : "";
case "max":
return worldPlayer.getUseWorldborder() || worldPlayer.getMaxRad() != worldDefault.getMaxRad() ? worldPlayer.getUseWorldborder() ? " &8(worldborder)" : "&a*" : "";
case "min":
return worldPlayer.getMinRad() != worldDefault.getMinRad() ? "&a*" : "";
case "price":
return worldPlayer.getPrice() != worldDefault.getPrice() ? "&a*" : "";
}
return "";
}
//Effects //Effects
private void infoEffects(CommandSender sendi) { private void infoEffects(CommandSender sendi) {
List<String> info = new ArrayList<>(); List<String> info = new ArrayList<>();

View File

@ -123,9 +123,9 @@ public class RTP {
// Set all methods // Set all methods
if (customWorlds.containsKey(world_name)) { if (customWorlds.containsKey(world_name)) {
RTPWorld cWorld = customWorlds.get(pWorld.getWorld().getName()); RTPWorld cWorld = customWorlds.get(pWorld.getWorld().getName());
pWorld.setup(cWorld, cWorld.getPrice(), biomes, personal); pWorld.setup(cWorld, biomes, personal);
} else } else
pWorld.setup(defaultWorld, defaultWorld.getPrice(), biomes, personal); pWorld.setup(defaultWorld, biomes, personal);
//World type //World type
WORLD_TYPE world_type = WORLD_TYPE.NORMAL; //World rtp type WORLD_TYPE world_type = WORLD_TYPE.NORMAL; //World rtp type
if (this.world_type.containsKey(world_name)) if (this.world_type.containsKey(world_name))

View File

@ -16,7 +16,7 @@ public class WorldCustom implements RTPWorld {
private List<String> Biomes; private List<String> Biomes;
public WorldCustom(String world) { public WorldCustom(String world) {
String pre = "CustomWorlds."; //String pre = "CustomWorlds.";
FileBasics.FILETYPE config = BetterRTP.getInstance().getFiles().getType(FileBasics.FILETYPE.CONFIG); FileBasics.FILETYPE config = BetterRTP.getInstance().getFiles().getType(FileBasics.FILETYPE.CONFIG);
List<Map<?, ?>> map = config.getMapList("CustomWorlds"); List<Map<?, ?>> map = config.getMapList("CustomWorlds");
this.world = world; this.world = world;
@ -75,8 +75,16 @@ public class WorldCustom implements RTPWorld {
} }
if (test.get("Biomes") != null) { if (test.get("Biomes") != null) {
if (test.get("Biomes").getClass() == ArrayList.class) if (test.get("Biomes").getClass() == ArrayList.class)
this.Biomes = new ArrayList<>((ArrayList) test.get("Biomes")); 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);
} }
} }
//Booleans //Booleans
@ -96,24 +104,22 @@ public class WorldCustom implements RTPWorld {
"WARNING! Custom world '" + world + "' Minimum radius of '" + minBorderRad + "' is not allowed! Set to default value!"); "WARNING! Custom world '" + world + "' Minimum radius of '" + minBorderRad + "' is not allowed! Set to default value!");
minBorderRad = BetterRTP.getInstance().getRTP().defaultWorld.getMinRad(); minBorderRad = BetterRTP.getInstance().getRTP().defaultWorld.getMinRad();
} }
if (BetterRTP.getInstance().getFiles().getType(FileBasics.FILETYPE.ECO).getBoolean("Economy.Enabled")) /*if (BetterRTP.getInstance().getFiles().getType(FileBasics.FILETYPE.ECO).getBoolean("Economy.Enabled"))
if (BetterRTP.getInstance().getFiles().getType(FileBasics.FILETYPE.ECO).getBoolean(pre + "Enabled")) { if (BetterRTP.getInstance().getFiles().getType(FileBasics.FILETYPE.ECO).getBoolean("CustomWorlds.Enabled")) {
map.clear(); List<Map<?, ?>> world_map = BetterRTP.getInstance().getFiles().getType(FileBasics.FILETYPE.ECO).getMapList("CustomWorlds.Worlds");
map = BetterRTP.getInstance().getFiles().getType(FileBasics.FILETYPE.ECO).getMapList("CustomWorlds"); for (Map<?, ?> m : world_map)
for (Map<?, ?> m : map)
for (Map.Entry<?, ?> entry : m.entrySet()) { for (Map.Entry<?, ?> entry : m.entrySet()) {
String key = entry.getKey().toString(); String _world = entry.getKey().toString();
Map<?, ?> test = ((Map<?, ?>) m.get(key)); //System.out.println("Custom World Price " + _world + ":" + entry.getValue().toString());
if (!key.equals(world)) if (!_world.equals(world))
continue; continue;
if (test.get("Price") != null) if (entry.getValue().getClass() == Integer.class)
if (test.get("Price").getClass() == Integer.class) price = Integer.parseInt((entry.getValue().toString()));
price = Integer.valueOf((test.get("Price")).toString());
} }
} else } else
price = BetterRTP.getInstance().getRTP().defaultWorld.getPrice(); price = worldDefault.getPrice();*/
//Other //Other
this.Biomes = config.getStringList(pre + world + ".Biomes"); //this.Biomes = config.getStringList("CustomWorlds." + world + ".Biomes");
} }
@Override @Override

View File

@ -5,13 +5,17 @@ import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
import me.SuperRonanCraft.BetterRTP.BetterRTP; import me.SuperRonanCraft.BetterRTP.BetterRTP;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import scala.Int;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
public class WorldDefault 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;
private HashMap<String, Integer> prices = new HashMap<>();
public void setup() { public void setup() {
//Setups //Setups
@ -34,9 +38,20 @@ public class WorldDefault implements RTPWorld {
"WARNING! Default Minimum radius of '" + minBorderRad + "' is not allowed! Set to '0'"); "WARNING! Default Minimum radius of '" + minBorderRad + "' is not allowed! Set to '0'");
minBorderRad = 0; minBorderRad = 0;
} }
if (BetterRTP.getInstance().getFiles().getType(FileBasics.FILETYPE.ECO).getBoolean("Economy.Enabled")) prices.clear();
if (BetterRTP.getInstance().getFiles().getType(FileBasics.FILETYPE.ECO).getBoolean("Economy.Enabled")) {
price = BetterRTP.getInstance().getFiles().getType(FileBasics.FILETYPE.ECO).getInt("Economy.Price"); price = BetterRTP.getInstance().getFiles().getType(FileBasics.FILETYPE.ECO).getInt("Economy.Price");
else if (BetterRTP.getInstance().getFiles().getType(FileBasics.FILETYPE.ECO).getBoolean("CustomWorlds.Enabled")) {
List<Map<?, ?>> world_map = BetterRTP.getInstance().getFiles().getType(FileBasics.FILETYPE.ECO).getMapList("CustomWorlds.Worlds");
for (Map<?, ?> m : world_map)
for (Map.Entry<?, ?> entry : m.entrySet()) {
String _world = entry.getKey().toString();
//System.out.println("Custom World Price " + _world + ":" + entry.getValue().toString());
if (entry.getValue().getClass() == Integer.class)
prices.put(_world, Integer.parseInt((entry.getValue().toString())));
}
}
} else
price = 0; price = 0;
//Other //Other
this.Biomes = config.getStringList(pre + ".Biomes"); this.Biomes = config.getStringList(pre + ".Biomes");
@ -67,6 +82,10 @@ public class WorldDefault implements RTPWorld {
return minBorderRad; return minBorderRad;
} }
public int getPrice(String world) {
return prices.getOrDefault(world, getPrice());
}
@Override @Override
public int getPrice() { public int getPrice() {
return price; return price;

View File

@ -28,13 +28,16 @@ public class WorldPlayer implements RTPWorld {
this.world = world; this.world = world;
} }
public void setup(RTPWorld world, int price, List<String> biomes, boolean personal) { public void setup(RTPWorld world, List<String> biomes, boolean personal) {
setUseWorldborder(world.getUseWorldborder()); setUseWorldborder(world.getUseWorldborder());
setCenterX(world.getCenterX()); setCenterX(world.getCenterX());
setCenterZ(world.getCenterZ()); setCenterZ(world.getCenterZ());
setMaxRad(world.getMaxRad()); setMaxRad(world.getMaxRad());
setMinRad(world.getMinRad()); setMinRad(world.getMinRad());
setPrice(price); if (world instanceof WorldDefault)
setPrice(((WorldDefault) world).getPrice(world.getWorld().getName()));
else
setPrice(world.getPrice());
List<String> list = new ArrayList<>(world.getBiomes()); List<String> list = new ArrayList<>(world.getBiomes());
if (biomes != null) { if (biomes != null) {
list.clear(); list.clear();

View File

@ -85,12 +85,13 @@ CustomWorlds:
MinRadius: 100 MinRadius: 100
CenterX: 0 CenterX: 0
CenterZ: 0 CenterZ: 0
Price: 75 Price: 50
- other_custom_world: - other_custom_world:
MaxRadius: 100000 MaxRadius: 10000
MinRadius: 1000 MinRadius: 150
CenterX: 123 CenterX: 123
CenterZ: -123 CenterZ: -123
Price: 0
## Biomes are optional, but useful! More biomes: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/block/Biome.html ## Biomes are optional, but useful! More biomes: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/block/Biome.html
Biomes: Biomes:
- 'desert' - 'desert'

View File

@ -3,7 +3,7 @@ Economy:
Enabled: false Enabled: false
## Set to "0" to not charge for rtp, "Success.Bypass" message will be sent! ## Set to "0" to not charge for rtp, "Success.Bypass" message will be sent!
## Give players the permission "betterrtp.eco.bypass" to bypass economy ## Give players the permission "betterrtp.eco.bypass" to bypass economy
Price: 5 Price: 500
Hunger: #Make rtp'ing take up hunger to avoid exploits Hunger: #Make rtp'ing take up hunger to avoid exploits
Enabled: false Enabled: false
@ -14,6 +14,6 @@ CustomWorlds:
Enabled: true Enabled: true
Worlds: Worlds:
## PlayerWorld will be charged "5" when typing /rtp, if they do not have "betterrtp.eco.bypass" ## PlayerWorld will be charged "5" when typing /rtp, if they do not have "betterrtp.eco.bypass"
world: 5 - world: 50
## Setting the price to "0" will make the "Success.Bypass" message show ## Setting the price to "0" will make the "Success.Bypass" message show
world_end: 0 - world_end: 0

View File

@ -1,5 +1,5 @@
main: me.SuperRonanCraft.BetterRTP.BetterRTP main: me.SuperRonanCraft.BetterRTP.BetterRTP
version: '3.0.2' version: '3.0.3'
name: BetterRTP name: BetterRTP
author: SuperRonanCraft author: SuperRonanCraft
softdepend: softdepend: