Advertisement
amitay12123

Untitled

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