Minecraft插件播放器名称错误

时间:2015-06-19 10:40:39

标签: java plugins server minecraft bukkit

我正在编写像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!");
                        }
                    }
                }
            }
        }


    }

}

和控制台只返回:

[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;1m$1000 zostalo pobrane z [0;31;22m10anat10[m[0;32;1m konta. Nowy stan konta: $0[m
[12:28:17] [Server thread/INFO]: CONSOLE issued server command: /eco give 10anat10 1000.0
[12:28:17] [Server thread/INFO]: [0;32;1m$1000 zostalo dodane do konta [0;31;22m10anat10[m§. Nowy stan konta: $1000.[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指定世界,但这不是它,并且日志中没有更多错误...请帮助我。

2 个答案:

答案 0 :(得分:1)

当我改变

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())){

它按预期行事。

答案 1 :(得分:1)

您需要比较字符串,而不是检查对象是否相等。 f / var source = $("#entry-template").html(); 比较字符串而string1.equals(string2)没有。

你可以试试这个:

string1.equalsIgnoreCase(string2)

或者如果您不希望区分大小写

string1 == string2