Add AdvancedShulkerFix and optimize LoginLocationFix

This commit is contained in:
HaHaWTH
2023-12-31 17:19:30 +08:00
parent c89a818696
commit be976b6738
6 changed files with 87 additions and 14 deletions
@@ -11,6 +11,7 @@ import fr.xephi.authme.initialization.OnShutdownPlayerSaver;
import fr.xephi.authme.initialization.OnStartupTasks;
import fr.xephi.authme.initialization.SettingsProvider;
import fr.xephi.authme.initialization.TaskCloser;
import fr.xephi.authme.listener.AdvancedShulkerFixListener;
import fr.xephi.authme.listener.BedrockAutoLoginListener;
import fr.xephi.authme.listener.BlockListener;
import fr.xephi.authme.listener.DoubleLoginFixListener;
@@ -359,6 +360,9 @@ public class AuthMe extends JavaPlugin {
if (settings.getProperty(SecuritySettings.ANTI_GHOST_PLAYERS)) {
pluginManager.registerEvents(injector.getSingleton(DoubleLoginFixListener.class), this);
}
if (settings.getProperty(SecuritySettings.ADVANCED_SHULKER_FIX)) {
pluginManager.registerEvents(injector.getSingleton(AdvancedShulkerFixListener.class), this);
}
}
/**
@@ -0,0 +1,43 @@
package fr.xephi.authme.listener;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockDispenseEvent;
//This fix is only for Minecraft 1.13-
public class AdvancedShulkerFixListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onDispenserActivate(BlockDispenseEvent event) {
Block block = event.getBlock();
if (block.getFace(block) == BlockFace.DOWN) {
//If the block is in y = 0
if (block.getY() == 0) {
event.setCancelled(true);
}
}
if (block.getFace(block) == BlockFace.UP) {
//If the block is in y = 255
if (block.getY() == 255) {
event.setCancelled(true);
}
}
}
//This implementation method will be available in my another plugin
// @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
// public void onDispenserBePlaced(BlockPlaceEvent event){
// Block block = event.getBlock();
// if (block.getType().equals(Material.DISPENSER)){
// if (block.getFace(block) == BlockFace.DOWN && block.getY() == 0){
// event.setCancelled(true);
// }
// if (block.getFace(block) == BlockFace.UP && block.getY() == 255){
// event.setCancelled(true);
// }
// }
// }
}
@@ -35,7 +35,7 @@ public class LoginLocationFixListener implements Listener {
private static Material materialPortal = Material.matchMaterial("PORTAL");
private static boolean isChecked = false; // false: unchecked/method not available true: method is available
private static boolean isAvailable; // false: unchecked/method not available true: method is available
private final boolean isSmartAsyncTeleport = AuthMe.settings.getProperty(SecuritySettings.SMART_ASYNC_TELEPORT);
private final boolean isFixPortalStuck = AuthMe.settings.getProperty(SecuritySettings.LOGIN_LOC_FIX_SUB_PORTAL);
private final boolean isFixGroundStuck = AuthMe.settings.getProperty(SecuritySettings.LOGIN_LOC_FIX_SUB_UNDERGROUND);
@@ -50,15 +50,15 @@ public class LoginLocationFixListener implements Listener {
}
try {
Method getMinHeightMethod = World.class.getMethod("getMinHeight");
isChecked = true;
isAvailable = true;
} catch (NoSuchMethodException e) {
isChecked = false;
isAvailable = false;
}
}
private int getMinHeight(World world) {
//This keeps compatibility of 1.16.x and lower
if (isChecked) {
if (isAvailable) {
return world.getMinHeight();
} else {
return 0;
@@ -97,10 +97,11 @@ public class LoginLocationFixListener implements Listener {
Material UpType = JoinLocation.getBlock().getRelative(BlockFace.UP).getType();
World world = player.getWorld();
int MaxHeight = world.getMaxHeight();
int MinHeight = getMinHeight(world);
if (!UpType.isOccluding() && !UpType.equals(Material.LAVA)) {
return;
}
for (int i = getMinHeight(world); i <= MaxHeight; i++) {
for (int i = MinHeight; i <= MaxHeight; i++) {
JoinLocation.setY(i);
Block JoinBlock = JoinLocation.getBlock();
if ((JoinBlock.getRelative(BlockFace.DOWN).getType().isBlock())
@@ -35,6 +35,11 @@ public final class SecuritySettings implements SettingsHolder {
public static final Property<Boolean> ANTI_GHOST_PLAYERS =
newProperty("3rdPartyFeature.fixes.antiGhostPlayer", false);
@Comment({"(MC1.13- only)",
"Should we fix the shulker crash bug with advanced method?"})
public static final Property<Boolean> ADVANCED_SHULKER_FIX =
newProperty("3rdPartyFeature.fixes.advancedShulkerFix", true);
@Comment({"Choose the best teleport method by server brand?",
"(Enable this if you are using Paper)"})
public static final Property<Boolean> SMART_ASYNC_TELEPORT =