首先,我想提前道歉,因为考虑到我的编码技能水平,我很可能会打扰很多编码员。
我喜欢编码!这真的让我很开心,我希望能够进步并变得更好但我不能独自完成,至少我认为是这样。
所以这是我在Eclipse上的问题,它一直告诉我,我的线路上有很多错误,但每当我尝试修复它们时(按照很多教程的方式)它都不想修复。 我在想它可能是eclispe程序的漏洞或类似的东西! (或者它可能只是我是一个白痴,不知道如何编码,这两个。)
所以这是我的编码,我正在尝试制作一个欢迎玩家的插件,并给他们一个温暖的信息以及一些免费体验点和一个免费项目。
显然有一个听众,这是我的编码。请告诉我有什么问题!
主:
package me.noobpowah;
import.org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class ServerFunctions extends JavaPlugin {
@Override
public void onEnable() {
new JoinListener(this);
}
@Override
public void onDisable() {
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[ args]) {
if (cmd.getName().equalsIgnoreCase("totalexp") && sender instanceof Player) {
Player player = (Player) sender;
player.sendMessage(ChatColor.GOLD + "Total EXP: " + player.gettotalExperience());
return true;
} else if (cmd.getName().equalsIgnoreCase("exp") && sender instanceof Player) {
Player player = (Player) sender;
player.sendMessage(ChatColor.GOLD + "EXP to next level: " + player.getExpToLevel());
return true;
}
return false;
}
}
听众:
package me.noobpowah;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.ChatColor;
import org.bukkit.inventory;
public class JoinListener {
public JoinListener(ServerFunctions plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler
public void onEvent(BlockPlaceEvent e) {
Player player = e.getPlayer();
e.setJoinMessage(ChatColor.AQUA + "Welcome, " + player.getName() + ", to
the server!");
//If new player
if (player.hasPlayedBefore() == false) {
player.sendMessage(ChatColor.Green + "You seem to be new here aren't
you? Here! Have a free apple as a welcome gift.");
//Adds 1 apple to the player's inventory
player.getInventory().addItem(new ItemStack(Material.APPLE, 1));
}
}
}
`
答案 0 :(得分:0)
<强>解决方案强>
此解决方案只修复了语法错误,并进行了一些导入。
ServerFunctions类
package me.noobpowah;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class ServerFunctions extends JavaPlugin {
@Override
public void onEnable() {
new JoinListener(this);
}
@Override
public void onDisable() {
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("totalexp") && sender instanceof Player) {
Player player = (Player) sender;
player.sendMessage(ChatColor.GOLD + "Total EXP: " + player.getTotalExperience());
return true;
} else if (cmd.getName().equalsIgnoreCase("exp") && sender instanceof Player) {
Player player = (Player) sender;
player.sendMessage(ChatColor.GOLD + "EXP to next level: " + player.getExpToLevel());
return true;
}
return false;
}
}
JoinListener类
package me.noobpowah;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.ChatColor;
import org.bukkit.inventory.ItemStack;
public class JoinListener implements Listener {
public JoinListener(ServerFunctions plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler
public void onEvent(BlockPlaceEvent e) {
Player player = e.getPlayer();
e.setJoinMessage(ChatColor.AQUA + "Welcome, " + player.getName() + ", to the server!");
//If new player
if (player.hasPlayedBefore() == false) {
player.sendMessage(ChatColor.GREEN + "You seem to be new here aren't you? Here! Have a free apple as a welcome gift.");
//Adds 1 apple to the player's inventory
player.getInventory().addItem(new ItemStack(Material.APPLE, 1));
}
}
}