[SOLVED] Can't get this to work...

Discussion in 'Plugin Development' started by Dark Shock, Aug 15, 2012.

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

    Dark Shock

    Nothing happens when I break cake..
    Hmmm.
    Eclipse has no errors. :/
    Code:
    package com.alifakih;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Shockworld extends JavaPlugin implements Listener{
        private static Boolean cake = true;
       
        public void onEnable() {
            getLogger().info("CakeSham has been enabled.");
            getServer().getPluginManager().registerEvents(this, this);
           
        }
       
        public void onDisable() {
            getLogger().info("CakeShame is now disabled.");
           
        }
       
        @EventHandler
        public void onPlayerInteractBlock(BlockBreakEvent evt)
        {
            Block b = evt.getBlock();
            if(cake == true)
            {
            if(b.getType() == Material.CAKE_BLOCK){
                evt.getPlayer().sendMessage("Shame on you! That's good cake!");
                evt.getPlayer().setFoodLevel(2);
            }
            else evt.getPlayer().sendMessage("");
               
            }
        }
       
        public void onPlayerCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if(cmd.getName().equalsIgnoreCase("stopcakeshame"));
    {
        cake = false;
        sender.sendMessage("CakeShame is now disabled for you.");
               
    }
     
    if(cmd.getName().equalsIgnoreCase("allowcakeshame"));
    {
        cake = true;
        sender.sendMessage("CakeShame is now enabled for you.");
               
    }
     
       
       
           
        }
       
       
        public void onPlayerJoin(PlayerJoinEvent event) {
            event.getPlayer().sendMessage("Breaking cake causes you to lose hunger! Cake is precious!");
           
        }
       
     
    }
    
     
  2. Offline

    Chiller

    Try changing: private static Boolean cake = true;
    To: private static boolean cake = true;
     
  3. Offline

    Dark Shock

    Nope. :(
     
  4. Offline

    javoris767

    Dark Shock
    Code:
        @EventHandler
        public void onPlayerInteractBlock(BlockBreakEvent evt)
        {
            Block b = evt.getBlock();
            if(cake == true)
            {
            if(b.getType() == Material.CAKE_BLOCK){
                evt.getPlayer().sendMessage("Shame on you! That's good cake!");
                evt.getPlayer().setFoodLevel(2);
            }
            else evt.getPlayer().sendMessage("");
             
            }
        }
    Basically you need to get the action.

    Code:
    if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
     
  5. Offline

    dchaosknight

    Dark Shock
    Are there any errors appearing in the console?
     
  6. Offline

    WarmakerT

    You forgot to return true :p
     
  7. Offline

    Chiller

    Instead of public void onPlayerInteractBlock(BlockBreakEvent evt)
    Make it: public void onBlockBreak(BlockBreakEvent evt)
     
  8. Offline

    Dark Shock

    It says something about an error in the jars Plugin.yml.
    The yml is:
    Code:
    name: CakeShame
    main: com.alifakih.Shockworld
    version: 0.1
    commands:
      stopcakeshame:
          description: Disable Cakeshame for you.
          usage: /<command>
          permission: <plugin name>.disable
          permission-message: You don't have <permission>
        allowcakeshame:
          description: Enables Cakeshame for you.
          usage: /<command>
          permission: <plugin name>.enable
          permission-message: You don't have <permission>
    Chiller, it worked earlier, but when I added the commands at the end, it stopped.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  9. Offline

    dchaosknight

  10. Offline

    Chiller

    You also put to events together: public void onPlayerInteractBlock(BlockBreakEvent evt)
    It should either be: public void onBlockBreakEvent(BlockBreakEvent evt)
    Or: public void onPlayerInteractEvent( PlayerInteractEvent evt)
     
  11. Offline

    dchaosknight

    Chiller
    If I remember correctly, the names of the methods don't matter anymore.
     
  12. Offline

    Dark Shock

    Doesn't it have to do with the plugin.yml file? The console says there's an error in it.. so...
     
  13. Offline

    dchaosknight

    Dark Shock
    What is the error reported in the console?
     
  14. Offline

    Dark Shock

    18:32:52 [SEVERE] Could not load 'plugins\CakeShame.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidDescriptionException: Invalid plugin.yml
     
  15. Offline

    dchaosknight

  16. Offline

    Dark Shock

    What do you mean?
     
  17. Offline

    dchaosknight

    Dark Shock
    In the plugin.yml file. Did you create a space for your permissions?
     
  18. Offline

    Dark Shock

    That's the entire plugin.yml file, I posted it earlier.

    I posted the entire plugin.yml file earlier...
    Code:
    name: CakeShame
    main: com.alifakih.Shockworld
    version: 0.1
     
    commands:
      stopcakeshame:
          description: Disable Cakeshame for you.
          usage: /<command>
          permission: <plugin name>.disable
          permission-message: You don't have <permission>
         
        allowcakeshame:
          description: Enables Cakeshame for you.
          usage: /<command>
          permission: <plugin name>.enable
          permission-message: You don't have <permission>
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  19. Offline

    dchaosknight

    Dark Shock
    Assuming <plugin name> is just a placeholder, the yml should look like this:
    Code:
    name: CakeShame
    main: com.alifakih.Shockworld
    version: 0.1
    commands:
      stopcakeshame:
          description: Disable Cakeshame for you.
          usage: /<command>
          permission: <plugin name>.disable
          permission-message: You don't have <permission>
      allowcakeshame:
          description: Enables Cakeshame for you.
          usage: /<command>
          permission: <plugin name>.enable
          permission-message: You don't have <permission>
    permissions:
      <name>.enable:
        description: <description here>
        default: <true|false|op|not op>
      <name>.disable:
        description: <description here>
        default: <true|false|op|not op>
    For the default (these are for non permission plugin servers, usually):
    true - everyone has the perm
    false - no one has the perm
    op- only op has this
    not op- everyone besides ops have the perm.
     
  20. Offline

    Dark Shock

    It still doesnt work.

    I tried that, but it seems like it's a problem with the class file. It worked earlier, but when I added the two "commands" it stopped. :/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  21. Offline

    dchaosknight

    Try using the hasPermission method and see if that works.
     
  22. Offline

    Dark Shock

    Caused by: while parsing a block mapping
    in "<reader>", line 5, column 3:
    stopcakeshame:
    ^
    expected <block end>, but found BlockMappingStart
    in "<reader>", line 10, column 5:
    allowcakeshame:
    ^
     
  23. Offline

    dchaosknight

    Is that part of the error log?
     
  24. Offline

    Dark Shock

    That's what the console says

    Code:
    19:07:50 [WARNING] To change this, set "online-mode" to "true" in the server.pro
    perties file.
    19:07:51 [INFO] This server is running CraftBukkit version git-Bukkit-1.3.1-R1.0
    -b2320jnks (MC: 1.3.1) (Implementing API version 1.3.1-R1.0)
    19:07:51 [SEVERE] Could not load 'plugins\CakeShame.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidDescriptionException: Invalid plugin.yml
            at org.bukkit.plugin.java.JavaPluginLoader.getPluginDescription(JavaPlug
    inLoader.java:208)
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager
    .java:132)
            at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:222)
            at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:198)
            at net.minecraft.server.ServerConfigurationManagerAbstract.<init>(Server
    ConfigurationManagerAbstract.java:50)
            at net.minecraft.server.ServerConfigurationManager.<init>(SourceFile:11)
     
            at net.minecraft.server.DedicatedServer.init(DedicatedServer.java:105)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:380)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    Caused by: while parsing a block mapping
    in "<reader>", line 5, column 3:
          stopcakeshame:
          ^
    expected <block end>, but found BlockMappingStart
    in "<reader>", line 10, column 5:
            allowcakeshame:
            ^
     
            at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingKey.produce(Par
    serImpl.java:575)
            at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:161)
            at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:146)
            at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java
    :230)
            at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:160)
            at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java
    :237)
            at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:160)
            at org.yaml.snakeyaml.composer.Composer.composeDocument(Composer.java:12
    3)
            at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:106)
     
            at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseCons
    tructor.java:121)
            at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:480)
            at org.yaml.snakeyaml.Yaml.load(Yaml.java:411)
            at org.bukkit.plugin.PluginDescriptionFile.<init>(PluginDescriptionFile.
    java:42)
            at org.bukkit.plugin.java.JavaPluginLoader.getPluginDescription(JavaPlug
    inLoader.java:203)
    Anyone?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  25. Offline

    Chiller

    Make sure instead of tabs use 4 spaces.
     
  26. Offline

    Dark Shock

    Okay it works now, but when I run /allowcakeshame and the /stopcakeshame it says "/allowcakeshame" or "/stopcakeshame" in the chat bar..
     
  27. Offline

    Chiller

    return true;
     
  28. Offline

    Dark Shock

    Where do I put that, because when I put it public void onPlayerCommand it errors...
    void methods cannot return value
     
  29. Offline

    Chiller

    Change it from void to boolean then insert return true; right before you close the method.
     
  30. Offline

    Dark Shock

    Same error.
     
Thread Status:
Not open for further replies.

Share This Page