mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-07-18 13:24:43 +02:00
Database correction / Code cleanup, Fixes #490
This commit is contained in:
@ -211,7 +211,7 @@ public class Auto extends SubCommand {
|
||||
MainUtil.lastPlot.put(worldname, start);
|
||||
if (lastPlot) {
|
||||
}
|
||||
if ((PS.get().getPlots(worldname).get(start) != null) && (PS.get().getPlots(worldname).get(start).owner != null)) {
|
||||
if ((PS.get().getPlot(worldname, start) != null) && (PS.get().getPlot(worldname, start).owner != null)) {
|
||||
continue;
|
||||
} else {
|
||||
lastPlot = false;
|
||||
|
@ -66,7 +66,7 @@ public class Claim extends SubCommand {
|
||||
}
|
||||
final String world = plot.world;
|
||||
final PlotWorld plotworld = PS.get().getPlotWorld(world);
|
||||
final Plot plot2 = PS.get().getPlots(world).get(plot.id);
|
||||
final Plot plot2 = PS.get().getPlot(world, plot.id);
|
||||
if (plotworld.SCHEMATIC_ON_CLAIM) {
|
||||
Schematic sch;
|
||||
if (schematic.equals("")) {
|
||||
|
@ -144,7 +144,7 @@ public class Cluster extends SubCommand {
|
||||
}
|
||||
ClusterManager.clusters.get(world).add(cluster);
|
||||
// Add any existing plots to the current cluster
|
||||
for (final Plot plot : PS.get().getPlots(plr.getLocation().getWorld()).values()) {
|
||||
for (final Plot plot : PS.get().getPlotsInWorld(plr.getLocation().getWorld())) {
|
||||
final PlotCluster current = ClusterManager.getCluster(plot);
|
||||
if (cluster.equals(current) && !cluster.isAdded(plot.owner)) {
|
||||
cluster.invited.add(plot.owner);
|
||||
@ -221,7 +221,7 @@ public class Cluster extends SubCommand {
|
||||
final PlotWorld plotworld = PS.get().getPlotWorld(plr.getLocation().getWorld());
|
||||
if (plotworld.TYPE == 2) {
|
||||
final ArrayList<Plot> toRemove = new ArrayList<>();
|
||||
for (final Plot plot : PS.get().getPlots(plr.getLocation().getWorld()).values()) {
|
||||
for (final Plot plot : PS.get().getPlotsInWorld(plr.getLocation().getWorld())) {
|
||||
final PlotCluster other = ClusterManager.getCluster(plot);
|
||||
if (cluster.equals(other)) {
|
||||
toRemove.add(plot);
|
||||
|
@ -76,7 +76,7 @@ public class Condense extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
final int radius = Integer.parseInt(args[2]);
|
||||
final Collection<Plot> plots = PS.get().getPlots(worldname).values();
|
||||
final Collection<Plot> plots = PS.get().getPlotsInWorld(worldname);
|
||||
final int size = plots.size();
|
||||
final int minimum_radius = (int) Math.ceil((Math.sqrt(size) / 2) + 1);
|
||||
if (radius < minimum_radius) {
|
||||
@ -165,7 +165,7 @@ public class Condense extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
final int radius = Integer.parseInt(args[2]);
|
||||
final Collection<Plot> plots = PS.get().getPlots(worldname).values();
|
||||
final Collection<Plot> plots = PS.get().getPlotsInWorld(worldname);
|
||||
final int size = plots.size();
|
||||
final int minimum_radius = (int) Math.ceil((Math.sqrt(size) / 2) + 1);
|
||||
if (radius < minimum_radius) {
|
||||
|
@ -93,8 +93,7 @@ public class DebugClaimTest extends SubCommand {
|
||||
final ArrayList<Plot> plots = new ArrayList<>();
|
||||
for (final PlotId id : MainUtil.getPlotSelectionIds(min, max)) {
|
||||
final Plot plot = MainUtil.getPlot(world, id);
|
||||
final boolean contains = PS.get().getPlots(world).containsKey(plot.id);
|
||||
if (contains) {
|
||||
if (PS.get().getPlot(world, plot.id) != null) {
|
||||
MainUtil.sendMessage(null, " - &cDB Already contains: " + plot.id);
|
||||
continue;
|
||||
}
|
||||
|
@ -72,6 +72,8 @@ import com.intellectualcrafters.plot.util.StringMan;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.plotsquared.bukkit.util.BukkitHybridUtils;
|
||||
import com.plotsquared.general.commands.Command;
|
||||
import com.plotsquared.general.commands.CommandCaller;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
@CommandDeclaration(
|
||||
@ -86,6 +88,19 @@ public class DebugExec extends SubCommand {
|
||||
private ScriptEngine engine;
|
||||
private Bindings scope;
|
||||
|
||||
public DebugExec() {
|
||||
File file = new File(PS.get().IMP.getDirectory(), "scripts" + File.separator + "start.js");
|
||||
if (file.exists()) {
|
||||
init();
|
||||
TaskManager.runTaskLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
onCommand(ConsolePlayer.getConsole(), new String[] {"runasync", "start.js"});
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void init() {
|
||||
if (engine != null) {
|
||||
return;
|
||||
@ -350,6 +365,33 @@ public class DebugExec extends SubCommand {
|
||||
MainUtil.sendMessage(player, "Possible sub commands: /plot debugexec <" + StringMan.join(allowed_params, "|") + ">");
|
||||
return false;
|
||||
}
|
||||
case "addcmd": {
|
||||
try {
|
||||
final String cmd = StringMan.join(Files.readLines(new File(new File(PS.get().IMP.getDirectory() + File.separator + "scripts"), args[1]), StandardCharsets.UTF_8), System.getProperty("line.separator"));
|
||||
Command<PlotPlayer> subcommand = new Command<PlotPlayer>(args[1].split("\\.")[0]) {
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer plr, String[] args) {
|
||||
try {
|
||||
scope.put("PlotPlayer", plr);
|
||||
scope.put("args", args);
|
||||
engine.eval(cmd, scope);
|
||||
return true;
|
||||
} catch (ScriptException e) {
|
||||
e.printStackTrace();
|
||||
MainUtil.sendMessage(player, C.COMMAND_WENT_WRONG);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
MainCommand.getInstance().addCommand(subcommand);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot debugexec addcmd <file>");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
case "runasync": {
|
||||
async = true;
|
||||
}
|
||||
@ -379,7 +421,7 @@ public class DebugExec extends SubCommand {
|
||||
}
|
||||
init();
|
||||
scope.put("PlotPlayer", player);
|
||||
System.out.print("> " + script);
|
||||
PS.debug("> " + script);
|
||||
try {
|
||||
if (async) {
|
||||
final String toExec = script;
|
||||
|
@ -60,7 +60,7 @@ public class DebugFixFlags extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
MainUtil.sendMessage(plr, "&8--- &6Starting task &8 ---");
|
||||
for (final Plot plot : PS.get().getPlots(world).values()) {
|
||||
for (final Plot plot : PS.get().getPlotsInWorld(world)) {
|
||||
final HashMap<String, Flag> flags = plot.getSettings().flags;
|
||||
Iterator<Entry<String, Flag>> i = flags.entrySet().iterator();
|
||||
boolean changed = false;
|
||||
|
@ -156,7 +156,7 @@ public class Merge extends SubCommand {
|
||||
HashSet<PlotId> multiPlots = new HashSet<>();
|
||||
final UUID u1 = plot.owner;
|
||||
for (final PlotId myid : plots) {
|
||||
final Plot myplot = PS.get().getPlots(world).get(myid);
|
||||
final Plot myplot = PS.get().getPlot(world, myid);
|
||||
if (myplot == null || myplot.owner == null) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERM_MERGE.s().replaceAll("%plot%", myid.toString()));
|
||||
return false;
|
||||
|
@ -46,6 +46,9 @@ public class MusicSubcommand extends SubCommand {
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer player, final String[] args) {
|
||||
|
||||
// TODO FIX PLOT MUSIC AS NPE FROM PLAYER.PLAYEFFECT
|
||||
System.out.print("TODO MUSIC");
|
||||
|
||||
final Location loc = player.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
|
@ -100,7 +100,7 @@ public class Purge extends SubCommand {
|
||||
final PlotId id = getId(arg);
|
||||
if (id != null) {
|
||||
final HashSet<Integer> ids = new HashSet<Integer>();
|
||||
final int DBid = DBFunc.getId(worldname, id);
|
||||
final int DBid = DBFunc.getId(MainUtil.getPlot(worldname, id));
|
||||
if (DBid != Integer.MAX_VALUE) {
|
||||
ids.add(DBid);
|
||||
}
|
||||
@ -117,7 +117,7 @@ public class Purge extends SubCommand {
|
||||
return finishPurge(length);
|
||||
}
|
||||
if (arg.equals("unknown")) {
|
||||
final Collection<Plot> plots = PS.get().getPlots(worldname).values();
|
||||
final Collection<Plot> plots = PS.get().getPlotsInWorld(worldname);
|
||||
final Set<PlotId> ids = new HashSet<>();
|
||||
for (final Plot plot : plots) {
|
||||
if (plot.owner != null) {
|
||||
@ -135,7 +135,7 @@ public class Purge extends SubCommand {
|
||||
return finishPurge(length);
|
||||
}
|
||||
if (arg.equals("unowned")) {
|
||||
final Collection<Plot> plots = PS.get().getPlots(worldname).values();
|
||||
final Collection<Plot> plots = PS.get().getPlotsInWorld(worldname);
|
||||
final Set<PlotId> ids = new HashSet<>();
|
||||
for (final Plot plot : plots) {
|
||||
if (plot.owner == null) {
|
||||
|
@ -181,12 +181,11 @@ public class SchematicCmd extends SubCommand {
|
||||
MainUtil.sendMessage(null, "&cNeed world arg. Use &7/plots sch exportall <world>");
|
||||
return false;
|
||||
}
|
||||
final Map<PlotId, Plot> plotmap = PS.get().getPlots(args[1]);
|
||||
if ((plotmap == null) || (plotmap.size() == 0)) {
|
||||
Collection<Plot> plots = PS.get().getPlotsInWorld(args[1]);
|
||||
if ((plots.size() == 0)) {
|
||||
MainUtil.sendMessage(plr, "&cInvalid world. Use &7/plots sch exportall <world>");
|
||||
return false;
|
||||
}
|
||||
Collection<Plot> plots = plotmap.values();
|
||||
boolean result = SchematicHandler.manager.exportAll(plots, null, null, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -199,7 +198,7 @@ public class SchematicCmd extends SubCommand {
|
||||
}
|
||||
else {
|
||||
MainUtil.sendMessage(plr, "&3PlotSquared&8->&3Schemaitc&8: &7Mass export has started. This may take a while.");
|
||||
MainUtil.sendMessage(plr, "&3PlotSquared&8->&3Schemaitc&8: &7Found &c" + plotmap.size() + "&7 plots...");
|
||||
MainUtil.sendMessage(plr, "&3PlotSquared&8->&3Schemaitc&8: &7Found &c" + plots.size() + "&7 plots...");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -210,7 +210,7 @@ public class Set extends SubCommand {
|
||||
MainUtil.sendMessage(plr, C.ALIAS_TOO_LONG);
|
||||
return false;
|
||||
}
|
||||
for (final Plot p : PS.get().getPlots(plr.getLocation().getWorld()).values()) {
|
||||
for (final Plot p : PS.get().getPlotsInWorld(plr.getLocation().getWorld())) {
|
||||
if (p.getSettings().getAlias().equalsIgnoreCase(alias)) {
|
||||
MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN);
|
||||
return false;
|
||||
|
@ -107,7 +107,7 @@ public class SetOwner extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
for (final PlotId id : plots) {
|
||||
Plot current = PS.get().getPlots(world).get(id);
|
||||
Plot current = PS.get().getPlot(world, id);
|
||||
if (current == null) {
|
||||
current = MainUtil.getPlot(world, id);
|
||||
current.owner = uuid;
|
||||
|
@ -98,7 +98,7 @@ public class TP extends SubCommand {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
for (final Plot p : PS.get().getPlots(world).values()) {
|
||||
for (final Plot p : PS.get().getPlotsInWorld(world)) {
|
||||
if ((p.getSettings().getAlias().length() > 0) && p.getSettings().getAlias().equalsIgnoreCase(a)) {
|
||||
return p;
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ public class Target extends SubCommand {
|
||||
if (StringMan.isEqualIgnoreCaseToAny(args[0], "near", "nearest")) {
|
||||
Plot closest = null;
|
||||
int distance = Integer.MAX_VALUE;
|
||||
for (Plot plot : PS.get().getPlots(ploc.getWorld()).values()) {
|
||||
for (Plot plot : PS.get().getPlotsInWorld(ploc.getWorld())) {
|
||||
double current = plot.getBottom().getEuclideanDistanceSquared(ploc);
|
||||
if (current < distance) {
|
||||
distance = (int) current;
|
||||
|
@ -116,7 +116,7 @@ public class Trim extends SubCommand {
|
||||
System.currentTimeMillis();
|
||||
sendMessage("Collecting region data...");
|
||||
final ArrayList<Plot> plots = new ArrayList<>();
|
||||
plots.addAll(PS.get().getPlots(world).values());
|
||||
plots.addAll(PS.get().getPlotsInWorld(world));
|
||||
final HashSet<ChunkLoc> chunks = new HashSet<>(ChunkManager.manager.getChunkChunks(world));
|
||||
sendMessage(" - MCA #: " + chunks.size());
|
||||
sendMessage(" - CHUNKS: " + (chunks.size() * 1024) + " (max)");
|
||||
|
@ -71,7 +71,7 @@ public class Visit extends SubCommand {
|
||||
plots = PS.get().sortPlots(PS.get().getPlots(user), SortType.CREATION_DATE, null);
|
||||
} else if (PS.get().isPlotWorld(args[0])) {
|
||||
// do plots by world
|
||||
plots = PS.get().sortPlots(PS.get().getPlots(args[0]).values(), SortType.CREATION_DATE, null);
|
||||
plots = PS.get().sortPlots(PS.get().getPlotsInWorld(args[0]), SortType.CREATION_DATE, null);
|
||||
}
|
||||
else {
|
||||
Plot plot = MainUtil.getPlotFromString(plr, args[0], true);
|
||||
|
@ -163,7 +163,7 @@ public class list extends SubCommand {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.world." + world);
|
||||
return false;
|
||||
}
|
||||
plots = new ArrayList<>(PS.get().getPlots(world).values());
|
||||
plots = new ArrayList<>(PS.get().getPlotsInWorld(world));
|
||||
break;
|
||||
}
|
||||
case "all": {
|
||||
@ -268,7 +268,7 @@ public class list extends SubCommand {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.world." + args[0]);
|
||||
return false;
|
||||
}
|
||||
plots = new ArrayList<>(PS.get().getPlots(args[0]).values());
|
||||
plots = new ArrayList<>(PS.get().getPlotsInWorld(args[0]));
|
||||
break;
|
||||
}
|
||||
UUID uuid = UUIDHandler.getUUID(args[0], null);
|
||||
|
Reference in New Issue
Block a user