LeavesMC / Leaves

Fork of Paper aimed at repairing broken vanilla properties.
https://leavesmc.org
Other
325 stars 34 forks source link

Enhanced bot api #210

Closed Lumine1909 closed 6 days ago

Lumine1909 commented 2 months ago

重写BotCreateEvent 添加BotRemoveEvent

MC-XiaoHei commented 2 months ago

或许v姐准备1206改包名

Bluemangoo commented 2 months ago

你先别改包名。

Lumine1909 commented 2 months ago

删掉了包名更改,添加了一些实现上的变动(

MC-XiaoHei commented 2 months ago

或许在BotCreateEvent中添加Source Enum类去标明创建来源会更具有可拓展性 例如分为API,Player,Console等

MC-XiaoHei commented 2 months ago

或许在BotCreateEvent中添加Source Enum类去标明创建来源会更具有可拓展性 例如分为API,Player,Console等

而不是单独来一个CreateByPlayerEvent

Lumine1909 commented 2 months ago

或许在BotCreateEvent中添加Source Enum类去标明创建来源会更具有可拓展性 例如分为API,Player,Console等

而不是单独来一个CreateByPlayerEvent 收到,确实是更好的想法 (edit) 我又想了一下,如果这样的话又变的麻烦了,监听玩家创建需要先判断是否来自玩家再获取,否则还有可能产生npe或者cce 看v姐怎么想吧(

MC-XiaoHei commented 2 months ago

或许在BotCreateEvent中添加Source Enum类去标明创建来源会更具有可拓展性 例如分为API,Player,Console等

而不是单独来一个CreateByPlayerEvent 收到,确实是更好的想法 (edit) 我又想了一下,如果这样的话又变的麻烦了,监听玩家创建需要先判断是否来自玩家再获取,否则还有可能产生npe或者cce 看v姐怎么想吧(

我认为这样是正确的,或许可以

event.getIfSource<Player>(Source.Player)
s-yh-china commented 1 month ago

为什么不直接用已有的ConsoleSender和Player来区分呢

MC-XiaoHei commented 1 week ago

为什么不直接用已有的ConsoleSender和Player来区分呢

因为不一定是sender创建的 可能是api

Lumine1909 commented 1 week ago

conflict了 等1.21release我再开始搞吧( 外群来的不要急qwq 现在可以用小黑的方法 监听CommandPreProcess事件然后处理即可

Lumine1909 commented 6 days ago

新的版本加了reason和xxer两个字段 现在可以直接用类似bukkit command的形式判断了

    private final Map<String, UUID> botOwnerMap = new HashMap<>();
    @EventHandler
    public void onBotCreate(BotCreateEvent e) {
        if (e.getCreator().isPresent() && e.getCreator().get() instanceof Player player) {
            botOwnerMap.put(e.getBot(), player.getUniqueId());
        }
    }
    @EventHandler
    public void onBotRemove(BotRemoveEvent e) {
        if (e.getRemover().isPresent() && e.getRemover().get() instanceof Player player) {
            if (!botOwnerMap.get(e.getBot().getName()).equals(player.getUniqueId())) {
                player.sendMessage(ChatColor.RED + "You can't remove it because it is not your bot!");
            }
        }
    }