mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 22:56:45 +01:00
Fixes #524
This commit is contained in:
parent
051449157a
commit
e28c68ee74
@ -254,13 +254,29 @@ public class PS {
|
||||
}
|
||||
|
||||
// World generators:
|
||||
ConfigurationSection section = config.getConfigurationSection("worlds");
|
||||
final ConfigurationSection section = config.getConfigurationSection("worlds");
|
||||
if (section != null) {
|
||||
for (String world : section.getKeys(false)) {
|
||||
if (world.equals("CheckingPlotSquaredGenerator")) {
|
||||
continue;
|
||||
}
|
||||
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
|
||||
|
@ -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
|
||||
|
@ -25,6 +25,7 @@ import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
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.PlotItemStack;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.StringMan;
|
||||
|
@ -25,6 +25,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.ConfigurationNode;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
@ -220,7 +221,11 @@ public class Setup extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
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];
|
||||
SetupUtils.setupMap.remove(name);
|
||||
|
@ -197,7 +197,7 @@ public enum C {
|
||||
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_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_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"),
|
||||
|
@ -81,23 +81,12 @@ public class SQLManager implements AbstractDB {
|
||||
public SQLManager(final Connection c, final String p) {
|
||||
// Private final
|
||||
this.connection = c;
|
||||
try {
|
||||
if (this.connection.getAutoCommit()) {
|
||||
this.connection.setAutoCommit(false);
|
||||
TaskManager.runTaskRepeat(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
commit();
|
||||
}
|
||||
TaskManager.runTaskRepeat(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
SQLManager.this.connection.commit();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, 200);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}, 200);
|
||||
this.prefix = p;
|
||||
// Set timout
|
||||
// setTimout();
|
||||
@ -671,6 +660,9 @@ public class SQLManager implements AbstractDB {
|
||||
|
||||
public void commit() {
|
||||
try {
|
||||
if (this.connection.getAutoCommit()) {
|
||||
this.connection.setAutoCommit(false);
|
||||
}
|
||||
this.connection.commit();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -53,16 +53,16 @@ public abstract class SquarePlotManager extends GridPlotManager {
|
||||
int idx;
|
||||
int idz;
|
||||
if (x < 0) {
|
||||
idx = ((x - 1)/size);
|
||||
x = size + ((x - 1) % size);
|
||||
idx = (x/size);
|
||||
x = size + (x % size);
|
||||
}
|
||||
else {
|
||||
idx = (x/size) + 1;
|
||||
x = (x % size);
|
||||
}
|
||||
if (z < 0) {
|
||||
idz = ((z - 1)/size);
|
||||
z = size + ((z - 1) % size);
|
||||
idz = (z/size);
|
||||
z = size + (z % size);
|
||||
}
|
||||
else {
|
||||
idz = (z/size) + 1;
|
||||
@ -104,16 +104,16 @@ public abstract class SquarePlotManager extends GridPlotManager {
|
||||
int rx;
|
||||
int rz;
|
||||
if (x < 0) {
|
||||
dx = ((x - 1) / size);
|
||||
rx = size + ((x - 1) % size);
|
||||
dx = (x / size);
|
||||
rx = size + (x % size);
|
||||
}
|
||||
else {
|
||||
dx = (x/size) + 1;
|
||||
rx = (x % size);
|
||||
}
|
||||
if (z < 0) {
|
||||
dz = ((z - 1)/size);
|
||||
rz = size + ((z - 1) % size);
|
||||
dz = (z/size);
|
||||
rz = size + (z % size);
|
||||
}
|
||||
else {
|
||||
dz = (z/size) + 1;
|
||||
|
@ -32,6 +32,10 @@ public class MathMan {
|
||||
};
|
||||
}
|
||||
|
||||
public static int roundInt(double value) {
|
||||
return (int) (value < 0 ? value - 1 : value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns [ pitch, yaw ]
|
||||
* @param x
|
||||
|
@ -19,16 +19,19 @@ import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.intellectualcrafters.configuration.ConfigurationSection;
|
||||
import com.intellectualcrafters.plot.IPlotMain;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.commands.MainCommand;
|
||||
import com.intellectualcrafters.plot.commands.WE_Anywhere;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.ConfigurationNode;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.object.SetupObject;
|
||||
import com.intellectualcrafters.plot.util.AbstractTitle;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.BlockUpdateUtil;
|
||||
@ -547,9 +550,40 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||
}
|
||||
|
||||
@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 {
|
||||
SetGenCB.setGenerator(BukkitUtil.getWorld(world));
|
||||
SetGenCB.setGenerator(BukkitUtil.getWorld(worldname));
|
||||
} catch (Exception e) {
|
||||
log("Failed to reload world: " + world);
|
||||
Bukkit.getServer().unloadWorld(world, false);
|
||||
|
@ -99,7 +99,6 @@ public class AugmentedPopulator extends BlockPopulator {
|
||||
public void populate(final World world, final Random rand, final Chunk chunk) {
|
||||
final int cx = chunk.getX();
|
||||
final int cz = chunk.getZ();
|
||||
PS.log("== POPULATING FOR: " + world + " | " + cx + "," + cz);
|
||||
final int bx = cx << 4;
|
||||
final int bz = cz << 4;
|
||||
final int tx = bx + 15;
|
||||
|
@ -134,6 +134,7 @@ import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.EventUtil;
|
||||
import com.intellectualcrafters.plot.util.ExpireManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.MathMan;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.RegExUtil;
|
||||
import com.intellectualcrafters.plot.util.StringMan;
|
||||
@ -480,16 +481,12 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
|
||||
plotEntry(pp, plot);
|
||||
}
|
||||
|
||||
public int getInt(double value) {
|
||||
return (int) (value < 0 ? value - 1 : value);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void PlayerMove(final PlayerMoveEvent event) {
|
||||
org.bukkit.Location from = event.getFrom();
|
||||
org.bukkit.Location to = event.getTo();
|
||||
int x2;
|
||||
if (getInt(from.getX()) != (x2 = getInt(to.getX()))) {
|
||||
if (MathMan.roundInt(from.getX()) != (x2 = MathMan.roundInt(to.getX()))) {
|
||||
Player player = event.getPlayer();
|
||||
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
|
||||
@ -502,7 +499,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
|
||||
return;
|
||||
}
|
||||
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");
|
||||
if (id == null) {
|
||||
if (lastPlot != null && !plotExit(pp, lastPlot)) {
|
||||
@ -552,7 +549,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
|
||||
return;
|
||||
}
|
||||
int z2;
|
||||
if (getInt(from.getZ()) != (z2 = getInt(to.getZ())) ) {
|
||||
if (MathMan.roundInt(from.getZ()) != (z2 = MathMan.roundInt(to.getZ())) ) {
|
||||
Player player = event.getPlayer();
|
||||
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();
|
||||
|
||||
int x2;
|
||||
if (getInt(from.getX()) != (x2 = getInt(to.getX()))) {
|
||||
if (MathMan.roundInt(from.getX()) != (x2 = MathMan.roundInt(to.getX()))) {
|
||||
Player player = event.getPlayer();
|
||||
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
|
||||
@ -1418,7 +1415,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
|
||||
return;
|
||||
}
|
||||
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");
|
||||
if (id == null) {
|
||||
if (lastPlot == null) {
|
||||
@ -1471,7 +1468,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
|
||||
return;
|
||||
}
|
||||
int z2;
|
||||
if (getInt(from.getZ()) != (z2 = getInt(to.getZ())) ) {
|
||||
if (MathMan.roundInt(from.getZ()) != (z2 = MathMan.roundInt(to.getZ())) ) {
|
||||
Player player = event.getPlayer();
|
||||
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.plotsquared.bukkit.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
@ -10,6 +11,7 @@ import org.bukkit.WorldCreator;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.intellectualcrafters.configuration.file.YamlConfiguration;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.ConfigurationNode;
|
||||
import com.intellectualcrafters.plot.generator.PlotGenerator;
|
||||
@ -69,14 +71,17 @@ public class BukkitSetupUtils extends SetupUtils {
|
||||
if (object.setupGenerator != null) {
|
||||
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);
|
||||
setGenerator(world, object.setupGenerator);
|
||||
} else {
|
||||
if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null) && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) {
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + world + " plugin:" + object.setupGenerator);
|
||||
setGenerator(world, object.setupGenerator);
|
||||
} else {
|
||||
final WorldCreator wc = new WorldCreator(object.world);
|
||||
wc.generator(object.setupGenerator);
|
||||
wc.environment(Environment.NORMAL);
|
||||
Bukkit.createWorld(wc);
|
||||
setGenerator(world, object.setupGenerator);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -92,6 +97,21 @@ public class BukkitSetupUtils extends SetupUtils {
|
||||
}
|
||||
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
|
||||
public String getGenerator(PlotWorld plotworld) {
|
||||
|
@ -137,7 +137,7 @@ public class BukkitUtil extends BlockManager {
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -172,7 +172,7 @@ public class BukkitUtil extends BlockManager {
|
||||
|
||||
public static Location getLocationFull(final Entity entity) {
|
||||
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());
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -64,7 +64,6 @@ public class SendChunk {
|
||||
if (!chunk.isLoaded()) {
|
||||
continue;
|
||||
}
|
||||
boolean unload = true;
|
||||
final Object c = methodGetHandle.of(chunk).call();
|
||||
final Object w = world.of(c).get();
|
||||
final Object p = players.of(w).get();
|
||||
@ -74,7 +73,6 @@ public class SendChunk {
|
||||
diffx = Math.abs(x - (chunk.getX() << 4));
|
||||
diffz = Math.abs(z - (chunk.getZ() << 4));
|
||||
if ((diffx <= view) && (diffz <= view)) {
|
||||
unload = false;
|
||||
if (v1_7_10) {
|
||||
chunk.getWorld().refreshChunk(chunk.getX(), chunk.getZ());
|
||||
chunk.load(true);
|
||||
@ -86,9 +84,6 @@ public class SendChunk {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (unload) {
|
||||
chunk.unload(true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user