Hello, I need to find out how to add a fly boolean or any kind of boolean i am new. Here is my code Code: package me.colaking.FlyPlus; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; public class FlyPlus extends JavaPlugin{ @Override public void onEnable(){ getLogger().info("FlyPlus Has Been Successfully been enabled!"); } @Override public void onDisable() { getLogger().info("FlyPlus Has Been Successfuly Been Disabled!"); } public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { Player player = (Player) sender; String commandLabel = null; if(commandLabel.equalsIgnoreCase("fly")){ } return false; } }
I don't understand why you need this? To define a boolean, I do at the top of main class: public static boolean booleanName = false; if you want to activate their fly, do : sender.allowFlight(true); EDIT by Moderator: merged posts, please use the edit button instead of double posting.
its better to store a hashmap so you can track the status of the fly for each player, and not for the global server. I recommend you look up tutorials for hashmaps
Say okai i got it but now i get this any help Code: 16:04:33 [INFO] C0lA_K1nG issued server command: /fly 16:04:33 [SEVERE] null org.bukkit.command.CommandException: Unhandled exception executing command 'fly' in plugin FlyPlus v1.0 at org.bukkit.command.PluginCommand.execute(PluginCommand.java:42) at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:16 8) at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:4 98) at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler. java:880) at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:826) at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:808) at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:44) at net.minecraft.server.NetworkManager.b(NetworkManager.java:282) at net.minecraft.server.NetServerHandler.d(NetServerHandler.java:109) at net.minecraft.server.ServerConnection.b(SourceFile:35) at net.minecraft.server.DedicatedServerConnection.b(SourceFile:30) at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:577) at net.minecraft.server.DedicatedServer.q(DedicatedServer.java:213) at net.minecraft.server.MinecraftServer.p(MinecraftServer.java:473) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:405) at net.minecraft.server.ThreadServerApplication.run(SourceFile:539) Caused by: java.lang.NullPointerException at me.colaking.FlyPlus.FlyPlus.onCommand(FlyPlus.java:26) at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40) ... 15 more > Code Code: package me.colaking.FlyPlus; 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 FlyPlus extends JavaPlugin{ @Override public void onEnable(){ getLogger().info("FlyPlus Has Been Successfully been enabled!"); } @Override public void onDisable() { getLogger().info("FlyPlus Has Been Successfuly Been Disabled!"); } @SuppressWarnings({ "null" }) public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { Player player = (Player) sender; String commandLabel = null; if(commandLabel.equalsIgnoreCase("fly")){ if (player.getAllowFlight() == false) { player.setAllowFlight(true); player.setFlying(true); player.sendMessage(ChatColor.GREEN + "[FlyPlus]" + ChatColor.AQUA + "Flying Enabled"); } } return false; } }
In your code you check weather the commandLabel is "fly", however you assign the commandLabel to be null. I think what you were meant to put is if (label.equalsIgnoreCase("fly")){ player.setAllowFlight(!player.getAllowFlight()); }
I dont this his isue is resolved, look at this part of his code: String commandLabel = null; if(commandLabel.equalsIgnoreCase("fly")){ I am almost 99% sure that will triger an exception
Now when i try to increase the fly speed with player.setFlySpeed i can't it just ruines /fly Code Code: package me.colaking.FlyPlus; 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 FlyPlus extends JavaPlugin{ @Override public void onEnable(){ getLogger().info("FlyPlus Has Been Successfully been enabled!"); } @Override public void onDisable() { getLogger().info("FlyPlus Has Been Successfuly Been Disabled!"); } public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { Player player = (Player) sender; if(label.equalsIgnoreCase("fly")){ if (player.getAllowFlight() == false) { player.setAllowFlight(true); player.setFlying(true); player.sendMessage(ChatColor.GREEN + "[FlyPlus]:" + ChatColor.AQUA + " Flying Enabled"); } else if (player.getAllowFlight() == true) { player.setAllowFlight(false); player.setFlying(false); player.sendMessage(ChatColor.GREEN + "[FlyPlus]:" + ChatColor.AQUA + " Flying Disabled"); } if(label.equalsIgnoreCase("fly") && args[0].equalsIgnoreCase("speed") && args[1].equalsIgnoreCase(2)){ if (player.getAllowFlight() == true) { player.setAllowFlight(true); player.setFlying(true); player.setFlySpeed(2) } } return false; } }}
C0lA_K1nG Do yourself a flavor and learn Java/Programming basics. What you do is just hoorible! First off you assume that args[0] and args[1] are there, then you make no difference between "/fly" and "/fly speed 2": Both will toggle fly mode... Then what's the reason of hardcoding 2? You could just check if the given value isn't higher than a max. value and use this... Also you blindly cast sender to player. See how I would solve your problem, but keep in mind that I made erros into the code, so you can't copy&paste (it's some mix-up of Java and pseudocode): Code:java public class FlyPlus extends JavaPlugin{ int max = 3; public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if(sender isNotAnInstanceOf Player) return true; Player player = (Player) sender; if(the length of the args array < 1) { boolean to = !player.getAllowFlight(); player.setAllowFlight(to); player.setFlying(to); player.sendMessage("ChatColor.GREEN + "[FlyPlus]: + ChatColor.AQUA + to ? "Enabled" : "Disabled"); else if(the length of the args > 1 && args[0].equalsIgnoreCase("speed") { if (!player.getAllowFlight()) { player.sendMessage(ChatColor.RED+"You aren't flying!"); return true; } try { int speed = ConvertStringToInt(args[0]); if(speed > max) throw a NumberFormatException; player.setFlySpeed(speed); player.sendMessage(ChatColor.GREEN+"New speed: "+speed); } catch(NumberFormatException e) { player.sendMessage(ChatColor.RED+"Invalid speed: "+args[1]+" (only values between 0 and "+max+" are allowed)"); } } else return false; return true; }}
You miss read my post. I told him to use label not command label, thus solving the problem he did have. I know he has a new problem now.