Make EventFactionsFactionShowAsync

This commit is contained in:
Olof Larsson 2015-01-10 13:00:29 +01:00
parent 0bc863b289
commit 5e4a42d2ac
4 changed files with 40 additions and 19 deletions

View File

@ -2,12 +2,17 @@ package com.massivecraft.factions.cmd;
import java.util.TreeSet;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.event.EventFactionsFactionShow;
import com.massivecraft.factions.event.EventFactionsFactionShowAsync;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm;
import com.massivecraft.massivecore.PriorityLines;
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
import com.massivecraft.massivecore.mixin.Mixin;
import com.massivecraft.massivecore.util.Txt;
public class CmdFactionsFaction extends FactionsCommand
@ -36,23 +41,33 @@ public class CmdFactionsFaction extends FactionsCommand
public void perform()
{
// Args
Faction faction = this.arg(0, ARFaction.get(), msenderFaction);
final Faction faction = this.arg(0, ARFaction.get(), msenderFaction);
if (faction == null) return;
// Event
EventFactionsFactionShow event = new EventFactionsFactionShow(sender, faction);
event.run();
if (event.isCancelled()) return;
final CommandSender sender = this.sender;
// Title
msg(Txt.titleize("Faction " + faction.getName(msender)));
// Lines
TreeSet<PriorityLines> priorityLiness = new TreeSet<PriorityLines>(event.getIdPriorityLiness().values());
for (PriorityLines priorityLines : priorityLiness)
Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), new Runnable()
{
sendMessage(priorityLines.getLines());
}
@Override
public void run()
{
// Event
EventFactionsFactionShowAsync event = new EventFactionsFactionShowAsync(sender, faction);
event.run();
if (event.isCancelled()) return;
// Title
Mixin.messageOne(sender, Txt.titleize("Faction " + faction.getName(msender)));
// Lines
TreeSet<PriorityLines> priorityLiness = new TreeSet<PriorityLines>(event.getIdPriorityLiness().values());
for (PriorityLines priorityLines : priorityLiness)
{
Mixin.messageOne(sender, priorityLines.getLines());
}
}
});
}
}

View File

@ -79,7 +79,7 @@ import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.entity.MPlayerColl;
import com.massivecraft.factions.event.EventFactionsChunkChangeType;
import com.massivecraft.factions.event.EventFactionsChunksChange;
import com.massivecraft.factions.event.EventFactionsFactionShow;
import com.massivecraft.factions.event.EventFactionsFactionShowAsync;
import com.massivecraft.factions.event.EventFactionsPvpDisallowed;
import com.massivecraft.factions.event.EventFactionsPowerChange;
import com.massivecraft.factions.event.EventFactionsPowerChange.PowerChangeReason;
@ -122,7 +122,7 @@ public class EngineMain extends EngineAbstract
// -------------------------------------------- //
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onFactionShow(EventFactionsFactionShow event)
public void onFactionShow(EventFactionsFactionShowAsync event)
{
final int tableCols = 4;
final CommandSender sender = event.getSender();

View File

@ -23,4 +23,10 @@ public abstract class EventFactionsAbstractSender extends EventMassiveCore
{
this.sender = sender;
}
public EventFactionsAbstractSender(boolean async, CommandSender sender)
{
super(async);
this.sender = sender;
}
}

View File

@ -9,7 +9,7 @@ import org.bukkit.event.HandlerList;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.massivecore.PriorityLines;
public class EventFactionsFactionShow extends EventFactionsAbstractSender
public class EventFactionsFactionShowAsync extends EventFactionsAbstractSender
{
// -------------------------------------------- //
// REQUIRED EVENT CODE
@ -33,9 +33,9 @@ public class EventFactionsFactionShow extends EventFactionsAbstractSender
// CONSTRUCT
// -------------------------------------------- //
public EventFactionsFactionShow(CommandSender sender, Faction faction)
public EventFactionsFactionShowAsync(CommandSender sender, Faction faction)
{
super(sender);
super(true, sender);
this.faction = faction;
this.idPriorityLiness = new HashMap<String, PriorityLines>();
}