- delete session on logout
- load session on world change (disk)
- set default chunk wait to 100ms
This commit is contained in:
Jesse Boyd 2016-04-20 06:30:34 +10:00
parent 6c141f462a
commit a8e335e23c
4 changed files with 85 additions and 19 deletions

View File

@ -15,6 +15,7 @@ import com.boydti.fawe.bukkit.v1_8.BukkitEditSessionWrapper_1_8;
import com.boydti.fawe.bukkit.v1_8.BukkitQueue_1_8;
import com.boydti.fawe.bukkit.v1_9.BukkitQueue_1_9;
import com.boydti.fawe.bukkit.v1_9.BukkitQueue_1_9_R1;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.EditSessionWrapper;
import com.boydti.fawe.object.FaweCommand;
import com.boydti.fawe.object.FawePlayer;
@ -34,6 +35,7 @@ import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
@ -293,6 +295,19 @@ public class FaweBukkit extends JavaPlugin implements IFawe, Listener {
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
FawePlayer fp = FawePlayer.wrap(player);
fp.unregister();
Fawe.get().unregister(event.getPlayer().getName());
}
@EventHandler
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
Player player = event.getPlayer();
FawePlayer fp = FawePlayer.wrap(player);
if (Settings.STORE_HISTORY_ON_DISK) {
fp.getSession().clearHistory();
fp.loadSessionFromDisk(fp.getWorld());
}
}
}

View File

@ -24,7 +24,7 @@ public class Settings {
public static int COMPRESSION_LEVEL = 0;
public static int BUFFER_SIZE = 531441;
public static boolean METRICS = true;
public static int CHUNK_WAIT = 0;
public static int CHUNK_WAIT = 100;
public static boolean REGION_RESTRICTIONS = true;
public static int ALLOCATE = 0;
public static int QUEUE_SIZE = 64;

View File

@ -42,24 +42,12 @@ public abstract class FawePlayer<T> {
}
try {
UUID uuid = getUUID();
for (World world : WorldEdit.getInstance().getServer().getWorlds()) {
ArrayDeque<Integer> editIds = new ArrayDeque<>();
File folder = new File(Fawe.imp().getDirectory(), "history" + File.separator + world.getName() + File.separator + uuid);
if (folder.isDirectory()) {
for (File file : folder.listFiles()) {
if (file.getName().endsWith(".bd")) {
int index = Integer.parseInt(file.getName().split("\\.")[0]);
editIds.add(index);
}
}
}
if (editIds.size() > 0) {
Fawe.debug(BBC.PREFIX.s() + " Indexing " + editIds.size() + " history objects for " + getName());
for (int index : editIds) {
DiskStorageHistory set = new DiskStorageHistory(world, uuid, index);
EditSession edit = set.toEditSession(getPlayer());
session.remember(edit);
}
String currentWorldName = getLocation().world;
World world = getWorld();
if (world != null) {
if (world.getName().equals(currentWorldName)) {
getSession().clearHistory();
loadSessionFromDisk(world);
}
}
} catch (Exception e) {
@ -68,6 +56,41 @@ public abstract class FawePlayer<T> {
}
}
public World getWorld() {
String currentWorldName = getLocation().world;
for (World world : WorldEdit.getInstance().getServer().getWorlds()) {
if (world.getName().equals(currentWorldName)) {
return world;
}
}
return null;
}
public void loadSessionFromDisk(World world) {
if (world == null) {
return;
}
UUID uuid = getUUID();
ArrayDeque<Integer> editIds = new ArrayDeque<>();
File folder = new File(Fawe.imp().getDirectory(), "history" + File.separator + world.getName() + File.separator + uuid);
if (folder.isDirectory()) {
for (File file : folder.listFiles()) {
if (file.getName().endsWith(".bd")) {
int index = Integer.parseInt(file.getName().split("\\.")[0]);
editIds.add(index);
}
}
}
if (editIds.size() > 0) {
Fawe.debug(BBC.PREFIX.s() + " Indexing " + editIds.size() + " history objects for " + getName());
for (int index : editIds) {
DiskStorageHistory set = new DiskStorageHistory(world, uuid, index);
EditSession edit = set.toEditSession(getPlayer());
session.remember(edit);
}
}
}
public FaweLimit getLimit() {
return Settings.getLimit(this);
}
@ -176,6 +199,8 @@ public abstract class FawePlayer<T> {
}
public void unregister() {
getSession().setClipboard(null);
getSession().clearHistory();
WorldEdit.getInstance().removeSession(getPlayer());
Fawe.get().unregister(getName());
}

View File

@ -1,17 +1,22 @@
package com.boydti.fawe.forge;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.FawePlayer;
import com.google.inject.Inject;
import com.sk89q.worldedit.WorldEdit;
import org.slf4j.Logger;
import org.spongepowered.api.Game;
import org.spongepowered.api.Server;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.entity.DisplaceEntityEvent;
import org.spongepowered.api.event.game.state.GamePreInitializationEvent;
import org.spongepowered.api.event.network.ClientConnectionEvent;
import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.plugin.PluginContainer;
import org.spongepowered.api.profile.GameProfileManager;
import org.spongepowered.api.world.World;
@Plugin(id = "com.boydti.fawe", name = "FastAsyncWorldEdit", description = "Lagless WorldEdit, Area restrictions, Memory mangement, Block logging", url = "https://github.com/boy0001/FastAsyncWorldedit", version = "3.3.16")
public class SpongeMain {
@ -52,6 +57,27 @@ public class SpongeMain {
@Listener
public void onQuit(ClientConnectionEvent.Disconnect event) {
Player player = event.getTargetEntity();
FawePlayer fp = FawePlayer.wrap(player);
fp.unregister();
Fawe.get().unregister(player.getName());
}
@Listener
public void onMove(DisplaceEntityEvent.TargetPlayer event) {
if (Settings.STORE_HISTORY_ON_DISK) {
World from = event.getFromTransform().getExtent();
World to = event.getToTransform().getExtent();
if (!from.equals(to)) {
Player player = event.getTargetEntity();
FawePlayer fp = FawePlayer.wrap(player);
for (com.sk89q.worldedit.world.World world : WorldEdit.getInstance().getServer().getWorlds()) {
if (world.getName().equals(to.getName())) {
fp.getSession().clearHistory();
fp.loadSessionFromDisk(world);
return;
}
}
}
}
}
}