start working on inviting members

This commit is contained in:
Taah 2024-05-06 03:20:06 -07:00
parent f866d9f5a3
commit 66222a0c4b
3 changed files with 45 additions and 7 deletions

View File

@ -2,6 +2,7 @@ package dev.plex.extras;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.ClassPath; import com.google.common.reflect.ClassPath;
import dev.plex.Plex;
import dev.plex.command.PlexCommand; import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
@ -35,7 +36,7 @@ public class TFMExtras extends PlexModule
private ModuleConfig config; private ModuleConfig config;
@Getter @Getter
private SlimeWorldHook slimeWorldHook = new SlimeWorldHook(); private SlimeWorldHook slimeWorldHook;
@Getter @Getter
private final IslandHandler islandHandler = new IslandHandler(); 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 = new ModuleConfig(this, "tfmextras/config.yml", "config.yml");
config.load(); config.load();
jumpPads = new JumpPads(); jumpPads = new JumpPads();
if (swmEnabled()) if (enableIslands())
{ {
slimeWorldHook = new SlimeWorldHook(); slimeWorldHook = new SlimeWorldHook();
} }
@ -58,7 +59,7 @@ public class TFMExtras extends PlexModule
@Override @Override
public void enable() public void enable()
{ {
if (swmEnabled()) if (enableIslands())
{ {
slimeWorldHook.onEnable(this); slimeWorldHook.onEnable(this);
registerCommand(new SlimeManagerCommand()); registerCommand(new SlimeManagerCommand());
@ -118,13 +119,15 @@ public class TFMExtras extends PlexModule
addDefaultMessage("islandPermissionUpdated", "<green>Your island permission for {0} has been updated to {1}.", "0 - Permission name", "1 - New value"); addDefaultMessage("islandPermissionUpdated", "<green>Your island permission for {0} has been updated to {1}.", "0 - Permission name", "1 - New value");
addDefaultMessage("cantModifyIsland", "<red>You can't modify this player's island!"); addDefaultMessage("cantModifyIsland", "<red>You can't modify this player's island!");
addDefaultMessage("cantVisitIsland", "<red>You can't visit this player's island!"); addDefaultMessage("cantVisitIsland", "<red>You can't visit this player's island!");
addDefaultMessage("islandMemberExists", "<red>This player is already a member of your island!");
addDefaultMessage("receivedInviteForIsland", "<green>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 @Override
public void disable() public void disable()
{ {
// Unregistering listeners / commands is handled by Plex // Unregistering listeners / commands is handled by Plex
if (swmEnabled()) if (enableIslands())
{ {
slimeWorldHook.onDisable(this); slimeWorldHook.onDisable(this);
} }
@ -169,16 +172,16 @@ public class TFMExtras extends PlexModule
return Collections.unmodifiableSet(classes); return Collections.unmodifiableSet(classes);
} }
public boolean swmEnabled() public boolean enableIslands()
{ {
try try
{ {
Class.forName("com.infernalsuite.aswm.api.exceptions.UnknownWorldException"); Class.forName("com.infernalsuite.aswm.api.exceptions.UnknownWorldException");
return true;
} }
catch (Exception ignored) catch (Exception ignored)
{ {
return false; return false;
} }
return true;
} }
} }

View File

@ -1,5 +1,7 @@
package dev.plex.extras.command.slime; package dev.plex.extras.command.slime;
import dev.plex.Plex;
import dev.plex.cache.DataUtils;
import dev.plex.command.PlexCommand; import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; 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.TFMExtras;
import dev.plex.extras.island.PlayerWorld; import dev.plex.extras.island.PlayerWorld;
import dev.plex.extras.island.info.IslandPermissions; import dev.plex.extras.island.info.IslandPermissions;
import dev.plex.player.PlexPlayer;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import java.util.Arrays; import java.util.Arrays;
@ -22,8 +25,9 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import redis.clients.jedis.Jedis;
@CommandParameters(name = "myworld", usage = "/<command> <create | goto | manage | members | shared | add | remove | settings> [player]") @CommandParameters(name = "myworld", usage = "/<command> <create | goto | info | invite | remove | settings> [player]")
@CommandPermissions(permission = "plex.tfmextras.myworld", source = RequiredCommandSource.IN_GAME) @CommandPermissions(permission = "plex.tfmextras.myworld", source = RequiredCommandSource.IN_GAME)
public class MyWorldCommand extends PlexCommand public class MyWorldCommand extends PlexCommand
{ {
@ -119,6 +123,34 @@ public class MyWorldCommand extends PlexCommand
return usage("/myworld settings <interact | edit | visit> <nobody | anyone | members>"); return usage("/myworld settings <interact | edit | visit> <nobody | anyone | members>");
} }
} }
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; return null;
} }

View File

@ -27,10 +27,13 @@ public class PlayerWorld
// @PrimaryKey // @PrimaryKey
private final UUID owner; private final UUID owner;
private final List<UUID> members; private final List<UUID> members;
private final List<UUID> pendingInvites = Lists.newArrayList();
private IslandPermissions editPermission; private IslandPermissions editPermission;
private IslandPermissions visitPermission; private IslandPermissions visitPermission;
private IslandPermissions interactPermission; private IslandPermissions interactPermission;
public boolean addMember(UUID member) public boolean addMember(UUID member)
{ {
if (members.contains(member)) if (members.contains(member))