Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-10 05:20:04 +01:00
Added expiration timer to sessions. Sessions will now last up to 10 minutes (by default) before removed, so you can quickly disconnect (or crash) and come back and still maintain your history.
Dieser Commit ist enthalten in:
Ursprung
a18546d698
Commit
d71d4a8569
@ -51,9 +51,11 @@ import com.sk89q.worldedit.regions.RegionSelector;
|
|||||||
*/
|
*/
|
||||||
public class LocalSession {
|
public class LocalSession {
|
||||||
public static int MAX_HISTORY_SIZE = 15;
|
public static int MAX_HISTORY_SIZE = 15;
|
||||||
|
public static int EXPIRATION_GRACE = 600000;
|
||||||
|
|
||||||
private LocalConfiguration config;
|
private LocalConfiguration config;
|
||||||
|
|
||||||
|
private long expirationTime = 0;
|
||||||
private LocalWorld selectionWorld;
|
private LocalWorld selectionWorld;
|
||||||
private RegionSelector selector = new CuboidRegionSelector();
|
private RegionSelector selector = new CuboidRegionSelector();
|
||||||
private boolean placeAtPos1 = false;
|
private boolean placeAtPos1 = false;
|
||||||
@ -615,4 +617,20 @@ public class LocalSession {
|
|||||||
return date.getBeginCalendar();
|
return date.getBeginCalendar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the last update time for calculating expiration.
|
||||||
|
*/
|
||||||
|
public void update() {
|
||||||
|
expirationTime = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether this session has expired.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean hasExpired() {
|
||||||
|
return System.currentTimeMillis() - expirationTime > EXPIRATION_GRACE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
37
src/main/java/com/sk89q/worldedit/SessionCheck.java
Normale Datei
37
src/main/java/com/sk89q/worldedit/SessionCheck.java
Normale Datei
@ -0,0 +1,37 @@
|
|||||||
|
// $Id$
|
||||||
|
/*
|
||||||
|
* WorldEdit
|
||||||
|
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.sk89q.worldedit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to discard old sessions.
|
||||||
|
*
|
||||||
|
* @author sk89q
|
||||||
|
*/
|
||||||
|
public interface SessionCheck {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a player is online.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean isOnlinePlayer(String name);
|
||||||
|
|
||||||
|
}
|
@ -129,11 +129,14 @@ public class WorldEdit {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public LocalSession getSession(LocalPlayer player) {
|
public LocalSession getSession(LocalPlayer player) {
|
||||||
|
LocalSession session;
|
||||||
|
|
||||||
|
synchronized (sessions) {
|
||||||
if (sessions.containsKey(player.getName())) {
|
if (sessions.containsKey(player.getName())) {
|
||||||
return sessions.get(player.getName());
|
return sessions.get(player.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalSession session = new LocalSession(config);
|
session = new LocalSession(config);
|
||||||
|
|
||||||
// Set the limit on the number of blocks that an operation can
|
// Set the limit on the number of blocks that an operation can
|
||||||
// change at once, or don't if the player has an override or there
|
// change at once, or don't if the player has an override or there
|
||||||
@ -164,6 +167,7 @@ public class WorldEdit {
|
|||||||
|
|
||||||
// Remember the session
|
// Remember the session
|
||||||
sessions.put(player.getName(), session);
|
sessions.put(player.getName(), session);
|
||||||
|
}
|
||||||
|
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
@ -175,8 +179,10 @@ public class WorldEdit {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public boolean hasSession(LocalPlayer player) {
|
public boolean hasSession(LocalPlayer player) {
|
||||||
|
synchronized (sessions) {
|
||||||
return sessions.containsKey(player.getName());
|
return sessions.containsKey(player.getName());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an item ID from an item name or an item ID number.
|
* Get an item ID from an item name or an item ID number.
|
||||||
@ -726,15 +732,19 @@ public class WorldEdit {
|
|||||||
* @param player
|
* @param player
|
||||||
*/
|
*/
|
||||||
public void removeSession(LocalPlayer player) {
|
public void removeSession(LocalPlayer player) {
|
||||||
|
synchronized (sessions) {
|
||||||
sessions.remove(player.getName());
|
sessions.remove(player.getName());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove all sessions.
|
* Remove all sessions.
|
||||||
*/
|
*/
|
||||||
public void clearSessions() {
|
public void clearSessions() {
|
||||||
|
synchronized (sessions) {
|
||||||
sessions.clear();
|
sessions.clear();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flush a block bag's changes to a player.
|
* Flush a block bag's changes to a player.
|
||||||
@ -788,10 +798,50 @@ public class WorldEdit {
|
|||||||
*
|
*
|
||||||
* @param player
|
* @param player
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public void handleDisconnect(LocalPlayer player) {
|
public void handleDisconnect(LocalPlayer player) {
|
||||||
|
forgetPlayer(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param player
|
||||||
|
*/
|
||||||
|
public void markExpire(LocalPlayer player) {
|
||||||
|
synchronized (sessions) {
|
||||||
|
LocalSession session = sessions.get(player.getName());
|
||||||
|
if (session != null) {
|
||||||
|
session.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forget a player.
|
||||||
|
*
|
||||||
|
* @param player
|
||||||
|
*/
|
||||||
|
public void forgetPlayer(LocalPlayer player) {
|
||||||
removeSession(player);
|
removeSession(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Flush expired sessions.
|
||||||
|
*/
|
||||||
|
public void flushExpiredSessions(SessionCheck checker) {
|
||||||
|
synchronized (sessions) {
|
||||||
|
Iterator<Map.Entry<String, LocalSession>> it = sessions.entrySet().iterator();
|
||||||
|
|
||||||
|
while (it.hasNext()) {
|
||||||
|
Map.Entry<String, LocalSession> entry = it.next();
|
||||||
|
if (entry.getValue().hasExpired()
|
||||||
|
&& !checker.isOnlinePlayer(entry.getKey())) {
|
||||||
|
it.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called on arm swing.
|
* Called on arm swing.
|
||||||
*
|
*
|
||||||
|
@ -82,6 +82,7 @@ public class BukkitConfiguration extends LocalConfiguration {
|
|||||||
noOpPermissions = config.getBoolean("no-op-permissions", false);
|
noOpPermissions = config.getBoolean("no-op-permissions", false);
|
||||||
|
|
||||||
LocalSession.MAX_HISTORY_SIZE = Math.max(15, config.getInt("history.size", 15));
|
LocalSession.MAX_HISTORY_SIZE = Math.max(15, config.getInt("history.size", 15));
|
||||||
|
LocalSession.EXPIRATION_GRACE = config.getInt("history.expiration", 10) * 60 * 1000;
|
||||||
|
|
||||||
String snapshotsDir = config.getString("snapshots.directory", "");
|
String snapshotsDir = config.getString("snapshots.directory", "");
|
||||||
if (!snapshotsDir.trim().equals("")) {
|
if (!snapshotsDir.trim().equals("")) {
|
||||||
|
51
src/main/java/com/sk89q/worldedit/bukkit/SessionTimer.java
Normale Datei
51
src/main/java/com/sk89q/worldedit/bukkit/SessionTimer.java
Normale Datei
@ -0,0 +1,51 @@
|
|||||||
|
// $Id$
|
||||||
|
/*
|
||||||
|
* WorldEdit
|
||||||
|
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.sk89q.worldedit.bukkit;
|
||||||
|
|
||||||
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import com.sk89q.worldedit.SessionCheck;
|
||||||
|
import com.sk89q.worldedit.WorldEdit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to remove expired sessions in Bukkit.
|
||||||
|
*
|
||||||
|
* @author sk89q
|
||||||
|
*/
|
||||||
|
public class SessionTimer implements Runnable {
|
||||||
|
|
||||||
|
private WorldEdit worldEdit;
|
||||||
|
private SessionCheck checker;
|
||||||
|
|
||||||
|
public SessionTimer(WorldEdit worldEdit, final Server server) {
|
||||||
|
this.worldEdit = worldEdit;
|
||||||
|
this.checker = new SessionCheck() {
|
||||||
|
public boolean isOnlinePlayer(String name) {
|
||||||
|
Player player = server.getPlayer(name);
|
||||||
|
return player != null && player.isOnline();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
worldEdit.flushExpiredSessions(checker);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -79,7 +79,7 @@ public class WorldEditPlayerListener extends PlayerListener {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
plugin.getWorldEdit().handleDisconnect(wrapPlayer(event.getPlayer()));
|
plugin.getWorldEdit().markExpire(wrapPlayer(event.getPlayer()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -101,6 +101,9 @@ public class WorldEditPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
// Now we can register events!
|
// Now we can register events!
|
||||||
registerEvents();
|
registerEvents();
|
||||||
|
|
||||||
|
getServer().getScheduler().scheduleAsyncRepeatingTask(this,
|
||||||
|
new SessionTimer(controller, getServer()), 120, 120);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -83,6 +83,7 @@ public class BrushTool implements TraceTool {
|
|||||||
* Set the brush.
|
* Set the brush.
|
||||||
*
|
*
|
||||||
* @param brush
|
* @param brush
|
||||||
|
* @param perm
|
||||||
*/
|
*/
|
||||||
public void setBrush(Brush brush, String perm) {
|
public void setBrush(Brush brush, String perm) {
|
||||||
this.brush = brush;
|
this.brush = brush;
|
||||||
|
@ -52,6 +52,7 @@ saving:
|
|||||||
|
|
||||||
history:
|
history:
|
||||||
size: 15
|
size: 15
|
||||||
|
expiration: 10
|
||||||
|
|
||||||
wand-item: 271
|
wand-item: 271
|
||||||
shell-save-type:
|
shell-save-type:
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren