Just can't find this one out...

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

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

    aikoels

    My code:

    So basically I have to create the player variable but everything I have tried just gets more errors,
    I also have an error on the "Sign sign = (Sign)block.getState();" line, the block has to be created
    There is also an error on the end of the "public class SeenSign extends JavaPlugin {" Saying I have to insert another "{" into it but that just makes many errors farther down
    Code:
    package com.github.aikoels.SeenSign;
     
    import net.minecraft.server.BlockSign;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Event;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.block.Sign;
    import org.bukkit.plugin.java.JavaPlugin;
    @SuppressWarnings("unused")
    public class SeenSign extends JavaPlugin {
        if (action == Action.PLACE_BLOCK && event.getPlacedBlock == Material.SIGN_POST) {
            Sign sign = (Sign)block.getState();
            if (sign.getLine(0).equalsIgnoreCase("[SEEN]") {
                if(player.hasPermission("SeenSign.Create")) {
     
            }else{
                player.sendMessage(ChatColor.RED + "You Do Not Have Permission To Create A Seen Sign!");
                    }
                }
            }
        }
    }
     
  2. Offline

    Chiller

  3. Offline

    aikoels

    I have read through this before, and I see what they use to implement player with a sender instanceof player, however I don't have a sender which is the issue
     
  4. Offline

    travja

    you have no block variable, so you need to get a block through an event, what event are you using for the above code?

    I suggest using SignChangeEvent.

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

    Courier

    I suggest you read this first, since you are trying to put code in a class without it being in a method.
    http://docs.oracle.com/javase/tutorial/java/concepts/index.html
     
  6. Offline

    aikoels

    Thanks, no errors now, here is what I am using
    Code:
    package com.github.aikoels.SeenSign;
     
    import net.minecraft.server.BlockSign;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Event;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.block.SignChangeEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.block.Sign;
    @SuppressWarnings("unused")
    public class SeenSign extends JavaPlugin {
        public void onSignChange(SignChangeEvent event) {
            Player p = event.getPlayer();
                if(event.getLine(0).contains("[Seen")){
                    if(p.hasPermission("SeenSign.Create"))
                        p.sendMessage(ChatColor.BLUE + "Seen Sign Created!");
                }else{
                    p.sendMessage(ChatColor.RED + "You Do Not Have Permission To Create A Seen Sign!");
            }
        }
    }
     
  7. Offline

    Courier

    That won't do anything though, because that code will never be called. You need your class to implement Listener, and to be registered in onEnable().
    http://wiki.bukkit.org/Introduction_to_the_New_Event_System
     
  8. Offline

    aikoels

    So this? but this doesn't seem right, it gives me the error on
    Code:
     public void onSignChange(SignChangeEvent event) {
    line saying that void isn't a valid type of variable, and thanks for helping me
    Code:
    public class SeenSign extends JavaPlugin implements Listener{
        public void onEnable() {
        public void onSignChange(SignChangeEvent event) {
            Player p = event.getPlayer();
                if(event.getLine(0).contains("[Seen]")){
                    if(p.hasPermission("SeenSign.Create"))
                        p.sendMessage(ChatColor.BLUE + "Seen Sign Created!");
                }else{
                    p.sendMessage(ChatColor.RED + "You Do Not Have Permission To Create A Seen Sign!");
                }
            }
        }
    }
    
     
  9. Offline

    Courier

  10. Offline

    aikoels

    I get what you are saying and have read through a few tutorials like you said, but I don't understand what you exactly are trying to get me to do with that link, just copy the basic stuff over like this? Because this also doesn't seem right. For example when it says "(this, this)" what do they want me to pout in that becuase I would have to creeate said variable if I put the onSignchange or anything like that, the besides that I tried to work with that code and decided to just leave the "(this, this)" for now, I essentially just need this one step to work for now, I don't care about too much more, all I really want it to do for now is say "you have created a seen sign" when someone places the sign and I have already gone through countless tutorials, all I am having the issue with is plugging it into minecraft and bukkit for it to register the signs being placed.

    And again, thanks for all your help.

    Here is the code with the "(this, this)" in it because I am not sure what you exactly meant for me to do with that.
    Code:
    package com.github.aikoels.SeenSign;
     
    import net.minecraft.server.BlockSign;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Event;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.block.SignChangeEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.block.Sign;
    @SuppressWarnings("unused")
    public class SeenSign extends JavaPlugin implements Listener{
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
        }
        @EventHandler
    public void onSignChange(SignChangeEvent event) {
            Player p = event.getPlayer();
           if(event.getLine(0).contains("[Seen]")){
           if(p.hasPermission("SeenSign.Create")){
           p.sendMessage(ChatColor.BLUE + "Seen Sign Created!");
           }else{
           p.sendMessage(ChatColor.RED + "You Do Not Have Permission To Create A Seen Sign!");
           }
    }
    }
    }
    
     
  11. Offline

    Courier

    Yeah, you need the .getPluginManager().registerEvents(this, this);. It registers this plugin as an event listener, so craftbukkit will call all methods marked with @EventHandler when that even occurs.
     
  12. Offline

    aikoels

    Thanks so much, I am now looking at a lot of java tutorials, hopefully I won't have any more problems, thanks again.
     
Thread Status:
Not open for further replies.

Share This Page