mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 21:26:45 +01:00
More options for plot listing
This commit is contained in:
parent
eb20d82545
commit
cca903bf8d
@ -10,6 +10,9 @@ import java.sql.ResultSet;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
@ -139,12 +142,36 @@ public class PlotSquared {
|
|||||||
return new LinkedHashSet<>(newplots);
|
return new LinkedHashSet<>(newplots);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LinkedHashSet<Plot> getPlotsSorted() {
|
public static ArrayList<Plot> sortPlots(Collection<Plot> plots) {
|
||||||
final ArrayList<Plot> newplots = new ArrayList<>();
|
ArrayList<Plot> newPlots = new ArrayList<>();
|
||||||
for (final HashMap<PlotId, Plot> world : plots.values()) {
|
newPlots.addAll(plots);
|
||||||
newplots.addAll(world.values());
|
Collections.sort(newPlots, new Comparator<Plot>() {
|
||||||
|
@Override
|
||||||
|
public int compare(Plot p1, Plot p2) {
|
||||||
|
return p1.hashCode() + p1.world.hashCode() - p2.hashCode() + p2.world.hashCode();
|
||||||
}
|
}
|
||||||
return new LinkedHashSet<>(newplots);
|
});
|
||||||
|
return newPlots;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ArrayList<Plot> sortPlots(Collection<Plot> plots, final String priorityWorld) {
|
||||||
|
ArrayList<Plot> newPlots = new ArrayList<>();
|
||||||
|
newPlots.addAll(plots);
|
||||||
|
Collections.sort(newPlots, new Comparator<Plot>() {
|
||||||
|
@Override
|
||||||
|
public int compare(Plot p1, Plot p2) {
|
||||||
|
int w1 = 0;
|
||||||
|
int w2 = 0;
|
||||||
|
if (!p1.world.equals(priorityWorld)) {
|
||||||
|
w1 = p1.hashCode();
|
||||||
|
}
|
||||||
|
if (!p2.world.equals(priorityWorld)) {
|
||||||
|
w2 = p2.hashCode();
|
||||||
|
}
|
||||||
|
return p1.hashCode() + w1 - p2.hashCode() - w2;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return newPlots;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set<Plot> getPlots(final String world, final String player) {
|
public static Set<Plot> getPlots(final String world, final String player) {
|
||||||
@ -193,7 +220,10 @@ public class PlotSquared {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Set<Plot> getPlots(final PlotPlayer player) {
|
public static Set<Plot> getPlots(final PlotPlayer player) {
|
||||||
final UUID uuid = player.getUUID();
|
return getPlots(player.getUUID());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Set<Plot> getPlots(final UUID uuid) {
|
||||||
final ArrayList<Plot> myplots = new ArrayList<>();
|
final ArrayList<Plot> myplots = new ArrayList<>();
|
||||||
for (final String world : plots.keySet()) {
|
for (final String world : plots.keySet()) {
|
||||||
if (isPlotWorld(world)) {
|
if (isPlotWorld(world)) {
|
||||||
|
@ -20,22 +20,12 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotSquared;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
|
||||||
import com.intellectualcrafters.plot.flag.Flag;
|
|
||||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
|
||||||
import com.intellectualcrafters.plot.object.CmdInstance;
|
import com.intellectualcrafters.plot.object.CmdInstance;
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
|
||||||
import com.intellectualcrafters.plot.util.CmdConfirm;
|
import com.intellectualcrafters.plot.util.CmdConfirm;
|
||||||
import com.intellectualcrafters.plot.util.EconHandler;
|
|
||||||
import com.intellectualcrafters.plot.util.MainUtil;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Citymonstret
|
* @author Citymonstret
|
||||||
@ -47,7 +37,6 @@ public class Confirm extends SubCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
String name = plr.getName();
|
|
||||||
CmdInstance command = CmdConfirm.getPending(plr);
|
CmdInstance command = CmdConfirm.getPending(plr);
|
||||||
if (command == null) {
|
if (command == null) {
|
||||||
MainUtil.sendMessage(plr, C.FAILED_CONFIRM);
|
MainUtil.sendMessage(plr, C.FAILED_CONFIRM);
|
||||||
|
@ -20,7 +20,11 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotSquared;
|
import com.intellectualcrafters.plot.PlotSquared;
|
||||||
@ -53,71 +57,29 @@ public class list extends SubCommand {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void noArgs(PlotPlayer plr) {
|
||||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
|
||||||
if (args.length < 1) {
|
|
||||||
final StringBuilder builder = new StringBuilder();
|
final StringBuilder builder = new StringBuilder();
|
||||||
builder.append(C.SUBCOMMAND_SET_OPTIONS_HEADER.s());
|
builder.append(C.SUBCOMMAND_SET_OPTIONS_HEADER.s());
|
||||||
if (plr != null) {
|
if (plr != null) {
|
||||||
builder.append(getArgumentList(new String[] { "mine", "shared", "world", "all", "forsale" }));
|
if (PlotSquared.economy != null) {
|
||||||
|
builder.append(getArgumentList(new String[] { "mine", "shared", "world", "all", "unowned", "unknown", "forsale", "<player>", "<world>"}));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
builder.append(getArgumentList(new String[] { "mine", "shared", "world", "all", "unowned", "unknown", "<player>", "<world>"}));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
builder.append(getArgumentList(new String[] { "all" }));
|
builder.append(getArgumentList(new String[] { "world", "all", "unowned", "unknown", "<player>", "<world>"}));
|
||||||
}
|
}
|
||||||
MainUtil.sendMessage(plr, builder.toString());
|
MainUtil.sendMessage(plr, builder.toString());
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
if (args[0].equalsIgnoreCase("forsale") && (plr != null)) {
|
|
||||||
if (PlotSquared.economy == null) {
|
@Override
|
||||||
return sendMessage(plr, C.ECON_DISABLED);
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||||
|
if (args.length < 1) {
|
||||||
|
noArgs(plr);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
final StringBuilder string = new StringBuilder();
|
|
||||||
string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "buyable")).append("\n");
|
|
||||||
int idx = 0;
|
|
||||||
for (final Plot p : PlotSquared.getPlots(plr.getLocation().getWorld()).values()) {
|
|
||||||
final Flag price = FlagManager.getPlotFlag(p, "price");
|
|
||||||
if (price != null) {
|
|
||||||
string.append(C.PLOT_LIST_ITEM_ORDERED.s().replaceAll("%in", idx + 1 + "").replaceAll("%id", p.id.toString()).replaceAll("%world", price.getValueString()).replaceAll("%owner", getName(p.owner))).append("\n");
|
|
||||||
idx++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (idx == 0) {
|
|
||||||
MainUtil.sendMessage(plr, C.NO_PLOTS);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
string.append(C.PLOT_LIST_FOOTER.s().replaceAll("%word%", "Includes").replaceAll("%num%", idx + "").replaceAll("%plot%", idx == 1 ? "plot" : "plots"));
|
|
||||||
MainUtil.sendMessage(plr, string.toString());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (args[0].equalsIgnoreCase("mine") && (plr != null)) {
|
|
||||||
final StringBuilder string = new StringBuilder();
|
|
||||||
string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "your")).append("\n");
|
|
||||||
int idx = 0;
|
|
||||||
for (final Plot p : PlotSquared.getPlots(plr)) {
|
|
||||||
string.append(C.PLOT_LIST_ITEM_ORDERED.s().replaceAll("%in", idx + 1 + "").replaceAll("%id", p.id.toString()).replaceAll("%world", p.world).replaceAll("%owner", getName(p.owner))).append("\n");
|
|
||||||
idx++;
|
|
||||||
}
|
|
||||||
if (idx == 0) {
|
|
||||||
MainUtil.sendMessage(plr, C.NO_PLOTS);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
string.append(C.PLOT_LIST_FOOTER.s().replaceAll("%word%", "You have").replaceAll("%num%", idx + "").replaceAll("%plot%", idx == 1 ? "plot" : "plots"));
|
|
||||||
MainUtil.sendMessage(plr, string.toString());
|
|
||||||
return true;
|
|
||||||
} else if (args[0].equalsIgnoreCase("shared") && (plr != null)) {
|
|
||||||
final StringBuilder string = new StringBuilder();
|
|
||||||
string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "all")).append("\n");
|
|
||||||
for (final Plot p : PlotSquared.getPlotsSorted()) {
|
|
||||||
if (p.helpers.contains(UUIDHandler.getUUID(plr))) {
|
|
||||||
string.append(C.PLOT_LIST_ITEM.s().replaceAll("%id", p.id.toString()).replaceAll("%world", p.world).replaceAll("%owner", getName(p.owner))).append("\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
string.append(C.PLOT_LIST_FOOTER.s().replaceAll("%word%", "There are").replaceAll("%num%", PlotSquared.getPlotsSorted().size() + "").replaceAll("%plot%", PlotSquared.getPlotsSorted().size() == 1 ? "plot" : "plots"));
|
|
||||||
MainUtil.sendMessage(plr, string.toString());
|
|
||||||
return true;
|
|
||||||
} else if (args[0].equalsIgnoreCase("all")) {
|
|
||||||
// Current page
|
|
||||||
int page = 0;
|
int page = 0;
|
||||||
// is a page specified? else use 0
|
|
||||||
if (args.length > 1) {
|
if (args.length > 1) {
|
||||||
try {
|
try {
|
||||||
page = Integer.parseInt(args[1]);
|
page = Integer.parseInt(args[1]);
|
||||||
@ -129,51 +91,146 @@ public class list extends SubCommand {
|
|||||||
page = 0;
|
page = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Collection<Plot> plots = null;
|
||||||
|
|
||||||
|
String world;
|
||||||
|
if (plr != null) {
|
||||||
|
world = plr.getLocation().getWorld();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Set<String> worlds = PlotSquared.getPlotWorlds();
|
||||||
|
if (worlds.size() == 0) {
|
||||||
|
world = "world";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
world = worlds.iterator().next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String arg = args[0].toLowerCase();
|
||||||
|
switch (arg) {
|
||||||
|
case "mine": {
|
||||||
|
if (plr == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
plots = PlotSquared.getPlots(plr);
|
||||||
|
}
|
||||||
|
case "shared": {
|
||||||
|
if (plr == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
for (Plot plot : PlotSquared.getPlots()) {
|
||||||
|
if (plot.helpers.contains(plr.getUUID()) || plot.trusted.contains(plr.getUUID())) {
|
||||||
|
plots.add(plot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case "world": {
|
||||||
|
plots = PlotSquared.getPlots(world).values();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "all": {
|
||||||
|
plots = PlotSquared.getPlots();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "forsale": {
|
||||||
|
if (PlotSquared.economy == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
plots = new HashSet<>();
|
||||||
|
for (Plot plot : PlotSquared.getPlots()) {
|
||||||
|
final Flag price = FlagManager.getPlotFlag(plot, "price");
|
||||||
|
if (price != null) {
|
||||||
|
plots.add(plot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "unowned": {
|
||||||
|
plots = new HashSet<>();
|
||||||
|
for (Plot plot : PlotSquared.getPlots()) {
|
||||||
|
if (plot.owner == null) {
|
||||||
|
plots.add(plot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "unknown": {
|
||||||
|
plots = new HashSet<>();
|
||||||
|
for (Plot plot : PlotSquared.getPlots()) {
|
||||||
|
if (plot.owner == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (UUIDHandler.getName(plot.owner) == null) {
|
||||||
|
plots.add(plot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
if (PlotSquared.isPlotWorld(args[0])) {
|
||||||
|
plots = PlotSquared.getPlots(args[0]).values();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
UUID uuid = UUIDHandler.getUUID(args[0]);
|
||||||
|
if (uuid != null) {
|
||||||
|
plots = PlotSquared.getPlots(uuid);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (plots == null) {
|
||||||
|
sendMessage(plr, C.DID_YOU_MEAN, new StringComparison(args[0], new String[] { "mine", "shared", "world", "all" }).getBestMatch());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (plots.size() == 0) {
|
||||||
|
MainUtil.sendMessage(plr, C.NO_PLOTS);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
displayPlots(plr, plots, page);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void displayPlots(PlotPlayer player, Collection<Plot> oldPlots, int page) {
|
||||||
|
ArrayList<Plot> plots = PlotSquared.sortPlots(oldPlots);
|
||||||
|
if (page < 0) {
|
||||||
|
page = 0;
|
||||||
|
}
|
||||||
// Get the total pages
|
// Get the total pages
|
||||||
// int totalPages = ((int) Math.ceil(12 *
|
// int totalPages = ((int) Math.ceil(12 *
|
||||||
// (PlotSquared.getPlotsSorted().size()) / 100));
|
// (PlotSquared.getPlotsSorted().size()) / 100));
|
||||||
final int totalPages = (int) Math.ceil(PlotSquared.getPlotsSorted().size() / 12);
|
final int totalPages = (int) Math.ceil(plots.size() / 12);
|
||||||
if (page > totalPages) {
|
if (page > totalPages) {
|
||||||
page = totalPages;
|
page = totalPages;
|
||||||
}
|
}
|
||||||
// Only display 12!
|
// Only display 12!
|
||||||
int max = (page * 12) + 12;
|
int max = (page * 12) + 12;
|
||||||
if (max > PlotSquared.getPlotsSorted().size()) {
|
if (max > plots.size()) {
|
||||||
max = PlotSquared.getPlotsSorted().size();
|
max = plots.size();
|
||||||
}
|
}
|
||||||
final StringBuilder string = new StringBuilder();
|
final StringBuilder string = new StringBuilder();
|
||||||
string.append(C.PLOT_LIST_HEADER_PAGED.s().replaceAll("%cur", page + 1 + "").replaceAll("%max", totalPages + 1 + "").replaceAll("%word%", "all")).append("\n");
|
string.append(C.PLOT_LIST_HEADER_PAGED.s().replaceAll("%cur", page + 1 + "").replaceAll("%max", totalPages + 1 + "").replaceAll("%word%", "all")).append("\n");
|
||||||
Plot p;
|
Plot p;
|
||||||
// This might work xD
|
// This might work xD
|
||||||
for (int x = (page * 12); x < max; x++) {
|
for (int x = (page * 12); x < max; x++) {
|
||||||
p = (Plot) PlotSquared.getPlotsSorted().toArray()[x];
|
p = (Plot) plots.toArray()[x];
|
||||||
string.append(C.PLOT_LIST_ITEM_ORDERED.s().replaceAll("%in", x + 1 + "").replaceAll("%id", p.id.toString()).replaceAll("%world", p.world).replaceAll("%owner", getName(p.owner))).append("\n");
|
string.append(C.PLOT_LIST_ITEM_ORDERED.s().replaceAll("%in", x + 1 + "").replaceAll("%id", p.id.toString()).replaceAll("%world", p.world).replaceAll("%owner", getName(p.owner))).append("\n");
|
||||||
}
|
}
|
||||||
string.append(C.PLOT_LIST_FOOTER.s().replaceAll("%word%", "There is").replaceAll("%num%", PlotSquared.getPlotsSorted().size() + "").replaceAll("%plot%", PlotSquared.getPlotsSorted().size() == 1 ? "plot" : "plots"));
|
string.append(C.PLOT_LIST_FOOTER.s().replaceAll("%word%", "There is").replaceAll("%num%", plots.size() + "").replaceAll("%plot%", plots.size() == 1 ? "plot" : "plots"));
|
||||||
MainUtil.sendMessage(plr, string.toString());
|
MainUtil.sendMessage(player, string.toString());
|
||||||
return true;
|
|
||||||
} else if (args[0].equalsIgnoreCase("world") && (plr != null)) {
|
|
||||||
final StringBuilder string = new StringBuilder();
|
|
||||||
string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "all")).append("\n");
|
|
||||||
final HashMap<PlotId, Plot> plots = PlotSquared.getPlots(plr.getLocation().getWorld());
|
|
||||||
for (final Plot p : plots.values()) {
|
|
||||||
string.append(C.PLOT_LIST_ITEM.s().replaceAll("%id", p.id.toString()).replaceAll("%world", p.world).replaceAll("%owner", getName(p.owner))).append("\n");
|
|
||||||
}
|
|
||||||
string.append(C.PLOT_LIST_FOOTER.s().replaceAll("%word%", "There is").replaceAll("%num%", plots.values().size() + "").replaceAll("%plot%", plots.values().size() == 1 ? "plot" : "plots"));
|
|
||||||
MainUtil.sendMessage(plr, string.toString());
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
// execute(plr);
|
|
||||||
sendMessage(plr, C.DID_YOU_MEAN, new StringComparison(args[0], new String[] { "mine", "shared", "world", "all" }).getBestMatch());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getArgumentList(final String[] strings) {
|
private String getArgumentList(final String[] strings) {
|
||||||
final StringBuilder builder = new StringBuilder();
|
final StringBuilder builder = new StringBuilder();
|
||||||
|
String prefix = "";
|
||||||
for (final String s : strings) {
|
for (final String s : strings) {
|
||||||
builder.append(MainUtil.colorise('&', s));
|
builder.append(prefix + MainUtil.colorise('&', s));
|
||||||
|
prefix = " | ";
|
||||||
}
|
}
|
||||||
return builder.toString().substring(1, builder.toString().length() - 1);
|
return builder.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -177,6 +177,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
|
|||||||
passed = false;
|
passed = false;
|
||||||
}
|
}
|
||||||
if (passed) {
|
if (passed) {
|
||||||
|
player.teleport(event.getTo());
|
||||||
final PlotPlayer pp = BukkitUtil.getPlayer(player);
|
final PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||||
MainUtil.sendMessage(pp, C.BORDER);
|
MainUtil.sendMessage(pp, C.BORDER);
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user