Sign help

Discussion in 'Plugin Development' started by ShredNyx, Sep 9, 2013.

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

    ShredNyx

    How can I create sign to where players sprightly click it ... It teleports them to certain coords....(and if you can leave how you add text on the sign) sorry I'm a noob at dis
     
  2. Offline

    kiwhen

    For this specific task, you would only need to know where the sign is, hook into PlayerInteractEvent, and check if a player clicks the block (where the sign is). After that you throw Player.teleport(Location).

    I assume you want more functionality with this, such as the ability to create dynamic teleportation signs, and edit them from inside the game? Stuff like that is important to know before we start to talk code. :)
     
  3. Offline

    _HybridPenguin_

    You could use something like this to detect when a player right clicks on a sign.

    Code:java
    1. @EventHandler
    2. public void interact(PlayerInteractEvent e) {
    3. //Do stuff
    4. }


    As for teleportation:
    Code:java
    1. World world = Bukkit.getServer().getWorld("//World Name");
    2. Location locationname = new Location(world, //x, //y, //z coords);
    3. player.teleport(locationname);
     
  4. Offline

    xize

    a small example in psuodo code:

    Code:
    @EventHandler
    public void signPlace(SignChangeEvent e) {
          if(e.getLine(0).contains("[teleport]")) {
                      e.setLine(0, ChatColor.translateAlternateColors("&", "&[teleport]");
          }
    }
     
    @EventHandler
    public void signInteract(PlayerInteractEvent e) {
        if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
                if(block.getType == Material.SIGN || block.getType == Material.SIGN_POST || block.getType == Material.WALL_SIGN) {
                      Sign sign = (Sign) e.getClickedBlock().getState();
                      if(sign.getLine(0).contains("[teleport]")) {
                            //let the player do something
                      }
                }
        }
    }
    
    edit
    basicly the most important thing is casting the Sign on getState(); and you can read lines of the sign;)
     
  5. Offline

    ShredNyx

    So top part of the code is where the text on the sign is...but where do I plug-in the text or how?
     
  6. Offline

    xize

    basicly yes event at the top code is activated when somebody presses the done button so you could retrieve the lines but also edit the sign lines and add permission checks so not everyone can create that sign because the first line is basicly a tag.

    with the tag I ment your other event which get triggered when your right click the sign it will search for the line with the name [teleport] and then do something.

    if you like to change the sign lines when the player clicks on the sign you could easily use sign.setLine(1, "see ya" + e.getPlayer().getName()); and update the block with sign.update(true);
     
Thread Status:
Not open for further replies.

Share This Page