Skip to content

Commit

Permalink
Add message when denied tp to a world.
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorfromhell committed Feb 25, 2024
1 parent 7ef32bf commit 04ed44a
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.lokka30</groupId>
<artifactId>PhantomWorlds</artifactId>
<version>2.0.5</version>
<version>2.0.6</version>

<name>PhantomWorlds</name>
<description>The Robust World Manager for Minecraft Servers</description>
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/me/lokka30/phantomworlds/PhantomWorlds.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void onEnable() {

if(settings.getConfig().getBoolean("backup-scheduler", true)) {
getLogger().info("Starting up Backup scheduler...");
backupService = new BackupScheduler().runTaskTimerAsynchronously(this, settings.getConfig().getInt("backup-delay") * 20L, settings.getConfig().getInt("backup-delay") * 20L);
backupService = new BackupScheduler().runTaskTimerAsynchronously(this, settings.getConfig().getInt("backup-delay", 600) * 20L, settings.getConfig().getInt("backup-delay", 600) * 20L);
}

getLogger().info("Start-up complete (took " + timer.getDuration() + "ms)");
Expand Down Expand Up @@ -230,7 +230,6 @@ void registerCommands() {
this.command = LiteBukkitFactory.builder()
.commands(new PWCommand())
.settings(settings -> settings
.fallbackPrefix("phantomworlds")
.nativePermissions(false)
)
.argument(GameMode.class, new GamemodeParameter())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
* @author creatorfromhell
* @since 2.0.5.0
*/
@Command(name = "phantomworlds", aliases = {"pw"})
@Command(name = "pw", aliases = {"phantomworlds"})
public class PWCommand {

@Execute(name = "backup", aliases = {"archive", "bu"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
* 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.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerTeleportEvent;

import java.util.Arrays;

/**
* PlayerTeleportEvent
*
Expand All @@ -48,14 +51,32 @@ public void onPortal(PlayerTeleportEvent event) {

final String cfgPath = "worlds-to-load." + event.getTo().getWorld().getName();

if(PhantomWorlds.instance().data.getConfig().getBoolean(cfgPath + ".whitelist", false)
if(!event.getPlayer().isOp() && PhantomWorlds.instance().data.getConfig().getBoolean(cfgPath + ".whitelist", false)
&& !event.getPlayer().hasPermission("phantomworlds.world.access." + event.getTo().getWorld().getName())) {
event.setCancelled(true);
return;
}

if(!event.getPlayer().isOp() && event.getPlayer().hasPermission("phantomworlds.world.deny." + event.getTo().getWorld().getName())) {
event.setCancelled(true);
}

if(plugin.worldManager.tpAwaiting.containsKey(event.getPlayer().getUniqueId())) {
if(!event.isCancelled()) {

(new MultiMessage(
PhantomWorlds.instance().messages.getConfig()
.getStringList("common.denied"),
Arrays.asList(
new MultiMessage.Placeholder("prefix", PhantomWorlds.instance().messages.getConfig()
.getString("common.prefix", "&b&lPhantomWorlds: &7"), true),
new MultiMessage.Placeholder("world", event.getTo().getWorld().getName(), false)
))).send(event.getPlayer());

} else {
plugin.worldManager.tpAwaiting.get(event.getPlayer().getUniqueId()).send(event.getPlayer());
}

plugin.worldManager.tpAwaiting.remove(event.getPlayer().getUniqueId());
}
}
}
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(2),
ADVANCED_SETTINGS(1),
MESSAGES(8),
MESSAGES(9),
DATA(2);

public final int latestFileVersion; // If == -1: 'do not migrate me!'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.lokka30.phantomworlds.managers;

import me.lokka30.microlib.messaging.MultiMessage;
import me.lokka30.phantomworlds.PhantomWorlds;
import me.lokka30.phantomworlds.misc.Utils;
import me.lokka30.phantomworlds.misc.WorldLoadResponse;
Expand All @@ -16,6 +17,8 @@
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

import static me.lokka30.phantomworlds.misc.Utils.zipFolder;

Expand All @@ -29,6 +32,8 @@ public class WorldManager {

public final Map<String, String> aliases = new LinkedHashMap<>();

public final Map<UUID, MultiMessage> tpAwaiting = new LinkedHashMap<>();

/**
* For all worlds listed in PW's data file, if they aren't already loaded by Bukkit, then tell
* Bukkit to load them
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/me/lokka30/phantomworlds/misc/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,8 @@ public static void teleportToWorld(@NotNull CommandSender sender, @NotNull Strin
))).send(sender);
return;
}
targetPlayer.teleport(parseSpawn(world));

(new MultiMessage(
PhantomWorlds.worldManager().tpAwaiting.put(targetPlayer.getUniqueId(), new MultiMessage(
PhantomWorlds.instance().messages.getConfig()
.getStringList("command.phantomworlds.subcommands." + subCommand + ".success"),
Arrays.asList(
Expand All @@ -369,7 +368,9 @@ public static void teleportToWorld(@NotNull CommandSender sender, @NotNull Strin
true),
new MultiMessage.Placeholder("player", targetPlayer.getName(), false),
new MultiMessage.Placeholder("world", worldName, false)
))).send(sender);
)));

targetPlayer.teleport(parseSpawn(world));
}

public static Location parseSpawn(final World world) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ common:

list-delimiter: '&7, &b'

denied: '%prefix% You do not have access to the world ''&b%world%&7''.'

command:

phantomworlds:
Expand Down Expand Up @@ -346,5 +348,5 @@ command:

# Do not touch anything here unless you know what you are doing.
advanced:
file-version: 8
file-version: 9
generated-with: '${project.version}'
4 changes: 2 additions & 2 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# / / | `.__/| / | \__/ `._.' / ' / |,' \,' `._.' / /\__ `___,' \___.'

name: 'PhantomWorlds'
version: '2.05'
version: '2.06'
description: 'The Robust World Manager for Minecraft Servers'
authors: [ 'creatorfromhell', 'lokka30' ]
website: 'https://github.com/lokka30/PhantomWorlds'
Expand Down Expand Up @@ -122,7 +122,7 @@ permissions:
description: 'Ability to run /pw set whitelist'

phantomworlds.command.phantomworlds.teleport:
default: op
default: true
description: 'Ability to run /pw teleport'

phantomworlds.command.phantomworlds.spawn:
Expand Down

0 comments on commit 04ed44a

Please sign in to comment.