Add Super Listener to whitelist events
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This is a very strict measure, but works great in disabling features and keeping the server to a very barebones setup.
This commit is contained in:
parent
4c9689af6f
commit
b6aeed7ea8
41
pom.xml
41
pom.xml
@ -42,6 +42,7 @@
|
|||||||
<version>1.19.2-R0.1-SNAPSHOT</version>
|
<version>1.19.2-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- https://mvnrepository.com/artifact/org.jetbrains/annotations -->
|
<!-- https://mvnrepository.com/artifact/org.jetbrains/annotations -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jetbrains</groupId>
|
<groupId>org.jetbrains</groupId>
|
||||||
@ -56,6 +57,46 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.reflections/reflections -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.reflections</groupId>
|
||||||
|
<artifactId>reflections</artifactId>
|
||||||
|
<version>0.10.2</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>single</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<mainClass>wtf.beatrice.limbomanager.LimboManager</mainClass>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
|
<descriptorRefs>
|
||||||
|
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||||
|
</descriptorRefs>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
<version>3.4.1</version>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -37,6 +37,10 @@ public class LimboManager extends JavaPlugin {
|
|||||||
pluginManager.registerEvents(new WorldLoadHandler(), this);
|
pluginManager.registerEvents(new WorldLoadHandler(), this);
|
||||||
pluginManager.registerEvents(new PlayerChatManager(), this);
|
pluginManager.registerEvents(new PlayerChatManager(), this);
|
||||||
|
|
||||||
|
SuperListener superListener = new SuperListener();
|
||||||
|
pluginManager.registerEvents(superListener, this);
|
||||||
|
superListener.doStuff();
|
||||||
|
|
||||||
// no need to check if folder exists, it will just skip creation.
|
// no need to check if folder exists, it will just skip creation.
|
||||||
getDataFolder().mkdirs();
|
getDataFolder().mkdirs();
|
||||||
schematicsFolderPath = getDataFolder().getAbsolutePath() + File.separator + "schematics";
|
schematicsFolderPath = getDataFolder().getAbsolutePath() + File.separator + "schematics";
|
||||||
|
@ -0,0 +1,72 @@
|
|||||||
|
package wtf.beatrice.limbomanager.listeners;
|
||||||
|
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.plugin.EventExecutor;
|
||||||
|
import org.reflections.Reflections;
|
||||||
|
import wtf.beatrice.limbomanager.LimboManager;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class SuperListener implements Listener
|
||||||
|
{
|
||||||
|
|
||||||
|
public void doStuff() {
|
||||||
|
|
||||||
|
// search event classes
|
||||||
|
Reflections reflections = new Reflections("org.bukkit");// change to also find custom events
|
||||||
|
Set<Class<? extends Event>> eventClasses = reflections.getSubTypesOf(Event.class).stream().
|
||||||
|
filter(clazz -> Arrays.stream(clazz.getDeclaredFields())
|
||||||
|
.anyMatch(field -> field.getType().getName().endsWith("HandlerList")))
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
LimboManager.getInstance().getLogger().info("Found " + eventClasses.size() + " available events!");
|
||||||
|
LimboManager.getInstance().getLogger()
|
||||||
|
.info(eventClasses.stream().map(Class::getName).collect(Collectors.joining(", ")));
|
||||||
|
|
||||||
|
// register events
|
||||||
|
EventExecutor eventExecutor = (listener, event) -> iGetCalledForEveryEvent(event);
|
||||||
|
eventClasses.forEach(clazz -> LimboManager.getInstance().getServer().getPluginManager()
|
||||||
|
.registerEvent(clazz, this, EventPriority.MONITOR, eventExecutor, LimboManager.getInstance()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private final String[] dontLog = { "PlayerMoveEvent", "BlockFadeEvent", "BlockPhysicsEvent", "LeavesDecayEvent",
|
||||||
|
"PlayerStatisticIncrementEvent", "PlayerRecipeDiscoverEvent", "PlayerArmSwingEvent", "BlockDropItemEvent",
|
||||||
|
"BlockFertilizeEvent", "AsyncPlayerChatPreviewEvent", "InventoryOpenEvent"
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
private final String[] allowed = {"PlayerMoveEvent", "PlayerTeleportEvent", "ServerCommandEvent",
|
||||||
|
"StandardPaperServerListPingEventImpl", "PlayerGameModeChangeEvent", "WorldUnloadEvent",
|
||||||
|
"TimeSkipEvent", "PlayerToggleSprintEvent", "PlayerChatEvent", "AsyncPlayerChatEvent",
|
||||||
|
"GenericGameEvent", "InventoryCreativeEvent", "PlayerItemHeldEvent", "PlayerInteractEvent",
|
||||||
|
"BlockPlaceEvent", "BlockBreakEvent", "PlayerToggleSneakEvent", "PlayerKickEvent",
|
||||||
|
"InventoryClickEvent"
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
public void iGetCalledForEveryEvent(Event event) {
|
||||||
|
if (Arrays.stream(dontLog).anyMatch(ignored -> event.getEventName().equals(ignored))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Arrays.stream(allowed).noneMatch(allowed -> event.getEventName().equals(allowed))) {
|
||||||
|
if(event instanceof Cancellable)
|
||||||
|
{
|
||||||
|
((Cancellable) event).setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(event instanceof Cancellable)
|
||||||
|
{
|
||||||
|
if(Arrays.stream(allowed).noneMatch(allowed -> event.getEventName().equals(allowed))) {
|
||||||
|
LimboManager.getInstance().getLogger().warning(event.getEventName() + " was called!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user