Plugin Help Need help with my gold in bedwars (my plugin)

Discussion in 'Plugin Help/Development/Requests' started by KaiTheCoder, Aug 14, 2017.

Thread Status:
Not open for further replies.
  1. Offline


    Hello i have a problem

    When i do /upgrade it says a internal error has eccoured


    package com.tumbledmc.islandwars;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Map;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.GameMode;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerPickupItemEvent;
    import org.bukkit.inventory.ItemStack;
    public class Islandwars extends JavaPlugin implements Listener{
        int players;
        Player player1;
        Player player2;
        HashMap<Player, Integer> gold = new HashMap<>();
        ArrayList<Player> playersAlive = new ArrayList<>();
        World map = Bukkit.getWorld("Rooftop");
        Player winner;
        HashMap<Player, Integer> iron = new HashMap<>();
        public void onEnable() {
            Bukkit.getPluginManager().registerEvents(this, this);
        public void onJoin(PlayerJoinEvent e) {
            if(Bukkit.getOnlinePlayers().size() >= 2) {
                for(Player p : Bukkit.getOnlinePlayers()) {
                    players = 2;
                player1 = playersAlive.get(0);
                player2 = playersAlive.get(1);
                player1.getInventory().addItem(new ItemStack(Material.WOOD_SWORD));
                player2.getInventory().addItem(new ItemStack(Material.WOOD_SWORD));
                player1.teleport(new Location(map, -32.172, 69.43533, -81.063));
                player2.teleport(new Location(map, -78.582, 69.29499, -34.209));
                Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
                    public void run() {
                        player1.getWorld().dropItem(new Location(map, -95.700, 65.50000, -33.408), new ItemStack(new ItemStack(Material.IRON_INGOT)));
                        player2.getWorld().dropItem(new Location(map, -33.448, 65.50000, -95.425),  new ItemStack(Material.IRON_INGOT));
                        player1.getWorld().dropItem(new Location(map, -95.700, 65.50000, -33.408), new ItemStack(new ItemStack(Material.GOLD_INGOT)));
                        player2.getWorld().dropItem(new Location(map, -33.448, 65.50000, -95.425),  new ItemStack(Material.GOLD_INGOT));
                }, 60L, 60L);
        public void onDeath(PlayerDeathEvent e) {
            if(players == 1) {
                for(Player p : Bukkit.getOnlinePlayers()) {
                    if(p.getGameMode() == GameMode.SURVIVAL) {
                        winner = p;
                        p.sendMessage(ChatColor.RED + "You Won GGGGGGGGGGGGGGGGGGGGGGGGGGGGG!");
        public void onPickup(PlayerPickupItemEvent e) {
            ItemStack iron1 = new ItemStack(Material.IRON_INGOT);
            ItemStack gold1 = new ItemStack(Material.GOLD_INGOT);
            if(e.getItem().getItemStack() == iron1) {
                iron.put(e.getPlayer(), iron.get(e.getPlayer()) + 1);
            }else if(e.getItem().getItemStack() == gold1) {
                gold.put(e.getPlayer(), gold.get(e.getPlayer()) + 1);
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            Player thesender = (Player) sender;
            if(label.equalsIgnoreCase("upgrade")) {
                if(gold.get(thesender) >= 7) {
                    thesender.getInventory().addItem(new ItemStack(Material.IRON_SWORD));
                }else {
                    return false;
            return false;
    Last edited by a moderator: Aug 14, 2017
  2. Offline


    1. Do not get the worlds before the on enable (i.e, don't set map outside of the onEnable). The way you currently have it will try to get the world before it even is loaded, so it will return null. Make sure rooftops is loaded before you set maps
    2. Do not hard code locations. You are bound to run into issues that way.
    3. You don't need to go to the millionth decimal place. Just go to the tenth
    4. Don't compare itemstacks with ==. That only compares memory space, which will almost always return false. Instead, use .isSimilar.
    5. Don't blindly cast sender to a player. Consoles, plugins, and command blocks can also issue commands. Make sure sender is a player before you create the sender.
    6. Do not use labels. They do not support aliases, and are only there for backwards compatibility. Instead, use command.getName()
    7. You do not need the else statement to return false; there are no extra statements after it.
    8. Main problem: We can't tell you what the issue is because you did not tell us what type the error is, nor where the error is coming from. Read this, and post which line is causing the problem.
Thread Status:
Not open for further replies.

Share This Page