Advertisement
Greenadine

PortalListener.java

Sep 1st, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.24 KB | None | 0 0
  1. package me.greenadine.worldspawns.portals;
  2.  
  3. import me.greenadine.worldspawns.Lang;
  4. import me.greenadine.worldspawns.Main;
  5. import me.greenadine.worldspawns.SettingsManager;
  6. import me.greenadine.worldspawns.SpawnFirework;
  7. import net.md_5.bungee.api.ChatColor;
  8. import org.bukkit.Location;
  9. import org.bukkit.Sound;
  10. import org.bukkit.World;
  11. import org.bukkit.block.Block;
  12. import org.bukkit.configuration.file.FileConfiguration;
  13. import org.bukkit.configuration.file.YamlConfiguration;
  14. import org.bukkit.entity.Player;
  15. import org.bukkit.event.EventHandler;
  16. import org.bukkit.event.Listener;
  17. import org.bukkit.event.player.PlayerMoveEvent;
  18.  
  19. import java.io.File;
  20. import java.util.List;
  21.  
  22. public class PortalListener implements Listener {
  23.  
  24. /*
  25. * WARNING: W.I.P.
  26. */
  27.  
  28. private Main main;
  29. SettingsManager settings;
  30. private Portal portal;
  31. private String prefix = ChatColor.translateAlternateColorCodes('&', Lang.PREFIX.toString());
  32.  
  33. public PortalListener(Main main) {
  34. this.main = main;
  35. settings = SettingsManager.getInstance();
  36. }
  37.  
  38. @EventHandler
  39. public void onPortalEnter(PlayerMoveEvent e) {
  40. Player p = e.getPlayer();
  41. Location ploc = p.getLocation();
  42. Block b = ploc.getBlock();
  43.  
  44. for (String portalName : portal.getPortals()) {
  45. File portalFile = new File(main.getDataFolder(), File.separator + "portals" + File.separator + portalName);
  46. FileConfiguration portals = YamlConfiguration.loadConfiguration(portalFile);
  47. List<Block> blocks = portal.getPortalBlocks(portalName);
  48.  
  49. for (Object block : blocks) {
  50. if (block == b) {
  51. if (portal.getType().equals("hub")) {
  52. World w = main.getServer().getWorld(settings.getHub().getString("hub.world"));
  53. double x2 = settings.getHub().getDouble("hub.x");
  54. double y2 = settings.getHub().getDouble("hub.y");
  55. double z2 = settings.getHub().getDouble("hub.z");
  56. float yaw = settings.getHub().getInt("hub.yaw");
  57. float pitch = settings.getHub().getInt("hub.pitch");
  58. p.teleport(new Location(w, x2, y2, z2, yaw, pitch));
  59. SpawnFirework firework = new SpawnFirework(p, main);
  60. if (main.getConfig().getBoolean("firework.enable")) {
  61. if (main.getConfig().getBoolean("firework.random")) {
  62. firework.spawnRandomFirework();
  63. } else {
  64. firework.spawnFirework();
  65. }
  66. } else {
  67. // Do nothing.
  68. }
  69. main.consoleMessage(prefix + ChatColor.translateAlternateColorCodes('&',
  70. Lang.COMMAND_HUB_TARGET_TELEPORTED.toString().replaceAll("%target%", p.getName())));
  71. p.sendMessage(prefix
  72. + ChatColor.translateAlternateColorCodes('&', Lang.COMMAND_HUB_TELEPORTED.toString()));
  73. if (enableSounds()) {
  74. p.playSound(p.getLocation(), Sound.ENTITY_ENDERMEN_TELEPORT, 10F, 1.0F);
  75. } else {
  76. // Nothing.
  77. }
  78. }
  79. if (portal.getType().equals("spawn")) {
  80. String worldname = portals.getString("PORTALNAME.spawn");
  81. World w = main.getServer().getWorld(worldname);
  82. if (w == null) {
  83. p.sendMessage(prefix + ChatColor.translateAlternateColorCodes('&',
  84. Lang.COMMAND_SPAWN_WORLD_NULL.toString().replaceAll("%worldname%", worldname)));
  85. return;
  86. }
  87. String xs = settings.getSpawns().getString("spawns." + worldname + ".x");
  88. String ys = settings.getSpawns().getString("spawns." + worldname + ".y");
  89. String zs = settings.getSpawns().getString("spawns." + worldname + ".z");
  90. String yaws = settings.getSpawns().getString("spawns." + worldname + ".yaw");
  91. String pitchs = settings.getSpawns().getString("spawns." + worldname + ".pitch");
  92. if (xs == null || ys == null || zs == null || yaws == null || pitchs == null) {
  93. p.sendMessage(prefix + ChatColor.translateAlternateColorCodes('7',
  94. Lang.COMMAND_SPAWN_NULL.toString().replaceAll("%worldname%", worldname)));
  95. return;
  96. } else {
  97. double x2 = settings.getSpawns().getDouble("spawns." + worldname + ".x");
  98. double y2 = settings.getSpawns().getDouble("spawns." + worldname + ".y");
  99. double z2 = settings.getSpawns().getDouble("spawns." + worldname + ".z");
  100. float yaw = settings.getSpawns().getInt("spawns." + worldname + ".yaw");
  101. float pitch = settings.getSpawns().getInt("spawns." + worldname + ".pitch");
  102. p.teleport(new Location(w, x2, y2, z2, yaw, pitch));
  103. SpawnFirework firework = new SpawnFirework(p, main);
  104. if (main.getConfig().getBoolean("firework.enable")) {
  105. if (main.getConfig().getBoolean("firework.random")) {
  106. firework.spawnRandomFirework();
  107. } else {
  108. firework.spawnFirework();
  109. }
  110. } else {
  111. // Do nothing.
  112. }
  113. main.consoleMessage(prefix + ChatColor.translateAlternateColorCodes('&',
  114. Lang.COMMAND_SPAWN_TELEPORT_PLAYER.toString().replaceAll("%target%", p.getName())));
  115. p.sendMessage(prefix + ChatColor.translateAlternateColorCodes('&',
  116. Lang.COMMAND_SPAWN_TELEPORT.toString()));
  117. if (enableSounds()) {
  118. p.playSound(p.getLocation(), Sound.ENTITY_ENDERMEN_TELEPORT, 10F, 1.0F);
  119. } else {
  120. // Nothing.
  121. }
  122. }
  123. } else {
  124. p.sendMessage(prefix + ChatColor.RED + "INVALID TYPE.");
  125. return;
  126. }
  127. }
  128. }
  129. }
  130. }
  131.  
  132. private boolean enableSounds() {
  133. if (main.getConfig().getBoolean("settings.enablesounds"))
  134. return true;
  135. if (!main.getConfig().getBoolean("settings.enableSounds")) {
  136. return false;
  137. } else {
  138. main.getConfig().set("settings.enableSounds", Boolean.valueOf(false));
  139. return false;
  140. }
  141. }
  142.  
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement