Skip to content

Commit

Permalink
events
Browse files Browse the repository at this point in the history
  • Loading branch information
Angeschossen committed Nov 11, 2024
1 parent 3755564 commit f027042
Show file tree
Hide file tree
Showing 8 changed files with 239 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public ChunkCoordinate(int x, int z) {
this.z = z;
this.hashcode = Objects.hash(x, z);
}

@Override
public boolean equals(Object object) {
if (!(object instanceof me.angeschossen.lands.api.land.ChunkCoordinate)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package me.angeschossen.lands.api.events.land.block;

import me.angeschossen.lands.api.land.Land;
import me.angeschossen.lands.api.land.block.LandBlock;
import me.angeschossen.lands.api.player.LandPlayer;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* Called whenever a player interacts with a mainblock or caputeflag etc.
* Landblock types: {@link me.angeschossen.lands.api.land.block.LandBlockType}
*/
public class LandBlockInteractEvent extends LandBlockEvent{
public static final HandlerList handlerList = new HandlerList();

public LandBlockInteractEvent(@NotNull Land land, @Nullable LandPlayer landPlayer, @NotNull LandBlock landBlock) {
super(land, landPlayer, landBlock);
}

public static HandlerList getHandlerList() {
return handlerList;
}

@Override
public @NotNull HandlerList getHandlers() {
return handlerList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* Called when a land block is placed. This will also be fired for the auto placed mainblock at land creation.
* Landblock types: {@link me.angeschossen.lands.api.land.block.LandBlockType}
*/
public class LandBlockPlaceEvent extends LandBlockEvent {
public static final HandlerList handlerList = new HandlerList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* Called when a land block is removed. This is called for blocks such as capture flags or mainblocks.
* Landblock types: {@link me.angeschossen.lands.api.land.block.LandBlockType}
*/
public class LandBlockRemoveEvent extends LandBlockEvent {
public static final HandlerList handlerList = new HandlerList();
private final @NotNull LandBlockRemovalReason reason;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package me.angeschossen.lands.api.events.memberholder;

import com.github.angeschossen.pluginframework.api.utils.Checks;
import com.google.common.collect.ImmutableMap;
import me.angeschossen.lands.api.memberholder.MemberHolder;
import me.angeschossen.lands.api.relations.Relation;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.UUID;

/**
* Called whenever the relationship between lands or nations changes.
*/
public class MemberHolderRelationChangedEvent extends MemberHolderEvent implements Cancellable {

public static final HandlerList handlerList = new HandlerList();

private final @NotNull MemberHolder target;
private final @NotNull Relation relation;
private boolean cancelled;

/**
* Create instance of this event.
*
* @param initiator land or nation that initiated the change
* @param target the target land or nation
* @param relation the new relation status
*/
public MemberHolderRelationChangedEvent(@NotNull MemberHolder initiator, @NotNull MemberHolder target, @NotNull Relation relation) {
super(initiator);

this.target = Checks.requireNonNull(target, "target");
this.relation = Checks.requireNonNull(relation, "relation");
}

@Override
public boolean isCancelled() {
return cancelled;
}

@Override
public void setCancelled(boolean b) {
this.cancelled = b;
}

/**
* Get the current relation.
*
* @return current relation between the two
*/
public @NotNull Relation getCurrentRelation() {
return memberHolder.getRelation(target);
}

/**
* Get the new relation.
*
* @return the new relation between the two
*/
public @NotNull Relation getNewRelation() {
return relation;
}

/**
* Get the target of the change.
*
* @return never null
*/
public @NotNull MemberHolder getTarget() {
return target;
}

public static HandlerList getHandlerList() {
return handlerList;
}

@Override
public @NotNull HandlerList getHandlers() {
return handlerList;
}

@Override
public void setExpressionVariables(ImmutableMap.@NotNull Builder<String, Object> builder) {
super.setExpressionVariables(builder);

target.setExpressionVariables("target_" + target.getExpressionPrefix(), builder, null);
}

@Override
public void setAffectedPlayers(ImmutableMap.@NotNull Builder<String, Collection<UUID>> builder) {
super.setAffectedPlayers(builder);

target.setAffectedPlayers("target_" + target.getExpressionPrefix(), builder);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package me.angeschossen.lands.api.events.player.role;

import com.github.angeschossen.pluginframework.api.utils.Checks;
import com.google.common.collect.ImmutableMap;
import me.angeschossen.lands.api.events.role.RoleEvent;
import me.angeschossen.lands.api.player.LandPlayer;
import me.angeschossen.lands.api.role.Role;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.UUID;

/**
* Called whenever a player toggles a role flag.
*/
public class PlayerToggleRoleFlagEvent extends RoleEvent implements Cancellable {
public static final HandlerList handlerList = new HandlerList();
private final @NotNull LandPlayer landPlayer;
private boolean cancelled;

/**
* Create instance of this event.
*
* @param role role for which the flag is changed
* @param landPlayer the player that changes the state
*/
public PlayerToggleRoleFlagEvent(@NotNull Role role, @NotNull LandPlayer landPlayer) {
super(role);

this.landPlayer = Checks.requireNonNull(landPlayer, "landPlayer");
}

/**
* Get the player.
* @return player that toggles the flag
*/
public @NotNull LandPlayer getLandPlayer() {
return landPlayer;
}

@Override
public @NotNull HandlerList getHandlers() {
return handlerList;
}

@Override
public boolean isCancelled() {
return cancelled;
}

@Override
public void setCancelled(boolean b) {
this.cancelled = b;
}

@Override
public void setAffectedPlayers(ImmutableMap.@NotNull Builder<String, Collection<UUID>> builder) {
landPlayer.setAffectedPlayers("player_", builder);
}
}
33 changes: 33 additions & 0 deletions src/main/java/me/angeschossen/lands/api/events/role/RoleEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package me.angeschossen.lands.api.events.role;

import com.github.angeschossen.pluginframework.api.utils.Checks;
import com.google.common.collect.ImmutableMap;
import me.angeschossen.lands.api.events.plugin.LandsEvent;
import me.angeschossen.lands.api.role.Role;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.UUID;

public abstract class RoleEvent extends LandsEvent {
protected final @NotNull Role role;

protected RoleEvent(@NotNull Role role) {
this.role = Checks.requireNonNull(role, "role");
}

/**
* Get the role.
*
* @return role affected by this event
*/
public @NotNull Role getRole() {
return role;
}

@Override
public void setExpressionVariables(ImmutableMap.@NotNull Builder<String, Object> builder) {
role.setExpressionVariables("role_", builder, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,14 @@ public interface MemberHolder extends BalanceHolder, ExpressionEntity, CMDTarget
*/
boolean isEnemy(@NotNull MemberHolder memberHolder);

/**
* Get the relationship between lands or nations.
*
* @param memberHolder the other land or nation
* @return never null
*/
@NotNull Relation getRelation(@NotNull MemberHolder memberHolder);

/**
* Check if they're in an active war.
*
Expand Down

0 comments on commit f027042

Please sign in to comment.