Better claiming. Step 1.

This commit is contained in:
Olof Larsson
2014-10-13 11:42:40 +02:00
parent b54293577d
commit c690d33ad6
16 changed files with 506 additions and 484 deletions

View File

@ -1,59 +0,0 @@
package com.massivecraft.factions.event;
import org.bukkit.command.CommandSender;
import org.bukkit.event.HandlerList;
import com.massivecraft.factions.entity.BoardColl;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.ps.PS;
public class EventFactionsChunkChange extends EventFactionsAbstractSender
{
// -------------------------------------------- //
// REQUIRED EVENT CODE
// -------------------------------------------- //
private static final HandlerList handlers = new HandlerList();
@Override public HandlerList getHandlers() { return handlers; }
public static HandlerList getHandlerList() { return handlers; }
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
private final PS chunk;
public PS getChunk() { return this.chunk; }
private final Faction currentFaction;
private final Faction newFaction;
public Faction getNewFaction() { return this.newFaction; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public EventFactionsChunkChange(CommandSender sender, PS chunk, Faction newFaction)
{
super(sender);
this.chunk = chunk.getChunk(true);
this.currentFaction = BoardColl.get().getFactionAt(chunk);
this.newFaction = newFaction;
}
// -------------------------------------------- //
// UTIL
// -------------------------------------------- //
public EventFactionsChunkChangeType getType()
{
if (currentFaction.isNone()) return EventFactionsChunkChangeType.BUY;
if (newFaction.isNormal()) return EventFactionsChunkChangeType.CONQUER;
MPlayer usender = this.getMSender();
if (usender != null && usender.getFaction() == currentFaction) return EventFactionsChunkChangeType.SELL;
return EventFactionsChunkChangeType.PILLAGE;
}
}

View File

@ -1,11 +1,14 @@
package com.massivecraft.factions.event;
import com.massivecraft.factions.entity.Faction;
public enum EventFactionsChunkChangeType
{
// -------------------------------------------- //
// ENUM
// -------------------------------------------- //
NONE("none", "none"),
BUY("buy", "bought"),
SELL("sell", "sold"),
CONQUER("conquer", "conquered"),
@ -31,4 +34,17 @@ public enum EventFactionsChunkChangeType
this.past = past;
}
// -------------------------------------------- //
// UTIL
// -------------------------------------------- //
public static EventFactionsChunkChangeType get(Faction oldFaction, Faction newFaction, Faction self)
{
if (newFaction == oldFaction) return NONE;
if (oldFaction.isNone()) return BUY;
if (newFaction.isNormal()) return CONQUER;
if (oldFaction == self) return SELL;
return PILLAGE;
}
}

View File

@ -0,0 +1,78 @@
package com.massivecraft.factions.event;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.bukkit.command.CommandSender;
import org.bukkit.event.HandlerList;
import com.massivecraft.factions.entity.BoardColl;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.MUtil;
public class EventFactionsChunksChange extends EventFactionsAbstractSender
{
// -------------------------------------------- //
// REQUIRED EVENT CODE
// -------------------------------------------- //
private static final HandlerList handlers = new HandlerList();
@Override public HandlerList getHandlers() { return handlers; }
public static HandlerList getHandlerList() { return handlers; }
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
private final Set<PS> chunks;
public Set<PS> getChunks() { return this.chunks; }
private final Faction newFaction;
public Faction getNewFaction() { return this.newFaction; }
private final Map<PS, Faction> oldChunkFaction;
public Map<PS, Faction> getOldChunkFaction() { return this.oldChunkFaction; }
private final Map<Faction, Set<PS>> oldFactionChunks;
public Map<Faction, Set<PS>> getOldFactionChunks() { return this.oldFactionChunks; }
private final Map<PS, EventFactionsChunkChangeType> chunkType;
public Map<PS, EventFactionsChunkChangeType> getChunkType() { return this.chunkType; }
private final Map<EventFactionsChunkChangeType, Set<PS>> typeChunks;
public Map<EventFactionsChunkChangeType, Set<PS>> getTypeChunks() { return this.typeChunks; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public EventFactionsChunksChange(CommandSender sender, Set<PS> chunks, Faction newFaction)
{
super(sender);
chunks = PS.getDistinctChunks(chunks);
this.chunks = Collections.unmodifiableSet(chunks);
this.newFaction = newFaction;
this.oldChunkFaction = Collections.unmodifiableMap(BoardColl.getChunkFaction(chunks));
this.oldFactionChunks = Collections.unmodifiableMap(MUtil.reverseIndex(this.oldChunkFaction));
MPlayer msender = this.getMSender();
Faction self = null;
if (msender != null) self = msender.getFaction();
Map<PS, EventFactionsChunkChangeType> currentChunkType = new LinkedHashMap<PS, EventFactionsChunkChangeType>();
for (Entry<PS, Faction> entry : this.oldChunkFaction.entrySet())
{
PS chunk = entry.getKey();
Faction from = entry.getValue();
currentChunkType.put(chunk, EventFactionsChunkChangeType.get(from, newFaction, self));
}
this.chunkType = Collections.unmodifiableMap(currentChunkType);
this.typeChunks = Collections.unmodifiableMap(MUtil.reverseIndex(this.chunkType));
}
}