Ensure recreation of faction flags and perms on getAll and every 3 seconds to allow for runtime database deletion without server crash.

This commit is contained in:
Olof Larsson 2014-11-19 11:24:36 +01:00
parent c058cd7ca5
commit f8d7e50828
7 changed files with 123 additions and 1 deletions

View File

@ -39,6 +39,7 @@ import com.massivecraft.factions.integration.herochat.IntegrationHerochat;
import com.massivecraft.factions.integration.lwc.IntegrationLwc;
import com.massivecraft.factions.mixin.PowerMixin;
import com.massivecraft.factions.mixin.PowerMixinDefault;
import com.massivecraft.factions.task.TaskFlagPermCreate;
import com.massivecraft.factions.task.TaskPlayerDataRemove;
import com.massivecraft.factions.task.TaskEconLandReward;
import com.massivecraft.factions.task.TaskPlayerPowerUpdate;
@ -161,6 +162,7 @@ public class Factions extends MassivePlugin
TaskPlayerPowerUpdate.get().activate(this);
TaskPlayerDataRemove.get().activate(this);
TaskEconLandReward.get().activate(this);
TaskFlagPermCreate.get().activate(this);
// Register built in chat modifiers
ChatModifierLc.get().register();

View File

@ -2,6 +2,7 @@ package com.massivecraft.factions.entity;
import java.util.List;
import com.massivecraft.factions.event.EventFactionsCreateFlags;
import com.massivecraft.massivecore.PredictateIsRegistered;
import com.massivecraft.massivecore.Prioritized;
import com.massivecraft.massivecore.Registerable;
@ -52,6 +53,13 @@ public class MFlag extends Entity<MFlag> implements Prioritized, Registerable
public static List<MFlag> getAll()
{
return getAll(false);
}
public static List<MFlag> getAll(boolean isAsync)
{
setupStandardFlags();
new EventFactionsCreateFlags(isAsync).run();
return MFlagColl.get().getAll(PredictateIsRegistered.get());
}

View File

@ -10,6 +10,7 @@ import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel;
import com.massivecraft.factions.TerritoryAccess;
import com.massivecraft.factions.event.EventFactionsCreatePerms;
import com.massivecraft.massivecore.PredictateIsRegistered;
import com.massivecraft.massivecore.Prioritized;
import com.massivecraft.massivecore.Registerable;
@ -85,6 +86,14 @@ public class MPerm extends Entity<MPerm> implements Prioritized, Registerable
public static List<MPerm> getAll()
{
return getAll(false);
}
public static List<MPerm> getAll(boolean isAsync)
{
setupStandardPerms();
new EventFactionsCreatePerms().run();
return MPermColl.get().getAll(PredictateIsRegistered.get());
}

View File

@ -4,5 +4,18 @@ import com.massivecraft.massivecore.event.EventMassiveCore;
public abstract class EventFactionsAbstract extends EventMassiveCore
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public EventFactionsAbstract()
{
}
public EventFactionsAbstract(boolean isAsync)
{
super(isAsync);
}
}

View File

@ -0,0 +1,32 @@
package com.massivecraft.factions.event;
import org.bukkit.event.HandlerList;
/**
* External plugins that add Faction flags should make sure they exist when this event is called.
*/
public class EventFactionsCreateFlags extends EventFactionsAbstract
{
// -------------------------------------------- //
// REQUIRED EVENT CODE
// -------------------------------------------- //
private static final HandlerList handlers = new HandlerList();
@Override public HandlerList getHandlers() { return handlers; }
public static HandlerList getHandlerList() { return handlers; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public EventFactionsCreateFlags()
{
}
public EventFactionsCreateFlags(boolean isAsync)
{
super(isAsync);
}
}

View File

@ -0,0 +1,18 @@
package com.massivecraft.factions.event;
import org.bukkit.event.HandlerList;
/**
* External plugins that add Faction perms should make sure they exist when this event is called.
*/
public class EventFactionsCreatePerms extends EventFactionsAbstract
{
// -------------------------------------------- //
// REQUIRED EVENT CODE
// -------------------------------------------- //
private static final HandlerList handlers = new HandlerList();
@Override public HandlerList getHandlers() { return handlers; }
public static HandlerList getHandlerList() { return handlers; }
}

View File

@ -0,0 +1,40 @@
package com.massivecraft.factions.task;
import com.massivecraft.factions.entity.MFlag;
import com.massivecraft.factions.entity.MPerm;
import com.massivecraft.massivecore.ModuloRepeatTask;
import com.massivecraft.massivecore.util.TimeUnit;
public class TaskFlagPermCreate extends ModuloRepeatTask
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static TaskFlagPermCreate i = new TaskFlagPermCreate();
public static TaskFlagPermCreate get() { return i; }
// -------------------------------------------- //
// OVERRIDE: MODULO REPEAT TASK
// -------------------------------------------- //
@Override
public long getDelayMillis()
{
return TimeUnit.MILLIS_PER_SECOND * 3;
}
@Override
public void setDelayMillis(long delayMillis)
{
}
@Override
public void invoke(long now)
{
MPerm.getAll();
MFlag.getAll();
}
}