mirror of
https://github.com/darverdevs/Uranium.git
synced 2024-11-21 23:06:04 -08:00
feat(listeners): add some more events relating to vanish
This commit is contained in:
parent
e4af236671
commit
f655a5af03
|
@ -6,6 +6,8 @@ import org.bukkit.entity.Player;
|
|||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||
|
||||
import uranium.listeners.ChatListener;
|
||||
import uranium.listeners.CommandListener;
|
||||
import uranium.listeners.PlayerListener;
|
||||
import uranium.user.*;
|
||||
|
||||
|
@ -13,6 +15,9 @@ public class Main extends JavaPlugin implements PluginMessageListener {
|
|||
|
||||
public void onEnable() {
|
||||
setupConfig();
|
||||
setupListeners();
|
||||
setupCommands();
|
||||
setupTasks();
|
||||
setupPluginChannels();
|
||||
}
|
||||
|
||||
|
@ -23,6 +28,8 @@ public class Main extends JavaPlugin implements PluginMessageListener {
|
|||
|
||||
private void setupListeners() {
|
||||
getServer().getPluginManager().registerEvents(new PlayerListener(this), this);
|
||||
getServer().getPluginManager().registerEvents(new ChatListener(this), this);
|
||||
getServer().getPluginManager().registerEvents(new CommandListener(this), this);
|
||||
}
|
||||
|
||||
private void setupCommands() {
|
||||
|
@ -45,11 +52,6 @@ public class Main extends JavaPlugin implements PluginMessageListener {
|
|||
getLogger().info("Done!");
|
||||
}
|
||||
|
||||
public void reloadConfig() {
|
||||
super.reloadConfig();
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
||||
if (!channel.equals("BungeeCord")) return;
|
||||
|
|
57
src/main/java/uranium/listeners/CommandListener.java
Normal file
57
src/main/java/uranium/listeners/CommandListener.java
Normal file
|
@ -0,0 +1,57 @@
|
|||
package uranium.listeners;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import uranium.Main;
|
||||
import uranium.user.*;
|
||||
import uranium.util.StringUtil;
|
||||
|
||||
public class CommandListener implements Listener {
|
||||
|
||||
private final Main plugin;
|
||||
|
||||
public CommandListener(Main plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onPlayerPreprocessCommand(PlayerCommandPreprocessEvent event) {
|
||||
if (!plugin.getConfig().getBoolean("override-ipban")) return;
|
||||
String message = event.getMessage().substring(1);
|
||||
String[] args = message.split("\\s+");
|
||||
String command = args[0];
|
||||
|
||||
if (command.equalsIgnoreCase("ipban")
|
||||
|| command.equalsIgnoreCase("banip")
|
||||
|| command.equalsIgnoreCase("ban-ip")) {
|
||||
args[0] = "ubanip";
|
||||
event.setMessage("/" + String.join(" ", args));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
|
||||
public void onPlayerPreprocessCommand2(PlayerCommandPreprocessEvent event) {
|
||||
User user = UserManager.getUser(event.getPlayer());
|
||||
String message = event.getMessage();
|
||||
|
||||
if (!StringUtil.validateMessage(message)) {
|
||||
event.setCancelled(true);
|
||||
user.sendMessage("&cYour command contained blacklisted words.");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||
public void onPlayerPreprocessCommand3(PlayerCommandPreprocessEvent event) {
|
||||
User user = UserManager.getUser(event.getPlayer());
|
||||
String message = event.getMessage();
|
||||
|
||||
if (user.hasPermission("uranium.commandspy")) return;
|
||||
UserManager.getUsers().forEach((u) -> {
|
||||
if (u.isCommandSpy())
|
||||
u.sendMessage(plugin.getConfig().getString("prefix") + "&e" + user.getName() + ": " + message);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -1,14 +1,23 @@
|
|||
package uranium.listeners;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.inventory.DoubleChestInventory;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import uranium.Main;
|
||||
import uranium.user.User;
|
||||
import uranium.user.UserManager;
|
||||
import uranium.util.StringUtil;
|
||||
|
||||
public class PlayerListener implements Listener {
|
||||
|
||||
|
@ -23,7 +32,10 @@ public class PlayerListener implements Listener {
|
|||
if (!plugin.getConfig().getBoolean("chat-filter.enabled")) return;
|
||||
String username = event.getPlayer().getName();
|
||||
|
||||
|
||||
if (!StringUtil.validateUsername(username)) {
|
||||
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
|
||||
event.setKickMessage(StringUtil.cc("&cYour username contains blacklisted words."));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
@ -47,4 +59,58 @@ public class PlayerListener implements Listener {
|
|||
UserManager.removeUser(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
|
||||
User user = UserManager.getUser(event.getPlayer());
|
||||
if (user == null) return; // Somehow this can occur
|
||||
if (!user.isVanished()) return;
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||
User user = UserManager.getUser(event.getPlayer());
|
||||
if (user == null) return; // Somehow this can occur
|
||||
if (!user.isVanished()) return;
|
||||
event.setCancelled(true);
|
||||
user.sendMessage("&cYou can't do that while vanished.");
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (!(event.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
|
||||
User user = UserManager.getUser(event.getPlayer());
|
||||
if (!user.isVanished()) return;
|
||||
|
||||
if (event.getClickedBlock().getType() == Material.CHEST
|
||||
|| event.getClickedBlock().getType() == Material.TRAPPED_CHEST) {
|
||||
event.setCancelled(true);
|
||||
Chest chest = (Chest) event.getClickedBlock().getState();
|
||||
Inventory inv = Bukkit.createInventory(null, chest.getInventory() instanceof DoubleChestInventory ? 54 : 27, chest.getInventory().getTitle());
|
||||
inv.setContents(chest.getInventory().getContents());
|
||||
user.getPlayer().openInventory(inv);
|
||||
user.sendMessage(plugin.getConfig().getString("prefix") + "Silently opening this chest.");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
User user = UserManager.getUser((Player) event.getWhoClicked());
|
||||
if (!user.isVanished()) return;
|
||||
|
||||
if (event.getInventory().getType() == InventoryType.CHEST)
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerDamageEntity(EntityDamageByEntityEvent event) {
|
||||
if (!(event.getEntity() instanceof Player) || !(event.getDamager() instanceof Player)) return;
|
||||
User user = UserManager.getUser((Player) event.getDamager());
|
||||
|
||||
if (user.isVanished()) {
|
||||
event.setCancelled(true);
|
||||
user.sendMessage("&cYou can't do that while vanished.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -35,4 +35,6 @@ suspicious-domains:
|
|||
webhook-url: ''
|
||||
|
||||
# Should we override the regular /banip, /ipban & /ban-ip commands with Uranium's version?
|
||||
override-ipban: true
|
||||
override-ipban: true
|
||||
# Main prefix
|
||||
prefix: '&8[&aUranium&8] &7'
|
Loading…
Reference in New Issue
Block a user