https://www.spigotmc.org/resources/t2c-opsecurity-permission-security-1-8-x-1-19-x.90739/update?update=478193
80 lines
3.0 KiB
Java
80 lines
3.0 KiB
Java
package net.t2code.opsecurity.events;
|
|
|
|
import net.t2code.opsecurity.Util;
|
|
import net.t2code.opsecurity.config.config.Config;
|
|
import net.t2code.opsecurity.check.OpCheck;
|
|
import net.t2code.opsecurity.check.PermissionCheck;
|
|
import net.t2code.opsecurity.system.Main;
|
|
import net.t2code.opsecurity.system.Permissions;
|
|
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
|
|
import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.event.EventHandler;
|
|
import org.bukkit.event.Listener;
|
|
import org.bukkit.event.player.*;
|
|
|
|
public class Events implements Listener {
|
|
public static void notifyPlayer(String msg) {
|
|
if (!Config.notifyJoinWarning.valueBoolean) return;
|
|
for (Player notifyPlayer : Bukkit.getOnlinePlayers()) {
|
|
if (!notifyPlayer.hasPermission(Permissions.notify)) continue;
|
|
T2Csend.player(notifyPlayer, msg);
|
|
if (Config.notifySoundEnable.valueBoolean) notifyPlayer.playSound(notifyPlayer.getLocation(), Config.notifySoundValue.sound, 3, 1);
|
|
}
|
|
}
|
|
|
|
@EventHandler
|
|
public void CommandSendEvent(PlayerCommandPreprocessEvent event) {
|
|
if (!Config.checkOnCommand.valueBoolean) return;
|
|
Player player = event.getPlayer();
|
|
if (OpCheck.onCheck(player, false) || PermissionCheck.onCheck(player, false)) {
|
|
if (event.isCancelled()) return;
|
|
event.setCancelled(true);
|
|
}
|
|
}
|
|
|
|
@EventHandler
|
|
public void PlayerChatEvent(PlayerChatEvent event) {
|
|
if (!Config.checkOnChat.valueBoolean) return;
|
|
Player player = event.getPlayer();
|
|
if (OpCheck.onCheck(player, false) || PermissionCheck.onCheck(player, false)) {
|
|
if (event.isCancelled()) return;
|
|
event.setCancelled(true);
|
|
}
|
|
}
|
|
|
|
@EventHandler
|
|
public void onInteract(PlayerInteractEvent event) {
|
|
if (!Config.checkOnInteract.valueBoolean) return;
|
|
Player player = event.getPlayer();
|
|
Bukkit.getScheduler().runTaskLaterAsynchronously(Main.getPlugin(), new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
if (OpCheck.onCheck(player, false) || PermissionCheck.onCheck(player, false)) {
|
|
event.setCancelled(true);
|
|
}
|
|
}
|
|
}, 1L);
|
|
}
|
|
|
|
@EventHandler
|
|
public void onJoinCheck(PlayerJoinEvent event) {
|
|
if (!Config.checkOnJoin.valueBoolean) return;
|
|
Player player = event.getPlayer();
|
|
Bukkit.getScheduler().runTaskLaterAsynchronously(Main.getPlugin(), new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
OpCheck.onCheck(player, true);
|
|
PermissionCheck.onCheck(player, true);
|
|
}
|
|
}, 1L);
|
|
}
|
|
|
|
@EventHandler
|
|
public void onJoinEvent(PlayerLoginEvent event) {
|
|
Player player = event.getPlayer();
|
|
T2CupdateAPI.join(Main.getPlugin(), Util.getPrefix(), Permissions.updatemsg, player, Util.getSpigotID(), Util.getDiscord());
|
|
}
|
|
}
|