Filled 2 up, one forward

Discussion in 'Archived: Plugin Requests' started by lucasbuck, Apr 1, 2014.

  1. Offline

    lucasbuck

    (Went back and edited my post to be more clear) :)

    Plugin category: Teleport

    Suggested name: 2 Up 1 Forward

    What I want: A command to teleport a player 2 blocks up, 1 block forward. That way if you have adventure type areas of maps, and have block breaking disabled, they can get out of wholes. An adjustable cooldown, or maybe set it for something like 10 minutes so it isn't griefed.

    Ideas for commands: /upforward

    Ideas for permissions: player.upforward

    When I'd like it by: When convenient
     
  2. Offline

    mine-care

    Hi, so in tecnical manner you want a plugin that will allow you to for instance /up and it will mabe u go 2 blocks up in the air and 1 forward...
    What i dont understand:
    1. you want it to be executed by commandblocks?
    2. you want it to have a specific message?
    3. you wlso want a land protection (No break or/and no place of blocks)?
    4. Do you mean launchpads? (this is somthing that wen u step on it aunces u high and moves u forward.)
    thanks
     
  3. Offline

    lucasbuck

    Sorry, I edited my post, hope it makes more sense now.
     
  4. Offline

    au2001

    I am doing it.

    It will be available for download on http://www.shadowcasted.com/#downloads

    Glad to help you.
    If you find any bug, just tell me!

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

    lucasbuck

    Thanks for working on it! It works fine if you are in a hole above ground (sky above), but if you are underground it goes straight to the top (like the /top command). Also, is there a way to do an adjustable cooldown?
     
  6. Offline

    au2001

    Ya, sure, I will tell you when it's available for download.

    lucasbuck
    I did that you were teleported to the first hole above you.

    Someone could help me for the cooldown? please send the function and how to use them.
    Thanks.

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

    JoTyler

    au2001 Me personally i use a cool down plugin for my server .. it is tons easier and you can make ANY command have a cool down of your choice.
     
  8. Offline

    au2001

    @JoTyle
    Yes but here, I need to do that in one plugin...
    I am still interested in that plugin to see how the've done. What's the name?
     
  9. Offline

    Benlewis9000

    au2001

    To make a cool down system is actually quite simple :) You just need to create an arrayList that stores the players name who is on cool down, and then when they type the command check if they are in the arrayList. If they are not, execute the command, then using a scheduler add them to the cool down list for a certain amount of time, and once that time runs out, have it remove them. If they are already on the arrayList just deny them access to it using if statements.

    If you still don't get it by this afternoon I will send some of my code over :)
     
  10. Offline

    au2001

    Benlewis9000
    That's what I did :
    Code:java
    1.  
    2. private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
    3. static ArrayList<Player> cooldown = new ArrayList<Player>();
    4. public void addtoList(final Player player) {
    5. cooldown.add(player);
    6. final Runnable remove = new Runnable() {
    7. public void run() { cooldown.remove(player); }
    8. };
    9. final ScheduledFuture<?> schedule = scheduler.scheduleAtFixedRate(remove, 10, 10, TimeUnit.SECONDS);
    10. scheduler.schedule(new Runnable() {
    11. public void run() { schedule.cancel(true); }
    12. }, 30, TimeUnit.SECONDS);
    13. }


    So now it works. The cool down is 30 seconds.
     
    Benlewis9000 likes this.
  11. Offline

    lucasbuck

    That works, thank you! 2 questions:
    1) Is the permission player.upforward ?
    2) Would it be hard to make the cooldown editable, like through a yml file? I was actually playing around with eclipse to see if I could do it myself, but I'm in over my head.
     
  12. Offline

    au2001

    1) Yes, the permission is player.upforward
    2) Ummm... Tried but didn't work...
     
  13. Offline

    Benlewis9000

    au2001 Instead of TimeUnit.SECONDS it is a lot easier to just set the tick cooldown to 'ticks * 20. That has aloways worked for me with config input. If you send me the source I could try?
     
  14. Offline

    au2001

    Benlewis9000

    Here's the source, thanks for trying :
    Code:java
    1. package me.au2001.UpForward;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.concurrent.Executors;
    5. import java.util.concurrent.ScheduledExecutorService;
    6. import java.util.concurrent.ScheduledFuture;
    7. import java.util.concurrent.TimeUnit;
    8. import java.util.logging.Logger;
    9.  
    10. import org.bukkit.ChatColor;
    11. import org.bukkit.Location;
    12. import org.bukkit.Material;
    13. import org.bukkit.command.Command;
    14. import org.bukkit.command.CommandSender;
    15. import org.bukkit.entity.Player;
    16. import org.bukkit.plugin.PluginDescriptionFile;
    17. import org.bukkit.plugin.java.JavaPlugin;
    18.  
    19. public class UpForward extends JavaPlugin {
    20. public final Logger logger = Logger.getLogger("Minecraft");
    21. private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
    22. static ArrayList<Player> cooldown = new ArrayList<Player>();
    23. private static long cooldown_lenght = 30;
    24. public static UpForward plugin;
    25.  
    26. public void onEnable() {
    27. PluginDescriptionFile pdfFile = this.getDescription();
    28. this.logger.info("[" + pdfFile.getName() + "] v" + pdfFile.getVersion() + " is enabled!");
    29. }
    30.  
    31. public void onDisable() {
    32. PluginDescriptionFile pdfFile = this.getDescription();
    33. this.logger.info("[" + pdfFile.getName() + "] is disabled!");
    34. }
    35.  
    36. public void addtoList(final Player player) {
    37. cooldown.add(player);
    38. final Runnable remove = new Runnable() {
    39. public void run() { cooldown.remove(player); }
    40. };
    41. final ScheduledFuture<?> schedule = scheduler.scheduleAtFixedRate(remove, 1, 10, TimeUnit.SECONDS);
    42. scheduler.schedule(new Runnable() {
    43. public void run() { schedule.cancel(true); }
    44. }, cooldown_lenght, TimeUnit.SECONDS);
    45. }
    46.  
    47. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    48. if (commandLabel.equalsIgnoreCase("upforward")) {
    49. if (args.length == 2 && args[0].equalsIgnoreCase("set")) {
    50. cooldown_lenght = Integer.parseInt(args[1].replaceAll("[\\D]", ""));
    51. sender.sendMessage("Cooldown lenght set to " + cooldown_lenght + " seconds.");
    52. return true;
    53. } else {
    54. if (sender instanceof Player) {
    55. Player player = (Player)sender;
    56. if (player.hasPermission("player.upforward")) {
    57. if (!cooldown.contains(player)) {
    58. Location location = player.getLocation().add(1, 0, 0);
    59. boolean found = false;
    60. while (!found) {
    61. if (player.getWorld().getBlockAt(location).getType().equals(Material.AIR)) {
    62. if (player.getWorld().getBlockAt(location.add(0, 1, 0)).getType().equals(Material.AIR)) {
    63. found = true;
    64. }
    65. } else {
    66. location.add(0, 1, 0);
    67. }
    68. }
    69. player.teleport(location);
    70. addtoList(player);
    71. return true;
    72. } else {
    73. sender.sendMessage(ChatColor.RED + "You must wait " + cooldown_lenght + " seconds between each command.");
    74. }
    75. } else {
    76. sender.sendMessage(ChatColor.RED + "You don't have permissions to execute this command.");
    77. }
    78. } else {
    79. sender.sendMessage("You must be a player to execute this command.");
    80. }
    81. }
    82. }
    83. return false;
    84. }
    85. }

    In this version, you can change the cool down length with /upforward set <length>
     
    Benlewis9000 likes this.
  15. Offline

    Benlewis9000

    au2001
    Great, I'll have a look this afternoon :)

    EDIT: Um, my pc has broken... Fails to get past the startup screen and just goes black, saying my wacom drivers are not installed out something...
     
  16. Offline

    MordorKing78

    Simple, set the y to 2 and teleport the player to it set also the x etc.. is this so hard? Everyone can code this ;)
     
  17. Offline

    timtower Administrator Administrator Moderator

    And what if the player is looking the other way?
     
  18. Offline

    MordorKing78

    Hmm thats smart XD But i thought you just can get were the player is looking at.
     
  19. Offline

    timtower Administrator Administrator Moderator

    You can :p
     
  20. Offline

    JoTyler

    timtower MordorKing78 But that is saying that the y+2 and the x+ 1(direction) is air … if it isn't well… Suffocation.
     
  21. Offline

    au2001

    You can download the ned version, I redid the permissions :
    upforward.use lets you use /upforward
    upforward.cooldown.bypass lets you bypass the cool down
    And I added the config, you choose the cool down length (it's in seconds).
    Also, I made that it takes the closest hole there is above you, here is a 2d illustration :
    ||_||||
    ||__||
    ||_x || <-- Goes here, not at the surface
    ||_||||
    ||P|| <-- Player that does /upforward
    ||||||
    _ -> air
    || -> blocks
     
  22. Offline

    MordorKing78

    No it goes + try it with an effect u set the y to 2 and the effect will go up 2. Ur get the location with p.getlocation etc.

    You cant suffocate in air.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  23. Offline

    JoTyler

  24. Offline

    MordorKing78

    Its saying first he gets that location the he adds a y of 2 and x of +1 were u looking at.
    Like p.getLocation.add(0,2,1) or something

    I could help u with it.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  25. Offline

    au2001

    MordorKing78
    That's too late sorry ;)

    I will upload the new version in a few hours, it should be the final one.
     
  26. Offline

    MordorKing78

    K, I was just asking because making a cooldown isnt hard.
     
  27. Offline

    au2001

    not really no, just do that :
    Code:java
    1. private static final ScheduledExecutorService worker = Executors.newSingleThreadScheduledExecutor();
    2. static ArrayList<Player> cooldown = new ArrayList<Player>();
    3.  
    4. if (!cooldown.contains(player) || player.hasPermission("upforward.cooldown.bypass")) {
    5. ...
    6. if (!player.hasPermission("upforward.cooldown.bypass")) {
    7. cooldown.add(player);
    8. Runnable task = new Runnable() {
    9. public void run() {
    10. cooldown.remove(0);
    11. }
    12. };
    13. worker.schedule(task, getConfig().getInt("cooldown"), TimeUnit.SECONDS);
    14. }
    15. } else {
    16. // ERROR MESSAGE, cool down isn't finished yet
    17. }
     
  28. Offline

    au2001

    lucasbuck
    Since this plugin has been created, please mark this as filled.
    If I helped you, like me, follow me and donate!
     
    lucasbuck likes this.
  29. Offline

    lucasbuck

    Thank you very much, and sorry for the late reply! After the update, I've had a mess. Kind of bad when you build and educational server with a ton of Citizens that give kids quests, and then they break Citizens. Still trying to sort out what direction to go. But again, thanks so much and sorry I didn't reply sooner.
     
  30. Offline

    au2001

Share This Page