Filled Teleport Random Distance in a Direction

Discussion in 'Plugin Requests' started by krlsmnk, Jul 19, 2018.

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


    Plugin category: Teleportation / Transportation

    Minecraft version: 1.13

    Suggested name: TpCompass

    What I want: A Random-ish TP plugin that doesn't rely on /commands. They always feel immersion-breaking and gimmick-y.

    A compass, when right-clicked, will teleport the player a random number of blocks (range defined in config) in that direction. The compass' lore will store (and display) the number of blocks traveled. When right clicked again (while the compass has Lore), it will return the player to the original location, then remove the compass Lore. This can be accomplished by storing the coordinates in and NBT tag.

    Now with 1.13, and the addition of the "^ ^ ^" option for the /tp command, this concept should be a LOT easier than it was before.


    1: Play a sound when the Compass is activated.

    2: While the Compass has Lore, the needle will point back to the original location it was used. Not sure if this is even possible without moving the worldspawn.

    Ideas for commands: PLEASE NO COMMANDS.

    Ideas for permissions: player.noCompass. Set it to true to prevent player from teleporting via the compass. Default is false, everyone should be allowed to use the Compass, but this option would allow the prevention of players who abuse or dupe it somehow.
  2. Offline


    Okey, I made it for you.
    I am open for feedback, but in my defense some points you mentioned were not that clear.

    Just write it in this chat and I will update the plugin ASAP

    The config has to look like this or otherwise an error will occur:

    MaxDistance: 10
    MinDistance: 1
    - Notch
    - JackTheRipper

    This should be called config.yml and put into plugins/TpCompass/(config.yml)

    As you can can see, I removed the idea of having a permission as every operator would already have it and due to that would not be allowed to teleport.
    Last edited: Jul 23, 2018
    krlsmnk likes this.
  3. Offline


    Pardon me, I don't mean to put you in a bad light nor take away any credit you undoubtedly deserve yourself and yourself only. I only wish to possibly help on the two points I discuss below, for the user and yourself's interest.

    You can make a default config.yml file in your plugin that will be saved and created when the plugin is enabled (if the config.yml doesn't already exist) by calling saveDefaultConfig(). Locate the config.yml in the src folder. This is done similarly to how you create the plugin.yml.

    This is helpful because then the user of the plugin does not need to create the config.yml himself, neither make sure all the nodes in it are correct. Those will be made by you already, inside the plugin.

    Example of the hierarchy view in IntelliJ IDEA of one of my plugins.

    The contents of config.yml.

    public void onEnable() {
    Save (and create if doesn't exist) the config.yml when the server enables.

    If we imagine all operators are allowed to use the compass in the first place: permissions can work if you take that into consideration. Like so:
    if (! player.isOp() && player.hasPermission("player.noCompass")) {
        // Disallow usage...
    Only when the player is not an operator, the permission check is run.
    johnny_boy likes this.
  4. Offline


    I agree with everything you said and I knew that there is this Bukkit.getConfig() thing. It‘s just my style of coding that I put every plugin in their seperate yml. For the second part. I liked the idea of saving those people in a file as permissions are rather confusing, as having the permission deny you access to something instead of giving you a privilege
  5. Offline


    Thanks so much, guys! You've both been super helpful.

    How can I test it? Will the pre7 build of Spigot work, or should I wait for the 1.13 full release?
  6. Offline


    Okay here's some testing updates:

    After setting up the config file as directed, I cannot get the compass to teleport me the desired amount of blocks.
    However, it WILL return me to the spot it was used on and clear that spot / Lore as intended....
    If I hold the Compass in my offhand, using Right Click will cause it to behave a bit odd.
    If I'm ALSO holding an item in my main hand, the Compass works as described above: marks location, adds lore, then ports back, removes lore.
    If I'm holding NOTHING in my main hand and the compass in my offhand: the compass stays locked in whatever lore mode it's currently in. It won't mark a new location and add lore if it's "active." It WILL return you to the marked spot but not remove the lore if it's "used."

    I'm kinda liking this, actually. It works a bit like a Hearthstone.

    Would it be possible hold the Compass and have Left Click be the teleport and Right Click be "mark this location, but don't TP me"? That would make this resource insanely useful.
  7. Offline


    Well I just forgot the OffHand in my coding
  8. Offline


    So how exactly do I need to set this up so I can get the initial teleport working?

    Current functionality is grand, but the original idea was for travel / exploration, not a "Home" plugin.

    After playing with this for a bit longer, I'm liking the aspect of tying a compass to a specific spot and being able to consistently go back there. Maybe add an option to prevent the compass from "forgetting" its saved location?

    There also seems to be times when the plugin "misses:"

    1: with a "Used" compass I will teleport to the location that I saved prior to the current one.

    2: Very occasionally I will teleport to the most recent saved location when the compass says "Active",

    3: and infrequently I will "save" a new location when trying to return to the saved one when the compass says "Used," and my old location will be forgotten, the new one saved, and the compass remains as "Used"

    4: Using 2+ compasses with different saved locations looks like it almost works, and occasionally it does. Both arrows point towards their respective saved location, but using either one is a big gamble. I can accept if this issue remains off the table, though, because it adds an unnecessary layer of complexity.

    Could you do as Axe_Villager suggested and make the plugin generate the config file? I've reformatted and placed this thing in every possible sub-directory and redefined the block thresholds several times, but the plugin never seems to port me.

    EDIT: Also, when I have a compass with a saved location, restarting the server makes the compass forget that location (probably due to the config file issue). The compass still shows that it has a saved location, but using it simply saves the current location.
    Last edited: Aug 18, 2018
  9. Offline


    *tried to remove double post and merge. can't find way to delete this*
    Last edited: Aug 5, 2018
  10. Offline


    Gonna bump this since it's been 2 weeks.
    Open to other coders; current version of plugin not working correctly as outlined above.
  11. Offline


    I can attempt this for you, can you be more specific on when the compass saves a location, when they are returned to that location and when the random teleport function is applied, after reading the initial thread and the comments, its a bit confusing.
    Last edited: Aug 20, 2018
  12. Offline


    Sure thing.

    1. Craft a compass. This is the default compass that points to spawn.
    2. User right clicks with the compass in hand. The plugin will save the current coords into the compass's NBT data, then teleport the player "X - Y" blocks (range defined in the config) in the direction they are facing.
    3. This "Used" compass, which has the coords NBT data, will now point towards the location is has saved.
    4. If the user right clicks with a "Used" compass, it will teleport them back to the saved location, then erase the saved location (becoming the default compass again).
    EDIT: Optional Config option:
    • Make renamed compasses never forget their saved location, and always teleport the user to that 1 spot.
  13. Offline


    I wouldn't store anything in the NBT data, this is because its actually difficult to do in code, and the way it works, it would break every update. So what I have done is given the compass a data value, and this value gets added to the config with the players UUID and their location, so it will work even after restarts. Another note is that the maximum directions a compass can point is limited to 1. This would mean if you filled your hotbar with compasses, they would all point at the last set location.

    Also you wanted me to add a config option to "never forget their saved location", is that referring to compasses saving their location after restarts, or is it referring to something else, and if so, how will that work differently.

    Here is what I have so far, let me know what you want changed: DOWNLOAD
    Last edited: Aug 21, 2018
  14. Offline


    That implementation does sound better.
    Multi-compass use is possible, but not the primary goal of the plugin. If they all have to point to the same location, that's fine.

    EDIT: It would be nice if the compass(es) pointed to the most recently saved / teleported location. So if I take the default compass and save a new location, it will point to that. If I then use my compass named "Home" to teleport back to my base, the compass(es) should point to the home coords.

    As far as "never forget their saved location," say I went to an Ice Spikes Biome and brought the default compass. I save the location of the biome in my compass. Then I rename the compass to "Ice Spikes" or whatever. When I use that compass, it should return me to the biome; however, since it has been renamed, the saved location will not be cleared from its "memory", meaning it will always take me to that location, no matter how many times I use it.

    Fantastic! I'll give it a look later this evening. I'll edit this reply once that's done so I don't end up double-posting.
  15. Offline


    You might be right, I will try and see if I can get a location to be set once the compass is in main hand. As for off hand support, I will add that in later when I have time.

    When you want the compass to keep returning to your home when renamed, does this mean the compass is always activated and when right clicked will only teleport them to their home, or should they keep the ability to teleport x blocks in x direction, but the compass will no longer overwrite the saved location.
    Last edited: Aug 21, 2018
  16. Offline


    Works pretty well so far. It's considerably more consistent; not perfect though. Trying to deduce why.

    When I set the max distance to 0, the plugin doesn't do anything. Not sure if that was a logical error in your random number generator section or there is some other reason.

    When I set it to 1 is typically behaves. Sometimes it "misses" on saving a location. It will play the sound and appear to teleport me, but it won't receive the enchanted effect and it won't save the location. My guess is it's picking 0 on the 0-1 RNG and that's causing it headache.

    Sometimes, (though much less frequently) it will "miss" on resetting the saved location upon returning. It will return me to the saved location, but remain enchanted, and further activation will return me to that location again. Eventually it will snap out of it, and correctly clear its memory, but I can't conclude why.

    While these "misses" are... odd... the enchanted effect helps a lot in showing me when it worked and didn't work. I can't seem to determine what's causing it to miss.

    I've had zero problems with it forgetting the saved location or failing to return me, even after a server restart. So well done there.

    If the compass is renamed, it should never forget its saved location, and its randomness should be removed. It should remain enchanted, and when used it should always return the user to the saved location, without additional teleports.
  17. Offline


    Is there any special reason for setting max blocks to 0, or you just checking for bugs? I also was able to set the compasses pin to target the specific compasses saved location, but remember this will still make all other compasses in the players inventory point in that direction until another activated clock is in hand. I also added a cooldown, because I believe the sole reason behind the "misses" is because of the plugin registering more than one click when the player only clicks once. You can set the cooldown time in the config. I also removed saved locations from config and made its own file because it was somehow overwriting other config settings and help notes. Renamed compassesare now able to only teleport to a saved spot (if set to true), remember that renaming must be done after the clock has become activated. Oh and lastly I added an option for min distance, please regen new config for new options.

    Latest version: DOWNLOAD
    Last edited: Aug 23, 2018
  18. Offline


    Current version seems to have corrected the big / main problems, so I'm going to mark this as filled. Wonderful work.

    The ONLY thing with the current version is the needle did not update its location until after I renamed the compass. This issue is very minor, so I'm not going to fret over it.

    PS: As a programmer myself whose worked a little with Java, could you direct me to some tutorial(s) on how to start making my own plugins? I'd hate to have to rely on you to fill all my nit-picky requests and hair-brained ideas. :)
  19. Offline


    I'm no pro at making bukkit plugins, my code is perhaps far from perfect. I've been making small plugins on an off for the past 2 or 3 years, but only got into it recently after putting quite a lot of hours into it. The best way to do it is to have a project that motivates you, start small and work around with the events. It's also good to use websites that teach most of the Java basics, if you already know an object oriented language, this should be really easy to adapt to. Then when you are feeling confident enough, come on here and try and help develop users ideas, and then take a more difficult project that contains something new that you didn't use before. For learning Bukkit plugins, Youtube is what kick started it for me. I will list some of my favourite youtube channels and tutorials below. {SourceCode} TheBCBroz

    If you don't know so much about Java and want to start making Plugins right away, this guy explains it pretty well and helped me out loads.

    P.S (I enjoy making your plugins)
    If you need any help with projects don't be afraid to ask on the forums or message us.
    I will look the problem with the compass pin and will edit this message with a new version if I find a fix.
Thread Status:
Not open for further replies.

Share This Page