[UNSOLVED] Plugin Console Error

Discussion in 'Plugin Development' started by Icelaunche, Jan 6, 2012.

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

    Icelaunche

    Error:
    Code:
    22:38:33 [SEVERE] Could not load 'plugins/SCE.jar' in folder 'plugins':
    java.lang.NoSuchMethodException: me.Icelaunche.SCE.SCE.<init>()
        at java.lang.Class.getConstructor0(Class.java:2706)
        at java.lang.Class.getConstructor(Class.java:1657)
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:173)
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:215)
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:136)
        at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:141)
        at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:117)
        at net.minecraft.server.ServerConfigurationManager.<init>(ServerConfigurationManager.java:52)
        at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:141)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:388)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:457)
    

    And the Code: (this is a test I just copied a Sign Change Event Tut and some Instabreak code from the class list its just a test)
    Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package me.Icelaunche.SCE;
    
    import java.util.logging.Logger;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Event;
    import org.bukkit.event.Event.Type;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    /**
     *
     * @author arunsundaram
     */
    public class SCE extends JavaPlugin {
    
        private static final Logger log = Logger.getLogger("Minecraft");
        private final SCEBlockListener blocklistener = new SCEBlockListener(this);
    
        private Player player;
        private boolean cancel;
        private ItemStack itemstack;
        private boolean instaBreak;
    
        public void onEnable() {
            PluginManager pm = this.getServer().getPluginManager();
            pm.registerEvent(Event.Type.SIGN_CHANGE, blocklistener,
                    Event.Priority.Normal, this);
            pm.registerEvent(Event.Type.BLOCK_DAMAGE, blocklistener, Event.Priority.Normal, this);
            log.info("[SCE] Enabled");
        }
    
        public void onDisable() {
            log.info("[SCE] Disabled");
    
        }
     
        public SCE (Player player, Block block, ItemStack itemInHand, boolean instaBreak) {
            this.instaBreak = instaBreak;
            this.player = player;
            this.itemstack = itemInHand;
            this.cancel = false;
      
        }
    
        public Player getPlayer() {
            return player;
        }
    
        public boolean getInstaBreak() {
            return instaBreak;
        }
    
        public void setInstaBreak(boolean bool) {
            this.instaBreak = bool;
        }
    
        public ItemStack getItemInHand() {
            return itemstack;
        }
    
        public boolean isCancelled() {
            return cancel;
        }
    
        public void setCancelled(boolean cancel) {
            this.cancel = cancel;
        }
    }
    
    And Block Listener (for the Sign Change Event) probably not needed but who knows:
    Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package me.Icelaunche.SCE;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Event.Type;
    import org.bukkit.event.block.BlockDamageEvent;
    import org.bukkit.event.block.BlockListener;
    import org.bukkit.event.block.SignChangeEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    
    /**
     *
     * @author arunsundaram
     */
    class SCEBlockListener extends BlockListener {
        public static SCE plugin;
    
        public SCEBlockListener(SCE instance) {
            plugin = instance;
    
        }
    public void onSignChange(SignChangeEvent event) {
            Player player = event.getPlayer();
            if(event.getLine(0).contains("[MySign]")){
                 event.setLine(0, "§4[MySign]");
                 event.setLine(1, "§5"+player.getName());
                 player.sendMessage(ChatColor.BLUE + "MySign successfully created!");
        
    }
    }
    }
           
    
     
  2. Offline

    tomjw64

    can you post your plugin.yml? I think that the error is there, as you define your main class there.
     
  3. Offline

    Icelaunche

    Plugin.yml (i tested this plugin before i added instabreak [only Sign Change Event] and it worked):
    Code:
    name: SCE
    author: Icelaunche
    main: me.Icelaunche.SCE.SCE
    version: 1.0
     
  4. Offline

    tomjw64

    The problem is the constructor for SCE. JavaPlugins aren't supposed to have constructors. If you want to store info about a player, which is what I think you are trying to do there(have one plugin per player to store data), try using a hashmap, or arraylist, or just something that can store lots o' data.

    P.S. Please reply next time, it helps me find your response easier. :)
     
  5. Offline

    Icelaunche

    how would i add a hashmap to this (i know how to use them bit i dont use them often so im not the best with them)
     
  6. Offline

    tomjw64

    It really just depends what you want to store, and I am the same way, I have little experience with sets and maps and such. You should probably post something on the overall goal that you are trying to achieve
     
  7. Offline

    Icelaunche

    Goal: To make a plugin that instabreaks a block (mainly want the instabreak) when it it hit with a pick and have something like Sign Change event in the same plugin for testing purposes.
     
  8. Offline

    tomjw64

    toggleable per player?
     
  9. Offline

    Icelaunche

    yes
     
  10. Offline

    tomjw64

    Code:java
    1. //HashMap
    2. Map<String,boolean> values = new HashMap<String,boolean>();
    3. //Adding values
    4. values.put(player.getName(),true);
    5. //Getting values
    6. (boolean)values.get(player.getName());

    Not sure this is all correct, or even if a hashmap is the best method. But hopefully this helps some.
     
  11. Offline

    hatstand

    Yeah, using a set and checking if the player is in the set would be faster and simpler. You also don't need to cast the result of values.get to a boolean. A good reference for what to use in a situation is here
     
  12. Offline

    tomjw64

    Well, i thought there would be a better way, considering how specialized some of the collections are, so thanks for that. But are you sure about the cast? Eclipse didn't like it when I didn't cast it. :(
     
  13. Offline

    hatstand

    That would probably be because you aren't assigning the value or using it in anything. The map is of a string and a boolean, so it returns a boolean already.
     
  14. Offline

    tomjw64

    Ahhh, I see now. When I tried it out myself I had used <String,Object>. haha, thanks. :p
     
  15. You don't need a HashMap just for a bool, use a List<String> and players that are in the list have flag true and the rest have flag false.

    EDIT: actually I belive a Set or HashSet would be better than a List here... see http://wiki.bukkit.org/Java_data_structure_classes#Choosing_the_Right_Structure

    Also, you can use ChatColor.X enum instead of directly hardcoding color codes, it's easier and works in signs.

    And there are alot of methods that are useless in the main class, apart from the constructor that triggers your error.
     
  16. Offline

    Icelaunche

    those would be?
     
  17. Basically, for instebreak I'm pretty sure what you'll want to do is:
    onPlayerInteract
    if its a left_click_block
    check if hashset contains the player
    get block and set it to Material.AIR
     
  18. "Those" what ?
     
  19. Offline

    hatstand

    Useless methods, I assume. You're referring to the getters and setters, aren't you?
     
  20. Yep, those... they're useless for the goal of the plugin.... also don't make any sense but that's another story :}

    Just to make it clear:
    Code:
        public SCE (Player player, Block block, ItemStack itemInHand, boolean instaBreak) {
            this.instaBreak = instaBreak;
            this.player = player;
            this.itemstack = itemInHand;
            this.cancel = false;
      
        }
    
        public Player getPlayer() {
            return player;
        }
    
        public boolean getInstaBreak() {
            return instaBreak;
        }
    
        public void setInstaBreak(boolean bool) {
            this.instaBreak = bool;
        }
    
        public ItemStack getItemInHand() {
            return itemstack;
        }
    
        public boolean isCancelled() {
            return cancel;
        }
    
        public void setCancelled(boolean cancel) {
            this.cancel = cancel;
        }
    All of these along with their variables should go.
    I dunno what template did you use but it's a confusing one it seems, you should learn to make plugins without templates... then after you've done your first plugin that you're happy about the structure, you can just copy that and alter it into a new plugin, as a "template". :p
     
  21. Offline

    Icelaunche

    then how do i add instabreak?
     
  22. I quickly skimmed through the thread. The error you're getting is because you have a constructor in your main class.
     
  23. @Icelaunche You have the answer:
    Find some tutorials, because there are *alot*, video and written.
     
  24. Offline

    Icelaunche

    i cant find any ones that do instabreak...
     
  25. Do you really expect people to make a tutorial for every ideea possible ?
    Find tutorials about making plugins with player events :)

    If you don't want to learn and just want the plugin, consider posting in the requests section :p
     
  26. Offline

    WizzleDonker

    If you want a tutorial, I reccomend the ones made by Dinnerbone himself... they still aren't outdated and teach you good programming practices in a nutshell.
    Start here
     
  27. Offline

    Icelaunche

    i want to learn :p and Wizzle i know that stuff
     
Thread Status:
Not open for further replies.

Share This Page