Minor fixes

This commit is contained in:
Jesse Boyd 2016-10-14 15:14:08 +11:00
parent 5978c9c3c0
commit c97544d083
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
4 changed files with 45 additions and 20 deletions

View File

@ -197,7 +197,7 @@ public class MainCommand extends Command {
} }
@Override @Override
public void execute(PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) { public void execute(final PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) {
// Clear perm caching // // Clear perm caching //
player.deleteMeta("perm"); player.deleteMeta("perm");
// Optional command scope // // Optional command scope //
@ -223,6 +223,37 @@ public class MainCommand extends Command {
// Trim command // Trim command
args = Arrays.copyOfRange(args, 1, args.length); 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<Command, Runnable, Runnable>() {
@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<Double> 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 { try {
super.execute(player, args, confirm, whenDone); super.execute(player, args, confirm, whenDone);

View File

@ -452,6 +452,10 @@ public enum C {
INVALID_PLAYER_WAIT("$2Player not found: $1%s$2, fetching it. Try again soon.", "Errors"), 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("$2Player not found: $1%s$2.", "Errors"),
INVALID_PLAYER_OFFLINE("$2The player must be online: $1%s.", "Errors"), INVALID_PLAYER_OFFLINE("$2The player must be online: $1%s.", "Errors"),
/*
* Command flag
*/
INVALID_COMMAND_FLAG("$2Invalid command flag: %s0", "Errors"),
/* /*
* Unknown Error * Unknown Error
*/ */

View File

@ -3,7 +3,6 @@ package com.plotsquared.nukkit.util;
import cn.nukkit.level.Level; import cn.nukkit.level.Level;
import cn.nukkit.level.generator.Generator; import cn.nukkit.level.generator.Generator;
import com.intellectualcrafters.configuration.ConfigurationSection; import com.intellectualcrafters.configuration.ConfigurationSection;
import com.intellectualcrafters.configuration.file.YamlConfiguration;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.ConfigurationNode; import com.intellectualcrafters.plot.config.ConfigurationNode;
import com.intellectualcrafters.plot.generator.GeneratorWrapper; import com.intellectualcrafters.plot.generator.GeneratorWrapper;
@ -12,7 +11,7 @@ import com.intellectualcrafters.plot.object.SetupObject;
import com.intellectualcrafters.plot.util.SetupUtils; import com.intellectualcrafters.plot.util.SetupUtils;
import com.plotsquared.nukkit.NukkitMain; import com.plotsquared.nukkit.NukkitMain;
import com.plotsquared.nukkit.generator.NukkitPlotGenerator; import com.plotsquared.nukkit.generator.NukkitPlotGenerator;
import java.io.File; import com.plotsquared.nukkit.util.block.NukkitHybridGen;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.HashMap; import java.util.HashMap;
@ -25,6 +24,7 @@ public class NukkitSetupUtils extends SetupUtils {
public NukkitSetupUtils(NukkitMain plugin) { public NukkitSetupUtils(NukkitMain plugin) {
this.plugin = plugin; this.plugin = plugin;
Generator.addGenerator(NukkitHybridGen.class, "PlotSquared", 1);
} }
@Override @Override
@ -119,14 +119,16 @@ public class NukkitSetupUtils extends SetupUtils {
HashMap<String, Object> map = new HashMap<>(); HashMap<String, Object> map = new HashMap<>();
map.put("world", object.world); map.put("world", object.world);
map.put("plot-generator", PS.get().IMP.getDefaultGenerator()); 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); plugin.getServer().loadLevel(object.world);
} }
try { try {
File nukkitFile = new File("nukkit.yml"); // File nukkitFile = new File("nukkit.yml");
YamlConfiguration nukkitYml = YamlConfiguration.loadConfiguration(nukkitFile); // YamlConfiguration nukkitYml = YamlConfiguration.loadConfiguration(nukkitFile);
nukkitYml.set("worlds." + object.world + ".generator", object.setupGenerator); // if (!nukkitYml.contains("worlds." + object.world + ".generator")) {
nukkitYml.save(nukkitFile); // nukkitYml.set("worlds." + object.world + ".generator", object.setupGenerator);
// nukkitYml.save(nukkitFile);
// }
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -138,17 +140,6 @@ public class NukkitSetupUtils extends SetupUtils {
return object.world; 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 @Override
public String getGenerator(PlotArea plotArea) { public String getGenerator(PlotArea plotArea) {
if (SetupUtils.generators.isEmpty()) { if (SetupUtils.generators.isEmpty()) {

View File

@ -2,7 +2,6 @@ package com.plotsquared.nukkit.util.block;
import cn.nukkit.level.Level; import cn.nukkit.level.Level;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.generator.HybridGen;
import com.plotsquared.nukkit.NukkitMain; import com.plotsquared.nukkit.NukkitMain;
import com.plotsquared.nukkit.generator.NukkitPlotGenerator; import com.plotsquared.nukkit.generator.NukkitPlotGenerator;
import java.util.Map; import java.util.Map;