Update this to Plex 1.4

This commit is contained in:
Taah 2023-08-28 04:31:52 -07:00
parent ea551c5427
commit 76b2c609eb
21 changed files with 317 additions and 49 deletions

View File

@ -8,14 +8,15 @@ repositories {
url = uri("https://repo.papermc.io/repository/maven-public/")
}
maven {
/*maven {
url = uri("https://nexus.telesphoreo.me/repository/plex/")
}
}*/
maven {
url = uri("https://repo.infernalsuite.com/repository/maven-snapshots/")
}
mavenCentral()
mavenLocal()
}
dependencies {
@ -23,7 +24,7 @@ dependencies {
annotationProcessor("org.projectlombok:lombok:1.18.28")
compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT")
implementation("org.apache.commons:commons-lang3:3.12.0")
compileOnly("dev.plex:server:1.3")
compileOnly("dev.plex:server:1.4-SNAPSHOT")
compileOnly("com.infernalsuite.aswm:api:1.20-R0.1-SNAPSHOT") {
exclude(group="com.flowpowered")
}

View File

@ -1,19 +1,28 @@
package dev.plex.extras;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.reflect.ClassPath;
import dev.plex.extras.hook.SlimeWorldHook;
import dev.plex.extras.listener.PlayerListener;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.config.ModuleConfig;
import dev.plex.extras.command.slime.MyWorldCommand;
import dev.plex.extras.command.slime.SlimeManagerCommand;
import dev.plex.extras.hook.SlimeWorldHook;
import dev.plex.extras.hook.slime.PlayerWorld;
import dev.plex.extras.jumppads.JumpPads;
import dev.plex.extras.listener.JumpPadsListener;
import dev.plex.listener.PlexListener;
import dev.plex.listener.impl.ChatListener;
import dev.plex.module.PlexModule;
import dev.plex.player.PlexPlayer;
import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils;
import dev.plex.util.minimessage.SafeMiniMessage;
import dev.plex.util.sql.SQLUtil;
import io.papermc.paper.event.player.AsyncChatEvent;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.Location;
import org.bukkit.World;
@ -44,7 +53,8 @@ public class TFMExtras extends PlexModule
config = new ModuleConfig(this, "tfmextras/config.yml", "config.yml");
config.load();
jumpPads = new JumpPads();
PlexLog.debug(String.valueOf(config.getInt("server.jumppad_strength")));
// PlexLog.debug(String.valueOf(config.getInt("server.jumppad_strength")));
// PlexLog.log("Test map: {0}", StringUtils.join(SQLUtil.createTable(Lists.newArrayList(), PlayerWorld.class), "\n"));
}
@Override
@ -53,8 +63,12 @@ public class TFMExtras extends PlexModule
if (slimeWorldHook.plugin() != null)
{
slimeWorldHook.onEnable(this);
registerCommand(new SlimeManagerCommand());
registerCommand(new MyWorldCommand());
}
getClassesFrom("dev.plex.extras.command").forEach(aClass ->
{
if (PlexCommand.class.isAssignableFrom(aClass) && aClass.isAnnotationPresent(CommandParameters.class) && aClass.isAnnotationPresent(CommandPermissions.class))
@ -94,7 +108,11 @@ public class TFMExtras extends PlexModule
addDefaultMessage("attributeList", "<gold>All possible attributes: <yellow>{0}", "0 - The attribute list, each split by a new line");
addDefaultMessage("modifiedAutoClear", "<gold>{0} will {1} have their inventory cleared when they join.", "0 - The player who will have their inventory cleared on join", "1 - Whether they had this option toggled (returns: 'no longer', 'now')");
addDefaultMessage("modifiedAutoTeleport", "<gold>{0} will {1} be teleported automatically when they join.", "0 - The player to be teleported automatically", "1 - Whether they had this option toggled (returns: 'no longer', 'now')");
addDefaultMessage("createdPlayerWorld", "<green>Welcome to the server! We've created you a new private world where you can invite your friends! View how to use this using /myworld!");
addDefaultMessage("createdPlayerWorld", "<green>Welcome to the server! We've created you a new private world where you can invite your friends! View how to use this using /myworld and visit it using /myworld goto!");
addDefaultMessage("playerWorldExists", "<red>Hey! Your world seems to already exist, go to it using /myworld goto");
addDefaultMessage("selfPlayerWorldNotFound", "<red>Hey! You don't seem to own a world yet. Go ahead and run /myworld create and then run /myworld for more help!");
addDefaultMessage("playerWorldNotFound", "<red>Hey! This player's world does not seem to exist. Are they online?");
addDefaultMessage("worldLoadError", "<red>Hey! It looks like something went wrong when this world was being loaded in, please try asking the player (or if it is yours, then rejoin) to rejoin and if not, tell the world owner to contact support on our <click:open_url:https://discord.gg/6QcT7K2Bkw><bold>Discord</bold></click>");
}
@Override

View File

@ -4,7 +4,7 @@ import dev.plex.extras.TFMExtras;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.rank.enums.Rank;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.command.CommandSender;
@ -15,7 +15,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.List;
@CommandParameters(name = "admininfo", description = "Information on how to apply for admin", aliases = "ai,si,staffinfo")
@CommandPermissions(level = Rank.OP, permission = "plex.tfmextras.admininfo")
@CommandPermissions( permission = "plex.tfmextras.admininfo")
public class AdminInfoCommand extends PlexCommand
{
private static final List<Component> ADMIN_INFO = TFMExtras.getModule().getConfig().getStringList("server.admininfo")

View File

@ -3,7 +3,7 @@ package dev.plex.extras.command;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.rank.enums.Rank;
import net.kyori.adventure.text.Component;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.attribute.Attribute;
@ -15,7 +15,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
@CommandParameters(name = "attributes", description = "Lists all possible attributes", aliases = "attributelist,attrlist")
@CommandPermissions(level = Rank.OP, permission = "plex.tfmextras.attrlist")
@CommandPermissions( permission = "plex.tfmextras.attrlist")
public class AttributeListCommand extends PlexCommand
{
@Override

View File

@ -7,7 +7,7 @@ import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.PlayerNotFoundException;
import dev.plex.player.PlexPlayer;
import dev.plex.rank.enums.Rank;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -17,7 +17,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.List;
@CommandParameters(name = "autoclear", description = "Toggle whether or not a player has their inventory automatically cleared when they join", usage = "/<command> <player>", aliases = "aclear,ac")
@CommandPermissions(level = Rank.ADMIN, permission = "plex.tfmextras.autoclear")
@CommandPermissions(permission = "plex.tfmextras.autoclear")
public class AutoClearCommand extends PlexCommand
{
@Override

View File

@ -7,7 +7,7 @@ import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.PlayerNotFoundException;
import dev.plex.player.PlexPlayer;
import dev.plex.rank.enums.Rank;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
@ -18,7 +18,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.List;
@CommandParameters(name = "autoteleport", description = "If a player is specified, it will toggle whether or not the player is automatically teleported when they join. If no player is specified, you will be randomly teleported", usage = "/<command> [player]", aliases = "autotp,rtp,randomtp,tpr")
@CommandPermissions(level = Rank.OP, permission = "plex.tfmextras.autotp")
@CommandPermissions( permission = "plex.tfmextras.autotp")
public class AutoTeleportCommand extends PlexCommand
{
@Override
@ -33,7 +33,7 @@ public class AutoTeleportCommand extends PlexCommand
player.teleportAsync(TFMExtras.getRandomLocation(player.getWorld()));
return null;
}
checkRank(sender, Rank.ADMIN, "plex.tfmextras.autotp.other");
checkPermission(sender, "plex.tfmextras.autotp.other");
PlexPlayer target = DataUtils.getPlayer(args[0]);
if (target == null)
{

View File

@ -4,7 +4,6 @@ import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.punishment.Punishment;
import dev.plex.rank.enums.Rank;
import net.kyori.adventure.text.Component;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.command.CommandSender;
@ -15,7 +14,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.stream.Collectors;
@CommandParameters(name = "banlist", description = "Manages the banlist", usage = "/<command> [purge]")
@CommandPermissions(level = Rank.ADMIN, permission = "plex.tfmextras.banlist")
@CommandPermissions(permission = "plex.tfmextras.banlist")
public class BanListCommand extends PlexCommand
{
@Override
@ -37,7 +36,7 @@ public class BanListCommand extends PlexCommand
}
if (!sender.getName().equalsIgnoreCase("console"))
{
if (!checkRank(sender, Rank.EXECUTIVE, "plex.tfmextras.banlist.clear"))
if (!checkPermission(sender, "plex.tfmextras.banlist.clear"))
{
return null;
}

View File

@ -3,7 +3,7 @@ package dev.plex.extras.command;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
import dev.plex.util.item.ItemBuilder;
import net.kyori.adventure.text.Component;
@ -17,7 +17,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "cake", description = "For the people that are still alive - gives a cake to everyone on the server")
@CommandPermissions(level = Rank.ADMIN, permission = "plex.tfmextras.cake")
@CommandPermissions(permission = "plex.tfmextras.cake")
public class CakeCommand extends PlexCommand
{
private static final ItemStack CAKE = new ItemBuilder(Material.CAKE)

View File

@ -4,7 +4,7 @@ import dev.plex.Plex;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.rank.enums.Rank;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.Bukkit;
@ -20,7 +20,7 @@ import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
@CommandParameters(name = "cartsit", description = "Sit in nearest minecart. If target is in a minecart already, they will be ejected", aliases = "minecartsit")
@CommandPermissions(level = Rank.NONOP, permission = "plex.tfmextras.cartsit")
@CommandPermissions(permission = "plex.tfmextras.cartsit")
public class CartSitCommand extends PlexCommand
{
@Override

View File

@ -3,7 +3,7 @@ package dev.plex.extras.command;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
@ -13,13 +13,13 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "clearchat", description = "Clears the chat", aliases = "cc,cleanchat,chatclear")
@CommandPermissions(level = Rank.ADMIN, permission = "plex.tfmextras.clearchat")
@CommandPermissions(permission = "plex.tfmextras.clearchat")
public class ClearChatCommand extends PlexCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args)
{
Bukkit.getOnlinePlayers().stream().filter(p -> !silentCheckRank(p, Rank.ADMIN, "plex.tfmextras.clearchat"))
Bukkit.getOnlinePlayers().stream().filter(p -> !silentCheckPermission(p, "plex.tfmextras.clearchat"))
.forEach(p ->
{
for (int i = 0; i < 100; i++)

View File

@ -3,7 +3,7 @@ package dev.plex.extras.command;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
@ -19,7 +19,7 @@ import java.util.Collection;
import java.util.concurrent.atomic.AtomicInteger;
@CommandParameters(name = "cloudclear", description = "Clears lingering potion area effect clouds", aliases = "clearcloud,aeclear")
@CommandPermissions(level = Rank.ADMIN, permission = "plex.tfmextras.cloudclear")
@CommandPermissions(permission = "plex.tfmextras.cloudclear")
public class CloudClearCommand extends PlexCommand
{
@Override

View File

@ -4,7 +4,7 @@ import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.command.CommandSender;
@ -13,7 +13,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "eject", description = "Removes all passengers from a player")
@CommandPermissions(level = Rank.OP, permission = "plex.tfmextras.eject", source = RequiredCommandSource.IN_GAME)
@CommandPermissions( permission = "plex.tfmextras.eject", source = RequiredCommandSource.IN_GAME)
public class EjectCommand extends PlexCommand
{
@Override

View File

@ -5,7 +5,7 @@ import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.apache.commons.lang3.StringUtils;
@ -22,7 +22,7 @@ import java.util.Arrays;
import java.util.List;
@CommandParameters(name = "enchant", description = "Enchants an item", usage = "/<command> <add | reset | list | addall | remove>", aliases = "enchantment")
@CommandPermissions(level = Rank.OP, permission = "plex.tfmextras.enchant", source = RequiredCommandSource.IN_GAME)
@CommandPermissions( permission = "plex.tfmextras.enchant", source = RequiredCommandSource.IN_GAME)
public class EnchantCommand extends PlexCommand
{
@Override

View File

@ -3,7 +3,7 @@ package dev.plex.extras.command;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
@ -22,7 +22,7 @@ import java.util.stream.Collectors;
*/
@CommandParameters(name = "emf", description = "Speak english.", usage = "/<command> <player>")
@CommandPermissions(level = Rank.ADMIN, permission = "plex.tfmextras.emf")
@CommandPermissions(permission = "plex.tfmextras.emf")
public class EnglishMfCommand extends PlexCommand
{
@Override

View File

@ -7,7 +7,7 @@ import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.extras.jumppads.JumpPads;
import dev.plex.extras.jumppads.Mode;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
@ -23,7 +23,7 @@ import java.util.Collections;
import java.util.List;
@CommandParameters(name = "jumppads", usage = "/jumppads <mode> [player]", description = "Enables jump pads for yourself or another player. Mode types available: none, regular, enhanced, extreme, ultimate", aliases = "jp,pads,launchpads")
@CommandPermissions(level = Rank.OP, permission = "plex.tfmextras.jumppads", source = RequiredCommandSource.ANY)
@CommandPermissions( permission = "plex.tfmextras.jumppads", source = RequiredCommandSource.ANY)
public class JumpPadsCommand extends PlexCommand
{
JumpPads jumpPads = TFMExtras.getModule().jumpPads;
@ -96,7 +96,7 @@ public class JumpPadsCommand extends PlexCommand
Mode mode = Mode.valueOf(args[0]);
if (!checkRank(sender, Rank.ADMIN, "plex.tfmextras.jumppads.others"))
if (!checkPermission(sender, "plex.tfmextras.jumppads.others"))
{
return permissionMessage();
}

View File

@ -4,7 +4,7 @@ import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.block.Block;
@ -19,7 +19,7 @@ import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
@CommandParameters(name = "randomfish", description = "Spawns a random type of fish at your location", aliases = "rfish,bird")
@CommandPermissions(level = Rank.OP, permission = "plex.tfmextras.randomfish", source = RequiredCommandSource.IN_GAME)
@CommandPermissions( permission = "plex.tfmextras.randomfish", source = RequiredCommandSource.IN_GAME)
public class RandomFishCommand extends PlexCommand
{
private static final List<EntityType> FISH_TYPES = Arrays.asList(EntityType.COD, EntityType.SALMON, EntityType.PUFFERFISH, EntityType.TROPICAL_FISH);

View File

@ -0,0 +1,85 @@
package dev.plex.extras.command.slime;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.PlayerNotFoundException;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.extras.TFMExtras;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author Taah
* @since 7:43 PM [24-08-2023]
*/
@CommandParameters(name = "myworld", usage = "/<command> <create | goto | manage | members | shared | add | remove | settings> [player]")
@CommandPermissions( permission = "plex.tfmextras.myworld", source = RequiredCommandSource.IN_GAME)
public class MyWorldCommand extends PlexCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args)
{
assert player != null;
if (args.length == 0)
{
return usage();
}
switch (args[0].toLowerCase())
{
case "create" ->
{
if (TFMExtras.getModule().getSlimeWorldHook().isWorldLoaded(player.getUniqueId().toString()))
{
return messageComponent("playerWorldExists");
}
TFMExtras.getModule().getSlimeWorldHook().createPlayerWorld(player.getUniqueId());
return messageComponent("createdPlayerWorld");
}
case "goto" ->
{
if (args.length == 1)
{
if (!TFMExtras.getModule().getSlimeWorldHook().isWorldLoaded(player.getUniqueId().toString()))
{
return messageComponent("selfPlayerWorldNotFound");
}
World world = Bukkit.getWorld(player.getUniqueId().toString());
if (world == null)
{
return messageComponent("worldLoadError");
}
player.teleportAsync(world.getSpawnLocation());
player.playSound(player.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 1f, 1f);
return null;
}
final Player target = Bukkit.getPlayer(args[1]);
if (target == null)
{
throw new PlayerNotFoundException();
}
if (!TFMExtras.getModule().getSlimeWorldHook().isWorldLoaded(target.getUniqueId().toString()))
{
return messageComponent("playerWorldNotFound");
}
World world = Bukkit.getWorld(target.getUniqueId().toString());
if (world == null)
{
return messageComponent("worldLoadError");
}
player.teleportAsync(world.getSpawnLocation());
player.playSound(player.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 1f, 1f);
return null;
}
}
return null;
}
}

View File

@ -0,0 +1,101 @@
package dev.plex.extras.command.slime;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.extras.TFMExtras;
import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import net.kyori.adventure.text.Component;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author Taah
* @since 7:11 PM [24-08-2023]
*/
@CommandParameters(name = "slimemanager", usage = "/<command> <delete | list> [world | all]", description = "Manages the slime worlds handled by the plugin")
@CommandPermissions(source = RequiredCommandSource.CONSOLE, permission = "plex.tfmextras.slimemanager")
public class SlimeManagerCommand extends PlexCommand
{
private ScheduledTask task = null;
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args)
{
if (args.length == 0)
{
return usage();
}
try
{
if (args[0].equalsIgnoreCase("delete"))
{
if (args.length != 2)
{
return usage("/slimemanager delete <world | all>");
}
String argument = args[1];
if (TFMExtras.getModule().getSlimeWorldHook().getLoader().listWorlds().isEmpty())
{
return mmString("<red>There are currently no loaded worlds.");
}
else if (!argument.equalsIgnoreCase("all") && TFMExtras.getModule().getSlimeWorldHook().getLoader().listWorlds().stream().noneMatch(s -> s.equalsIgnoreCase(argument)))
{
return mmString("<red>There is no world called " + argument);
}
if (task != null)
{
if (argument.equalsIgnoreCase("all"))
{
TFMExtras.getModule().getSlimeWorldHook().getLoader().listWorlds().forEach(s ->
TFMExtras.getModule().getSlimeWorldHook().deleteWorld(s));
if (task != null && !task.isCancelled())
{
task.cancel();
task = null;
}
return mmString("<green>Successfully permanently deleted all slime module loaded worlds!");
}
else
{
TFMExtras.getModule().getSlimeWorldHook().deleteWorld(argument);
if (task != null && !task.isCancelled())
{
task.cancel();
task = null;
}
return mmString("<green>Successfully permanently deleted the world <dark_green>" + argument);
}
}
else
{
task = Bukkit.getGlobalRegionScheduler().runDelayed(plugin, scheduledTask ->
{
this.task = null;
sender.sendMessage(PlexUtils.mmDeserialize("<red>You did not confirm the deletion in time!"));
}, 10 * 20L);
return mmString("<green>Run this command again to confirm deletion.");
}
}
else if (args[0].equalsIgnoreCase("list"))
{
return mmString("<blue>Current worlds: <white>" + StringUtils.join(TFMExtras.getModule().getSlimeWorldHook().getLoader().listWorlds(), ", "));
}
}
catch (Exception e)
{
PlexLog.debug("{0}: {1}", e.getClass().getName(), e.getMessage());
return null;
}
return null;
}
}

View File

@ -9,13 +9,16 @@ import com.infernalsuite.aswm.api.world.properties.SlimeProperties;
import com.infernalsuite.aswm.api.world.properties.SlimePropertyMap;
import dev.plex.extras.TFMExtras;
import dev.plex.util.PlexLog;
import lombok.Getter;
import org.apache.commons.lang3.tuple.Pair;
import org.bukkit.Bukkit;
import org.bukkit.GameRule;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.event.world.WorldLoadEvent;
import java.io.IOException;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
@ -29,8 +32,11 @@ public class SlimeWorldHook implements IHook<SlimePlugin>
private static final String WORLD_NOT_FOUND = "<red>This world could not be found!";
private static final String STORAGE_FAILURE = "<red>This world cannot be stored!";
private final Set<String> LOADED_WORLDS = Sets.newHashSet();
private final Set<String> loadedWorlds = Sets.newHashSet();
// private final List<>
@Getter
private SlimeLoader loader;
@ -46,7 +52,6 @@ public class SlimeWorldHook implements IHook<SlimePlugin>
PlexLog.log("<green>Enabling SWM Hook");
this.loader = plugin().getLoader("mysql");
this.loadAllWorlds();
}
@Override
@ -54,7 +59,7 @@ public class SlimeWorldHook implements IHook<SlimePlugin>
{
PlexLog.log("<green>Disabling SWM Hook");
AtomicInteger i = new AtomicInteger();
LOADED_WORLDS.forEach(s ->
loadedWorlds.forEach(s ->
{
final World world = Bukkit.getWorld(s);
if (world != null)
@ -104,7 +109,7 @@ public class SlimeWorldHook implements IHook<SlimePlugin>
world.setSpawnLocation(0, 130, 0);
world.setAutoSave(true);
LOADED_WORLDS.add(s);
loadedWorlds.add(s);
double configuratedSize = TFMExtras.getModule().getConfig().getDouble("player-worlds.size");
world.getWorldBorder().setCenter(world.getSpawnLocation());
@ -120,6 +125,27 @@ public class SlimeWorldHook implements IHook<SlimePlugin>
}
}
public boolean isWorldLoaded(String world)
{
return loadedWorlds.stream().anyMatch(s -> s.equals(world));
}
public void deleteWorld(String world)
{
try
{
if (Bukkit.getWorld(world) != null)
{
Bukkit.unloadWorld(world, false);
}
this.loader.deleteWorld(world);
}
catch (UnknownWorldException | IOException e)
{
PlexLog.error(e.getMessage());
}
}
public Pair<World, Boolean> createPlayerWorld(UUID uuid)
{
final SlimePropertyMap slimePropertyMap = new SlimePropertyMap();
@ -173,7 +199,7 @@ public class SlimeWorldHook implements IHook<SlimePlugin>
world.getBlockAt(0, 128, 0).setType(Material.STONE);
}
LOADED_WORLDS.add(uuid.toString());
loadedWorlds.add(uuid.toString());
double configuratedSize = TFMExtras.getModule().getConfig().getDouble("player-worlds.size");
world.getWorldBorder().setCenter(world.getSpawnLocation());
@ -181,9 +207,16 @@ public class SlimeWorldHook implements IHook<SlimePlugin>
world.getWorldBorder().setDamageAmount(0);
world.getWorldBorder().setDamageBuffer(0);
final WorldLoadEvent event = new WorldLoadEvent(world);
Bukkit.getServer().getPluginManager().callEvent(event);
return Pair.of(world, newWorld);
}
public Set<String> loadedWorlds()
{
return this.loadedWorlds;
}
@Override
public SlimePlugin plugin()

View File

@ -0,0 +1,27 @@
package dev.plex.extras.hook.slime;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import dev.plex.storage.annotation.PrimaryKey;
import dev.plex.storage.annotation.SQLTable;
import lombok.Data;
import org.bukkit.GameRule;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/**
* @author Taah
* @since 9:26 PM [24-08-2023]
*/
@Data
@SQLTable("player_worlds")
public class PlayerWorld
{
@PrimaryKey
private final UUID owner;
private final List<UUID> members = Lists.newArrayList();
private boolean anyoneCanEdit;
private boolean anyoneCanVisit;
}

View File

@ -3,12 +3,15 @@ package dev.plex.extras.listener;
import dev.plex.Plex;
import dev.plex.extras.TFMExtras;
import dev.plex.listener.PlexListener;
import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.scheduler.BukkitRunnable;
public class PlayerListener extends PlexListener
@ -41,13 +44,14 @@ public class PlayerListener extends PlexListener
}
@EventHandler
public void createPlayerWorld(PlayerJoinEvent event)
public void unloadWorld(PlayerQuitEvent event)
{
final Player player = event.getPlayer();
final Pair<World, Boolean> world = TFMExtras.getModule().getSlimeWorldHook().createPlayerWorld(player.getUniqueId());
if (world.getRight())
PlexLog.log("{0}", TFMExtras.getModule().getSlimeWorldHook().isWorldLoaded(player.getUniqueId().toString()));
PlexLog.log("{0}", Bukkit.getWorld(player.getUniqueId().toString()) != null);
if (TFMExtras.getModule().getSlimeWorldHook().isWorldLoaded(player.getUniqueId().toString()) && Bukkit.getWorld(player.getUniqueId().toString()) != null)
{
player.sendMessage(PlexUtils.messageComponent("createdPlayerWorld"));
Bukkit.unloadWorld(player.getUniqueId().toString(), true);
}
}
}