Bukkit头衔问题

时间:2016-02-06 00:44:55

标签: java minecraft bukkit

在“我的世界”中,我一直在制作的插件做了一些事情,包括在加入时向玩家发送标题。通常它会循环并多次发送标题。迄今为止最大的一次超过100,000次。我无法弄清楚问题出在哪里。没有任何错误。这是我的一些代码:

CLASS PLogin:

package me.photon.PLogin;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;

public class OnLogin implements Listener{
    private final main plugin;
public OnLogin(main plugin){
    this.plugin=plugin;
    plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
//Variables----------------------
private String name;
private Player target;
private String world="Spawn2.0";
//End Variables------------------
@EventHandler
private void onJoin(PlayerJoinEvent event){
    new BukkitRunnable(){
        @SuppressWarnings("deprecation")
        @Override
        public void run() {
            if((event.getPlayer() instanceof Player)){
    target=event.getPlayer();
    name=event.getPlayer().getName();
    Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),"sun "+target.getWorld().getName()+" sun");
    Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),"title "+name+" title {text:'"+plugin.getConfig().getString("title")+"';color:"+plugin.getConfig().getString("titlecolor")+"}");
    Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),"title "+name+" subtitle {text:'"+plugin.getConfig().getString("subtitle")+"';color:"+plugin.getConfig().getString("subcolor")+"}");
    if(target.getWorld().getName().equals(world)||target.getWorld().getName().equals("Skyblock")){
        GiveItems gi=new GiveItems(plugin);
        gi.main(target);
    }else{
        for(int i=0;i<target.getInventory().getSize();i++){
            ItemStack ci=target.getInventory().getItem(i);
            GiveItems gi=new GiveItems(plugin);
            System.out.println(ci);
            if(ci.getAmount()>=1&&ci!=null&&(ci==gi.creative()||ci==gi.new_survival()||ci==gi.ninjas()||ci==gi.old_survival()||ci==gi.parkour()||ci==gi.prison()||ci==gi.skyblock()||ci==gi.dcreative()||ci==gi.dnew_survival()||ci==gi.dninjas()||ci==gi.dold_survival()||ci==gi.dparkour()||ci==gi.dprison()||ci==gi.dskyblock())){
                int amt=ci.getAmount();
                ci.setAmount(amt-=1);
                target.updateInventory();
                System.out.println("Deleted "+ci);
            }
        }
    }
    if(!target.hasPlayedBefore()){  
    plugin.getConfig().set("exempt."+name+".exempt", false);
    plugin.saveConfig();
    plugin.reloadConfig();
            }
            }
            if(plugin.getConfig().getBoolean("tp")){
                if(plugin.getConfig().getBoolean("exempt."+name+".exempt")==false){
                    b("tp","spawn");
                }
            }
            this.cancel();
        }
    }.runTaskLater(this.plugin, 20);

}
@SuppressWarnings("unused")
private void a(String msg){
    target.sendMessage(ChatColor.translateAlternateColorCodes('&', msg));
}
private void b(String cmd1, String cmd2){
    Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), cmd1+name+cmd2);
}
public Player getTarget(){
    return target;
}
public String getWorld(){
    return world;
}
}

CLASS主要:

package me.photon.PLogin

//imports

public final class main extends JavaPlugin{
@Override
public void onEnable(){
    this.getConfig().options().copyDefaults(true);
    this.saveConfig();
    this.saveDefaultConfig();
    new OnLogin(this);
}
}

很抱歉,如果我遗漏任何变数。 在此先感谢您的帮助,

光子

P.S。对于任何寻找代码示例的人,请不要使用这篇文章! (有些事情可能会遗漏)谢谢

1 个答案:

答案 0 :(得分:0)

问题是您在显示磁贴后没有取消BukkitRunnable。 您应该在显示标题后添加Reader