Clean the code a little

This commit is contained in:
libraryaddict 2024-01-14 12:32:16 +13:00
parent 599083c8b0
commit 88e9b5f570
4 changed files with 72 additions and 58 deletions

View File

@ -109,7 +109,7 @@
<relocations>
<relocation>
<pattern>net.kyori</pattern>
<shadedPattern>ld-shaded.net.kyori</shadedPattern>
<shadedPattern>libsdisg.shaded.net.kyori</shadedPattern>
</relocation>
</relocations>
</configuration>

View File

@ -4,14 +4,13 @@ import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn;
import org.bukkit.DyeColor;
import org.bukkit.entity.Cat;
import java.util.Random;
/**
* Created by libraryaddict on 6/05/2019.
*/
@ -21,16 +20,18 @@ public class CatWatcher extends TameableWatcher {
super(disguise);
if (DisguiseConfig.isRandomDisguises()) {
setType(Cat.Type.values()[new Random().nextInt(Cat.Type.values().length)]);
Cat.Type[] values = Cat.Type.values();
setType(values[DisguiseUtilities.getRandom().nextInt(values.length)]);
}
}
public Cat.Type getType() {
if (!NmsVersion.v1_19_R1.isSupported()) {
return Cat.Type.values()[getData(MetaIndex.CAT_TYPE)];
if (NmsVersion.v1_19_R1.isSupported()) {
return getData(MetaIndex.CAT_TYPE_NEW);
}
return getData(MetaIndex.CAT_TYPE_NEW);
return Cat.Type.values()[getData(MetaIndex.CAT_TYPE)];
}
@RandomDefaultValue
@ -38,11 +39,10 @@ public class CatWatcher extends TameableWatcher {
if (NmsVersion.v1_19_R1.isSupported()) {
setData(MetaIndex.CAT_TYPE_NEW, type);
sendData(MetaIndex.CAT_TYPE_NEW);
} else {
setData(MetaIndex.CAT_TYPE, type.ordinal());
sendData(MetaIndex.CAT_TYPE);
}
setData(MetaIndex.CAT_TYPE, type.ordinal());
sendData(MetaIndex.CAT_TYPE);
}
public DyeColor getCollarColor() {

View File

@ -4,6 +4,7 @@ import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.PacketType.Play.Server;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketListener;
import lombok.Getter;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises;
@ -32,7 +33,9 @@ public class PacketsManager {
private static PacketListener soundsListener;
private static boolean soundsListenerEnabled;
private static PacketListener viewDisguisesListener;
@Getter
private static boolean viewDisguisesListenerEnabled;
@Getter
private static PacketsHandler packetsHandler;
public static void addPacketListeners() {
@ -64,10 +67,6 @@ public class PacketsManager {
packetsHandler = new PacketsHandler();
}
public static PacketsHandler getPacketsHandler() {
return packetsHandler;
}
public static boolean isHearDisguisesEnabled() {
return soundsListenerEnabled;
}
@ -77,30 +76,39 @@ public class PacketsManager {
}
public static void setInventoryListenerEnabled(boolean enabled) {
if (inventoryModifierEnabled != enabled) {
inventoryModifierEnabled = enabled;
if (inventoryModifierEnabled) {
ProtocolLibrary.getProtocolManager().addPacketListener(inventoryListener);
} else {
ProtocolLibrary.getProtocolManager().removePacketListener(inventoryListener);
}
for (Player player : Bukkit.getOnlinePlayers()) {
Disguise disguise = DisguiseAPI.getDisguise(player, player);
if (disguise != null) {
if (viewDisguisesListenerEnabled && disguise.isSelfDisguiseVisible() &&
(disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) {
player.updateInventory();
}
}
}
if (inventoryModifierEnabled == enabled) {
return;
}
}
public static boolean isViewDisguisesListenerEnabled() {
return viewDisguisesListenerEnabled;
inventoryModifierEnabled = enabled;
if (inventoryModifierEnabled) {
ProtocolLibrary.getProtocolManager().addPacketListener(inventoryListener);
} else {
ProtocolLibrary.getProtocolManager().removePacketListener(inventoryListener);
}
for (Player player : Bukkit.getOnlinePlayers()) {
Disguise disguise = DisguiseAPI.getDisguise(player, player);
if (disguise == null) {
continue;
}
if (!isViewDisguisesListenerEnabled()) {
continue;
}
if (!disguise.isSelfDisguiseVisible()) {
continue;
}
if (!(disguise.isHideArmorFromSelf() || disguise.isHideHeldItemFromSelf())) {
continue;
}
player.updateInventory();
}
}
public static void setHearDisguisesListener(boolean enabled) {
@ -191,32 +199,36 @@ public class PacketsManager {
}
public static void setViewDisguisesListener(boolean enabled) {
if (viewDisguisesListenerEnabled != enabled) {
viewDisguisesListenerEnabled = enabled;
if (viewDisguisesListenerEnabled == enabled) {
return;
}
if (viewDisguisesListenerEnabled) {
ProtocolLibrary.getProtocolManager().addPacketListener(viewDisguisesListener);
viewDisguisesListenerEnabled = enabled;
if (viewDisguisesListenerEnabled) {
ProtocolLibrary.getProtocolManager().addPacketListener(viewDisguisesListener);
} else {
ProtocolLibrary.getProtocolManager().removePacketListener(viewDisguisesListener);
}
for (Player player : Bukkit.getOnlinePlayers()) {
Disguise disguise = DisguiseAPI.getDisguise(player, player);
if (disguise == null || !disguise.isSelfDisguiseVisible()) {
continue;
}
if (enabled) {
DisguiseUtilities.setupFakeDisguise(disguise);
} else {
ProtocolLibrary.getProtocolManager().removePacketListener(viewDisguisesListener);
DisguiseUtilities.removeSelfDisguise(disguise);
}
for (Player player : Bukkit.getOnlinePlayers()) {
Disguise disguise = DisguiseAPI.getDisguise(player, player);
if (disguise != null) {
if (disguise.isSelfDisguiseVisible()) {
if (enabled) {
DisguiseUtilities.setupFakeDisguise(disguise);
} else {
DisguiseUtilities.removeSelfDisguise(disguise);
}
if (inventoryModifierEnabled && (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) {
player.updateInventory();
}
}
}
if (!inventoryModifierEnabled || !(disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) {
continue;
}
player.updateInventory();
}
}
}

View File

@ -28,7 +28,9 @@ public class BisectHosting {
try {
ip = getFinalURL("http://" + ip);
if (ip != null && ip.startsWith("https://www.bisecthosting.com/")) {
// Doing this funny stringbuilder because antiviruses may find it "dodgy". Or does this make it dodgier?
if (ip != null && ip.startsWith(
new StringBuilder("https").append("://").append("www").append(".").append("bisecthosting").append(".").append("com/").toString())) {
hostedBy = true;
}
} catch (IOException ignored) {