mirror of
https://github.com/plexusorg/Module-NUSH.git
synced 2025-02-22 19:20:39 +00:00
Make everything work (#1)
This commit is contained in:
parent
35a5ffe71c
commit
1207990b77
@ -2,6 +2,7 @@ package dev.plex.nush;
|
|||||||
|
|
||||||
import dev.plex.Plex;
|
import dev.plex.Plex;
|
||||||
import dev.plex.module.PlexModule;
|
import dev.plex.module.PlexModule;
|
||||||
|
import dev.plex.nush.handler.impl.ActionHandler;
|
||||||
import dev.plex.nush.handler.impl.CommandHandler;
|
import dev.plex.nush.handler.impl.CommandHandler;
|
||||||
import dev.plex.nush.handler.impl.ListenerHandler;
|
import dev.plex.nush.handler.impl.ListenerHandler;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -27,6 +28,7 @@ public class NushModule extends PlexModule {
|
|||||||
plex.messages.addDefault(entry.getKey(), entry.getValue());
|
plex.messages.addDefault(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new ActionHandler().init(this);
|
||||||
new CommandHandler().init(this);
|
new CommandHandler().init(this);
|
||||||
new ListenerHandler().init(this);
|
new ListenerHandler().init(this);
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import dev.plex.nush.NushAction;
|
|||||||
import dev.plex.nush.NushModule;
|
import dev.plex.nush.NushModule;
|
||||||
import dev.plex.nush.handler.impl.ActionHandler;
|
import dev.plex.nush.handler.impl.ActionHandler;
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
|
import dev.plex.util.PlexLog;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
@ -18,6 +19,9 @@ 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 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]")
|
@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")
|
@CommandPermissions(level = Rank.ADMIN, permission = "plex.nush.command")
|
||||||
public class NUSHCommand extends PlexCommand {
|
public class NUSHCommand extends PlexCommand {
|
||||||
@ -36,28 +40,34 @@ public class NUSHCommand extends PlexCommand {
|
|||||||
} else {
|
} else {
|
||||||
if (args[0].equalsIgnoreCase("work")) {
|
if (args[0].equalsIgnoreCase("work")) {
|
||||||
try {
|
try {
|
||||||
UUID nushIdentifier = UUID.fromString(args[0]);
|
UUID nushIdentifier = UUID.fromString(args[1]);
|
||||||
Message nushMessage = ActionHandler.MAP.get(nushIdentifier);
|
Message nushMessage = ActionHandler.MAP.get(nushIdentifier);
|
||||||
|
|
||||||
|
if (nushMessage == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
NushAction action = NushAction.fromOrdinal(Integer.parseInt(args[2]));
|
NushAction action = NushAction.fromOrdinal(Integer.parseInt(args[2]));
|
||||||
if (action == null) {
|
if (action == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (action == ACCEPT || action == CANCEL) {
|
||||||
|
ActionHandler.resolve(nushIdentifier, action);
|
||||||
|
return Component.text(action.humanReadable, NamedTextColor.YELLOW);
|
||||||
|
}
|
||||||
|
|
||||||
StringBuilder command = new StringBuilder();
|
StringBuilder command = new StringBuilder();
|
||||||
|
|
||||||
switch (action) {
|
|
||||||
case ACCEPT:
|
|
||||||
case CANCEL:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
command.append(action.name().toLowerCase());
|
command.append(action.name().toLowerCase());
|
||||||
break;
|
command.append(" ");
|
||||||
}
|
command.append(nushMessage.getSender());
|
||||||
|
|
||||||
command.append(" ").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());
|
Bukkit.dispatchCommand(commandSender, command.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
ActionHandler.resolve(nushIdentifier, action);
|
ActionHandler.resolve(nushIdentifier, action);
|
||||||
return Component.text(action.humanReadable, NamedTextColor.YELLOW);
|
return Component.text(action.humanReadable, NamedTextColor.YELLOW);
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
|
@ -22,6 +22,7 @@ import net.kyori.adventure.text.minimessage.MiniMessage;
|
|||||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
|
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class ActionHandler implements Handler {
|
public class ActionHandler implements Handler {
|
||||||
|
|
||||||
@ -39,8 +40,11 @@ public class ActionHandler implements Handler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (action == NushAction.ACCEPT) {
|
if (action == NushAction.ACCEPT) {
|
||||||
Audience.audience(Bukkit.getServer())
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
.sendMessage(Identity.identity(message.getSender()), getMessage(message));
|
if (player.getUniqueId() != message.getSender()) {
|
||||||
|
player.sendMessage(Identity.identity(message.getSender()), getMessage(message));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
MAP.remove(uuid);
|
MAP.remove(uuid);
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,14 @@ package dev.plex.nush.handler.impl;
|
|||||||
|
|
||||||
import dev.plex.nush.NushModule;
|
import dev.plex.nush.NushModule;
|
||||||
import dev.plex.nush.handler.Handler;
|
import dev.plex.nush.handler.Handler;
|
||||||
|
import dev.plex.nush.listener.impl.ChatListener;
|
||||||
import dev.plex.nush.listener.impl.JoinListener;
|
import dev.plex.nush.listener.impl.JoinListener;
|
||||||
|
|
||||||
public class ListenerHandler implements Handler {
|
public class ListenerHandler implements Handler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(NushModule module) {
|
public void init(NushModule module) {
|
||||||
|
module.registerListener(new ChatListener());
|
||||||
module.registerListener(new JoinListener());
|
module.registerListener(new JoinListener());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,13 +26,13 @@ public class ChatListener extends PlexListener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onChat(AsyncChatEvent event) {
|
public void onChat(AsyncChatEvent event) {
|
||||||
|
if(event.isCancelled()) return;
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
Instant firstJoined = Instant.ofEpochMilli(player.getFirstPlayed());
|
Instant firstJoined = Instant.ofEpochMilli(player.getFirstPlayed());
|
||||||
Instant rightNow = Instant.now();
|
Instant rightNow = Instant.now();
|
||||||
long difference = (Duration.between(firstJoined, rightNow).getSeconds() / 60);
|
long difference = (Duration.between(firstJoined, rightNow).getSeconds() / 60);
|
||||||
if (difference >= 15) {
|
if (difference >= 15) {
|
||||||
PlexLog.debug(player.getName(), "has been on the server for", difference,
|
PlexLog.debug("{0} has been on the server for {1} minutes, so Nush will skip them.", player.getName(), difference);
|
||||||
"minutes, so Nush will skip them.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ public class ChatListener extends PlexListener {
|
|||||||
RankManager rankManager = plex.getRankManager();
|
RankManager rankManager = plex.getRankManager();
|
||||||
|
|
||||||
if (rankManager.isAdmin(plexPlayer)) {
|
if (rankManager.isAdmin(plexPlayer)) {
|
||||||
PlexLog.debug(player.getName(), "is an admin so Nush will skip them.");
|
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
|
return; // we needn't process the chat message if they're an admin
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,6 +52,11 @@ public class ChatListener extends PlexListener {
|
|||||||
ActionHandler.MAP.put(key, message);
|
ActionHandler.MAP.put(key, message);
|
||||||
Component component = ActionHandler.getMessage(message);
|
Component component = ActionHandler.getMessage(message);
|
||||||
|
|
||||||
|
// Send the user the message so they think it got sent
|
||||||
|
player.sendMessage(component);
|
||||||
|
|
||||||
|
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);
|
String command = String.format("/nush work %s %d", key, value.ordinal);
|
||||||
component = component.append(
|
component = component.append(
|
||||||
@ -63,6 +68,6 @@ public class ChatListener extends PlexListener {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
PlexUtils.broadcast(component);
|
PlexUtils.broadcastToAdmins(component);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user