mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2025-01-25 17:01:28 +01:00
teleportation will now correctly reset fly/upgrades.
This commit is contained in:
parent
43a6373ce2
commit
efd4b9938e
@ -1,8 +1,22 @@
|
||||
package me.goodandevil.skyblock.listeners;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.UUID;
|
||||
|
||||
import me.goodandevil.skyblock.SkyBlock;
|
||||
import me.goodandevil.skyblock.api.event.player.PlayerIslandEnterEvent;
|
||||
import me.goodandevil.skyblock.api.event.player.PlayerIslandExitEvent;
|
||||
import me.goodandevil.skyblock.api.event.player.PlayerIslandSwitchEvent;
|
||||
import me.goodandevil.skyblock.config.FileManager;
|
||||
import me.goodandevil.skyblock.config.FileManager.Config;
|
||||
import me.goodandevil.skyblock.island.Island;
|
||||
import me.goodandevil.skyblock.island.IslandManager;
|
||||
import me.goodandevil.skyblock.island.IslandWorld;
|
||||
import me.goodandevil.skyblock.message.MessageManager;
|
||||
import me.goodandevil.skyblock.playerdata.PlayerData;
|
||||
import me.goodandevil.skyblock.playerdata.PlayerDataManager;
|
||||
import me.goodandevil.skyblock.sound.SoundManager;
|
||||
import me.goodandevil.skyblock.utils.version.NMSUtil;
|
||||
import me.goodandevil.skyblock.utils.version.Sounds;
|
||||
import me.goodandevil.skyblock.visit.Visit;
|
||||
import me.goodandevil.skyblock.world.WorldManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
@ -12,175 +26,162 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
|
||||
import me.goodandevil.skyblock.SkyBlock;
|
||||
import me.goodandevil.skyblock.api.event.player.PlayerIslandEnterEvent;
|
||||
import me.goodandevil.skyblock.api.event.player.PlayerIslandExitEvent;
|
||||
import me.goodandevil.skyblock.api.event.player.PlayerIslandSwitchEvent;
|
||||
import me.goodandevil.skyblock.config.FileManager;
|
||||
import me.goodandevil.skyblock.config.FileManager.Config;
|
||||
import me.goodandevil.skyblock.island.Island;
|
||||
import me.goodandevil.skyblock.message.MessageManager;
|
||||
import me.goodandevil.skyblock.island.IslandManager;
|
||||
import me.goodandevil.skyblock.island.IslandWorld;
|
||||
import me.goodandevil.skyblock.playerdata.PlayerData;
|
||||
import me.goodandevil.skyblock.playerdata.PlayerDataManager;
|
||||
import me.goodandevil.skyblock.sound.SoundManager;
|
||||
import me.goodandevil.skyblock.utils.version.NMSUtil;
|
||||
import me.goodandevil.skyblock.utils.version.Sounds;
|
||||
import me.goodandevil.skyblock.visit.Visit;
|
||||
import me.goodandevil.skyblock.world.WorldManager;
|
||||
import java.io.File;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Teleport implements Listener {
|
||||
|
||||
private final SkyBlock skyblock;
|
||||
private final SkyBlock skyblock;
|
||||
|
||||
public Teleport(SkyBlock skyblock) {
|
||||
this.skyblock = skyblock;
|
||||
}
|
||||
public Teleport(SkyBlock skyblock) {
|
||||
this.skyblock = skyblock;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
@EventHandler
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
PlayerDataManager playerDataManager = skyblock.getPlayerDataManager();
|
||||
MessageManager messageManager = skyblock.getMessageManager();
|
||||
IslandManager islandManager = skyblock.getIslandManager();
|
||||
SoundManager soundManager = skyblock.getSoundManager();
|
||||
WorldManager worldManager = skyblock.getWorldManager();
|
||||
FileManager fileManager = skyblock.getFileManager();
|
||||
PlayerDataManager playerDataManager = skyblock.getPlayerDataManager();
|
||||
MessageManager messageManager = skyblock.getMessageManager();
|
||||
IslandManager islandManager = skyblock.getIslandManager();
|
||||
SoundManager soundManager = skyblock.getSoundManager();
|
||||
WorldManager worldManager = skyblock.getWorldManager();
|
||||
FileManager fileManager = skyblock.getFileManager();
|
||||
|
||||
Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml"));
|
||||
FileConfiguration configLoad = config.getFileConfiguration();
|
||||
Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml"));
|
||||
FileConfiguration configLoad = config.getFileConfiguration();
|
||||
|
||||
islandManager.removeUpgrades(player, false);
|
||||
islandManager.loadPlayer(player);
|
||||
islandManager.removeUpgrades(player, false);
|
||||
islandManager.loadPlayer(player);
|
||||
|
||||
if (worldManager.isIslandWorld(player.getWorld())) {
|
||||
boolean isCause = false;
|
||||
if (worldManager.isIslandWorld(player.getWorld())) {
|
||||
boolean isCause = false;
|
||||
|
||||
if (event.getCause() == TeleportCause.ENDER_PEARL || event.getCause() == TeleportCause.NETHER_PORTAL
|
||||
|| event.getCause() == TeleportCause.END_PORTAL) {
|
||||
isCause = true;
|
||||
} else {
|
||||
if (NMSUtil.getVersionNumber() > 9) {
|
||||
if (event.getCause() == TeleportCause.END_GATEWAY) {
|
||||
isCause = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (event.getCause() == TeleportCause.ENDER_PEARL || event.getCause() == TeleportCause.NETHER_PORTAL
|
||||
|| event.getCause() == TeleportCause.END_PORTAL) {
|
||||
isCause = true;
|
||||
} else {
|
||||
if (NMSUtil.getVersionNumber() > 9) {
|
||||
if (event.getCause() == TeleportCause.END_GATEWAY) {
|
||||
isCause = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isCause && !islandManager.hasPermission(player, "Portal")) {
|
||||
event.setCancelled(true);
|
||||
if (isCause && !islandManager.hasPermission(player, "Portal")) {
|
||||
event.setCancelled(true);
|
||||
|
||||
messageManager.sendMessage(player, configLoad.getString("Island.Settings.Permission.Message"));
|
||||
soundManager.playSound(player, Sounds.VILLAGER_NO.bukkitSound(), 1.0F, 1.0F);
|
||||
messageManager.sendMessage(player, configLoad.getString("Island.Settings.Permission.Message"));
|
||||
soundManager.playSound(player, Sounds.VILLAGER_NO.bukkitSound(), 1.0F, 1.0F);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (playerDataManager.hasPlayerData(player)) {
|
||||
PlayerData playerData = playerDataManager.getPlayerData(player);
|
||||
if (playerDataManager.hasPlayerData(player)) {
|
||||
PlayerData playerData = playerDataManager.getPlayerData(player);
|
||||
|
||||
Island island = islandManager.getIslandAtLocation(event.getTo());
|
||||
Island island = islandManager.getIslandAtLocation(event.getTo());
|
||||
|
||||
if (island != null) {
|
||||
if (!island.getOwnerUUID().equals(playerData.getOwner())) {
|
||||
if (!player.hasPermission("fabledskyblock.bypass") && !player.hasPermission("fabledskyblock.bypass.*")
|
||||
&& !player.hasPermission("fabledskyblock.*")) {
|
||||
if (!island.isOpen() && !island.isCoopPlayer(player.getUniqueId())) {
|
||||
event.setCancelled(true);
|
||||
if (island != null) {
|
||||
islandManager.giveUpgrades(player, island);
|
||||
islandManager.giveFly(player, island);
|
||||
if (!island.getOwnerUUID().equals(playerData.getOwner())) {
|
||||
if (!player.hasPermission("fabledskyblock.bypass") && !player.hasPermission("fabledskyblock.bypass.*")
|
||||
&& !player.hasPermission("fabledskyblock.*")) {
|
||||
if (!island.isOpen() && !island.isCoopPlayer(player.getUniqueId())) {
|
||||
event.setCancelled(true);
|
||||
|
||||
messageManager.sendMessage(player,
|
||||
configLoad.getString("Island.Visit.Closed.Plugin.Message"));
|
||||
soundManager.playSound(player, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F);
|
||||
messageManager.sendMessage(player,
|
||||
configLoad.getString("Island.Visit.Closed.Plugin.Message"));
|
||||
soundManager.playSound(player, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F);
|
||||
|
||||
return;
|
||||
} else if (fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml"))
|
||||
.getFileConfiguration().getBoolean("Island.Visitor.Banning")
|
||||
&& island.getBan().isBanned(player.getUniqueId())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else if (fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml"))
|
||||
.getFileConfiguration().getBoolean("Island.Visitor.Banning")
|
||||
&& island.getBan().isBanned(player.getUniqueId())) {
|
||||
event.setCancelled(true);
|
||||
|
||||
messageManager.sendMessage(player,
|
||||
configLoad.getString("Island.Visit.Banned.Teleport.Message"));
|
||||
soundManager.playSound(player, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F);
|
||||
messageManager.sendMessage(player,
|
||||
configLoad.getString("Island.Visit.Banned.Teleport.Message"));
|
||||
soundManager.playSound(player, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (playerData.getIsland() != null && !playerData.getIsland().equals(island.getOwnerUUID())) {
|
||||
me.goodandevil.skyblock.api.island.Island exitIsland = null;
|
||||
if (playerData.getIsland() != null && !playerData.getIsland().equals(island.getOwnerUUID())) {
|
||||
me.goodandevil.skyblock.api.island.Island exitIsland = null;
|
||||
|
||||
OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(playerData.getIsland());
|
||||
OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(playerData.getIsland());
|
||||
|
||||
if (islandManager.containsIsland(playerData.getIsland())) {
|
||||
exitIsland = islandManager.getIsland(offlinePlayer).getAPIWrapper();
|
||||
}
|
||||
if (islandManager.containsIsland(playerData.getIsland())) {
|
||||
exitIsland = islandManager.getIsland(offlinePlayer).getAPIWrapper();
|
||||
}
|
||||
|
||||
Bukkit.getServer().getPluginManager().callEvent(new PlayerIslandExitEvent(player, exitIsland));
|
||||
Bukkit.getServer().getPluginManager()
|
||||
.callEvent(new PlayerIslandSwitchEvent(player, exitIsland, island.getAPIWrapper()));
|
||||
Bukkit.getServer().getPluginManager().callEvent(new PlayerIslandExitEvent(player, exitIsland));
|
||||
Bukkit.getServer().getPluginManager()
|
||||
.callEvent(new PlayerIslandSwitchEvent(player, exitIsland, island.getAPIWrapper()));
|
||||
|
||||
playerData.setVisitTime(0);
|
||||
}
|
||||
playerData.setVisitTime(0);
|
||||
}
|
||||
|
||||
if (worldManager.getIslandWorld(event.getTo().getWorld()) == IslandWorld.Normal) {
|
||||
if (!island.isWeatherSynchronized()) {
|
||||
player.setPlayerTime(island.getTime(),
|
||||
fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml"))
|
||||
.getFileConfiguration().getBoolean("Island.Weather.Time.Cycle"));
|
||||
player.setPlayerWeather(island.getWeather());
|
||||
}
|
||||
}
|
||||
if (worldManager.getIslandWorld(event.getTo().getWorld()) == IslandWorld.Normal) {
|
||||
if (!island.isWeatherSynchronized()) {
|
||||
player.setPlayerTime(island.getTime(),
|
||||
fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml"))
|
||||
.getFileConfiguration().getBoolean("Island.Weather.Time.Cycle"));
|
||||
player.setPlayerWeather(island.getWeather());
|
||||
}
|
||||
}
|
||||
|
||||
UUID islandOwnerUUID = playerData.getIsland();
|
||||
playerData.setIsland(island.getOwnerUUID());
|
||||
UUID islandOwnerUUID = playerData.getIsland();
|
||||
playerData.setIsland(island.getOwnerUUID());
|
||||
|
||||
if (islandOwnerUUID != null && islandManager.containsIsland(islandOwnerUUID)
|
||||
&& (playerData.getOwner() == null || !playerData.getOwner().equals(islandOwnerUUID))) {
|
||||
islandManager.unloadIsland(
|
||||
islandManager.getIsland(Bukkit.getServer().getOfflinePlayer(islandOwnerUUID)), null);
|
||||
}
|
||||
if (islandOwnerUUID != null && islandManager.containsIsland(islandOwnerUUID)
|
||||
&& (playerData.getOwner() == null || !playerData.getOwner().equals(islandOwnerUUID))) {
|
||||
islandManager.unloadIsland(
|
||||
islandManager.getIsland(Bukkit.getServer().getOfflinePlayer(islandOwnerUUID)), null);
|
||||
}
|
||||
|
||||
Visit visit = island.getVisit();
|
||||
Visit visit = island.getVisit();
|
||||
|
||||
if (!visit.isVisitor(player.getUniqueId())) {
|
||||
Bukkit.getServer().getPluginManager()
|
||||
.callEvent(new PlayerIslandEnterEvent(player, island.getAPIWrapper()));
|
||||
if (!visit.isVisitor(player.getUniqueId())) {
|
||||
Bukkit.getServer().getPluginManager()
|
||||
.callEvent(new PlayerIslandEnterEvent(player, island.getAPIWrapper()));
|
||||
|
||||
visit.addVisitor(player.getUniqueId());
|
||||
visit.save();
|
||||
}
|
||||
visit.addVisitor(player.getUniqueId());
|
||||
visit.save();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
player.resetPlayerTime();
|
||||
player.resetPlayerWeather();
|
||||
player.resetPlayerTime();
|
||||
player.resetPlayerWeather();
|
||||
|
||||
if (playerData.getIsland() != null) {
|
||||
me.goodandevil.skyblock.api.island.Island islandWrapper = null;
|
||||
island = islandManager.getIsland(Bukkit.getServer().getOfflinePlayer(playerData.getIsland()));
|
||||
if (playerData.getIsland() != null) {
|
||||
me.goodandevil.skyblock.api.island.Island islandWrapper = null;
|
||||
island = islandManager.getIsland(Bukkit.getServer().getOfflinePlayer(playerData.getIsland()));
|
||||
|
||||
if (island != null) {
|
||||
islandWrapper = island.getAPIWrapper();
|
||||
}
|
||||
if (island != null) {
|
||||
islandWrapper = island.getAPIWrapper();
|
||||
}
|
||||
|
||||
Bukkit.getServer().getPluginManager().callEvent(new PlayerIslandExitEvent(player, islandWrapper));
|
||||
Bukkit.getServer().getPluginManager().callEvent(new PlayerIslandExitEvent(player, islandWrapper));
|
||||
|
||||
playerData.setVisitTime(0);
|
||||
}
|
||||
playerData.setVisitTime(0);
|
||||
}
|
||||
|
||||
UUID islandOwnerUUID = playerData.getIsland();
|
||||
playerData.setIsland(null);
|
||||
UUID islandOwnerUUID = playerData.getIsland();
|
||||
playerData.setIsland(null);
|
||||
|
||||
if (islandOwnerUUID != null && islandManager.containsIsland(islandOwnerUUID)
|
||||
&& (playerData.getOwner() == null || !playerData.getOwner().equals(islandOwnerUUID))) {
|
||||
islandManager.unloadIsland(
|
||||
islandManager.getIsland(Bukkit.getServer().getOfflinePlayer(islandOwnerUUID)), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (islandOwnerUUID != null && islandManager.containsIsland(islandOwnerUUID)
|
||||
&& (playerData.getOwner() == null || !playerData.getOwner().equals(islandOwnerUUID))) {
|
||||
islandManager.unloadIsland(
|
||||
islandManager.getIsland(Bukkit.getServer().getOfflinePlayer(islandOwnerUUID)), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user