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.

This commit is contained in:
Bea 2020-06-12 13:53:28 +02:00
parent bcdad0739d
commit 431c245043
10 changed files with 45 additions and 9 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
.idea/ .idea/
out/

View File

@ -1 +1 @@
Changing back build version 10.0.161 in file plugin.yml to BUILD_VERSION... Changing back build version 10.0.165 in file plugin.yml to BUILD_VERSION...

View File

@ -1,5 +1,5 @@
#Build Number for ANT. Do not edit! #Build Number for ANT. Do not edit!
#Sat Apr 04 18:08:45 CEST 2020 #Fri Jun 12 13:50:42 CEST 2020
build.number=162 build.number=166
\#Build=Number for ANT. Do not edit\! \#Build=Number for ANT. Do not edit\!
\#Tue=Jul 30 16\:09\:09 CEST 2019 \#Tue=Jul 30 16\:09\:09 CEST 2019

View File

@ -16,4 +16,5 @@ teleportation:
teleport-to-hub-on-respawn: false teleport-to-hub-on-respawn: false
respawn-handler: true respawn-handler: true
settings: settings:
multiverse-bypass: false multiverse-bypass: false
fix-invisible-after-tp: false

View File

@ -12,6 +12,9 @@ import org.bukkit.entity.Player;
import java.util.logging.Level; 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 public class WorldTpCommand implements CommandExecutor
{ {
@ -70,7 +73,9 @@ public class WorldTpCommand implements CommandExecutor
// Cast Player to commandSender so we can teleport it. // Cast Player to commandSender so we can teleport it.
Player player = (Player)commandSender; Player player = (Player)commandSender;
// Teleport the Player. // 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. // Tell the player he has been teleported.
String teleportedMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.INFO_WORLDTP_TELEPORTED, false); String teleportedMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.INFO_WORLDTP_TELEPORTED, false);
teleportedMessage = teleportedMessage.replace("%world%", destinationWorldName).replace("%w%", destinationWorldName); teleportedMessage = teleportedMessage.replace("%world%", destinationWorldName).replace("%w%", destinationWorldName);

View File

@ -1,5 +1,8 @@
package net.mindoverflow.hubthat.utils; package net.mindoverflow.hubthat.utils;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList; import java.util.ArrayList;
public class CommonValues public class CommonValues
@ -10,4 +13,6 @@ public class CommonValues
public static ArrayList<String>cancelRunnable = new ArrayList<>(); public static ArrayList<String>cancelRunnable = new ArrayList<>();
public static Boolean updateChecker = true; 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);
} }

View File

@ -24,6 +24,8 @@ public enum ConfigEntries
MULTIVERSE_BYPASS("settings.multiverse-bypass"), MULTIVERSE_BYPASS("settings.multiverse-bypass"),
INVISIBILITY_FIX("settings.fix-invisible-after-tp"),
//UPDATE_CHECKER_ENABLE("updates.enable-update-checker"), //UPDATE_CHECKER_ENABLE("updates.enable-update-checker"),
; ;

View File

@ -10,7 +10,7 @@ import java.util.logging.Level;
public class Debugger public class Debugger
{ {
// Enable or disable debugging messages (aka verbosity). // 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. // Initialize needed variables. We will need those variables to be able to precisely debug the plugin.
private String className; private String className;

View File

@ -24,7 +24,11 @@ public class TeleportUtils
{ {
Location location = new Location(plugin.getServer().getWorld(worldName), x, y, z, (float)yaw, (float)pitch); Location location = new Location(plugin.getServer().getWorld(worldName), x, y, z, (float)yaw, (float)pitch);
Player player = plugin.getServer().getPlayer(playerName); 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. // 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. // 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); 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. // Check if the player is teleporting to the hub.
if(type == FileUtils.FileType.HUB_YAML) if(type == FileUtils.FileType.HUB_YAML)
@ -135,7 +141,7 @@ public class TeleportUtils
sender.sendMessage(message); 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); MessageUtils.sendLocalizedMessage(player, LocalizedMessages.INFO_SPAWN_TELEPORTED);
@ -150,4 +156,19 @@ public class TeleportUtils
{ {
teleportPlayer(sender, player, type, null); 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();
}
} }

View File

@ -70,6 +70,7 @@ public class FileUtils
UpdateChecker.task = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, plugin.updateChecker, 1, 20 * 60 * 60 * 12); 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. // Only reload the needed File.