Fix cleaning bug
This commit is contained in:
parent
8090acc04a
commit
4904bb39c6
@ -5,7 +5,7 @@ import com.massivecraft.factions.entity.MConf;
|
|||||||
import com.massivecraft.factions.entity.MPlayer;
|
import com.massivecraft.factions.entity.MPlayer;
|
||||||
import com.massivecraft.massivecore.MassiveException;
|
import com.massivecraft.massivecore.MassiveException;
|
||||||
import com.massivecraft.massivecore.Progressbar;
|
import com.massivecraft.massivecore.Progressbar;
|
||||||
import com.massivecraft.massivecore.event.EventMassiveCorePlayercleanToleranceMillis;
|
import com.massivecraft.massivecore.event.EventMassiveCorePlayerCleanInactivityToleranceMillis;
|
||||||
import com.massivecraft.massivecore.util.TimeDiffUtil;
|
import com.massivecraft.massivecore.util.TimeDiffUtil;
|
||||||
import com.massivecraft.massivecore.util.TimeUnit;
|
import com.massivecraft.massivecore.util.TimeUnit;
|
||||||
import com.massivecraft.massivecore.util.Txt;
|
import com.massivecraft.massivecore.util.Txt;
|
||||||
@ -80,9 +80,9 @@ public class CmdFactionsPlayer extends FactionsCommand
|
|||||||
msg("<a>Power per Death: <v>%.2f", mplayer.getPowerPerDeath());
|
msg("<a>Power per Death: <v>%.2f", mplayer.getPowerPerDeath());
|
||||||
|
|
||||||
// Display automatic kick / remove info if the system is in use
|
// Display automatic kick / remove info if the system is in use
|
||||||
if (MConf.get().playercleanToleranceMillis <= 0) return;
|
if (MConf.get().cleanInactivityToleranceMillis <= 0) return;
|
||||||
|
|
||||||
EventMassiveCorePlayercleanToleranceMillis event = new EventMassiveCorePlayercleanToleranceMillis(mplayer);
|
EventMassiveCorePlayerCleanInactivityToleranceMillis event = new EventMassiveCorePlayerCleanInactivityToleranceMillis(mplayer.getLastActivityMillis(), mplayer);
|
||||||
event.run();
|
event.run();
|
||||||
msg("<i>Automatic removal after %s <i>of inactivity:", format(event.getToleranceMillis()));
|
msg("<i>Automatic removal after %s <i>of inactivity:", format(event.getToleranceMillis()));
|
||||||
for (Entry<String, Long> causeMillis : event.getToleranceCauseMillis().entrySet())
|
for (Entry<String, Long> causeMillis : event.getToleranceCauseMillis().entrySet())
|
||||||
|
@ -5,28 +5,28 @@ import com.massivecraft.factions.entity.MConf;
|
|||||||
import com.massivecraft.factions.entity.MPlayer;
|
import com.massivecraft.factions.entity.MPlayer;
|
||||||
import com.massivecraft.factions.entity.MPlayerColl;
|
import com.massivecraft.factions.entity.MPlayerColl;
|
||||||
import com.massivecraft.massivecore.Engine;
|
import com.massivecraft.massivecore.Engine;
|
||||||
import com.massivecraft.massivecore.event.EventMassiveCorePlayercleanToleranceMillis;
|
import com.massivecraft.massivecore.event.EventMassiveCorePlayerCleanInactivityToleranceMillis;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
public class EnginePlayerclean extends Engine
|
public class EngineCleanInactivity extends Engine
|
||||||
{
|
{
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// INSTANCE & CONSTRUCT
|
// INSTANCE & CONSTRUCT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
private static EnginePlayerclean i = new EnginePlayerclean();
|
private static EngineCleanInactivity i = new EngineCleanInactivity();
|
||||||
public static EnginePlayerclean get() { return i; }
|
public static EngineCleanInactivity get() { return i; }
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// REMOVE PLAYER MILLIS
|
// REMOVE PLAYER MILLIS
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
public void ageBonus(EventMassiveCorePlayercleanToleranceMillis event)
|
public void ageBonus(EventMassiveCorePlayerCleanInactivityToleranceMillis event)
|
||||||
{
|
{
|
||||||
if (event.getColl() != MPlayerColl.get()) return;
|
if (event.getColl() != MPlayerColl.get()) return;
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ public class EnginePlayerclean extends Engine
|
|||||||
applyFactionAgeBonus(event);
|
applyFactionAgeBonus(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void applyPlayerAgeBonus(EventMassiveCorePlayercleanToleranceMillis event)
|
public void applyPlayerAgeBonus(EventMassiveCorePlayerCleanInactivityToleranceMillis event)
|
||||||
{
|
{
|
||||||
// Calculate First Played
|
// Calculate First Played
|
||||||
Long firstPlayed = event.getEntity().getFirstPlayed();
|
Long firstPlayed = event.getEntity().getFirstPlayed();
|
||||||
@ -45,14 +45,14 @@ public class EnginePlayerclean extends Engine
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the Bonus!
|
// Calculate the Bonus!
|
||||||
Long bonus = calculateBonus(age, MConf.get().playercleanToleranceMillisPlayerAgeToBonus);
|
Long bonus = calculateBonus(age, MConf.get().cleanInactivityToleranceMillisPlayerAgeToBonus);
|
||||||
if (bonus == null) return;
|
if (bonus == null) return;
|
||||||
|
|
||||||
// Apply
|
// Apply
|
||||||
event.getToleranceCauseMillis().put("Player Age Bonus", bonus);
|
event.getToleranceCauseMillis().put("Player Age Bonus", bonus);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void applyFactionAgeBonus(EventMassiveCorePlayercleanToleranceMillis event)
|
public void applyFactionAgeBonus(EventMassiveCorePlayerCleanInactivityToleranceMillis event)
|
||||||
{
|
{
|
||||||
// Calculate Faction Age
|
// Calculate Faction Age
|
||||||
Faction faction = ((MPlayer)event.getEntity()).getFaction();
|
Faction faction = ((MPlayer)event.getEntity()).getFaction();
|
||||||
@ -63,7 +63,7 @@ public class EnginePlayerclean extends Engine
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the Bonus!
|
// Calculate the Bonus!
|
||||||
Long bonus = calculateBonus(age, MConf.get().playercleanToleranceMillisFactionAgeToBonus);
|
Long bonus = calculateBonus(age, MConf.get().cleanInactivityToleranceMillisFactionAgeToBonus);
|
||||||
if (bonus == null) return;
|
if (bonus == null) return;
|
||||||
|
|
||||||
// Apply
|
// Apply
|
@ -88,7 +88,7 @@ public class Faction extends Entity<Faction> implements FactionsParticipator
|
|||||||
if (Money.exists(this))
|
if (Money.exists(this))
|
||||||
{
|
{
|
||||||
// ... remove it.
|
// ... remove it.
|
||||||
Money.set(this, null, 0);
|
Money.set(this, null, 0, "Factions");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,17 +111,17 @@ public class MConf extends Entity<MConf>
|
|||||||
|
|
||||||
// The Default
|
// The Default
|
||||||
@EditorType(TypeMillisDiff.class)
|
@EditorType(TypeMillisDiff.class)
|
||||||
public long playercleanToleranceMillis = 10 * TimeUnit.MILLIS_PER_DAY; // 10 days
|
public long cleanInactivityToleranceMillis = 10 * TimeUnit.MILLIS_PER_DAY; // 10 days
|
||||||
|
|
||||||
// Player Age Bonus
|
// Player Age Bonus
|
||||||
@EditorTypeInner({TypeMillisDiff.class, TypeMillisDiff.class})
|
@EditorTypeInner({TypeMillisDiff.class, TypeMillisDiff.class})
|
||||||
public Map<Long, Long> playercleanToleranceMillisPlayerAgeToBonus = MUtil.map(
|
public Map<Long, Long> cleanInactivityToleranceMillisPlayerAgeToBonus = MUtil.map(
|
||||||
2 * TimeUnit.MILLIS_PER_WEEK, 10 * TimeUnit.MILLIS_PER_DAY // +10 days after 2 weeks
|
2 * TimeUnit.MILLIS_PER_WEEK, 10 * TimeUnit.MILLIS_PER_DAY // +10 days after 2 weeks
|
||||||
);
|
);
|
||||||
|
|
||||||
// Faction Age Bonus
|
// Faction Age Bonus
|
||||||
@EditorTypeInner({TypeMillisDiff.class, TypeMillisDiff.class})
|
@EditorTypeInner({TypeMillisDiff.class, TypeMillisDiff.class})
|
||||||
public Map<Long, Long> playercleanToleranceMillisFactionAgeToBonus = MUtil.map(
|
public Map<Long, Long> cleanInactivityToleranceMillisFactionAgeToBonus = MUtil.map(
|
||||||
4 * TimeUnit.MILLIS_PER_WEEK, 10 * TimeUnit.MILLIS_PER_DAY, // +10 days after 4 weeks
|
4 * TimeUnit.MILLIS_PER_WEEK, 10 * TimeUnit.MILLIS_PER_DAY, // +10 days after 4 weeks
|
||||||
2 * TimeUnit.MILLIS_PER_WEEK, 5 * TimeUnit.MILLIS_PER_DAY // +5 days after 2 weeks
|
2 * TimeUnit.MILLIS_PER_WEEK, 5 * TimeUnit.MILLIS_PER_DAY // +5 days after 2 weeks
|
||||||
);
|
);
|
||||||
|
@ -18,7 +18,6 @@ import com.massivecraft.massivecore.mixin.MixinTitle;
|
|||||||
import com.massivecraft.massivecore.ps.PS;
|
import com.massivecraft.massivecore.ps.PS;
|
||||||
import com.massivecraft.massivecore.ps.PSFormatHumanSpace;
|
import com.massivecraft.massivecore.ps.PSFormatHumanSpace;
|
||||||
import com.massivecraft.massivecore.store.SenderEntity;
|
import com.massivecraft.massivecore.store.SenderEntity;
|
||||||
import com.massivecraft.massivecore.store.inactive.Inactive;
|
|
||||||
import com.massivecraft.massivecore.util.IdUtil;
|
import com.massivecraft.massivecore.util.IdUtil;
|
||||||
import com.massivecraft.massivecore.util.MUtil;
|
import com.massivecraft.massivecore.util.MUtil;
|
||||||
import com.massivecraft.massivecore.util.Txt;
|
import com.massivecraft.massivecore.util.Txt;
|
||||||
@ -34,7 +33,7 @@ import java.util.Iterator;
|
|||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class MPlayer extends SenderEntity<MPlayer> implements FactionsParticipator, Inactive
|
public class MPlayer extends SenderEntity<MPlayer> implements FactionsParticipator
|
||||||
{
|
{
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// META
|
// META
|
||||||
@ -78,7 +77,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements FactionsParticipat
|
|||||||
@Override
|
@Override
|
||||||
public boolean isDefault()
|
public boolean isDefault()
|
||||||
{
|
{
|
||||||
// Last activity millis is data we use for clearing out inactive players. So it does not in itself make the player data worth keeping.
|
// Last activity millis is data we use for clearing out cleanable players. So it does not in itself make the player data worth keeping.
|
||||||
if (this.hasFaction()) return false;
|
if (this.hasFaction()) return false;
|
||||||
// Role means nothing without a faction.
|
// Role means nothing without a faction.
|
||||||
// Title means nothing without a faction.
|
// Title means nothing without a faction.
|
||||||
@ -106,6 +105,17 @@ public class MPlayer extends SenderEntity<MPlayer> implements FactionsParticipat
|
|||||||
{
|
{
|
||||||
FactionsIndex.get().update(this);
|
FactionsIndex.get().update(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void preClean()
|
||||||
|
{
|
||||||
|
if (this.getRole() == Rel.LEADER)
|
||||||
|
{
|
||||||
|
this.getFaction().promoteNewLeader();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.leave();
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// FIELDS: RAW
|
// FIELDS: RAW
|
||||||
@ -114,9 +124,9 @@ public class MPlayer extends SenderEntity<MPlayer> implements FactionsParticipat
|
|||||||
// Each field has it's own section further down since just the getter and setter logic takes up quite some place.
|
// Each field has it's own section further down since just the getter and setter logic takes up quite some place.
|
||||||
|
|
||||||
// The last known time of explicit player activity, such as login or logout.
|
// The last known time of explicit player activity, such as login or logout.
|
||||||
// This value is most importantly used for removing inactive players.
|
// This value is most importantly used for removing cleanable players.
|
||||||
// For that reason it defaults to the current time.
|
// For that reason it defaults to the current time.
|
||||||
// Really inactive players will be considered newly active when upgrading Factions from 2.6 --> 2.7.
|
// Really cleanable players will be considered newly active when upgrading Factions from 2.6 --> 2.7.
|
||||||
// There is actually more than one reason we store this data ourselves and don't use the OfflinePlayer#getLastPlayed.
|
// There is actually more than one reason we store this data ourselves and don't use the OfflinePlayer#getLastPlayed.
|
||||||
// 1. I don't trust that method. It's been very buggy or even completely broken in previous Bukkit versions.
|
// 1. I don't trust that method. It's been very buggy or even completely broken in previous Bukkit versions.
|
||||||
// 2. The method depends on the player.dat files being present.
|
// 2. The method depends on the player.dat files being present.
|
||||||
@ -229,7 +239,13 @@ public class MPlayer extends SenderEntity<MPlayer> implements FactionsParticipat
|
|||||||
{
|
{
|
||||||
this.setLastActivityMillis(System.currentTimeMillis());
|
this.setLastActivityMillis(System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldBeCleaned(long now)
|
||||||
|
{
|
||||||
|
return this.shouldBeCleaned(now, this.lastActivityMillis);
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// FIELD: factionId
|
// FIELD: factionId
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
@ -12,7 +12,7 @@ public class MPlayerColl extends SenderColl<MPlayer>
|
|||||||
public static MPlayerColl get() { return i; }
|
public static MPlayerColl get() { return i; }
|
||||||
public MPlayerColl()
|
public MPlayerColl()
|
||||||
{
|
{
|
||||||
this.setPlayercleanTaskEnabled(true);
|
this.setCleanTaskEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -30,9 +30,9 @@ public class MPlayerColl extends SenderColl<MPlayer>
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getPlayercleanToleranceMillis()
|
public long getCleanInactivityToleranceMillis()
|
||||||
{
|
{
|
||||||
return MConf.get().playercleanToleranceMillis;
|
return MConf.get().cleanInactivityToleranceMillis;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,20 +4,20 @@ import com.massivecraft.factions.entity.MConf;
|
|||||||
import com.massivecraft.massivecore.store.migrator.MigratorFieldRename;
|
import com.massivecraft.massivecore.store.migrator.MigratorFieldRename;
|
||||||
import com.massivecraft.massivecore.store.migrator.MigratorRoot;
|
import com.massivecraft.massivecore.store.migrator.MigratorRoot;
|
||||||
|
|
||||||
public class MigratorMConf002Playerclean extends MigratorRoot
|
public class MigratorMConf002CleanInactivity extends MigratorRoot
|
||||||
{
|
{
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// INSTANCE & CONSTRUCT
|
// INSTANCE & CONSTRUCT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
private static MigratorMConf002Playerclean i = new MigratorMConf002Playerclean();
|
private static MigratorMConf002CleanInactivity i = new MigratorMConf002CleanInactivity();
|
||||||
public static MigratorMConf002Playerclean get() { return i; }
|
public static MigratorMConf002CleanInactivity get() { return i; }
|
||||||
private MigratorMConf002Playerclean()
|
private MigratorMConf002CleanInactivity()
|
||||||
{
|
{
|
||||||
super(MConf.class);
|
super(MConf.class);
|
||||||
this.addInnerMigrator(MigratorFieldRename.get("removePlayerMillisDefault", "playercleanToleranceMillis"));
|
this.addInnerMigrator(MigratorFieldRename.get("removePlayerMillisDefault", "cleanInactivityToleranceMillis"));
|
||||||
this.addInnerMigrator(MigratorFieldRename.get("removePlayerMillisPlayerAgeToBonus", "playercleanToleranceMillisPlayerAgeToBonus"));
|
this.addInnerMigrator(MigratorFieldRename.get("removePlayerMillisPlayerAgeToBonus", "cleanInactivityToleranceMillisPlayerAgeToBonus"));
|
||||||
this.addInnerMigrator(MigratorFieldRename.get("removePlayerMillisFactionAgeToBonus", "playercleanToleranceMillisFactionAgeToBonus"));
|
this.addInnerMigrator(MigratorFieldRename.get("removePlayerMillisFactionAgeToBonus", "cleanInactivityToleranceMillisFactionAgeToBonus"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user