package play.corelia.online; import java.util.Arrays; import java.util.List; import java.util.function.BiPredicate; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerPortalEvent; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.RegisteredListener; import org.bukkit.plugin.java.JavaPlugin; public class Core extends JavaPlugin { // Get the value "config" FileConfiguration config = getConfig(); public void onEnable() { config = getConfig(); this.saveDefaultConfig(); loadConfig(); this.getCommand("dp").setExecutor(new Commands(this)); } public void loadConfig(){ getConfig().options().copyDefaults(true); saveConfig(); } @SuppressWarnings("unchecked") static void filter(Class type, BiPredicate filter) { HandlerList handler; try { handler = (HandlerList) type.getDeclaredMethod("getHandlerList").invoke(null); } catch (Throwable e) { throw new RuntimeException(e); } Arrays.asList(handler.getRegisteredListeners()).forEach(listener -> { handler.unregister(listener); handler.register(new RegisteredListener(listener.getListener(), ($, event) -> { if (filter.test(listener.getPlugin(), (Type) event)) listener.callEvent(event); }, listener.getPriority(), listener.getPlugin(), false)); }); } @SuppressWarnings("unlikely-arg-type") public void supress() { ConfigurationSection targetPlugin = config.getConfigurationSection("location.world"); for (String key : targetPlugin.getKeys(false)) { List targetWorld = targetPlugin.getStringList(key); filter(PlayerInteractEvent.class, (plugin, event) -> plugin == targetPlugin && event.getPlayer().getWorld().equals(targetWorld)); } } public void repeat(PlayerPortalEvent event) { for (int i = 0; i >= 0; i++) { supress(); } } }