Plugin Metrics Help!!

Discussion in 'Plugin Development' started by Vidsify, Jun 12, 2014.

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

    Vidsify

    Hi

    I'm trying to add Metrics to my plugin but the Plugin Metrics folder isn't loading in the plugins folder.

    I have added the metrics.java file.


    t.png

    I made a pom.xml file like it said on the wiki page

    Code:
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
     
        <groupId>org.mcstats.bukkit</groupId>
        <artifactId>metrics</artifactId>
        <version>R8-SNAPSHOT</version>
        <packaging>jar</packaging>
        <url>mcstats.org</url>
        <name>Metrics (Bukkit)</name>
     
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>
     
        <repositories>
            <repository>
                <id>Bukkit Official</id>
                <url>http://repo.bukkit.org/content/repositories/public</url>
            </repository>
        </repositories>
     
        <dependencies>
            <dependency>
                <groupId>org.bukkit</groupId>
                <artifactId>bukkit</artifactId>
                <version>1.7.9_R3</version>
                <type>jar</type>
                <scope>compile</scope>
            </dependency>
        </dependencies>
     
        <build>
            <defaultGoal>clean package</defaultGoal>
     
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.0.2</version>
                    <configuration>
                        <source>1.5</source>
                        <target>1.5</target>
                    </configuration>
                </plugin>
            </plugins>
        </build>
     
        <distributionManagement>
            <repository>
                <id>mcstats.releases</id>
                <name>mcstats.org releases</name>
                <url>http://repo.mcstats.org/content/repositories/releases/</url>
            </repository>
     
            <snapshotRepository>
                <id>mcstats.snapshots</id>
                <name>mcstats.org snapshots</name>
                <url>http://repo.mcstats.org/content/repositories/snapshots/</url>
            </snapshotRepository>
        </distributionManagement>
    </project>
    
    And finally I add the lines of code into my onEnable()

    Code:java
    1. @Override
    2. public void onEnable() {
    3. try {
    4. Metrics metrics = new Metrics(this);
    5. metrics.start();
    6. } catch (IOException e) {
    7. // Failed to submit the stats :-(
    8. }
    9. //initialiseConfig();
    10. PluginDescriptionFile pdfFile = this.getDescription();
    11. this.logger.info(pdfFile.getName() + " Version "
    12. + pdfFile.getVersion() + " Has been Enabled!");
    13. }
    14.  


    Any ideas why its not loading?
     
  2. Offline

    Vidsify

    A random *bump*
     
  3. Vidsify
    You don't need the pom.xml file, you already have the code in your project.

    You should change the comment in the catch block to a more helpful line of code, such as e.printStackTrace(). This way you can see if anything went wrong.

    Is your plugin loading at all? Any startup errors in console?
     
  4. Offline

    Vidsify

    Assist My plugin is loading fine and I get no errors in the console. So I have deleted the pom.xml and added that line of code you said. Is this where is goes?

    Code:java
    1. @Override
    2. public void onEnable() {
    3. try {
    4. Metrics metrics = new Metrics(this);
    5. metrics.start();
    6. } catch (IOException e) {
    7. e.printStackTrace(); // Failed to submit the stats :-(
    8. }
     
  5. Offline

    LucasEmanuel

    What do you mean by
     
  6. Offline

    Vidsify

    LucasEmanuel So i added the code into my plugin. When you start a plugin with Metrics built into it, it creates a folder for the plugin metrics file in your plugins folder for you server. And that's not loading
     
  7. Offline

    LucasEmanuel

    May we see your entire code?
     
  8. Offline

    Vidsify

    LucasEmanuel I'm very sorry but no. All you what you need i have provided as it's nothing to do with the rest of the plugin
     
  9. Offline

    LucasEmanuel

    No offense but if you haven't solved this problem then you can not know that this is the only part in your code that is not working. We at this forum will not be able to help you since there is nothing wrong with the code you have posted, thus it is somewhere else in your code. And since you will not provide it we can offer no further assistance.
     
    Assist likes this.
  10. Offline

    Vidsify

    The problem is I don't know how to upload my code to GitHub. I'm typing this on my tablet. So when I'm on my PC next I'll upload the code to this thread
     
  11. Offline

    LucasEmanuel

    You dont need to use github, you can just use the code tags on this forum.
     
  12. Offline

    Vidsify

    LucasEmanuel Here you go
    Code:java
    1. // Add custom multipliers
    2. // Add config for it
    3. // Add toggle commands
    4.  
    5. package me.Vidsify.DurEXP;
    6.  
    7. import java.io.IOException;
    8. import java.util.logging.Logger;
    9.  
    10.  
    11. //import org.bukkit.configuration.file.FileConfiguration;
    12. import org.bukkit.event.EventHandler;
    13. import org.bukkit.event.player.PlayerExpChangeEvent;
    14. import org.bukkit.plugin.PluginDescriptionFile;
    15. import org.bukkit.plugin.java.JavaPlugin;
    16.  
    17. public class DurEXP extends JavaPlugin {
    18.  
    19. public class Main extends JavaPlugin {
    20. public final Logger logger = Logger.getLogger("Minecraft");
    21. public DurEXP plugin;
    22.  
    23. @Override
    24. public void onDisable() {
    25. PluginDescriptionFile pdfFile = this.getDescription();
    26. this.logger.info(pdfFile.getName() + " Has been Disabled!");
    27. }
    28.  
    29. @Override
    30. public void onEnable() {
    31. try {
    32. Metrics metrics = new Metrics(this);
    33. metrics.start();
    34. } catch (IOException e) {
    35. e.printStackTrace(); // Failed to submit the stats :-(
    36. }
    37. //initialiseConfig();
    38. PluginDescriptionFile pdfFile = this.getDescription();
    39. this.logger.info(pdfFile.getName() + " Version "
    40. + pdfFile.getVersion() + " Has been Enabled!");
    41. }
    42.  
    43.  
    44. //public void initialiseConfig() {
    45. //FileConfiguration config = getConfig();
    46. //config.addDefault("Setings.Enable", true);
    47. //config.options().copyDefaults(true);
    48. //saveConfig();
    49. //}
    50.  
    51. @EventHandler
    52. public void doubleExperience(PlayerExpChangeEvent e) {
    53. if (e.getPlayer().hasPermission(" DoubleurEXP.multiplier.2 ")) {
    54. e.setAmount(e.getAmount() * 2);
    55. } else if (e.getPlayer().hasPermission("")) {
    56. e.setAmount(e.getAmount() * 1);
    57.  
    58. }
    59.  
    60. }
    61.  
    62. @EventHandler
    63. public void doubleExperience1(PlayerExpChangeEvent e) {
    64. if (e.getPlayer().hasPermission(" DoubleurEXP.multiplier.3 ")) {
    65. e.setAmount(e.getAmount() * 3);
    66. } else if (e.getPlayer().hasPermission("")) {
    67. e.setAmount(e.getAmount() * 1);
    68. }
    69.  
    70. }
    71.  
    72. @EventHandler
    73. public void doubleExperience2(PlayerExpChangeEvent e) {
    74. if (e.getPlayer().hasPermission(" DoubleurEXP.multiplier.4 ")) {
    75. e.setAmount(e.getAmount() * 4);
    76. } else if (e.getPlayer().hasPermission("")) {
    77. e.setAmount(e.getAmount() * 1);
    78. }
    79.  
    80. }
    81.  
    82. @EventHandler
    83. public void doubleExperience3(PlayerExpChangeEvent e) {
    84. if (e.getPlayer().hasPermission(" DoubleurEXP.multiplier.5 ")) {
    85. e.setAmount(e.getAmount() * 5);
    86. } else if (e.getPlayer().hasPermission("")) {
    87. e.setAmount(e.getAmount() * 1);
    88. }
    89.  
    90. }
    91.  
    92. @EventHandler
    93. public void doubleExperience4(PlayerExpChangeEvent e) {
    94. if (e.getPlayer().hasPermission(" DoubleurEXP.multiplier.6 ")) {
    95. e.setAmount(e.getAmount() * 6);
    96. } else if (e.getPlayer().hasPermission("")) {
    97. e.setAmount(e.getAmount() * 1);
    98. }
    99.  
    100. }
    101.  
    102. @EventHandler
    103. public void doubleExperience5(PlayerExpChangeEvent e) {
    104. if (e.getPlayer().hasPermission(" DoubleurEXP.multiplier.7 ")) {
    105. e.setAmount(e.getAmount() * 7);
    106. } else if (e.getPlayer().hasPermission("")) {
    107. e.setAmount(e.getAmount() * 1);
    108. }
    109.  
    110. }
    111.  
    112. @EventHandler
    113. public void doubleExperience6(PlayerExpChangeEvent e) {
    114. if (e.getPlayer().hasPermission(" DoubleurEXP.multiplier.8")) {
    115. e.setAmount(e.getAmount() * 8);
    116. } else if (e.getPlayer().hasPermission("")) {
    117. e.setAmount(e.getAmount() * 1);
    118. }
    119.  
    120. }
    121.  
    122. @EventHandler
    123. public void doubleExperience7(PlayerExpChangeEvent e) {
    124. if (e.getPlayer().hasPermission(" DoubleurEXP.multiplier.9 ")) {
    125. e.setAmount(e.getAmount() * 9);
    126. } else if (e.getPlayer().hasPermission("")) {
    127. e.setAmount(e.getAmount() * 1);
    128. }
    129.  
    130. }
    131.  
    132. @EventHandler
    133. public void doubleExperience8(PlayerExpChangeEvent e) {
    134. if (e.getPlayer().hasPermission(" DoubleurEXP.multiplier.10 ")) {
    135. e.setAmount(e.getAmount() * 10);
    136. } else if (e.getPlayer().hasPermission("")) {
    137. e.setAmount(e.getAmount() * 1);
    138. }
    139.  
    140. }
    141.  
    142. @EventHandler
    143. public void doubleExperience9(PlayerExpChangeEvent e) {
    144. if (e.getPlayer().hasPermission(" DoubleurEXP.multiplier.half ")) {
    145. e.setAmount((int) (e.getAmount() * 0.5));
    146. } else if (e.getPlayer().hasPermission("")) {
    147. e.setAmount(e.getAmount() * 1);
    148. }
    149.  
    150. }
    151.  
    152. @EventHandler
    153. public void doubleExperience10(PlayerExpChangeEvent e) {
    154. if (e.getPlayer().hasPermission(" DoubleurEXP.multiplier.1.5 ")) {
    155. e.setAmount((int) (e.getAmount() * 1.5));
    156. } else if (e.getPlayer().hasPermission("")) {
    157. e.setAmount(e.getAmount() * 1);
    158. }
    159.  
    160. }
    161. }
    162.  
    163. }
     
  13. Offline

    LucasEmanuel

    Well now I'm able to spot your problem, you have defined everything inside a class inside a class. Since the server can't find your onEnable() in your outer class it doesn't get called. Remove the inner class and move everything inside it to your outer class and it should work fine.
     
  14. Offline

    Vidsify


    Sorry to sound a bit of an idiot but I don't understand what you mean
     
  15. Offline

    LucasEmanuel

    Like this:
    Code:
    // Add custom multipliers
    // Add config for it
    // Add toggle commands
     
    package me.Vidsify.DurEXP;
     
    import java.io.IOException;
    import java.util.logging.Logger;
     
     
    //import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.player.PlayerExpChangeEvent;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class DurEXP extends JavaPlugin {
        public final Logger logger = Logger.getLogger("Minecraft");
        public DurEXP plugin;
     
        @Override
        public void onDisable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Has been Disabled!");
        }
     
        @Override
        public void onEnable() {
            try {
                Metrics metrics = new Metrics(this);
                metrics.start();
            } catch (IOException e) {
                e.printStackTrace(); // Failed to submit the stats :-(
            }
            //initialiseConfig();
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Version "
                    + pdfFile.getVersion() + " Has been Enabled!");
        }
     
     
        //public void initialiseConfig() {
        //FileConfiguration config = getConfig();
        //config.addDefault("Setings.Enable", true);
        //config.options().copyDefaults(true);
        //saveConfig();
        //}
     
        @EventHandler
        public void doubleExperience(PlayerExpChangeEvent e) {
            if (e.getPlayer().hasPermission(" DoubleurEXP.multiplier.2 ")) {
                e.setAmount(e.getAmount() * 2);
            } else if (e.getPlayer().hasPermission("")) {
                e.setAmount(e.getAmount() * 1);
     
            }
     
        }
     
        @EventHandler
        public void doubleExperience1(PlayerExpChangeEvent e) {
            if (e.getPlayer().hasPermission(" DoubleurEXP.multiplier.3 ")) {
                e.setAmount(e.getAmount() * 3);
            } else if (e.getPlayer().hasPermission("")) {
                e.setAmount(e.getAmount() * 1);
            }
     
        }
     
        @EventHandler
        public void doubleExperience2(PlayerExpChangeEvent e) {
            if (e.getPlayer().hasPermission(" DoubleurEXP.multiplier.4 ")) {
                e.setAmount(e.getAmount() * 4);
            } else if (e.getPlayer().hasPermission("")) {
                e.setAmount(e.getAmount() * 1);
            }
     
        }
     
        @EventHandler
        public void doubleExperience3(PlayerExpChangeEvent e) {
            if (e.getPlayer().hasPermission(" DoubleurEXP.multiplier.5 ")) {
                e.setAmount(e.getAmount() * 5);
            } else if (e.getPlayer().hasPermission("")) {
                e.setAmount(e.getAmount() * 1);
            }
     
        }
     
        @EventHandler
        public void doubleExperience4(PlayerExpChangeEvent e) {
            if (e.getPlayer().hasPermission(" DoubleurEXP.multiplier.6 ")) {
                e.setAmount(e.getAmount() * 6);
            } else if (e.getPlayer().hasPermission("")) {
                e.setAmount(e.getAmount() * 1);
            }
     
        }
     
        @EventHandler
        public void doubleExperience5(PlayerExpChangeEvent e) {
            if (e.getPlayer().hasPermission(" DoubleurEXP.multiplier.7 ")) {
                e.setAmount(e.getAmount() * 7);
            } else if (e.getPlayer().hasPermission("")) {
                e.setAmount(e.getAmount() * 1);
            }
     
        }
     
        @EventHandler
        public void doubleExperience6(PlayerExpChangeEvent e) {
            if (e.getPlayer().hasPermission(" DoubleurEXP.multiplier.8")) {
                e.setAmount(e.getAmount() * 8);
            } else if (e.getPlayer().hasPermission("")) {
                e.setAmount(e.getAmount() * 1);
            }
     
        }
     
        @EventHandler
        public void doubleExperience7(PlayerExpChangeEvent e) {
            if (e.getPlayer().hasPermission(" DoubleurEXP.multiplier.9 ")) {
                e.setAmount(e.getAmount() * 9);
            } else if (e.getPlayer().hasPermission("")) {
                e.setAmount(e.getAmount() * 1);
            }
     
        }
     
        @EventHandler
        public void doubleExperience8(PlayerExpChangeEvent e) {
            if (e.getPlayer().hasPermission(" DoubleurEXP.multiplier.10 ")) {
                e.setAmount(e.getAmount() * 10);
            } else if (e.getPlayer().hasPermission("")) {
                e.setAmount(e.getAmount() * 1);
            }
     
        }
     
        @EventHandler
        public void doubleExperience9(PlayerExpChangeEvent e) {
            if (e.getPlayer().hasPermission(" DoubleurEXP.multiplier.half ")) {
                e.setAmount((int) (e.getAmount() * 0.5));
            } else if (e.getPlayer().hasPermission("")) {
                e.setAmount(e.getAmount() * 1);
            }
     
        }
     
        @EventHandler
        public void doubleExperience10(PlayerExpChangeEvent e) {
            if (e.getPlayer().hasPermission(" DoubleurEXP.multiplier.1.5 ")) {
                e.setAmount((int) (e.getAmount() * 1.5));
            } else if (e.getPlayer().hasPermission("")) {
                e.setAmount(e.getAmount() * 1);
            }
     
        }
    }
     
    Vidsify likes this.
  16. Offline

    Vidsify

Thread Status:
Not open for further replies.

Share This Page