From 431c245043da884300031347f147750a686b9e4e Mon Sep 17 00:00:00 2001 From: Lorenzo Date: Fri, 12 Jun 2020 13:53:28 +0200 Subject: [PATCH] implemented possible player teleportation invisibility fix. enable it in config.yml, at "settings.fix-invisible-after-tp", ONLY IF NEEDED. only some buggy Spigot versions have this issue. --- .gitignore | 1 + ant_buildversion_end.txt | 2 +- build.number | 4 +-- src/config.yml | 3 ++- .../hubthat/commands/WorldTpCommand.java | 7 ++++- .../hubthat/utils/CommonValues.java | 5 ++++ .../hubthat/utils/ConfigEntries.java | 2 ++ .../mindoverflow/hubthat/utils/Debugger.java | 2 +- .../hubthat/utils/TeleportUtils.java | 27 ++++++++++++++++--- .../hubthat/utils/files/FileUtils.java | 1 + 10 files changed, 45 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 9f11b75..1395c2d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .idea/ +out/ diff --git a/ant_buildversion_end.txt b/ant_buildversion_end.txt index b1a1360..a55e5aa 100644 --- a/ant_buildversion_end.txt +++ b/ant_buildversion_end.txt @@ -1 +1 @@ -Changing back build version 10.0.161 in file plugin.yml to BUILD_VERSION... \ No newline at end of file +Changing back build version 10.0.165 in file plugin.yml to BUILD_VERSION... \ No newline at end of file diff --git a/build.number b/build.number index d2f3f38..3759b79 100644 --- a/build.number +++ b/build.number @@ -1,5 +1,5 @@ #Build Number for ANT. Do not edit! -#Sat Apr 04 18:08:45 CEST 2020 -build.number=162 +#Fri Jun 12 13:50:42 CEST 2020 +build.number=166 \#Build=Number for ANT. Do not edit\! \#Tue=Jul 30 16\:09\:09 CEST 2019 diff --git a/src/config.yml b/src/config.yml index ddb7369..d6cb469 100644 --- a/src/config.yml +++ b/src/config.yml @@ -16,4 +16,5 @@ teleportation: teleport-to-hub-on-respawn: false respawn-handler: true settings: - multiverse-bypass: false \ No newline at end of file + multiverse-bypass: false + fix-invisible-after-tp: false \ No newline at end of file diff --git a/src/net/mindoverflow/hubthat/commands/WorldTpCommand.java b/src/net/mindoverflow/hubthat/commands/WorldTpCommand.java index 4364c34..a7cbbff 100644 --- a/src/net/mindoverflow/hubthat/commands/WorldTpCommand.java +++ b/src/net/mindoverflow/hubthat/commands/WorldTpCommand.java @@ -12,6 +12,9 @@ import org.bukkit.entity.Player; import java.util.logging.Level; +import static net.mindoverflow.hubthat.utils.TeleportUtils.fixInvisibilityAfter; +import static net.mindoverflow.hubthat.utils.TeleportUtils.fixInvisibilityBefore; + public class WorldTpCommand implements CommandExecutor { @@ -70,7 +73,9 @@ public class WorldTpCommand implements CommandExecutor // Cast Player to commandSender so we can teleport it. Player player = (Player)commandSender; // Teleport the Player. - player.teleport(destinationLocation); + fixInvisibilityBefore(player, destinationLocation); + plugin.getServer().getScheduler().runTaskLater(plugin, () -> player.teleport(destinationLocation), 1); + fixInvisibilityAfter(player); // Tell the player he has been teleported. String teleportedMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.INFO_WORLDTP_TELEPORTED, false); teleportedMessage = teleportedMessage.replace("%world%", destinationWorldName).replace("%w%", destinationWorldName); diff --git a/src/net/mindoverflow/hubthat/utils/CommonValues.java b/src/net/mindoverflow/hubthat/utils/CommonValues.java index d60cd59..d8e7e82 100644 --- a/src/net/mindoverflow/hubthat/utils/CommonValues.java +++ b/src/net/mindoverflow/hubthat/utils/CommonValues.java @@ -1,5 +1,8 @@ package net.mindoverflow.hubthat.utils; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + import java.util.ArrayList; public class CommonValues @@ -10,4 +13,6 @@ public class CommonValues public static ArrayListcancelRunnable = new ArrayList<>(); public static Boolean updateChecker = true; + public static boolean invisibilityFix = false; // sometimes, in buggy versions of Spigot, players become invisible after getting teleported. this fixes the problem. + public static final ItemStack AIR = new ItemStack(Material.AIR, 1); } diff --git a/src/net/mindoverflow/hubthat/utils/ConfigEntries.java b/src/net/mindoverflow/hubthat/utils/ConfigEntries.java index 1795c84..304addd 100644 --- a/src/net/mindoverflow/hubthat/utils/ConfigEntries.java +++ b/src/net/mindoverflow/hubthat/utils/ConfigEntries.java @@ -24,6 +24,8 @@ public enum ConfigEntries MULTIVERSE_BYPASS("settings.multiverse-bypass"), + INVISIBILITY_FIX("settings.fix-invisible-after-tp"), + //UPDATE_CHECKER_ENABLE("updates.enable-update-checker"), ; diff --git a/src/net/mindoverflow/hubthat/utils/Debugger.java b/src/net/mindoverflow/hubthat/utils/Debugger.java index 798366a..3671ad0 100644 --- a/src/net/mindoverflow/hubthat/utils/Debugger.java +++ b/src/net/mindoverflow/hubthat/utils/Debugger.java @@ -10,7 +10,7 @@ import java.util.logging.Level; public class Debugger { // Enable or disable debugging messages (aka verbosity). - private final boolean DEBUGGING = false; + private final boolean DEBUGGING = true; // Initialize needed variables. We will need those variables to be able to precisely debug the plugin. private String className; diff --git a/src/net/mindoverflow/hubthat/utils/TeleportUtils.java b/src/net/mindoverflow/hubthat/utils/TeleportUtils.java index 11cd658..c558cbf 100644 --- a/src/net/mindoverflow/hubthat/utils/TeleportUtils.java +++ b/src/net/mindoverflow/hubthat/utils/TeleportUtils.java @@ -24,7 +24,11 @@ public class TeleportUtils { Location location = new Location(plugin.getServer().getWorld(worldName), x, y, z, (float)yaw, (float)pitch); Player player = plugin.getServer().getPlayer(playerName); - player.teleport(location); + if(player == null) return; + + fixInvisibilityBefore(player, location); + plugin.getServer().getScheduler().runTaskLater(plugin, () -> player.teleport(location), 1); + fixInvisibilityAfter(player); } // Method to teleport a player, given its username and defined if it's a hub or a spawn. @@ -121,7 +125,9 @@ public class TeleportUtils // Store the location in a variable and teleport the player to it. final Location finalLocation = new Location(destinationWorld, x, y, z, (float)yaw, (float)pitch); - player.teleport(finalLocation); + fixInvisibilityBefore(player, finalLocation); + plugin.getServer().getScheduler().runTaskLater(plugin, () -> player.teleport(finalLocation), 1); + fixInvisibilityAfter(player); // Check if the player is teleporting to the hub. if(type == FileUtils.FileType.HUB_YAML) @@ -135,7 +141,7 @@ public class TeleportUtils sender.sendMessage(message); } } - else if(type == FileUtils.FileType.SPAWN_YAML) + else //if(type == FileUtils.FileType.SPAWN_YAML) // left here but commented, for easy understanding { MessageUtils.sendLocalizedMessage(player, LocalizedMessages.INFO_SPAWN_TELEPORTED); @@ -150,4 +156,19 @@ public class TeleportUtils { teleportPlayer(sender, player, type, null); } + + public static void fixInvisibilityAfter(Player player) + { + if(CommonValues.invisibilityFix) + { + debugger.sendDebugMessage(Level.INFO, "Invisibility fix enabled!"); + player.getInventory().addItem(CommonValues.AIR); + } + } + + public static void fixInvisibilityBefore(Player player, Location destination) + { + destination.getChunk().load(); + } + } diff --git a/src/net/mindoverflow/hubthat/utils/files/FileUtils.java b/src/net/mindoverflow/hubthat/utils/files/FileUtils.java index cc477ea..8d011da 100644 --- a/src/net/mindoverflow/hubthat/utils/files/FileUtils.java +++ b/src/net/mindoverflow/hubthat/utils/files/FileUtils.java @@ -70,6 +70,7 @@ public class FileUtils UpdateChecker.task = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, plugin.updateChecker, 1, 20 * 60 * 60 * 12); } + CommonValues.invisibilityFix = config.getBoolean(ConfigEntries.INVISIBILITY_FIX.path); } // Only reload the needed File.