Solved More dumb signs.

Discussion in 'Plugin Development' started by qhenckel, Oct 15, 2013.

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

    qhenckel

    OK I have come to a grinding halt in my caffeine fueled coding spree.
    My event signchangeevent can't give me a sign object to send on down the line.
    I need to be able to change the lines of this sign later so how do I keep it around? I have searched all over. This is my code so far:
    Code:java
    1. public void sign(SignChangeEvent event) {
    2. WorldEditPlugin worldEditPlugin = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
    3. Player player = event.getPlayer();
    4. Selection selection = worldEditPlugin.getSelection(player);
    5. if (event.getPlayer().hasPermission("censussigns.create")){
    6. if (event.getLine(0).equalsIgnoreCase("[census]")){
    7. String areaname = event.getLine(1);
    8. event.setLine(0, "There are:");
    9. event.setLine(1, "Somenumber");
    10. Sign sign = (Sign) event;
    11. event.setLine(2, "In the area:");
    12. event.setLine(3, areaname);
    13. String selectionstring = String.format("%d;%d;%d;%d;%d;%d",
    14. selection.getMaximumPoint().getBlockX(),
    15. selection.getMaximumPoint().getBlockY(),
    16. selection.getMaximumPoint().getBlockZ(),
    17. selection.getMinimumPoint().getBlockX(),
    18. selection.getMinimumPoint().getBlockY(),
    19. selection.getMinimumPoint().getBlockZ()
    20. );
    21. event.getBlock().setMetadata("census", new FixedMetadataValue(plugin, selectionstring));
    22. signs.add(sign);
    23. getLogger().info("making a sign");
    24. player.sendMessage("you made a census sign with name: " + sign.getLine(1));
    25.  
    26. }
    27. }
    28. }

    As you can see i use the event.setline That works great. but my cast come up with an error.
    Please help I am really stuck.
     
  2. Offline

    xize

    hmm I haven't looked in eclipse myself but did you tried to use Sign sign = (Sign) event.getBlock().getState(); ?, Im not sure if this event support getting the sign object as I know it get triggered when the player clicks the done button however if its not you might want to listen to BlockPlaceEvent and check for the sign material and then cast it on state.

    as for storing signs, you could store it in a HashMap depending how you want to use it though and then use a iterator with a entry set.
     
  3. Offline

    WauloK

    Code:java
    1. // Save sign location to config.yml
    2. Location loc = event.getBlock().getLocation();
    3. plugin.getConfig().set(arenaName + ".sign.x", loc.getX());
    4. plugin.getConfig().set(arenaName + ".sign.y", loc.getY());
    5. plugin.getConfig().set(arenaName + ".sign.z", loc.getZ());
    6. plugin.getConfig().set(arenaName + ".sign.world", loc.getWorld().getName());
    7. plugin.saveConfig();
     
  4. Offline

    qhenckel

    @xize
    I have tried all that. except setting up a BlockPlaceEvent. thanks for your time.
    @WauloK
    What is this answering? What of my problems is this solving? Please explain.
     
  5. Offline

    WauloK

    This saves the location of the sign to your config file so you can later read it from the config and change the sign info.
     
  6. Offline

    desht

    qhenckel You can't cast a SignChangeEvent to a Sign; Sign isn't a kind of event, it's a subclass of BlockState.

    Since the block involved in a SignChangeEvent must be a sign, you can do this:
    Code:
    Sign sign = (Sign) event.getBlock().getState();
    
    However, I'd advise against using a Sign object as long-term storage (which you seem to be doing with signs.add(sign) ) - since BlockState objects can easily become invalid. Probably better to store the block's location (but again, be careful about long-term storage of Location objects - better to serialise the location into a String and store that).
     
  7. Offline

    qhenckel

    @desht
    ^^^^^ This doesn't work. no errors but it doesn't update the sign.
     
  8. Offline

    xize

    qhenckel did you tried sign.update(true); ?
     
  9. Offline

    qhenckel

    YAY! thanks that worked!
    Thanks @xize
     
Thread Status:
Not open for further replies.

Share This Page