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

添加两个bot事件 #210

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

Lumine1909
Copy link
Contributor

@MC-XiaoHei MC-XiaoHei requested a review from s-yh-china May 5, 2024 04:31
@MC-XiaoHei
Copy link
Member

或许v姐准备1206改包名

@Bluemangoo
Copy link
Member

你先别改包名。

@Lumine1909 Lumine1909 reopened this May 5, 2024
@Lumine1909
Copy link
Contributor Author

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

private String joinMessage;
private Location createLocation;
private boolean cancel = false;
+ private final boolean isAsync;
Copy link
Member

Choose a reason for hiding this comment

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

我没有看明白为什么要存这个。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

防止有人异步操作bukkitapi
BotCreateState有同步和异步两个创建方法 /bot命令是异步创建
监听命令产生的创建事件并使用bkapi可能导致某些问题

有了这个就可以在监听器判断异步,避免上述问题了

Copy link
Member

Choose a reason for hiding this comment

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

举个例子。?

Copy link
Member

Choose a reason for hiding this comment

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

防止有人异步操作bukkitapi BotCreateState有同步和异步两个创建方法 /bot命令是异步创建 监听命令产生的创建事件并使用bkapi可能导致某些问题

有了这个就可以在监听器判断异步,避免上述问题了

这种应该分成两个事件(吧

Copy link
Member

Choose a reason for hiding this comment

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

我没想明白什么情况下会出问题。

当然我觉得最优雅的解法是.then()传入lambda然后创建后调用(写js写的)。

而且应该是创建时而不是发送命令时发事件吧,真的有区别吗。

Copy link
Member

Choose a reason for hiding this comment

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

要不你给我描述下什么场景需要判断是否async做出不同行为。能不能全部按async算。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

建议去翻之前???的聊天记录

给我截一下。

image

image

image

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

要不你给我描述下什么场景需要判断是否async做出不同行为。能不能全部按async算。

举个例子,需要在假人创建时清空附近353的空间并在假人脚下创建一个3*3黑曜石平台

旧版的api根本不知道是否是主线程创建的,而操作世界必须在主线程,否则会有奇奇怪怪的bug和线程安全问题
唯一的解法就是用BukkitRunnable(但是真的所有人都会考虑到这里吗?

当然混用是没问题的,因为就算在同步事件用BkRunnable在下一刻处理也不会有什么大问题(除非有需要精细时序的内容)

Copy link
Member

Choose a reason for hiding this comment

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

那么是否async的处理的区别是什么。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

那么是否async的处理的区别是什么。

像我说的,一旦有精细时序的需要,BkRunnable可能会有问题
你可以去看一下bkapi(尤其是paper),包含异步操作的内容都做了异步事件处理

Copy link
Member

@s-yh-china s-yh-china left a comment

Choose a reason for hiding this comment

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

不应该单独作为一个patch,应该合并回0010-Fakeplayer-support.patch

@Lumine1909 Lumine1909 force-pushed the botapi branch 2 times, most recently from 2a93e5a to 27634dd Compare May 6, 2024 01:09
@MC-XiaoHei
Copy link
Member

MC-XiaoHei commented May 6, 2024

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

@MC-XiaoHei
Copy link
Member

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

而不是单独来一个CreateByPlayerEvent

@Lumine1909
Copy link
Contributor Author

Lumine1909 commented May 6, 2024

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

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

@Lumine1909 Lumine1909 requested a review from s-yh-china May 6, 2024 15:04
@Lumine1909 Lumine1909 changed the title 修改包名为 org.leavesmc.leaves.xxx, 添加两个bot事件 添加两个bot事件 May 6, 2024
@MC-XiaoHei
Copy link
Member

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

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

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

event.getIfSource<Player>(Source.Player)

@s-yh-china
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants