在“我的世界”中,我一直在制作的插件可以做一些事情,包括在加入时向玩家发送标题。通常它会循环并多次发送标题。到目前为止,它达到的最大的一个是超过10万次。我不知道问题出在哪里。没有任何类型的错误。下面是我的一小段代码:
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;
}
}类main:
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);
}
}如果我遗漏了像变量这样的东西,我很抱歉。提前感谢你的帮助,
光子
另外,对于任何正在寻找代码示例的人,请不要使用这篇文章!(有些东西可能会遗漏)谢谢
发布于 2016-02-06 08:55:16
问题是,在显示磁贴后,您没有取消BukkitRunnable。您应该在显示标题后添加this.cancel();。
https://stackoverflow.com/questions/35235933
复制相似问题