Revert "Revert "Revert "Revert "Revert "Revert "Revert "Revert "Revert "Revert "Revert "Revert "Revert "Revert "Revert "Revert "Revert "https://media.discordapp.net/attachments/968519299763413022/976916680032800868/caption.gif"""""""""""""""""

This reverts commit 47a52ded3b.
This commit is contained in:
Allink 2022-05-20 10:32:43 +01:00
parent 47a52ded3b
commit 352b515f65
No known key found for this signature in database
GPG Key ID: 7F1F1B98F0FAAD13
11 changed files with 247 additions and 307 deletions

View File

@ -7,8 +7,7 @@ import net.kyori.adventure.text.Component;
@Data
@AllArgsConstructor
public class Message
{
public class Message {
UUID sender;
Component message;

View File

@ -2,8 +2,7 @@ package dev.plex.nush;
import javax.annotation.Nullable;
public enum NushAction
{
public enum NushAction {
MUTE("Mute Player", 0),
CANCEL("Cancel", 1),
SMITE("Smite", 2),
@ -13,19 +12,15 @@ public enum NushAction
public final String humanReadable;
public final int ordinal;
NushAction(String humanReadable, int ordinal)
{
NushAction(String humanReadable, int ordinal) {
this.humanReadable = humanReadable;
this.ordinal = ordinal;
}
@Nullable
public static NushAction fromOrdinal(int ordinal)
{
for (NushAction value : NushAction.values())
{
if (value.ordinal == ordinal)
{
public static NushAction fromOrdinal(int ordinal) {
for (NushAction value : NushAction.values()) {
if (value.ordinal == ordinal) {
return value;
}
}

View File

@ -8,8 +8,7 @@ import dev.plex.nush.handler.impl.ListenerHandler;
import java.util.Map;
import java.util.Map.Entry;
public class NushModule extends PlexModule
{
public class NushModule extends PlexModule {
public static final Map<String, String> messages = Map.ofEntries(
Map.entry("nushToggled", "<aqua>{0} - {1} NUSH."),
@ -17,18 +16,15 @@ public class NushModule extends PlexModule
public static boolean enabled = false;
private static NushModule INSTANCE;
public static NushModule getInstance()
{
public static NushModule getInstance() {
return INSTANCE;
}
@Override
public void enable()
{
public void enable() {
INSTANCE = this;
Plex plex = getPlex();
for (Entry<String, String> entry : messages.entrySet())
{
for (Entry<String, String> entry : messages.entrySet()) {
plex.messages.addDefault(entry.getKey(), entry.getValue());
}
@ -38,8 +34,7 @@ public class NushModule extends PlexModule
}
@Override
public void disable()
{
public void disable() {
// Unregistering listeners / commands is handled by Plex
}
}

View File

@ -18,53 +18,41 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import static dev.plex.nush.NushAction.ACCEPT;
import static dev.plex.nush.NushAction.CANCEL;
@CommandParameters(name = "nush", aliases = "raidmode", description = "Toggle NUSH on or off.", usage = "/<command> [on | enable | off | disable | toggle]")
@CommandPermissions(level = Rank.ADMIN, permission = "plex.nush.command")
public class NUSHCommand extends PlexCommand
{
public class NUSHCommand extends PlexCommand {
@Override
protected Component execute(@NotNull CommandSender commandSender, @Nullable Player player,
@NotNull String[] args)
{
if (args.length == 0)
{
@NotNull String[] args) {
if (args.length == 0) {
NushModule.enabled = !NushModule.enabled;
}
else if (args.length == 1)
{
switch (args[0].toLowerCase())
{
} else if (args.length == 1) {
switch (args[0].toLowerCase()) {
case "on", "enable" -> NushModule.enabled = true;
case "off", "disable" -> NushModule.enabled = false;
case "toggle" -> NushModule.enabled = !NushModule.enabled;
}
}
else
{
if (args[0].equalsIgnoreCase("work"))
{
try
{
} else {
if (args[0].equalsIgnoreCase("work")) {
try {
UUID nushIdentifier = UUID.fromString(args[1]);
Message nushMessage = ActionHandler.MAP.get(nushIdentifier);
if (nushMessage == null)
{
if (nushMessage == null) {
return null;
}
NushAction action = NushAction.fromOrdinal(Integer.parseInt(args[2]));
if (action == null)
{
if (action == null) {
return null;
}
if (action == ACCEPT || action == CANCEL)
{
if (action == ACCEPT || action == CANCEL) {
ActionHandler.resolve(nushIdentifier, action);
return Component.text(action.humanReadable, NamedTextColor.YELLOW);
}
@ -75,17 +63,14 @@ public class NUSHCommand extends PlexCommand
command.append(" ");
command.append(nushMessage.getSender());
if (!command.toString().trim().isEmpty())
{
if (!command.toString().trim().isEmpty()) {
PlexLog.debug("Dispatching command: {0}", command.toString());
Bukkit.dispatchCommand(commandSender, command.toString());
}
ActionHandler.resolve(nushIdentifier, action);
return Component.text(action.humanReadable, NamedTextColor.YELLOW);
}
catch (Exception ignored)
{
} catch (Exception ignored) {
return null;
}
}

View File

@ -2,8 +2,7 @@ package dev.plex.nush.handler;
import dev.plex.nush.NushModule;
public interface Handler
{
public interface Handler {
void init(NushModule module);
}

View File

@ -12,6 +12,7 @@ import dev.plex.util.minimessage.SafeMiniMessage;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextReplacementConfig;
@ -23,8 +24,7 @@ import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class ActionHandler implements Handler
{
public class ActionHandler implements Handler {
public static final Map<UUID, Message> MAP = new HashMap<>();
private final static TextReplacementConfig URL_REPLACEMENT_CONFIG = TextReplacementConfig.builder()
@ -34,19 +34,14 @@ public class ActionHandler implements Handler
ClickEvent.openUrl(matchResult.group()))).build();
private static NushModule MODULE;
public static void resolve(UUID uuid, NushAction action)
{
public static void resolve(UUID uuid, NushAction action) {
Message message = MAP.get(uuid);
if (message == null)
{
if (message == null) {
return;
}
if (action == NushAction.ACCEPT)
{
for (Player player : Bukkit.getOnlinePlayers())
{
if (player.getUniqueId() != message.getSender())
{
if (action == NushAction.ACCEPT) {
for (Player player : Bukkit.getOnlinePlayers()) {
if (player.getUniqueId() != message.getSender()) {
player.sendMessage(Identity.identity(message.getSender()), getMessage(message));
}
}
@ -54,16 +49,14 @@ public class ActionHandler implements Handler
MAP.remove(uuid);
}
public static Component getMessage(Message message)
{
public static Component getMessage(Message message) {
String text = PlexUtils.getTextFromComponent(message.getMessage());
Plex plex = MODULE.getPlex();
PlexPlayer plexPlayer = DataUtils.getPlayer(message.getSender());
Component prefix = plex.getRankManager().getPrefix(plexPlayer);
Component component = Component.empty();
if (prefix != null)
{
if (prefix != null) {
component = component.append(prefix);
}
@ -82,8 +75,7 @@ public class ActionHandler implements Handler
}
@Override
public void init(NushModule module)
{
public void init(NushModule module) {
MODULE = NushModule.getInstance();
}
}

View File

@ -4,12 +4,10 @@ import dev.plex.nush.NushModule;
import dev.plex.nush.command.impl.NUSHCommand;
import dev.plex.nush.handler.Handler;
public class CommandHandler implements Handler
{
public class CommandHandler implements Handler {
@Override
public void init(NushModule module)
{
public void init(NushModule module) {
module.registerCommand(new NUSHCommand());
}
}

View File

@ -5,12 +5,10 @@ import dev.plex.nush.handler.Handler;
import dev.plex.nush.listener.impl.ChatListener;
import dev.plex.nush.listener.impl.JoinListener;
public class ListenerHandler implements Handler
{
public class ListenerHandler implements Handler {
@Override
public void init(NushModule module)
{
public void init(NushModule module) {
module.registerListener(new ChatListener());
module.registerListener(new JoinListener());
}

View File

@ -22,22 +22,16 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
public class ChatListener extends PlexListener
{
public class ChatListener extends PlexListener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onChat(AsyncChatEvent event)
{
if (event.isCancelled())
{
return;
}
public void onChat(AsyncChatEvent event) {
if(event.isCancelled()) return;
Player player = event.getPlayer();
Instant firstJoined = Instant.ofEpochMilli(player.getFirstPlayed());
Instant rightNow = Instant.now();
long difference = (Duration.between(firstJoined, rightNow).getSeconds() / 60);
if (difference >= 15)
{
if (difference >= 15) {
PlexLog.debug("{0} has been on the server for {1} minutes, so Nush will skip them.", player.getName(), difference);
return;
}
@ -47,8 +41,7 @@ public class ChatListener extends PlexListener
PlexPlayer plexPlayer = DataUtils.getPlayer(player.getUniqueId());
RankManager rankManager = plex.getRankManager();
if (rankManager.isAdmin(plexPlayer))
{
if (rankManager.isAdmin(plexPlayer)) {
PlexLog.debug("{0} is an admin so Nush will skip them.", player.getName());
return; // we needn't process the chat message if they're an admin
}
@ -64,8 +57,7 @@ public class ChatListener extends PlexListener
component = component.append(Component.text("\n"));
for (NushAction value : NushAction.values())
{
for (NushAction value : NushAction.values()) {
String command = String.format("/nush work %s %d", key, value.ordinal);
component = component.append(
Component.text(String.format("[%s] ", value.humanReadable))

View File

@ -10,20 +10,17 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
public class JoinListener extends PlexListener
{
public class JoinListener extends PlexListener {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event)
{
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
NushModule module = NushModule.getInstance();
Plex plex = module.getPlex();
PlexPlayer plexPlayer = DataUtils.getPlayer(player.getUniqueId());
RankManager rankManager = plex.getRankManager();
if (!rankManager.isAdmin(plexPlayer))
{
if (!rankManager.isAdmin(plexPlayer)) {
return; // we only want to add admins
}
/*if (ChatListener.work.containsKey())

View File

@ -10,32 +10,24 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
public class ReflectionsUtil
{
public class ReflectionsUtil {
@SuppressWarnings("UnstableApiUsage")
public static Set<Class<?>> getClassesFrom(String packageName)
{
public static Set<Class<?>> getClassesFrom(String packageName) {
Set<Class<?>> classes = new HashSet<>();
try
{
try {
ClassPath path = ClassPath.from(Plex.class.getClassLoader());
ImmutableSet<ClassPath.ClassInfo> infoSet = path.getTopLevelClasses(packageName);
infoSet.forEach(info ->
{
try
{
try {
Class<?> clazz = Class.forName(info.getName());
classes.add(clazz);
}
catch (ClassNotFoundException ex)
{
} catch (ClassNotFoundException ex) {
PlexLog.error("Unable to find class " + info.getName() + " in " + packageName);
}
});
}
catch (IOException ex)
{
} catch (IOException ex) {
PlexLog.error("Something went wrong while fetching classes from " + packageName);
throw new RuntimeException(ex);
}
@ -44,16 +36,14 @@ public class ReflectionsUtil
@SuppressWarnings("unchecked")
public static <T> Set<Class<? extends T>> getClassesBySubType(String packageName,
Class<T> subType)
{
Class<T> subType) {
Set<Class<?>> loadedClasses = getClassesFrom(packageName);
Set<Class<? extends T>> classes = new HashSet<>();
loadedClasses.forEach(clazz ->
{
if (clazz.getSuperclass() == subType || Arrays.asList(clazz.getInterfaces())
.contains(subType))
{
classes.add((Class<? extends T>)clazz);
.contains(subType)) {
classes.add((Class<? extends T>) clazz);
}
});
return Collections.unmodifiableSet(classes);