Skip to content

Commit

Permalink
Add Ban Restrictions
Browse files Browse the repository at this point in the history
- Fix typos.
- Give the plugin the ability to restrict ops and permanent ops being banned.
- Update README.md.
  • Loading branch information
aappleton8 committed May 13, 2019
1 parent c61f13d commit 874693e
Show file tree
Hide file tree
Showing 9 changed files with 355 additions and 68 deletions.
Binary file removed Jar/OpPermissions_v1.0.2.2_1.7-1.13.jar
Binary file not shown.
Binary file added Jar/OpPermissions_v1.0.3.1_1.7.6-1.14.0.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 aappleton8
Copyright (c) 2018 - 2019 aappleton8

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
108 changes: 87 additions & 21 deletions OpPermissions/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: OpPermissions
main: me.OpPermissions.OpPermissionsMainClass
version: 1.0.2.2
version: 1.0.3.1
description: A plugin helping with op permissions
author: aappleton3
database: false
commands:
opset:
description: Add or remove someone to the list of permenant ops
description: Add or remove someone to the list of permanent ops
usage: /opset add|remove|list|version|{help [all|config] [1|2|3]}|check|{config <action> [field]} [playername|data]
permission-message: You do not have the required permissions to perform this command
oppermissions:
Expand All @@ -25,9 +25,13 @@ commands:
description: The command to add and remove blocked commands
usage: /opcommand {add|remove|check <command>}|list
permission-message: You do not have the required permissions to perform this command
opbancommands:
description: The command to add and remove blocked ban commands for ops
usage: /opbancommands {add|remove|check <command>}|list
permission-message: You do not have the required permissions to perform this command
permissions:
oppermissions.*:
description: Add or remove players to the permenant ops list
description: Add or remove players to the permanent ops list
default: false
children:
oppermissions.read.*: true
Expand All @@ -42,23 +46,25 @@ permissions:
oppermissions.seepluginmessages: true
oppermissions.commands.*: true
oppermissions.showopattempts: true
oppermissions.ban.*: true
oppermissions.opbancommands.*: true
oppermissions.read.*:
description: List and check the permenant ops
description: List and check the permanent ops
default: op
children:
oppermissions.read.list: true
oppermissions.read.check: true
oppermissions.read.list:
description: List the permenant ops
description: List the permanent ops
default: op
oppermissions.read.check:
description: Check if a player is a permenant op
description: Check if a player is a permanent op
default: op
oppermissions.add:
description: Add a permenant op to the list
description: Add a permanent op to the list
default: false
oppermissions.remove:
description: Remove a permenant op from the list
description: Remove a permanent op from the list
default: false
oppermissions.config.*:
description: Change the config file
Expand Down Expand Up @@ -89,6 +95,9 @@ permissions:
oppermissions.config.set.permanentopsusecommands: true
oppermissions.config.set.showopattempts: true
oppermissions.config.set.showcommanduse: true
oppermissions.config.set.bannableops: true
oppermissions.config.set.bannablepermanentops: true
oppermissions.config.set.deoponban: true
oppermissions.config.set.opscanop:
description: Set the value of the opscanop field of the config file
default: false
Expand Down Expand Up @@ -139,6 +148,26 @@ permissions:
default: false
children:
oppermissions.config.seedetailedsethelp: true
oppermissions.config.set.bannableops:
description: Let the player ban ops
default: false
children:
oppermissions.config.seedetailedsethelp: true
oppermissions.config.set.bannablepermanentops:
description: Let the player ban permanent ops
default: false
children:
oppermissions.config.seedetailedsethelp: true
oppermissions.config.set.deoponban:
description: Make the plugin deop ops who get banned
default: false
children:
oppermissions.config.seedetailedsethelp: true
oppermissions.config.set.showbanattempts:
description: Let the player see op ban attempts, even if they are unsuccessful
default: false
children:
oppermissions.config.seedetailedsethelp: true
oppermissions.showallhelp:
description: Can see help for commands the player does not have permission to use
default: op
Expand Down Expand Up @@ -188,29 +217,66 @@ permissions:
default: false
children:
oppermissions.commands.add: true
oppermissions.command.remove: true
oppermissions.command.list: true
oppermissions.command.check: true
oppermissions.command.command: true
oppermissions.command.show: true
oppermissions.command.add:
description: Add a enw blocked command
default: false
oppermissions.command.remove:
oppermissions.commands.remove: true
oppermissions.commands.list: true
oppermissions.commands.check: true
oppermissions.commands.command: true
oppermissions.commands.show: true
oppermissions.commands.add:
description: Add a new blocked command
default: false
oppermissions.commands.remove:
description: remove a blocked command
default: false
oppermissions.command.list:
oppermissions.commands.list:
description: List the blocked commands
default: false
oppermissions.command.check:
oppermissions.commands.check:
description: Check if a command is blocked
default: false
oppermissions.command.command:
oppermissions.commands.command:
description: Perform the blocked commands
default: false
oppermissions.command.show:
oppermissions.commands.show:
description: Be notified every time someone tries to use (even if unsuccessfully) one of the commands on the blocked command list
default: false
oppermissions.showopattempts:
description: Be notified every time someone tries to use (even if unsuccessfully) the /op or /deop command
default: false
oppermissions.ban.*:
description: Ban all ops and permanent ops, depending non the config file
default: false
children:
oppermissions.ban.permanentops: true
oppermissions.ban.show: true
oppermissions.ban.permanentops:
description: Ban permanent ops depending on the config file
default: false
children:
oppermissions.ban.ops: true
oppermissions.ban.ops:
description: Ban ops depending on the config file
default: false
oppermissions.ban.show:
description: Be notified every time someone tries to use (even if unsuccessfully) one of the ban commands on an op
default: false
oppermissions.opbancommands.*:
description: The root command to add and remove blocked commands
default: false
children:
oppermissions.opbancommands.add: true
oppermissions.opbancommands.remove: true
oppermissions.opbancommands.list: true
oppermissions.opbancommands.check: true
oppermissions.opbancommands.add:
description: Add a new watched ban command
default: false
oppermissions.opbancommands.remove:
description: Remove a watched ban command
default: false
oppermissions.opbancommands.list:
description: List the watched ban commands
default: false
oppermissions.opbancommands.check:
description: Check if a command is watched ban command
default: false
11 changes: 11 additions & 0 deletions OpPermissions/src/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ announceops: no
showopattempts: true
permanentopsusecommands: true
showcommanduse: true
bannableops: default
bannablepermanentops: default
deoponban: false
showbanattempts: true
ops: []
commands: []
opbancommands:
- ban
- tempban
- kick
- blacklist
- ip-ban
- ban-ip

124 changes: 124 additions & 0 deletions OpPermissions/src/me/OpPermissions/MyPlayerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public void onPlayerJoin(PlayerJoinEvent event) {
}
}

@SuppressWarnings("deprecation")
@EventHandler (ignoreCancelled = false, priority = EventPriority.MONITOR)
public void onAllPlayerCommands(PlayerCommandPreprocessEvent event) {
if (plugin.getConfig().getBoolean("showopattempts")) {
Expand All @@ -92,12 +93,27 @@ public void onAllPlayerCommands(PlayerCommandPreprocessEvent event) {
Bukkit.broadcast(ChatColor.BLUE + plugin.formattedPluginName + event.getPlayer().getName() + " tried to use '" + event.getMessage() + "' with a success status of: " + String.valueOf(!event.isCancelled()), "oppermissions.command.show");
}
}
if (plugin.getConfig().getBoolean("showbanattempts")) {
List<String> banCommands = plugin.getConfig().getStringList("opbancommands");
String[] command = event.getMessage().replace("/", "").toLowerCase().split(" ");
if (command.length > 1) {
if (banCommands.contains(command[0])) {
if (Bukkit.getOfflinePlayer(command[1]) != null) {
if (Bukkit.getOfflinePlayer(command[1]).isOp()) {
Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.BLUE + plugin.formattedPluginName + event.getPlayer().getName() + " tried to use '" + event.getMessage() + "' with a success status of: " + String.valueOf(!event.isCancelled()));
Bukkit.broadcast(ChatColor.BLUE + plugin.formattedPluginName + event.getPlayer().getName() + " tried to use '" + event.getMessage() + "' with a success status of: " + String.valueOf(!event.isCancelled()), "oppermissions.ban.show");
}
}
}
}
}
}

