Portals

Discussion in 'Plugin Development' started by XgXXSnipz, Mar 10, 2014.

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

    XgXXSnipz

    Ok so im making a plugin so that you can create portals by clicking a diamond block with a stick and then you do ./wc portal create and then when you step on the diamond block after that it will randomly teleport you, heres me code, I have no idea how do to the create portal points, my main class that does it by command
    Code:java
    1. package me.JoeyLangston.MCTeleport;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.Random;
    5.  
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.Location;
    9. import org.bukkit.command.Command;
    10. import org.bukkit.command.CommandSender;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.event.Listener;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14.  
    15. public class Main extends JavaPlugin implements Listener {
    16.  
    17.  
    18. ArrayList<Player> cooldown = new ArrayList<Player>();
    19.  
    20.  
    21. public void onEnable() {
    22. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    23.  
    24. }
    25.  
    26. public void onDisable() {
    27.  
    28. getLogger().info("MC-Teleport is now disabled.");
    29.  
    30. }
    31.  
    32. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    33. final Player p = (Player) sender;
    34. if(cmd.getName().equalsIgnoreCase("Wilderness")){
    35. if(cooldown.contains(p)) {
    36. p.sendMessage(ChatColor.YELLOW + "You must wait 5 seconds before using this command again!");
    37. return true;
    38. }
    39. Location loc = p.getLocation();
    40. Random rand = new Random();
    41. loc.setX(rand.nextInt(1001)-500);
    42. loc.setZ(rand.nextInt(1001)-500);
    43. loc.setY(5);
    44. p.sendMessage(ChatColor.YELLOW + "You Have Been Randomly Teleported!");
    45. p.teleport(loc);
    46. loc.add(0,69,0);
    47. cooldown.add(p);
    48. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    49. public void run(){
    50. cooldown.remove(p);
    51. }
    52. },100);
    53. return true;
    54. }
    55. return false;
    56.  
    57. }
    58. }
    59.  


    My portal class which doesnt even work



    Code:java
    1. package me.JoeyLangston.MCTeleport;
    2.  
    3. import java.util.Random;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.Location;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.player.PlayerMoveEvent;
    11.  
    12. public class Portal implements Listener {
    13.  
    14.  
    15.  
    16. @SuppressWarnings("deprecation")
    17. @EventHandler
    18. public void moveEvent(PlayerMoveEvent e) { //Checks if the player moves
    19. Player player = e.getPlayer();
    20. Location loc = player.getPlayer().getLocation();
    21. loc.setY(loc.getY() -1);
    22. int block = loc.getWorld().getBlockTypeIdAt(loc);
    23. if(block == 57) {
    24.  
    25. Random rand = new Random();
    26. loc.setX(rand.nextInt(1001)-500);
    27. loc.setZ(rand.nextInt(1001)-500);
    28. loc.setY(5);
    29.  
    30. player.sendMessage(ChatColor.YELLOW + "You Have Been Randomly Teleported!");
    31.  
    32.  
    33.  
    34. }
    35. }
    36. }


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

    TheRage66

    try registering that class in your onEnable like this

    Code:
    public void onEnable(){
      getServer().getPluginManager().registerEvents(new Portal(), this);
    }
     
    iiHeroo likes this.
  3. Offline

    deploycraft

    You think that will work?

    Im the one who requested this plugin from XgXXSnipz
     
  4. Offline

    TheRage66

  5. Offline

    deploycraft

    Also the plugin spawns us in blocks underground and lava/water.

    Whats the fix for that? Thanks
     
  6. Offline

    xXSniperzzXx_SD

    If you look at my portable portals plugin you can see how to make portals the "Cheaper" way(getting target from the item lore)
     
Thread Status:
Not open for further replies.

Share This Page