Search in sources :

Example 16 with ConquerFaction

use of me.andrew28.addons.conquer.api.ConquerFaction in project Conquer by xXAndrew28Xx.

the class MSEventForwarder method onClaimChange.

@EventHandler
public void onClaimChange(EventFactionsChunksChange event) {
    ConquerFaction faction = MSFaction.get(plugin, event.getNewFaction());
    ConquerPlayer player = MSPlayer.get(plugin, event.getMPlayer());
    Set<PS> chunks = event.getChunks();
    Map<PS, EventFactionsChunkChangeType> chunkTypeMap = event.getChunkType();
    // Check if it's an unclaim all
    if (chunks.size() == faction.getClaims().length && chunkTypeMap.values().stream().allMatch(type -> type == EventFactionsChunkChangeType.SELL)) {
        ConquerUnclaimAllEvent forwardEvent = new ConquerUnclaimAllEvent(faction, player);
        callEvent(forwardEvent);
        if (forwardEvent.isCancelled()) {
            event.setCancelled(true);
        }
    }
    for (PS chunk : chunks) {
        EventFactionsChunkChangeType type = chunkTypeMap.get(chunk);
        ConquerClaim claim = MSClaim.get(plugin, chunk);
        Event forwardEvent;
        switch(type) {
            case NONE:
                continue;
            case BUY:
                forwardEvent = new ConquerLandClaimEvent(claim, true, faction, player);
                break;
            case CONQUER:
            case PILLAGE:
                forwardEvent = new ConquerLandClaimEvent(claim, false, faction, player);
                break;
            default:
                return;
        }
        callEvent(forwardEvent);
        if (((Cancellable) forwardEvent).isCancelled()) {
            event.setCancelled(true);
            return;
        }
    }
}
Also used : EventForwarder(me.andrew28.addons.conquer.api.EventForwarder) Cancellable(org.bukkit.event.Cancellable) ConquerUnclaimAllEvent(me.andrew28.addons.conquer.api.events.ConquerUnclaimAllEvent) EventFactionsCreate(com.massivecraft.factions.event.EventFactionsCreate) EventFactionsRelationChange(com.massivecraft.factions.event.EventFactionsRelationChange) Event(org.bukkit.event.Event) ConquerFactionRelationEvent(me.andrew28.addons.conquer.api.events.ConquerFactionRelationEvent) EventHandler(org.bukkit.event.EventHandler) EventFactionsDisband(com.massivecraft.factions.event.EventFactionsDisband) ConquerClaim(me.andrew28.addons.conquer.api.ConquerClaim) Map(java.util.Map) EventFactionsMembershipChange(com.massivecraft.factions.event.EventFactionsMembershipChange) ConquerFactionLeaveEvent(me.andrew28.addons.conquer.api.events.ConquerFactionLeaveEvent) ConquerFaction(me.andrew28.addons.conquer.api.ConquerFaction) ConquerPowerLossEvent(me.andrew28.addons.conquer.api.events.ConquerPowerLossEvent) EventFactionsChunkChangeType(com.massivecraft.factions.event.EventFactionsChunkChangeType) ConquerFactionDisbandEvent(me.andrew28.addons.conquer.api.events.ConquerFactionDisbandEvent) Relation(me.andrew28.addons.conquer.api.Relation) PS(com.massivecraft.massivecore.ps.PS) ConquerFactionRelationWishEvent(me.andrew28.addons.conquer.api.events.ConquerFactionRelationWishEvent) ConquerLandClaimEvent(me.andrew28.addons.conquer.api.events.ConquerLandClaimEvent) EventFactionsPowerChange(com.massivecraft.factions.event.EventFactionsPowerChange) Set(java.util.Set) ConquerFactionJoinEvent(me.andrew28.addons.conquer.api.events.ConquerFactionJoinEvent) EventFactionsChunksChange(com.massivecraft.factions.event.EventFactionsChunksChange) ConquerPlayer(me.andrew28.addons.conquer.api.ConquerPlayer) ConquerFactionCreateEvent(me.andrew28.addons.conquer.api.events.ConquerFactionCreateEvent) PS(com.massivecraft.massivecore.ps.PS) ConquerFaction(me.andrew28.addons.conquer.api.ConquerFaction) Cancellable(org.bukkit.event.Cancellable) ConquerUnclaimAllEvent(me.andrew28.addons.conquer.api.events.ConquerUnclaimAllEvent) Event(org.bukkit.event.Event) ConquerFactionRelationEvent(me.andrew28.addons.conquer.api.events.ConquerFactionRelationEvent) ConquerFactionLeaveEvent(me.andrew28.addons.conquer.api.events.ConquerFactionLeaveEvent) ConquerPowerLossEvent(me.andrew28.addons.conquer.api.events.ConquerPowerLossEvent) ConquerFactionDisbandEvent(me.andrew28.addons.conquer.api.events.ConquerFactionDisbandEvent) ConquerFactionRelationWishEvent(me.andrew28.addons.conquer.api.events.ConquerFactionRelationWishEvent) ConquerLandClaimEvent(me.andrew28.addons.conquer.api.events.ConquerLandClaimEvent) ConquerFactionJoinEvent(me.andrew28.addons.conquer.api.events.ConquerFactionJoinEvent) ConquerFactionCreateEvent(me.andrew28.addons.conquer.api.events.ConquerFactionCreateEvent) ConquerUnclaimAllEvent(me.andrew28.addons.conquer.api.events.ConquerUnclaimAllEvent) ConquerLandClaimEvent(me.andrew28.addons.conquer.api.events.ConquerLandClaimEvent) ConquerPlayer(me.andrew28.addons.conquer.api.ConquerPlayer) ConquerClaim(me.andrew28.addons.conquer.api.ConquerClaim) EventFactionsChunkChangeType(com.massivecraft.factions.event.EventFactionsChunkChangeType) EventHandler(org.bukkit.event.EventHandler)

Example 17 with ConquerFaction

use of me.andrew28.addons.conquer.api.ConquerFaction in project Conquer by xXAndrew28Xx.

the class MSEventForwarder method onMembershipChange.

@EventHandler
public void onMembershipChange(EventFactionsMembershipChange event) {
    ConquerFaction faction = MSFaction.get(plugin, event.getNewFaction());
    ConquerPlayer player = MSPlayer.get(plugin, event.getMPlayer());
    Event forwardEvent;
    switch(event.getReason()) {
        case JOIN:
        case CREATE:
            forwardEvent = new ConquerFactionJoinEvent(faction, player);
            break;
        case LEAVE:
        case KICK:
        case DISBAND:
            forwardEvent = new ConquerFactionLeaveEvent(faction, player);
            break;
        default:
            return;
    }
    callEvent(forwardEvent);
    if (((Cancellable) forwardEvent).isCancelled()) {
        event.setCancelled(true);
    }
}
Also used : ConquerFaction(me.andrew28.addons.conquer.api.ConquerFaction) ConquerFactionJoinEvent(me.andrew28.addons.conquer.api.events.ConquerFactionJoinEvent) Cancellable(org.bukkit.event.Cancellable) ConquerUnclaimAllEvent(me.andrew28.addons.conquer.api.events.ConquerUnclaimAllEvent) Event(org.bukkit.event.Event) ConquerFactionRelationEvent(me.andrew28.addons.conquer.api.events.ConquerFactionRelationEvent) ConquerFactionLeaveEvent(me.andrew28.addons.conquer.api.events.ConquerFactionLeaveEvent) ConquerPowerLossEvent(me.andrew28.addons.conquer.api.events.ConquerPowerLossEvent) ConquerFactionDisbandEvent(me.andrew28.addons.conquer.api.events.ConquerFactionDisbandEvent) ConquerFactionRelationWishEvent(me.andrew28.addons.conquer.api.events.ConquerFactionRelationWishEvent) ConquerLandClaimEvent(me.andrew28.addons.conquer.api.events.ConquerLandClaimEvent) ConquerFactionJoinEvent(me.andrew28.addons.conquer.api.events.ConquerFactionJoinEvent) ConquerFactionCreateEvent(me.andrew28.addons.conquer.api.events.ConquerFactionCreateEvent) ConquerPlayer(me.andrew28.addons.conquer.api.ConquerPlayer) ConquerFactionLeaveEvent(me.andrew28.addons.conquer.api.events.ConquerFactionLeaveEvent) EventHandler(org.bukkit.event.EventHandler)

Example 18 with ConquerFaction

use of me.andrew28.addons.conquer.api.ConquerFaction in project Conquer by xXAndrew28Xx.

the class EffInvitePlayer method execute.

