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