mirror of
https://github.com/bloodmc/GriefDefender.git
synced 2025-01-06 19:28:20 +01:00
Improve command execute checks with args. Closes #101
This commit is contained in:
parent
352f8ceb32
commit
ef9324efd1
@ -953,6 +953,10 @@ public static String handleCommandFlag(CommandSender src, String target) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static boolean validateCommandMapping(CommandSender src, String command, String pluginId) {
|
private static boolean validateCommandMapping(CommandSender src, String command, String pluginId) {
|
||||||
|
if (command.equalsIgnoreCase("any")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
Command commandMapping = NMSUtil.getInstance().getBukkitCommandMap().getCommand(command);
|
Command commandMapping = NMSUtil.getInstance().getBukkitCommandMap().getCommand(command);
|
||||||
if (commandMapping == null) {
|
if (commandMapping == null) {
|
||||||
TextAdapter.sendComponent(src, MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.PLUGIN_COMMAND_NOT_FOUND,
|
TextAdapter.sendComponent(src, MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.PLUGIN_COMMAND_NOT_FOUND,
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
import com.griefdefender.GDTimings;
|
import com.griefdefender.GDTimings;
|
||||||
import com.griefdefender.GriefDefenderPlugin;
|
import com.griefdefender.GriefDefenderPlugin;
|
||||||
import com.griefdefender.api.Tristate;
|
import com.griefdefender.api.Tristate;
|
||||||
|
import com.griefdefender.api.claim.TrustTypes;
|
||||||
import com.griefdefender.api.permission.flag.Flags;
|
import com.griefdefender.api.permission.flag.Flags;
|
||||||
import com.griefdefender.api.permission.option.Options;
|
import com.griefdefender.api.permission.option.Options;
|
||||||
import com.griefdefender.claim.GDClaim;
|
import com.griefdefender.claim.GDClaim;
|
||||||
@ -202,10 +203,21 @@ public void onPlayerCommand(PlayerCommandPreprocessEvent event) {
|
|||||||
|
|
||||||
if (GDFlags.COMMAND_EXECUTE && !inPvpCombat && !commandExecuteSourceBlacklisted && !commandExecuteTargetBlacklisted) {
|
if (GDFlags.COMMAND_EXECUTE && !inPvpCombat && !commandExecuteSourceBlacklisted && !commandExecuteTargetBlacklisted) {
|
||||||
// First check base command
|
// First check base command
|
||||||
Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, player.getLocation(), claim, Flags.COMMAND_EXECUTE, player, commandBaseTarget, player, true);
|
Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, player.getLocation(), claim, Flags.COMMAND_EXECUTE, player, commandBaseTarget, player, TrustTypes.MANAGER, true);
|
||||||
if (result != Tristate.FALSE) {
|
if (result != Tristate.FALSE && args.length > 0) {
|
||||||
// check with args
|
// Check with args
|
||||||
result = GDPermissionManager.getInstance().getFinalPermission(event, player.getLocation(), claim, Flags.COMMAND_EXECUTE, player, commandTargetWithArgs, player, true);
|
// Test with each arg, break once result returns false
|
||||||
|
String commandBaseTargetArgCheck = commandBaseTarget;
|
||||||
|
for (String arg : args) {
|
||||||
|
if (!arg.isEmpty()) {
|
||||||
|
commandBaseTargetArgCheck = commandBaseTargetArgCheck + "." + arg;
|
||||||
|
result = GDPermissionManager.getInstance().getFinalPermission(event, player.getLocation(), claim, Flags.COMMAND_EXECUTE, player, commandBaseTargetArgCheck, player, TrustTypes.MANAGER, true);
|
||||||
|
if (result == Tristate.FALSE) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (result == Tristate.FALSE) {
|
if (result == Tristate.FALSE) {
|
||||||
final Component denyMessage = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.COMMAND_BLOCKED,
|
final Component denyMessage = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.COMMAND_BLOCKED,
|
||||||
@ -224,9 +236,19 @@ public void onPlayerCommand(PlayerCommandPreprocessEvent event) {
|
|||||||
if (GDFlags.COMMAND_EXECUTE_PVP && inPvpCombat && !commandExecuteSourceBlacklisted && !commandExecuteTargetBlacklisted) {
|
if (GDFlags.COMMAND_EXECUTE_PVP && inPvpCombat && !commandExecuteSourceBlacklisted && !commandExecuteTargetBlacklisted) {
|
||||||
// First check base command
|
// First check base command
|
||||||
Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, player.getLocation(), claim, Flags.COMMAND_EXECUTE_PVP, player, commandBaseTarget, player, true);
|
Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, player.getLocation(), claim, Flags.COMMAND_EXECUTE_PVP, player, commandBaseTarget, player, true);
|
||||||
if (result != Tristate.FALSE) {
|
if (result != Tristate.FALSE && args.length > 0) {
|
||||||
// check with args
|
// check with args
|
||||||
result = GDPermissionManager.getInstance().getFinalPermission(event, player.getLocation(), claim, Flags.COMMAND_EXECUTE_PVP, player, commandTargetWithArgs, player, true);
|
// Test with each arg, break once result returns false
|
||||||
|
String commandBaseTargetArgCheck = commandBaseTarget;
|
||||||
|
for (String arg : args) {
|
||||||
|
if (!arg.isEmpty()) {
|
||||||
|
commandBaseTargetArgCheck = commandBaseTargetArgCheck + "." + arg;
|
||||||
|
result = GDPermissionManager.getInstance().getFinalPermission(event, player.getLocation(), claim, Flags.COMMAND_EXECUTE_PVP, player, commandBaseTargetArgCheck, player, true);
|
||||||
|
if (result == Tristate.FALSE) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (result == Tristate.FALSE) {
|
if (result == Tristate.FALSE) {
|
||||||
final Component denyMessage = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.COMMAND_BLOCKED,
|
final Component denyMessage = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.COMMAND_BLOCKED,
|
||||||
@ -235,6 +257,8 @@ public void onPlayerCommand(PlayerCommandPreprocessEvent event) {
|
|||||||
"player", claim.getOwnerName()));
|
"player", claim.getOwnerName()));
|
||||||
GriefDefenderPlugin.sendMessage(player, denyMessage);
|
GriefDefenderPlugin.sendMessage(player, denyMessage);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
GDTimings.PLAYER_COMMAND_EVENT.stopTiming();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GDTimings.PLAYER_COMMAND_EVENT.stopTiming();
|
GDTimings.PLAYER_COMMAND_EVENT.stopTiming();
|
||||||
|
@ -964,6 +964,10 @@ public static String handleCommandFlag(CommandSource src, String target) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static boolean validateCommandMapping(CommandSource src, String command, String pluginId) {
|
private static boolean validateCommandMapping(CommandSource src, String command, String pluginId) {
|
||||||
|
if (command.equals("any")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
CommandMapping commandMapping = Sponge.getCommandManager().get(command).orElse(null);
|
CommandMapping commandMapping = Sponge.getCommandManager().get(command).orElse(null);
|
||||||
if (commandMapping == null) {
|
if (commandMapping == null) {
|
||||||
TextAdapter.sendComponent(src, MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.PLUGIN_COMMAND_NOT_FOUND,
|
TextAdapter.sendComponent(src, MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.PLUGIN_COMMAND_NOT_FOUND,
|
||||||
|
@ -364,10 +364,21 @@ public void onPlayerCommand(SendCommandEvent event, @First Player player) {
|
|||||||
|
|
||||||
if (GDFlags.COMMAND_EXECUTE && !inPvpCombat && !commandExecuteSourceBlacklisted && !commandExecuteTargetBlacklisted) {
|
if (GDFlags.COMMAND_EXECUTE && !inPvpCombat && !commandExecuteSourceBlacklisted && !commandExecuteTargetBlacklisted) {
|
||||||
// First check base command
|
// First check base command
|
||||||
Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, player.getLocation(), claim, Flags.COMMAND_EXECUTE, event.getSource(), commandBaseTarget, player, true);
|
Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, player.getLocation(), claim, Flags.COMMAND_EXECUTE, event.getSource(), commandBaseTarget, player, TrustTypes.MANAGER, true);
|
||||||
if (result != Tristate.FALSE) {
|
if (result != Tristate.FALSE && args.length > 0) {
|
||||||
// check with args
|
// Check with args
|
||||||
result = GDPermissionManager.getInstance().getFinalPermission(event, player.getLocation(), claim, Flags.COMMAND_EXECUTE, event.getSource(), commandTargetWithArgs, player, true);
|
// Test with each arg, break once result returns false
|
||||||
|
String commandBaseTargetArgCheck = commandBaseTarget;
|
||||||
|
for (String arg : args) {
|
||||||
|
if (!arg.isEmpty()) {
|
||||||
|
commandBaseTargetArgCheck = commandBaseTargetArgCheck + "." + arg;
|
||||||
|
result = GDPermissionManager.getInstance().getFinalPermission(event, player.getLocation(), claim, Flags.COMMAND_EXECUTE, event.getSource(), commandBaseTargetArgCheck, player, TrustTypes.MANAGER, true);
|
||||||
|
if (result == Tristate.FALSE) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (result == Tristate.FALSE) {
|
if (result == Tristate.FALSE) {
|
||||||
final Component denyMessage = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.COMMAND_BLOCKED,
|
final Component denyMessage = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.COMMAND_BLOCKED,
|
||||||
@ -385,9 +396,19 @@ public void onPlayerCommand(SendCommandEvent event, @First Player player) {
|
|||||||
if (GDFlags.COMMAND_EXECUTE_PVP && inPvpCombat && !commandExecuteSourceBlacklisted && !commandExecuteTargetBlacklisted) {
|
if (GDFlags.COMMAND_EXECUTE_PVP && inPvpCombat && !commandExecuteSourceBlacklisted && !commandExecuteTargetBlacklisted) {
|
||||||
// First check base command
|
// First check base command
|
||||||
Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, player.getLocation(), claim, Flags.COMMAND_EXECUTE_PVP, event.getSource(), commandBaseTarget, player, true);
|
Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, player.getLocation(), claim, Flags.COMMAND_EXECUTE_PVP, event.getSource(), commandBaseTarget, player, true);
|
||||||
if (result != Tristate.FALSE) {
|
if (result != Tristate.FALSE && args.length > 0) {
|
||||||
// check with args
|
// check with args
|
||||||
result = GDPermissionManager.getInstance().getFinalPermission(event, player.getLocation(), claim, Flags.COMMAND_EXECUTE_PVP, event.getSource(), commandTargetWithArgs, player, true);
|
// Test with each arg, break once result returns false
|
||||||
|
String commandBaseTargetArgCheck = commandBaseTarget;
|
||||||
|
for (String arg : args) {
|
||||||
|
if (!arg.isEmpty()) {
|
||||||
|
commandBaseTargetArgCheck = commandBaseTargetArgCheck + "." + arg;
|
||||||
|
result = GDPermissionManager.getInstance().getFinalPermission(event, player.getLocation(), claim, Flags.COMMAND_EXECUTE_PVP, event.getSource(), commandBaseTargetArgCheck, player, true);
|
||||||
|
if (result == Tristate.FALSE) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (result == Tristate.FALSE) {
|
if (result == Tristate.FALSE) {
|
||||||
final Component denyMessage = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.COMMAND_BLOCKED,
|
final Component denyMessage = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.COMMAND_BLOCKED,
|
||||||
|
Loading…
Reference in New Issue
Block a user