mirror of
https://github.com/RonanPlugins/BetterRTP.git
synced 2026-04-03 06:26:26 +00:00
Location command and world fix
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -7,7 +7,7 @@
|
||||
<groupId>me.SuperRonanCraft</groupId>
|
||||
<artifactId>BetterRTP</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>3.6.1</version>
|
||||
<version>3.6.2-DEV</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
|
||||
@@ -6,12 +6,11 @@ import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommandHelpable;
|
||||
import me.SuperRonanCraft.BetterRTP.player.rtp.RTP_TYPE;
|
||||
import me.SuperRonanCraft.BetterRTP.references.PermissionNode;
|
||||
import me.SuperRonanCraft.BetterRTP.references.helpers.HelperRTP;
|
||||
import me.SuperRonanCraft.BetterRTP.references.messages.Message_RTP;
|
||||
import me.SuperRonanCraft.BetterRTP.references.messages.MessagesCore;
|
||||
import me.SuperRonanCraft.BetterRTP.references.messages.MessagesHelp;
|
||||
import me.SuperRonanCraft.BetterRTP.references.messages.MessagesUsage;
|
||||
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.RTPWorld;
|
||||
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.WorldLocations;
|
||||
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.WorldLocation;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -34,9 +33,9 @@ public class CmdLocation implements RTPCommand, RTPCommandHelpable {
|
||||
if (args.length == 2) {
|
||||
if (sendi instanceof Player) {
|
||||
Player p = (Player) sendi;
|
||||
for (String location_name : getLocations(sendi, p.getWorld()).keySet())
|
||||
if (location_name.equalsIgnoreCase(args[1].toLowerCase())) {
|
||||
HelperRTP.tp(p, sendi, null, null, RTP_TYPE.COMMAND, false, false, (WorldLocations) getLocations().get(location_name));
|
||||
for (Map.Entry<String, RTPWorld> location : getLocations(sendi, p.getWorld()).entrySet())
|
||||
if (location.getKey().equalsIgnoreCase(args[1].toLowerCase())) {
|
||||
HelperRTP.tp(p, sendi, null, null, RTP_TYPE.COMMAND, false, false, (WorldLocation) location.getValue());
|
||||
return;
|
||||
}
|
||||
usage(sendi, label);
|
||||
@@ -47,7 +46,7 @@ public class CmdLocation implements RTPCommand, RTPCommandHelpable {
|
||||
if (p != null && p.isOnline()) {
|
||||
for (String location_name : getLocations(sendi, null).keySet()) {
|
||||
if (location_name.equalsIgnoreCase(args[1].toLowerCase())) {
|
||||
HelperRTP.tp(p, sendi, null, null, RTP_TYPE.COMMAND, false, false, (WorldLocations) getLocations().get(location_name));
|
||||
HelperRTP.tp(p, sendi, null, null, RTP_TYPE.COMMAND, false, false, (WorldLocation) getLocations().get(location_name));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ public class RTPLoader {
|
||||
List<Map<?, ?>> map = config.getMapList("Locations");
|
||||
for (Map<?, ?> m : map)
|
||||
for (Map.Entry<?, ?> entry : m.entrySet()) {
|
||||
WorldLocations location = new WorldLocations(entry.getKey().toString());
|
||||
WorldLocation location = new WorldLocation(entry.getKey().toString());
|
||||
if (location.isValid()) {
|
||||
worlds.put(entry.getKey().toString(), location);
|
||||
BetterRTP.debug("- Location '" + entry.getKey() + "' registered");
|
||||
|
||||
@@ -3,20 +3,13 @@ package me.SuperRonanCraft.BetterRTP.player.rtp;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
||||
import me.SuperRonanCraft.BetterRTP.player.commands.types.CmdLocation;
|
||||
import me.SuperRonanCraft.BetterRTP.references.helpers.HelperRTP;
|
||||
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.RTPWorld;
|
||||
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.WorldLocations;
|
||||
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.WorldLocation;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class RTPSetupInformation {
|
||||
//Will provide information to setup an RTP attempt
|
||||
@@ -26,7 +19,7 @@ public class RTPSetupInformation {
|
||||
@Getter private final boolean personalized;
|
||||
@Getter private final boolean cooldown;
|
||||
@Getter @Setter @Nullable private List<String> biomes;
|
||||
@Getter @Setter @Nullable private WorldLocations location;
|
||||
@Getter @Setter @Nullable private WorldLocation location;
|
||||
@Getter private final boolean delay;
|
||||
@Getter @Nullable private final RTP_TYPE rtp_type;
|
||||
|
||||
@@ -44,7 +37,7 @@ public class RTPSetupInformation {
|
||||
@Nullable List<String> biomes,
|
||||
boolean delay,
|
||||
@Nullable RTP_TYPE rtp_type,
|
||||
@Nullable WorldLocations location) {
|
||||
@Nullable WorldLocation location) {
|
||||
this(world, sender, player, personalized, biomes, delay, rtp_type, location, true);
|
||||
}
|
||||
|
||||
@@ -55,7 +48,7 @@ public class RTPSetupInformation {
|
||||
@Nullable List<String> biomes,
|
||||
boolean delay,
|
||||
@Nullable RTP_TYPE rtp_type,
|
||||
@Nullable WorldLocations location,
|
||||
@Nullable WorldLocation location,
|
||||
boolean cooldown) {
|
||||
this.world = world;
|
||||
this.sender = sender;
|
||||
@@ -68,8 +61,6 @@ public class RTPSetupInformation {
|
||||
if (this.world == null) {
|
||||
if (player != null)
|
||||
this.world = player.getWorld();
|
||||
else if (this.location != null)
|
||||
this.world = this.location.getWorld();
|
||||
}
|
||||
this.cooldown = cooldown;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import me.SuperRonanCraft.BetterRTP.references.PermissionNode;
|
||||
import me.SuperRonanCraft.BetterRTP.references.WarningHandler;
|
||||
import me.SuperRonanCraft.BetterRTP.references.messages.Message_RTP;
|
||||
import me.SuperRonanCraft.BetterRTP.references.messages.placeholder.Placeholders;
|
||||
import me.SuperRonanCraft.BetterRTP.references.player.HelperPlayer;
|
||||
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.PermissionGroup;
|
||||
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.*;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -41,8 +40,8 @@ public class HelperRTP {
|
||||
}
|
||||
|
||||
public static void tp(@NotNull Player player, CommandSender sendi, @Nullable World world, List<String> biomes, RTP_TYPE rtpType,
|
||||
boolean ignoreCooldown, boolean ignoreDelay, WorldLocations locations) {
|
||||
world = getActualWorld(player, world);
|
||||
boolean ignoreCooldown, boolean ignoreDelay, @Nullable WorldLocation location) {
|
||||
world = getActualWorld(player, world, location);
|
||||
RTPSetupInformation setup_info = new RTPSetupInformation(
|
||||
world,
|
||||
sendi,
|
||||
@@ -51,7 +50,7 @@ public class HelperRTP {
|
||||
biomes,
|
||||
!ignoreDelay && HelperRTP_Check.applyDelay(player, sendi),
|
||||
rtpType,
|
||||
locations,
|
||||
location,
|
||||
!ignoreCooldown && HelperRTP_Check.applyCooldown(sendi, player)
|
||||
);
|
||||
//RTP request cancelled reason
|
||||
@@ -74,21 +73,27 @@ public class HelperRTP {
|
||||
return BetterRTP.getInstance();
|
||||
}
|
||||
|
||||
public static World getActualWorld(Player player, World world) {
|
||||
public static World getActualWorld(Player player, World world, @Nullable WorldLocation location) {
|
||||
if (world == null)
|
||||
world = player.getWorld();
|
||||
if (location != null)
|
||||
world = location.getWorld();
|
||||
if (BetterRTP.getInstance().getRTP().overriden.containsKey(world.getName()))
|
||||
world = Bukkit.getWorld(BetterRTP.getInstance().getRTP().overriden.get(world.getName()));
|
||||
return world;
|
||||
}
|
||||
|
||||
public static World getActualWorld(Player player, World world) {
|
||||
return getActualWorld(player, world, null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static WorldLocations getRandomLocation(CommandSender sender, World world) {
|
||||
public static WorldLocation getRandomLocation(CommandSender sender, World world) {
|
||||
HashMap<String, RTPWorld> locations_permissible = CmdLocation.getLocations(sender, world);
|
||||
if (!locations_permissible.isEmpty()) {
|
||||
List<String> valuesList = new ArrayList<>(locations_permissible.keySet());
|
||||
String randomIndex = valuesList.get(new Random().nextInt(valuesList.size()));
|
||||
return (WorldLocations) locations_permissible.get(randomIndex);
|
||||
return (WorldLocation) locations_permissible.get(randomIndex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -98,7 +103,7 @@ public class HelperRTP {
|
||||
|
||||
//Random Location
|
||||
if (setup_info.getLocation() == null && BetterRTP.getInstance().getSettings().isUseLocationIfAvailable()) {
|
||||
WorldLocations worldLocation = HelperRTP.getRandomLocation(setup_info.getSender(), setup_info.getWorld());
|
||||
WorldLocation worldLocation = HelperRTP.getRandomLocation(setup_info.getSender(), setup_info.getWorld());
|
||||
if (worldLocation != null) {
|
||||
setup_info.setLocation(worldLocation);
|
||||
setup_info.setWorld(worldLocation.getWorld());
|
||||
@@ -121,6 +126,7 @@ public class HelperRTP {
|
||||
pWorld.setup(setup_name, setup_info.getLocation(), setup_info.getLocation().getBiomes());
|
||||
}
|
||||
|
||||
//Setup world (if no location pre-setup)
|
||||
if (!pWorld.isSetup()) {
|
||||
WorldPermissionGroup group = getGroup(pWorld);
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class WorldLocations implements RTPWorld, RTPWorld_Defaulted {
|
||||
public class WorldLocation implements RTPWorld, RTPWorld_Defaulted {
|
||||
private boolean useWorldborder;
|
||||
private int centerX, centerZ, maxRad, minRad, price, miny, maxy;
|
||||
private long cooldown;
|
||||
@@ -22,7 +22,7 @@ public class WorldLocations implements RTPWorld, RTPWorld_Defaulted {
|
||||
private RTP_SHAPE shape;
|
||||
private final String name;
|
||||
|
||||
public WorldLocations(String location_name) {
|
||||
public WorldLocation(String location_name) {
|
||||
FileOther.FILETYPE config = BetterRTP.getInstance().getFiles().getType(FileOther.FILETYPE.LOCATIONS);
|
||||
List<Map<?, ?>> map = config.getMapList("Locations");
|
||||
//WorldDefault worldDefault = BetterRTP.getInstance().getRTP().defaultWorld;
|
||||
@@ -44,7 +44,7 @@ public class WorldPlayer implements RTPWorld, RTPWorld_Defaulted {
|
||||
}
|
||||
|
||||
public void setup(String setup_name, RTPWorld world, List<String> biomes) {
|
||||
if (world instanceof WorldLocations) {
|
||||
if (world instanceof WorldLocation) {
|
||||
setup_type = RTP_SETUP_TYPE.LOCATION;
|
||||
} else if (world instanceof WorldCustom) {
|
||||
setup_type = RTP_SETUP_TYPE.CUSTOM_WORLD;
|
||||
|
||||
Reference in New Issue
Block a user