refactor!: Remove MVPlayerSession (#2838)
Remove teleport / message cooldown along with it
This commit is contained in:
parent
c05d866f2f
commit
bf5ab8d1b3
|
@ -59,7 +59,6 @@ import com.onarandombox.MultiverseCore.teleportation.SimpleBlockSafety;
|
|||
import com.onarandombox.MultiverseCore.teleportation.SimpleLocationManipulation;
|
||||
import com.onarandombox.MultiverseCore.teleportation.SimpleSafeTTeleporter;
|
||||
import com.onarandombox.MultiverseCore.utils.MVPermissions;
|
||||
import com.onarandombox.MultiverseCore.utils.MVPlayerSession;
|
||||
import com.onarandombox.MultiverseCore.utils.TestingMode;
|
||||
import com.onarandombox.MultiverseCore.utils.UnsafeCallWrapper;
|
||||
import com.onarandombox.MultiverseCore.utils.metrics.MetricsConfigurator;
|
||||
|
@ -69,7 +68,6 @@ import me.main__.util.SerializationConfig.SerializationConfig;
|
|||
import org.bukkit.configuration.Configuration;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
@ -504,35 +502,6 @@ public class MultiverseCore extends JavaPlugin implements MVCore {
|
|||
}
|
||||
|
||||
|
||||
//TODO - Extract MVPlayerSession to a separate class - END
|
||||
private final HashMap<String, MVPlayerSession> playerSessions = new HashMap<String, MVPlayerSession>();
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public MVPlayerSession getPlayerSession(Player player) {
|
||||
if (this.playerSessions.containsKey(player.getName())) {
|
||||
return this.playerSessions.get(player.getName());
|
||||
} else {
|
||||
this.playerSessions.put(player.getName(), new MVPlayerSession(player, getMVConfig()));
|
||||
return this.playerSessions.get(player.getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a player-session.
|
||||
*
|
||||
* @param player The {@link Player} that owned the session.
|
||||
*/
|
||||
public void removePlayerSession(Player player) {
|
||||
if (this.playerSessions.containsKey(player.getName())) {
|
||||
this.playerSessions.remove(player.getName());
|
||||
}
|
||||
}
|
||||
//TODO - Extract MVPlayerSession to a separate class - END
|
||||
|
||||
|
||||
//TODO: REMOVE THIS STATIC CRAP - START
|
||||
private static final Map<String, String> teleportQueue = new HashMap<String, String>();
|
||||
|
||||
|
|
|
@ -59,14 +59,10 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
|
|||
@Property
|
||||
private volatile boolean silentstart;
|
||||
@Property
|
||||
private volatile int messagecooldown;
|
||||
@Property
|
||||
private volatile double version;
|
||||
@Property
|
||||
private volatile String firstspawnworld;
|
||||
@Property
|
||||
private volatile int teleportcooldown;
|
||||
@Property
|
||||
private volatile boolean defaultportalsearch;
|
||||
@Property
|
||||
private volatile int portalsearchradius;
|
||||
|
@ -98,8 +94,6 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
|
|||
firstspawnoverride = true;
|
||||
displaypermerrors = true;
|
||||
globaldebug = 0;
|
||||
messagecooldown = 5000;
|
||||
teleportcooldown = 1000;
|
||||
this.version = 2.9;
|
||||
silentstart = false;
|
||||
defaultportalsearch = true;
|
||||
|
@ -237,22 +231,6 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
|
|||
Bukkit.getPluginManager().callEvent(new MVDebugModeEvent(globalDebug));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int getMessageCooldown() {
|
||||
return this.messagecooldown;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setMessageCooldown(int messageCooldown) {
|
||||
this.messagecooldown = messageCooldown;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -285,22 +263,6 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
|
|||
this.firstspawnworld = firstSpawnWorld;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int getTeleportCooldown() {
|
||||
return this.teleportcooldown;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setTeleportCooldown(int teleportCooldown) {
|
||||
this.teleportcooldown = teleportCooldown;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSilentStart(boolean silentStart) {
|
||||
Logging.setShowingConfig(!silentStart);
|
||||
|
|
|
@ -14,18 +14,6 @@ public interface MVConfig extends ConfigurationSerializable {
|
|||
*/
|
||||
boolean setConfigProperty(String property, String value);
|
||||
|
||||
/**
|
||||
* Sets portalCooldown.
|
||||
* @param portalCooldown The new value.
|
||||
*/
|
||||
void setTeleportCooldown(int portalCooldown);
|
||||
|
||||
/**
|
||||
* Gets portalCooldown.
|
||||
* @return portalCooldown.
|
||||
*/
|
||||
int getTeleportCooldown();
|
||||
|
||||
/**
|
||||
* Sets firstSpawnWorld.
|
||||
* @param firstSpawnWorld The new value.
|
||||
|
@ -50,18 +38,6 @@ public interface MVConfig extends ConfigurationSerializable {
|
|||
*/
|
||||
double getVersion();
|
||||
|
||||
/**
|
||||
* Sets messageCooldown.
|
||||
* @param messageCooldown The new value.
|
||||
*/
|
||||
void setMessageCooldown(int messageCooldown);
|
||||
|
||||
/**
|
||||
* Gets messageCooldown.
|
||||
* @return messageCooldown.
|
||||
*/
|
||||
int getMessageCooldown();
|
||||
|
||||
/**
|
||||
* Sets globalDebug.
|
||||
* @param globalDebug The new value.
|
||||
|
|
|
@ -15,9 +15,7 @@ import com.onarandombox.MultiverseCore.teleportation.SimpleBlockSafety;
|
|||
import com.onarandombox.MultiverseCore.teleportation.SimpleLocationManipulation;
|
||||
import com.onarandombox.MultiverseCore.teleportation.SimpleSafeTTeleporter;
|
||||
import com.onarandombox.MultiverseCore.utils.MVPermissions;
|
||||
import com.onarandombox.MultiverseCore.utils.MVPlayerSession;
|
||||
import com.onarandombox.MultiverseCore.utils.UnsafeCallWrapper;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Multiverse 2 Core API
|
||||
|
@ -46,17 +44,6 @@ public interface MVCore extends MVPlugin {
|
|||
*/
|
||||
UnsafeCallWrapper getUnsafeCallWrapper();
|
||||
|
||||
/**
|
||||
* Gets the {@link MVPlayerSession} for the given player.
|
||||
* This will also create a player session if one does not exist
|
||||
* for a player.
|
||||
*
|
||||
* @param player The player's session to grab.
|
||||
*
|
||||
* @return The corresponding {@link MVPlayerSession}.
|
||||
*/
|
||||
MVPlayerSession getPlayerSession(Player player);
|
||||
|
||||
/**
|
||||
* Multiverse uses an advanced permissions setup, this object
|
||||
* simplifies getting/setting permissions.
|
||||
|
|
|
@ -12,8 +12,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorld;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.event.MVRespawnEvent;
|
||||
import com.onarandombox.MultiverseCore.utils.PermissionTools;
|
||||
import org.bukkit.GameMode;
|
||||
|
@ -28,7 +28,6 @@ import org.bukkit.event.Listener;
|
|||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerPortalEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
|
@ -139,15 +138,6 @@ public class MVPlayerListener implements Listener {
|
|||
playerWorld.put(event.getPlayer().getName(), event.getPlayer().getWorld().getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when a player quits the game.
|
||||
* @param event The Event that was fired.
|
||||
*/
|
||||
@EventHandler
|
||||
public void playerQuit(PlayerQuitEvent event) {
|
||||
this.plugin.removePlayerSession(event.getPlayer());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when a player teleports anywhere.
|
||||
* @param event The Event that was fired.
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.MVConfig;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* A player-session.
|
||||
*/
|
||||
public class MVPlayerSession {
|
||||
|
||||
private Player player; // Player holder, may be unnecessary.
|
||||
|
||||
private long teleportLast = 0L; // Timestamp for the Players last Portal Teleportation.
|
||||
private long messageLast = 0L; // Timestamp for the Players last Alert Message.
|
||||
|
||||
private MVConfig config; // Configuration file to find out Cooldown Timers.
|
||||
|
||||
public MVPlayerSession(Player player, MVConfig config) {
|
||||
this.player = player;
|
||||
this.config = config;
|
||||
// this.bedSpawn = null;
|
||||
}
|
||||
|
||||
/** Update the Teleport time. */
|
||||
public void teleport() {
|
||||
this.teleportLast = (new Date()).getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* Grab whether the cooldown on Portal use has expired or not.
|
||||
* @return True if the {@link Player} associated with this player-session is teleportable.
|
||||
*/
|
||||
public boolean getTeleportable() {
|
||||
long time = (new Date()).getTime();
|
||||
return ((time - this.teleportLast) > this.config.getTeleportCooldown());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue