diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java index a82337de4..fb46885c6 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java @@ -197,7 +197,7 @@ public class MainCommand extends Command { } @Override - public void execute(PlotPlayer player, String[] args, RunnableVal3 confirm, RunnableVal2 whenDone) { + public void execute(final PlotPlayer player, String[] args, RunnableVal3 confirm, RunnableVal2 whenDone) { // Clear perm caching // player.deleteMeta("perm"); // Optional command scope // @@ -223,6 +223,37 @@ public class MainCommand extends Command { // Trim command args = Arrays.copyOfRange(args, 1, args.length); } + if (args.length >= 2 && args[0].charAt(0) == '-') { + switch (args[0].substring(1)) { + case "f": + confirm = new RunnableVal3() { + @Override + public void run(final Command cmd, final Runnable success, final Runnable failure) { + if (EconHandler.manager != null) { + PlotArea area = player.getApplicablePlotArea(); + if (area != null) { + Expression priceEval = area.PRICES.get(cmd.getFullId()); + Double price = priceEval != null ? priceEval.evaluate(0d) : 0d; + if (price != 0d && EconHandler.manager.getMoney(player) < price) { + if (failure != null) { + failure.run(); + } + return; + } + } + } + if (success != null) { + success.run(); + } + } + }; + args = Arrays.copyOfRange(args, 1, args.length); + break; + default: + C.INVALID_COMMAND_FLAG.send(player); + return; + } + } } try { super.execute(player, args, confirm, whenDone); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/config/C.java b/Core/src/main/java/com/intellectualcrafters/plot/config/C.java index 93432f633..460056740 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -452,6 +452,10 @@ public enum C { INVALID_PLAYER_WAIT("$2Player not found: $1%s$2, fetching it. Try again soon.", "Errors"), INVALID_PLAYER("$2Player not found: $1%s$2.", "Errors"), INVALID_PLAYER_OFFLINE("$2The player must be online: $1%s.", "Errors"), + /* + * Command flag + */ + INVALID_COMMAND_FLAG("$2Invalid command flag: %s0", "Errors"), /* * Unknown Error */ diff --git a/Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitSetupUtils.java b/Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitSetupUtils.java index 548d3c935..53530b260 100644 --- a/Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitSetupUtils.java +++ b/Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitSetupUtils.java @@ -3,7 +3,6 @@ package com.plotsquared.nukkit.util; import cn.nukkit.level.Level; import cn.nukkit.level.generator.Generator; import com.intellectualcrafters.configuration.ConfigurationSection; -import com.intellectualcrafters.configuration.file.YamlConfiguration; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.ConfigurationNode; import com.intellectualcrafters.plot.generator.GeneratorWrapper; @@ -12,7 +11,7 @@ import com.intellectualcrafters.plot.object.SetupObject; import com.intellectualcrafters.plot.util.SetupUtils; import com.plotsquared.nukkit.NukkitMain; import com.plotsquared.nukkit.generator.NukkitPlotGenerator; -import java.io.File; +import com.plotsquared.nukkit.util.block.NukkitHybridGen; import java.io.IOException; import java.lang.reflect.Field; import java.util.HashMap; @@ -25,6 +24,7 @@ public class NukkitSetupUtils extends SetupUtils { public NukkitSetupUtils(NukkitMain plugin) { this.plugin = plugin; + Generator.addGenerator(NukkitHybridGen.class, "PlotSquared", 1); } @Override @@ -119,14 +119,16 @@ public class NukkitSetupUtils extends SetupUtils { HashMap map = new HashMap<>(); map.put("world", object.world); map.put("plot-generator", PS.get().IMP.getDefaultGenerator()); - if (!plugin.getServer().generateLevel(object.world, object.world.hashCode(), NukkitPlotGenerator.class, map)) { + if (!plugin.getServer().generateLevel(object.world, object.world.hashCode(), NukkitHybridGen.class, map)) { plugin.getServer().loadLevel(object.world); } try { - File nukkitFile = new File("nukkit.yml"); - YamlConfiguration nukkitYml = YamlConfiguration.loadConfiguration(nukkitFile); - nukkitYml.set("worlds." + object.world + ".generator", object.setupGenerator); - nukkitYml.save(nukkitFile); +// File nukkitFile = new File("nukkit.yml"); +// YamlConfiguration nukkitYml = YamlConfiguration.loadConfiguration(nukkitFile); +// if (!nukkitYml.contains("worlds." + object.world + ".generator")) { +// nukkitYml.set("worlds." + object.world + ".generator", object.setupGenerator); +// nukkitYml.save(nukkitFile); +// } } catch (Throwable e) { e.printStackTrace(); } @@ -138,17 +140,6 @@ public class NukkitSetupUtils extends SetupUtils { return object.world; } - public void setGenerator(String world, String generator) { - File file = new File("nukkit.yml").getAbsoluteFile(); - YamlConfiguration yml = YamlConfiguration.loadConfiguration(file); - yml.set("worlds." + world + ".generator", generator); - try { - yml.save(file); - } catch (IOException e) { - e.printStackTrace(); - } - } - @Override public String getGenerator(PlotArea plotArea) { if (SetupUtils.generators.isEmpty()) { diff --git a/Nukkit/src/main/java/com/plotsquared/nukkit/util/block/NukkitHybridGen.java b/Nukkit/src/main/java/com/plotsquared/nukkit/util/block/NukkitHybridGen.java index aec5bf646..68a79014d 100644 --- a/Nukkit/src/main/java/com/plotsquared/nukkit/util/block/NukkitHybridGen.java +++ b/Nukkit/src/main/java/com/plotsquared/nukkit/util/block/NukkitHybridGen.java @@ -2,7 +2,6 @@ package com.plotsquared.nukkit.util.block; import cn.nukkit.level.Level; import com.intellectualcrafters.plot.PS; -import com.intellectualcrafters.plot.generator.HybridGen; import com.plotsquared.nukkit.NukkitMain; import com.plotsquared.nukkit.generator.NukkitPlotGenerator; import java.util.Map;