PlayerJoinEvent - 创建欢迎消息 Spigot 1.12.2 (Java)
PlayerJoinEvent - Create a welcome message Spigot 1.12.2 (Java)
我不明白为什么他总是returns对我说“你没玩过”然后第一次还好,但第二次我不明白
我想提出一个条件:
如果玩家已经玩过,我什么都不做:没有消息,玩家什么也没收到!
如果玩家从未玩过:欢迎消息+他收到一个物品+我得到他的位置来爆炸烟花
我想添加一个加入第二个条件的玩家的计数器
Commands Class:
package fr.antyss77.pandowelcome;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
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;
public class Commands implements Listener {
private Main main;
@EventHandler
public void PlayerJoin(PlayerJoinEvent e) {
Player player = e.getPlayer();
Location loc = player.getLocation();
boolean hasPlayed = player.hasPlayedBefore();
if (hasPlayed != true) {
player.sendMessage("You've already played !");
} else {
player.sendMessage("You never played !");
player.getInventory().addItem(new ItemStack(Material.SAND, 12));
loc.getWorld().spawnEntity(loc, EntityType.SPLASH_POTION);
}
}
}
Main class:
package fr.antyss77.pandowelcome;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin {
private String color(String arg) {
return ChatColor.translateAlternateColorCodes('&', arg);
}
public void onEnable() {
Bukkit.getConsoleSender().sendMessage(color("&6[&ePandoWelcomer&6] &ehas just started."));
getServer().getPluginManager().registerEvents(new Commands(), this);
}
public void onDisable() {
Bukkit.getConsoleSender().sendMessage(color("&6[&cPandoWelcomer&6] &ehas been shut down."));
}
}
如果有人能帮助我理解我的错误,我将无限感激,提前谢谢!
if (hasPlayed != true)
应该是 if (hasPlayed == true)
,因为它与您想要的相反。
您的代码如下所示:
package fr.antyss77.pandowelcome;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
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;
public class Commands implements Listener {
private Main main;
@EventHandler
public void PlayerJoin(PlayerJoinEvent e) {
Player player = e.getPlayer();
Location loc = player.getLocation();
boolean hasPlayed = player.hasPlayedBefore();
if (hasPlayed == true) {
player.sendMessage("You've already played !");
} else {
player.sendMessage("You never played !");
player.getInventory().addItem(new ItemStack(Material.SAND, 12));
loc.getWorld().spawnEntity(loc, EntityType.SPLASH_POTION);
}
}
}
我不明白为什么他总是returns对我说“你没玩过”然后第一次还好,但第二次我不明白
我想提出一个条件: 如果玩家已经玩过,我什么都不做:没有消息,玩家什么也没收到! 如果玩家从未玩过:欢迎消息+他收到一个物品+我得到他的位置来爆炸烟花 我想添加一个加入第二个条件的玩家的计数器
Commands Class:
package fr.antyss77.pandowelcome;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
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;
public class Commands implements Listener {
private Main main;
@EventHandler
public void PlayerJoin(PlayerJoinEvent e) {
Player player = e.getPlayer();
Location loc = player.getLocation();
boolean hasPlayed = player.hasPlayedBefore();
if (hasPlayed != true) {
player.sendMessage("You've already played !");
} else {
player.sendMessage("You never played !");
player.getInventory().addItem(new ItemStack(Material.SAND, 12));
loc.getWorld().spawnEntity(loc, EntityType.SPLASH_POTION);
}
}
}
Main class:
package fr.antyss77.pandowelcome;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin {
private String color(String arg) {
return ChatColor.translateAlternateColorCodes('&', arg);
}
public void onEnable() {
Bukkit.getConsoleSender().sendMessage(color("&6[&ePandoWelcomer&6] &ehas just started."));
getServer().getPluginManager().registerEvents(new Commands(), this);
}
public void onDisable() {
Bukkit.getConsoleSender().sendMessage(color("&6[&cPandoWelcomer&6] &ehas been shut down."));
}
}
如果有人能帮助我理解我的错误,我将无限感激,提前谢谢!
if (hasPlayed != true)
应该是 if (hasPlayed == true)
,因为它与您想要的相反。
您的代码如下所示:
package fr.antyss77.pandowelcome;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
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;
public class Commands implements Listener {
private Main main;
@EventHandler
public void PlayerJoin(PlayerJoinEvent e) {
Player player = e.getPlayer();
Location loc = player.getLocation();
boolean hasPlayed = player.hasPlayedBefore();
if (hasPlayed == true) {
player.sendMessage("You've already played !");
} else {
player.sendMessage("You never played !");
player.getInventory().addItem(new ItemStack(Material.SAND, 12));
loc.getWorld().spawnEntity(loc, EntityType.SPLASH_POTION);
}
}
}