Remove the API component - closes #51

ver/1.2
Focusvity 4 months ago
parent f806470fd5
commit d6b44863aa
No known key found for this signature in database
GPG Key ID: 85AD157561ABE94B
  1. 32
      api/build.gradle
  2. 11
      api/src/main/java/dev/plex/api/IPlayerCache.java
  3. 6
      api/src/main/java/dev/plex/api/PlexApi.java
  4. 6
      api/src/main/java/dev/plex/api/PlexApiProvider.java
  5. 8
      api/src/main/java/dev/plex/api/chat/IChatHandler.java
  6. 32
      api/src/main/java/dev/plex/api/permission/IPermissionHandler.java
  7. 67
      api/src/main/java/dev/plex/api/player/IPlexPlayer.java
  8. 30
      api/src/main/java/dev/plex/api/plugin/PlexPlugin.java
  9. 26
      api/src/main/java/dev/plex/api/rank/IRank.java
  10. 1
      build.gradle
  11. 1
      proxy/build.gradle.kts
  12. 1
      server/build.gradle
  13. 60
      server/src/main/java/dev/plex/Plex.java
  14. 14
      server/src/main/java/dev/plex/PlexProvider.java
  15. 3
      server/src/main/java/dev/plex/cache/PlayerCache.java
  16. 18
      server/src/main/java/dev/plex/command/PlexCommand.java
  17. 6
      server/src/main/java/dev/plex/command/impl/AdminCMD.java
  18. 2
      server/src/main/java/dev/plex/command/impl/AdminChatCMD.java
  19. 2
      server/src/main/java/dev/plex/command/impl/AdventureCMD.java
  20. 2
      server/src/main/java/dev/plex/command/impl/CreativeCMD.java
  21. 2
      server/src/main/java/dev/plex/command/impl/GamemodeCMD.java
  22. 2
      server/src/main/java/dev/plex/command/impl/SmiteCMD.java
  23. 2
      server/src/main/java/dev/plex/command/impl/SpectatorCMD.java
  24. 2
      server/src/main/java/dev/plex/command/impl/SurvivalCMD.java
  25. 6
      server/src/main/java/dev/plex/event/AdminAddEvent.java
  26. 6
      server/src/main/java/dev/plex/event/AdminRemoveEvent.java
  27. 10
      server/src/main/java/dev/plex/event/AdminSetRankEvent.java
  28. 2
      server/src/main/java/dev/plex/event/GameModeUpdateEvent.java
  29. 10
      server/src/main/java/dev/plex/event/PunishedPlayerEvent.java
  30. 6
      server/src/main/java/dev/plex/event/PunishedPlayerFreezeEvent.java
  31. 6
      server/src/main/java/dev/plex/event/PunishedPlayerLockupEvent.java
  32. 6
      server/src/main/java/dev/plex/event/PunishedPlayerMuteEvent.java
  33. 14
      server/src/main/java/dev/plex/listener/impl/AdminListener.java
  34. 9
      server/src/main/java/dev/plex/listener/impl/BlockListener.java
  35. 2
      server/src/main/java/dev/plex/listener/impl/BookListener.java
  36. 38
      server/src/main/java/dev/plex/listener/impl/ChatListener.java
  37. 2
      server/src/main/java/dev/plex/listener/impl/GameModeListener.java
  38. 44
      server/src/main/java/dev/plex/listener/impl/MobListener.java
  39. 8
      server/src/main/java/dev/plex/listener/impl/PlayerListener.java
  40. 12
      server/src/main/java/dev/plex/listener/impl/TabListener.java
  41. 11
      server/src/main/java/dev/plex/listener/impl/WorldListener.java
  42. 8
      server/src/main/java/dev/plex/menu/PunishedPlayerMenu.java
  43. 10
      server/src/main/java/dev/plex/menu/PunishmentMenu.java
  44. 4
      server/src/main/java/dev/plex/module/ModuleManager.java
  45. 2
      server/src/main/java/dev/plex/module/loader/LibraryLoader.java
  46. 7
      server/src/main/java/dev/plex/permission/handler/NativePermissionHandler.java
  47. 28
      server/src/main/java/dev/plex/permission/handler/VaultPermissionHandler.java
  48. 3
      server/src/main/java/dev/plex/player/PlexPlayer.java
  49. 17
      server/src/main/java/dev/plex/punishment/PunishmentManager.java
  50. 11
      server/src/main/java/dev/plex/rank/enums/Rank.java
  51. 8
      server/src/main/java/dev/plex/rank/enums/Title.java
  52. 1
      server/src/main/java/dev/plex/storage/MongoConnection.java
  53. 8
      server/src/main/java/dev/plex/storage/codec/ZonedDateTimeCodec.java
  54. 4
      server/src/main/java/dev/plex/util/GameRuleUtil.java
  55. 2
      server/src/main/java/dev/plex/util/MojangUtils.java
  56. 7
      server/src/main/java/dev/plex/util/PlexUtils.java
  57. 2
      server/src/main/java/dev/plex/util/ReflectionsUtil.java
  58. 2
      server/src/main/java/dev/plex/util/TimeUtils.java
  59. 4
      server/src/main/java/dev/plex/util/UpdateChecker.java
  60. 6
      server/src/main/java/dev/plex/util/WebUtils.java
  61. 2
      server/src/main/java/dev/plex/world/NoiseChunkGenerator.java
  62. 2
      server/src/main/java/dev/plex/world/OctaveChunkGenerator.java
  63. 1
      settings.gradle

@ -1,32 +0,0 @@
group = rootProject.group
version = rootProject.version
description = "Plex-API"
jar {
archiveBaseName.set("Plex-API")
}
tasks {
jar {
finalizedBy(rootProject.tasks.copyJars)
}
shadowJar {
enabled = false
}
}
publishing {
publications {
maven(MavenPublication) {
from components.java
}
}
}
dependencies {
compileOnly "org.projectlombok:lombok:1.18.24"
annotationProcessor "org.projectlombok:lombok:1.18.24"
compileOnly "io.papermc.paper:paper-api:1.19.1-R0.1-SNAPSHOT"
compileOnly "org.json:json:20220320"
}

@ -1,11 +0,0 @@
package dev.plex.api;
import java.util.Map;
import java.util.UUID;
public interface IPlayerCache<T>
{
Map<UUID, T> getPlexPlayerMap();
T getPlexPlayer(UUID uuid);
}

@ -1,6 +0,0 @@
package dev.plex.api;
public interface PlexApi
{
IPlayerCache<?> getPlayerCache();
}

@ -1,6 +0,0 @@
package dev.plex.api;
public interface PlexApiProvider
{
PlexApi getApi();
}

@ -1,8 +0,0 @@
package dev.plex.api.chat;
import io.papermc.paper.event.player.AsyncChatEvent;
public interface IChatHandler
{
void doChat(AsyncChatEvent event);
}

@ -1,32 +0,0 @@
package dev.plex.api.permission;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public interface IPermissionHandler
{
default boolean hasPermission(@NotNull Player player, @Nullable String permission)
{
if (permission == null)
{
return true;
}
return player.hasPermission(permission);
}
default boolean hasPermission(@NotNull OfflinePlayer player, @Nullable String permission)
{
if (permission == null)
{
return true;
}
if (player.isOnline() && Bukkit.getPlayer(player.getUniqueId()) != null)
{
return Bukkit.getPlayer(player.getUniqueId()).hasPermission(permission);
}
throw new UnsupportedOperationException("Not implemented yet");
}
}

@ -1,67 +0,0 @@
package dev.plex.api.player;
import java.util.List;
import java.util.UUID;
import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionAttachment;
public interface IPlexPlayer
{
String getId();
UUID getUuid();
String getName();
Player getPlayer();
void setPlayer(Player player);
String getLoginMessage();
void setLoginMessage(String message);
String getPrefix();
void setPrefix(String prefix);
boolean isVanished();
void setVanished(boolean vanished);
boolean isCommandSpy();
void setCommandSpy(boolean commandSpy);
boolean isFrozen();
void setFrozen(boolean frozen);
boolean isMuted();
void setMuted(boolean muted);
boolean isLockedUp();
void setLockedUp(boolean lockedUp);
boolean isAdminActive();
void setAdminActive(boolean active);
long getCoins();
void setCoins(long coins);
String getRank();
void setRank(String rank);
List<String> getIps();
void setIps(List<String> ips);
PermissionAttachment getPermissionAttachment();
void setPermissionAttachment(PermissionAttachment attachment);
}

@ -1,30 +0,0 @@
package dev.plex.api.plugin;
import dev.plex.api.chat.IChatHandler;
import dev.plex.api.permission.IPermissionHandler;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.plugin.java.JavaPlugin;
@Getter
@Setter
public abstract class PlexPlugin extends JavaPlugin
{
@Setter(AccessLevel.NONE)
private static PlexPlugin plugin;
private IChatHandler chatHandler;
private IPermissionHandler permissionHandler;
@Override
public void onLoad()
{
plugin = this;
}
public static PlexPlugin get()
{
return plugin;
}
}

@ -1,26 +0,0 @@
package dev.plex.api.rank;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.json.JSONObject;
public interface IRank<T>
{
int getLevel();
String getLoginMessage();
void setLoginMessage(String message);
String getReadable();
Component getPrefix();
void setPrefix(String prefix);
NamedTextColor getColor();
boolean isAtLeast(T rank);
JSONObject toJSON();
}

@ -60,7 +60,6 @@ subprojects {
}
clean {
dependsOn(":api:clean")
dependsOn(":server:clean")
dependsOn(":proxy:clean")
}

