mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-12-01 13:23:56 +01:00
Tweaks
Use sign with plot schematic Tweak world unloading
This commit is contained in:
parent
2360782234
commit
92f94ecedc
@ -200,7 +200,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
public void run() {
|
public void run() {
|
||||||
unload();
|
unload();
|
||||||
}
|
}
|
||||||
}, 20);
|
}, 5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,19 +211,26 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
SinglePlotArea area = ((SinglePlotAreaManager) manager).getArea();
|
SinglePlotArea area = ((SinglePlotAreaManager) manager).getArea();
|
||||||
for (World world : Bukkit.getWorlds()) {
|
for (World world : Bukkit.getWorlds()) {
|
||||||
String name = world.getName();
|
String name = world.getName();
|
||||||
|
char char0 = name.charAt(0);
|
||||||
|
if (!Character.isDigit(char0) && char0 != '-') continue;
|
||||||
|
if (!world.getPlayers().isEmpty()) continue;
|
||||||
|
|
||||||
PlotId id = PlotId.fromString(name);
|
PlotId id = PlotId.fromString(name);
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
Plot plot = area.getOwnedPlot(id);
|
Plot plot = area.getOwnedPlot(id);
|
||||||
if (plot != null) {
|
if (plot != null) {
|
||||||
List<PlotPlayer> players = plot.getPlayersInPlot();
|
if (PlotPlayer.wrap(plot.owner) == null) {
|
||||||
if (players.isEmpty() && PlotPlayer.wrap(plot.owner) == null) {
|
if (world.getKeepSpawnInMemory()) {
|
||||||
for (Chunk chunk : world.getLoadedChunks()) {
|
world.setKeepSpawnInMemory(false);
|
||||||
if (!chunk.unload(true, false)) return;
|
|
||||||
if (System.currentTimeMillis() - start > 20) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Chunk[] chunks = world.getLoadedChunks();
|
||||||
|
if (chunks.length == 0) {
|
||||||
|
if (!Bukkit.unloadWorld(world, true)) {
|
||||||
|
PS.debug("Failed to unload " + world.getName());
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
Bukkit.unloadWorld(world, true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,15 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
World world = getWorld(worldName);
|
World world = getWorld(worldName);
|
||||||
Block block = world.getBlockAt(x, y, z);
|
Block block = world.getBlockAt(x, y, z);
|
||||||
// block.setType(Material.AIR);
|
// block.setType(Material.AIR);
|
||||||
block.setTypeIdAndData(Material.WALL_SIGN.getId(), (byte) 2, false);
|
Material type = block.getType();
|
||||||
|
if (type != Material.SIGN && type != Material.SIGN_POST) {
|
||||||
|
int data = 2;
|
||||||
|
if (world.getBlockAt(x, y, z + 1).getType().isSolid()) data = 2;
|
||||||
|
else if (world.getBlockAt(x + 1, y, z).getType().isSolid()) data = 4;
|
||||||
|
else if (world.getBlockAt(x, y, z - 1).getType().isSolid()) data = 3;
|
||||||
|
else if (world.getBlockAt(x - 1, y, z).getType().isSolid()) data = 5;
|
||||||
|
block.setTypeIdAndData(Material.WALL_SIGN.getId(), (byte) data, false);
|
||||||
|
}
|
||||||
BlockState blockstate = block.getState();
|
BlockState blockstate = block.getState();
|
||||||
if (blockstate instanceof Sign) {
|
if (blockstate instanceof Sign) {
|
||||||
final Sign sign = (Sign) blockstate;
|
final Sign sign = (Sign) blockstate;
|
||||||
|
@ -214,11 +214,15 @@ public class HybridGen extends IndependentPlotGenerator {
|
|||||||
if (queue == null) {
|
if (queue == null) {
|
||||||
queue = GlobalBlockQueue.IMP.getNewQueue(hpw.worldname, false);
|
queue = GlobalBlockQueue.IMP.getNewQueue(hpw.worldname, false);
|
||||||
}
|
}
|
||||||
SchematicHandler.manager.restoreTile(queue, entry.getValue(), p1x + x, entry.getKey(), p1z + z);
|
CompoundTag tag = entry.getValue();
|
||||||
|
SchematicHandler.manager.restoreTile(queue, tag, p1x + x, entry.getKey(), p1z + z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (queue != null) {
|
||||||
|
queue.flush();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -208,4 +208,13 @@ public class HybridPlotManager extends ClassicPlotManager {
|
|||||||
}
|
}
|
||||||
createSchemAbs(plotWorld, queue, l1, l2, false);
|
createSchemAbs(plotWorld, queue, l1, l2, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove sign for a plot.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Location getSignLoc(PlotArea plotArea, Plot plot) {
|
||||||
|
HybridPlotWorld dpw = (HybridPlotWorld) plotArea;
|
||||||
|
return dpw.getSignLocation(plot);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,18 +2,21 @@ package com.intellectualcrafters.plot.generator;
|
|||||||
|
|
||||||
import com.intellectualcrafters.configuration.ConfigurationSection;
|
import com.intellectualcrafters.configuration.ConfigurationSection;
|
||||||
import com.intellectualcrafters.jnbt.CompoundTag;
|
import com.intellectualcrafters.jnbt.CompoundTag;
|
||||||
|
import com.intellectualcrafters.jnbt.Tag;
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.intellectualcrafters.plot.PS;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.object.BlockLoc;
|
import com.intellectualcrafters.plot.object.BlockLoc;
|
||||||
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotArea;
|
import com.intellectualcrafters.plot.object.PlotArea;
|
||||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
import com.intellectualcrafters.plot.util.MainUtil;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
import com.intellectualcrafters.plot.util.MathMan;
|
import com.intellectualcrafters.plot.util.MathMan;
|
||||||
|
import com.intellectualcrafters.plot.util.ReflectionUtils;
|
||||||
import com.intellectualcrafters.plot.util.SchematicHandler;
|
import com.intellectualcrafters.plot.util.SchematicHandler;
|
||||||
import com.intellectualcrafters.plot.util.SchematicHandler.Dimension;
|
import com.intellectualcrafters.plot.util.SchematicHandler.Dimension;
|
||||||
import com.intellectualcrafters.plot.util.SchematicHandler.Schematic;
|
import com.intellectualcrafters.plot.util.SchematicHandler.Schematic;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -26,6 +29,7 @@ public class HybridPlotWorld extends ClassicPlotWorld {
|
|||||||
public short PATH_WIDTH_UPPER;
|
public short PATH_WIDTH_UPPER;
|
||||||
public HashMap<Integer, char[]> G_SCH;
|
public HashMap<Integer, char[]> G_SCH;
|
||||||
public HashMap<Integer, HashMap<Integer, CompoundTag>> G_SCH_STATE;
|
public HashMap<Integer, HashMap<Integer, CompoundTag>> G_SCH_STATE;
|
||||||
|
private Location SIGN_LOCATION;
|
||||||
|
|
||||||
public HybridPlotWorld(String worldName, String id, IndependentPlotGenerator generator, PlotId min, PlotId max) {
|
public HybridPlotWorld(String worldName, String id, IndependentPlotGenerator generator, PlotId min, PlotId max) {
|
||||||
super(worldName, id, generator, min, max);
|
super(worldName, id, generator, min, max);
|
||||||
@ -45,6 +49,19 @@ public class HybridPlotWorld extends ClassicPlotWorld {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Location getSignLocation(Plot plot) {
|
||||||
|
plot = plot.getBasePlot(false);
|
||||||
|
Location bot = plot.getBottomAbs();
|
||||||
|
if (SIGN_LOCATION == null) {
|
||||||
|
bot.setY(ROAD_HEIGHT + 1);
|
||||||
|
return bot.add(-1, ROAD_HEIGHT, -2);
|
||||||
|
} else {
|
||||||
|
bot.setY(0);
|
||||||
|
Location loc = bot.add(SIGN_LOCATION.getX(), SIGN_LOCATION.getY(), SIGN_LOCATION.getZ());
|
||||||
|
return loc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME depends on block ids
|
// FIXME depends on block ids
|
||||||
// Possibly make abstract?
|
// Possibly make abstract?
|
||||||
public static byte rotate(short id, byte data) {
|
public static byte rotate(short id, byte data) {
|
||||||
@ -228,6 +245,7 @@ public class HybridPlotWorld extends ClassicPlotWorld {
|
|||||||
HashMap<BlockLoc, CompoundTag> items = schematic3.getTiles();
|
HashMap<BlockLoc, CompoundTag> items = schematic3.getTiles();
|
||||||
if (!items.isEmpty()) {
|
if (!items.isEmpty()) {
|
||||||
this.G_SCH_STATE = new HashMap<>();
|
this.G_SCH_STATE = new HashMap<>();
|
||||||
|
outer:
|
||||||
for (Map.Entry<BlockLoc, CompoundTag> entry : items.entrySet()) {
|
for (Map.Entry<BlockLoc, CompoundTag> entry : items.entrySet()) {
|
||||||
BlockLoc loc = entry.getKey();
|
BlockLoc loc = entry.getKey();
|
||||||
short x = (short) (loc.x + shift + oddshift + centerShiftX);
|
short x = (short) (loc.x + shift + oddshift + centerShiftX);
|
||||||
@ -240,6 +258,16 @@ public class HybridPlotWorld extends ClassicPlotWorld {
|
|||||||
this.G_SCH_STATE.put(pair, existing);
|
this.G_SCH_STATE.put(pair, existing);
|
||||||
}
|
}
|
||||||
existing.put((int) y, entry.getValue());
|
existing.put((int) y, entry.getValue());
|
||||||
|
|
||||||
|
CompoundTag tag = entry.getValue();
|
||||||
|
Map<String, Tag> map = ReflectionUtils.getMap(tag.getValue());
|
||||||
|
for (int i = 1; i <= 4; i++) {
|
||||||
|
String ln = tag.getString("Line" + i);
|
||||||
|
if (ln == null || ln.length() > 11) continue outer;
|
||||||
|
}
|
||||||
|
SIGN_LOCATION = new Location(worldname, loc.x + centerShiftX, this.PLOT_HEIGHT + loc.y, loc.z + centerShiftZ);
|
||||||
|
ALLOW_SIGNS = true;
|
||||||
|
continue outer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,6 +96,30 @@ public abstract class SquarePlotManager extends GridPlotManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PlotId getNearestPlotId(PlotArea plotArea, int x, int y, int z) {
|
||||||
|
SquarePlotWorld dpw = (SquarePlotWorld) plotArea;
|
||||||
|
if (dpw.ROAD_OFFSET_X != 0) {
|
||||||
|
x -= dpw.ROAD_OFFSET_X;
|
||||||
|
}
|
||||||
|
if (dpw.ROAD_OFFSET_Z != 0) {
|
||||||
|
z -= dpw.ROAD_OFFSET_Z;
|
||||||
|
}
|
||||||
|
int size = dpw.PLOT_WIDTH + dpw.ROAD_WIDTH;
|
||||||
|
int idx;
|
||||||
|
if (x < 0) {
|
||||||
|
idx = x / size;
|
||||||
|
} else {
|
||||||
|
idx = (x / size) + 1;
|
||||||
|
}
|
||||||
|
int idz;
|
||||||
|
if (z < 0) {
|
||||||
|
idz = z / size;
|
||||||
|
} else {
|
||||||
|
idz = (z / size) + 1;
|
||||||
|
}
|
||||||
|
return new PlotId(idx, idz);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlotId getPlotId(PlotArea plotArea, int x, int y, int z) {
|
public PlotId getPlotId(PlotArea plotArea, int x, int y, int z) {
|
||||||
try {
|
try {
|
||||||
|
@ -182,6 +182,12 @@ public class MathMan {
|
|||||||
return new float[]{(float) (pitch_sin * Math.cos(yaw)), (float) (pitch_sin * Math.sin(yaw)), (float) Math.cos(pitch)};
|
return new float[]{(float) (pitch_sin * Math.cos(yaw)), (float) (pitch_sin * Math.sin(yaw)), (float) Math.cos(pitch)};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int floorMod(int x, int y) {
|
||||||
|
int i = x % y;
|
||||||
|
if (i < 0) i += y;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
public static int roundInt(double value) {
|
public static int roundInt(double value) {
|
||||||
return (int) (value < 0 ? (value == (int) value) ? value : value - 1 : value);
|
return (int) (value < 0 ? (value == (int) value) ? value : value - 1 : value);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user