@SuppressWarnings("deprecation")
@EventHandler (ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPlayerCommand(PlayerCommandPreprocessEvent event) {
boolean canDeop = true;
boolean checkBanCommand = false;
if (event.getMessage().startsWith("/op") || event.getMessage().startsWith("/deop")) {
String[] rawArgs = event.getMessage().replace("/", "").split(" ");
if ((rawArgs.length == 2) && (rawArgs[0].equalsIgnoreCase("op") || rawArgs[0].equalsIgnoreCase("deop"))) {
Expand Down Expand Up @@ -150,6 +166,7 @@ else if (opSetting.equalsIgnoreCase("no") || opSetting.equalsIgnoreCase("false")
}
else {
List<String> blockedCommands = plugin.getConfig().getStringList("commands");
List<String> banCommands = plugin.getConfig().getStringList("opbancommands");
if (blockedCommands.contains(event.getMessage().replace("/", "").toLowerCase())) {
if (event.getPlayer().hasPermission("oppermissions.command.command")) {
// No action required
Expand All @@ -175,6 +192,10 @@ else if (plugin.getConfig().getBoolean("permanentopsusecommands")) {
plugin.noPermission((CommandSender) event.getPlayer());
}
}
String[] commandWord = event.getMessage().split(" ");
if (banCommands.contains(commandWord[0].replace("/", "").toLowerCase()) && (event.isCancelled() == false) && (commandWord.length > 1)) {
checkBanCommand = true;
}
}
if ((event.getMessage().startsWith("/deop")) && (canDeop == true)) {
String[] rawArgs = event.getMessage().replace("/", "").split(" ");
Expand Down Expand Up @@ -204,6 +225,109 @@ else if (event.getPlayer().hasPermission("oppermissions.remove")) {
}
}
}
if (checkBanCommand == true) {
String playerNameToBan = event.getMessage().split(" ")[1];
Boolean playerToBanOnList = false;
Boolean playerOnList = false;
if (Bukkit.getOfflinePlayer(playerNameToBan).isOp()) {
if (plugin.getConfig().getBoolean("useuuids") == false) {
if (plugin.getConfig().getStringList("ops").contains(playerNameToBan)) {
playerToBanOnList = true;
}
if (plugin.getConfig().getStringList("ops").contains(event.getPlayer().getName())) {
playerOnList = true;
}
}
else {
String playerToBan = Bukkit.getPlayer(playerNameToBan).getUniqueId().toString();
if (plugin.getConfig().getStringList("ops").contains(playerToBan)) {
playerToBanOnList = true;
}
if (plugin.getConfig().getStringList("ops").contains(event.getPlayer().getUniqueId().toString())) {
playerOnList = true;
}
}
String bannableOps = plugin.getConfig().getString("bannableops");
String bannablePermanentOps = plugin.getConfig().getString("bannablepermanentops");
// Handle ops
if (bannableOps.equalsIgnoreCase("default")) {
// No acton required
}
else if (bannableOps.equalsIgnoreCase("no") || bannableOps.equalsIgnoreCase("false")) {
event.setCancelled(true);
event.getPlayer().sendMessage(ChatColor.RED + "Only the console can punish ops ");
}
else if (bannableOps.equalsIgnoreCase("op")) {
if (event.getPlayer().isOp() == false) {
event.setCancelled(true);
event.getPlayer().sendMessage(ChatColor.RED + "You must be an op to punish an op ");
}
}
else if (bannableOps.equalsIgnoreCase("permanent")) {
if (playerOnList == false) {
event.setCancelled(true);
event.getPlayer().sendMessage(ChatColor.RED + "You must be a permanent op to ban an op ");
}
}
else if (bannableOps.equalsIgnoreCase("permission")) {
if (event.getPlayer().hasPermission("oppermissions.ban.ops") == false) {
event.setCancelled(true);
event.getPlayer().sendMessage(ChatColor.RED + "You need the permission 'oppermissions.ban.ops' to ban an op ");
}
}
else {
event.getPlayer().sendMessage(ChatColor.RED + "The " + plugin.getName() + " plugin config has an invalid value in the 'bannableops' field and as such this command has been disallowed ");
plugin.logger.warning(plugin.formattedPluginName + "The config has an invalid value in the 'bannableops' field (it should be 'op', 'permission', 'permanent', 'default', 'false' or 'no'");
event.setCancelled(true);
}
// Handle permanent ops
if ((event.isCancelled() == false) && (playerToBanOnList == true)) {
if (bannablePermanentOps.equalsIgnoreCase("default")) {
// No action required
}
else if (bannablePermanentOps.equalsIgnoreCase("no") || bannablePermanentOps.equalsIgnoreCase("false")) {
event.setCancelled(true);
event.getPlayer().sendMessage(ChatColor.RED + "Only the console can punish permanent ops ");
}
else if (bannablePermanentOps.equalsIgnoreCase("op")) {
if (event.getPlayer().isOp() == false) {
event.setCancelled(true);
event.getPlayer().sendMessage(ChatColor.RED + "You must be an op to punish a permanent op ");
}
}
else if (bannablePermanentOps.equalsIgnoreCase("permanent")) {
if (playerOnList == false) {
event.setCancelled(true);
event.getPlayer().sendMessage(ChatColor.RED + "You must be a permanent op to punish a permanent op ");
}
}
else if (bannablePermanentOps.equalsIgnoreCase("permission")) {
if (event.getPlayer().hasPermission("oppermissions.ban.permanentops") == false) {
event.setCancelled(true);
event.getPlayer().sendMessage(ChatColor.RED + "You need the permission 'oppermissions.ban.permanentops' to ban a permanent op ");
}
}
else {
event.getPlayer().sendMessage(ChatColor.RED + "The " + plugin.getName() + " plugin config has an invalid value in the 'bannablepermanentops' field and as such this command has been disallowed ");
plugin.logger.warning(plugin.formattedPluginName + "The config has an invalid value in the 'bannablepermanentops' field (it should be 'op', 'permission', 'permanent', 'default', 'false' or 'no'");
event.setCancelled(true);
}
}
if (event.isCancelled() == false) {
if (plugin.getConfig().getBoolean("deoponban")) {
if (plugin.getConfig().getBoolean("useuuids") == true) {
playerNameToBan = Bukkit.getOfflinePlayer(playerNameToBan).getUniqueId().toString();
}
if (playerToBanOnList) {
List<String> ops = plugin.getConfig().getStringList("ops");
ops.remove(playerNameToBan);
plugin.getConfig().set("ops", ops);
plugin.saveConfig();
}
}
}
}
}
}

@SuppressWarnings("deprecation")
Expand Down
Loading

0 comments on commit 874693e

Please sign in to comment.