我想使用我的其他课程包括我的主类 / Java Minecraft纸插件上的侦听器
- 我将Gradle用于构建,Java,Minecraft,纸插件
- Ctrl+F,找出
我分别制作了这些插件的“问题”。现在,我将它们放在一个插件中,但将每个班级分开。然后,发生此错误。我想解决这个问题。 我认为thir_function.third_listener
可以用于该位置,但似乎是werng ...
package com;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.GameRule;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
public class mainclass extends JavaPlugin implements Listener {
@Override
public void onEnable() {
getLogger().warning("Server started.");
first_function first = new first_function(this);
first.onEnable();
second_function second = new second_function(this);
second.onEnable();
third_function third = new third_function(this);
third.onEnable();
PlayerJoinEvent third_listener;
third.onPlayerJoin(third_function.third_listener); // the problem. please help me, how can I get rid of this error?
}
}
class first_function implements Listener {
private final mainclass plugin;
first_function(mainclass plugin) {
this.plugin = plugin;
}
void onEnable() {
this.plugin.getLogger().warning("Hello, world!");
}
}
class second_function implements Listener {
private final mainclass plugin;
second_function(mainclass plugin) {
this.plugin = plugin;
}
void onEnable() {
World world = this.plugin.getServer().getWorld("world");
world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, false);
}
}
class third_function implements Listener {
private final mainclass plugin;
third_function(mainclass plugin) {
this.plugin = plugin;
}
Listener third_listener = (this);
void onEnable() {
this.plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler
void onPlayerJoin(PlayerJoinEvent event) {
event.getPlayer().sendActionBar(Component.text("Welcome",(NamedTextColor.BLUE)));
}
}
- I use gradle for build, Java, minecraft, Paper plugin
- ctrl+f , figure out " the problem "
I made each of these plugins separately. Now, I am putting them together into one plugin but separating each class. Then, this error occurred. I want to solve this problem.
I thought third_function.third_listener
could be used for that place, but It seems to be worng...
package com;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.GameRule;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
public class mainclass extends JavaPlugin implements Listener {
@Override
public void onEnable() {
getLogger().warning("Server started.");
first_function first = new first_function(this);
first.onEnable();
second_function second = new second_function(this);
second.onEnable();
third_function third = new third_function(this);
third.onEnable();
PlayerJoinEvent third_listener;
third.onPlayerJoin(third_function.third_listener); // the problem. please help me, how can I get rid of this error?
}
}
class first_function implements Listener {
private final mainclass plugin;
first_function(mainclass plugin) {
this.plugin = plugin;
}
void onEnable() {
this.plugin.getLogger().warning("Hello, world!");
}
}
class second_function implements Listener {
private final mainclass plugin;
second_function(mainclass plugin) {
this.plugin = plugin;
}
void onEnable() {
World world = this.plugin.getServer().getWorld("world");
world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, false);
}
}
class third_function implements Listener {
private final mainclass plugin;
third_function(mainclass plugin) {
this.plugin = plugin;
}
Listener third_listener = (this);
void onEnable() {
this.plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler
void onPlayerJoin(PlayerJoinEvent event) {
event.getPlayer().sendActionBar(Component.text("Welcome",(NamedTextColor.BLUE)));
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该注册听众,而不是尝试自己调用该方法。例如:
另外,我主要建议您使用全局Java名称惯例,例如name
thirdfunction
而不是third_function
例如You should register the listener and not try to call the method yourself. For example:
Also, I mostly suggest you to use global java names convention, such as name
ThirdFunction
instead ofthird_function
for example