@Override
protected void execute(Event e) {
    ConquerPlayer[] players = this.players.getArray(e);
    ConquerFaction[] factions = this.factions.getArray(e);
    if (players == null || factions == null) {
        return;
    }
    for (ConquerPlayer player : players) {
        if (player == null) {
            continue;
        }
        for (ConquerFaction faction : factions) {
            if (faction == null) {
                continue;
            }
            if (invite) {
                faction.invite(player);
            } else {
                faction.deinvite(player);
            }
        }
    }
}
Also used : ConquerFaction(me.andrew28.addons.conquer.api.ConquerFaction) ConquerPlayer(me.andrew28.addons.conquer.api.ConquerPlayer)

Example 19 with ConquerFaction

use of me.andrew28.addons.conquer.api.ConquerFaction in project Conquer by xXAndrew28Xx.

the class ExprClaimsOfFaction method get.

@Override
protected ConquerClaim[] get(Event e) {
    List<ConquerClaim> claims = new ArrayList<>();
    ConquerFaction[] factions = this.factions.getArray(e);
    for (ConquerFaction faction : factions) {
        if (faction == null) {
            continue;
        }
        claims.addAll(Arrays.asList(faction.getClaims()));
    }
    return claims.toArray(new ConquerClaim[claims.size()]);
}
Also used : ConquerFaction(me.andrew28.addons.conquer.api.ConquerFaction) ArrayList(java.util.ArrayList) ConquerClaim(me.andrew28.addons.conquer.api.ConquerClaim)

Example 20 with ConquerFaction

use of me.andrew28.addons.conquer.api.ConquerFaction in project Conquer by xXAndrew28Xx.

the class ExprFactionAtLocClaim method get.

@Override
protected ConquerFaction[] get(Event e) {
    Set<ConquerFaction> factions = new HashSet<>();
    FactionResolver factionResolver = Conquer.getInstance().getFactions().getFactionResolver();
    Object[] claimObjects = this.targets.getArray(e);
    if (claimObjects == null) {
        return null;
    }
    for (Object claimObject : claimObjects) {
        if (claimObject instanceof ConquerClaim) {
            factions.add(factionResolver.getByClaim((ConquerClaim) claimObject));
        } else if (claimObject instanceof Location) {
            factions.add(factionResolver.getAtLocation((Location) claimObject));
        }
    }
    return factions.toArray(new ConquerFaction[factions.size()]);
}
Also used : FactionResolver(me.andrew28.addons.conquer.api.FactionResolver) ConquerFaction(me.andrew28.addons.conquer.api.ConquerFaction) ConquerClaim(me.andrew28.addons.conquer.api.ConquerClaim) HashSet(java.util.HashSet) Location(org.bukkit.Location)

Aggregations

ConquerFaction (me.andrew28.addons.conquer.api.ConquerFaction)35 ConquerPlayer (me.andrew28.addons.conquer.api.ConquerPlayer)11 EventHandler (org.bukkit.event.EventHandler)7 Relation (me.andrew28.addons.conquer.api.Relation)6 ArrayList (java.util.ArrayList)5 ConquerFactionRelationEvent (me.andrew28.addons.conquer.api.events.ConquerFactionRelationEvent)5 ConquerFactionRelationWishEvent (me.andrew28.addons.conquer.api.events.ConquerFactionRelationWishEvent)5 ConquerClaim (me.andrew28.addons.conquer.api.ConquerClaim)4 Location (org.bukkit.Location)4 HashSet (java.util.HashSet)3 ConquerLandClaimEvent (me.andrew28.addons.conquer.api.events.ConquerLandClaimEvent)3 ConquerPowerLossEvent (me.andrew28.addons.conquer.api.events.ConquerPowerLossEvent)3 Event (org.bukkit.event.Event)3 Map (java.util.Map)2 FactionResolver (me.andrew28.addons.conquer.api.FactionResolver)2 ConquerFactionCreateEvent (me.andrew28.addons.conquer.api.events.ConquerFactionCreateEvent)2 ConquerFactionDisbandEvent (me.andrew28.addons.conquer.api.events.ConquerFactionDisbandEvent)2 ConquerFactionJoinEvent (me.andrew28.addons.conquer.api.events.ConquerFactionJoinEvent)2 ConquerFactionLeaveEvent (me.andrew28.addons.conquer.api.events.ConquerFactionLeaveEvent)2 ConquerUnclaimAllEvent (me.andrew28.addons.conquer.api.events.ConquerUnclaimAllEvent)2