Better list!

Even added argument suggestion (so proud of that class xD<3)
Fixes #8
This commit is contained in:
Sauilitired 2014-11-02 21:14:47 +01:00
parent c883f2f7d9
commit c5bd4c4935
7 changed files with 86 additions and 51 deletions

View File

@ -254,8 +254,10 @@ public enum C {
/* /*
* List * List
*/ */
PLOT_LIST_HEADER_PAGED("&c(Page &6%cur&c/&6%max&c) &6List of %word% plots"),
PLOT_LIST_HEADER("&6List of %word% plots"), PLOT_LIST_HEADER("&6List of %word% plots"),
PLOT_LIST_ITEM("&c>> &6%id% &c- &6%owner%"), PLOT_LIST_ITEM("&c>> &6%id&c:&6%world &c- &6%owner"),
PLOT_LIST_ITEM_ORDERED("&c[&6%in&c] >> &6%id&c:&6%world &c- &6%owner"),
PLOT_LIST_FOOTER("&c>> &6%word% a total of &c%num% &6claimed %plot%."), PLOT_LIST_FOOTER("&c>> &6%word% a total of &c%num% &6claimed %plot%."),
/* /*
* Left * Left

View File

@ -222,7 +222,7 @@ public class PlotMain extends JavaPlugin {
* List of all plots * List of all plots
* DO NOT USE EXCEPT FOR DATABASE PURPOSES * DO NOT USE EXCEPT FOR DATABASE PURPOSES
*/ */
private static HashMap<String, HashMap<PlotId, Plot>> plots; private static LinkedHashMap<String, HashMap<PlotId, Plot>> plots;
/** /**
* All loaded plot worlds * All loaded plot worlds
*/ */
@ -234,12 +234,20 @@ public class PlotMain extends JavaPlugin {
* *
* @return HashMap containing the plot ID and the plot object. * @return HashMap containing the plot ID and the plot object.
*/ */
public static Set<Plot> getPlots() { public static Set<Plot> getPlots() {
ArrayList<Plot> myplots = new ArrayList<>();
for (HashMap<PlotId, Plot> world : plots.values()) {
myplots.addAll(world.values());
}
return new HashSet<>(myplots);
}
public static LinkedHashSet<Plot> getPlotsSorted() {
ArrayList<Plot> myplots = new ArrayList<>(); ArrayList<Plot> myplots = new ArrayList<>();
for (HashMap<PlotId, Plot> world : plots.values()) { for (HashMap<PlotId, Plot> world : plots.values()) {
myplots.addAll(world.values()); myplots.addAll(world.values());
} }
return new HashSet<>(myplots); return new LinkedHashSet<>(myplots);
} }
/** /**
@ -1515,8 +1523,12 @@ public class PlotMain extends JavaPlugin {
return plots; return plots;
} }
public static void setAllPlotsRaw(HashMap<String, HashMap<PlotId, Plot>> plots) { public static void setAllPlotsRaw(LinkedHashMap<String, HashMap<PlotId, Plot>> plots) {
PlotMain.plots = plots; PlotMain.plots = plots;
} }
public static void setAllPlotsRaw(HashMap<String, HashMap<PlotId, Plot>> plots) {
PlotMain.plots = new LinkedHashMap<String, HashMap<PlotId, Plot>>();
PlotMain.plots.putAll(plots);
}
} }

View File

@ -8,18 +8,12 @@
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.HashMap; import com.intellectualcrafters.plot.*;
import java.util.UUID;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C; import java.util.HashMap;
import com.intellectualcrafters.plot.PlayerFunctions; import java.util.UUID;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotId;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.UUIDHandler;
/** /**
* @author Citymonstret * @author Citymonstret
@ -49,8 +43,7 @@ public class list extends SubCommand {
string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "your") + "\n"); string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "your") + "\n");
int idx = 0; int idx = 0;
for (Plot p : PlotMain.getPlots(plr)) { for (Plot p : PlotMain.getPlots(plr)) {
string.append(C.PLOT_LIST_ITEM.s().replaceAll("%id%", p.id.x + ";" + p.id.y + ";" + p.world).replaceAll("%owner%", getName(p.owner)) 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");
+ "\n");
idx++; idx++;
} }
if (idx == 0) { if (idx == 0) {
@ -66,27 +59,55 @@ public class list extends SubCommand {
if (args[0].equalsIgnoreCase("shared") && plr!=null) { if (args[0].equalsIgnoreCase("shared") && plr!=null) {
StringBuilder string = new StringBuilder(); StringBuilder string = new StringBuilder();
string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "all") + "\n"); string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "all") + "\n");
for (Plot p : PlotMain.getPlots()) { for (Plot p : PlotMain.getPlotsSorted()) {
if (p.helpers.contains(plr.getUniqueId())) { if (p.helpers.contains(plr.getUniqueId())) {
string.append(C.PLOT_LIST_ITEM.s().replaceAll("%id%", p.id.x + ";" + p.id.y + ";" + p.world).replaceAll("%owner%", getName(p.owner)) string.append(C.PLOT_LIST_ITEM.s().replaceAll("%id", p.id.toString()).replaceAll("%world", p.world).replaceAll("%owner", getName(p.owner))).append("\n");
+ "\n");
} }
} }
string.append(C.PLOT_LIST_FOOTER.s().replaceAll("%word%", "There are").replaceAll("%num%", PlotMain.getPlots().size() string.append(C.PLOT_LIST_FOOTER.s().replaceAll("%word%", "There are").replaceAll("%num%", PlotMain.getPlotsSorted().size()
+ "").replaceAll("%plot%", PlotMain.getPlots().size() == 1 ? "plot" : "plots")); + "").replaceAll("%plot%", PlotMain.getPlotsSorted().size() == 1 ? "plot" : "plots"));
PlayerFunctions.sendMessage(plr, string.toString()); PlayerFunctions.sendMessage(plr, string.toString());
return true; return true;
} }
else else
if (args[0].equalsIgnoreCase("all")) { if (args[0].equalsIgnoreCase("all")) {
StringBuilder string = new StringBuilder(); // Current page
string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "all") + "\n"); int page = 0;
for (Plot p : PlotMain.getPlots()) {
string.append(C.PLOT_LIST_ITEM.s().replaceAll("%id%", p.id.x + ";" + p.id.y + ";" + p.world).replaceAll("%owner%", getName(p.owner)) //is a page specified? else use 0
+ "\n"); if(args.length > 1) {
try {
page = Integer.parseInt(args[1]);
} catch(Exception e) {
page = 0;
}
}
//Get the total pages
int totalPages = ((int) Math.ceil(12 * (PlotMain.getPlotsSorted().size()) / 100));
if(page > totalPages)
page = totalPages;
//Only display 12!
int max = (page * 12) + 12;
if(max > PlotMain.getPlotsSorted().size())
max = PlotMain.getPlotsSorted().size();
StringBuilder string = new StringBuilder();
string.append(C.PLOT_LIST_HEADER_PAGED.s().replaceAll("%cur", page + 1 + "").replaceAll("%max", totalPages + 1 + "").replaceAll("%word%", "all") + "\n");
Plot p;
//This might work xD
for (int x = (page * 12); x < max; x++) {
p = (Plot) PlotMain.getPlotsSorted().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_FOOTER.s().replaceAll("%word%", "There is").replaceAll("%num%", PlotMain.getPlots().size()
+ "").replaceAll("%plot%", PlotMain.getPlots().size() == 1 ? "plot" : "plots")); string.append(C.PLOT_LIST_FOOTER.s().replaceAll("%word%", "There is").replaceAll("%num%", PlotMain.getPlotsSorted().size()
+ "").replaceAll("%plot%", PlotMain.getPlotsSorted().size() == 1 ? "plot" : "plots"));
PlayerFunctions.sendMessage(plr, string.toString()); PlayerFunctions.sendMessage(plr, string.toString());
return true; return true;
} }
@ -96,8 +117,7 @@ public class list extends SubCommand {
string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "all") + "\n"); string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "all") + "\n");
HashMap<PlotId, Plot> plots = PlotMain.getPlots(plr.getWorld()); HashMap<PlotId, Plot> plots = PlotMain.getPlots(plr.getWorld());
for (Plot p : plots.values()) { for (Plot p : plots.values()) {
string.append(C.PLOT_LIST_ITEM.s().replaceAll("%id%", p.id.x + ";" + p.id.y + ";" + p.world).replaceAll("%owner%", getName(p.owner)) string.append(C.PLOT_LIST_ITEM.s().replaceAll("%id", p.id.toString()).replaceAll("%world", p.world).replaceAll("%owner", getName(p.owner))).append("\n");
+ "\n");
} }
string.append(C.PLOT_LIST_FOOTER.s().replaceAll("%word%", "There is").replaceAll("%num%", plots.values().size() string.append(C.PLOT_LIST_FOOTER.s().replaceAll("%word%", "There is").replaceAll("%num%", plots.values().size()
+ "").replaceAll("%plot%", plots.values().size() == 1 ? "plot" : "plots")); + "").replaceAll("%plot%", plots.values().size() == 1 ? "plot" : "plots"));
@ -105,8 +125,9 @@ public class list extends SubCommand {
return true; return true;
} }
else { else {
execute(plr); //execute(plr);
return false; sendMessage(plr, C.DID_YOU_MEAN, new StringComparsion(args[0], new String[] { "mine", "shared", "world", "all" }).getBestMatch());
return false;
} }
} }

View File

@ -8,17 +8,17 @@
package com.intellectualcrafters.plot.database; package com.intellectualcrafters.plot.database;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.UUID;
import org.bukkit.OfflinePlayer;
import com.intellectualcrafters.plot.Flag; import com.intellectualcrafters.plot.Flag;
import com.intellectualcrafters.plot.Plot; import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotComment; import com.intellectualcrafters.plot.PlotComment;
import com.intellectualcrafters.plot.PlotId; import com.intellectualcrafters.plot.PlotId;
import org.bukkit.OfflinePlayer;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.UUID;
/** /**
* @author Citymonstret * @author Citymonstret
@ -78,7 +78,7 @@ public abstract class AbstractDB {
/** /**
* @return * @return
*/ */
public abstract HashMap<String, HashMap<PlotId, Plot>> getPlots(); public abstract LinkedHashMap<String, HashMap<PlotId, Plot>> getPlots();
public abstract void setMerged(final String world, final Plot plot, final boolean[] merged); public abstract void setMerged(final String world, final Plot plot, final boolean[] merged);

View File

@ -8,16 +8,16 @@
package com.intellectualcrafters.plot.database; package com.intellectualcrafters.plot.database;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.UUID;
import org.bukkit.OfflinePlayer;
import com.intellectualcrafters.plot.Flag; import com.intellectualcrafters.plot.Flag;
import com.intellectualcrafters.plot.Plot; import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotComment; import com.intellectualcrafters.plot.PlotComment;
import com.intellectualcrafters.plot.PlotId; import com.intellectualcrafters.plot.PlotId;
import org.bukkit.OfflinePlayer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.UUID;
/** /**
* @author Citymonstret * @author Citymonstret
@ -111,7 +111,7 @@ public class DBFunc {
/** /**
* @return * @return
*/ */
public static HashMap<String, HashMap<PlotId, Plot>> getPlots() { public static LinkedHashMap<String, HashMap<PlotId, Plot>> getPlots() {
return dbManager.getPlots(); return dbManager.getPlots();
} }

View File

@ -377,8 +377,8 @@ public class SQLManager extends AbstractDB {
* @return * @return
*/ */
@Override @Override
public HashMap<String, HashMap<PlotId, Plot>> getPlots() { public LinkedHashMap<String, HashMap<PlotId, Plot>> getPlots() {
HashMap<String, HashMap<PlotId, Plot>> newplots = new HashMap<String, HashMap<PlotId, Plot>>(); LinkedHashMap<String, HashMap<PlotId, Plot>> newplots = new LinkedHashMap<String, HashMap<PlotId, Plot>>();
try { try {
DatabaseMetaData data = connection.getMetaData(); DatabaseMetaData data = connection.getMetaData();
ResultSet rs = data.getColumns(null, null, PREFIX+"plot", "plot_id"); ResultSet rs = data.getColumns(null, null, PREFIX+"plot", "plot_id");

View File

@ -146,7 +146,7 @@ public class DefaultPlotWorld extends PlotWorld {
new ConfigurationNode("plot.filling", DefaultPlotWorld.MAIN_BLOCK_DEFAULT, "Plot block", Configuration.BLOCKLIST, true), new ConfigurationNode("plot.filling", DefaultPlotWorld.MAIN_BLOCK_DEFAULT, "Plot block", Configuration.BLOCKLIST, true),
new ConfigurationNode("plot.floor", DefaultPlotWorld.TOP_BLOCK_DEFAULT, "Plot floor block", Configuration.BLOCKLIST, true), new ConfigurationNode("plot.floor", DefaultPlotWorld.TOP_BLOCK_DEFAULT, "Plot floor block", Configuration.BLOCKLIST, true),
new ConfigurationNode("wall.block", DefaultPlotWorld.WALL_BLOCK_DEFAULT, "Top wall block", Configuration.BLOCK, true), new ConfigurationNode("wall.block", DefaultPlotWorld.WALL_BLOCK_DEFAULT, "Top wall block", Configuration.BLOCK, true),
new ConfigurationNode("wall.block.claimed", DefaultPlotWorld.CLAIMED_WALL_BLOCK_DEFAULT, "Wall block (claimed)", Configuration.BLOCK, true), new ConfigurationNode("wall.block_claimed", DefaultPlotWorld.CLAIMED_WALL_BLOCK_DEFAULT, "Wall block (claimed)", Configuration.BLOCK, true),
new ConfigurationNode("road.width", DefaultPlotWorld.ROAD_WIDTH_DEFAULT, "Road width", Configuration.INTEGER, true), new ConfigurationNode("road.width", DefaultPlotWorld.ROAD_WIDTH_DEFAULT, "Road width", Configuration.INTEGER, true),
new ConfigurationNode("road.height", DefaultPlotWorld.ROAD_HEIGHT_DEFAULT, "Road height", Configuration.INTEGER, true), new ConfigurationNode("road.height", DefaultPlotWorld.ROAD_HEIGHT_DEFAULT, "Road height", Configuration.INTEGER, true),
new ConfigurationNode("road.enable_stripes", DefaultPlotWorld.ROAD_STRIPES_ENABLED_DEFAULT, "Enable road stripes", Configuration.BOOLEAN, true), new ConfigurationNode("road.enable_stripes", DefaultPlotWorld.ROAD_STRIPES_ENABLED_DEFAULT, "Enable road stripes", Configuration.BOOLEAN, true),
@ -182,6 +182,6 @@ public class DefaultPlotWorld extends PlotWorld {
this.ROAD_STRIPES = (PlotBlock) Configuration.BLOCK.parseString(config.getString("road.stripes")); this.ROAD_STRIPES = (PlotBlock) Configuration.BLOCK.parseString(config.getString("road.stripes"));
this.WALL_FILLING = (PlotBlock) Configuration.BLOCK.parseString(config.getString("wall.filling")); this.WALL_FILLING = (PlotBlock) Configuration.BLOCK.parseString(config.getString("wall.filling"));
this.WALL_HEIGHT = config.getInt("wall.height"); this.WALL_HEIGHT = config.getInt("wall.height");
this.CLAIMED_WALL_BLOCK = (PlotBlock) Configuration.BLOCK.parseString(config.getString("wall.block.claimed")); this.CLAIMED_WALL_BLOCK = (PlotBlock) Configuration.BLOCK.parseString(config.getString("wall.block_claimed"));
} }
} }