mirror of
https://github.com/plexusorg/Module-NUSH.git
synced 2025-02-22 03:00:38 +00:00
Committing current progress, not ready for production
This commit is contained in:
parent
61ab59c9e2
commit
76b2b18fe4
@ -19,12 +19,13 @@ dependencies {
|
|||||||
compileOnly("org.projectlombok:lombok:1.18.22")
|
compileOnly("org.projectlombok:lombok:1.18.22")
|
||||||
annotationProcessor("org.projectlombok:lombok:1.18.22")
|
annotationProcessor("org.projectlombok:lombok:1.18.22")
|
||||||
compileOnly("io.papermc.paper:paper-api:1.18.2-R0.1-SNAPSHOT")
|
compileOnly("io.papermc.paper:paper-api:1.18.2-R0.1-SNAPSHOT")
|
||||||
compileOnly("dev.plex:Plex:1.0.1-SNAPSHOT")
|
compileOnly("dev.plex:server:1.1-SNAPSHOT")
|
||||||
|
compileOnly("dev.plex:api:1.1-SNAPSHOT")
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "dev.plex"
|
group = "dev.plex"
|
||||||
version = "1.0"
|
version = "1.0"
|
||||||
description = "ExampleModule"
|
description = "Stop raiding."
|
||||||
|
|
||||||
java {
|
java {
|
||||||
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
||||||
@ -39,7 +40,7 @@ publishing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tasks.getByName<Jar>("jar") {
|
tasks.getByName<Jar>("jar") {
|
||||||
archiveBaseName.set("Plex-ExampleModule")
|
archiveBaseName.set("Plex-NUSH")
|
||||||
archiveVersion.set("")
|
archiveVersion.set("")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
rootProject.name = "plexmodule-template"
|
rootProject.name = "Module-NUSH"
|
||||||
|
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
package dev.plex;
|
|
||||||
|
|
||||||
import dev.plex.command.ExampleCommand;
|
|
||||||
import dev.plex.listener.ExampleListener;
|
|
||||||
import dev.plex.module.PlexModule;
|
|
||||||
|
|
||||||
public class ExampleModule extends PlexModule
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void enable()
|
|
||||||
{
|
|
||||||
registerCommand(new ExampleCommand());
|
|
||||||
registerListener(new ExampleListener());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void disable()
|
|
||||||
{
|
|
||||||
// Unregistering listeners / commands is handled by Plex
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
package dev.plex.command;
|
|
||||||
|
|
||||||
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.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
@CommandParameters(name = "examplemodule", description = "An example command provided by Plex's example module")
|
|
||||||
@CommandPermissions(level = Rank.OP, permission = "plex.module.command")
|
|
||||||
public class ExampleCommand extends PlexCommand
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
protected Component execute(@NotNull CommandSender commandSender, @Nullable Player player, @NotNull String[] strings)
|
|
||||||
{
|
|
||||||
return Component.text("Example module command");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
package dev.plex.listener;
|
|
||||||
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
|
|
||||||
public class ExampleListener extends PlexListener
|
|
||||||
{
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
player.sendMessage(Component.text("This is a message from Plex's example module!").color(NamedTextColor.GOLD));
|
|
||||||
}
|
|
||||||
}
|
|
30
src/main/java/dev/plex/nush/NushModule.java
Normal file
30
src/main/java/dev/plex/nush/NushModule.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package dev.plex.nush;
|
||||||
|
|
||||||
|
import dev.plex.nush.handler.impl.CommandHandler;
|
||||||
|
import dev.plex.nush.handler.impl.ListenerHandler;
|
||||||
|
import dev.plex.module.PlexModule;
|
||||||
|
|
||||||
|
public class NushModule extends PlexModule
|
||||||
|
{
|
||||||
|
public static boolean enabled = false;
|
||||||
|
private static NushModule INSTANCE;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enable()
|
||||||
|
{
|
||||||
|
INSTANCE = this;
|
||||||
|
getPlex().messages.addDefault("nushToggled", "<aqua>{0} - {1} NUSH.");
|
||||||
|
new CommandHandler().init(this);
|
||||||
|
new ListenerHandler().init(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void disable()
|
||||||
|
{
|
||||||
|
// Unregistering listeners / commands is handled by Plex
|
||||||
|
}
|
||||||
|
|
||||||
|
public static NushModule getInstance() {
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
}
|
36
src/main/java/dev/plex/nush/command/impl/NUSHCommand.java
Normal file
36
src/main/java/dev/plex/nush/command/impl/NUSHCommand.java
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package dev.plex.nush.command.impl;
|
||||||
|
|
||||||
|
import dev.plex.command.PlexCommand;
|
||||||
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
|
import dev.plex.nush.NushModule;
|
||||||
|
import dev.plex.rank.enums.Rank;
|
||||||
|
import dev.plex.util.PlexUtils;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
@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
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
protected Component execute(@NotNull CommandSender commandSender, @Nullable Player player, @NotNull String[] args)
|
||||||
|
{
|
||||||
|
if(args.length == 0) {
|
||||||
|
NushModule.enabled = !NushModule.enabled;
|
||||||
|
} 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PlexUtils.broadcastToAdmins(messageComponent("nushToggled", commandSender.getName(), NushModule.enabled ? "Enabling" : "Disabling"));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
7
src/main/java/dev/plex/nush/handler/Handler.java
Normal file
7
src/main/java/dev/plex/nush/handler/Handler.java
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package dev.plex.nush.handler;
|
||||||
|
|
||||||
|
import dev.plex.nush.NushModule;
|
||||||
|
|
||||||
|
public interface Handler {
|
||||||
|
void init(NushModule module);
|
||||||
|
}
|
13
src/main/java/dev/plex/nush/handler/impl/CommandHandler.java
Normal file
13
src/main/java/dev/plex/nush/handler/impl/CommandHandler.java
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package dev.plex.nush.handler.impl;
|
||||||
|
|
||||||
|
import dev.plex.nush.NushModule;
|
||||||
|
import dev.plex.nush.command.impl.NUSHCommand;
|
||||||
|
import dev.plex.nush.handler.Handler;
|
||||||
|
|
||||||
|
public class CommandHandler implements Handler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(NushModule module) {
|
||||||
|
module.registerCommand(new NUSHCommand());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package dev.plex.nush.handler.impl;
|
||||||
|
|
||||||
|
import dev.plex.nush.NushModule;
|
||||||
|
import dev.plex.nush.handler.Handler;
|
||||||
|
import dev.plex.nush.listener.impl.JoinListener;
|
||||||
|
|
||||||
|
public class ListenerHandler implements Handler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(NushModule module) {
|
||||||
|
module.registerListener(new JoinListener());
|
||||||
|
}
|
||||||
|
}
|
50
src/main/java/dev/plex/nush/listener/impl/ChatListener.java
Normal file
50
src/main/java/dev/plex/nush/listener/impl/ChatListener.java
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
package dev.plex.nush.listener.impl;
|
||||||
|
|
||||||
|
import dev.plex.Plex;
|
||||||
|
import dev.plex.admin.Admin;
|
||||||
|
import dev.plex.cache.DataUtils;
|
||||||
|
import dev.plex.listener.PlexListener;
|
||||||
|
import dev.plex.nush.NushModule;
|
||||||
|
import dev.plex.player.PlexPlayer;
|
||||||
|
import dev.plex.rank.RankManager;
|
||||||
|
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
|
||||||
|
public class ChatListener extends PlexListener {
|
||||||
|
public static final Map<Admin, Integer> work = new HashMap<>();
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onChat(AsyncChatEvent event) {
|
||||||
|
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) return;
|
||||||
|
|
||||||
|
NushModule module = NushModule.getInstance();
|
||||||
|
Plex plex = module.getPlex();
|
||||||
|
PlexPlayer plexPlayer = DataUtils.getPlayer(player.getUniqueId());
|
||||||
|
RankManager rankManager = plex.getRankManager();
|
||||||
|
|
||||||
|
if(rankManager.isAdmin(plexPlayer)) return; // we needn't process the chat message if they're an admin
|
||||||
|
Entry<Admin, Integer> leastWork = null;
|
||||||
|
|
||||||
|
for (Entry<Admin, Integer> adminIntegerEntry : work.entrySet()) {
|
||||||
|
if(leastWork == null) {
|
||||||
|
leastWork = adminIntegerEntry;
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
if(leastWork.getValue() > adminIntegerEntry.getValue()) {
|
||||||
|
leastWork = adminIntegerEntry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
30
src/main/java/dev/plex/nush/listener/impl/JoinListener.java
Normal file
30
src/main/java/dev/plex/nush/listener/impl/JoinListener.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package dev.plex.nush.listener.impl;
|
||||||
|
|
||||||
|
import dev.plex.Plex;
|
||||||
|
import dev.plex.cache.DataUtils;
|
||||||
|
import dev.plex.listener.PlexListener;
|
||||||
|
import dev.plex.nush.NushModule;
|
||||||
|
import dev.plex.player.PlexPlayer;
|
||||||
|
import dev.plex.rank.RankManager;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
|
||||||
|
public class JoinListener extends PlexListener
|
||||||
|
{
|
||||||
|
@EventHandler
|
||||||
|
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)) return; // we only want to add admins
|
||||||
|
if(ChatListener.work.containsKey())
|
||||||
|
}
|
||||||
|
}
|
59
src/main/java/dev/plex/nush/util/ReflectionsUtil.java
Normal file
59
src/main/java/dev/plex/nush/util/ReflectionsUtil.java
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
package dev.plex.nush.util;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.reflect.ClassPath;
|
||||||
|
import dev.plex.Plex;
|
||||||
|
|
||||||
|
import dev.plex.util.PlexLog;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class ReflectionsUtil
|
||||||
|
{
|
||||||
|
@SuppressWarnings("UnstableApiUsage")
|
||||||
|
public static Set<Class<?>> getClassesFrom(String packageName)
|
||||||
|
{
|
||||||
|
Set<Class<?>> classes = new HashSet<>();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ClassPath path = ClassPath.from(Plex.class.getClassLoader());
|
||||||
|
ImmutableSet<ClassPath.ClassInfo> infoSet = path.getTopLevelClasses(packageName);
|
||||||
|
infoSet.forEach(info ->
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Class<?> clazz = Class.forName(info.getName());
|
||||||
|
classes.add(clazz);
|
||||||
|
}
|
||||||
|
catch (ClassNotFoundException ex)
|
||||||
|
{
|
||||||
|
PlexLog.error("Unable to find class " + info.getName() + " in " + packageName);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
PlexLog.error("Something went wrong while fetching classes from " + packageName);
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
return Collections.unmodifiableSet(classes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static <T> Set<Class<? extends T>> getClassesBySubType(String packageName, 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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return Collections.unmodifiableSet(classes);
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
name: ExampleModule
|
name: NushModule
|
||||||
main: dev.plex.ExampleModule
|
main: dev.plex.nush.NushModule
|
||||||
description: An example module for Plex
|
description: Stops raiding in its tracks.
|
||||||
version: 1.0
|
version: 1.0
|
Loading…
x
Reference in New Issue
Block a user