Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LockEntityEvent #134

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions bukkit/src/main/java/org/popcraft/bolt/event/LockEntityEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.popcraft.bolt.event;

import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;

public class LockEntityEvent extends Cancellable implements Event {
private final Player player;
private final Entity entity;

public LockEntityEvent(Player player, Entity entity) {
this.player = player;
this.entity = entity;
}

public Player getPlayer() {
return this.player;
}

public Entity getEntity() {
return this.entity;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import org.bukkit.entity.Player;
import org.popcraft.bolt.BoltPlugin;
import org.popcraft.bolt.access.Access;
import org.popcraft.bolt.event.Cancellable;
import org.popcraft.bolt.event.LockBlockEvent;
import org.popcraft.bolt.event.LockEntityEvent;
import org.popcraft.bolt.lang.Translation;
import org.popcraft.bolt.protection.Protection;
import org.popcraft.bolt.util.Action;
Expand Down Expand Up @@ -62,18 +64,23 @@ private boolean triggerAction(final Player player, final Protection protection,
final Action.Type actionType = action.getType();
switch (actionType) {
case LOCK -> {
final Cancellable event;
if (object instanceof final Block block) {
final LockBlockEvent event = new LockBlockEvent(player, block);
plugin.getEventBus().post(event);
if (event.isCancelled()) {
BoltComponents.sendMessage(
player,
Translation.CLICK_LOCKED_CANCELLED,
plugin.isUseActionBar(),
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(block, player))
);
break;
}
event = new LockBlockEvent(player, block);
} else if (object instanceof final Entity entity) {
event = new LockEntityEvent(player, entity);
} else {
throw new IllegalStateException("Protection is not a block or entity");
}
plugin.getEventBus().post(event);
if (event.isCancelled()) {
BoltComponents.sendMessage(
player,
Translation.CLICK_LOCKED_CANCELLED,
plugin.isUseActionBar(),
Placeholder.component(Translation.Placeholder.PROTECTION, displayName)
);
break;
}
final String protectionType = Optional.ofNullable(action.getData())
.flatMap(type -> plugin.getBolt().getAccessRegistry().getProtectionByType(type))
Expand Down