This commit is contained in:
boy0001 2015-08-09 19:58:29 +10:00
parent 051449157a
commit e28c68ee74
14 changed files with 113 additions and 49 deletions

View File

@ -254,13 +254,29 @@ public class PS {
} }
// World generators: // World generators:
ConfigurationSection section = config.getConfigurationSection("worlds"); final ConfigurationSection section = config.getConfigurationSection("worlds");
if (section != null) { if (section != null) {
for (String world : section.getKeys(false)) { for (String world : section.getKeys(false)) {
if (world.equals("CheckingPlotSquaredGenerator")) {
continue;
}
if (BlockManager.manager.isWorld(world)) { if (BlockManager.manager.isWorld(world)) {
break; IMP.setGenerator(world);
} }
} }
TaskManager.runTaskLater(new Runnable() {
@Override
public void run() {
for (String world : section.getKeys(false)) {
if (world.equals("CheckingPlotSquaredGenerator")) {
continue;
}
if (!BlockManager.manager.isWorld(world)) {
IMP.setGenerator(world);
}
}
}
}, 1);
} }
// Copy files // Copy files

View File

@ -62,7 +62,7 @@ import com.plotsquared.bukkit.util.BukkitUtil;
* *
*/ */
@SuppressWarnings("unused") public class PlotAPI { public class PlotAPI {
/** /**
* Permission that allows for admin access, this permission node will allow the player to use any part of the * Permission that allows for admin access, this permission node will allow the player to use any part of the

View File

@ -25,6 +25,7 @@ import java.util.Collection;
import java.util.UUID; import java.util.UUID;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
@ -36,6 +37,7 @@ import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotInventory; import com.intellectualcrafters.plot.object.PlotInventory;
import com.intellectualcrafters.plot.object.PlotItemStack; import com.intellectualcrafters.plot.object.PlotItemStack;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.StringMan;

View File

@ -25,6 +25,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.ConfigurationNode; import com.intellectualcrafters.plot.config.ConfigurationNode;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
@ -220,7 +221,11 @@ public class Setup extends SubCommand {
return false; return false;
} }
if (BlockManager.manager.isWorld(args[0])) { if (BlockManager.manager.isWorld(args[0])) {
MainUtil.sendMessage(plr, "&cThat world name is already taken!"); if (PS.get().isPlotWorld(args[0])) {
MainUtil.sendMessage(plr, "&cThat world name is already taken!");
return false;
}
MainUtil.sendMessage(plr, "&cThe world you specified already exists. After restarting, new terrain will use PlotSquared, however you may need to reset the world for it to generate correctly!");
} }
object.world = args[0]; object.world = args[0];
SetupUtils.setupMap.remove(name); SetupUtils.setupMap.remove(name);

View File

@ -197,7 +197,7 @@ public enum C {
SETUP_STEP("$3[$1Step %s0$3] $1%s1 $2- $1Expecting: $2%s2 $1Default: $2%s3", "Setup"), SETUP_STEP("$3[$1Step %s0$3] $1%s1 $2- $1Expecting: $2%s2 $1Default: $2%s3", "Setup"),
SETUP_INVALID_ARG("$2%s0 is not a valid argument for step %s1. To cancel setup use: $1/plot setup cancel", "Setup"), SETUP_INVALID_ARG("$2%s0 is not a valid argument for step %s1. To cancel setup use: $1/plot setup cancel", "Setup"),
SETUP_VALID_ARG("$2Value $1%s0 $2set to %s1", "Setup"), SETUP_VALID_ARG("$2Value $1%s0 $2set to %s1", "Setup"),
SETUP_FINISHED("$3If you are using MULTIVERSE or MULTIWORLD the world should have just been created. Otherwise you will need to add the world manually through the bukkit.yml", "Setup"), SETUP_FINISHED("$4You should have been teleported to the created world. Otherwise you will need to set the generator manually using the bukkit.yml or your chosen world management plugin.", "Setup"),
SETUP_WORLD_TAKEN("$2%s is already a registered plotworld", "Setup"), SETUP_WORLD_TAKEN("$2%s is already a registered plotworld", "Setup"),
SETUP_MISSING_WORLD("$2You need to specify a world name ($1/plot setup &l<world>$1 <generator>$2)&-$1Additional commands:&-$2 - $1/plot setup <value>&-$2 - $1/plot setup back&-$2 - $1/plot setup cancel", "Setup"), SETUP_MISSING_WORLD("$2You need to specify a world name ($1/plot setup &l<world>$1 <generator>$2)&-$1Additional commands:&-$2 - $1/plot setup <value>&-$2 - $1/plot setup back&-$2 - $1/plot setup cancel", "Setup"),
SETUP_MISSING_GENERATOR("$2You need to specify a generator ($1/plot setup <world> &l<generator>&r$2)&-$1Additional commands:&-$2 - $1/plot setup <value>&-$2 - $1/plot setup back&-$2 - $1/plot setup cancel", "Setup"), SETUP_MISSING_GENERATOR("$2You need to specify a generator ($1/plot setup <world> &l<generator>&r$2)&-$1Additional commands:&-$2 - $1/plot setup <value>&-$2 - $1/plot setup back&-$2 - $1/plot setup cancel", "Setup"),

View File

@ -81,23 +81,12 @@ public class SQLManager implements AbstractDB {
public SQLManager(final Connection c, final String p) { public SQLManager(final Connection c, final String p) {
// Private final // Private final
this.connection = c; this.connection = c;
try { TaskManager.runTaskRepeat(new Runnable() {
if (this.connection.getAutoCommit()) { @Override
this.connection.setAutoCommit(false); public void run() {
commit();
} }
TaskManager.runTaskRepeat(new Runnable() { }, 200);
@Override
public void run() {
try {
SQLManager.this.connection.commit();
} catch (SQLException e) {
e.printStackTrace();
}
}
}, 200);
} catch (SQLException e) {
e.printStackTrace();
}
this.prefix = p; this.prefix = p;
// Set timout // Set timout
// setTimout(); // setTimout();
@ -671,6 +660,9 @@ public class SQLManager implements AbstractDB {
public void commit() { public void commit() {
try { try {
if (this.connection.getAutoCommit()) {
this.connection.setAutoCommit(false);
}
this.connection.commit(); this.connection.commit();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -53,16 +53,16 @@ public abstract class SquarePlotManager extends GridPlotManager {
int idx; int idx;
int idz; int idz;
if (x < 0) { if (x < 0) {
idx = ((x - 1)/size); idx = (x/size);
x = size + ((x - 1) % size); x = size + (x % size);
} }
else { else {
idx = (x/size) + 1; idx = (x/size) + 1;
x = (x % size); x = (x % size);
} }
if (z < 0) { if (z < 0) {
idz = ((z - 1)/size); idz = (z/size);
z = size + ((z - 1) % size); z = size + (z % size);
} }
else { else {
idz = (z/size) + 1; idz = (z/size) + 1;
@ -104,16 +104,16 @@ public abstract class SquarePlotManager extends GridPlotManager {
int rx; int rx;
int rz; int rz;
if (x < 0) { if (x < 0) {
dx = ((x - 1) / size); dx = (x / size);
rx = size + ((x - 1) % size); rx = size + (x % size);
} }
else { else {
dx = (x/size) + 1; dx = (x/size) + 1;
rx = (x % size); rx = (x % size);
} }
if (z < 0) { if (z < 0) {
dz = ((z - 1)/size); dz = (z/size);
rz = size + ((z - 1) % size); rz = size + (z % size);
} }
else { else {
dz = (z/size) + 1; dz = (z/size) + 1;

View File

@ -32,6 +32,10 @@ public class MathMan {
}; };
} }
public static int roundInt(double value) {
return (int) (value < 0 ? value - 1 : value);
}
/** /**
* Returns [ pitch, yaw ] * Returns [ pitch, yaw ]
* @param x * @param x

View File

@ -19,16 +19,19 @@ import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import com.intellectualcrafters.configuration.ConfigurationSection;
import com.intellectualcrafters.plot.IPlotMain; import com.intellectualcrafters.plot.IPlotMain;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.commands.MainCommand; import com.intellectualcrafters.plot.commands.MainCommand;
import com.intellectualcrafters.plot.commands.WE_Anywhere; import com.intellectualcrafters.plot.commands.WE_Anywhere;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.ConfigurationNode;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.generator.HybridUtils; import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.SetupObject;
import com.intellectualcrafters.plot.util.AbstractTitle; import com.intellectualcrafters.plot.util.AbstractTitle;
import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.BlockUpdateUtil; import com.intellectualcrafters.plot.util.BlockUpdateUtil;
@ -547,9 +550,40 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
} }
@Override @Override
public void setGenerator(String world) { public void setGenerator(String worldname) {
World world = BukkitUtil.getWorld(worldname);
if (world == null) {
// create world
System.out.print("CREATING WORLD: " + worldname);
System.out.print("CREATING WORLD: " + worldname);
System.out.print("CREATING WORLD: " + worldname);
System.out.print("CREATING WORLD: " + worldname);
ConfigurationSection worldConfig = PS.get().config.getConfigurationSection("worlds." + worldname);
String manager = worldConfig.getString("generator.plugin");
if (manager == null) {
manager = "PlotSquared";
}
String generator = worldConfig.getString("generator.init");
if (generator == null) {
generator = manager;
}
int type = worldConfig.getInt("generator.type");
int terrain = worldConfig.getInt("generator.terrain");
SetupObject setup = new SetupObject();
setup.plotManager = manager;
setup.setupGenerator = generator;
setup.type = type;
setup.terrain = terrain;
setup.step = new ConfigurationNode[0];
setup.world = worldname;
SetupUtils.manager.setupWorld(setup);
return;
}
try { try {
SetGenCB.setGenerator(BukkitUtil.getWorld(world)); SetGenCB.setGenerator(BukkitUtil.getWorld(worldname));
} catch (Exception e) { } catch (Exception e) {
log("Failed to reload world: " + world); log("Failed to reload world: " + world);
Bukkit.getServer().unloadWorld(world, false); Bukkit.getServer().unloadWorld(world, false);

View File

@ -99,7 +99,6 @@ public class AugmentedPopulator extends BlockPopulator {
public void populate(final World world, final Random rand, final Chunk chunk) { public void populate(final World world, final Random rand, final Chunk chunk) {
final int cx = chunk.getX(); final int cx = chunk.getX();
final int cz = chunk.getZ(); final int cz = chunk.getZ();
PS.log("== POPULATING FOR: " + world + " | " + cx + "," + cz);
final int bx = cx << 4; final int bx = cx << 4;
final int bz = cz << 4; final int bz = cz << 4;
final int tx = bx + 15; final int tx = bx + 15;

View File

@ -134,6 +134,7 @@ import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.ExpireManager; import com.intellectualcrafters.plot.util.ExpireManager;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.RegExUtil; import com.intellectualcrafters.plot.util.RegExUtil;
import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.StringMan;
@ -480,16 +481,12 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
plotEntry(pp, plot); plotEntry(pp, plot);
} }
public int getInt(double value) {
return (int) (value < 0 ? value - 1 : value);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void PlayerMove(final PlayerMoveEvent event) { public void PlayerMove(final PlayerMoveEvent event) {
org.bukkit.Location from = event.getFrom(); org.bukkit.Location from = event.getFrom();
org.bukkit.Location to = event.getTo(); org.bukkit.Location to = event.getTo();
int x2; int x2;
if (getInt(from.getX()) != (x2 = getInt(to.getX()))) { if (MathMan.roundInt(from.getX()) != (x2 = MathMan.roundInt(to.getX()))) {
Player player = event.getPlayer(); Player player = event.getPlayer();
PlotPlayer pp = BukkitUtil.getPlayer(player); PlotPlayer pp = BukkitUtil.getPlayer(player);
@ -502,7 +499,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
return; return;
} }
PlotManager plotManager = PS.get().getPlotManager(worldname); PlotManager plotManager = PS.get().getPlotManager(worldname);
PlotId id = plotManager.getPlotId(plotworld, x2, 0, getInt(to.getZ())); PlotId id = plotManager.getPlotId(plotworld, x2, 0, MathMan.roundInt(to.getZ()));
Plot lastPlot = (Plot) pp.getMeta("lastplot"); Plot lastPlot = (Plot) pp.getMeta("lastplot");
if (id == null) { if (id == null) {
if (lastPlot != null && !plotExit(pp, lastPlot)) { if (lastPlot != null && !plotExit(pp, lastPlot)) {
@ -552,7 +549,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
return; return;
} }
int z2; int z2;
if (getInt(from.getZ()) != (z2 = getInt(to.getZ())) ) { if (MathMan.roundInt(from.getZ()) != (z2 = MathMan.roundInt(to.getZ())) ) {
Player player = event.getPlayer(); Player player = event.getPlayer();
PlotPlayer pp = BukkitUtil.getPlayer(player); PlotPlayer pp = BukkitUtil.getPlayer(player);
@ -1405,7 +1402,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
final org.bukkit.Location to = event.getTo(); final org.bukkit.Location to = event.getTo();
int x2; int x2;
if (getInt(from.getX()) != (x2 = getInt(to.getX()))) { if (MathMan.roundInt(from.getX()) != (x2 = MathMan.roundInt(to.getX()))) {
Player player = event.getPlayer(); Player player = event.getPlayer();
PlotPlayer pp = BukkitUtil.getPlayer(player); PlotPlayer pp = BukkitUtil.getPlayer(player);
@ -1418,7 +1415,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
return; return;
} }
PlotManager plotManager = PS.get().getPlotManager(worldname); PlotManager plotManager = PS.get().getPlotManager(worldname);
PlotId id = plotManager.getPlotId(plotworld, x2, 0, getInt(to.getZ())); PlotId id = plotManager.getPlotId(plotworld, x2, 0, MathMan.roundInt(to.getZ()));
Plot lastPlot = (Plot) pp.getMeta("lastplot"); Plot lastPlot = (Plot) pp.getMeta("lastplot");
if (id == null) { if (id == null) {
if (lastPlot == null) { if (lastPlot == null) {
@ -1471,7 +1468,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
return; return;
} }
int z2; int z2;
if (getInt(from.getZ()) != (z2 = getInt(to.getZ())) ) { if (MathMan.roundInt(from.getZ()) != (z2 = MathMan.roundInt(to.getZ())) ) {
Player player = event.getPlayer(); Player player = event.getPlayer();
PlotPlayer pp = BukkitUtil.getPlayer(player); PlotPlayer pp = BukkitUtil.getPlayer(player);

View File

@ -1,5 +1,6 @@
package com.plotsquared.bukkit.util; package com.plotsquared.bukkit.util;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -10,6 +11,7 @@ import org.bukkit.WorldCreator;
import org.bukkit.generator.ChunkGenerator; import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
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.PlotGenerator; import com.intellectualcrafters.plot.generator.PlotGenerator;
@ -69,14 +71,17 @@ public class BukkitSetupUtils extends SetupUtils {
if (object.setupGenerator != null) { if (object.setupGenerator != null) {
if ((Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) && Bukkit.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) { if ((Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) && Bukkit.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) {
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv create " + world + " normal -g " + object.setupGenerator); Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv create " + world + " normal -g " + object.setupGenerator);
setGenerator(world, object.setupGenerator);
} else { } else {
if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null) && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) { if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null) && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) {
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + world + " plugin:" + object.setupGenerator); Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + world + " plugin:" + object.setupGenerator);
setGenerator(world, object.setupGenerator);
} else { } else {
final WorldCreator wc = new WorldCreator(object.world); final WorldCreator wc = new WorldCreator(object.world);
wc.generator(object.setupGenerator); wc.generator(object.setupGenerator);
wc.environment(Environment.NORMAL); wc.environment(Environment.NORMAL);
Bukkit.createWorld(wc); Bukkit.createWorld(wc);
setGenerator(world, object.setupGenerator);
} }
} }
} else { } else {
@ -93,6 +98,21 @@ public class BukkitSetupUtils extends SetupUtils {
return object.world; return object.world;
} }
public void setGenerator(String world, String generator) {
if (Bukkit.getWorlds().size() == 0 || !Bukkit.getWorlds().get(0).getName().equals(world)) {
return;
}
File file = new File("bukkit.yml").getAbsoluteFile();
System.out.print(file.getAbsolutePath());
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(PlotWorld plotworld) { public String getGenerator(PlotWorld plotworld) {
if (SetupUtils.generators.size() == 0) { if (SetupUtils.generators.size() == 0) {

View File

@ -137,7 +137,7 @@ public class BukkitUtil extends BlockManager {
} }
public static Location getLocation(final org.bukkit.Location loc) { public static Location getLocation(final org.bukkit.Location loc) {
return new Location(loc.getWorld().getName(), (int) loc.getX(), (int) loc.getY(), (int) loc.getZ()); return new Location(loc.getWorld().getName(), MathMan.roundInt(loc.getX()), MathMan.roundInt(loc.getY()), MathMan.roundInt(loc.getZ()));
} }
public static org.bukkit.Location getLocation(final Location loc) { public static org.bukkit.Location getLocation(final Location loc) {
@ -172,7 +172,7 @@ public class BukkitUtil extends BlockManager {
public static Location getLocationFull(final Entity entity) { public static Location getLocationFull(final Entity entity) {
org.bukkit.Location loc = entity.getLocation(); org.bukkit.Location loc = entity.getLocation();
return new Location(loc.getWorld().getName(), (int) loc.getX(), (int) loc.getY(), (int) loc.getZ(), loc.getYaw(), loc.getPitch()); return new Location(loc.getWorld().getName(), MathMan.roundInt(loc.getX()), MathMan.roundInt(loc.getY()), MathMan.roundInt(loc.getZ()), loc.getYaw(), loc.getPitch());
} }
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////

View File

@ -64,7 +64,6 @@ public class SendChunk {
if (!chunk.isLoaded()) { if (!chunk.isLoaded()) {
continue; continue;
} }
boolean unload = true;
final Object c = methodGetHandle.of(chunk).call(); final Object c = methodGetHandle.of(chunk).call();
final Object w = world.of(c).get(); final Object w = world.of(c).get();
final Object p = players.of(w).get(); final Object p = players.of(w).get();
@ -74,7 +73,6 @@ public class SendChunk {
diffx = Math.abs(x - (chunk.getX() << 4)); diffx = Math.abs(x - (chunk.getX() << 4));
diffz = Math.abs(z - (chunk.getZ() << 4)); diffz = Math.abs(z - (chunk.getZ() << 4));
if ((diffx <= view) && (diffz <= view)) { if ((diffx <= view) && (diffz <= view)) {
unload = false;
if (v1_7_10) { if (v1_7_10) {
chunk.getWorld().refreshChunk(chunk.getX(), chunk.getZ()); chunk.getWorld().refreshChunk(chunk.getX(), chunk.getZ());
chunk.load(true); chunk.load(true);
@ -86,9 +84,6 @@ public class SendChunk {
} }
} }
} }
if (unload) {
chunk.unload(true, true);
}
} }
} }