onPlayerJoin Error... I think.

Discussion in 'Plugin Development' started by Aeromcdoom, Mar 17, 2012.

  1. Offline

    Aeromcdoom

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I have an event on my plugin, the onPlayerJoin...
    I don't think this does anything... It sits there doing nothing, and I rely on this code for my plugin commands.

    Code (Text):
    1.     @EventHandler(priority = EventPriority.NORMAL)
    2.     public boolean playerJoinEvent(PlayerJoinEvent event){
    3.         FileConfiguration config;
    4.         Player player = event.getPlayer();
    5.         try{
    6.             config = getConfig();
    7.             File aCommands = new File("plugins"+File.separator+"aCommands"+File.separator+"Players"+File.separator+player.getName()+File.separator + "config.yml");
    8.             aCommands.mkdir();
    9.             if(!config.contains("general.name")) {
    10.                 config.set("general.name", player.getName());
    11.                 }
    12.             if(!config.contains("teleport.allow")) {
    13.                 config.set("teleport.allow", true);
    14.                 }
    15.             if(!config.contains("general.afk")) {
    16.                 config.set("general.afk", false);
    17.                 }
    18.             saveConfig();
    19.         }catch(Exception e1){
    20.         e1.printStackTrace();
    21.         }
    22.         return false;
    23.     }
    I get this error when I try /ac... I suspect its the onJoinPlayer event...

    Code (Text):
    1. 012-03-16 19:34:07 [SEVERE] null
    2. org.bukkit.command.CommandException: Unhandled exception executing command 'ac' in plugin aCommands v0.4
    3. at org.bukkit.command.PluginCommand.execute(PluginCommand.java:42)
    4. at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:166)
    5. at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:461)
    6. at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.java:818)
    7. at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:778)
    8. at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:761)
    9. at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:33)
    10. at net.minecraft.server.NetworkManager.b(NetworkManager.java:229)
    11. at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:112)
    12. at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:78)
    13. at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:554)
    14. at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:452)
    15. at net.minecraft.server.ThreadServerApplication.run(SourceFile:490)
    16. Caused by: java.lang.NullPointerException
    17. at net.sky.the.venture.acommands.aCommands.onCommand(aCommands.java:96)
    18. at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40)
    19. ... 12 more
     
  2. Offline

    CRAZYxMUNK3Y

    My BukkitDev Profile
    My Plugins (1)
    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Can you post all classes please, either on PasteBin, or using the syntax=java code
    Code (Text):
    1. [syntax=java]code here[/syntax]
    Thanks
     
  3. Offline

    zwap1233

    My BukkitDev Profile
    My Plugins (1)
    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    i see: java.lang.NullPointerException that means that you tried to give a variable the value null.
    also i see only return false; are you sure you don't have to return true?
     
  4. Offline

    dsmyth1915

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Try changing the return false; to return true; . You should also paste in your command handler for /ac to see of there is any problems in there.
     
  5. Offline

    Aeromcdoom

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I changed
    Code:java
    1. @EventHandler(priority = EventPriority.NORMAL)
    to:


    Code:java
    1. @EventHandler(priority = EventPriority.MONITOR)
    Does the onCommand() have to be return false or true?
     
  6. Offline

    dsmyth1915

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    If it returns false, then the listeners stops, if you return true it continues to listen. Also, there's is an error with your onCommand(aCommands.java:96) so check your a commands on line 96
     
  7. Offline

    ferrybig

    My BukkitDev Profile
    My Plugins (8)
    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    the return value of an listener is ignored, as far I know
     
  8. Offline

    Aeromcdoom

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME


    Thats...
    Code:java
    1. Boolean teleport = config.getBoolean("teleport.allow");

    But I probably know why...
     
  9. Offline

    nisovin

    My BukkitDev Profile
    My Plugins (7)
    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Your listener method should be a void not a boolean. Listeners don't return values.
     
  10. Offline

    Aeromcdoom

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    This is my code, It's under anything... So its kind of like this.

    Code:java
    1. public class aCommands extends JavaPlugin{
    2. @EventHandler(priority = EventPriority.MONITOR)
    3. public void playerJoinEvent(PlayerJoinEvent event){
    4. Player player = event.getPlayer();
    5. try{
    6. config = getConfig();
    7. File aCommands2 = new File("plugins"+File.separator+"aCommands"+File.separator+"Players"+File.separator+player.getName());
    8. aCommands2.mkdir();
    9. File PlayerConfig = new File(aCommands2+File.separator+"config.yml");
    10. try{
    11. PlayerConfig.createNewFile();
    12. log.info("aCommands: aHomes is created.");
    13. }
    14. catch ( IOException ex ){
    15. log.info("Error: #2");
    16. }
    17.  
    18. if(!config.contains("general.name")) {
    19. config.set("general.name", player.getName());
    20. }
    21. if(!config.contains("teleport.allow")) {
    22. config.set("teleport.allow", true);
    23. }
    24. if(!config.contains("general.afk")) {
    25. config.set("general.afk", false);
    26. }
    27. saveConfig();
    28. log.info("Created config file for "+player.getName());
    29. }catch(Exception e1){
    30. e1.printStackTrace();
    31. }
    32. }
    33. }[syntax][/syntax]
     
  11. Offline

    nisovin

    My BukkitDev Profile
    My Plugins (7)
    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Your event listener needs to be in a class that implements Listener. Then you need to register the event.
     
  12. Offline

    Aeromcdoom

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Heres a rewrite... But the listener doesn't activate on playerJoinEvent...
    Code (Text):
    1. public class aCommands extends JavaPlugin implements Listener{
    2. //Other code
    3. }
    Othercode:
    Code (Text):
    1.     @EventHandler(priority = EventPriority.MONITOR)
    2.     public void playerJoinEvent(PlayerJoinEvent event){
    3.         Player player = event.getPlayer();
    4.         try{
    5.             config = getConfig();
    6.             File aCommands2 = new File("plugins"+File.separator+"aCommands"+File.separator+"Players"+File.separator+player.getName());
    7.             aCommands2.mkdir();
    8.             File PlayerConfig = new File(aCommands2+File.separator+"config.yml");
    9.               try{
    10.                     PlayerConfig.createNewFile();
    11.                     log.info("aCommands: aHomes is created.");
    12.                   }
    13.                   catch ( IOException ex ){
    14.                       log.info("Error: #2");
    15.                   }
    16.  
    17.             if(!config.contains("general.name")) {
    18.                 config.set("general.name", player.getName());
    19.                 }
    20.             if(!config.contains("teleport.allow")) {
    21.                 config.set("teleport.allow", true);
    22.                 }
    23.             if(!config.contains("general.afk")) {
    24.                 config.set("general.afk", false);
    25.                 }
    26.             saveConfig();
    27.             log.info("Created config file for "+player.getName());
    28.         }catch(Exception e1){
    29.         e1.printStackTrace();
    30.         }
    31.     }
     
  13. Offline

    dsmyth1915

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Change monitor back to normal, see if that works.
     
  14. Offline

    nisovin

    My BukkitDev Profile
    My Plugins (7)
    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    It looks like you still haven't registered the event.
     
  15. Offline

    Aeromcdoom

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    How do I register it?
     
  16. Offline

    CRAZYxMUNK3Y

    My BukkitDev Profile
    My Plugins (1)
    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    This is my main class on how to register new classes and events
    Code:java
    1.  
    2. private GlassDropsCommands commands; // Declaring variable, private/public <ClassName> <Variable>
    3.  
    4.  
    5. public void onEnable() {
    6. commands = new GlassDropsCommands(this); // variable = new<ClassName.java>(this);
    7. PluginManager pm = Bukkit.getServer().getPluginManager();
    8. pm.registerEvents(this.commands, this); // Registering events
    9. }
    10.  


    Hope this kind of makes sence.
     
  17. Offline

    Aeromcdoom

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Thanks... Now the onPlayerJoin is activating but I get this...
    Code (Text):
    1. 2012-03-17 20:01:17 [SEVERE] null
    2. org.bukkit.command.CommandException: Unhandled exception executing command 'ac' in plugin aCommands v0.4
    3. at org.bukkit.command.PluginCommand.execute(PluginCommand.java:42)
    4. at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:166)
    5. at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:461)
    6. at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.java:818)
    7. at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:778)
    8. at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:761)
    9. at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:33)
    10. at net.minecraft.server.NetworkManager.b(NetworkManager.java:229)
    11. at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:112)
    12. at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:78)
    13. at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:554)
    14. at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:452)
    15. at net.minecraft.server.ThreadServerApplication.run(SourceFile:490)
    16. Caused by: java.lang.NullPointerException
    17. at net.sky.the.venture.acommands.aCommands.onCommand(aCommands.java:102)
    18. at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40)
    19. ... 12 more
     
  18. Offline

    CRAZYxMUNK3Y

    My BukkitDev Profile
    My Plugins (1)
    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Have you rgistered the command in the onEnable()?
     
  19. Offline

    Aeromcdoom

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Heres my onEnable start.
    Those are the first 4 lines.
    Code:java
    1. public void onEnable(){
    2. commands = new aCommands();
    3. PluginManager pm = Bukkit.getServer().getPluginManager();
    4. pm.registerEvents(this.commands, this); // Registering events
    5. PluginDescriptionFile pdfFile = this.getDescription();
     
  20. Offline

    Aeromcdoom

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Nope... It's something to do with the onCommand and onPlayerJoin
     
  21. Offline

    CRAZYxMUNK3Y

    My BukkitDev Profile
    My Plugins (1)
    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Code:java
    1.  
    2. getCommand("command").setExecutor(ClassVariable);
    3. // Mine is
    4. getCommand("gd").setExecutor(commands);
    5.  


    Add that and see if it works.
     
  22. Offline

    zwap1233

    My BukkitDev Profile
    My Plugins (1)
    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    what is line 102 at at net.sky.the.venture.acommands.aCommands.onCommand?
     
  23. Offline

    Aeromcdoom

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    To onEnable?
     
  24. Offline

    CRAZYxMUNK3Y

    My BukkitDev Profile
    My Plugins (1)
    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Yeah...
     
  25. Offline

    Aeromcdoom

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Error with this line
    getCommand("command").setExecutor(commands);
     
  26. Offline

    Aeromcdoom

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Unless classVariable is meant to be something else than commands
     
  27. Offline

    CRAZYxMUNK3Y

    My BukkitDev Profile
    My Plugins (1)
    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Can you post your whole Main class, and the class that has the commands (CTRL+A it)?
     
  28. Offline

    Aeromcdoom

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Its going to be long... Really long..
    Code:java
    1. package net.sky.the.venture.acommands;
    2.  
    3. import java.io.BufferedReader;
    4. import java.io.BufferedWriter;
    5. import java.io.File;
    6. import java.io.FileReader;
    7. import java.io.FileWriter;
    8. import java.io.IOException;
    9. import java.util.HashMap;
    10. import java.util.Map.Entry;
    11. import java.util.logging.Logger;
    12.  
    13. import org.bukkit.Bukkit;
    14. import org.bukkit.ChatColor;
    15. import org.bukkit.GameMode;
    16. import org.bukkit.Location;
    17. import org.bukkit.World;
    18. import org.bukkit.command.Command;
    19. import org.bukkit.command.CommandSender;
    20. import org.bukkit.configuration.file.FileConfiguration;
    21. import org.bukkit.entity.Player;
    22. import org.bukkit.event.EventHandler;
    23. import org.bukkit.event.EventPriority;
    24. import org.bukkit.event.Listener;
    25. import org.bukkit.event.player.PlayerJoinEvent;
    26. import org.bukkit.plugin.PluginDescriptionFile;
    27. import org.bukkit.plugin.PluginManager;
    28. import org.bukkit.plugin.java.JavaPlugin;
    29.  
    30. public class aCommands extends JavaPlugin implements Listener{
    31.  
    32. Logger log;
    33. private final String FILE_HOMES = "aHomes.txt";
    34. private File m_Folder;
    35. private HashMap<String, Location> m_Homes = new HashMap<String, Location>();
    36. String author = "AeroMcDoom";
    37. FileConfiguration config;
    38. private aCommands commands;
    39. Boolean teleport;
    40.  
    41.  
    42. public void onEnable(){
    43. commands = new aCommands();
    44. PluginManager pm = Bukkit.getServer().getPluginManager();
    45. pm.registerEvents(this.commands, this); // Registering events
    46. getCommand("command").setExecutor(commands);
    47. PluginDescriptionFile pdfFile = this.getDescription();
    48. log = this.getLogger();
    49. log.info("aCommands: Version - " + pdfFile.getVersion());
    50. log.info("aCommands: Loading Systems");
    51.  
    52. m_Folder = getDataFolder();
    53. if ( !m_Folder.exists() ){
    54. log.info("aCommands: Config folder missing, creating...");
    55. m_Folder.mkdir();
    56. log.info("aCommands: aHomes is created.");
    57. }
    58. File homelist = new File(m_Folder.getAbsolutePath() + File.separator + FILE_HOMES);
    59. if ( !homelist.exists() ){
    60. log.info("aCommands: aHomes.txt is missing, creating...");
    61. try{
    62. homelist.createNewFile();
    63. log.info("aCommands: aHomes is created.");
    64. }
    65. catch ( IOException ex ){
    66. log.info("Error: #2");
    67. }
    68. }
    69. try{
    70. File configs = new File(m_Folder.getAbsolutePath() + File.separator + "config.yml");
    71. File aCommands = new File("plugins" + File.separator + "aCommands");
    72. aCommands.mkdir();
    73. if ( !configs.exists() ){
    74. log.info("Config.yml is missing");
    75. try{
    76. configs.createNewFile();
    77. log.info("aCommands: aHomes is created.");
    78. }
    79. catch ( IOException ex ){
    80. log.info("Error: #1");
    81. }
    82. }
    83. saveConfig();
    84. }catch(Exception e1){
    85. e1.printStackTrace();
    86. }
    87. log.info("Loading aHomes...");
    88. if ( loadSettings() )
    89. log.info("Loading aHomes completed.");
    90. else
    91. log.info("Loading aHomes failed.");
    92. log.info("Systems Loaded");
    93. }
    94.  
    95. public void onDisable(){
    96. log.info("Unloading Systems");
    97. log.info("Saving Configs.");
    98. saveConfig();
    99. log.info("Systems Unloaded");
    100. }
    101.  
    102. public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
    103. Player player = (Player)sender;
    104. loadPlayerConfig(player,config);
    105. config = getConfig();
    106. teleport = config.getBoolean("teleport.allow");
    107. PluginDescriptionFile pdfFile = this.getDescription();
    108. if (!(sender instanceof Player)) {
    109. sender.sendMessage(ChatColor.RED + "This command has to be called by a player!");
    110. return true;
    111. }
    112. CommandBoost extrac = new CommandBoost();
    113. if (command.getName().equalsIgnoreCase("setspawn")) {
    114. if (!player.hasPermission("command.op")){
    115. player.sendMessage(ChatColor.RED + "You don't have permission to do that.");
    116. return true;
    117. }
    118. Location spawn = player.getLocation();
    119. player.getWorld().setSpawnLocation(spawn.getBlockX(), spawn.getBlockY(), spawn.getBlockZ());
    120. player.sendMessage(ChatColor.RED + "Spawn set");
    121. } else if (command.getName().equalsIgnoreCase("spawn")) {
    122. if (!player.hasPermission("command.default")){
    123. player.sendMessage(ChatColor.RED + "You don't have a permission to do that.");
    124. return true;
    125. }
    126. Location spawn = player.getWorld().getSpawnLocation();
    127. spawn.setX(spawn.getBlockX() + 0.5);
    128. spawn.setY(spawn.getBlockY());
    129. spawn.setZ(spawn.getBlockZ() + 0.5);
    130. player.teleport(spawn);
    131. } else if (command.getName().equalsIgnoreCase("acversion")){
    132. player.sendMessage("aCommands: Version - " + pdfFile.getVersion());
    133. } else if (command.getName().equalsIgnoreCase("acauthor")){
    134. player.sendMessage("aCommands: Author - " + author);
    135. } else if (command.getName().equalsIgnoreCase("ac")){
    136. player.sendMessage("aCommands: Showing Help");
    137. player.sendMessage("Version - /acversion");
    138. } else if (command.getName().equalsIgnoreCase("home")){
    139. Location loc = m_Homes.get(player.getName());
    140. if ( loc != null ){
    141. player.teleport(loc);
    142. } else {
    143. player.sendMessage( ChatColor.RED + "Home not set, yet. Set it with /home, first" );
    144. }
    145. return true;
    146. } else if (command.getName().equalsIgnoreCase("sethome")){
    147. m_Homes.put(player.getName(), player.getLocation());
    148. player.sendMessage( ChatColor.GREEN + "Home set!" );
    149. saveSettings();
    150. return true;
    151. } else if (command.getName().equalsIgnoreCase("time")){
    152. if (!player.hasPermission("command.op")){
    153. player.sendMessage(ChatColor.RED + "You don't have permission to do that.");
    154. return true;
    155. }
    156. return extrac.timeSet(player, args[0]);
    157. } else if (command.getName().equalsIgnoreCase("strike")){
    158. if (!player.hasPermission("command.op")){
    159. player.sendMessage(ChatColor.RED + "You don't have permission to do that.");
    160. return true;
    161. }
    162. if (args.length == 0){
    163. return extrac.lightningStrike(player, args[0]);
    164. }else if (args.length == 1){
    165. return extrac.lightningStrike(player, args.length > 0 ? args[0] : null);
    166. }
    167. } else if (command.getName().equalsIgnoreCase("players")){
    168. return extrac.playerList(player);
    169. } else if (command.getName().equalsIgnoreCase("s")){
    170. if (!player.hasPermission("command.op")){
    171. player.sendMessage(ChatColor.RED + "You don't have permission to do that.");
    172. return true;
    173. }
    174. if (config.getBoolean("teleport.allow")){
    175. return extrac.playerTpHere(player,playerFind(player, args[0]));
    176. } else {
    177. player.sendMessage("That person has teleportation disabled...");
    178. }
    179. } else if (command.getName().equalsIgnoreCase("tp")){
    180. if (!player.hasPermission("command.op")){
    181. player.sendMessage(ChatColor.RED + "You don't have permission to do that.");
    182. return true;
    183. }
    184. if (config.getBoolean("teleport.allow")){
    185. return extrac.playerTpTo(player, (playerFind(player, args[0])));
    186. } else {
    187. player.sendMessage("That person has teleportation disabled...");
    188. }
    189. } else if (command.getName().equalsIgnoreCase("tpoverride")){
    190. if (!player.hasPermission("command.op")){
    191. player.sendMessage(ChatColor.RED + "You don't have permission to do that.");
    192. return true;
    193. }
    194. return extrac.playerTpTo(player, (playerFind(player, args[0])));
    195. } else if (command.getName().equalsIgnoreCase("soverride")){
    196. if (!player.hasPermission("command.op")){
    197. player.sendMessage(ChatColor.RED + "You don't have permission to do that.");
    198. return true;
    199. }
    200. return extrac.playerTpHere(player,playerFind(player, args[0]));
    201. } else if (command.getName().equalsIgnoreCase("tpdeny")){
    202. if (!player.hasPermission("command.op")){
    203. player.sendMessage(ChatColor.RED + "You don't have permission to do that.");
    204. return true;
    205. }
    206. if (config.getBoolean("teleport.allow")){
    207. if(!config.contains("teleport.allow")) {
    208. config.set("teleport.allow", false);
    209. player.sendMessage("You have disabled teleportation");
    210. }
    211. }
    212. } else if (command.getName().equalsIgnoreCase("tpallow")){
    213. if (!player.hasPermission("command.op")){
    214. player.sendMessage(ChatColor.RED + "You don't have permission to do that.");
    215. return true;
    216. }
    217. if (teleport){
    218. if(!config.contains("teleport.allow")) {
    219. config.set("teleport.allow", false);
    220. player.sendMessage("You have enabled teleportation");
    221. }
    222. }
    223. } else if (command.getName().equalsIgnoreCase("afk")){
    224. if(!config.contains("general.afk")) {
    225. config.set("general.afk", true);
    226. Bukkit.getServer().broadcastMessage( " is now AFK");
    227. }
    228. Bukkit.getServer().broadcastMessage(player + " is now AFK");
    229. } else if (command.getName().equalsIgnoreCase("noafk")){
    230. Bukkit.getServer().broadcastMessage(player + " has come back online");
    231. } else if (command.getName().equalsIgnoreCase("gm")){
    232. player.setGameMode(player.getGameMode() == GameMode.SURVIVAL ? GameMode.CREATIVE : GameMode.SURVIVAL);
    233. player.sendMessage(player.getGameMode() == GameMode.SURVIVAL ? "You are now in Creative mode" : "You are now in Survival mode");
    234. }
    235. return false;
    236. }
    237.  
    238. private boolean saveSettings()
    239. {
    240. try
    241. {
    242. BufferedWriter writer = new BufferedWriter(new FileWriter((m_Folder.getAbsolutePath() + File.separator + FILE_HOMES)));
    243. for ( Entry<String, Location> entry : m_Homes.entrySet() )
    244. {
    245. Location loc = entry.getValue();
    246. if ( loc != null )
    247. {
    248. writer.write(entry.getKey() + ";" + loc.getX() + ";" + loc.getBlockY() + ";" + loc.getBlockZ() + ";" + loc.getPitch() + ";" + loc.getYaw() + ";" + loc.getWorld().getName() );
    249. writer.newLine();
    250. }
    251. }
    252. writer.close();
    253. return true;
    254. }
    255. catch (Exception ex)
    256. {
    257. return false;
    258. }
    259. }
    260.  
    261. public boolean loadSettings()
    262. {
    263. try
    264. {
    265. BufferedReader reader = new BufferedReader(new FileReader((m_Folder.getAbsolutePath() + File.separator + "aHomes.txt")));
    266. String line = reader.readLine();
    267. while ( line != null )
    268. {
    269. String[] values = line.split(";");
    270. if ( values.length == 7 )
    271. {
    272. double X = Double.parseDouble(values[1]);
    273. double Y = Double.parseDouble(values[2]);
    274. double Z = Double.parseDouble(values[3]);
    275. float pitch = Float.parseFloat(values[4]);
    276. float yaw = Float.parseFloat(values[5]);
    277.  
    278. World world = getServer().getWorld(values[6]);
    279. if ( world != null )
    280. m_Homes.put(values[0], new Location(world, X, Y, Z, yaw, pitch));
    281. }
    282. line = reader.readLine();
    283. }
    284. return true;
    285. }
    286. catch (Exception ex)
    287. {
    288. return false;
    289. }
    290. }
    291.  
    292. public Player playerFind(Player player, String arg){
    293. Player targetplayer = null;
    294. if (player.getServer().getPlayer(arg) != null) {
    295. targetplayer = player.getServer().getPlayer(arg);
    296. }
    297. return targetplayer;
    298. }
    299.  
    300. @EventHandler(priority = EventPriority.NORMAL)
    301. public void playerJoinEvent(PlayerJoinEvent event){
    302. Player player = event.getPlayer();
    303. File aCommands2 = new File("plugins"+File.separator+"aCommands"+File.separator+"Players"+File.separator+player.getName());
    304. try{
    305. aCommands2.mkdir();
    306. }catch(Exception e1){
    307. e1.printStackTrace();
    308. }
    309.  
    310. try{
    311. File PlayerConfig = new File(aCommands2+File.separator+"config.yml");
    312. PlayerConfig.createNewFile();
    313. log.info("aCommands: aHomes is created.");
    314.  
    315. if(!config.contains("general.name")) {
    316. config.set("general.name", player.getName());
    317. }
    318. if(!config.contains("teleport.allow")) {
    319. config.set("teleport.allow", true);
    320. }
    321. if(!config.contains("general.afk")) {
    322. config.set("general.afk", false);
    323. }
    324. saveConfig();
    325. log.info("Created config file for "+player.getName());
    326. }
    327. catch ( IOException ex ){
    328. log.info("Error: #2");
    329. }
    330.  
    331. }
    332. public void loadPlayerConfig(Player player, FileConfiguration config){
    333. File aCommands2 = new File("plugins"+File.separator+"aCommands"+File.separator+"Players"+File.separator+player.getName());
    334. File playerConfig = new File(aCommands2+File.separator+"config.yml");
    335. if (!(playerConfig.exists())){
    336. aCommands2.mkdir();
    337. try {
    338. playerConfig.createNewFile();
    339. } catch (IOException e) {
    340. e.printStackTrace();
    341. }
    342. }
    343. teleport = config.getBoolean("teleport.allow");
    344.  
    345. }


    The End...
     
  29. Offline

    CRAZYxMUNK3Y

    My BukkitDev Profile
    My Plugins (1)
    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I assumed that you has more thah one class, the;

    private aCommands commands;
    and
    commands = new aCommands();

    is not needed.

    As for the rest, i don't know sorry :(

    Hopefully someone else knows...
     
  30. Offline

    MrMag518

    My BukkitDev Profile
    My Plugins (11)
    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    1. Make a new class called something like "Commands" and make it implement "CommandExecutor"
    Code:java
    1. public class Ping implements CommandExecutor {

    2. get the instanceof of "plugin"
    Code:java
    1. public static pluginclass plugin;
    2. public Ping(pluginclass instance)
    3. {
    4. plugin = instance;
    5. }

    3. Writte the command into the commandexecutor class.
    4. Writte the command into the "plugin.yml"
    HTML:
    1. commands:
    2.   ping:
    3.     usage: "Usage: /<command>"
    5. Execute the command.
    Under the "public class pluginname extends JavaPlugin implements Listener {"
    Code:java
    1. private Ping ping = null;

    In the onEnable() method:
    Code:java
    1. ping = new Ping(this);


    This a slack way to execute commands.
    Btw, "Ping" is just an example command.
     

Share This Page