From 149257f1544a87fb5eb657c28be5f764ba86f8ed Mon Sep 17 00:00:00 2001 From: Brettflan Date: Wed, 5 Oct 2011 00:33:15 -0500 Subject: [PATCH] When a player is kicked from their faction by the autoLeaveAfterDaysOfInactivity routine, the rest of their stored data is now dropped as well When a player is banned from the server, they will now be kicked from their faction and have their stored data removed (only works on CB 1240 or newer) --- src/com/massivecraft/factions/FPlayer.java | 11 ++++++++--- src/com/massivecraft/factions/Faction.java | 7 ++++++- .../listeners/FactionsPlayerListener.java | 18 ++++++++++++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/com/massivecraft/factions/FPlayer.java b/src/com/massivecraft/factions/FPlayer.java index 28de534f..4b1cddc2 100644 --- a/src/com/massivecraft/factions/FPlayer.java +++ b/src/com/massivecraft/factions/FPlayer.java @@ -51,6 +51,7 @@ public class FPlayer { private transient boolean autoSafeZoneEnabled; private transient boolean autoWarZoneEnabled; private transient boolean loginPvpDisabled; + private transient boolean deleteMe; private ChatMode chatMode; // -------------------------------------------- // @@ -68,6 +69,7 @@ public class FPlayer { this.autoSafeZoneEnabled = false; this.autoWarZoneEnabled = false; this.loginPvpDisabled = (Conf.noPVPDamageToOthersForXSecondsAfterLogin > 0) ? true : false; + this.deleteMe = false; if (Conf.newPlayerStartingFactionID > 0 && Faction.exists(Conf.newPlayerStartingFactionID)) { this.factionId = Conf.newPlayerStartingFactionID; @@ -226,6 +228,10 @@ public class FPlayer { public void setLastStoodAt(FLocation flocation) { this.lastStoodAt = flocation; } + + public void markForDeletion(boolean delete) { + deleteMe = delete; + } //----------------------------------------------// // Title, Name, Faction Tag and Chat @@ -720,9 +726,7 @@ public class FPlayer { // -------------------------------------------- // public boolean shouldBeSaved() { -// return this.factionId != 0; - // we now need to track all players, so they don't get stuck back into a default faction if factionless; also to keep track of lost power and such - return true; + return !deleteMe; } public static boolean save() { @@ -797,6 +801,7 @@ public class FPlayer { for (FPlayer fplayer : FPlayer.getAll()) { if (now - fplayer.getLastLoginTime() > toleranceMillis) { fplayer.leave(false); + fplayer.markForDeletion(true); } } } diff --git a/src/com/massivecraft/factions/Faction.java b/src/com/massivecraft/factions/Faction.java index 8c462616..3e83f91a 100644 --- a/src/com/massivecraft/factions/Faction.java +++ b/src/com/massivecraft/factions/Faction.java @@ -593,7 +593,12 @@ public class Faction { return false; } - + + + //----------------------------------------------// + // Bank functions + //----------------------------------------------// + public double getMoney() { return this.money; } diff --git a/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java index 30ed47ad..6fd49e8f 100644 --- a/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -17,6 +17,7 @@ import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerKickEvent; import org.bukkit.event.player.PlayerListener; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerQuitEvent; @@ -510,4 +511,21 @@ public class FactionsPlayerListener extends PlayerListener{ return false; } + @Override + public void onPlayerKick(PlayerKickEvent event) { + if (event.isCancelled()) { + return; + } + + // if player was banned (not just kicked), get rid of their stored info + if (event.getReason().equals("Banned by admin.")) { + FPlayer badGuy = FPlayer.get(event.getPlayer()); + if (badGuy == null) { + return; + } + + badGuy.leave(false); + badGuy.markForDeletion(true); + } + } }