Skip to content

Commit

Permalink
new RTPOnDeath option for world configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperRonanCraft committed Dec 28, 2023
1 parent 2350b6a commit 418ef2a
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 220 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package me.SuperRonanCraft.BetterRTP.player.events;

import me.SuperRonanCraft.BetterRTP.player.rtp.RTPSetupInformation;
import me.SuperRonanCraft.BetterRTP.player.rtp.RTP_TYPE;
import me.SuperRonanCraft.BetterRTP.references.helpers.HelperRTP;
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.WorldPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerRespawnEvent;

public class Death {

static void respawnEvent(PlayerRespawnEvent e) {
Player p = e.getPlayer();
WorldPlayer worldPlayer = HelperRTP.getPlayerWorld(new RTPSetupInformation(
p.getWorld(),
p, p, false
));
if (worldPlayer.getRTPOnDeath()) {
HelperRTP.tp(p, p, p.getWorld(), null, RTP_TYPE.FORCED, true, true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
import org.bukkit.event.Listener;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.*;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.plugin.PluginManager;

Expand Down Expand Up @@ -65,4 +62,9 @@ private void rtpPost(RTP_TeleportPostEvent e) {
private void worldLoad(WorldLoadEvent e) {
worldLoad.load(e);
}

@EventHandler
private void onRespawn(PlayerRespawnEvent e) {
Death.respawnEvent(e);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

public class RTP {

final RTPTeleport teleport = new RTPTeleport();
@Getter final RTPTeleport teleport = new RTPTeleport();
//Cache
public final HashMap<String, String> overriden = new HashMap<>();
@Getter List<String> disabledWorlds, blockList;
Expand All @@ -35,10 +35,6 @@ public class RTP {
@Getter private final HashMap<String, RTPWorld> RTPworldLocations = new HashMap<>();
@Getter private final HashMap<String, PermissionGroup> permissionGroups = new HashMap<>();

public RTPTeleport getTeleport() {
return teleport;
}

public void load() {
FileOther.FILETYPE config = FileOther.FILETYPE.CONFIG;
disabledWorlds = config.getStringList("DisabledWorlds");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public enum RTP_TYPE {
COMMAND, //Player executed command
FORCED, //Player was forced to rtp (/rtp player <player>)
RESPAWN, //Player respawned and world has RTPOnDeath enabled
JOIN, //Player joined and was rtp'd automatically
TEST, //Player was just testing out effects
ADDON, //Player RTP'd from the external addons plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ default String getID() {
}

long getCooldown();

boolean getRTPOnDeath();
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public interface RTPWorld_Defaulted {

void setCooldown(long value);

void setRTPOnDeath(boolean bool);

default void setupDefaults() {
setAllFrom(BetterRTP.getInstance().getRTP().getRTPdefaultWorld());
}
Expand All @@ -48,5 +50,6 @@ default void setAllFrom(RTPWorld rtpWorld) {
setMinY(rtpWorld.getMinY());
setMaxY(rtpWorld.getMaxY());
setCooldown(rtpWorld.getCooldown());
setRTPOnDeath(rtpWorld.getRTPOnDeath());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public class WorldCustom implements RTPWorld, RTPWorld_Defaulted {
public World world;
private boolean useWorldborder;
private boolean useWorldborder, RTPOnDeath;
private int centerX, centerZ, maxRad, minRad, price, miny, maxy;
private long cooldown;
private List<String> biomes;
Expand Down Expand Up @@ -202,6 +202,10 @@ public long getCooldown() {
return cooldown;
}

@Override public boolean getRTPOnDeath() {
return RTPOnDeath;
}

//Setters
@Override
public void setUseWorldBorder(boolean value) {
Expand Down Expand Up @@ -262,4 +266,8 @@ public void setMaxY(int value) {
public void setCooldown(long value) {
this.cooldown = value;
}

@Override public void setRTPOnDeath(boolean bool) {
RTPOnDeath = bool;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.logging.Logger;

public class WorldDefault implements RTPWorld {
private boolean useWorldborder;
private boolean useWorldborder, RTPOnDeath;
private int centerX, centerZ, maxRad, minRad, price, miny, maxy;
private List<String> Biomes;
private final HashMap<String, Integer> prices = new HashMap<>();
Expand All @@ -26,6 +26,7 @@ public void load() {
FileOther.FILETYPE config = BetterRTP.getInstance().getFiles().getType(FileOther.FILETYPE.CONFIG);
//Booleans
useWorldborder = config.getBoolean(pre + ".UseWorldBorder");
RTPOnDeath = config.getBoolean(pre + ".RTPOnDeath");
//Integers
centerX = config.getInt(pre + ".CenterX");
centerZ = config.getInt(pre + ".CenterZ");
Expand Down Expand Up @@ -149,4 +150,8 @@ public int getMaxY() {
public long getCooldown() {
return BetterRTP.getInstance().getCooldowns().getDefaultCooldownTime();
}

@Override public boolean getRTPOnDeath() {
return RTPOnDeath;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.util.Map;

public class WorldLocation implements RTPWorld, RTPWorld_Defaulted {
private boolean useWorldborder;
private boolean useWorldborder, RTPOnDeath;
private int centerX, centerZ, maxRad, minRad, price, miny, maxy;
private long cooldown;
private List<String> biomes;
Expand Down Expand Up @@ -143,6 +143,12 @@ public WorldLocation(String location_name) {
this.cooldown = Long.parseLong(section.get("Cooldown").toString());
BetterRTP.debug("- - Cooldown: " + cooldown);
}
if (section.get("RTPOnDeath") != null) {
if (section.get("RTPOnDeath").getClass() == Boolean.class) {
RTPOnDeath = Boolean.parseBoolean(section.get("RTPOnDeath").toString());
BetterRTP.debug("- - RTPOnDeath: " + RTPOnDeath);
}
}
}
}
}
Expand Down Expand Up @@ -217,6 +223,10 @@ public String getID() {
public long getCooldown() {
return cooldown;
}

@Override public boolean getRTPOnDeath() {
return RTPOnDeath;
}
//Setters

@Override
Expand Down Expand Up @@ -278,4 +288,8 @@ public void setMaxY(int value) {
public void setCooldown(long value) {
this.cooldown = value;
}

@Override public void setRTPOnDeath(boolean bool) {
this.RTPOnDeath = bool;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

@SuppressWarnings("rawtypes")
public class WorldPermissionGroup implements RTPWorld, RTPWorld_Defaulted {
private boolean useWorldborder;
private boolean useWorldborder, RTPOnDeath;
private int centerX, centerZ, maxRad, minRad, price, miny, maxy;
private List<String> biomes;
public World world;
Expand Down Expand Up @@ -123,6 +123,12 @@ public WorldPermissionGroup(String group, World world, Map.Entry fields) {
this.cooldown = Long.parseLong(hash3.getValue().toString());
BetterRTP.debug("- - Cooldown: " + cooldown);
}
if (field.equalsIgnoreCase("RTPOnDeath")) {
if (hash3.getValue().getClass() == Boolean.class) {
RTPOnDeath = Boolean.parseBoolean(hash3.getValue().toString());
BetterRTP.debug("- - RTPOnDeath: " + RTPOnDeath);
}
}
}
}

Expand Down Expand Up @@ -186,6 +192,10 @@ public long getCooldown() {
return cooldown;
}

@Override public boolean getRTPOnDeath() {
return RTPOnDeath;
}

@Override
public void setUseWorldBorder(boolean value) {
this.useWorldborder = value;
Expand Down Expand Up @@ -246,78 +256,7 @@ public void setCooldown(long value) {
this.cooldown = 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;
}
@Override public void setRTPOnDeath(boolean bool) {
this.RTPOnDeath = bool;
}
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;
}
}*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

public class WorldPlayer implements RTPWorld, RTPWorld_Defaulted {
private boolean useWorldborder;
private boolean RTPOnDeath;
private int CenterX, CenterZ, maxRad, minRad, price, min_y, max_y;
private long cooldown;
private List<String> Biomes;
Expand Down Expand Up @@ -51,6 +52,7 @@ public void setup(String setup_name, RTPWorld world, List<String> biomes) {
setup_type = RTP_SETUP_TYPE.PERMISSIONGROUP;
this.setup_name = setup_name;
setUseWorldBorder(world.getUseWorldborder());
setRTPOnDeath(world.getRTPOnDeath());

//BetterRTP.getInstance().getLogger().info("WorldPlayer Center x: " + CenterX);
setCenterX(world.getCenterX());
Expand Down Expand Up @@ -164,6 +166,10 @@ public void setUseWorldBorder(boolean bool) {
useWorldborder = bool;
}

@Override public void setRTPOnDeath(boolean bool) {
RTPOnDeath = bool;
}

@Override
public void setCenterX(int x) {
CenterX = x;
Expand Down Expand Up @@ -240,4 +246,9 @@ public int getMaxY() {
public long getCooldown() {
return cooldown;
}

@Override public boolean getRTPOnDeath() {
return RTPOnDeath;
}

}
Loading

0 comments on commit 418ef2a

Please sign in to comment.