Skip to content

Commit

Permalink
Add /pw set transfer for 1.20.5.
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorfromhell committed Apr 28, 2024
1 parent eea4bad commit 8699014
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.20.1-R0.1-SNAPSHOT</version>
<version>1.20.5-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import me.lokka30.microlib.messaging.MultiMessage;
import me.lokka30.phantomworlds.PhantomWorlds;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.event.EventHandler;
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;

/**
Expand Down Expand Up @@ -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());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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!'
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/me/lokka30/phantomworlds/misc/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
15 changes: 14 additions & 1 deletion src/main/resources/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -29,6 +32,7 @@ command:
- '&8 &m->&b /%label% set effects <world> [effects] &8- &7set the potion effects to be applied to players in this world.'
- '&8 &m->&b /%label% set gamemode <world> <gamemode> &8- &7set the gamemode for this world.'
- '&8 &m->&b /%label% set portal <world> <portal type> <world to> &8- &7set where the specified portal type takes players in this world.'
- '&8 &m->&b /%label% set transfer <world> <portal type> <ip:port> &8- &7set the server where the specified portal type takes players in this world.'
- '&8 &m->&b /%label% set whitelist <world> <whitelist(true/false)> &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'
Expand All @@ -51,6 +55,7 @@ command:
seteffects: '&b/pw set effects <world> [effects] &8- &7set the potion effects to be applied to players in this world.'
setgamemode: '&b/pw set gamemode <world> <gamemode> &8- &7set the gamemode for this world.'
setportal: '&b/pw set portal <world> <portal type> <world to> &8- &7set where the specified portal type takes players in this world.'
settransfer: '&b/pw set transfer <world> <portal type> <ip:port> &8- &7set the server where the specified portal type takes players in this world.'
setwhitelist: '&b/pw set whitelist <world> <whitelist(true/false)> &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 <world> &8- &7delete a world'
Expand Down Expand Up @@ -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 <world> <portal type> <ip:port> &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:
Expand Down Expand Up @@ -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}'

0 comments on commit 8699014

Please sign in to comment.