@ -42,5 +42,4 @@ dependencies {
compileOnly("org.json:json:20220320")
compileOnly("com.velocitypowered:velocity-api:3.1.2-SNAPSHOT")
annotationProcessor("com.velocitypowered:velocity-api:3.1.2-SNAPSHOT")
implementation(project(":api"))
}

@ -28,7 +28,6 @@ dependencies {
}
implementation "org.bstats:bstats-base:3.0.0"
implementation "org.bstats:bstats-bukkit:3.0.0"
implementation project(":api")
}
group = rootProject.group

@ -2,19 +2,12 @@ package dev.plex;
import dev.plex.admin.Admin;
import dev.plex.admin.AdminList;
import dev.plex.api.PlexApi;
import dev.plex.api.PlexApiProvider;
import dev.plex.api.plugin.PlexPlugin;
import dev.plex.cache.DataUtils;
import dev.plex.cache.PlayerCache;
import dev.plex.config.Config;
import dev.plex.handlers.CommandHandler;
import dev.plex.handlers.ListenerHandler;
import dev.plex.hook.VaultHook;
import dev.plex.listener.impl.ChatListener;
import dev.plex.module.ModuleManager;
import dev.plex.permission.handler.NativePermissionHandler;
import dev.plex.permission.handler.VaultPermissionHandler;
import dev.plex.player.PlexPlayer;
import dev.plex.punishment.PunishmentManager;
import dev.plex.rank.RankManager;
@ -37,29 +30,26 @@ import dev.plex.world.CustomWorld;
import java.io.File;
import lombok.Getter;
import lombok.Setter;
import org.bson.conversions.Bson;
import net.milkbowl.vault.chat.Chat;
import net.milkbowl.vault.permission.Permission;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
@Getter
@Setter
public class Plex extends PlexPlugin implements PlexApiProvider
public class Plex extends JavaPlugin
{
public static final BuildInfo build = new BuildInfo();
private static Plex plugin;
public Config config;
public Config messages;
public Config indefBans;
public Config commands;
public Config toggles;
private PlexProvider provider;
public File modulesFolder;
private StorageType storageType = StorageType.SQLITE;
public static final BuildInfo build = new BuildInfo();
private SQLConnection sqlConnection;
private MongoConnection mongoConnection;
private RedisConnection redisConnection;
@ -82,6 +72,9 @@ public class Plex extends PlexPlugin implements PlexApiProvider
private UpdateChecker updateChecker;
private String system;
private Permission permissions;
private Chat chat;
public static Plex get()
{
@ -110,8 +103,7 @@ public class Plex extends PlexPlugin implements PlexApiProvider
moduleManager.loadAllModules();
moduleManager.loadModules();
this.setChatHandler(new ChatListener.ChatHandlerImpl());
//this.setChatHandler(new ChatListener.ChatHandlerImpl());
}
@Override
@ -145,21 +137,15 @@ public class Plex extends PlexPlugin implements PlexApiProvider
e.printStackTrace();
}
boolean permissions = false;
if (getServer().getPluginManager().isPluginEnabled("Vault"))
if (system.equals("permissions"))
{
VaultPermissionHandler handler = new VaultPermissionHandler();
if (VaultHook.getPermission() != null)
if (!getServer().getPluginManager().isPluginEnabled("Vault"))
{
this.setPermissionHandler(handler);
permissions = true;
PlexLog.debug("Enabling Vault support for permissions with a permission plugin: " + VaultHook.getPermission().getName());
throw new RuntimeException("Vault is required to run on the server if you use permissions!");
}
}
if (!permissions)
{
this.setPermissionHandler(new NativePermissionHandler());
permissions = setupPermissions();
chat = setupChat();
}
updateChecker = new UpdateChecker();
@ -221,8 +207,6 @@ public class Plex extends PlexPlugin implements PlexApiProvider
}
this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
provider = new PlexProvider();
moduleManager.enableModules();
}
@ -284,9 +268,17 @@ public class Plex extends PlexPlugin implements PlexApiProvider
});
}
@Override
public PlexApi getApi()
private Permission setupPermissions()
{
RegisteredServiceProvider<Permission> rsp = Bukkit.getServicesManager().getRegistration(Permission.class);
permissions = rsp.getProvider();
return permissions;
}
private Chat setupChat()
{
return provider;
RegisteredServiceProvider<Chat> rsp = Bukkit.getServicesManager().getRegistration(Chat.class);
chat = rsp.getProvider();
return chat;
}
}

@ -1,14 +0,0 @@
package dev.plex;
import dev.plex.api.IPlayerCache;
import dev.plex.api.PlexApi;
import dev.plex.player.PlexPlayer;
public class PlexProvider implements PlexApi
{
@Override
public IPlayerCache<PlexPlayer> getPlayerCache()
{
return Plex.get().getPlayerCache();
}
}

