覆盖 WorldGuard 标志

Override WorldGuard flag

我正在开发一个插件,允许玩家在带有 PVP: deny 标志的 WorldGuard 区域进行 PVP,但仅当特定条件为真时。

我已经尝试过: - 将 priority 设置为 HIGHEST - 设置 event.setCancelled(false)

我是 Bukkit 编程的新手,所以我还不是很熟悉这些功能。

问:是否可以为玩家攻击者临时设置WorldGuard绕过权限?我怎样才能做到这一点?我试过了,没成功。

问题2:是否可以取消发送"You can't PvP here!"消息的WorldGuard事件?

@EventHandler(priority=EventPriority.HIGHEST)
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
    Player attacker = (Player) event.getDamager();

    if(!conditionIsTrue) {
        event.setCancelled(true);
    }
    else {
        event.setCancelled(false);
    }
} // onEntityDamageByEntity

感谢您花时间帮助我。

问题 1 的答案:根据你所说的 Bukkit 新手,我会说不,这是不可能的。实现这一点的唯一方法是反编译WorldGuard,在你想控制的部分添加一个if语句,使这个if语句依赖于服务器上的一个全局变量,然后重新编译并保存。然后,您将在插件中编辑此全局变量(例如 PlayerMetaFixedMetaDataValues)。

问题 2 的答案:同样,这需要您进行反编译、编辑和重新编译。尽管这会简单得多,因为您为此真正要做的就是删除 sender.sendMessage("You can't pvp here"); part of the code.

P.S: 你应该检查是否有这个插件的配置文件,因为如果有我会说它可能有一个设置来关闭这个 PvP 消息

我做了更多的研究,因为没有找到有用的答案。


问题一:是否可以为玩家攻击者临时设置WorldGuard绕过权限?

答:可以,但不推荐。取消 WorldGuard 事件更容易。


问题 2: 是否可以取消发送 "You can't PvP here!" 消息的 WorldGuard 事件?

回答:是的,取消onDisallowedPVPEvent将停止阻止PVP和消息。


代码:

@EventHandler
public void onDisallowPvpEvent(DisallowedPVPEvent event) {
    if(//condition) {
        event.setCancelled(true);
    }
}