package me.san33der.pvp;
import java.util.Random;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import me.san33der.pvp.listeners;
public class Main extends JavaPlugin {
private static Main instance;
public void log(String string) {
}
public static Main getInstance() {
return instance;
}
public void registerListeners() {
PluginManager pm = getServer().getPluginManager();
pm.registerEvents(new listeners(this), this);
}
public void registerCommands() {
// not used yet
}
@Override
public void onEnable() {
getLogger().info("has been enabled");
instance = this;
registerListeners();
registerCommands();
}
@Override
public void onDisable() {
getLogger().info("has been disabled");
instance = null;
}
// commands
@Override
public boolean onCommand(CommandSender sender, Command cmd, String commendlabel, String[] args) {
// starter command
if (cmd.getName().equalsIgnoreCase("starter") && sender instanceof Player) {
Player p = (Player) sender;
p.getInventory().clear();
ItemStack starterbow = new ItemStack(Material.BOW);
ItemMeta m = starterbow.getItemMeta();
m.setDisplayName(ChatColor.GREEN + "starterbow");
starterbow.setItemMeta(m);
starterbow.addEnchantment(Enchantment.ARROW_FIRE, 1);
starterbow.addEnchantment(Enchantment.ARROW_INFINITE, 1);
p.getInventory().addItem(starterbow);
p.getInventory().addItem(new ItemStack(Material.ARROW));
p.getInventory().setChestplate(new ItemStack(Material.IRON_CHESTPLATE));
p.getInventory().setLeggings(new ItemStack(Material.IRON_LEGGINGS));
p.getInventory().setBoots(new ItemStack(Material.IRON_BOOTS));
p.getInventory().setHelmet(new ItemStack(Material.IRON_HELMET));
p.setMaxHealth(50);
p.setHealth(50);
p.sendMessage(ChatColor.DARK_RED + "YOU WAS GIVING THE" + ChatColor.YELLOW + " starterkit");
}
return false;
// end of starter command
// amateur command
if(cmd.getName().equalsIgnoreCase("amateur")&&sender instanceof Player) {
Player p = (Player) sender;
p.getInventory().clear();
ItemStack amateurbow = new ItemStack(Material.BOW);
ItemMeta n = amateurbow.getItemMeta();
n.setDisplayName(ChatColor.YELLOW + "amateurbow");
amateurbow.setItemMeta(n);
amateurbow.addEnchantment(Enchantment.ARROW_FIRE, 1);
amateurbow.addEnchantment(Enchantment.ARROW_INFINITE, 1);
ItemStack amateursword = new ItemStack(Material.DIAMOND_SWORD);
ItemMeta m = amateursword.getItemMeta();
m.setDisplayName(ChatColor.YELLOW + "amateursword");
amateursword.setItemMeta(m);
amateursword.addEnchantment(Enchantment.FIRE_ASPECT, 2);
amateursword.addEnchantment(Enchantment.KNOCKBACK, 2);
p.getInventory().setChestplate(new ItemStack(Material.IRON_CHESTPLATE));
p.getInventory().setBoots(new ItemStack(Material.IRON_BOOTS));
p.getInventory().setHelmet(new ItemStack(Material.IRON_HELMET));
p.getInventory().setLeggings(new ItemStack(Material.IRON_LEGGINGS));
p.getInventory().addItem(amateursword);
p.getInventory().addItem(amateurbow);
p.getInventory().addItem(new ItemStack(Material.ARROW, 1));
p.setMaxHealth(30);
p.setHealth(30);
p.sendMessage(ChatColor.GOLD + "you was given the" + ChatColor.DARK_GRAY + " amateurkit");
return false;
}
// random teleport
if(cmd.getName().equalsIgnoreCase("teleportme")&&sender instanceof Player) {
Player player = (Player) sender;
Location originalLocation = player.getLocation();
Random random = new Random();
Location teleportLocation = null;
int x = random.nextInt(10) + 1;
int y = 30;
int z = random.nextInt(10) + 1;
boolean isOnLand = false;
while (isOnLand == false) {
teleportLocation = new Location(player.getWorld(), x, y, z);
if (teleportLocation.getBlock().getType() != Material.AIR) {
isOnLand = true;
} else
y--;
}
player.teleport(new Location(player.getWorld(), teleportLocation.getX(), teleportLocation.getY() + 1,
teleportLocation.getZ()));
player.sendMessage(ChatColor.RED + "You have been teleported "
+ (int) teleportLocation.distance(originalLocation) + " blocks away!");
return true;
return false;
// spawn
if(cmd.getName().equalsIgnoreCase("spawn")&&sender instanceof Player)
{
Player p = (Player) sender;
p.teleport(p.getWorld().getSpawnLocation());
p.sendMessage(ChatColor.RED + "you have been teleported to spawn");
return false;
// setspawn
if (cmd.getName().equalsIgnoreCase("setspawn") && sender instanceof Player) {
p.getWorld().setSpawnLocation(p.getLocation().getBlockX(), p.getLocation().getBlockY(),
p.getLocation().getBlockZ());
p.sendMessage("spawn location has been set at world" + p.getWorld().getName());
}
return false;
}
}
}
它有什么问题我不明白我做错了。
由于我刚刚开始使用java而且我想从错误中吸取教训,所以我非常感谢您的全面解释。
答案 0 :(得分:0)
看看你的缩进和包围。每种方法都应该有一个开合花括号。您获得的错误是由某个地方缺少括号引起的,这意味着编译器认为您没有正确关闭该类。