@ -1,7 +1,6 @@
package dev.plex.cache;
import com.google.common.collect.Maps;
import dev.plex.api.IPlayerCache;
import dev.plex.player.PlexPlayer;
import java.util.Map;
import java.util.UUID;
@ -10,7 +9,7 @@ import java.util.UUID;
* Cache storage
*/
public class PlayerCache implements IPlayerCache<PlexPlayer>
public class PlayerCache
{
/**
* A key/value pair where the key is the unique ID of the Plex Player

@ -155,7 +155,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
}
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
{
if (!perms.permission().isEmpty() && !plugin.getPermissionHandler().hasPermission(player, perms.permission()))
if (!perms.permission().isEmpty() && !player.hasPermission(perms.permission()))
{
send(sender, messageComponent("noPermissionNode", perms.permission()));
return true;
@ -191,7 +191,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
}
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
{
if (!perms.permission().isEmpty() && !plugin.getPermissionHandler().hasPermission(Bukkit.getOfflinePlayer(plexPlayer.getName()), perms.permission()))
if (!perms.permission().isEmpty() && !plugin.getPermissions().playerHas(null, Bukkit.getPlayer(plexPlayer.getName()), perms.permission()))
{
send(sender, messageComponent("noPermissionNode", perms.permission()));
return true;
@ -206,7 +206,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
}
try
{
Component component = this.execute(sender, isConsole(sender) ? null : (Player) sender, args);
Component component = this.execute(sender, isConsole(sender) ? null : (Player)sender, args);
if (component != null)
{
send(sender, component);
@ -292,7 +292,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
{
if (!isConsole(sender))
{
return checkRank((Player) sender, rank, permission);
return checkRank((Player)sender, rank, permission);
}
if (!sender.getName().equalsIgnoreCase("console"))
{
@ -310,7 +310,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
}
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
{
if (!perms.permission().isEmpty() && !plugin.getPermissionHandler().hasPermission(Bukkit.getOfflinePlayer(plexPlayer.getName()), perms.permission()))
if (!perms.permission().isEmpty() && !plugin.getPermissions().playerHas(null, Bukkit.getOfflinePlayer(plexPlayer.getName()), perms.permission()))
{
throw new CommandFailException(PlexUtils.messageString("noPermissionNode", permission));
}
@ -348,7 +348,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
}
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
{
if (!perms.permission().isEmpty() && !plugin.getPermissionHandler().hasPermission(player, permission))
if (!perms.permission().isEmpty() && !player.hasPermission(perms.permission()))
{
throw new CommandFailException(PlexUtils.messageString("noPermissionNode", permission));
}
@ -369,7 +369,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
}
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
{
return !perms.permission().isEmpty() && plugin.getPermissionHandler().hasPermission(player, permission);
return !perms.permission().isEmpty() && player.hasPermission(permission);
}
return false;
}
@ -387,7 +387,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
{
if (!isConsole(sender))
{
return checkTab((Player) sender, rank, permission);
return checkTab((Player)sender, rank, permission);
}
return true;
}
@ -410,7 +410,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
}
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
{
return !perms.permission().isEmpty() && plugin.getPermissionHandler().hasPermission(player, permission);
return !perms.permission().isEmpty() && player.hasPermission(permission);
}
return true;
}

@ -1,9 +1,6 @@
package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.api.event.AdminAddEvent;
import dev.plex.api.event.AdminRemoveEvent;
import dev.plex.api.event.AdminSetRankEvent;
import dev.plex.cache.DataUtils;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
@ -12,6 +9,9 @@ import dev.plex.command.annotation.System;
import dev.plex.command.exception.ConsoleOnlyException;
import dev.plex.command.exception.PlayerNotFoundException;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.event.AdminAddEvent;
import dev.plex.event.AdminRemoveEvent;
import dev.plex.event.AdminSetRankEvent;
import dev.plex.player.PlexPlayer;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;

@ -45,7 +45,7 @@ public class AdminChatCMD extends PlexCommand
}
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
{
if (plugin.getPermissionHandler().hasPermission(player, "plex.adminchat"))
if (player.hasPermission("plex.adminchat"))
{
player.sendMessage(PlexUtils.messageComponent("adminChatFormat", sender.getName(), message));
}

@ -1,12 +1,12 @@
package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.api.event.GameModeUpdateEvent;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandFailException;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.event.GameModeUpdateEvent;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
import java.util.List;

@ -1,12 +1,12 @@
package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.api.event.GameModeUpdateEvent;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandFailException;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.event.GameModeUpdateEvent;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
import java.util.List;

@ -1,11 +1,11 @@
package dev.plex.command.impl;
import dev.plex.api.event.GameModeUpdateEvent;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandFailException;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.event.GameModeUpdateEvent;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
import java.util.Arrays;

@ -17,8 +17,8 @@ import java.util.List;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.title.Title;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.World;

@ -1,12 +1,12 @@
package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.api.event.GameModeUpdateEvent;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandFailException;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.event.GameModeUpdateEvent;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
import java.util.List;

@ -1,12 +1,12 @@
package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.api.event.GameModeUpdateEvent;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandFailException;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.event.GameModeUpdateEvent;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
import java.util.List;

@ -1,6 +1,6 @@
package dev.plex.api.event;
package dev.plex.event;
import dev.plex.api.player.IPlexPlayer;
import dev.plex.player.PlexPlayer;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.bukkit.command.CommandSender;
@ -24,7 +24,7 @@ public class AdminAddEvent extends Event
/**
* The PlexPlayer that was added
*/
private final IPlexPlayer plexPlayer;
private final PlexPlayer plexPlayer;
public static HandlerList getHandlerList()
{

@ -1,6 +1,6 @@
package dev.plex.api.event;
package dev.plex.event;
import dev.plex.api.player.IPlexPlayer;
import dev.plex.player.PlexPlayer;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.bukkit.command.CommandSender;
@ -24,7 +24,7 @@ public class AdminRemoveEvent extends Event
/**
* The PlexPlayer that was removed
*/
private final IPlexPlayer plexPlayer;
private final PlexPlayer plexPlayer;
public static HandlerList getHandlerList()
{

@ -1,7 +1,7 @@
package dev.plex.api.event;
package dev.plex.event;
import dev.plex.api.player.IPlexPlayer;
import dev.plex.api.rank.IRank;
import dev.plex.player.PlexPlayer;
import dev.plex.rank.enums.Rank;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.bukkit.command.CommandSender;
@ -25,12 +25,12 @@ public class AdminSetRankEvent extends Event
/**
* The PlexPlayer that was removed
*/
private final IPlexPlayer plexPlayer;
private final PlexPlayer plexPlayer;
/**
* The rank the player was set to
*/
private final IRank rank;
private final Rank rank;
public static HandlerList getHandlerList()
{

@ -1,4 +1,4 @@
package dev.plex.api.event;
package dev.plex.event;
import lombok.Data;
import lombok.EqualsAndHashCode;

@ -1,6 +1,6 @@
package dev.plex.api.event;
package dev.plex.event;
import dev.plex.api.player.IPlexPlayer;
import dev.plex.player.PlexPlayer;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Bukkit;
@ -16,7 +16,7 @@ public abstract class PunishedPlayerEvent extends PlayerEvent implements Cancell
/**
* The player who was punished
*/
protected IPlexPlayer punishedPlayer;
protected PlexPlayer punishedPlayer;
/**
* Whether the event was cancelled
@ -28,9 +28,9 @@ public abstract class PunishedPlayerEvent extends PlayerEvent implements Cancell
* Creates an event object
*
* @param punishedPlayer The player who was punished
* @see IPlexPlayer
* @see PlexPlayer
*/
protected PunishedPlayerEvent(IPlexPlayer punishedPlayer)
protected PunishedPlayerEvent(PlexPlayer punishedPlayer)
{
super(Bukkit.getPlayer(punishedPlayer.getUuid()));
this.punishedPlayer = punishedPlayer;

@ -1,6 +1,6 @@
package dev.plex.api.event;
package dev.plex.event;
import dev.plex.api.player.IPlexPlayer;
import dev.plex.player.PlexPlayer;
import lombok.Getter;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
@ -24,7 +24,7 @@ public class PunishedPlayerFreezeEvent extends PunishedPlayerEvent implements Ca
* @param punishedPlayer The player who was punished
* @param frozen The new frozen status
*/
public PunishedPlayerFreezeEvent(IPlexPlayer punishedPlayer, boolean frozen)
public PunishedPlayerFreezeEvent(PlexPlayer punishedPlayer, boolean frozen)
{
super(punishedPlayer);
this.frozen = frozen;

@ -1,6 +1,6 @@
package dev.plex.api.event;
package dev.plex.event;
import dev.plex.api.player.IPlexPlayer;
import dev.plex.player.PlexPlayer;
import lombok.Getter;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
@ -24,7 +24,7 @@ public class PunishedPlayerLockupEvent extends PunishedPlayerEvent implements Ca
* @param punishedPlayer The player who was punished
* @param lockedUp The new muted status
*/
public PunishedPlayerLockupEvent(IPlexPlayer punishedPlayer, boolean lockedUp)
public PunishedPlayerLockupEvent(PlexPlayer punishedPlayer, boolean lockedUp)
{
super(punishedPlayer);
this.lockedUp = lockedUp;

@ -1,6 +1,6 @@
package dev.plex.api.event;
package dev.plex.event;
import dev.plex.api.player.IPlexPlayer;
import dev.plex.player.PlexPlayer;
import lombok.Getter;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
@ -24,7 +24,7 @@ public class PunishedPlayerMuteEvent extends PunishedPlayerEvent implements Canc
* @param punishedPlayer The player who was punished
* @param muted The new muted status
*/
public PunishedPlayerMuteEvent(IPlexPlayer punishedPlayer, boolean muted)
public PunishedPlayerMuteEvent(PlexPlayer punishedPlayer, boolean muted)
{
super(punishedPlayer);
this.muted = muted;

@ -1,9 +1,9 @@
package dev.plex.listener.impl;
import dev.plex.api.event.AdminAddEvent;
import dev.plex.api.event.AdminRemoveEvent;
import dev.plex.api.event.AdminSetRankEvent;
import dev.plex.cache.DataUtils;
import dev.plex.event.AdminAddEvent;
import dev.plex.event.AdminRemoveEvent;
import dev.plex.event.AdminSetRankEvent;
import dev.plex.listener.PlexListener;
import dev.plex.player.PlexPlayer;
import dev.plex.rank.enums.Rank;
@ -17,7 +17,7 @@ public class AdminListener extends PlexListener
public void onAdminAdd(AdminAddEvent event)
{
String userSender = event.getSender().getName();
PlexPlayer target = (PlexPlayer) event.getPlexPlayer();
PlexPlayer target = (PlexPlayer)event.getPlexPlayer();
if (target.getRankFromString().isAtLeast(Rank.ADMIN))
{
PlexUtils.broadcast(messageComponent("adminReadded", userSender, target.getName(), target.getRankFromString().getReadable()));
@ -35,7 +35,7 @@ public class AdminListener extends PlexListener
public void onAdminRemove(AdminRemoveEvent event)
{
String userSender = event.getSender().getName();
PlexPlayer target = (PlexPlayer) event.getPlexPlayer();
PlexPlayer target = (PlexPlayer)event.getPlexPlayer();
target.setAdminActive(false);
DataUtils.update(target);
PlexUtils.broadcast(messageComponent("adminRemoved", userSender, target.getName()));
@ -45,8 +45,8 @@ public class AdminListener extends PlexListener
public void onAdminSetRank(AdminSetRankEvent event)
{
String userSender = event.getSender().getName();
PlexPlayer target = (PlexPlayer) event.getPlexPlayer();
Rank newRank = (Rank) event.getRank();
PlexPlayer target = (PlexPlayer)event.getPlexPlayer();
Rank newRank = (Rank)event.getRank();
target.setRank(newRank.name().toLowerCase());
DataUtils.update(target);
PlexUtils.broadcast(messageComponent("adminSetRank", userSender, target.getName(), newRank.getReadable()));

@ -16,13 +16,10 @@ import org.bukkit.event.block.BlockPlaceEvent;
public class BlockListener extends PlexListener
{
public List<String> blockedPlayers = new ArrayList<>();
private static final List<Material> blockedBlocks = new ArrayList<>();
private static List<String> cachedBlockedBlocksConfig = null;
private static final List<Material> SIGNS = Arrays.stream(Material.values()).filter((mat) -> mat.name().endsWith("_SIGN")).toList();
private static List<String> cachedBlockedBlocksConfig = null;
public List<String> blockedPlayers = new ArrayList<>();
@EventHandler(priority = EventPriority.LOW)
public void onBlockPlace(BlockPlaceEvent event)
@ -60,7 +57,7 @@ public class BlockListener extends PlexListener
if (SIGNS.contains(block.getType()))
{
Sign sign = (Sign) block.getState();
Sign sign = (Sign)block.getState();
boolean anythingChanged = false;
for (int i = 0; i < sign.lines().size(); i++)
{

@ -24,6 +24,6 @@ public class BookListener extends PlexListener
}
event.setNewBookMeta((BookMeta) event.getNewBookMeta().pages(pages));
event.setNewBookMeta((BookMeta)event.getNewBookMeta().pages(pages));
}
}

@ -1,6 +1,5 @@
package dev.plex.listener.impl;
import dev.plex.api.chat.IChatHandler;
import dev.plex.listener.PlexListener;
import dev.plex.listener.annotation.Toggleable;
import dev.plex.player.PlexPlayer;
@ -21,6 +20,7 @@ import org.jetbrains.annotations.NotNull;
@Toggleable("chat.enabled")
public class ChatListener extends PlexListener
{
private final static TextReplacementConfig URL_REPLACEMENT_CONFIG = TextReplacementConfig
.builder()
.match("(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]")
@ -29,36 +29,26 @@ public class ChatListener extends PlexListener
.clickEvent(ClickEvent.openUrl(
matchResult.group()
))).build();
private final PlexChatRenderer renderer = new PlexChatRenderer();
@EventHandler
public void onChat(AsyncChatEvent event)
{
plugin.getChatHandler().doChat(event);
}
public static class ChatHandlerImpl implements IChatHandler
{
private final PlexChatRenderer renderer = new PlexChatRenderer();
PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayerMap().get(event.getPlayer().getUniqueId());
Component prefix = plugin.getRankManager().getPrefix(plexPlayer);
@Override
public void doChat(AsyncChatEvent event)
if (prefix != null)
{
PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayerMap().get(event.getPlayer().getUniqueId());
Component prefix = plugin.getRankManager().getPrefix(plexPlayer);
if (prefix != null)
{
renderer.hasPrefix = true;
renderer.prefix = prefix;
}
else
{
renderer.hasPrefix = false;
renderer.prefix = null;
}
event.renderer(renderer);
renderer.hasPrefix = true;
renderer.prefix = prefix;
}
else
{
renderer.hasPrefix = false;
renderer.prefix = null;
}
event.renderer(renderer);
}
public static class PlexChatRenderer implements ChatRenderer

@ -1,6 +1,6 @@
package dev.plex.listener.impl;
import dev.plex.api.event.GameModeUpdateEvent;
import dev.plex.event.GameModeUpdateEvent;
import dev.plex.listener.PlexListener;
import dev.plex.util.PlexUtils;
import org.bukkit.command.CommandSender;

@ -28,6 +28,27 @@ public class MobListener extends PlexListener
{
private static final List<Material> SPAWN_EGGS = Arrays.stream(Material.values()).filter((mat) -> mat.name().endsWith("_SPAWN_EGG")).toList();
private static EntityType spawnEggToEntityType(Material mat)
{
EntityType eggType;
try
{
if (mat == Material.MOOSHROOM_SPAWN_EGG)
{
eggType = EntityType.MUSHROOM_COW;
}
else
{
eggType = EntityType.valueOf(mat.name().substring(0, mat.name().length() - 10));
}
}
catch (IllegalArgumentException ignored)
{
return null;
}
return eggType;
}
@EventHandler
public void onEntitySpawn(EntitySpawnEvent event)
{
@ -56,7 +77,7 @@ public class MobListener extends PlexListener
if (SPAWN_EGGS.contains(itemType))
{
Block block = event.getBlock();
Location blockLoc = BlockUtils.relative(block.getLocation(), ((Directional) block.getBlockData()).getFacing()).add(.5, 0, .5);
Location blockLoc = BlockUtils.relative(block.getLocation(), ((Directional)block.getBlockData()).getFacing()).add(.5, 0, .5);
EntityType eggType = spawnEggToEntityType(itemType);
if (eggType != null)
{
@ -108,25 +129,4 @@ public class MobListener extends PlexListener
}
}
}
private static EntityType spawnEggToEntityType(Material mat)
{
EntityType eggType;
try
{
if (mat == Material.MOOSHROOM_SPAWN_EGG)
{
eggType = EntityType.MUSHROOM_COW;
}
else
{
eggType = EntityType.valueOf(mat.name().substring(0, mat.name().length() - 10));
}
}
catch (IllegalArgumentException ignored)
{
return null;
}
return eggType;
}
}

@ -7,10 +7,8 @@ import dev.plex.storage.StorageType;
import dev.plex.util.PermissionsUtil;
import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils;
import java.util.Arrays;
import java.util.List;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.format.NamedTextColor;
@ -36,7 +34,8 @@ public class PlayerListener<T> extends PlexListener
{
player.setOp(true);
PlexLog.debug("Automatically opped " + player.getName() + " since ranks are enabled.");
} else if (plugin.getSystem().equalsIgnoreCase("permissions"))
}
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
{
player.setOp(false);
PlexLog.debug("Automatically deopped " + player.getName() + " since ranks are disabled.");
@ -49,7 +48,8 @@ public class PlayerListener<T> extends PlexListener
plexPlayer.setName(player.getName()); // set the name of the player
plexPlayer.setIps(Arrays.asList(player.getAddress().getAddress().getHostAddress().trim())); // set the arraylist of ips
DataUtils.insert(plexPlayer); // insert data in some wack db
} else
}
else
{
plexPlayer = DataUtils.getPlayer(player.getUniqueId());
List<String> ips = plexPlayer.getIps();

@ -1,9 +1,9 @@
package dev.plex.listener.impl;
import dev.plex.api.event.AdminAddEvent;
import dev.plex.api.event.AdminRemoveEvent;
import dev.plex.api.event.AdminSetRankEvent;
import dev.plex.cache.DataUtils;
import dev.plex.event.AdminAddEvent;
import dev.plex.event.AdminRemoveEvent;
import dev.plex.event.AdminSetRankEvent;
import dev.plex.listener.PlexListener;
import dev.plex.player.PlexPlayer;
import net.kyori.adventure.text.Component;
@ -25,7 +25,7 @@ public class TabListener extends PlexListener
@EventHandler(priority = EventPriority.HIGHEST)
public void onAdminAdd(AdminAddEvent event)
{
PlexPlayer plexPlayer = (PlexPlayer) event.getPlexPlayer();
PlexPlayer plexPlayer = (PlexPlayer)event.getPlexPlayer();
Player player = event.getPlexPlayer().getPlayer();
if (player == null)
{
@ -37,7 +37,7 @@ public class TabListener extends PlexListener
@EventHandler(priority = EventPriority.HIGHEST)
public void onAdminRemove(AdminRemoveEvent event)
{
PlexPlayer plexPlayer = (PlexPlayer) event.getPlexPlayer();
PlexPlayer plexPlayer = (PlexPlayer)event.getPlexPlayer();
Player player = event.getPlexPlayer().getPlayer();
if (player == null)
{
@ -49,7 +49,7 @@ public class TabListener extends PlexListener
@EventHandler(priority = EventPriority.HIGHEST)
public void onAdminSetRank(AdminSetRankEvent event)
{
PlexPlayer plexPlayer = (PlexPlayer) event.getPlexPlayer();
PlexPlayer plexPlayer = (PlexPlayer)event.getPlexPlayer();
Player player = event.getPlexPlayer().getPlayer();
if (player == null)
{

@ -76,8 +76,8 @@ public class WorldListener extends PlexListener
if (command != null)
{
// This does check for aliases
boolean isWeCommand = command instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand) command).getPlugin().equals(Bukkit.getPluginManager().getPlugin("WorldEdit"));
boolean isFaweCommand = command instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand) command).getPlugin().equals(Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit"));
boolean isWeCommand = command instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand)command).getPlugin().equals(Bukkit.getPluginManager().getPlugin("WorldEdit"));
boolean isFaweCommand = command instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand)command).getPlugin().equals(Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit"));
if (isWeCommand || isFaweCommand || EDIT_COMMANDS.contains(message.toLowerCase()))
{
event.getPlayer().sendMessage(Component.text("You do not have permission to use that command in this world.").color(NamedTextColor.RED));
@ -139,7 +139,7 @@ public class WorldListener extends PlexListener
/**
* Check if a Player has the ability to modify the world they are in
*
* @param player The player who wants to modify the world
* @param player The player who wants to modify the world
* @param showMessage Whether the message from the config.yml should be shown
* @return Returns true if the person has the ability to modify the world
*/
@ -154,7 +154,7 @@ public class WorldListener extends PlexListener
{
return true;
}
if (plugin.getPermissionHandler().hasPermission(player, permission))
if (player.hasPermission(permission))
{
return true;
}
@ -188,6 +188,7 @@ public class WorldListener extends PlexListener
/**
* Check if a Player has the ability to enter the requested world
*
* @param player The player who wants to enter the world
* @return Returns true if the person has the ability to enter the world
*/
@ -202,7 +203,7 @@ public class WorldListener extends PlexListener
{
return true;
}
if (plugin.getPermissionHandler().hasPermission(player, permission))
if (player.hasPermission(permission))
{
return true;
}

@ -134,7 +134,7 @@ public class PunishedPlayerMenu extends AbstractMenu
{
return;
}
openInv((Player) event.getWhoClicked(), getCurrentInventoryIndex(inv) + 1);
openInv((Player)event.getWhoClicked(), getCurrentInventoryIndex(inv) + 1);
}
else if (item.getItemMeta().displayName().equals(Component.text("Previous Page").color(NamedTextColor.LIGHT_PURPLE)))
{
@ -150,17 +150,17 @@ public class PunishedPlayerMenu extends AbstractMenu
{
return;
}
openInv((Player) event.getWhoClicked(), getCurrentInventoryIndex(inv) - 1);
openInv((Player)event.getWhoClicked(), getCurrentInventoryIndex(inv) - 1);
}
}
else if (item.getType() == Material.BARRIER)
{
new PunishmentMenu().openInv((Player) event.getWhoClicked(), 0);
new PunishmentMenu().openInv((Player)event.getWhoClicked(), 0);
}
else if (item.getType() == Material.PLAYER_HEAD)
{
SkullMeta meta = (SkullMeta) item.getItemMeta();
SkullMeta meta = (SkullMeta)item.getItemMeta();
OfflinePlayer player = meta.getOwningPlayer();
assert player != null;
PlexPlayer punishedPlayer = DataUtils.getPlayer(player.getUniqueId()) == null ? null : Plex.get().getPlayerCache().getPlexPlayer(player.getUniqueId());

@ -71,7 +71,7 @@ public class PunishmentMenu extends AbstractMenu
ItemStack item = new ItemStack(Material.PLAYER_HEAD);
SkullMeta meta = (SkullMeta) item.getItemMeta();
SkullMeta meta = (SkullMeta)item.getItemMeta();
meta.setOwningPlayer(playe