我想使用我的其他课程包括我的主类 / Java Minecraft纸插件上的侦听器

发布于 2025-02-05 08:38:07 字数 2213 浏览 2 评论 0原文

  • 我将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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

握住我的手 2025-02-12 08:38:08

您应该注册听众,而不是尝试自己调用该方法。例如:

@Override
public void onEnable() {
    third_function third = new third_function(this);
    getServer().getPluginManager().registerEvents(third, this);
}

另外,我主要建议您使用全局Java名称惯例,例如name thirdfunction而不是third_function例如

You should register the listener and not try to call the method yourself. For example:

@Override
public void onEnable() {
    third_function third = new third_function(this);
    getServer().getPluginManager().registerEvents(third, this);
}

Also, I mostly suggest you to use global java names convention, such as name ThirdFunction instead of third_function for example

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文