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

[WIP] INTERACT_CAULDRONフラグの実装 #1

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions src/main/java/net/okocraft/moreflags/CustomFlags.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ static void init() {

public static final StateFlag EGG_SPAWN_CHICK = registerFlag(createStateFlag("egg-spawn-chick", true));

public static final StateFlag INTERACT_CAULDRON = registerFlag(createStateFlag("interact-cauldron", true));

@SuppressWarnings("unchecked")
private static <F extends Flag<?>, C extends F> F registerFlag(C flag) {
FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/okocraft/moreflags/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.okocraft.moreflags;

import net.okocraft.moreflags.listener.BeaconEffectListener;
import net.okocraft.moreflags.listener.CauldronLevelChangeListener;
import net.okocraft.moreflags.listener.DeathMessageListener;
import net.okocraft.moreflags.listener.EggSpawnChickListener;
import net.okocraft.moreflags.listener.RaidListener;
Expand Down Expand Up @@ -36,6 +37,7 @@ public void onEnable() {
pm.registerEvents(new WorldGuardInternalListener(), this);
pm.registerEvents(new RaidListener(this), this);
pm.registerEvents(new EggSpawnChickListener(), this);
pm.registerEvents(new CauldronLevelChangeListener(), this);
if (protocolLibHook != null) {
protocolLibHook.registerHandlers();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package net.okocraft.moreflags.listener;

import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.flags.StateFlag;
import net.okocraft.moreflags.CustomFlags;
import net.okocraft.moreflags.util.FlagUtil;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.CauldronLevelChangeEvent;

public class CauldronLevelChangeListener implements Listener {

@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
private void onCauldronLevelChange(CauldronLevelChangeEvent event) {
CauldronLevelChangeEvent.ChangeReason reason = event.getReason();
Entity entity = event.getEntity();

if (entity == null || entity.getType() != EntityType.PLAYER) return;
if (isNaturalInteract(reason)) return;
Comment on lines +24 to +25
Copy link
Author

@jukey17 jukey17 Mar 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

プレイヤーによる操作のみ処理するつもりで弾いているが、これで全てのケースを網羅できているのかは経験値不足で分からず。。
テストワールドで自分ができる最低限の操作のみでイベントの発火は確認しました


Block block = event.getBlock();
LocalPlayer player = WorldGuardPlugin.inst().wrapPlayer((Player) entity);
StateFlag.State state = FlagUtil.queryValue(block.getWorld(), block.getLocation(), player, CustomFlags.INTERACT_CAULDRON);
if (state == StateFlag.State.DENY) {
event.setCancelled(true);
}
}

private boolean isNaturalInteract(CauldronLevelChangeEvent.ChangeReason reason) {
return reason == CauldronLevelChangeEvent.ChangeReason.EXTINGUISH || reason == CauldronLevelChangeEvent.ChangeReason.EVAPORATE || reason == CauldronLevelChangeEvent.ChangeReason.NATURAL_FILL;
}
}