mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-24 11:45:31 +01:00
WIP: Added admin why command.
This commit is contained in:
parent
0020cbf849
commit
e89cdb8d6a
@ -0,0 +1,72 @@
|
||||
package world.bentobox.bentobox.api.commands.admin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
public class AdminWhyCommand extends ConfirmableCommand {
|
||||
|
||||
public AdminWhyCommand(CompositeCommand parent) {
|
||||
super(parent, "why");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("admin.why");
|
||||
setParametersHelp("commands.admin.why.parameters");
|
||||
setDescription("commands.admin.why.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
// If args are not right, show help
|
||||
if (args.size() != 1) {
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
// Get target
|
||||
UUID targetUUID = getPlayers().getUUID(args.get(0));
|
||||
if (targetUUID == null) {
|
||||
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
|
||||
return false;
|
||||
}
|
||||
// Set meta data on player
|
||||
User target = User.getInstance(targetUUID);
|
||||
if (!target.isOnline()) {
|
||||
user.sendMessage("general.errors.offline-player");
|
||||
return false;
|
||||
}
|
||||
// Determine the debug mode and toggle if required
|
||||
boolean newValue = !target.getPlayer().getMetadata(getWorld().getName() + "_why_debug").stream()
|
||||
.filter(p -> p.getOwningPlugin().equals(getPlugin())).findFirst().map(p -> p.asBoolean()).orElse(false);
|
||||
if (newValue) {
|
||||
user.sendMessage("commands.admin.why.turning-on", TextVariables.NAME, target.getName());
|
||||
} else {
|
||||
user.sendMessage("commands.admin.why.turning-off", TextVariables.NAME, target.getName());
|
||||
}
|
||||
// Set the debug meta
|
||||
target.getPlayer().setMetadata(getWorld().getName() + "_why_debug", new FixedMetadataValue(getPlugin(), newValue));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
|
||||
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
|
||||
if (args.isEmpty()) {
|
||||
// Don't show every player on the server. Require at least the first letter
|
||||
return Optional.empty();
|
||||
}
|
||||
List<String> options = new ArrayList<>(Util.getOnlinePlayerList(user));
|
||||
return Optional.of(Util.tabLimit(options, lastArg));
|
||||
}
|
||||
|
||||
}
|
@ -15,6 +15,7 @@ import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
/**
|
||||
* Abstract class for flag listeners. Provides common code.
|
||||
@ -40,7 +41,11 @@ public abstract class AbstractFlagListener implements Listener {
|
||||
NOT_ALLOWED_ON_ISLAND,
|
||||
NOT_ALLOWED_IN_WORLD,
|
||||
ERROR_NO_ASSOCIATED_USER,
|
||||
NOT_SET
|
||||
NOT_SET,
|
||||
SETTING_ALLOWED_ON_ISLAND,
|
||||
SETTING_NOT_ALLOWED_ON_ISLAND,
|
||||
SETTING_ALLOWED_IN_WORLD,
|
||||
SETTING_NOT_ALLOWED_IN_WORLD
|
||||
}
|
||||
|
||||
private BentoBox plugin = BentoBox.getInstance();
|
||||
@ -143,13 +148,12 @@ public abstract class AbstractFlagListener implements Listener {
|
||||
* @return true if the check is okay, false if it was disallowed
|
||||
*/
|
||||
public boolean checkIsland(Event e, Location loc, Flag flag, boolean silent) {
|
||||
why = Why.NOT_SET;
|
||||
// If this is not an Island World or a standard Nether or End, skip
|
||||
if (!plugin.getIWM().inWorld(loc)
|
||||
|| (plugin.getIWM().isNether(loc.getWorld()) && !plugin.getIWM().isNetherIslands(loc.getWorld()))
|
||||
|| (plugin.getIWM().isEnd(loc.getWorld()) && !plugin.getIWM().isEndIslands(loc.getWorld()))
|
||||
) {
|
||||
why = Why.UNPROTECTED_WORLD;
|
||||
report(user, e, loc, flag, Why.UNPROTECTED_WORLD);
|
||||
return true;
|
||||
}
|
||||
// Get the island and if present
|
||||
@ -158,9 +162,9 @@ public abstract class AbstractFlagListener implements Listener {
|
||||
if (flag.getType().equals(Flag.Type.SETTING)) {
|
||||
// If the island exists, return the setting, otherwise return the default setting for this flag
|
||||
if (island.isPresent()) {
|
||||
why = island.map(x -> x.isAllowed(flag)).orElse(false) ? Why.ALLOWED_ON_ISLAND : Why.NOT_ALLOWED_ON_ISLAND;
|
||||
report(user, e, loc, flag, island.map(x -> x.isAllowed(flag)).orElse(false) ? Why.SETTING_ALLOWED_ON_ISLAND : Why.SETTING_NOT_ALLOWED_ON_ISLAND);
|
||||
} else {
|
||||
why = flag.isSetForWorld(loc.getWorld()) ? Why.ALLOWED_IN_WORLD : Why.NOT_ALLOWED_IN_WORLD;
|
||||
report(user, e, loc, flag, flag.isSetForWorld(loc.getWorld()) ? Why.SETTING_ALLOWED_IN_WORLD : Why.SETTING_NOT_ALLOWED_IN_WORLD);
|
||||
}
|
||||
return island.map(x -> x.isAllowed(flag)).orElse(flag.isSetForWorld(loc.getWorld()));
|
||||
}
|
||||
@ -172,18 +176,18 @@ public abstract class AbstractFlagListener implements Listener {
|
||||
// TODO: is this the correct handling here?
|
||||
if (user == null && !createEventUser(e)) {
|
||||
plugin.logError("Check island had no associated user! " + e.getEventName());
|
||||
why = Why.ERROR_NO_ASSOCIATED_USER;
|
||||
report(user, e, loc, flag, Why.ERROR_NO_ASSOCIATED_USER);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Ops or "bypass everywhere" moderators can do anything
|
||||
if (user.isOp() || user.hasPermission(getIWM().getPermissionPrefix(loc.getWorld()) + ".mod.bypass." + flag.getID() + ".everywhere")) {
|
||||
user = null;
|
||||
if (user.isOp() || user.hasPermission(getIWM().getPermissionPrefix(loc.getWorld()) + ".mod.bypass." + flag.getID() + ".everywhere")) {
|
||||
if (user.isOp()) {
|
||||
why = Why.OP;
|
||||
report(user, e, loc, flag, Why.OP);
|
||||
} else {
|
||||
why = Why.BYPASS_EVERYWHERE;
|
||||
report(user, e, loc, flag, Why.BYPASS_EVERYWHERE);
|
||||
}
|
||||
user = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -193,29 +197,41 @@ public abstract class AbstractFlagListener implements Listener {
|
||||
if (island.isPresent()) {
|
||||
// If it is not allowed on the island, "bypass island" moderators can do anything
|
||||
if (island.get().isAllowed(user, flag)) {
|
||||
why = Why.RANK_ALLOWED;
|
||||
}
|
||||
if (user.hasPermission(getIWM().getPermissionPrefix(loc.getWorld()) + ".mod.bypass." + flag.getID() + ".island")) {
|
||||
why = Why.BYPASS_ISLAND;
|
||||
}
|
||||
report(user, e, loc, flag, Why.RANK_ALLOWED);
|
||||
user = null;
|
||||
return true;
|
||||
} else if (user.hasPermission(getIWM().getPermissionPrefix(loc.getWorld()) + ".mod.bypass." + flag.getID() + ".island")) {
|
||||
report(user, e, loc, flag, Why.BYPASS_ISLAND);
|
||||
user = null;
|
||||
return true;
|
||||
}
|
||||
report(user, e, loc, flag, Why.NOT_ALLOWED_ON_ISLAND);
|
||||
// Clear the user for the next time
|
||||
why = Why.NOT_ALLOWED_ON_ISLAND;
|
||||
user = null;
|
||||
return false;
|
||||
}
|
||||
// The player is in the world, but not on an island, so general world settings apply
|
||||
if (flag.isSetForWorld(loc.getWorld())) {
|
||||
why = Why.ALLOWED_IN_WORLD;
|
||||
report(user, e, loc, flag, Why.ALLOWED_IN_WORLD);
|
||||
user = null;
|
||||
return true;
|
||||
} else {
|
||||
why = Why.NOT_ALLOWED_IN_WORLD;
|
||||
report(user, e, loc, flag, Why.NOT_ALLOWED_IN_WORLD);
|
||||
noGo(e, flag, silent);
|
||||
user = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void report(User user, Event e, Location loc, Flag flag, Why why) {
|
||||
if (user.getPlayer().getMetadata(loc.getWorld().getName() + "_why_debug").stream()
|
||||
.filter(p -> p.getOwningPlugin().equals(getPlugin())).findFirst().map(p -> p.asBoolean()).orElse(false)) {
|
||||
plugin.log("Why: " + e.getEventName() + " in world " + loc.getWorld().getName() + " at " + Util.xyz(loc.toVector()));
|
||||
plugin.log("Why: " + (user == null ? "Unknown" : user.getName()) + " " + flag.getID() + " - " + why.name());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the flag for this ID
|
||||
* @param id - the flag ID
|
||||
|
@ -171,6 +171,11 @@ commands:
|
||||
description: "deletes a player's island"
|
||||
cannot-delete-team-leader: "&cAll island members have to be kicked from the island before deleting it."
|
||||
deleted-island: "&aIsland at &e[xyz] &ahas been successfully deleted."
|
||||
why:
|
||||
parameters: "<player>"
|
||||
description: "Toggle console protection debug reporting"
|
||||
turning-on: "Turning on console debug for [name]"
|
||||
turning-off: "Turning off console debug for [name]"
|
||||
bentobox:
|
||||
description: "BentoBox admin command"
|
||||
about:
|
||||
|
Loading…
Reference in New Issue
Block a user