so my plugin for some reason always has the boolean start true, can someone please tell me why? Code:java /** To change this license header, choose License Headers in Project Properties.* To change this template file, choose Tools | Templates* and open the template in the editor.*/package wizardsway; import java.util.ArrayList;import org.bukkit.Bukkit;import org.bukkit.ChatColor;import org.bukkit.Location;import org.bukkit.Material;import org.bukkit.block.Sign;import org.bukkit.entity.Player;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.event.block.Action;import org.bukkit.event.player.PlayerInteractEntityEvent;import org.bukkit.event.player.PlayerInteractEvent;import org.bukkit.event.player.PlayerQuitEvent;import org.bukkit.inventory.ItemStack; /**** @author plankton*/public class PlayerListener implements Listener { ArrayList<Location> signs = new ArrayList<Location>(); private WizardsWay plugin; public PlayerListener(WizardsWay plugin) {plugin.getServer().getPluginManager().registerEvents(this, plugin);this.plugin = plugin;} @EventHandlerpublic void onPlayerUse(PlayerInteractEntityEvent event) {Player p = event.getPlayer();if (p.getItemInHand().getType() == Material.BLAZE_ROD && event.getRightClicked() instanceof Player) {Player strike = (Player) event.getRightClicked();if (!plugin.wizards.contains(strike.getName()) && plugin.players.contains(strike.getName())) {strike.getWorld().strikeLightning(strike.getLocation());strike.sendMessage(ChatColor.DARK_PURPLE + "[Ww]" + ChatColor.YELLOW + "You have been switched to the wizard side!");plugin.players.remove(strike.getName());plugin.turnwizard(strike);strike.getInventory().addItem(new ItemStack(Material.BLAZE_ROD));}}} @EventHandlerpublic void onPlayerLeave(PlayerQuitEvent event) {if (plugin.wizards.contains(event.getPlayer().getName())) {plugin.wizards.remove(event.getPlayer().getName());} else if (plugin.players.contains(event.getPlayer().getName())) {plugin.players.remove(event.getPlayer().getName());}}}
I cannot either see any boolean variables there. Can you tell us which line or function is causing problems, what is it supposed to do and what is it doing now? The salvation is in the details.
Sorry, thats the player listener, here is where the problem is: Code:java /** To change this license header, choose License Headers in Project Properties.* To change this template file, choose Tools | Templates* and open the template in the editor.*/package wizardsway; import java.util.ArrayList;import java.util.HashMap;import java.util.Random;import java.util.UUID;import org.bukkit.Bukkit;import org.bukkit.ChatColor;import org.bukkit.Color;import org.bukkit.Location;import org.bukkit.Material;import org.bukkit.command.Command;import org.bukkit.command.CommandSender;import org.bukkit.entity.Player;import org.bukkit.inventory.ItemStack;import org.bukkit.inventory.meta.LeatherArmorMeta;import org.bukkit.plugin.java.JavaPlugin; /**** @author plankton*/public class WizardsWay extends JavaPlugin { HashMap<String, Location> backlocation = new HashMap<String, Location>(); Random rand = new Random(); ArrayList<String> players = new ArrayList<String>(); ArrayList<String> wizards = new ArrayList<String>(); boolean start = false; public void onEnable() { new PlayerListener(this); Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() { //for the "plugin" variable, use "this" if you're running this from the main class public void run() { if (start = true && players.size() == 1) { start = false; for (String name : players) { Bukkit.getServer().broadcastMessage(ChatColor.DARK_PURPLE + "[Ww]" + ChatColor.YELLOW + name + " has won wizardsway!"); players.remove(name); } for (String name : wizards) { Player p = (Player) Bukkit.getServer().matchPlayer(name); p.getInventory().setHelmet(new ItemStack(Material.AIR)); p.getInventory().setChestplate(new ItemStack(Material.AIR)); p.getInventory().setLeggings(new ItemStack(Material.AIR)); p.getInventory().setBoots(new ItemStack(Material.AIR)); wizards.remove(p.getName()); p.teleport(backlocation.get(p.getName())); } } } }, 0, 2); //The first number is the amount of ticks before the loop is started. And the second number is the number of ticks before it repeats. (there are usually ~20 ticks in a second) } public void onDisable() { } public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { Player p = (Player) sender; if (cmd.getName().equalsIgnoreCase("ww")) { int length = args.length; if (length == 1) { if (args[0].equalsIgnoreCase("setspawn")) { getConfig().set("WizardsWay.Location", p.getLocation()); saveConfig(); Bukkit.broadcastMessage(ChatColor.DARK_PURPLE + "[Ww]" + ChatColor.YELLOW + "WizardsWay arena created, you may now use /ww join"); } if (args[0].equalsIgnoreCase("join")) { if (start = false) { backlocation.put(p.getName(), p.getLocation()); p.teleport((Location) getConfig().get("WizardsWay.Location")); int team = rand.nextInt(2); if (!players.contains(p.getName()) || !wizards.contains(p.getName())) { if (team == 0) { turnwizard(p); } else { players.add(p.getName()); } } else { p.sendMessage(ChatColor.DARK_PURPLE + "[Ww]" + ChatColor.YELLOW + "You already joined the game"); } } else { p.sendMessage(ChatColor.DARK_PURPLE + "[Ww]" + ChatColor.YELLOW + "Game already started"); } } if (args[0].equalsIgnoreCase("start")) { if (wizards.size() > 0 && players.size() > 0) { for (String name : wizards) { Bukkit.getServer().getPlayer(name).getInventory().addItem(new ItemStack(Material.BLAZE_ROD)); start = true; } } else { p.sendMessage(ChatColor.DARK_PURPLE + "[Ww]" + ChatColor.YELLOW + "Not enough players/wizards!"); } } if (args[0].equalsIgnoreCase("leave")) { if (wizards.contains(p.getName()) || players.contains(p.getName())) { p.teleport(backlocation.get(p.getName())); if (wizards.contains(p.getName())) { wizards.remove(p.getName()); } else if (players.contains(p.getName())) { players.remove(p.getName()); } } else { p.sendMessage(ChatColor.DARK_PURPLE + "[Ww]" + ChatColor.YELLOW + "You are not in game!"); } } } } return false; } public void turnwizard(Player p) { ItemStack helm = new ItemStack(Material.LEATHER_HELMET); ItemStack chest = new ItemStack(Material.LEATHER_CHESTPLATE); ItemStack pants = new ItemStack(Material.LEATHER_LEGGINGS); ItemStack boots = new ItemStack(Material.LEATHER_BOOTS); LeatherArmorMeta hmeta = (LeatherArmorMeta) helm.getItemMeta(); LeatherArmorMeta cmeta = (LeatherArmorMeta) chest.getItemMeta(); LeatherArmorMeta pmeta = (LeatherArmorMeta) pants.getItemMeta(); LeatherArmorMeta bmeta = (LeatherArmorMeta) boots.getItemMeta(); hmeta.setColor(Color.YELLOW); cmeta.setColor(Color.PURPLE); pmeta.setColor(Color.YELLOW); bmeta.setColor(Color.PURPLE); helm.setItemMeta(hmeta); chest.setItemMeta(cmeta); pants.setItemMeta(pmeta); boots.setItemMeta(bmeta); p.getInventory().setHelmet(helm); p.getInventory().setChestplate(chest); p.getInventory().setLeggings(pants); p.getInventory().setBoots(boots); wizards.add(p.getName()); }} when i type /ww join, it always says the game started when it didnt EDIT by Moderator: merged posts, please use the edit button instead of double posting.
In pretty much all your if statements, you use if (start = false) or if (start = true) I believe you mean to use == for a comparison.
ok, i will try it and why would it make a difference? thank you, it works! EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Glad it works. Do note this however. Instead of comparing booleans using ==, there are some quicker ways to compare the boolean. Instead of if (start == true) { you could just do if (start) { Instead of if (start == false) { you could just do if (!start) { Both ways are quicker and prevent you from missing then second = and changing it from a comparison to an assignment.