mirror of
https://github.com/darverdevs/Uranium.git
synced 2024-11-24 16:16:05 -08:00
feat: add banip, commandspy & domain commands
This commit is contained in:
parent
f655a5af03
commit
97ebb635a7
|
@ -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() {
|
||||
|
|
62
src/main/java/uranium/commands/BanIP.java
Normal file
62
src/main/java/uranium/commands/BanIP.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
36
src/main/java/uranium/commands/CommandSpy.java
Normal file
36
src/main/java/uranium/commands/CommandSpy.java
Normal 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;
|
||||
}
|
||||
}
|
55
src/main/java/uranium/commands/Domain.java
Normal file
55
src/main/java/uranium/commands/Domain.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
28
src/main/java/uranium/listeners/BlockListener.java
Normal file
28
src/main/java/uranium/listeners/BlockListener.java
Normal 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.");
|
||||
}
|
||||
|
||||
}
|
|
@ -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) {
|
||||
|
|
23
src/main/java/uranium/util/Util.java
Normal file
23
src/main/java/uranium/util/Util.java
Normal 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));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user