[request] sign compass

Discussion in 'Archived: Plugin Requests' started by Morlanius, Dec 22, 2012.

  1. Offline

    Morlanius

    Hi
    This is probably pretty simple, but i would like some sign formatting codes for <x> <y> <z> <fa> or,
    a [compass] that can go on a sign, however not a database one that requires each sign is logged, should work just like &4 etc.


    Morlanius
     
  2. Offline

    Mozio

    I dont understand what you need. Explain more in-depth
     
  3. Offline

    Morlanius

    basicly, i would either like one of those text replacement macros like &4 for red text etc but replaceing <x> <y> <z> with the cords of the sign and <fa> the direction (in the direction the player would be when reading the sign, like sign_direction+180(degrees))
    or, just done where i can put [compass] on a sign and it'll do it that way. but as a text replacement the same way colour and all that works so it doesnt need to store sign locations to file (in my application they will be moved, build and removed quite alot)
     
  4. just a sign that shows the coords of the block its placed on? or the coords of the sign its self like:
    first line: x=200
    second: y=200
    third: z = 200 and the fourt line the direction? i dunno how to do that, becus what when 2 players are looking at the sign? then u had to edit the packets sended to the player and tell them the 4th line contains there direction... (dunno if someone would want to make that)
     
  5. Offline

    Morlanius


    yeah, something like that, the direction is the direction of the sign not the player.
    The sign looking something like
    X: ****
    Z: ****
    Alt: ***
    Dir: *

    where the stars are the data to be, or failing that a text replace for <x> <y> <z> and <f> would allow it to styled any way the end user wants.

    I'm pretty sure there must be something out there that does this, but i just cant find it, been all over bukkit, if someone can help pls do, lol.

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

    Zoroark173

    You can just do this manually, by standing where the sign is, and marking down the cords, then putting them on a sign...
     
  7. Offline

    Morlanius

    Thats not what i want, the sign needs to be filling its own data
    it shouldnt be that difficult, i would do it myself but im in no way
    a java person lol.
    its just a string alias that maps to a symbol and the data is the objects own basic data, loc.x loc.y loc.z and yaw or whatever they are using in the api.
    I'm really surprised to be honest that its not almost standard to include cords as symbols if the effort was gone though to do colours.
     
  8. okey i made a little version but no direction, ill look at that now,
    here: <Edit by Moderator: Redacted mediafire url>
    1 permission: sign.compass
    just place a sign with on first line [compass], if it worked u will get a message, and the coords of the sign will be displayed on it

    doing the direction now
     
    Last edited by a moderator: Nov 8, 2016
  9. Offline

    Morlanius

    wow, thanks for helping =D
    im getting an error when trying this, ill paste it
    a dev server is working fine with it, but the can you make it so it updates on the item refresh or something like that rather than just the one update when its created,its in a moving object but the cords arent following the sign. (the plugin basicly does a WE /move type deal)
    I'm using the latest release of bukkit on linux.

    15:46:07 [SEVERE] Could not load 'plugins/Compass Signs.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.UnsupportedClassVersionError: me/captainbern/signs/Main : Unsupported major.minor version 51.0
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:184)
    at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:305)
    at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:230)
    at org.bukkit.craftbukkit.v1_4_6.CraftServer.loadPlugins(CraftServer.java:235)
    at org.bukkit.craftbukkit.v1_4_6.CraftServer.<init>(CraftServer.java:213)
    at net.minecraft.server.v1_4_6.PlayerList.<init>(PlayerList.java:52)
    at net.minecraft.server.v1_4_6.DedicatedPlayerList.<init>(SourceFile:11)
    at net.minecraft.server.v1_4_6.DedicatedServer.init(DedicatedServer.java:104)
    at net.minecraft.server.v1_4_6.MinecraftServer.run(MinecraftServer.java:399)
    at net.minecraft.server.v1_4_6.ThreadServerApplication.run(SourceFile:849)
    Caused by: java.lang.UnsupportedClassVersionError: me/captainbern/signs/Main : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at org.bukkit.plugin.java.PluginClassLoader.findClass0(PluginClassLoader.java:80)
    at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:53)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:173)
    ... 9 more
     
  10. almost ready with the dir stuff

    what the freck i has no errors, what plugins u use?
    oh wait i know what to do gimme a second
     
  11. Offline

    Morlanius

    umm WG,WE, towny,ships, Permissionsbukkit multiverse, SmS and machinacore mainly
     
  12. does this one work? <Edit by Moderator: Redacted mediafire url>

    for the moving thing u just want if u place it on a block and for some reason u can move that block and the sign the sign just updates every time its location ?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Nov 8, 2016
  13. Offline

    Morlanius

    yeah like on the refresh cycle of the sign
     
  14. okey trying it naw

    okey use this , still no updater but cant find a good way, <Edit by Moderator: Redacted mediafire url>

    okey im too lazy to make it update the sign when the sign moves... ill try to do it tomorrow

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Nov 8, 2016
  15. Offline

    1mpre55

    Actually, a the sign cannot move. When the sign or the block it's on is pushed by a piston, the sign pops off. If you want to, you can make the sign move with it's support block by listening to BlockPistonExtendEvent, checking all affected blocks for signs and then doing some magic to allow the event while keeping the sign on the block.
     
  16. Offline

    Morlanius

    its being moved by a plugin not by a piston, actually what happens is the plugin grabs a netlist of the blocks, then shifts their cords by a value then reinserts the objects, like copy and paste. just very quickly. so i would imagine it would generate an create event or something
     
  17. Offline

    45zeldafan

    It would be easier to do /getpos in-game, or press F3.
     
  18. Offline

    1mpre55

    Oh, sorry, I misunderstood that. But unfortunately there is no block.move(newLocation) or anything like that and plugins that "move" blocks actually just set new values to existing Block objects, as a result there is no BlockMoveEvent or anything like that. WE and other plugins may have their own API with such events, try that.
     
  19. Offline

    Morlanius

    but the block is causing some kind of update in order for it to be re-pop'ed into the world when its data is updated.
     
  20. Offline

    1mpre55

    No, there is no update other than the physics check. No events are fired or anything like that.
     
  21. Ima gonna try it maybe if i can make a loop that constantly checks if whats on the sign written is true and if not then writethe true information, ithink that way will work
     
  22. Offline

    1mpre55

    I hope that by looping you mean creating a repeating async task. But even then, how are you going to get the sign's new location so that you aren't casting an air's BlockState to Sign? A much simplier solution would be to make the sign update on right-click.
     
  23. i think i found a solution; just place an item frame with a compass in it
    imm to lazy to make the plugin i made better if someone wants the source, ill post it here..
     
  24. Offline

    Morlanius

    that would be fantastic, please do
     
  25. okey lemme take a look
    the Main class
    Code:
    package me.captainbern.signs;
     
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Main extends JavaPlugin{
       
        public void onEnable(){
            getLogger().info("Signs enabled.");
           
            PluginManager manager = this.getServer().getPluginManager();
           
            manager.registerEvents(new Sign(this), this);
           
        }
       
        public void onisable(){
            getLogger().info("Signs disabled.");
           
        }
     
    }
    and the Sign class
    Code:
    package me.captainbern.signs;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.block.BlockFace;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.SignChangeEvent;
     
    public class Sign implements Listener {
     
        public Sign(Main plugin) {
     
        }
     
        @EventHandler(priority = EventPriority.NORMAL)
        public void onSignChange(final SignChangeEvent event){
     
            Player player = event.getPlayer();
            Location loc = event.getBlock().getLocation();
            int x = loc.getBlockX();
            int y = loc.getBlockY();
            int z = loc.getBlockZ();
     
            //dir code
     
            BlockFace dir = null;
     
            float y1 = player.getLocation().getYaw();
     
            if( y1 < 0 ){y1 += 360;}
     
            y1 %= 360;
     
            int i = (int)((y1+8) / 22.5);
     
            if(i == 0){dir = BlockFace.SOUTH;}
            else if(i == 1){dir = BlockFace.SOUTH;}
            else if(i == 2){dir = BlockFace.SOUTH;}
            else if(i == 3){dir = BlockFace.SOUTH;}
            else if(i == 4){dir = BlockFace.WEST;}
            else if(i == 5){dir = BlockFace.WEST;}
            else if(i == 6){dir = BlockFace.WEST;}
            else if(i == 7){dir = BlockFace.NORTH;}
            else if(i == 8){dir = BlockFace.NORTH;}
            else if(i == 9){dir = BlockFace.NORTH;}
            else if(i == 10){dir = BlockFace.EAST;}
            else if(i == 11){dir = BlockFace.EAST;}
            else if(i == 12){dir = BlockFace.EAST;}
            else if(i == 13){dir = BlockFace.EAST;}
            else if(i == 14){dir = BlockFace.EAST;}
            else if(i == 15){dir = BlockFace.EAST;}
            else {dir = BlockFace.SOUTH;}
     
            //dir code stop
     
            if(event.getBlock().getType() == Material.SIGN_POST || event.getBlock().getType() == Material.WALL_SIGN || event.getBlock().getType() == Material.SIGN) {
                if(event.getLine(0).contains("[compass]")){
                    if(player.hasPermission("sign.compass")){
                        event.setLine(0, ChatColor.AQUA + "X = " + String.valueOf(x));
                        event.setLine(1, ChatColor.AQUA + "Y = " + String.valueOf(y));
                        event.setLine(2, ChatColor.AQUA + "Z = " + String.valueOf(z));
                        event.setLine(3, ChatColor.AQUA + "Dir = " + dir);
                        player.sendMessage(ChatColor.GREEN + "Succesfully created compass sign!");
                    }else{
                        player.sendMessage(ChatColor.RED + "You don't have the permission to make a compass sign!");
                    }
                }
            }
        }
     
    }
    can i get a like now?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
    Morlanius likes this.
  26. it can be done easly btw... every item has a unique id, just get that id, put it in a .yml file when a player puts [compass] on it, and then make a new runnable... let the runnable check for the blocks in the .yml, and then u kno what to do.. i don't have time naw
     
  27. Offline

    1mpre55

    If you're replying to my post, then you're confusing blocks, items and entities. Placed signs is a Block; ItemStack is what can be placed in Inventory or dropped as Item objects; Item is a type of Entity that represents a floating item and as any other Entity it indeed has a unique id. But I fail to see how that'll help you.

    What you need to do is find a new Block object that has the sign that was moved by a plugin and update that sign's text. Since there is no event being fired, you're not going to be able to detect the sign being moved at all, but even if you decide to waste server's resources by running a repeating task checking if sign still exists or not, once you detect that it was moved, there is no way to tell which Block object has it now. Sign and BlockState don't extend Entity, and they don't get updated when the block changes. Each world consists of hundreds to tens of thousands of loaded chunks, each chunk contains about 65536 blocks, scanning through them all might take you hours. And keep in mind that the other plugin could simply remove or replace the sign.

    You were talking about Item having a unique id. That's true, but Item is a floating item. You know, that thing that doesn't contain any information other than item id, amount and damage and automatically despawns after 5 minutes? Sure you can track every dropped Item that contains a sign, but what good will that do?

    It seems like you just came up with a few "terms" you thought sounded smart, combined them in sentences that made sense to you and explained your inability to make it with lack of time. Face it, you can't make it because nobody can without modifying the CraftBukkit server. But there is a simple solution - update the sign when a player right-clicks it. Alternatively, if you really don't care about the server's resources, detect and update all signs around a player on PlayerMoveEvent.
     
    CaptainBern likes this.
  28. Offline

    Morlanius

    Actually, just using a click event to update it would actually solve the problem, not my most preferred option but it would certainly be workable, but letting my brains ramble a bit what about ....
    I'm not over familiar with how this API works, im not java developer. I'm more at home in C, ive said this before, but i just wanted to be clear lol. ok ..
    I'm using a plugin that moves blocks, so at some level what is basically happening is; it records a table of blocks and their data, changes the (lets say) x value by +5, sets existing (in world) blocks to id 0 and null data values, then sends a block update with the altered values in, perhaps a synchronization function is called to verify blocks (guessing here), could that event be used?

    or...

    So, as java either extends or overrides, couldn't there be an extend to block_update_func (or whatever its called) and have check on the blocks (i assume there is already this in the game tick for processing redstone etc)
    so something like;
    ?(block_id==def_sign_post && block.text[0]=="[compass]"){block.text[2]=str("X=")+block.x .... and so on }

    would simply update every sign in the game with line 0 as [compass] when it does its natural checks.

    (this is purely concept-code)

    Would something like that be possible? and with 1 optional, only 8 references and 1 function call it should only be adding a dozen or so instructions into the duty cycle it should'nt lag at all.

    or am I barking up the wrong tree here?

    Oh and another thing, the last post says
    Mu understanding of the Java structure is that when you extend or override a function its inline, so its accessing the same address space in stack etc, or do you have to extern/optional/import/require each variable from the private classes that you are extending?
    either way, by extending, overriding and optional including to the main execution stack like that means that the plugs are in fact modifying the CraftBukkit server, that's the point.
     
  29. i really didn't want to look smart btw.. i just didn't think about it, and yes u are right... ill just make it on right click it refreshes the sign.. :/ thanks for the good explenation btw, i really learned something about it..
     
    1mpre55 likes this.
  30. Offline

    1mpre55

    So, that plugin could fire it's own BlockUpdateEvent or BlockMoveEvent, but in order for another plugin to get that event, it'd have to be compiled against your plugin to import that event class. Bukkit itself does not fire any events when a block is modified with block.setType(material) or block.setData(myByte). If it did, there would be high risk of creating accidental infinite loops.
    The last time I checked, the only kind of update that runs after a plugin modifies a block is physics (gravity) check.
    I know very little when it comes to compiling against CraftBukkit and/or reflections, but it's my understanding that it's not the same as modification of the server. In either case, it's best to just stick to the Bukkit API so that the plugin is version-independent.
     
    Morlanius likes this.

Share This Page