feat: add banip, commandspy & domain commands

This commit is contained in:
ColdDev 2022-10-24 15:48:10 +01:00
parent f655a5af03
commit 97ebb635a7
7 changed files with 210 additions and 7 deletions

View File

@ -6,9 +6,7 @@ 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.listeners.*;
import uranium.user.*;
public class Main extends JavaPlugin implements PluginMessageListener {
@ -30,6 +28,7 @@ public class Main extends JavaPlugin implements PluginMessageListener {
getServer().getPluginManager().registerEvents(new PlayerListener(this), this);
getServer().getPluginManager().registerEvents(new ChatListener(this), this);
getServer().getPluginManager().registerEvents(new CommandListener(this), this);
getServer().getPluginManager().registerEvents(new BlockListener(), this);
}
private void setupCommands() {

View File

@ -0,0 +1,62 @@
package uranium.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import uranium.Main;
import uranium.user.User;
import uranium.user.UserManager;
import uranium.util.StringUtil;
import uranium.util.Util;
public class BanIP implements CommandExecutor {
private final Main plugin;
public BanIP(Main plugin) {
this.plugin = plugin;
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(StringUtil.cc(plugin.getConfig().getString("prefix") + "&cPlease use the Bungee console to ban IPs."));
return true;
}
User user = UserManager.getUser((Player) sender);
if (!user.hasPermission("uranium.banip")) {
user.sendMessage(plugin.getConfig().getString("prefix") + "&cYou do not have permission to use this command.");
return true;
}
if (args.length < 1) {
user.sendMessage(plugin.getConfig().getString("prefix") + "&cUsage: /ubanip <player>");
return true;
}
Player target = plugin.getServer().getPlayer(args[0]);
User targetUser;
if (target == null) {
user.sendMessage(plugin.getConfig().getString("prefix") + "&cThat player is not online.");
return true;
}
targetUser = UserManager.getUser(target);
if (targetUser.hasPermission("uranium.banip.exempt")) {
user.sendMessage(plugin.getConfig().getString("prefix") + "&cYou cannot IP ban this user!");
return true;
}
if (targetUser.getIP() == null) {
user.sendMessage(plugin.getConfig().getString("prefix") + "&cThis user's IP address has not been detected yet. Please wait a moment.");
return true;
}
user.sendBungeeMessage("EAG|ConsoleCommand", "eag-ban-ip " + targetUser.getIP());
if (Util.multiplePlayersOnIP(targetUser.getIP()))
user.sendBungeeMessage("EAG|ConsoleCommand", "eag-ban-ip confirm");
user.sendMessage(plugin.getConfig().getString("prefix") + "This user has been IP banned. Please note that if anyone else had the same IP, they were also kicked.");
Util.sendAll(plugin.getConfig().getString("prefix") + "&c" + targetUser.getName() + " &7was IP banned by &c" + user.getName() + "&7.");
return true;
}
}

View File

@ -0,0 +1,36 @@
package uranium.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import uranium.Main;
import uranium.user.User;
import uranium.user.UserManager;
import uranium.util.StringUtil;
public class CommandSpy implements CommandExecutor {
private final Main plugin;
public CommandSpy(Main plugin) {
this.plugin = plugin;
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(StringUtil.cc(plugin.getConfig().getString("prefix") + "&cThis command can only be used in-game."));
return true;
}
User user = UserManager.getUser((Player) sender);
if (!user.hasPermission("uranium.commandspy")) {
user.sendMessage(plugin.getConfig().getString("prefix") + "&cYou do not have permission to use this command.");
return true;
}
user.setCommandSpy(!user.isCommandSpy());
user.sendMessage(plugin.getConfig().getString("prefix") + "You have " + (user.isCommandSpy() ? "enabled" : "disabled") + " &aCommand Spy&7.");
return true;
}
}

View File

@ -0,0 +1,55 @@
package uranium.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import uranium.Main;
import uranium.user.User;
import uranium.user.UserManager;
import uranium.util.StringUtil;
public class Domain implements CommandExecutor {
private final Main plugin;
public Domain(Main plugin) {
this.plugin = plugin;
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(StringUtil.cc(plugin.getConfig().getString("prefix") + "&cThis command can only be used in-game."));
return true;
}
User user = UserManager.getUser((Player) sender);
if (!user.hasPermission("uranium.domain")) {
user.sendMessage(plugin.getConfig().getString("prefix") + "&cUsage: /domain <player>");
return true;
}
Player target = plugin.getServer().getPlayer(args[0]);
User targetUser;
if (target == null) {
user.sendMessage(plugin.getConfig().getString("prefix") + "&cPlayer " + args[0] + " is not online.");
return true;
}
targetUser = UserManager.getUser(target);
String domain = targetUser.getDomain();
if (domain == null) {
user.sendMessage(plugin.getConfig().getString("prefix") + "&c" + targetUser.getName() + "'s domain has not been detected yet.");
return true;
}
user.sendMessage(plugin.getConfig().getString("prefix") + "&a" + targetUser.getName() + " &7" + (
domain.equals("null")
? "is using an offline download."
: domain.equals("")
? "is using the debug runtime."
: "'s domain is &a" + domain + "&7."));
return true;
}
}

View File

@ -0,0 +1,28 @@
package uranium.listeners;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import uranium.user.User;
import uranium.user.UserManager;
public class BlockListener implements Listener {
@EventHandler(ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
User user = UserManager.getUser(event.getPlayer());
if (!user.isVanished()) return;
event.setCancelled(true);
user.sendMessage("&cYou can't do that while vanished.");
}
@EventHandler(ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) {
User user = UserManager.getUser(event.getPlayer());
if (!user.isVanished()) return;
event.setCancelled(true);
user.sendMessage("&cYou can't do that while vanished.");
}
}

View File

@ -92,7 +92,7 @@ public class User {
this.commandSpy = commandSpy;
}
public void sendBungeeMessage(Player player, String channel, String message) {
public void sendBungeeMessage(String channel, String message) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF(channel);
out.writeUTF(message);
@ -100,7 +100,7 @@ public class User {
player.sendPluginMessage(JavaPlugin.getPlugin(Main.class), "BungeeCord", out.toByteArray());
}
public void sendBungeeMessage(Player player, String channel) {
public void sendBungeeMessage(String channel) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF(channel);
@ -108,8 +108,8 @@ public class User {
}
public void onJoin() {
sendBungeeMessage(player, "IP");
sendBungeeMessage(player, "EAG|GetDomain");
sendBungeeMessage("IP");
sendBungeeMessage("EAG|GetDomain");
}
public void sendMessage(String message) {

View File

@ -0,0 +1,23 @@
package uranium.util;
import org.bukkit.Bukkit;
import uranium.user.UserManager;
import java.util.concurrent.atomic.AtomicInteger;
public class Util {
public static boolean multiplePlayersOnIP(String ip) {
AtomicInteger count = new AtomicInteger(0);
UserManager.getUsers().forEach((user) -> {
if (user.getIP().equalsIgnoreCase(ip)) count.getAndAdd(1);
});
return count.get() > 1;
}
public static void sendAll(String message) {
UserManager.getUsers().forEach((user) -> user.sendMessage(message));
Bukkit.getConsoleSender().sendMessage(StringUtil.cc(message));
}
}