Fixes #1534 + various

Auto world loading/unloading
Auto player teleporting on login
This commit is contained in:
Jesse Boyd 2017-04-04 07:59:36 +10:00
parent 3f54ba23c2
commit 022372e9b7
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
8 changed files with 224 additions and 6 deletions

View File

@ -12,12 +12,30 @@ import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.generator.IndependentPlotGenerator; import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.SetupObject; import com.intellectualcrafters.plot.object.SetupObject;
import com.intellectualcrafters.plot.object.chat.PlainChatManager; import com.intellectualcrafters.plot.object.chat.PlainChatManager;
import com.intellectualcrafters.plot.object.worlds.PlotAreaManager;
import com.intellectualcrafters.plot.object.worlds.SinglePlotArea;
import com.intellectualcrafters.plot.object.worlds.SinglePlotAreaManager;
import com.intellectualcrafters.plot.object.worlds.SingleWorldGenerator; import com.intellectualcrafters.plot.object.worlds.SingleWorldGenerator;
import com.intellectualcrafters.plot.util.*; import com.intellectualcrafters.plot.util.AbstractTitle;
import com.intellectualcrafters.plot.util.ChatManager;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.ConsoleColors;
import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.InventoryUtil;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.SetupUtils;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
import com.intellectualcrafters.plot.util.WorldUtil;
import com.intellectualcrafters.plot.util.block.QueueProvider; import com.intellectualcrafters.plot.util.block.QueueProvider;
import com.intellectualcrafters.plot.uuid.UUIDWrapper; import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import com.plotsquared.bukkit.database.plotme.ClassicPlotMeConnector; import com.plotsquared.bukkit.database.plotme.ClassicPlotMeConnector;
@ -33,7 +51,21 @@ import com.plotsquared.bukkit.listeners.PlayerEvents_1_9;
import com.plotsquared.bukkit.listeners.PlotPlusListener; import com.plotsquared.bukkit.listeners.PlotPlusListener;
import com.plotsquared.bukkit.listeners.WorldEvents; import com.plotsquared.bukkit.listeners.WorldEvents;
import com.plotsquared.bukkit.titles.DefaultTitle_111; import com.plotsquared.bukkit.titles.DefaultTitle_111;
import com.plotsquared.bukkit.util.*; import com.plotsquared.bukkit.util.BukkitChatManager;
import com.plotsquared.bukkit.util.BukkitChunkManager;
import com.plotsquared.bukkit.util.BukkitCommand;
import com.plotsquared.bukkit.util.BukkitEconHandler;
import com.plotsquared.bukkit.util.BukkitEventUtil;
import com.plotsquared.bukkit.util.BukkitHybridUtils;
import com.plotsquared.bukkit.util.BukkitInventoryUtil;
import com.plotsquared.bukkit.util.BukkitSchematicHandler;
import com.plotsquared.bukkit.util.BukkitSetupUtils;
import com.plotsquared.bukkit.util.BukkitTaskManager;
import com.plotsquared.bukkit.util.BukkitUtil;
import com.plotsquared.bukkit.util.BukkitVersion;
import com.plotsquared.bukkit.util.Metrics;
import com.plotsquared.bukkit.util.SendChunk;
import com.plotsquared.bukkit.util.SetGenCB;
import com.plotsquared.bukkit.util.block.BukkitLocalQueue; import com.plotsquared.bukkit.util.block.BukkitLocalQueue;
import com.plotsquared.bukkit.util.block.BukkitLocalQueue_1_7; import com.plotsquared.bukkit.util.block.BukkitLocalQueue_1_7;
import com.plotsquared.bukkit.util.block.BukkitLocalQueue_1_8; import com.plotsquared.bukkit.util.block.BukkitLocalQueue_1_8;
@ -56,6 +88,7 @@ import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Chunk;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.World; import org.bukkit.World;
@ -159,6 +192,41 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
} else { } else {
PS.log(C.CONSOLE_PLEASE_ENABLE_METRICS.f(getPluginName())); PS.log(C.CONSOLE_PLEASE_ENABLE_METRICS.f(getPluginName()));
} }
if (Settings.Enabled_Components.WORLDS) {
TaskManager.IMP.taskRepeat(new Runnable() {
@Override
public void run() {
unload();
}
}, 20);
}
}
public void unload() {
PlotAreaManager manager = PS.get().getPlotAreaManager();
if (manager instanceof SinglePlotAreaManager) {
long start = System.currentTimeMillis();
SinglePlotArea area = ((SinglePlotAreaManager) manager).getArea();
for (World world : Bukkit.getWorlds()) {
String name = world.getName();
PlotId id = PlotId.fromString(name);
if (id != null) {
Plot plot = area.getOwnedPlot(id);
if (plot != null) {
List<PlotPlayer> players = plot.getPlayersInPlot();
if (players.isEmpty() && PlotPlayer.wrap(plot.owner) == null) {
for (Chunk chunk : world.getLoadedChunks()) {
chunk.unload(true, false);
if (System.currentTimeMillis() - start > 20) {
return;
}
}
Bukkit.unloadWorld(world, false);
}
}
}
}
}
} }
@Override @Override

View File

@ -19,7 +19,7 @@ import java.util.UUID;
@CommandDeclaration( @CommandDeclaration(
command = "remove", command = "remove",
aliases = {"r","untrust", "ut", "undeny", "ud"}, aliases = {"r","untrust", "ut", "undeny", "unban", "ud"},
description = "Remove a player from a plot", description = "Remove a player from a plot",
usage = "/plot remove <player>", usage = "/plot remove <player>",
category = CommandCategory.SETTINGS, category = CommandCategory.SETTINGS,

View File

@ -1678,7 +1678,7 @@ public class Plot {
* @param uuid * @param uuid
*/ */
public boolean removeDenied(UUID uuid) { public boolean removeDenied(UUID uuid) {
if (uuid == DBFunc.everyone) { if (uuid == DBFunc.everyone && !denied.contains(uuid)) {
boolean result = false; boolean result = false;
for (UUID other : new HashSet<>(getDenied())) { for (UUID other : new HashSet<>(getDenied())) {
result = rmvDenied(other) || result; result = rmvDenied(other) || result;
@ -1705,7 +1705,7 @@ public class Plot {
* @param uuid * @param uuid
*/ */
public boolean removeTrusted(UUID uuid) { public boolean removeTrusted(UUID uuid) {
if (uuid == DBFunc.everyone) { if (uuid == DBFunc.everyone && !trusted.contains(uuid)) {
boolean result = false; boolean result = false;
for (UUID other : new HashSet<>(getTrusted())) { for (UUID other : new HashSet<>(getTrusted())) {
result = rmvTrusted(other) || result; result = rmvTrusted(other) || result;
@ -1735,7 +1735,7 @@ public class Plot {
if (this.members == null) { if (this.members == null) {
return false; return false;
} }
if (uuid == DBFunc.everyone) { if (uuid == DBFunc.everyone && !members.contains(uuid)) {
boolean result = false; boolean result = false;
for (UUID other : new HashSet<>(this.members)) { for (UUID other : new HashSet<>(this.members)) {
result = rmvMember(other) || result; result = rmvMember(other) || result;

View File

@ -5,14 +5,19 @@ import com.intellectualcrafters.plot.commands.RequiredType;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.Flags; import com.intellectualcrafters.plot.flag.Flags;
import com.intellectualcrafters.plot.object.worlds.PlotAreaManager;
import com.intellectualcrafters.plot.object.worlds.SinglePlotArea;
import com.intellectualcrafters.plot.object.worlds.SinglePlotAreaManager;
import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.PlotGameMode; import com.intellectualcrafters.plot.util.PlotGameMode;
import com.intellectualcrafters.plot.util.PlotWeather; import com.intellectualcrafters.plot.util.PlotWeather;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.util.expiry.ExpireManager; import com.intellectualcrafters.plot.util.expiry.ExpireManager;
import com.plotsquared.general.commands.CommandCaller; import com.plotsquared.general.commands.CommandCaller;
import java.nio.ByteBuffer;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
@ -401,6 +406,21 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
public void unregister() { public void unregister() {
Plot plot = getCurrentPlot(); Plot plot = getCurrentPlot();
if (plot != null) { if (plot != null) {
if (Settings.Enabled_Components.PERSISTENT_META) {
if (plot.getArea() instanceof SinglePlotArea) {
PlotId id = plot.getId();
int x = id.x;
int z = id.y;
ByteBuffer buffer = ByteBuffer.allocate(13);
buffer.putShort((short) x);
buffer.putShort((short) z);
Location loc = getLocation();
buffer.putInt(loc.getX());
buffer.put((byte) loc.getY());
buffer.putInt(loc.getZ());
setPersistentMeta("quitLoc", buffer.array());
}
}
EventUtil.manager.callLeave(this, plot); EventUtil.manager.callLeave(this, plot);
} }
if (Settings.Enabled_Components.BAN_DELETER && isBanned()) { if (Settings.Enabled_Components.BAN_DELETER && isBanned()) {
@ -470,6 +490,32 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
@Override @Override
public void run(Map<String, byte[]> value) { public void run(Map<String, byte[]> value) {
PlotPlayer.this.metaMap = value; PlotPlayer.this.metaMap = value;
if (!value.isEmpty()) {
if (Settings.Enabled_Components.PERSISTENT_META) {
PlotAreaManager manager = PS.get().getPlotAreaManager();
if (manager instanceof SinglePlotAreaManager) {
PlotArea area = ((SinglePlotAreaManager) manager).getArea();
byte[] arr = PlotPlayer.this.getPersistentMeta("quitLoc");
if (arr != null) {
ByteBuffer quitWorld = ByteBuffer.wrap(arr);
PlotId id = new PlotId(quitWorld.getShort(), quitWorld.getShort());
int x = quitWorld.getInt();
int y = quitWorld.get() & 0xFF;
int z = quitWorld.getInt();
Plot plot = area.getOwnedPlot(id);
if (plot != null && plot.isLoaded()) {
final Location loc = new Location(plot.getWorldName(), x, y, z);
TaskManager.IMP.sync(new RunnableVal<Object>() {
@Override
public void run(Object o) {
teleport(loc);
}
});
}
}
}
}
}
} }
}); });
} }

View File

@ -41,8 +41,20 @@ public class SinglePlotArea extends GridPlotWorld {
setup.step = new ConfigurationNode[0]; setup.step = new ConfigurationNode[0];
setup.world = worldName; setup.world = worldName;
SetupUtils.manager.setupWorld(setup); SetupUtils.manager.setupWorld(setup);
// String worldName = plot.getWorldName();
// World world = Bukkit.getWorld(worldName);
// if (world != null) {
// return world;
// }
// WorldCreator wc = new WorldCreator(worldName);
// wc.generator("PlotSquared:single");
// wc.environment(World.Environment.NORMAL);
// wc.type(WorldType.FLAT);
// return AsyncWorld.create(wc);
} }
@Override @Override
public ConfigurationNode[] getSettingNodes() { public ConfigurationNode[] getSettingNodes() {
return new ConfigurationNode[] { return new ConfigurationNode[] {

View File

@ -6,6 +6,7 @@ import cn.nukkit.Player;
import cn.nukkit.entity.Entity; import cn.nukkit.entity.Entity;
import cn.nukkit.event.Listener; import cn.nukkit.event.Listener;
import cn.nukkit.level.Level; import cn.nukkit.level.Level;
import cn.nukkit.level.format.generic.BaseFullChunk;
import cn.nukkit.level.generator.Generator; import cn.nukkit.level.generator.Generator;
import cn.nukkit.metadata.MetadataValue; import cn.nukkit.metadata.MetadataValue;
import cn.nukkit.plugin.Plugin; import cn.nukkit.plugin.Plugin;
@ -23,11 +24,15 @@ import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.generator.IndependentPlotGenerator; import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.SetupObject; import com.intellectualcrafters.plot.object.SetupObject;
import com.intellectualcrafters.plot.object.chat.PlainChatManager; import com.intellectualcrafters.plot.object.chat.PlainChatManager;
import com.intellectualcrafters.plot.object.worlds.PlotAreaManager;
import com.intellectualcrafters.plot.object.worlds.SinglePlotArea;
import com.intellectualcrafters.plot.object.worlds.SinglePlotAreaManager;
import com.intellectualcrafters.plot.util.AbstractTitle; import com.intellectualcrafters.plot.util.AbstractTitle;
import com.intellectualcrafters.plot.util.ChatManager; import com.intellectualcrafters.plot.util.ChatManager;
import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ChunkManager;
@ -106,11 +111,54 @@ public final class NukkitMain extends PluginBase implements Listener, IPlotMain
PS.log(C.CONSOLE_PLEASE_ENABLE_METRICS.f(getPluginName())); PS.log(C.CONSOLE_PLEASE_ENABLE_METRICS.f(getPluginName()));
} }
Generator.addGenerator(NukkitHybridGen.class, getPluginName(), 1); Generator.addGenerator(NukkitHybridGen.class, getPluginName(), 1);
if (Settings.Enabled_Components.WORLDS) {
TaskManager.IMP.taskRepeat(new Runnable() {
@Override
public void run() {
unload();
}
}, 20);
}
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
public void unload() {
PlotAreaManager manager = PS.get().getPlotAreaManager();
if (manager instanceof SinglePlotAreaManager) {
long start = System.currentTimeMillis();
SinglePlotArea area = ((SinglePlotAreaManager) manager).getArea();
Map<Integer, Level> worlds = getServer().getLevels();
Level unload = null;
for (Level world : getServer().getLevels().values()) {
String name = world.getName();
PlotId id = PlotId.fromString(name);
if (id != null) {
Plot plot = area.getOwnedPlot(id);
if (plot != null) {
List<PlotPlayer> players = plot.getPlayersInPlot();
if (players.isEmpty() && PlotPlayer.wrap(plot.owner) == null) {
unload = world;
break;
}
}
}
}
if (unload != null) {
Map<String, BaseFullChunk> chunks = unload.getChunks();
BaseFullChunk[] toUnload = chunks.values().toArray(new BaseFullChunk[chunks.size()]);
for (BaseFullChunk chunk : toUnload) {
chunk.unload(true, false);
if (System.currentTimeMillis() - start > 20) {
return;
}
}
getServer().unloadLevel(unload, true);
}
}
}
@Override @Override
public void onDisable() { public void onDisable() {
PS.get().disable(); PS.get().disable();

View File

@ -11,8 +11,13 @@ import com.intellectualcrafters.plot.generator.GeneratorWrapper;
import com.intellectualcrafters.plot.generator.HybridGen; import com.intellectualcrafters.plot.generator.HybridGen;
import com.intellectualcrafters.plot.generator.HybridUtils; import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.generator.IndependentPlotGenerator; import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.SetupObject; import com.intellectualcrafters.plot.object.SetupObject;
import com.intellectualcrafters.plot.object.worlds.PlotAreaManager;
import com.intellectualcrafters.plot.object.worlds.SinglePlotArea;
import com.intellectualcrafters.plot.object.worlds.SinglePlotAreaManager;
import com.intellectualcrafters.plot.util.AbstractTitle; import com.intellectualcrafters.plot.util.AbstractTitle;
import com.intellectualcrafters.plot.util.ChatManager; import com.intellectualcrafters.plot.util.ChatManager;
import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ChunkManager;
@ -63,6 +68,7 @@ import org.spongepowered.api.event.game.state.GamePreInitializationEvent;
import org.spongepowered.api.plugin.Plugin; import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.plugin.PluginContainer; import org.spongepowered.api.plugin.PluginContainer;
import org.spongepowered.api.profile.GameProfileManager; import org.spongepowered.api.profile.GameProfileManager;
import org.spongepowered.api.world.Chunk;
import org.spongepowered.api.world.World; import org.spongepowered.api.world.World;
import org.spongepowered.api.world.gen.GenerationPopulator; import org.spongepowered.api.world.gen.GenerationPopulator;
import org.spongepowered.api.world.gen.WorldGenerator; import org.spongepowered.api.world.gen.WorldGenerator;
@ -137,6 +143,41 @@ public class SpongeMain implements IPlotMain {
new PS(this, "Sponge"); new PS(this, "Sponge");
this.server = this.game.getServer(); this.server = this.game.getServer();
this.game.getRegistry().register(WorldGeneratorModifier.class, (WorldGeneratorModifier) PS.get().IMP.getDefaultGenerator().specify(null)); this.game.getRegistry().register(WorldGeneratorModifier.class, (WorldGeneratorModifier) PS.get().IMP.getDefaultGenerator().specify(null));
if (Settings.Enabled_Components.WORLDS) {
TaskManager.IMP.taskRepeat(new Runnable() {
@Override
public void run() {
unload();
}
}, 20);
}
}
public void unload() {
PlotAreaManager manager = PS.get().getPlotAreaManager();
if (manager instanceof SinglePlotAreaManager) {
long start = System.currentTimeMillis();
SinglePlotArea area = ((SinglePlotAreaManager) manager).getArea();
for (World world : Sponge.getServer().getWorlds()) {
String name = world.getName();
PlotId id = PlotId.fromString(name);
if (id != null) {
Plot plot = area.getOwnedPlot(id);
if (plot != null) {
List<PlotPlayer> players = plot.getPlayersInPlot();
if (players.isEmpty() && PlotPlayer.wrap(plot.owner) == null) {
for (Chunk chunk : world.getLoadedChunks()) {
chunk.unloadChunk();
if (System.currentTimeMillis() - start > 20) {
return;
}
}
Sponge.getServer().unloadWorld(world);
}
}
}
}
}
} }
@Override @Override

View File

@ -20,6 +20,9 @@ ext {
} }
version = "3.5.1-SNAPSHOT-${revision}" version = "3.5.1-SNAPSHOT-${revision}"
description = rootProject.name description = rootProject.name
if ( project.hasProperty("lzNoVersion") ) { // gradle build -PlzNoVersion
version = "unknown";
}
subprojects { subprojects {
apply plugin: 'java' apply plugin: 'java'