Advertisement
amitay12123

Untitled

May 31st, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 KB | None | 0 0
  1. package me.amitay.realwarp;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. import org.bukkit.Bukkit;
  7. import org.bukkit.Location;
  8. import org.bukkit.Material;
  9. import org.bukkit.World;
  10. import org.bukkit.command.Command;
  11. import org.bukkit.command.CommandSender;
  12. import org.bukkit.entity.Player;
  13. import org.bukkit.inventory.Inventory;
  14. import org.bukkit.inventory.ItemStack;
  15. import org.bukkit.inventory.meta.ItemMeta;
  16. import org.bukkit.plugin.java.JavaPlugin;
  17.  
  18. import net.md_5.bungee.api.ChatColor;
  19.  
  20. public class Main extends JavaPlugin{
  21.  
  22. @Override
  23.  
  24. public void onEnable() {
  25. getConfig().options().copyDefaults(true);
  26. saveConfig();
  27.  
  28. }
  29.  
  30.  
  31.  
  32. @Override
  33. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  34.  
  35.  
  36. if (!(sender instanceof Player)) {
  37. sender.sendMessage(ChatColor.DARK_RED + "Error");
  38. return true;
  39. }
  40.  
  41. Player p = (Player) sender;
  42.  
  43.  
  44.  
  45. if (args.length == 1){
  46. String arg = args[0].toLowerCase();
  47.  
  48. if(label.equalsIgnoreCase("setwarp")) {
  49.  
  50. if (args.length == 0) {
  51. p.sendMessage(ChatColor.RED + "please write a name of a warp");
  52. return true;
  53. }
  54.  
  55. List<String> list = getConfig().getStringList("warpnames");
  56. if (list != null) {
  57. list = new ArrayList<>();
  58. }
  59. if (!list.contains(args[0])) {
  60. list.add(args[0]);
  61. getConfig().set("warpnames", list);
  62. saveConfig();
  63.  
  64. }
  65.  
  66. getConfig().set("warps." + arg + ".world", p.getWorld().getName());
  67. getConfig().set("warps." + arg + ".x", p.getLocation().getX());
  68. getConfig().set("warps." + arg + ".y", p.getLocation().getY());
  69. getConfig().set("warps." + arg + ".z", p.getLocation().getZ());
  70. getConfig().set("warps." + arg + ".yaw", p.getLocation().getYaw());
  71. getConfig().set("warps." + arg + ".pitch", p.getLocation().getPitch());
  72.  
  73.  
  74.  
  75. saveConfig();
  76. p.sendMessage(ChatColor.GREEN + "Successfuly aded a new warp: " + ChatColor.DARK_GREEN + arg + "!");
  77.  
  78. return true;
  79.  
  80. }
  81.  
  82. if(label.equalsIgnoreCase("delwarp")) {
  83. if (getConfig().getConfigurationSection("warps") == null) {
  84. p.sendMessage(ChatColor.RED + "Error, this warp does not exist");
  85. return true;
  86.  
  87. }
  88.  
  89. List<String> list = getConfig().getStringList("warpnames");
  90. if (list != null) {
  91. list = new ArrayList<>();
  92. }
  93. if (list.contains(args[0])) {
  94. list.remove(args[0]);
  95. getConfig().set("warpnames", list);
  96. saveConfig();
  97. }
  98.  
  99.  
  100. getConfig().set("warps", null);
  101. saveConfig();
  102. p.sendMessage(ChatColor.GREEN + "Successfuly deleted warp: " + ChatColor.DARK_GREEN + arg + "!");
  103.  
  104. }
  105.  
  106. else if (label.equalsIgnoreCase("warp")) {
  107.  
  108. if (getConfig().getConfigurationSection("warps." + arg) == null) {
  109. p.sendMessage(ChatColor.RED + "Error, this warp does not exist");
  110. return true;
  111. }
  112.  
  113.  
  114.  
  115.  
  116. World world = Bukkit.getWorld(getConfig().getString("warps." + arg + ".world"));
  117.  
  118. double x =getConfig().getDouble("warps." + arg + ".x");
  119. double y =getConfig().getDouble("warps." + arg + ".y");
  120. double z =getConfig().getDouble("warps." + arg + ".z");
  121. float yaw = (float) getConfig().getDouble("warps." + arg + ".yaw");
  122. float pitch = (float) getConfig().getDouble("warps." + arg + ".pitch");
  123.  
  124. p.teleport(new Location(world, x, y, z, yaw, pitch));
  125.  
  126. p.sendMessage(ChatColor.GREEN + "You successfully teleported to the warp: " + ChatColor.DARK_GREEN + arg + ChatColor.GREEN + "!");
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135. }
  136.  
  137.  
  138. if(label.equalsIgnoreCase("warps")) {
  139.  
  140. if (args.length == 1) {
  141. p.sendMessage(ChatColor.RED + "Error");
  142. return true;
  143. }
  144.  
  145. List<String> list = getConfig().getStringList("warpnames");
  146. if (list != null) {
  147. int size = 9 + list.size() - (list.size()%9);
  148. Inventory inventory = Bukkit.createInventory(null, size, "warps");
  149. int slot = 0;
  150.  
  151. for(String warp:list) {
  152. ItemStack stack = new ItemStack(Material.STONE);
  153. ItemMeta meta = stack.getItemMeta();
  154. meta.setDisplayName(warp);
  155. stack.setItemMeta(meta);
  156. inventory.setItem(slot, stack);
  157. slot++;
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165. }
  166.  
  167.  
  168. p.openInventory(inventory);
  169.  
  170.  
  171. }
  172. }
  173.  
  174. }
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190. return false;
  191.  
  192.  
  193.  
  194.  
  195. }
  196. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement