mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-29 16:46:45 +01:00
fix: remove plot-alias with "/p alias" (#1779)
* fix: remove plot-alias with "/p alias" remove plot-alias with "/p alias" #1718 * Apply requested Review Changes Restored the original Permisson to keep backwards compatibility Clean unused imports. * added some improvements after testing added some improvements after testing
This commit is contained in:
parent
3779b17720
commit
7d39d09317
@ -132,6 +132,8 @@ permissions:
|
|||||||
plots.set.biome: true
|
plots.set.biome: true
|
||||||
plots.set.home: true
|
plots.set.home: true
|
||||||
plots.set.alias: true
|
plots.set.alias: true
|
||||||
|
plots.alias.set: true
|
||||||
|
plots.alias.remove: true
|
||||||
plots.set.description: true
|
plots.set.description: true
|
||||||
plots.description: true
|
plots.description: true
|
||||||
plots.alias: true
|
plots.alias: true
|
||||||
@ -238,6 +240,8 @@ permissions:
|
|||||||
plotme.use.nameplot:
|
plotme.use.nameplot:
|
||||||
children:
|
children:
|
||||||
plots.set.alias: true
|
plots.set.alias: true
|
||||||
|
plots.alias.set: true
|
||||||
|
plots.alias.remove: true
|
||||||
plotme.limit.*:
|
plotme.limit.*:
|
||||||
children:
|
children:
|
||||||
plots.plot.*: true
|
plots.plot.*: true
|
||||||
|
@ -2,27 +2,83 @@ package com.intellectualcrafters.plot.commands;
|
|||||||
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.intellectualcrafters.plot.PS;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
import com.intellectualcrafters.plot.object.StringWrapper;
|
||||||
import com.intellectualcrafters.plot.util.MainUtil;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
|
import com.intellectualcrafters.plot.util.Permissions;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
@CommandDeclaration(
|
@CommandDeclaration(
|
||||||
command = "setalias",
|
command = "setalias",
|
||||||
permission = "plots.set.alias",
|
permission = "plots.alias",
|
||||||
description = "Set the plot name",
|
description = "Set the plot name",
|
||||||
usage = "/plot alias <alias>",
|
usage = "/plot alias <set|remove> <alias>",
|
||||||
aliases = {"alias", "sa", "name", "rename", "setname", "seta", "nameplot"},
|
aliases = {"alias", "sa", "name", "rename", "setname", "seta", "nameplot"},
|
||||||
category = CommandCategory.SETTINGS,
|
category = CommandCategory.SETTINGS,
|
||||||
requiredType = RequiredType.NONE)
|
requiredType = RequiredType.NONE)
|
||||||
public class Alias extends SetCommand {
|
public class Alias extends SubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean set(PlotPlayer player, Plot plot, String alias) {
|
public boolean onCommand(PlotPlayer player, String[] args) {
|
||||||
|
|
||||||
|
if (args.length == 0) {
|
||||||
|
C.COMMAND_SYNTAX.send(player, "/plot alias <set|remove> <value>");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Location loc = player.getLocation();
|
||||||
|
Plot plot = loc.getPlotAbs();
|
||||||
|
if (plot == null) {
|
||||||
|
return !sendMessage(player, C.NOT_IN_PLOT);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!plot.hasOwner()) {
|
||||||
|
sendMessage(player, C.PLOT_NOT_CLAIMED);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!plot.isOwner(player.getUUID())) {
|
||||||
|
MainUtil.sendMessage(player, C.NO_PLOT_PERMS);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean result = false;
|
||||||
|
|
||||||
|
switch (args[0].toLowerCase()) {
|
||||||
|
case "set":
|
||||||
|
if (args.length != 2) {
|
||||||
|
C.COMMAND_SYNTAX.send(player, "/plot alias <set> <value>");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(canExecuteCommand(player, C.PERMISSION_ALIAS_SET, false) || canExecuteCommand(player, C.PERMISSION_ALIAS_SET_OBSOLETE, false)) {
|
||||||
|
result = setAlias(player, plot, args[1]);
|
||||||
|
} else {
|
||||||
|
MainUtil.sendMessage(player, C.NO_PERMISSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case "remove":
|
||||||
|
if(canExecuteCommand(player, C.PERMISSION_ALIAS_REMOVE, true)) {
|
||||||
|
result = removeAlias(player, plot);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
C.COMMAND_SYNTAX.send(player, "/plot alias <set|remove> <alias>");
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private boolean setAlias(PlotPlayer player, Plot plot, String alias) {
|
||||||
|
|
||||||
if (alias.isEmpty()) {
|
if (alias.isEmpty()) {
|
||||||
C.COMMAND_SYNTAX.send(player, getUsage());
|
C.COMMAND_SYNTAX.send(player, "/plot alias <set> <value>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (alias.length() >= 50) {
|
if (alias.length() >= 50) {
|
||||||
@ -47,4 +103,20 @@ public class Alias extends SetCommand {
|
|||||||
MainUtil.sendMessage(player, C.ALIAS_SET_TO.s().replaceAll("%alias%", alias));
|
MainUtil.sendMessage(player, C.ALIAS_SET_TO.s().replaceAll("%alias%", alias));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean removeAlias(PlotPlayer player, Plot plot) {
|
||||||
|
plot.setAlias(null);
|
||||||
|
MainUtil.sendMessage(player, C.ALIAS_REMOVED.s());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean canExecuteCommand(PlotPlayer player, C caption, boolean sendMessage) {
|
||||||
|
if (!Permissions.hasPermission(player, caption)) {
|
||||||
|
if(sendMessage) {
|
||||||
|
MainUtil.sendMessage(player, C.NO_PERMISSION);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -156,6 +156,9 @@ public enum C {
|
|||||||
PERMISSION_SHARED("plots.visit.shared", "static.permissions"),
|
PERMISSION_SHARED("plots.visit.shared", "static.permissions"),
|
||||||
PERMISSION_VISIT_OTHER("plots.visit.other", "static.permissions"),
|
PERMISSION_VISIT_OTHER("plots.visit.other", "static.permissions"),
|
||||||
PERMISSION_HOME("plots.home", "static.permissions"),
|
PERMISSION_HOME("plots.home", "static.permissions"),
|
||||||
|
PERMISSION_ALIAS_SET_OBSOLETE("plots.set.alias", "static.permissions"), // Note this is for backwards compatibility
|
||||||
|
PERMISSION_ALIAS_SET("plots.alias.set", "static.permissions"),
|
||||||
|
PERMISSION_ALIAS_REMOVE("plots.alias.remove", "static.permissions"),
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Static console
|
* Static console
|
||||||
@ -395,6 +398,7 @@ public enum C {
|
|||||||
* Alias
|
* Alias
|
||||||
*/
|
*/
|
||||||
ALIAS_SET_TO("$2Plot alias set to $1%alias%", "Alias"),
|
ALIAS_SET_TO("$2Plot alias set to $1%alias%", "Alias"),
|
||||||
|
ALIAS_REMOVED("$2Plot alias removed", "Alias"),
|
||||||
MISSING_ALIAS("$2You need to specify an alias", "Alias"),
|
MISSING_ALIAS("$2You need to specify an alias", "Alias"),
|
||||||
ALIAS_TOO_LONG("$2The alias must be < 50 characters in length", "Alias"),
|
ALIAS_TOO_LONG("$2The alias must be < 50 characters in length", "Alias"),
|
||||||
ALIAS_IS_TAKEN("$2That alias is already taken", "Alias"),
|
ALIAS_IS_TAKEN("$2That alias is already taken", "Alias"),
|
||||||
|
@ -110,6 +110,7 @@ ALIAS_SET_TO: "$2Plot Alias auf $1%alias% gesetzt"
|
|||||||
MISSING_ALIAS: "$2Du musst einen Alias angeben"
|
MISSING_ALIAS: "$2Du musst einen Alias angeben"
|
||||||
ALIAS_TOO_LONG: "$2Der Alias darf nicht länger als 50 Zeichen sein"
|
ALIAS_TOO_LONG: "$2Der Alias darf nicht länger als 50 Zeichen sein"
|
||||||
ALIAS_IS_TAKEN: "$2Dieser Alias wird bereits verwendet"
|
ALIAS_IS_TAKEN: "$2Dieser Alias wird bereits verwendet"
|
||||||
|
ALIAS_REMOVED: "$2Der Alias wurde gelöscht"
|
||||||
MISSING_POSITION: "$2Du musst eine Position angeben. Mögliche Werte: $1none"
|
MISSING_POSITION: "$2Du musst eine Position angeben. Mögliche Werte: $1none"
|
||||||
POSITION_SET: "$1Die Position wurde auf deinen aktuellen Standort gesetzt"
|
POSITION_SET: "$1Die Position wurde auf deinen aktuellen Standort gesetzt"
|
||||||
HOME_ARGUMENT: "$2Verwende /plot set home [none]"
|
HOME_ARGUMENT: "$2Verwende /plot set home [none]"
|
||||||
|
@ -122,6 +122,8 @@ permissions:
|
|||||||
plots.set.biome: true
|
plots.set.biome: true
|
||||||
plots.set.home: true
|
plots.set.home: true
|
||||||
plots.set.alias: true
|
plots.set.alias: true
|
||||||
|
plots.alias.set: true
|
||||||
|
plots.alias.remove: true
|
||||||
plots.set.description: true
|
plots.set.description: true
|
||||||
plots.description: true
|
plots.description: true
|
||||||
plots.alias: true
|
plots.alias: true
|
||||||
|
Loading…
Reference in New Issue
Block a user