Private plugin not generating files?

Discussion in 'Plugin Development' started by FTWin01Gurl, Feb 22, 2013.

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

    FTWin01Gurl

    ¡Hola!

    I'm having problems with my private custom plugin which will NOT create any files. The flatfile class which I'm using to manage should work. If anyone can find out what's wrong, please do tell me.

    Code:
    package me.FTWin01Gurl.RoleplayChat;
    
    import java.io.File;
    
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.entity.Player;
    
    public class NameDB {
    
        private File file;
        private YamlConfiguration config;
        
        
        public NameDB(File configFile) {
            file = configFile;
            config = YamlConfiguration.loadConfiguration(file);
        }
        
        public String getDisplayName(Player player) {
            String name = player.getName();
            if ( config.contains(name) ) {
                return config.getString(name);
            } else {
                return player.getName();
            }
        }
        
        public void setDisplayName(String playerN, String name) {
            config.set(playerN, name);
        }
        
    }
    
    
     
  2. Offline

    Lolmewn Retired Staff

    You're not even performing
    Code:Java
    1.  
    2. if(!file.exists()){
    3. file.getParentFile().mkdirs();
    4. file.createNewFile();
    5. }
     
  3. Offline

    Shevchik

    you set a value,
    but forgot to save the config.
     
  4. Offline

    FTWin01Gurl

    Will test it. I'll post here results

    Alright. It works!
    But my plugin has more complicated problems. At chat, the plugin crashes at 46.

    Code:
    2013-02-22 16:53:39 [SEVERE] Could not pass event AsyncPlayerChatEvent to RoleplayChat v1.4.7R10.1
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:459)
        at net.minecraft.server.v1_4_R1.PlayerConnection.chat(PlayerConnection.java:903)
        at net.minecraft.server.v1_4_R1.PlayerConnection.a(PlayerConnection.java:853)
        at net.minecraft.server.v1_4_R1.Packet3Chat.handle(Packet3Chat.java:44)
        at net.minecraft.server.v1_4_R1.NetworkManager.i(NetworkManager.java:208)
        at net.minecraft.server.v1_4_R1.NetworkManager.c(NetworkManager.java:344)
        at net.minecraft.server.v1_4_R1.NetworkReaderThread.run(SourceFile:93)
    Caused by: java.lang.NullPointerException
        at me.FTWin01Gurl.RoleplayChat.RPListener.onChat(RPListener.java:64)
        at sun.reflect.GeneratedMethodAccessor46.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
        ... 9 more
    Code:java
    1.  
    2. package me.FTWin01Gurl.RoleplayChat;
    3.  
    4. import java.util.Iterator;
    5. import java.util.List;
    6.  
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.entity.Entity;
    9. import org.bukkit.entity.EntityType;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.event.EventHandler;
    12. import org.bukkit.event.Listener;
    13. import org.bukkit.event.player.AsyncPlayerChatEvent;
    14. import org.bukkit.event.player.PlayerJoinEvent;
    15. import org.bukkit.event.player.PlayerQuitEvent;
    16.  
    17. public class RPListener implements Listener {
    18.  
    19. private RoleplayChat main;
    20. private NameDB db;
    21. private ChannelsManagement ch;
    22.  
    23. public RPListener(RoleplayChat rpChat, NameDB nameDB, ChannelsManagement chManage) {
    24. main = rpChat;
    25. db = nameDB;
    26. ch = chManage;
    27. }
    28.  
    29. @EventHandler
    30. public void onJoin(PlayerJoinEvent event) {
    31. Player player = event.getPlayer();
    32. String dispReturn = db.getDisplayName(player);
    33. player.sendMessage(ChatColor.YELLOW+"Channel focus to OOC");
    34. ch.setFocus(player, "ooc");
    35. if ( dispReturn != player.getName() ) {
    36. player.setDisplayName(dispReturn);
    37. event.setJoinMessage(dispReturn + " has joined Dark Sun roleplay.");
    38. } else {
    39. event.setJoinMessage(player.getName() + " has joined Dark Sun roleplay.");
    40. Player[] players = main.getServer().getOnlinePlayers();
    41. for (int i = 0; i > players.length; i++) {
    42. if ( players[I].hasPermission("rpchat.warnRPname") ){[/I]
    43. [I] Player playerOP = players[I];[/I][/I]
    44. [I] playerOP.sendMessage(ChatColor.RED+player.getName()+" does not have a roleplay name set!");[/I]
    45. [I] }[/I]
    46. [I] }[/I]
    47. [I] }[/I]
    48. [I] }[/I]
    49.  
    50. [I] @EventHandler[/I]
    51. [I] public void onLeave(PlayerQuitEvent event) {[/I]
    52. [I] Player disconnected = event.getPlayer();[/I]
    53. [I] String dispReturn = db.getDisplayName(disconnected);[/I]
    54. [I] event.setQuitMessage(dispReturn + " has left Dark Sun roleplay.");[/I]
    55. [I] }[/I]
    56.  
    57. [I] @EventHandler[/I]
    58. [I] public void onChat(AsyncPlayerChatEvent event) {[/I]
    59. [I] if (event.isCancelled()) {[/I]
    60. [I] return;[/I]
    61. [I] }[/I]
    62.  
    63. [I] Player chatter = event.getPlayer();[/I]
    64. [I] String channel = ch.getChannel(chatter);[/I]
    65. [I] if ( channel.equals("ooc")) {[/I]
    66. [I] event.setCancelled(true);[/I]
    67. [I] Player[] players = main.getServer().getOnlinePlayers();[/I]
    68. [I] for( int i = 0 ; i <= players.length; i++) {[/I]
    69. [I] players[I].sendMessage(ChatColor.YELLOW+"[OOC] " + chatter.getDisplayName() + ": " + event.getMessage());[/I][/I]
    70. [I] }[/I]
    71. [I] } else if ( channel.equals("ic") ) {[/I]
    72. [I] List<Entity> Erange = chatter.getNearbyEntities(20, 20, 20);[/I]
    73. [I] Iterator<Entity> ErangeIter = Erange.iterator();[/I]
    74. [I] while (ErangeIter.hasNext()) {[/I]
    75. [I] Entity entity = ErangeIter.next();[/I]
    76. [I] if ( entity.getType() == EntityType.PLAYER ) {[/I]
    77. [I] Player player = (Player)entity;[/I]
    78. [I] player.sendMessage(ChatColor.WHITE+"[IC] " + chatter.getDisplayName() + ": " + event.getMessage());[/I]
    79. [I] }[/I]
    80. [I] }[/I]
    81. [I] } else if ( channel.equals("w") ) {[/I]
    82. [I] List<Entity> Erange = chatter.getNearbyEntities(7, 7, 7);[/I]
    83. [I] Iterator<Entity> ErangeIter = Erange.iterator();[/I]
    84. [I] while (ErangeIter.hasNext()) {[/I]
    85. [I] Entity entity = ErangeIter.next();[/I]
    86. [I] if ( entity.getType() == EntityType.PLAYER ) {[/I]
    87. [I] Player player = (Player)entity;[/I]
    88. [I] player.sendMessage(ChatColor.GOLD+"[W] " + chatter.getDisplayName() + ": " + event.getMessage());[/I]
    89. [I] }[/I]
    90. [I] }[/I]
    91. [I] } else if ( channel.equals("y") ) {[/I]
    92. [I] List<Entity> Erange = chatter.getNearbyEntities(30, 30, 30);[/I]
    93. [I] Iterator<Entity> ErangeIter = Erange.iterator();[/I]
    94. [I] while (ErangeIter.hasNext()) {[/I]
    95. [I] Entity entity = ErangeIter.next();[/I]
    96. [I] if ( entity.getType() == EntityType.PLAYER ) {[/I]
    97. [I] Player player = (Player)entity;[/I]
    98. [I] player.sendMessage(ChatColor.RED+"[Y] " + chatter.getDisplayName() + ": " + event.getMessage());[/I]
    99. [I] }[/I]
    100. [I] }[/I]
    101. [I] }[/I]
    102. [I] event.setCancelled(true);[/I]
    103. [I] }[/I]
    104. [I]}[/I]
    105. [I][/code][/I]
    106.  
    107. [I]And commands do NOT work.[/I]
    108.  
    109. (65 in the syntax, java syntax is an ass)
    110.  
    111. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  5. Offline

    Double0negative

Thread Status:
Not open for further replies.

Share This Page