diff --git a/src/main/java/dev/plex/extras/TFMExtras.java b/src/main/java/dev/plex/extras/TFMExtras.java index efb271f..734ca22 100755 --- a/src/main/java/dev/plex/extras/TFMExtras.java +++ b/src/main/java/dev/plex/extras/TFMExtras.java @@ -2,6 +2,7 @@ package dev.plex.extras; import com.google.common.collect.ImmutableSet; import com.google.common.reflect.ClassPath; +import dev.plex.Plex; import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; @@ -35,7 +36,7 @@ public class TFMExtras extends PlexModule private ModuleConfig config; @Getter - private SlimeWorldHook slimeWorldHook = new SlimeWorldHook(); + private SlimeWorldHook slimeWorldHook; @Getter private final IslandHandler islandHandler = new IslandHandler(); @@ -47,7 +48,7 @@ public class TFMExtras extends PlexModule config = new ModuleConfig(this, "tfmextras/config.yml", "config.yml"); config.load(); jumpPads = new JumpPads(); - if (swmEnabled()) + if (enableIslands()) { slimeWorldHook = new SlimeWorldHook(); } @@ -58,7 +59,7 @@ public class TFMExtras extends PlexModule @Override public void enable() { - if (swmEnabled()) + if (enableIslands()) { slimeWorldHook.onEnable(this); registerCommand(new SlimeManagerCommand()); @@ -118,13 +119,15 @@ public class TFMExtras extends PlexModule addDefaultMessage("islandPermissionUpdated", "Your island permission for {0} has been updated to {1}.", "0 - Permission name", "1 - New value"); addDefaultMessage("cantModifyIsland", "You can't modify this player's island!"); addDefaultMessage("cantVisitIsland", "You can't visit this player's island!"); + addDefaultMessage("islandMemberExists", "This player is already a member of your island!"); + addDefaultMessage("receivedInviteForIsland", "You have been invited to join "); //TODO: Finish this message... my laptop isn't liking minecraft so I can't do formatting for it, and do receivedInviteForIsland message } @Override public void disable() { // Unregistering listeners / commands is handled by Plex - if (swmEnabled()) + if (enableIslands()) { slimeWorldHook.onDisable(this); } @@ -169,16 +172,16 @@ public class TFMExtras extends PlexModule return Collections.unmodifiableSet(classes); } - public boolean swmEnabled() + public boolean enableIslands() { try { Class.forName("com.infernalsuite.aswm.api.exceptions.UnknownWorldException"); + return true; } catch (Exception ignored) { return false; } - return true; } } diff --git a/src/main/java/dev/plex/extras/command/slime/MyWorldCommand.java b/src/main/java/dev/plex/extras/command/slime/MyWorldCommand.java index 59df259..76722a9 100644 --- a/src/main/java/dev/plex/extras/command/slime/MyWorldCommand.java +++ b/src/main/java/dev/plex/extras/command/slime/MyWorldCommand.java @@ -1,5 +1,7 @@ package dev.plex.extras.command.slime; +import dev.plex.Plex; +import dev.plex.cache.DataUtils; import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; @@ -8,6 +10,7 @@ import dev.plex.command.source.RequiredCommandSource; import dev.plex.extras.TFMExtras; import dev.plex.extras.island.PlayerWorld; import dev.plex.extras.island.info.IslandPermissions; +import dev.plex.player.PlexPlayer; import dev.plex.util.PlexUtils; import java.util.Arrays; @@ -22,8 +25,9 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import redis.clients.jedis.Jedis; -@CommandParameters(name = "myworld", usage = "/ [player]") +@CommandParameters(name = "myworld", usage = "/ [player]") @CommandPermissions(permission = "plex.tfmextras.myworld", source = RequiredCommandSource.IN_GAME) public class MyWorldCommand extends PlexCommand { @@ -119,6 +123,34 @@ public class MyWorldCommand extends PlexCommand return usage("/myworld settings "); } } + + case "invite" -> { + final PlexPlayer plexPlayer = DataUtils.getPlayer(args[1], false); + if (plexPlayer == null) + { + throw new PlayerNotFoundException(); + } + + if (!TFMExtras.getModule().getSlimeWorldHook().isWorldLoaded(player.getUniqueId().toString())) + { + return messageComponent("selfPlayerWorldNotFound"); + } + + final PlayerWorld playerWorld = TFMExtras.getModule().getIslandHandler().loadedIslands().get(player.getUniqueId()); + if (playerWorld.members().contains(plexPlayer.getPlayer().getUniqueId())) + { + return messageComponent("islandMemberExists"); + } + playerWorld.pendingInvites().add(plexPlayer.getUuid()); + if (Bukkit.getPlayer(plexPlayer.getUuid()) != null) + { + final Player target = Bukkit.getPlayer(plexPlayer.getUuid()); + assert target != null; + target.sendMessage(messageComponent("receivedInviteForIsland", player.getName())); + } + + return messageComponent("sentInviteToIsland"); + } } return null; } diff --git a/src/main/java/dev/plex/extras/island/PlayerWorld.java b/src/main/java/dev/plex/extras/island/PlayerWorld.java index da97080..4d8d956 100644 --- a/src/main/java/dev/plex/extras/island/PlayerWorld.java +++ b/src/main/java/dev/plex/extras/island/PlayerWorld.java @@ -27,10 +27,13 @@ public class PlayerWorld // @PrimaryKey private final UUID owner; private final List members; + private final List pendingInvites = Lists.newArrayList(); + private IslandPermissions editPermission; private IslandPermissions visitPermission; private IslandPermissions interactPermission; + public boolean addMember(UUID member) { if (members.contains(member))