diff --git a/pom.xml b/pom.xml index 9fb0437..35ebeb9 100644 --- a/pom.xml +++ b/pom.xml @@ -44,7 +44,7 @@ org.spigotmc spigot-api - 1.20.1-R0.1-SNAPSHOT + 1.20.5-R0.1-SNAPSHOT provided diff --git a/src/main/java/me/lokka30/phantomworlds/commands/PWCommand.java b/src/main/java/me/lokka30/phantomworlds/commands/PWCommand.java index 433fa54..401eda3 100644 --- a/src/main/java/me/lokka30/phantomworlds/commands/PWCommand.java +++ b/src/main/java/me/lokka30/phantomworlds/commands/PWCommand.java @@ -41,6 +41,7 @@ import me.lokka30.phantomworlds.commands.sub.set.SetEffectsCommand; import me.lokka30.phantomworlds.commands.sub.set.SetGamemodeCommand; import me.lokka30.phantomworlds.commands.sub.set.SetPortalCommand; +import me.lokka30.phantomworlds.commands.sub.set.SetTransferCommand; import me.lokka30.phantomworlds.commands.sub.set.SetWhitelistCommand; import me.lokka30.phantomworlds.commands.utils.WorldFolder; import org.bukkit.GameMode; @@ -151,6 +152,13 @@ public void setPortal(@Context CommandSender commandSender, @Arg("world") World SetPortalCommand.onCommand(commandSender, world, portal, worldTo); } + @Execute(name = "set transfer") + @Permission("phantomworlds.command.phantomworlds.set.transfer") + @Description("command.phantomworlds.help.settransfer") + public void setPortal(@Context CommandSender commandSender, @Arg("world") World world, @Arg("portal type") PortalType portal, @Arg("ip:port") String ip) { + SetTransferCommand.onCommand(commandSender, world, portal, ip); + } + @Execute(name = "set whitelist") @Permission("phantomworlds.command.phantomworlds.set.whitelist") @Description("command.phantomworlds.help.setwhitelist") diff --git a/src/main/java/me/lokka30/phantomworlds/commands/sub/set/SetTransferCommand.java b/src/main/java/me/lokka30/phantomworlds/commands/sub/set/SetTransferCommand.java new file mode 100644 index 0000000..62e1bb5 --- /dev/null +++ b/src/main/java/me/lokka30/phantomworlds/commands/sub/set/SetTransferCommand.java @@ -0,0 +1,72 @@ +package me.lokka30.phantomworlds.commands.sub.set; +/* + * Phantom Worlds + * Copyright (C) 2023 - 2024 Daniel "creatorfromhell" Vidmar + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import me.lokka30.microlib.messaging.MultiMessage; +import me.lokka30.phantomworlds.PhantomWorlds; +import me.lokka30.phantomworlds.misc.Utils; +import org.bukkit.PortalType; +import org.bukkit.World; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.io.IOException; +import java.util.Arrays; + +/** + * SetTransferCommand + * + * @author creatorfromhell + * @since 2.0.5.0 + */ +public class SetTransferCommand { + + public static void onCommand(final CommandSender sender, final World world, final PortalType portal, final String ip) { + if(!Utils.checkWorld(sender, "command.phantomworlds.subcommands.settransfer.usage", world)) { + return; + } + + final String type = (portal.equals(PortalType.ENDER))? "endtransfer" : "nethertransfer"; + + final World finalWorld = (world == null)? ((Player)sender).getWorld() : world; + + final String cfgPath = "worlds-to-load." + finalWorld.getName(); + if(PhantomWorlds.instance().data.getConfig().contains(cfgPath)) { + //PhantomWorlds manages this world so let's set the spawn here for better accuracy. + PhantomWorlds.instance().data.getConfig().set(cfgPath + "." + type, ip); + + try { + PhantomWorlds.instance().data.save(); + } catch(final IOException ex) { + throw new RuntimeException(ex); + } + + } + + (new MultiMessage( + PhantomWorlds.instance().messages.getConfig() + .getStringList("command.phantomworlds.subcommands.settransfer.success"), Arrays.asList( + new MultiMessage.Placeholder("prefix", + PhantomWorlds.instance().messages.getConfig().getString("common.prefix", "&b&lPhantomWorlds: &7"), + true), + new MultiMessage.Placeholder("world", finalWorld.getName(), false), + new MultiMessage.Placeholder("portal", portal.name(), false), + new MultiMessage.Placeholder("transfer", ip, false) + ))).send(sender); + } +} \ No newline at end of file diff --git a/src/main/java/me/lokka30/phantomworlds/listeners/player/PlayerPortalListener.java b/src/main/java/me/lokka30/phantomworlds/listeners/player/PlayerPortalListener.java index c7c54d9..a43afe4 100644 --- a/src/main/java/me/lokka30/phantomworlds/listeners/player/PlayerPortalListener.java +++ b/src/main/java/me/lokka30/phantomworlds/listeners/player/PlayerPortalListener.java @@ -17,6 +17,7 @@ * along with this program. If not, see . */ +import me.lokka30.microlib.messaging.MultiMessage; import me.lokka30.phantomworlds.PhantomWorlds; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -24,6 +25,8 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerPortalEvent; +import java.util.Arrays; + import static org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.END_PORTAL; /** @@ -64,5 +67,40 @@ public void onPortal(PlayerPortalEvent event) { } toLocation.setWorld(Bukkit.getWorld(to)); } + + final String transferConfig = (end)? ".endtransfer" : ".nethertransfer"; + + if(PhantomWorlds.instance().data.getConfig().contains(cfgPath + transferConfig)) { + event.setCancelled(true); + final String to = PhantomWorlds.instance().data.getConfig().getString(cfgPath + transferConfig); + + if(to == null) { + plugin.getLogger().warning("Configured transfer host doesn't exist!"); + (new MultiMessage( + PhantomWorlds.instance().messages.getConfig() + .getStringList("common.invalidtransfer"), Arrays.asList( + new MultiMessage.Placeholder("prefix", + PhantomWorlds.instance().messages.getConfig().getString("common.prefix", "&b&lPhantomWorlds: &7"), + true) + ))).send(event.getPlayer()); + return; + } + + final String[] details = to.split(":"); + + final int port = (details.length >= 2)? Integer.parseInt(details[1]) : 25565; + + try { + event.getPlayer().transfer(details[0], port); + } catch(NoSuchMethodError ignore) { + (new MultiMessage( + PhantomWorlds.instance().messages.getConfig() + .getStringList("common.invalidtransfer"), Arrays.asList( + new MultiMessage.Placeholder("prefix", + PhantomWorlds.instance().messages.getConfig().getString("common.prefix", "&b&lPhantomWorlds: &7"), + true) + ))).send(event.getPlayer()); + } + } } } \ No newline at end of file diff --git a/src/main/java/me/lokka30/phantomworlds/managers/FileManager.java b/src/main/java/me/lokka30/phantomworlds/managers/FileManager.java index ecdf5f8..9aec6fc 100644 --- a/src/main/java/me/lokka30/phantomworlds/managers/FileManager.java +++ b/src/main/java/me/lokka30/phantomworlds/managers/FileManager.java @@ -161,7 +161,7 @@ void alertIncorrectVersion(final PWFile pwFile) { public enum PWFile { SETTINGS(3), ADVANCED_SETTINGS(1), - MESSAGES(9), + MESSAGES(10), DATA(2); public final int latestFileVersion; // If == -1: 'do not migrate me!' diff --git a/src/main/java/me/lokka30/phantomworlds/misc/Utils.java b/src/main/java/me/lokka30/phantomworlds/misc/Utils.java index 4564385..d4f38b8 100644 --- a/src/main/java/me/lokka30/phantomworlds/misc/Utils.java +++ b/src/main/java/me/lokka30/phantomworlds/misc/Utils.java @@ -422,4 +422,8 @@ public static boolean isOneSeventeen(final String version) { version.contains("1.12") || version.contains("1.13") || version.contains("1.14") || version.contains("1.15") || version.contains("1.16"); } + + public static boolean isTwentyFive(final String version) { + return version.contains("1.20.5"); + } } \ No newline at end of file diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index 5991965..6368f59 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -15,6 +15,9 @@ common: denied: - '%prefix% You do not have access to the world ''&b%world%&7''.' + invalidtransfer: + - '%prefix% Server has improperly configured world transfer settings!' + command: phantomworlds: @@ -29,6 +32,7 @@ command: - '&8 &m->&b /%label% set effects [effects] &8- &7set the potion effects to be applied to players in this world.' - '&8 &m->&b /%label% set gamemode &8- &7set the gamemode for this world.' - '&8 &m->&b /%label% set portal &8- &7set where the specified portal type takes players in this world.' + - '&8 &m->&b /%label% set transfer &8- &7set the server where the specified portal type takes players in this world.' - '&8 &m->&b /%label% set whitelist &8- &7set whether there is a whitelist for this world or not.' - '&8 &m->&b /%label% setspawn &8- &7set the spawnpoint of a world' - '&8 &m->&b /%label% delete &8- &7delete a world' @@ -51,6 +55,7 @@ command: seteffects: '&b/pw set effects [effects] &8- &7set the potion effects to be applied to players in this world.' setgamemode: '&b/pw set gamemode &8- &7set the gamemode for this world.' setportal: '&b/pw set portal &8- &7set where the specified portal type takes players in this world.' + settransfer: '&b/pw set transfer &8- &7set the server where the specified portal type takes players in this world.' setwhitelist: '&b/pw set whitelist &8- &7set whether there is a whitelist for this world or not.' setspawn: '&b/pw setspawn [x] [y] [z] [world] [yaw] [pitch] &8- &7set the spawnpoint of a world' delete: '&b/pw delete &8- &7delete a world' @@ -266,6 +271,14 @@ command: success: - '%prefix% Successfully set the portal destination for portal ''&b%portal%&7'' of world ''&b%world%&7'' to world ''&b%world_to%&7''.' + settransfer: + + usage: + - '%prefix% Invalid usage, try ''&b/%label% set transfer &8- &7''.' + + success: + - '%prefix% Successfully set the server destination for portal ''&b%portal%&7'' of world ''&b%world%&7'' to world ''&b%transfer%&7''.' + setwhitelist: usage: @@ -349,5 +362,5 @@ command: # Do not touch anything here unless you know what you are doing. advanced: - file-version: 9 + file-version: 10 generated-with: '${project.version}' \ No newline at end of file