mirror of
https://github.com/RonanPlugins/BetterRTP.git
synced 2025-08-18 09:35:50 +00:00
RTP settings and player teleport classes seperated
This commit is contained in:
parent
b7d389db01
commit
5f43ba5590
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>me.SuperRonanCraft</groupId>
|
<groupId>me.SuperRonanCraft</groupId>
|
||||||
<artifactId>BetterRTP</artifactId>
|
<artifactId>BetterRTP</artifactId>
|
||||||
<version>2.14.0</version>
|
<version>2.14.1</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package me.SuperRonanCraft.BetterRTP;
|
package me.SuperRonanCraft.BetterRTP;
|
||||||
|
|
||||||
import me.SuperRonanCraft.BetterRTP.player.PlayerInfo;
|
import me.SuperRonanCraft.BetterRTP.player.PlayerInfo;
|
||||||
import me.SuperRonanCraft.BetterRTP.player.rtp.RTP;
|
|
||||||
import me.SuperRonanCraft.BetterRTP.player.commands.Commands;
|
import me.SuperRonanCraft.BetterRTP.player.commands.Commands;
|
||||||
import me.SuperRonanCraft.BetterRTP.player.events.Listener;
|
import me.SuperRonanCraft.BetterRTP.player.events.Listener;
|
||||||
|
import me.SuperRonanCraft.BetterRTP.player.rtp.RTP;
|
||||||
import me.SuperRonanCraft.BetterRTP.references.depends.DepEconomy;
|
import me.SuperRonanCraft.BetterRTP.references.depends.DepEconomy;
|
||||||
import me.SuperRonanCraft.BetterRTP.references.Permissions;
|
import me.SuperRonanCraft.BetterRTP.references.Permissions;
|
||||||
import me.SuperRonanCraft.BetterRTP.references.Updater;
|
import me.SuperRonanCraft.BetterRTP.references.Updater;
|
||||||
|
@ -8,6 +8,7 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -138,7 +139,7 @@ public class CmdEdit implements RTPCommand, RTPCommandHelpable { //Edit a worlds
|
|||||||
list.add(cmd.name().toLowerCase());
|
list.add(cmd.name().toLowerCase());
|
||||||
} else if (args.length == 3) {
|
} else if (args.length == 3) {
|
||||||
for (RTP_CMD_EDIT cmd : RTP_CMD_EDIT.values())
|
for (RTP_CMD_EDIT cmd : RTP_CMD_EDIT.values())
|
||||||
if (cmd.name().toLowerCase().startsWith(args[1].toLowerCase())) {
|
if (cmd.name().equalsIgnoreCase(args[1])) {
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case WORLD: //List all worlds
|
case WORLD: //List all worlds
|
||||||
for (World world : Bukkit.getWorlds())
|
for (World world : Bukkit.getWorlds())
|
||||||
@ -151,9 +152,26 @@ public class CmdEdit implements RTPCommand, RTPCommandHelpable { //Edit a worlds
|
|||||||
}
|
}
|
||||||
} else if (args.length == 4) {
|
} else if (args.length == 4) {
|
||||||
for (RTP_CMD_EDIT cmd : RTP_CMD_EDIT.values())
|
for (RTP_CMD_EDIT cmd : RTP_CMD_EDIT.values())
|
||||||
if (cmd.name().toLowerCase().startsWith(args[1].toLowerCase()))
|
if (cmd.name().equalsIgnoreCase(args[1]))
|
||||||
if (cmd == RTP_CMD_EDIT.WORLD)
|
switch (cmd) {
|
||||||
list.addAll(tabCompleteSub(args));
|
case WORLD:
|
||||||
|
list.addAll(tabCompleteSub(args)); break;
|
||||||
|
case DEFAULT:
|
||||||
|
if (args[2].equalsIgnoreCase(RTP_CMD_EDIT_SUB.CENTER_X.name()))
|
||||||
|
list.add(String.valueOf(((Player) sendi).getLocation().getBlockX()));
|
||||||
|
else if (args[2].equalsIgnoreCase(RTP_CMD_EDIT_SUB.CENTER_Z.name()))
|
||||||
|
list.add(String.valueOf(((Player) sendi).getLocation().getBlockZ()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (args.length == 5) {
|
||||||
|
for (RTP_CMD_EDIT cmd : RTP_CMD_EDIT.values())
|
||||||
|
if (cmd.name().equalsIgnoreCase(args[1]))
|
||||||
|
if (cmd == RTP_CMD_EDIT.WORLD) {
|
||||||
|
if (args[3].equalsIgnoreCase(RTP_CMD_EDIT_SUB.CENTER_X.name()))
|
||||||
|
list.add(String.valueOf(((Player) sendi).getLocation().getBlockX()));
|
||||||
|
else if (args[3].equalsIgnoreCase(RTP_CMD_EDIT_SUB.CENTER_Z.name()))
|
||||||
|
list.add(String.valueOf(((Player) sendi).getLocation().getBlockZ()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
@ -195,7 +213,7 @@ public class CmdEdit implements RTPCommand, RTPCommandHelpable { //Edit a worlds
|
|||||||
|
|
||||||
enum RTP_CMD_EDIT_SUB {
|
enum RTP_CMD_EDIT_SUB {
|
||||||
CENTER_X("CenterX", "INT"),
|
CENTER_X("CenterX", "INT"),
|
||||||
CENTER_Y("CenterY", "INT"),
|
CENTER_Z("CenterZ", "INT"),
|
||||||
MAX("MaxRadius", "INT"),
|
MAX("MaxRadius", "INT"),
|
||||||
MIN("MinRadius", "INT"),
|
MIN("MinRadius", "INT"),
|
||||||
USEWORLDBORDER("UseWorldBorder", "BOL");
|
USEWORLDBORDER("UseWorldBorder", "BOL");
|
||||||
|
@ -64,9 +64,7 @@ public class CmdInfo implements RTPCommand, RTPCommandHelpable {
|
|||||||
Main pl = Main.getInstance();
|
Main pl = Main.getInstance();
|
||||||
|
|
||||||
for (ParticleEffect eff : ParticleEffect.VALUES) {
|
for (ParticleEffect eff : ParticleEffect.VALUES) {
|
||||||
if (info.isEmpty()) {
|
if (info.isEmpty() || info.size() % 2 == 0) {
|
||||||
info.add("&7" + eff.name() + "&r");
|
|
||||||
} else if (info.size() % 2 == 0) {
|
|
||||||
info.add("&7" + eff.name() + "&r");
|
info.add("&7" + eff.name() + "&r");
|
||||||
} else
|
} else
|
||||||
info.add("&f" + eff.name() + "&r");
|
info.add("&f" + eff.name() + "&r");
|
||||||
@ -82,9 +80,7 @@ public class CmdInfo implements RTPCommand, RTPCommandHelpable {
|
|||||||
List<String> info = new ArrayList<>();
|
List<String> info = new ArrayList<>();
|
||||||
|
|
||||||
for (String shape : RTPParticles.shapeTypes) {
|
for (String shape : RTPParticles.shapeTypes) {
|
||||||
if (info.isEmpty()) {
|
if (info.isEmpty() || info.size() % 2 == 0) {
|
||||||
info.add("&7" + shape + "&r");
|
|
||||||
} else if (info.size() % 2 == 0) {
|
|
||||||
info.add("&7" + shape + "&r");
|
info.add("&7" + shape + "&r");
|
||||||
} else
|
} else
|
||||||
info.add("&f" + shape + "&r");
|
info.add("&f" + shape + "&r");
|
||||||
@ -97,7 +93,7 @@ public class CmdInfo implements RTPCommand, RTPCommandHelpable {
|
|||||||
|
|
||||||
//World
|
//World
|
||||||
private void sendInfoWorld(CommandSender sendi, List<String> list) { //Send info
|
private void sendInfoWorld(CommandSender sendi, List<String> list) { //Send info
|
||||||
list.add(0, "&e&m-----&6 BetterRTP Info &e&m-----");
|
list.add(0, "&e&m-----&6 BetterRTP &8| Info &e&m-----");
|
||||||
list.forEach(str ->
|
list.forEach(str ->
|
||||||
list.set(list.indexOf(str), Main.getInstance().getText().color(str)));
|
list.set(list.indexOf(str), Main.getInstance().getText().color(str)));
|
||||||
sendi.sendMessage(list.toArray(new String[0]));
|
sendi.sendMessage(list.toArray(new String[0]));
|
||||||
@ -144,9 +140,7 @@ public class CmdInfo implements RTPCommand, RTPCommandHelpable {
|
|||||||
List<String> info = new ArrayList<>();
|
List<String> info = new ArrayList<>();
|
||||||
|
|
||||||
for (PotionEffectType effect : PotionEffectType.values()) {
|
for (PotionEffectType effect : PotionEffectType.values()) {
|
||||||
if (info.isEmpty()) {
|
if (info.isEmpty() || info.size() % 2 == 0) {
|
||||||
info.add("&7" + effect.getName() + "&r");
|
|
||||||
} else if (info.size() % 2 == 0) {
|
|
||||||
info.add("&7" + effect.getName() + "&r");
|
info.add("&7" + effect.getName() + "&r");
|
||||||
} else
|
} else
|
||||||
info.add("&f" + effect.getName() + "&r");
|
info.add("&f" + effect.getName() + "&r");
|
||||||
|
@ -5,9 +5,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
|||||||
|
|
||||||
class Leave {
|
class Leave {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
void event(PlayerQuitEvent e) {
|
void event(PlayerQuitEvent e) {
|
||||||
if (Main.getInstance().getCmd().rtping.containsKey(e.getPlayer().getUniqueId()))
|
|
||||||
Main.getInstance().getCmd().rtping.remove(e.getPlayer().getUniqueId());
|
Main.getInstance().getCmd().rtping.remove(e.getPlayer().getUniqueId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,34 +1,29 @@
|
|||||||
package me.SuperRonanCraft.BetterRTP.player.rtp;
|
package me.SuperRonanCraft.BetterRTP.player.rtp;
|
||||||
|
|
||||||
import io.papermc.lib.PaperLib;
|
|
||||||
import me.SuperRonanCraft.BetterRTP.Main;
|
import me.SuperRonanCraft.BetterRTP.Main;
|
||||||
import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
|
import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
|
||||||
import me.SuperRonanCraft.BetterRTP.references.worlds.*;
|
import me.SuperRonanCraft.BetterRTP.references.worlds.*;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
public class RTP {
|
public class RTP {
|
||||||
|
|
||||||
private final RTPTeleport teleport = new RTPTeleport();
|
final RTPTeleport teleport = new RTPTeleport();
|
||||||
private final RTPPluginValidation softDepends = new RTPPluginValidation();
|
final RTPPluginValidation softDepends = new RTPPluginValidation();
|
||||||
public final RTPPermissionGroup permConfig = new RTPPermissionGroup();
|
public final RTPPermissionGroup permConfig = new RTPPermissionGroup();
|
||||||
//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 WorldDefault defaultWorld = new WorldDefault();
|
public WorldDefault defaultWorld = new WorldDefault();
|
||||||
private List<String> disabledWorlds, blockList;
|
List<String> disabledWorlds, blockList;
|
||||||
private int maxAttempts, delayTime;
|
int maxAttempts, delayTime;
|
||||||
private boolean cancelOnMove, cancelOnDamage;
|
boolean cancelOnMove, cancelOnDamage;
|
||||||
public HashMap<String, WORLD_TYPE> world_type = new HashMap<>();
|
public HashMap<String, WORLD_TYPE> world_type = new HashMap<>();
|
||||||
|
|
||||||
public RTPTeleport getTeleport() {
|
public RTPTeleport getTeleport() {
|
||||||
@ -137,148 +132,11 @@ public class RTP {
|
|||||||
return pWorld;
|
return pWorld;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start(Player p, CommandSender sendi, String worldName, List<String> biomes, boolean delay) {
|
|
||||||
// Check overrides
|
|
||||||
if (worldName == null)
|
|
||||||
worldName = p.getWorld().getName();
|
|
||||||
if (overriden.containsKey(worldName))
|
|
||||||
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().getText().getNoPermissionWorld(p, worldName);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Check disabled worlds
|
|
||||||
if (disabledWorlds.contains(worldName)) {
|
|
||||||
getPl().getText().getDisabledWorld(sendi, worldName);
|
|
||||||
//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());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
WorldPlayer pWorld = getPlayerWorld(p, worldName, biomes, true);
|
|
||||||
// Economy
|
|
||||||
if (!getPl().getEco().charge(p, pWorld.getPrice())) {
|
|
||||||
//getPl().getCmd().cooldowns.remove(p.getUniqueId());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//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) {
|
|
||||||
new RTPDelay(sendi, pWorld, delayTime, cancelOnMove, cancelOnDamage);
|
|
||||||
} else {
|
|
||||||
teleport.beforeTeleportInstant(p);
|
|
||||||
findSafeLocation(sendi, pWorld);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void findSafeLocation(CommandSender sendi, WorldPlayer pWorld) {
|
|
||||||
if (pWorld.getAttempts() >= maxAttempts) //Cancel out, too many tried
|
|
||||||
metMax(sendi, pWorld.getPlayer(), pWorld.getPrice());
|
|
||||||
else { //Try again to find a safe location
|
|
||||||
Location loc = pWorld.generateRandomXZ(defaultWorld); //randomLoc(pWorld);
|
|
||||||
CompletableFuture<Chunk> chunk = PaperLib.getChunkAtAsync(pWorld.getWorld(), loc.getBlockX(), loc.getBlockZ());
|
|
||||||
chunk.thenAccept(result -> {
|
|
||||||
Location tpLoc;
|
|
||||||
float yaw = pWorld.getPlayer().getLocation().getYaw();
|
|
||||||
float pitch = pWorld.getPlayer().getLocation().getPitch();
|
|
||||||
switch (pWorld.getWorldtype()) { //Get a Y position and check for bad blocks
|
|
||||||
case NETHER:
|
|
||||||
tpLoc = getLocAtNether(loc.getBlockX(), loc.getBlockZ(), pWorld.getWorld(), yaw, pitch, pWorld); break;
|
|
||||||
case NORMAL:
|
|
||||||
default:
|
|
||||||
tpLoc = getLocAtNormal(loc.getBlockX(), loc.getBlockZ(), pWorld.getWorld(), yaw, pitch, pWorld);
|
|
||||||
}
|
|
||||||
if (tpLoc != null && checkDepends(tpLoc))
|
|
||||||
teleport.sendPlayer(sendi, pWorld.getPlayer(), tpLoc, pWorld.getPrice(), pWorld.getAttempts());
|
|
||||||
else
|
|
||||||
findSafeLocation(sendi, pWorld);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compressed code for MaxAttempts being met
|
|
||||||
private void metMax(CommandSender sendi, Player p, int price) {
|
|
||||||
if (p == sendi)
|
|
||||||
getPl().getText().getFailedNotSafe(sendi, maxAttempts);
|
|
||||||
else
|
|
||||||
getPl().getText().getOtherNotSafe(sendi, maxAttempts, p.getDisplayName());
|
|
||||||
getPl().getCmd().cooldowns.remove(p.getUniqueId());
|
|
||||||
getPl().getEco().unCharge(p, price);
|
|
||||||
getPl().getCmd().rtping.put(p.getUniqueId(), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Location getLocAtNormal(int x, int z, World world, Float yaw, Float pitch, WorldPlayer pWorld) {
|
|
||||||
Block b = world.getHighestBlockAt(x, z);
|
|
||||||
if (b.getType().toString().endsWith("AIR")) //1.15.1 or less
|
|
||||||
b = world.getBlockAt(x, b.getY() - 1, z);
|
|
||||||
else if (!b.getType().isSolid()) { //Water, lava, shrubs...
|
|
||||||
if (!badBlock(b.getType().name(), x, z, pWorld.getWorld(), null)) { //Make sure it's not an invalid block (ex: water, lava...)
|
|
||||||
//int y = world.getHighestBlockYAt(x, z);
|
|
||||||
b = world.getBlockAt(x, b.getY() - 1, z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//System.out.println(b.getType().name());
|
|
||||||
if (b.getY() > 0 && !badBlock(b.getType().name(), x, z, pWorld.getWorld(), pWorld.getBiomes())) {
|
|
||||||
return new Location(world, (x + 0.5), b.getY() + 1, (z + 0.5), yaw, pitch);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Location getLocAtNether(int x, int z, World world, Float yaw, Float pitch, WorldPlayer pWorld) {
|
|
||||||
//System.out.println("-----------");
|
|
||||||
for (int y = 1; y < world.getMaxHeight(); y++) {
|
|
||||||
// System.out.println("--");
|
|
||||||
Block block_current = world.getBlockAt(x, y, z);
|
|
||||||
//System.out.println(block_current.getType().name());
|
|
||||||
if (block_current.getType().name().endsWith("AIR") || !block_current.getType().isSolid()) {
|
|
||||||
//System.out.println(block_current.getType().name());
|
|
||||||
if (!block_current.getType().name().endsWith("AIR") &&
|
|
||||||
!block_current.getType().isSolid()) { //Block is not a solid (ex: lava, water...)
|
|
||||||
String block_in = block_current.getType().name();
|
|
||||||
if (badBlock(block_in, x, z, pWorld.getWorld(), null))
|
|
||||||
continue;//return null;
|
|
||||||
}
|
|
||||||
//System.out.println(block_current.getType().name());
|
|
||||||
String block = world.getBlockAt(x, y - 1, z).getType().name();
|
|
||||||
if (block.endsWith("AIR")) //Block below is air, skip
|
|
||||||
continue;
|
|
||||||
if (world.getBlockAt(x, y + 1, z).getType().name().endsWith("AIR") //Head space
|
|
||||||
&& !badBlock(block, x, z, pWorld.getWorld(), pWorld.getBiomes())) //Valid block
|
|
||||||
return new Location(world, (x + 0.5), y, (z + 0.5), yaw, pitch);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean checkDepends(Location loc) {
|
|
||||||
return softDepends.checkLocation(loc);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bad blocks, or bad biome
|
|
||||||
private boolean badBlock(String block, int x, int z, World world, List<String> biomes) {
|
|
||||||
for (String currentBlock : blockList) //Check Block
|
|
||||||
if (currentBlock.toUpperCase().equals(block))
|
|
||||||
return true;
|
|
||||||
//Check Biomes
|
|
||||||
if (biomes == null || biomes.isEmpty())
|
|
||||||
return false;
|
|
||||||
String biomeCurrent = world.getBiome(x, z).name();
|
|
||||||
for (String biome : biomes)
|
|
||||||
if (biomeCurrent.toUpperCase().contains(biome.toUpperCase()))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
//FALSE MEANS NO BAD BLOCKS/BIOME WHERE FOUND!
|
|
||||||
}
|
|
||||||
|
|
||||||
private Main getPl() {
|
private Main getPl() {
|
||||||
return Main.getInstance();
|
return Main.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void start(Player p, CommandSender sendi, String world_name, List<String> biomes, boolean delay) {
|
||||||
|
new RTPPlayer(p, this).teleport(sendi, world_name, biomes, delay);
|
||||||
|
}
|
||||||
}
|
}
|
@ -15,11 +15,13 @@ class RTPDelay implements Listener {
|
|||||||
private int run;
|
private int run;
|
||||||
private final WorldPlayer pWorld;
|
private final WorldPlayer pWorld;
|
||||||
private final boolean cancelOnMove, cancelOnDamage;
|
private final boolean cancelOnMove, cancelOnDamage;
|
||||||
|
private final RTPPlayer rtp;
|
||||||
|
|
||||||
RTPDelay(CommandSender sendi, WorldPlayer pWorld, int delay, boolean cancelOnMove, boolean cancelOnDamage) {
|
RTPDelay(CommandSender sendi, RTPPlayer rtp, 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;
|
||||||
|
this.rtp = rtp;
|
||||||
delay(sendi, delay);
|
delay(sendi, delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,17 +70,8 @@ class RTPDelay implements Listener {
|
|||||||
private Runnable run(final CommandSender sendi, final RTPDelay cls) {
|
private Runnable run(final CommandSender sendi, final RTPDelay cls) {
|
||||||
return () -> {
|
return () -> {
|
||||||
HandlerList.unregisterAll(cls);
|
HandlerList.unregisterAll(cls);
|
||||||
if (getPl().getCmd().rtping.containsKey(pWorld.getPlayer().getUniqueId())) {
|
if (getPl().getCmd().rtping.containsKey(pWorld.getPlayer().getUniqueId()))
|
||||||
try {
|
rtp.findSafeLocation(sendi, pWorld);
|
||||||
getPl().getRTP().findSafeLocation(sendi, pWorld);
|
|
||||||
} catch (NullPointerException e) {
|
|
||||||
if (pWorld.getPrice() > 0)
|
|
||||||
getPl().getEco().unCharge(pWorld.getPlayer(), pWorld.getPrice());
|
|
||||||
}
|
|
||||||
getPl().getCmd().rtping.put(pWorld.getPlayer().getUniqueId(), false);
|
|
||||||
} else if (pWorld.getPrice() > 0)
|
|
||||||
getPl().getEco().unCharge(pWorld.getPlayer(), pWorld.getPrice());
|
|
||||||
Bukkit.getScheduler().cancelTask(run);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,171 @@
|
|||||||
|
package me.SuperRonanCraft.BetterRTP.player.rtp;
|
||||||
|
|
||||||
|
import io.papermc.lib.PaperLib;
|
||||||
|
import me.SuperRonanCraft.BetterRTP.Main;
|
||||||
|
import me.SuperRonanCraft.BetterRTP.references.worlds.*;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Chunk;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
public class RTPPlayer {
|
||||||
|
|
||||||
|
private final Player p;
|
||||||
|
private final RTP settings;
|
||||||
|
|
||||||
|
RTPPlayer(Player p, RTP settings) {
|
||||||
|
this.p = p;
|
||||||
|
this.settings = settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void teleport(CommandSender sendi, String worldName, List<String> biomes, boolean delay) {
|
||||||
|
// Check overrides
|
||||||
|
if (worldName == null)
|
||||||
|
worldName = p.getWorld().getName();
|
||||||
|
if (settings.overriden.containsKey(worldName))
|
||||||
|
worldName = settings.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().getText().getNoPermissionWorld(p, worldName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Check disabled worlds
|
||||||
|
if (settings.disabledWorlds.contains(worldName)) {
|
||||||
|
getPl().getText().getDisabledWorld(sendi, worldName);
|
||||||
|
//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());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
WorldPlayer pWorld = settings.getPlayerWorld(p, worldName, biomes, true);
|
||||||
|
// Economy
|
||||||
|
if (!getPl().getEco().charge(p, pWorld.getPrice())) {
|
||||||
|
//getPl().getCmd().cooldowns.remove(p.getUniqueId());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//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) {
|
||||||
|
new RTPDelay(sendi, this, pWorld, settings.delayTime, settings.cancelOnMove, settings.cancelOnDamage);
|
||||||
|
} else {
|
||||||
|
settings.teleport.beforeTeleportInstant(p);
|
||||||
|
findSafeLocation(sendi, pWorld);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void findSafeLocation(CommandSender sendi, WorldPlayer pWorld) {
|
||||||
|
if (pWorld.getAttempts() >= settings.maxAttempts) //Cancel out, too many tried
|
||||||
|
metMax(sendi, pWorld.getPlayer(), pWorld.getPrice());
|
||||||
|
else { //Try again to find a safe location
|
||||||
|
Location loc = pWorld.generateRandomXZ(settings.defaultWorld); //randomLoc(pWorld);
|
||||||
|
CompletableFuture<Chunk> chunk = PaperLib.getChunkAtAsync(pWorld.getWorld(), loc.getBlockX(), loc.getBlockZ());
|
||||||
|
chunk.thenAccept(result -> {
|
||||||
|
Location tpLoc;
|
||||||
|
float yaw = pWorld.getPlayer().getLocation().getYaw();
|
||||||
|
float pitch = pWorld.getPlayer().getLocation().getPitch();
|
||||||
|
switch (pWorld.getWorldtype()) { //Get a Y position and check for bad blocks
|
||||||
|
case NETHER:
|
||||||
|
tpLoc = getLocAtNether(loc.getBlockX(), loc.getBlockZ(), pWorld.getWorld(), yaw, pitch, pWorld); break;
|
||||||
|
case NORMAL:
|
||||||
|
default:
|
||||||
|
tpLoc = getLocAtNormal(loc.getBlockX(), loc.getBlockZ(), pWorld.getWorld(), yaw, pitch, pWorld);
|
||||||
|
}
|
||||||
|
if (tpLoc != null && checkDepends(tpLoc))
|
||||||
|
settings.teleport.sendPlayer(sendi, pWorld.getPlayer(), tpLoc, pWorld.getPrice(), pWorld.getAttempts());
|
||||||
|
else
|
||||||
|
findSafeLocation(sendi, pWorld);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compressed code for MaxAttempts being met
|
||||||
|
private void metMax(CommandSender sendi, Player p, int price) {
|
||||||
|
if (p == sendi)
|
||||||
|
getPl().getText().getFailedNotSafe(sendi, settings.maxAttempts);
|
||||||
|
else
|
||||||
|
getPl().getText().getOtherNotSafe(sendi, settings.maxAttempts, p.getDisplayName());
|
||||||
|
getPl().getCmd().cooldowns.remove(p.getUniqueId());
|
||||||
|
getPl().getEco().unCharge(p, price);
|
||||||
|
getPl().getCmd().rtping.put(p.getUniqueId(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Location getLocAtNormal(int x, int z, World world, Float yaw, Float pitch, WorldPlayer pWorld) {
|
||||||
|
Block b = world.getHighestBlockAt(x, z);
|
||||||
|
if (b.getType().toString().endsWith("AIR")) //1.15.1 or less
|
||||||
|
b = world.getBlockAt(x, b.getY() - 1, z);
|
||||||
|
else if (!b.getType().isSolid()) { //Water, lava, shrubs...
|
||||||
|
if (!badBlock(b.getType().name(), x, z, pWorld.getWorld(), null)) { //Make sure it's not an invalid block (ex: water, lava...)
|
||||||
|
//int y = world.getHighestBlockYAt(x, z);
|
||||||
|
b = world.getBlockAt(x, b.getY() - 1, z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//System.out.println(b.getType().name());
|
||||||
|
if (b.getY() > 0 && !badBlock(b.getType().name(), x, z, pWorld.getWorld(), pWorld.getBiomes())) {
|
||||||
|
return new Location(world, (x + 0.5), b.getY() + 1, (z + 0.5), yaw, pitch);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Location getLocAtNether(int x, int z, World world, Float yaw, Float pitch, WorldPlayer pWorld) {
|
||||||
|
//System.out.println("-----------");
|
||||||
|
for (int y = 1; y < world.getMaxHeight(); y++) {
|
||||||
|
// System.out.println("--");
|
||||||
|
Block block_current = world.getBlockAt(x, y, z);
|
||||||
|
//System.out.println(block_current.getType().name());
|
||||||
|
if (block_current.getType().name().endsWith("AIR") || !block_current.getType().isSolid()) {
|
||||||
|
//System.out.println(block_current.getType().name());
|
||||||
|
if (!block_current.getType().name().endsWith("AIR") &&
|
||||||
|
!block_current.getType().isSolid()) { //Block is not a solid (ex: lava, water...)
|
||||||
|
String block_in = block_current.getType().name();
|
||||||
|
if (badBlock(block_in, x, z, pWorld.getWorld(), null))
|
||||||
|
continue;//return null;
|
||||||
|
}
|
||||||
|
//System.out.println(block_current.getType().name());
|
||||||
|
String block = world.getBlockAt(x, y - 1, z).getType().name();
|
||||||
|
if (block.endsWith("AIR")) //Block below is air, skip
|
||||||
|
continue;
|
||||||
|
if (world.getBlockAt(x, y + 1, z).getType().name().endsWith("AIR") //Head space
|
||||||
|
&& !badBlock(block, x, z, pWorld.getWorld(), pWorld.getBiomes())) //Valid block
|
||||||
|
return new Location(world, (x + 0.5), y, (z + 0.5), yaw, pitch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkDepends(Location loc) {
|
||||||
|
return settings.softDepends.checkLocation(loc);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bad blocks, or bad biome
|
||||||
|
private boolean badBlock(String block, int x, int z, World world, List<String> biomes) {
|
||||||
|
for (String currentBlock : settings.blockList) //Check Block
|
||||||
|
if (currentBlock.toUpperCase().equals(block))
|
||||||
|
return true;
|
||||||
|
//Check Biomes
|
||||||
|
if (biomes == null || biomes.isEmpty())
|
||||||
|
return false;
|
||||||
|
String biomeCurrent = world.getBiome(x, z).name();
|
||||||
|
for (String biome : biomes)
|
||||||
|
if (biomeCurrent.toUpperCase().contains(biome.toUpperCase()))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
//FALSE MEANS NO BAD BLOCKS/BIOME WHERE FOUND!
|
||||||
|
}
|
||||||
|
|
||||||
|
private Main getPl() {
|
||||||
|
return Main.getInstance();
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
main: me.SuperRonanCraft.BetterRTP.Main
|
main: me.SuperRonanCraft.BetterRTP.Main
|
||||||
version: '2.14.0'
|
version: '2.14.1'
|
||||||
name: BetterRTP
|
name: BetterRTP
|
||||||
author: SuperRonanCraft
|
author: SuperRonanCraft
|
||||||
softdepend: [Vault, WorldGuard, GriefPrevention, Towny, Factions, RedProtect]
|
softdepend: [Vault, WorldGuard, GriefPrevention, Towny, Factions, RedProtect]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user