use of me.andrew28.addons.conquer.api.ConquerPlayer 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);
}
}
use of me.andrew28.addons.conquer.api.ConquerPlayer 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.ConquerPlayer in project Conquer by xXAndrew28Xx.
the class MSEventForwarder method onPowerChange.
@EventHandler
public void onPowerChange(EventFactionsPowerChange event) {
ConquerPlayer player = MSPlayer.get(plugin, event.getMPlayer());
double oldPower = player.getPower();
double newPower = event.getNewPower();
if (newPower < oldPower) {
ConquerPowerLossEvent forwardEvent = new ConquerPowerLossEvent(player.getFaction(), player);
callEvent(forwardEvent);
if (forwardEvent.isCancelled()) {
event.setCancelled(true);
}
}
}
use of me.andrew28.addons.conquer.api.ConquerPlayer in project Conquer by xXAndrew28Xx.
the class ExprFactionOfPlayer method change.
@Override
public void change(Event e, Object[] delta, Changer.ChangeMode mode) {
ConquerPlayer[] players = getExpr().getArray(e);
if (players == null) {
return;
}
ConquerFaction faction = null;
if (mode == Changer.ChangeMode.SET) {
if (delta == null || delta.length == 0) {
return;
}
faction = (ConquerFaction) delta[0];
}
for (ConquerPlayer player : players) {
if (player == null) {
continue;
}
player.setFaction(faction);
}
}
use of me.andrew28.addons.conquer.api.ConquerPlayer in project Conquer by xXAndrew28Xx.
the class ExprMembersOfFaction method get.
@Override
protected ConquerPlayer[] get(Event e) {
Set<ConquerPlayer> players = new HashSet<>();
ConquerFaction[] factions = this.factions.getArray(e);
for (ConquerFaction faction : factions) {
if (faction == null) {
continue;
}
players.addAll(Arrays.asList(faction.getMembers()));
}
return players.toArray(new ConquerPlayer[players.size()]);
}
Aggregations