Skip to content

Commit

Permalink
event
Browse files Browse the repository at this point in the history
  • Loading branch information
Angeschossen committed Dec 18, 2023
1 parent 58ef8c6 commit 13059b6
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package me.angeschossen.lands.api.events.land.block;

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

public class LandBlockCreationEvent extends LandBlockEvent {
public static final HandlerList handlerList = new HandlerList();

/**
* Create an instance of this event.
*
* @param landPlayer player that placed the landblock. If null, no player is involved.
* @param landBlock landblock that is being placed
*/
public LandBlockCreationEvent(@Nullable LandPlayer landPlayer, @NotNull LandBlock landBlock) {
super(landBlock.getContainer().getLand(), 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
@@ -0,0 +1,35 @@
package me.angeschossen.lands.api.events.land.block;

import me.angeschossen.lands.api.events.land.LandEvent;
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.Cancellable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public abstract class LandBlockEvent extends LandEvent implements Cancellable {

protected final @NotNull LandBlock landBlock;
protected boolean cancelled;

public LandBlockEvent(@NotNull Land land, @Nullable LandPlayer landPlayer, @NotNull LandBlock landBlock) {
super(land, landPlayer);
this.landBlock = landBlock;
}

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

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

@NotNull
public final LandBlock getLandBlock() {
return landBlock;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package me.angeschossen.lands.api.events.land.block;

import me.angeschossen.lands.api.events.land.LandEvent;
import me.angeschossen.lands.api.events.land.bank.BankEvent;
import me.angeschossen.lands.api.land.Land;
import me.angeschossen.lands.api.land.block.LandBlock;
import me.angeschossen.lands.api.land.block.removalreason.LandBlockRemovalReason;
import me.angeschossen.lands.api.player.LandPlayer;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class LandBlockRemovalEvent extends LandBlockEvent {
public static final HandlerList handlerList = new HandlerList();
private final @NotNull LandBlockRemovalReason reason;

/**
* Create an instance of this event.
*
* @param landPlayer player that initiated the removal. If null, no player is involved.
* @param landBlock landblock that is being removed
* @param reason the reason of the removal
*/
public LandBlockRemovalEvent(@Nullable LandPlayer landPlayer, @NotNull LandBlock landBlock, @NotNull LandBlockRemovalReason reason) {
super(landBlock.getContainer().getLand(), landPlayer, landBlock);

this.reason = reason;
}

/**
* Get the reason of the removal.
*
* @return reason of removal
*/
@NotNull
public final LandBlockRemovalReason getReason() {
return reason;
}

public static HandlerList getHandlerList() {
return handlerList;
}

@Override
public @NotNull HandlerList getHandlers() {
return handlerList;
}
}
21 changes: 21 additions & 0 deletions src/main/java/me/angeschossen/lands/api/land/block/LandBlock.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package me.angeschossen.lands.api.land.block;

import com.github.angeschossen.pluginframework.api.blockutil.impl.BlockPosition;
import me.angeschossen.lands.api.land.Container;
import me.angeschossen.lands.api.land.block.removalreason.LandBlockRemovalReason;
import me.angeschossen.lands.api.player.LandPlayer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* Special blocks that can be placed inside a land.
Expand All @@ -14,6 +18,13 @@ public interface LandBlock {
*/
@NotNull String getId();

/**
* Get the container in which the landblock is placed in.
*
* @return never null. A landblock needs to be placed inside a land
*/
@NotNull Container getContainer();

/**
* Get the center of the structure.
*
Expand All @@ -38,4 +49,14 @@ public interface LandBlock {
* @return type of the block
*/
@NotNull LandBlockType getType();

/**
* @param landPlayer The player that initiated the removal. null, if no player involved.
* @param reason The reason of the removal
* @param done will be executed once all blocks are removed
* @param delayTicks remove a block each x ticks. So if the landblock
* consists of 5 blocks it will take 5 * x ticks to remove the complete landblock.
* @return false, if a 3rd party plugin cancelled the removal of the landblock
*/
boolean remove(@Nullable LandPlayer landPlayer, @NotNull LandBlockRemovalReason reason, @Nullable Runnable done, int delayTicks);
}

0 comments on commit 13059b6

Please sign in to comment.