use of me.andrew28.addons.conquer.api.ConquerClaim in project Conquer by xXAndrew28Xx.
the class EffChangeClaimOwnership method execute.
@Override
protected void execute(Event e) {
Object[] claimObjects = this.claims.getArray(e);
if (claimObjects == null) {
return;
}
List<ConquerClaim> claims = new ArrayList<>();
for (Object claimObject : claimObjects) {
if (claimObject instanceof ConquerClaim) {
claims.add((ConquerClaim) claimObject);
} else if (claimObject instanceof Location) {
claims.add(Conquer.getInstance().getFactions().getClaim((Location) claimObject));
}
}
if (claiming) {
if (forFactions) {
ConquerFaction faction = (ConquerFaction) this.type.getSingle(e);
if (faction == null) {
return;
}
claims.forEach(faction::claim);
} else {
ClaimType type = (ClaimType) this.type.getSingle(e);
if (type == null) {
return;
}
claims.forEach(claim -> claim.setTo(type));
}
} else {
claims.forEach(claim -> claim.setTo(ClaimType.WILDERNESS));
}
}
use of me.andrew28.addons.conquer.api.ConquerClaim in project Conquer by xXAndrew28Xx.
the class ExprTypeOfClaim method change.
@Override
public void change(Event e, Object[] delta, Changer.ChangeMode mode) {
ConquerClaim[] claims = getExpr().getArray(e);
if (claims == null) {
return;
}
ClaimType type = ClaimType.WILDERNESS;
if (mode == Changer.ChangeMode.SET) {
if (delta == null || delta.length == 0) {
return;
}
type = (ClaimType) delta[0];
if (type == null) {
type = ClaimType.WILDERNESS;
}
}
for (ConquerClaim claim : claims) {
if (claim == null) {
continue;
}
claim.setTo(type);
}
}
use of me.andrew28.addons.conquer.api.ConquerClaim 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;
}
}
}
use of me.andrew28.addons.conquer.api.ConquerClaim 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()]);
}
use of me.andrew28.addons.conquer.api.ConquerClaim 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()]);
}
Aggregations