This commit is contained in:
Jesse Boyd
2015-09-29 16:29:28 +10:00
parent c3eb44f51c
commit b9bb9f5674
10 changed files with 175 additions and 83 deletions

View File

@ -4,12 +4,16 @@ import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.StringMan;
import com.plotsquared.general.commands.Command;
@ -91,10 +95,35 @@ public class GenerateDocs {
}
public static List<String> getPerms(final String cmd, final List<String> lines) {
final ArrayList<String> perms = new ArrayList<String>();
final HashSet<String> perms = new HashSet<String>();
final Pattern p = Pattern.compile("\"([^\"]*)\"");
final Pattern p2 = Pattern.compile("C.PERMISSION_\\s*(\\w+)");
String last = null;
for (final String line : lines) {
Matcher m2 = p2.matcher(line);
while (m2.find()) {
perms.add(C.valueOf("PERMISSION_" + m2.group(1)).s());
}
if (line.contains("Permissions.hasPermission(")) {
String[] split = line.split("Permissions.hasPermission");
split = Arrays.copyOfRange(split, 1, split.length);
for (String method : split) {
String perm = method.split("[,|)]")[1].trim();
if (!perm.toLowerCase().equals(perm)) {
if (perm.startsWith("C.")) {
perm = C.valueOf(perm.split("\\.")[1]).s();
}
else {
continue;
}
}
else {
perm = perm.substring(1, perm.length() - 1);
}
perms.add(perm);
}
final Matcher m = p.matcher(line);
while (m.find()) {
String perm = m.group(1);
@ -102,21 +131,42 @@ public class GenerateDocs {
perm += "<arg>";
}
if (perm.startsWith(".")) {
perms.set(perms.size() - 1, perms.get(perms.size() - 1) + perm);
perms.remove(last);
perms.add(last + perm);
} else if (perm.contains(".")) {
last = perm;
perms.add(perm);
}
}
}
else if (line.contains("Permissions.hasPermissionRange")) {
String[] split = line.split("Permissions.hasPermissionRange");
split = Arrays.copyOfRange(split, 1, split.length);
for (String method : split) {
String perm = method.split("[,|)]")[1].trim();
if (!perm.toLowerCase().equals(perm)) {
if (perm.startsWith("C.")) {
perm = C.valueOf(perm.split("\\.")[1]).s();
}
else {
continue;
}
}
else {
perm = perm.substring(1, perm.length() - 1);
}
perms.add(perm + ".<#>");
}
}
}
switch (cmd.toLowerCase()) {
case "auto":
case "claim": {
perms.add("plots.plot.#");
perms.add("plots.plot.<#>");
break;
}
}
return perms;
return new ArrayList<>(perms);
}
public static String getComments(final List<String> lines) {

View File

@ -86,10 +86,15 @@ public class Merge extends SubCommand {
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
return false;
}
final boolean admin = Permissions.hasPermission(plr, "plots.admin.command.merge");
if (!plot.isOwner(plr.getUUID()) && !admin) {
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
UUID uuid = plr.getUUID();
if (!plot.isOwner(uuid)) {
if (!Permissions.hasPermission(plr, "plots.admin.command.merge")) {
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
else {
uuid = plot.owner;
}
}
final PlotWorld plotworld = PS.get().getPlotWorld(plot.world);
if ((EconHandler.manager != null) && plotworld.USE_ECONOMY && plotworld.MERGE_PRICE > 0d && EconHandler.manager.getMoney(plr) < plotworld.MERGE_PRICE) {
@ -98,8 +103,8 @@ public class Merge extends SubCommand {
}
int direction = -1;
final int size = plot.getConnectedPlots().size();
final int maxSize = Permissions.hasPermissionRange(plr, "plots.merge", Settings.MAX_PLOTS);
if (size >= maxSize) {
final int maxSize = Permissions.hasPermissionRange(plr, "plots.merge", Settings.MAX_PLOTS);
if (size - 1> maxSize) {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.merge." + (size + 1));
return false;
}
@ -120,7 +125,7 @@ public class Merge extends SubCommand {
// }
} else {
if (args[0].equalsIgnoreCase("all") || args[0].equalsIgnoreCase("auto")) {
if (MainUtil.autoMerge(plot, -1, maxSize - size, plr.getUUID(), (args.length != 2) || !args[1].equalsIgnoreCase("false"))) {
if (MainUtil.autoMerge(plot, -1, maxSize - size, uuid, (args.length != 2) || !args[1].equalsIgnoreCase("false"))) {
if ((EconHandler.manager != null) && plotworld.USE_ECONOMY && plotworld.MERGE_PRICE > 0d) {
EconHandler.manager.withdrawMoney(plr, plotworld.MERGE_PRICE);
sendMessage(plr, C.REMOVED_BALANCE, plotworld.MERGE_PRICE + "");
@ -144,7 +149,7 @@ public class Merge extends SubCommand {
MainUtil.sendMessage(plr, C.DIRECTION.s().replaceAll("%dir%", direction(loc.getYaw())));
return false;
}
if (MainUtil.autoMerge(plot, direction, maxSize - size, plot.owner, (args.length != 2) || !args[1].equalsIgnoreCase("false"))) {
if (MainUtil.autoMerge(plot, direction, maxSize - size, uuid, (args.length != 2) || !args[1].equalsIgnoreCase("false"))) {
if ((EconHandler.manager != null) && plotworld.USE_ECONOMY && plotworld.MERGE_PRICE > 0d) {
EconHandler.manager.withdrawMoney(plr, plotworld.MERGE_PRICE);
sendMessage(plr, C.REMOVED_BALANCE, plotworld.MERGE_PRICE + "");
@ -153,7 +158,7 @@ public class Merge extends SubCommand {
return true;
}
Plot adjacent = MainUtil.getPlotAbs(plot.world, MainUtil.getPlotIdRelative(plot.id, direction));
if (adjacent == null || !adjacent.hasOwner() || adjacent.getMerged((direction + 2) % 4)) {
if (adjacent == null || !adjacent.hasOwner() || adjacent.getMerged((direction + 2) % 4) || adjacent.isOwner(uuid)) {
MainUtil.sendMessage(plr, C.NO_AVAILABLE_AUTOMERGE);
return false;
}
@ -163,8 +168,8 @@ public class Merge extends SubCommand {
}
HashSet<UUID> uuids = adjacent.getOwners();
boolean isOnline = false;
for (final UUID uuid : uuids) {
final PlotPlayer accepter = UUIDHandler.getPlayer(uuid);
for (final UUID owner : uuids) {
final PlotPlayer accepter = UUIDHandler.getPlayer(owner);
if (accepter == null) {
continue;
}
@ -174,7 +179,7 @@ public class Merge extends SubCommand {
@Override
public void run() {
MainUtil.sendMessage(accepter, C.MERGE_ACCEPTED);
MainUtil.autoMerge(plot, dir, maxSize - size, uuid, true);
MainUtil.autoMerge(plot, dir, maxSize - size, owner, true);
final PlotPlayer pp = UUIDHandler.getPlayer(plr.getUUID());
if (pp == null) {
sendMessage(accepter, C.MERGE_NOT_VALID);

View File

@ -97,7 +97,7 @@ public class Toggle extends SubCommand {
return true;
}
});
if (PS.get().worldedit != null) {
if (PS.get() != null && PS.get().worldedit != null) {
toggles.put("worldedit", new Command<PlotPlayer>("worldedit", "/plot toggle worldedit", "Toggle worldedit bypass", C.PERMISSION_WORLDEDIT_BYPASS.s()) {
@Override

View File

@ -21,6 +21,7 @@
package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
@ -44,7 +45,7 @@ import com.plotsquared.general.commands.CommandDeclaration;
command = "visit",
permission = "plots.visit",
description = "Visit someones plot",
usage = "/plot visit <player|aliases|world|id> [#]",
usage = "/plot visit <player|alias|world|id> [#]",
aliases = { "v" },
requiredType = RequiredType.NONE,
category = CommandCategory.TELEPORT)
@ -94,8 +95,7 @@ public class Visit extends SubCommand {
} else {
final Plot plot = MainUtil.getPlotFromString(player, args[0], true);
if (plot != null) {
unsorted = new HashSet<>();
unsorted.add(plot);
unsorted = new HashSet<>(Arrays.asList(plot.getBasePlot(false)));
}
}
break;