mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 07:06:44 +01:00
Fixing some stuff after testing
This commit is contained in:
parent
5b2e83587b
commit
955fa674d0
@ -44,6 +44,7 @@ import com.intellectualcrafters.plot.util.StringMan;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.plotsquared.bukkit.generator.AugmentedPopulator;
|
||||
import com.plotsquared.bukkit.generator.BukkitGeneratorWrapper;
|
||||
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
||||
import com.plotsquared.bukkit.generator.HybridGen;
|
||||
import com.plotsquared.bukkit.util.SetupUtils;
|
||||
@ -154,7 +155,7 @@ public class Cluster extends SubCommand {
|
||||
PlotWorld plotworld = PS.get().getPlotWorld(world);
|
||||
if (plotworld == null) {
|
||||
PS.get().config.createSection("worlds." + world);
|
||||
PS.get().loadWorld(world, null);
|
||||
PS.get().loadWorld(world, PS.get().IMP.getGenerator(world, null));
|
||||
}
|
||||
else {
|
||||
final String gen_string = PS.get().config.getString("worlds." + world + "." + "generator.plugin");
|
||||
@ -302,8 +303,9 @@ public class Cluster extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
long start = System.currentTimeMillis();
|
||||
ClusterManager.regenCluster(cluster);
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_REGENERATED);
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_REGENERATED, (System.currentTimeMillis() - start) + "");
|
||||
return true;
|
||||
}
|
||||
case "add":
|
||||
|
@ -153,47 +153,43 @@ public class MainCommand extends CommandManager<PlotPlayer> {
|
||||
// return help;
|
||||
// }
|
||||
//
|
||||
public static void displayHelp(PlotPlayer player, String cat, int page) {
|
||||
if (cat != null && StringMan.isEqualIgnoreCase(cat, "all")) {
|
||||
cat = null;
|
||||
public static void displayHelp(PlotPlayer player, String cat, int page, String label) {
|
||||
CommandCategory catEnum = null;
|
||||
if (cat != null) {
|
||||
if (StringMan.isEqualIgnoreCase(cat, "all")) {
|
||||
catEnum = null;
|
||||
}
|
||||
else {
|
||||
for (CommandCategory c : CommandCategory.values()) {
|
||||
if (StringMan.isEqualIgnoreCaseToAny(cat, c.name(), c.toString())) {
|
||||
catEnum = c;
|
||||
cat = c.name();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (catEnum == null) {
|
||||
cat = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cat == null && page == 0) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
builder.append(C.HELP_INFO.s());
|
||||
for (final CommandCategory category : CommandCategory.values()) {
|
||||
builder.append("\n").append(C.HELP_INFO_ITEM.s().replaceAll("%category%", category.toString().toLowerCase()).replaceAll("%category_desc%", category.toString()));
|
||||
builder.append(C.HELP_HEADER.s());
|
||||
for (final CommandCategory c : CommandCategory.values()) {
|
||||
builder.append("\n" + StringMan.replaceAll(C.HELP_INFO_ITEM.s(), "%category%", c.toString().toLowerCase(), "%category_desc%", c.toString()));
|
||||
}
|
||||
builder.append("\n").append(C.HELP_INFO_ITEM.s().replaceAll("%category%", "all").replaceAll("%category_desc%", "Display all commands"));
|
||||
MainUtil.sendMessage(player, builder.toString());
|
||||
return;
|
||||
}
|
||||
CommandCategory cato = null;
|
||||
for (final CommandCategory category : CommandCategory.values()) {
|
||||
if (cat.equalsIgnoreCase(category.toString())) {
|
||||
cato = category;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((cato == null) && !cat.equalsIgnoreCase("all")) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
builder.append(C.HELP_INFO.s());
|
||||
for (final CommandCategory category : CommandCategory.values()) {
|
||||
builder.append("\n").append(C.HELP_INFO_ITEM.s().replaceAll("%category%", category.toString().toLowerCase()).replaceAll("%category_desc%", category.toString()));
|
||||
}
|
||||
builder.append("\n" + C.HELP_FOOTER.s());
|
||||
MainUtil.sendMessage(player, builder.toString(), false);
|
||||
return;
|
||||
}
|
||||
page--;
|
||||
new HelpMenu(player)
|
||||
.setCategory(cato)
|
||||
.setCategory(catEnum)
|
||||
.getCommands()
|
||||
.generateMaxPages()
|
||||
.generatePage(page)
|
||||
.generatePage(page, label)
|
||||
.render();
|
||||
// final StringBuilder help = new StringBuilder();
|
||||
// for (final String string : helpMenu(player, cato, page)) {
|
||||
// help.append(string).append("\n");
|
||||
// }
|
||||
// MainUtil.sendMessage(player, help.toString());
|
||||
}
|
||||
|
||||
public static boolean onCommand(final PlotPlayer player, final String cmd, final String... args) {
|
||||
@ -207,44 +203,37 @@ public class MainCommand extends CommandManager<PlotPlayer> {
|
||||
switch (args.length) {
|
||||
case 3: {
|
||||
category = args[1];
|
||||
if (MathMan.isInteger(args[2])) {
|
||||
try {
|
||||
help_index = Integer.parseInt(args[2]);
|
||||
}
|
||||
catch (NumberFormatException e) {}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
if (MathMan.isInteger(args[args.length - 1])) {
|
||||
if (MathMan.isInteger(args[1])) {
|
||||
category = null;
|
||||
try {
|
||||
help_index = Integer.parseInt(args[1]) - 1;
|
||||
help_index = Integer.parseInt(args[1]);
|
||||
}
|
||||
catch (NumberFormatException e) {}
|
||||
}
|
||||
if (category == null) {
|
||||
category = args[1];
|
||||
}
|
||||
}
|
||||
case 1: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (args.length == 3) {
|
||||
if (MathMan.isInteger(args[args.length - 1])) {
|
||||
category = null;
|
||||
try {
|
||||
help_index = Integer.parseInt(args[1]) - 1;
|
||||
}
|
||||
catch (NumberFormatException e) {}
|
||||
}
|
||||
else {
|
||||
category = args[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (MathMan.isInteger(args[args.length - 1])) {
|
||||
else if (args.length == 1 && MathMan.isInteger(args[args.length - 1])) {
|
||||
try {
|
||||
help_index = Integer.parseInt(args[args.length - 1]) - 1;
|
||||
help_index = Integer.parseInt(args[args.length - 1]);
|
||||
}
|
||||
catch (NumberFormatException e) {}
|
||||
}
|
||||
if (help_index != -1) {
|
||||
displayHelp(player, category, help_index);
|
||||
displayHelp(player, category, help_index, cmd);
|
||||
return true;
|
||||
}
|
||||
StringBuilder builder = new StringBuilder(cmd).append(" ");
|
||||
|
@ -361,7 +361,7 @@ public class Set extends SubCommand {
|
||||
a.append(" ").append(args[x]);
|
||||
}
|
||||
}
|
||||
MainCommand.onCommand(plr, world, ("flag set " + args[0] + a.toString()).split(" "));
|
||||
MainCommand.onCommand(plr, "flag", ("set " + args[0] + a.toString()).split(" "));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ public enum C {
|
||||
NO_PLOT_INBOX("$2You must stand in or supply a plot argument", "Comment"),
|
||||
COMMENT_REMOVED("$4Successfully deleted comment/s:n$2 - '$3%s$2'", "Comment"),
|
||||
COMMENT_ADDED("$4A comment has been left", "Comment"),
|
||||
COMMENT_HEADER("$2====== Comments ======", "Comment"),
|
||||
COMMENT_HEADER("$2&m---------&r $1Comments $2&m---------&r", "Comment"),
|
||||
INBOX_EMPTY("$2No comments","Comment"),
|
||||
/*
|
||||
* Console
|
||||
@ -388,7 +388,7 @@ public enum C {
|
||||
NONE("None", "Info"),
|
||||
PLOT_UNOWNED("$2The current plot must have an owner to perform this action", "Info"),
|
||||
PLOT_INFO_UNCLAIMED("$2Plot $1%s$2 is not yet claimed", "Info"),
|
||||
PLOT_INFO_HEADER("$3====== $1INFO $3======", false, "Info"),
|
||||
PLOT_INFO_HEADER("$3&m---------&r $1INFO $3&m---------", false, "Info"),
|
||||
PLOT_INFO("$1ID: $2%id%$1&-" + "$1Alias: $2%alias%$1&-" + "$1Owner: $2%owner%$1&-" + "$1Biome: $2%biome%$1&-" + "$1Can Build: $2%build%$1&-" + "$1Rating: $2%rating%&-" + "$1Trusted: $2%trusted%$1&-" + "$1Members: $2%members%$1&-" + "$1Denied: $2%denied%$1&-" + "$1Flags: $2%flags%", "Info"),
|
||||
PLOT_INFO_TRUSTED("$1Trusted:$2 %trusted%", "Info"),
|
||||
PLOT_INFO_MEMBERS("$1Members:$2 %members%", "Info"),
|
||||
@ -505,11 +505,10 @@ public enum C {
|
||||
/*
|
||||
* Help
|
||||
*/
|
||||
HELP_HEADER("$3====== $1Plot\u00B2 Help $3======", "Help"),
|
||||
HELP_HEADER("$3&m---------&r $1Plot\u00B2 Help $3&m---------", "Help"),
|
||||
HELP_PAGE_HEADER("$1Category: $2%category%$2,$1 Page: $2%current%$3/$2%max%$2", "Help"),
|
||||
HELP_FOOTER("$3====== $1Plot\u00B2 Help $3======", "Help"),
|
||||
HELP_FOOTER("$3&m---------&r $1Plot\u00B2 Help $3&m---------", "Help"),
|
||||
|
||||
HELP_INFO("$3====== $1Choose a Category $3======", false, "Help"),
|
||||
HELP_INFO_ITEM("$1/plots help %category% $3- $2%category_desc%", "Help"),
|
||||
HELP_ITEM("$1%usage% [%alias%]&- $3- $2%desc%&-", "Help"),
|
||||
/*
|
||||
|
@ -158,6 +158,9 @@ public class ClusterManager {
|
||||
public static PlotCluster getCluster(final Location loc) {
|
||||
final String world = loc.getWorld();
|
||||
PlotManager manager = PS.get().getPlotManager(world);
|
||||
if (manager == null) {
|
||||
return null;
|
||||
}
|
||||
PlotId id = manager.getPlotIdAbs(PS.get().getPlotWorld(world), loc.getX(), loc.getY(), loc.getZ());
|
||||
if (id != null) {
|
||||
return getCluster(world, id);
|
||||
|
@ -152,12 +152,10 @@ public class StringMan {
|
||||
|
||||
public static String join(Object[] array, String delimiter) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
System.out.print(array.getClass().getName());
|
||||
for (int i = 0, j = array.length; i < j; i++) {
|
||||
if (i > 0) {
|
||||
result.append(delimiter);
|
||||
}
|
||||
System.out.print(array[i].getClass().getName());
|
||||
result.append(array[i]);
|
||||
}
|
||||
return result.toString();
|
||||
|
@ -33,18 +33,18 @@ public class HelpMenu {
|
||||
}
|
||||
|
||||
public HelpMenu generateMaxPages() {
|
||||
this._maxPage = Math.min(_commands.size() / PER_PAGE, 1);
|
||||
this._maxPage = Math.max(_commands.size() - 1 / PER_PAGE, 1);
|
||||
return this;
|
||||
}
|
||||
|
||||
public HelpMenu generatePage(int currentPage) {
|
||||
public HelpMenu generatePage(int currentPage, String label) {
|
||||
if (currentPage > _maxPage) {
|
||||
currentPage = _maxPage;
|
||||
}
|
||||
_page = new HelpPage(_commandCategory, currentPage, _maxPage);
|
||||
int max = Math.min((currentPage * PER_PAGE) + PER_PAGE, _commands.size());
|
||||
int max = Math.min((currentPage * PER_PAGE) + (PER_PAGE - 1), _commands.size());
|
||||
for (int i = currentPage * PER_PAGE; i < max; i++) {
|
||||
_page.addHelpItem(new HelpObject(_commands.get(i)));
|
||||
_page.addHelpItem(new HelpObject(_commands.get(i), label));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -10,14 +10,9 @@ public class HelpObject {
|
||||
private final Command _command;
|
||||
private final String _rendered;
|
||||
|
||||
public HelpObject(final Command command) {
|
||||
public HelpObject(final Command command, String label) {
|
||||
this._command = command;
|
||||
String rendered = C.HELP_ITEM.s();
|
||||
this._rendered = rendered
|
||||
.replace("%usage%", _command.getUsage())
|
||||
.replace("%alias%", _command.getAliases().size() > 0 ? StringMan.join(_command.getAliases(), "|") : "")
|
||||
.replace("%desc%", _command.getDescription())
|
||||
.replace("%arguments%", buildArgumentList(_command.getRequiredArguments())); // TODO Make configurable
|
||||
this._rendered = StringMan.replaceAll(C.HELP_ITEM.s(), "%usage%", _command.getUsage(), "[%alias%]", _command.getAliases().size() > 0 ? "(" + StringMan.join(_command.getAliases(), "|") + ")" : "","%desc%", _command.getDescription(),"%arguments%", buildArgumentList(_command.getRequiredArguments()), "{label}", label);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -26,8 +21,11 @@ public class HelpObject {
|
||||
}
|
||||
|
||||
private String buildArgumentList(Argument[] arguments) {
|
||||
if (arguments == null) {
|
||||
return "";
|
||||
}
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (final Argument argument : arguments) {
|
||||
for (final Argument<?> argument : arguments) {
|
||||
builder.append("[").append(argument.getName()).append(" (").append(argument.getExample()).append(")],");
|
||||
}
|
||||
return arguments.length > 0 ? builder.substring(0, builder.length() - 1) : "";
|
||||
|
@ -5,25 +5,27 @@ import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class HelpPage {
|
||||
|
||||
private final Set<HelpObject> _helpObjecs;
|
||||
private final List<HelpObject> _helpObjecs;
|
||||
private final String _header;
|
||||
|
||||
public HelpPage(CommandCategory category, int currentPage, int maxPages) {
|
||||
_helpObjecs = new HashSet<>();
|
||||
_helpObjecs = new ArrayList<>();
|
||||
_header = C.HELP_PAGE_HEADER.s()
|
||||
.replace("%category%", category == null ? "ALL" : category.toString())
|
||||
.replace("%current%", currentPage + "")
|
||||
.replace("%max%", maxPages + "");
|
||||
.replace("%current%", (currentPage + 1) + "")
|
||||
.replace("%max%", (maxPages + 1) + "");
|
||||
}
|
||||
|
||||
public void render(final PlotPlayer player) {
|
||||
if (_helpObjecs.size() < 2) {
|
||||
MainUtil.sendMessage(player, C.NO_COMMANDS.s(), false);
|
||||
if (_helpObjecs.size() < 1) {
|
||||
MainUtil.sendMessage(player, C.NOT_VALID_NUMBER, "(0)");
|
||||
} else {
|
||||
MainUtil.sendMessage(player, C.HELP_HEADER.s(), false);
|
||||
MainUtil.sendMessage(player, _header, false);
|
||||
|
@ -114,6 +114,9 @@ public abstract class Command<E extends CommandCaller> extends CommandManager {
|
||||
}
|
||||
|
||||
final public String getUsage() {
|
||||
if (this.usage.length() == 0) {
|
||||
return "/{label} " + command;
|
||||
}
|
||||
return this.usage;
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ public @interface CommandDeclaration {
|
||||
|
||||
String command();
|
||||
|
||||
String[] aliases() default "";
|
||||
String[] aliases() default {};
|
||||
|
||||
String permission() default "";
|
||||
|
||||
|
@ -408,6 +408,9 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||
|
||||
@Override
|
||||
public BukkitGeneratorWrapper getGenerator(final String world, final String name) {
|
||||
if (name == null) {
|
||||
return new BukkitGeneratorWrapper(world, null);
|
||||
}
|
||||
final Plugin gen_plugin = Bukkit.getPluginManager().getPlugin(name);
|
||||
ChunkGenerator gen;
|
||||
if ((gen_plugin != null) && gen_plugin.isEnabled()) {
|
||||
|
@ -46,9 +46,6 @@ public class BukkitGeneratorWrapper extends PlotGenerator<ChunkGenerator> {
|
||||
if (gen_wrapper != null) {
|
||||
generator = gen_wrapper.generator;
|
||||
}
|
||||
else {
|
||||
System.out.print("INVALID GENERATOR: " + gen_string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,9 +38,6 @@ public class WorldEvents implements Listener {
|
||||
if (PS.get().config.contains("worlds." + name)) {
|
||||
PS.get().loadWorld(name, new BukkitGeneratorWrapper(name, null));
|
||||
}
|
||||
else if (gen != null) {
|
||||
System.out.print("NOT INSTANCE OF BukkitGeneratorWrapper: " + gen.getClass().getName());
|
||||
}
|
||||
}
|
||||
lastWorld = null;
|
||||
}
|
||||
|
@ -63,6 +63,7 @@ import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class BukkitChunkManager extends ChunkManager {
|
||||
@ -359,6 +360,7 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
final Random r = new Random(System.currentTimeMillis());
|
||||
final AugmentedPopulator ap = augpop;
|
||||
TaskManager.runTask(new Runnable() {
|
||||
@Override
|
||||
@ -380,7 +382,7 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
CURRENT_PLOT_CLEAR = new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ());
|
||||
if (xxb >= p1x && xxt <= p2x && zzb >= p1z && zzt <= p2z) {
|
||||
if (canRegen && ap != null) {
|
||||
ap.populate(worldObj, null, chunkObj);
|
||||
ap.populate(worldObj, r, chunkObj);
|
||||
}
|
||||
else {
|
||||
regenerateChunk(world, chunk);
|
||||
@ -452,7 +454,7 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
}
|
||||
saveEntitiesOut(chunkObj, CURRENT_PLOT_CLEAR);
|
||||
if (canRegen && ap != null) {
|
||||
ap.populate(worldObj, null, chunkObj);
|
||||
ap.populate(worldObj, r, chunkObj);
|
||||
}
|
||||
else {
|
||||
regenerateChunk(world, chunk);
|
||||
|
@ -50,6 +50,6 @@ public class SetGenCB {
|
||||
}
|
||||
}
|
||||
}
|
||||
PS.get().loadWorld(world.getName(), null);
|
||||
PS.get().loadWorld(world.getName(), PS.get().IMP.getGenerator(world.getName(), null));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user