diff options
author | HacktheTime <l4bg0jb7@duck.com> | 2023-09-03 11:09:38 +0200 |
---|---|---|
committer | HacktheTime <l4bg0jb7@duck.com> | 2023-09-03 11:09:38 +0200 |
commit | cdd951d912e172ea42fc9707a786db6e69ba2901 (patch) | |
tree | 006302c766d9e09e141a9ee03e73c0626750191b /src/main/java/de/hype/bbsentials/constants/enviromentShared | |
parent | 7d9f695e2603c2349ce0693bb0e1e6dbbd274fbc (diff) | |
download | BBsentials-cdd951d912e172ea42fc9707a786db6e69ba2901.tar.gz BBsentials-cdd951d912e172ea42fc9707a786db6e69ba2901.tar.bz2 BBsentials-cdd951d912e172ea42fc9707a786db6e69ba2901.zip |
added packet communication to work now at least as base. not all features changed and therefore supported yet. first version working at least partially with the new server.
fixed trapper yes via chat prompt action not working. changed the get getter of the string from messageOriginal in Chat.java to now use just messageOriginal.getString(). previosly removed everything in [] brackets.
Diffstat (limited to 'src/main/java/de/hype/bbsentials/constants/enviromentShared')
7 files changed, 442 insertions, 0 deletions
diff --git a/src/main/java/de/hype/bbsentials/constants/enviromentShared/AuthenticationConstants.java b/src/main/java/de/hype/bbsentials/constants/enviromentShared/AuthenticationConstants.java new file mode 100644 index 0000000..878f303 --- /dev/null +++ b/src/main/java/de/hype/bbsentials/constants/enviromentShared/AuthenticationConstants.java @@ -0,0 +1,7 @@ +package de.hype.bbsentials.constants.enviromentShared; + +public class AuthenticationConstants { + //Authentication Types + public static final String MOJANG = "MOJANG"; + public static final String DATABASE = "DATABASE"; +} diff --git a/src/main/java/de/hype/bbsentials/constants/enviromentShared/ChChestItem.java b/src/main/java/de/hype/bbsentials/constants/enviromentShared/ChChestItem.java new file mode 100644 index 0000000..3e6a346 --- /dev/null +++ b/src/main/java/de/hype/bbsentials/constants/enviromentShared/ChChestItem.java @@ -0,0 +1,46 @@ +package de.hype.bbsentials.constants.enviromentShared; + +public class ChChestItem { + private String displayName; + private boolean custom; + + public ChChestItem(String displayName) { + this.displayName = displayName; + this.custom = false; + } + + public ChChestItem(String displayName, boolean custom) { + this.displayName = displayName; + this.custom = custom; + } + + public String getDisplayName() { + return displayName; + } + + public ChChestItem setDisplayName(String displayName) { + this.displayName = displayName; + return this; + } + + public boolean isCustom() { + return custom; + } + + @Override + public String toString() { + return displayName; + } + + public boolean isGemstone() { + return displayName.startsWith("Flawless") && displayName.endsWith("Gemstone"); + } + + public boolean isRoboPart() { + String[] roboParts = {"Control Switch", "Electron Transmitter", "FTX 3070", "Robotron Reflector", "Superlite Motor", "Synthetic Heart"}; + for (String roboPart : roboParts) { + if (displayName.equals(roboPart)) return true; + } + return false; + } +}
\ No newline at end of file diff --git a/src/main/java/de/hype/bbsentials/constants/enviromentShared/ChChestItems.java b/src/main/java/de/hype/bbsentials/constants/enviromentShared/ChChestItems.java new file mode 100644 index 0000000..a416f6e --- /dev/null +++ b/src/main/java/de/hype/bbsentials/constants/enviromentShared/ChChestItems.java @@ -0,0 +1,87 @@ +package de.hype.bbsentials.constants.enviromentShared; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +public class ChChestItems { + private static final List<ChChestItem> items = new ArrayList<>(); + + public static final ChChestItem PrehistoricEgg = new ChChestItem("Prehistoric Egg"); + public static final ChChestItem Pickonimbus2000 = new ChChestItem("Pickonimbus 2000"); + public static final ChChestItem ControlSwitch = new ChChestItem("Control Switch"); + public static final ChChestItem ElectronTransmitter = new ChChestItem("Electron Transmitter"); + public static final ChChestItem FTX3070 = new ChChestItem("FTX 3070"); + public static final ChChestItem RobotronReflector = new ChChestItem("Robotron Reflector"); + public static final ChChestItem SuperliteMotor = new ChChestItem("Superlite Motor"); + public static final ChChestItem SyntheticHeart = new ChChestItem("Synthetic Heart"); + public static final ChChestItem FlawlessGemstone = new ChChestItem("Flawless Gemstone"); + public static final ChChestItem JungleHeart = new ChChestItem("Jungle Heart"); + + // Automatically populate predefined items using reflection + static { + Field[] fields = ChChestItems.class.getDeclaredFields(); + for (Field field : fields) { + if (field.getType().equals(ChChestItem.class) && isPublicStaticFinal(field)) { + try { + items.add((ChChestItem) field.get(null)); + } catch (IllegalAccessException e) { + // Handle exception + } + } + } + } + + public static ChChestItem getItem(String displayName) { + ChChestItem existingItem = getPredefinedItem(displayName); + + if (existingItem != null) { + return existingItem; + } + + ChChestItem customItem = new ChChestItem(displayName, true); + return customItem; + } + + private static ChChestItem getPredefinedItem(String displayName) { + for (ChChestItem item : items) { + if (item.getDisplayName().equals(displayName)) { + return item; + } + } + return null; + } + + public static ChChestItem[] getItem(String[] displayNames) { + ChChestItem[] result = new ChChestItem[displayNames.length]; + for (int i = 0; i < displayNames.length; i++) { + result[i] = getItem(displayNames[i]); + } + return result; + } + + // Utility method to check if a field is public, static, and final + private static boolean isPublicStaticFinal(Field field) { + return java.lang.reflect.Modifier.isPublic(field.getModifiers()) && + java.lang.reflect.Modifier.isStatic(field.getModifiers()) && + java.lang.reflect.Modifier.isFinal(field.getModifiers()); + } + + public static ChChestItem createCustomItem(String displayName) { + ChChestItem customItem = new ChChestItem(displayName, true); + items.add(customItem); + return customItem; + } + + public static List<ChChestItem> getAllItems() { + return items; + } + + public static List<String> getAllItemNames() { + return items.stream() + .map(ChChestItem::getDisplayName) + .collect(Collectors.toList()); + //very fancy way to convert a list to a list of values from the previous list + } +}
\ No newline at end of file diff --git a/src/main/java/de/hype/bbsentials/constants/enviromentShared/EnumUtils.java b/src/main/java/de/hype/bbsentials/constants/enviromentShared/EnumUtils.java new file mode 100644 index 0000000..8407774 --- /dev/null +++ b/src/main/java/de/hype/bbsentials/constants/enviromentShared/EnumUtils.java @@ -0,0 +1,209 @@ +package de.hype.bbsentials.constants.enviromentShared; + + +import de.hype.bbsentials.constants.BBDisplayNameProvider; +import de.hype.bbsentials.constants.BBDisplayNameProviderWithCustom; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +public class EnumUtils { + public static List<String> getAllDisplayNames(Class<? extends BBDisplayNameProvider> enumClass) { + List<String> displayNames = new ArrayList<>(); + + for (BBDisplayNameProvider item : enumClass.getEnumConstants()) { + displayNames.add(item.getDisplayName()); + } + + return displayNames; + } + + public static <T extends Enum<T> & BBDisplayNameProvider> List<T> getEnumsAsList(Class<T> enumClass) { + List<T> enumList = new ArrayList<>(); + + for (T item : enumClass.getEnumConstants()) { + enumList.add(item); + } + + return enumList; + } + + public static List<String> getDisplayNames(Collection<? extends BBDisplayNameProvider> itemList) { + List<String> displayNames = new ArrayList<>(); + for (BBDisplayNameProvider item : itemList) { + displayNames.add(item.getDisplayName()); + } + return displayNames; + } + + public static <T extends BBDisplayNameProvider> List<T> getEnumsAsList(List<T> itemList) { + List<T> enumList = new ArrayList<>(itemList); + return enumList; + } + + public static List<String> getAllEnumNames(Class<? extends Enum<?>> enumClass) { + List<String> enumNames = new ArrayList<>(); + Enum<?>[] enumConstants = enumClass.getEnumConstants(); + + for (Enum<?> enumConstant : enumConstants) { + enumNames.add(enumConstant.name()); + } + + return enumNames; + } + +// public interface BBDisplayNameProvider { +// String getDisplayName(); +// default public String serialize() { +// return name() + ":" + displayName; +// } +// +// default public ChChestItems deserialize(String serializedValue) { +// String[] parts = serializedValue.split(":"); +// if (parts.length != 2) { +// throw new IllegalArgumentException("Invalid serialized value format"); +// } +// String enumName = parts[0]; +// String displayName = parts[1]; +// +// return ChChestItems.valueOf(enumName).setDisplayName(displayName); +// } +// } + + + + // Methods for BBDisplayNameProviderWithCustom + + public static <T extends Enum<T> & BBDisplayNameProviderWithCustom> T getEnumByNameWithCustom(Class<T> enumClass, String enumName) { + boolean found = false; + for (T enumValue : enumClass.getEnumConstants()) { + if (enumValue.name().equals(enumName)) { + return (enumValue); + } + } + return createCustomEnum(enumClass, enumName); + } + + public static <T extends Enum<T> & BBDisplayNameProviderWithCustom> T getEnumByValueWithCustom(Class<T> enumClass, String value) { + for (T enumValue : enumClass.getEnumConstants()) { + if (enumValue.getDisplayName().equals(value)) { + return enumValue; + } + } + return (createCustomEnum(enumClass, value)); + + } + + public static <T extends Enum<T> & BBDisplayNameProviderWithCustom> T[] getEnumsByNameWithCustom(Class<T> enumClass, String[] names) { + List<T> matchingEnums = new ArrayList<>(); + + for (String name : names) { + boolean found = false; + for (T enumValue : enumClass.getEnumConstants()) { + if (enumValue.name().equals(name)) { + matchingEnums.add(enumValue); + found = true; + break; + } + } + if (!found) { + matchingEnums.add(createCustomEnum(enumClass, name)); + } + } + + return matchingEnums.toArray((T[]) java.lang.reflect.Array.newInstance(enumClass, 0)); + } + + public static <T extends Enum<T> & BBDisplayNameProviderWithCustom> T[] getEnumsByValueWithCustom(Class<T> enumClass, String[] values) { + List<T> matchingEnums = new ArrayList<>(); + + for (String value : values) { + boolean found = false; + for (T enumValue : enumClass.getEnumConstants()) { + if (enumValue.toString().equals(value)) { + matchingEnums.add(enumValue); + found = true; + break; + } + } + if (!found) { + matchingEnums.add(createCustomEnum(enumClass, value)); + } + } + + return matchingEnums.toArray((T[]) java.lang.reflect.Array.newInstance(enumClass, 0)); + } + + // Methods for BBDisplayNameProvider + + public static <T extends Enum<T> & BBDisplayNameProvider> T getEnumByName(Class<T> enumClass, String enumName) { + try { + return Enum.valueOf(enumClass, enumName); + } catch (IllegalArgumentException e) { + return null; // Enum value not found + } + } + + public static <T extends Enum<T> & BBDisplayNameProvider> T getEnumByValue(Class<T> enumClass, String value) { + for (T enumValue : enumClass.getEnumConstants()) { + if (enumValue.getDisplayName().equals(value)) { + return enumValue; + } + } + return null; + } + + public static <T extends Enum<T> & BBDisplayNameProvider> T[] getEnumsByName(Class<T> enumClass, String[] names) { + List<T> matchingEnums = new ArrayList<>(); + + for (String name : names) { + boolean found = false; + for (T enumValue : enumClass.getEnumConstants()) { + if (enumValue.name().equals(name)) { + matchingEnums.add(enumValue); + found = true; + break; + } + } + } + + return matchingEnums.toArray((T[]) java.lang.reflect.Array.newInstance(enumClass, 0)); + } + + public static <T extends Enum<T> & BBDisplayNameProvider> T[] getEnumsByValue(Class<T> enumClass, String[] values) { + List<T> matchingEnums = new ArrayList<>(); + + for (String value : values) { + boolean found = false; + for (T enumValue : enumClass.getEnumConstants()) { + if (enumValue.getDisplayName().equals(value)) { + matchingEnums.add(enumValue); + found = true; + break; + } + } + } + + return matchingEnums.toArray((T[]) java.lang.reflect.Array.newInstance(enumClass, 0)); + } + + private static <T extends Enum<T> & BBDisplayNameProviderWithCustom> T createCustomEnum(Class<T> enumClass, String value) { + T customEnum = null; + try { + customEnum = Enum.valueOf(enumClass, "Custom"); + } catch (Exception ignored) { + try { + customEnum = Enum.valueOf(enumClass, "CUSTOM"); + } catch (Exception ignored2) { + } + } + if (customEnum == null) { + } + customEnum.setDisplayName(value); + return customEnum; + + } +} + + diff --git a/src/main/java/de/hype/bbsentials/constants/enviromentShared/InternalReasonConstants.java b/src/main/java/de/hype/bbsentials/constants/enviromentShared/InternalReasonConstants.java new file mode 100644 index 0000000..79bf13a --- /dev/null +++ b/src/main/java/de/hype/bbsentials/constants/enviromentShared/InternalReasonConstants.java @@ -0,0 +1,14 @@ +package de.hype.bbsentials.constants.enviromentShared; + +public enum InternalReasonConstants { + INVALID_PARAMETER, + MISSING_PARAMETER, + INSUFFICIENT_PRIVILEGES, + MUTED, + BANNED, + API_UNSUPPORTED, + INVALID_LOGIN, + KICKED, + ANOTHER_LOGIN, + SERVER_RESTART +} diff --git a/src/main/java/de/hype/bbsentials/constants/enviromentShared/Islands.java b/src/main/java/de/hype/bbsentials/constants/enviromentShared/Islands.java new file mode 100644 index 0000000..f03c8ae --- /dev/null +++ b/src/main/java/de/hype/bbsentials/constants/enviromentShared/Islands.java @@ -0,0 +1,39 @@ +package de.hype.bbsentials.constants.enviromentShared; + +import de.hype.bbsentials.constants.BBDisplayNameProvider; + +public enum Islands implements BBDisplayNameProvider { + CRYSTAL_HOLLOWS("crystal_hollows", "Crystal Hollows"), + CRIMSON_ISLE("crimson_isle", "Crimson Isle"), + DEEP_CAVERNS("mining_2", "Deep Caverns"), + DUNGEON("dungeon", "Dungeon"), + DUNGEON_HUB("dungeon_hub", "Dungeon Hub"), + DWARVEN_MINES("mining_3", "Dwarven Mines"), + GOLD_MINE("mining_1", "Gold Mine"), + HUB("hub", "Hub"), + KUUDRA("kuudra", "Kuudra"), + PRIVATE_ISLAND("dynamic", "Private Islands"), + SPIDERS_DEN("combat_1", "Spider's Den"), + THE_END("combat_3", "The End"), + THE_FARMING_ISLANDS("farming_1", "The Farming Islands"), + THE_RIFT("rift", "The Rift"); + + + private final String internalName; + private final String displayName; + + Islands(String internalName, String displayName) { + this.internalName = internalName; + this.displayName = displayName; + } + + public String getInternalName() { + return internalName; + } + + public String getDisplayName() { + return displayName; + } + + +} diff --git a/src/main/java/de/hype/bbsentials/constants/enviromentShared/MiningEvents.java b/src/main/java/de/hype/bbsentials/constants/enviromentShared/MiningEvents.java new file mode 100644 index 0000000..1dc72d1 --- /dev/null +++ b/src/main/java/de/hype/bbsentials/constants/enviromentShared/MiningEvents.java @@ -0,0 +1,40 @@ +package de.hype.bbsentials.constants.enviromentShared; + + +import de.hype.bbsentials.constants.BBDisplayNameProvider; + +// Mining Events +public enum MiningEvents implements BBDisplayNameProvider { + BETTER_TOGETHER("Better Together"), + DOUBLE_POWDER("Double Powder"), + GONE_WITH_THE_WIND("Gone with the Wind"), + GOBLIN_RAID("Goblin Raid"), + MITHRIL_GOURMAND("Mithril Gourmand"), + RAFFLE("Raffle"); + + private final String displayName; + + MiningEvents(String displayName) { + this.displayName = displayName; + } + + @Override + public String getDisplayName() { + return displayName; + } + + //Some Events cant happen in Crystal Holows + public boolean isDWEventOnly() { + if (this.equals(MiningEvents.MITHRIL_GOURMAND) || this.equals(MiningEvents.RAFFLE) || this.equals(MiningEvents.GOBLIN_RAID)) { + return true; + } + return false; + } + + public static boolean isDWEventOnly(String event) { + if (event.equals(MiningEvents.MITHRIL_GOURMAND.getDisplayName()) || event.equals(MiningEvents.RAFFLE.getDisplayName()) || event.equals(MiningEvents.GOBLIN_RAID.getDisplayName())) { + return true; + } + return false; + } +} |