Minecraft 插件玩家名称错误

Minecraft plugin player name error

我正在写类似 SRM 的东西,在服务器重置之前一切都很好。当我写一个标志并试图购买它(分配给标志的区域)时,它应该向我发送一条我不能的消息,它确实如此,但在服务器重置后它没有,并且在这两种情况下变量都是一样...这是我的代码:

package pl.maccraft.regs;

import java.util.logging.Logger;

import net.milkbowl.vault.economy.Economy;

import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;

import com.sk89q.worldguard.bukkit.RegionContainer;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;

import org.bukkit.plugin.Plugin;

public final class egs extends JavaPlugin implements Listener {

    private static final Logger log = Logger.getLogger("Minecraft");
    public static Economy econ = null;

    @Override
    public void onEnable() {
        getServer().getPluginManager().registerEvents(this, this);
        getWorldGuard();
        if (!setupEconomy() ) {
            log.severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
            getServer().getPluginManager().disablePlugin(this);
            return;
        }
    }

    private WorldGuardPlugin getWorldGuard() {
        Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");

        // WorldGuard may not be loaded
        if (plugin == null || !(plugin instanceof WorldGuardPlugin)) {
            return null; // Maybe you want throw an exception instead
        }

        return (WorldGuardPlugin) plugin;
    }

    private boolean setupEconomy() {
        if (getServer().getPluginManager().getPlugin("Vault") == null) {
            return false;
        }
        RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
        if (rsp == null) {
            return false;
        }

        econ = rsp.getProvider();
        return econ != null;
    }

    @EventHandler
    public void playerInteract(PlayerInteractEvent event){
        Player player = event.getPlayer();
        if(event.getAction() == org.bukkit.event.block.Action.LEFT_CLICK_BLOCK){
        Block b = event.getClickedBlock();
        if (b.getType() == (Material.SIGN) || b.getType() == (Material.SIGN_POST) || b.getType() == (Material.WALL_SIGN)){
            Sign sign = (Sign) b.getState();
            if (sign.getLine(0).equals("[sell]")){
                if (!sign.getLine(1).isEmpty()){


                RegionContainer container = getWorldGuard().getRegionContainer();
                RegionManager regions = container.get(player.getWorld());
                if (regions != null) {

                    ProtectedRegion region = regions.getRegion(sign.getLine(1));
                    if (region != null) {
                    DefaultDomain owners = region.getOwners();
                    if(owners.contains(player.getUniqueId())){
                        if (!sign.getLine(2).isEmpty()){
                            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "say stan:" + econ.getBalance(player));
                        event.setCancelled(true);
                        player.sendMessage("To jest twój region");
                        sign.setLine(0, ChatColor.DARK_RED + "[sprzedam]");
                        sign.setLine(3, sign.getLine(1));
                        sign.setLine(1, player.getName());
                        sign.update(true);  
                    }else{
                        player.sendMessage("Podaj cenę w trzeciej linii!");
                    }
                    }else{
                        player.sendMessage("To nie jest twój region!");
                    };
                    } else {
                        player.sendMessage("Taki region nie istnieje!");
                    }
                } else {
                    player.sendMessage("Wystąpił błąd, który nie powinien się zdarzyć, powiadom o tym administrację!");
                }


                }else{
                    player.sendMessage("Podaj nazwę regionu w drugiej linii!");
                }   
            }
        }
        }
        if(event.getAction() == org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK){
            Block b = event.getClickedBlock();
            if (b.getType() == (Material.SIGN) || b.getType() == (Material.SIGN_POST) || b.getType() == (Material.WALL_SIGN)){
                Sign sign = (Sign) b.getState();
                if (sign.getLine(0).equals(ChatColor.DARK_RED + "[sprzedam]")){
                    if (event.getPlayer().getName() == sign.getLine(1)){
                        player.sendMessage("nie możesz kupić własnej działki");
                        player.sendMessage(event.getPlayer().getName() + " " + sign.getLine(1));
                    }else{
                        player.sendMessage(event.getPlayer().getName() + " " + sign.getLine(1));
                        Double si = Double.valueOf(sign.getLine(2));
                        if(si <= econ.getBalance(player)){//TO POWINNO BYĆ WIĘKSZE LUB RÓWNE A NIE TAKIE SAMO!!!
                        RegionContainer container = getWorldGuard().getRegionContainer();
                        RegionManager regions = container.get(player.getWorld());

                        if (regions != null) {
                            ProtectedRegion region = regions.getRegion(sign.getLine(3));
                            if (region != null) {
                                Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "eco take " + player.getName() + " " + si);
                                Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "eco give " + sign.getLine(1) + " " + si);
                                Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "rg removeowner " + sign.getLine(3) + " " + sign.getLine(1));
                                Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "rg addowner " + sign.getLine(3) + " " + player.getName());
                                sign.setLine(0, ChatColor.DARK_RED + "[sprzedane]");
                                player.sendMessage("kupiono działkę " + sign.getLine(3) + " za " + si);
                                sign.setLine(1, event.getPlayer().getName());
                                sign.setLine(2, "");
                                sign.setLine(3, "");
                                sign.update(true);
                            }

                        }else{
                            player.sendMessage("wystąpił błąd");
                        }


                        }else{
                            player.sendMessage("Nie masz wystarczająco dużo kasy!");
                        }
                    }
                }
            }
        }


    }

}

和控制台 returns 只有这个:

[12:27:42] [Server thread/INFO]: [0;35;1m[Server[0;35;1m] stan:1000.0[m
[12:28:17] [Server thread/INFO]: CONSOLE issued server command: /eco take 10anat10 1000.0
[12:28:17] [Server thread/INFO]: [0;32;1m00 zostalo pobrane z [0;31;22m10anat10[m[0;32;1m konta. Nowy stan konta: [=11=][m
[12:28:17] [Server thread/INFO]: CONSOLE issued server command: /eco give 10anat10 1000.0
[12:28:17] [Server thread/INFO]: [0;32;1m00 zostalo dodane do konta [0;31;22m10anat10[m§. Nowy stan konta: 00.[m
[12:28:17] [Server thread/INFO]: [0;31;1mPlease specify the world with -w world_name.[m
[12:28:17] [Server thread/INFO]: [0;31;1mPlease specify the world with -w world_name.[m

我知道我没有为 rg addowner 和 removeovner 指定 world,但事实并非如此,日志中也没有更多错误...请帮助我。

当我改变

if(event.getPlayer().getName() == sign.getLine(1)){

RegionContainer container = getWorldGuard().getRegionContainer();
RegionManager regions = container.get(player.getWorld());
if(regions != null){
  ProtectedRegion region = regions.getRegion(sign.getLine(3));
  DefaultDomain owners = region.getOwners();
if(owners.contains(player.getUniqueId())){

它按预期运行。

您需要比较字符串而不是检查对象是否相等。 string1.equals(string2)/string1.equalsIgnoreCase(string2) 比较字符串而 string1 == string2 不比较。

你可以试试这个:

if (event.getPlayer().getName().equals(sign.getLine(1)))

或者如果您不想区分大小写

if (event.getPlayer().getName().equalsIgnoreCase(sign.getLine(1)))