Advertisement
Guest User

Untitled

a guest
Dec 26th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. package me.AceLV.RandomTeleport;
  2.  
  3.  
  4. import java.io.File;
  5.  
  6. import org.bukkit.ChatColor;
  7. import org.bukkit.Location;
  8. import org.bukkit.command.Command;
  9. import org.bukkit.command.CommandSender;
  10. import org.bukkit.entity.Player;
  11. import org.bukkit.plugin.java.JavaPlugin;
  12.  
  13. public class Main extends JavaPlugin {
  14. @Override
  15. public void onEnable() {
  16.  
  17. if(!new File(this.getDataFolder(), "config.yml").exists()) {
  18. this.saveDefaultConfig();
  19. }
  20. }
  21. @Override
  22. public void onDisable() {
  23. }
  24.  
  25. public boolean onCommand(CommandSender thesender, Command cmd, String commandLabel, String[] args)
  26. {
  27. if(commandLabel.equalsIgnoreCase("rt"))
  28. {
  29. Player player = (Player) thesender;
  30. if(player.hasPermission("RandomTeleport.tp"))
  31. {
  32. int randomX = (int) (Math.random() * 1000);
  33. int randomZ = (int) (Math.random() * 1000);
  34. int randomY = player.getWorld().getHighestBlockYAt(randomX, randomZ);
  35.  
  36.  
  37. //This will get the string from the config
  38. String Config = this.getConfig().getString("teleport-message");
  39.  
  40. //This will replace the {Player} With the name
  41. String Replaced = Config.replace("{Player}", player.getName());
  42.  
  43. //This will translate the color codes!
  44. player.sendMessage(ChatColor.translateAlternateColorCodes('&', Replaced));
  45.  
  46. Location randomLocation = new Location(player.getWorld(), randomX, randomY, randomZ);
  47. player.teleport(randomLocation);
  48.  
  49. }
  50. else player.sendMessage(this.getConfig().getString("perm-deny-message"));
  51. }
  52. return true;
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement