From 0e81a2463cef0efcd71943120175c33021cb942e Mon Sep 17 00:00:00 2001 From: mosemister Date: Fri, 14 Jun 2024 17:09:48 +0100 Subject: [PATCH] Optimizations across the whole system --- src/main/java/org/core/TranslateCore.java | 18 - .../java/org/core/adventureText/AText.java | 197 ---------- .../adventure/AdventureText.java | 154 -------- .../format/NamedTextColours.java | 51 --- .../core/adventureText/format/TextColour.java | 83 ----- .../core/adventureText/legacy/LegacyText.java | 183 ---------- .../argument/SuggestCommandArgument.java | 7 +- .../arguments/id/BlockGroupArgument.java | 3 +- .../commands/timings/TimingsCommand.java | 20 +- .../java/org/core/config/parser/Parser.java | 1 - .../parsers/StringToATextLegacyParser.java | 20 -- src/main/java/org/core/entity/Entity.java | 25 -- .../living/human/player/LivePlayer.java | 4 +- .../connection/ClientConnectionEvent.java | 15 - .../java/org/core/inventory/Inventory.java | 24 +- .../inventories/BasicEntityInventory.java | 5 +- .../general/block/FurnaceInventory.java | 19 +- .../general/entity/PlayerInventory.java | 26 +- .../general/entity/ZombieInventory.java | 9 +- .../snapshots/UnknownInventorySnapshot.java | 15 +- .../DispenserBasedInventorySnapshot.java | 28 +- .../core/inventory/item/stack/ItemStack.java | 36 -- .../inventory/item/stack/LiveItemStack.java | 68 ++-- .../org/core/inventory/parts/ArmorPart.java | 17 +- .../core/inventory/parts/InventoryPart.java | 3 +- .../java/org/core/inventory/parts/Slot.java | 5 +- .../parts/snapshot/Grid2x2Snapshot.java | 12 +- .../parts/snapshot/Grid3x3Snapshot.java | 12 +- .../parts/snapshot/HotbarSnapshot.java | 12 +- .../snapshot/MainPlayerInventorySnapshot.java | 12 +- .../parts/snapshot/SlotSnapshot.java | 5 + src/main/java/org/core/logger/Logger.java | 6 - src/main/java/org/core/platform/Platform.java | 55 ++- .../org/core/platform/PlatformServer.java | 16 +- .../java/org/core/source/Messageable.java | 7 - .../core/source/command/ConsoleSource.java | 4 +- .../org/core/source/viewer/CommandViewer.java | 20 -- src/main/java/org/core/utils/BarUtils.java | 3 +- src/main/java/org/core/world/Extent.java | 23 +- src/main/java/org/core/world/WorldExtent.java | 20 +- .../org/core/world/boss/ServerBossBar.java | 100 ------ .../core/world/boss/colour/BossColour.java | 6 - .../core/world/boss/colour/BossColours.java | 35 -- .../org/core/world/expload/Explosion.java | 12 +- .../core/world/position/block/BlockType.java | 19 +- .../position/block/details/BlockDetails.java | 11 +- .../block/entity/TileEntitySnapshot.java | 13 +- .../block/entity/sign/SignTileEntity.java | 28 -- .../position/block/grouptype/BlockGroup.java | 24 +- .../position/block/grouptype/BlockGroups.java | 64 +--- .../grouptype/versions/BlockGroups1V13.java | 336 ------------------ .../grouptype/versions/CommonBlockGroups.java | 75 ---- .../grouptype/versions/CoreBlockGroup.java | 16 - .../world/position/impl/BlockPosition.java | 10 +- .../org/core/world/structure/Structure.java | 9 +- 55 files changed, 355 insertions(+), 1646 deletions(-) delete mode 100644 src/main/java/org/core/adventureText/AText.java delete mode 100644 src/main/java/org/core/adventureText/adventure/AdventureText.java delete mode 100644 src/main/java/org/core/adventureText/format/NamedTextColours.java delete mode 100644 src/main/java/org/core/adventureText/format/TextColour.java delete mode 100644 src/main/java/org/core/adventureText/legacy/LegacyText.java delete mode 100644 src/main/java/org/core/config/parser/parsers/StringToATextLegacyParser.java delete mode 100644 src/main/java/org/core/source/viewer/CommandViewer.java delete mode 100644 src/main/java/org/core/world/boss/ServerBossBar.java delete mode 100644 src/main/java/org/core/world/boss/colour/BossColour.java delete mode 100644 src/main/java/org/core/world/boss/colour/BossColours.java delete mode 100644 src/main/java/org/core/world/position/block/grouptype/versions/BlockGroups1V13.java delete mode 100644 src/main/java/org/core/world/position/block/grouptype/versions/CommonBlockGroups.java delete mode 100644 src/main/java/org/core/world/position/block/grouptype/versions/CoreBlockGroup.java diff --git a/src/main/java/org/core/TranslateCore.java b/src/main/java/org/core/TranslateCore.java index 39d4c788..e6059e9d 100644 --- a/src/main/java/org/core/TranslateCore.java +++ b/src/main/java/org/core/TranslateCore.java @@ -11,7 +11,6 @@ import org.core.platform.plugin.CorePlugin; import org.core.schedule.ScheduleManager; import org.core.source.command.ConsoleSource; -import org.core.world.boss.ServerBossBar; import org.jetbrains.annotations.NotNull; import java.io.*; @@ -46,12 +45,6 @@ public static boolean hasStarted() { PlatformServer getRawServer(); - @Deprecated(forRemoval = true) - ServerBossBar bossBuilder(); - - @Deprecated(forRemoval = true) - ServerBossBar bossBuilder(BossBar bar); - ConfigManager getRawConfigManager(); CurrencyManager getRawCurrencyManager(); @@ -89,17 +82,6 @@ static ConfigurationStream.ConfigurationFile createConfigurationFile(File file, return getConfigManager().read(file, type); } - @Deprecated(forRemoval = true) - static ServerBossBar createBossBar() { - return TranslateCore.CoreImplementation.getImplementation().bossBuilder(); - } - - - @Deprecated(forRemoval = true) - static ServerBossBar createBossBar(@NotNull BossBar bar) { - return TranslateCore.CoreImplementation.getImplementation().bossBuilder(bar); - } - static Optional> getStandAloneLauncher() { InputStream is = TranslateCore.class.getResourceAsStream("/META-INF/translate-core.properties"); if (is == null) { diff --git a/src/main/java/org/core/adventureText/AText.java b/src/main/java/org/core/adventureText/AText.java deleted file mode 100644 index 774855b8..00000000 --- a/src/main/java/org/core/adventureText/AText.java +++ /dev/null @@ -1,197 +0,0 @@ -package org.core.adventureText; - -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.ComponentLike; -import org.core.adventureText.adventure.AdventureText; -import org.core.adventureText.format.TextColour; -import org.core.adventureText.legacy.LegacyText; -import org.core.utils.ComponentUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Collections; -import java.util.List; -import java.util.Optional; - -/** - * AText is a wrapper for all text on the server. If the server platform has AdventureComponent provided with it - * (such as Sponge or Paper) then AText will wrap over that, however if the platform doesn't have AdventureComponent - * then AText will wrap over a String using Legacy chat colours. - *

- * AText is immutable, therefore any modifications you do will be applied to the result of the method - * - * @deprecated Removed as component is now supported by all platforms (except spigot). Using Component - */ -@Deprecated(forRemoval = true) -public interface AText extends ComponentLike { - - String COMPONENT_CLASS_PATH = "net.kyori.adventure.text.Component"; - String PLAIN_COMPONENT_CLASS_PATH = "net.kyori.adventure.text.serializer.plain.PlainComponentSerializer"; - String LEGACY_COMPONENT_CLASS_PATH = "net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer"; - - @Override - default @NotNull Component asComponent() { - if (this instanceof AdventureText) { - return ((AdventureText) this).getComponent(); - } - return ComponentUtils.fromLegacy(this.toLegacy()); - } - - /** - * Adds the provided text to the end of this text - * - * @param aText The text to add to the end - * @return The modified text - */ - @NotNull AText append(@NotNull AText aText); - - /** - * Checks if the provided text is included in this text - * Note, that colours must match, if you don't need to match colours, then use {@link #toPlain()} - * - * @param aText The text to check for - * @return if the provided text is contained - */ - boolean contains(@NotNull AText aText); - - /** - * Checks if the provided string is included in this text - * Node, that the colours, styles, etc don't need to match - * - * @param s The string to check for - * @return If the provided text is contained - */ - default boolean contains(@NotNull String s) { - return this.toPlain().contains(s); - } - - /** - * Checks if the provided string is included in this text - * Node, that the colours, styles, etc don't need to match - * - * @param s The string to check for - * @param ignoreCase true if the s should be ignored on case - * @return If the provided text is contained - */ - default boolean contains(@NotNull String s, boolean ignoreCase) { - if (ignoreCase) { - return this.containsIgnoreCase(s); - } - return this.toPlain().contains(s); - } - - boolean containsIgnoreCase(@NotNull String s); - - /** - * Replace all the matching with the provided AText - * - * @param containing The text to look for - * @param aText The text to replace with - * @return The modified text - */ - @NotNull AText withAllAs(@NotNull String containing, @Nullable AText aText); - - @NotNull AText withAllAsIgnoreCase(@NotNull String containing, @Nullable AText aText); - - /** - * Gets the text colour of this text - * - * @return The colour of the text - if colour is not changed, then it will be {@link Optional#empty()} - */ - Optional getColour(); - - /** - * Changes the colour of this text with the provided colour, - * this can be null to remove the colour. Removing the colour - * will set the colour to the default. If default and this has - * a parent with a colour then that colour will be displayed on this text - * - * @param colour The colour to change to - * @return The modified text - */ - @NotNull AText withColour(@Nullable TextColour colour); - - /** - * Gets the children of the AText - * - * @return The children of the AText - */ - @NotNull List getChildren(); - - /** - * Gets the text within this text - * - * @return the text in String form - */ - @NotNull String toPlain(); - - /** - * Gets the text in legacy form - * - * @return the legacy text in String form - */ - @NotNull String toLegacy(); - - /** - * Removes the colour. See {@link #withColour(TextColour)} for more info - * - * @return The modified text - */ - default AText removeColour() { - return this.withColour(null); - } - - /** - * Checks if the provided text is equal via legacy text - * - * @param text The text to compare - * @return boolean check - */ - default boolean equalsLegacy(AText text) { - return this.toLegacy().equals(text.toLegacy()); - } - - /** - * Checks if the provided text has the same text - * - * @param text The provided text - * @return boolean check - */ - default boolean equalsIgnoreCase(AText text) { - return this.toPlain().equalsIgnoreCase(text.toPlain()); - } - - /** - * Converts a string with no formatting into AText - * - * @param text The text to wrap - * @return The text object - */ - static AText ofPlain(@NotNull String text) { - try { - Class.forName(COMPONENT_CLASS_PATH); - Class.forName(PLAIN_COMPONENT_CLASS_PATH); - return AdventureText.plain(text); - } catch (ClassNotFoundException e) { - return new LegacyText(null, text, Collections.emptyList()); - } - } - - /** - * Converts a string with legacy formatting into AText - * - * @param text The text to wrap - * @return The text object - */ - static AText ofLegacy(@NotNull String text) { - try { - Class.forName(COMPONENT_CLASS_PATH); - Class.forName(PLAIN_COMPONENT_CLASS_PATH); - Class.forName(LEGACY_COMPONENT_CLASS_PATH); - return AdventureText.legacy(text); - } catch (ClassNotFoundException e) { - return new LegacyText(null, text, Collections.emptyList()); - } - } - -} diff --git a/src/main/java/org/core/adventureText/adventure/AdventureText.java b/src/main/java/org/core/adventureText/adventure/AdventureText.java deleted file mode 100644 index 903afec6..00000000 --- a/src/main/java/org/core/adventureText/adventure/AdventureText.java +++ /dev/null @@ -1,154 +0,0 @@ -package org.core.adventureText.adventure; - -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.TextReplacementConfig; -import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.format.TextColor; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; -import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer; -import net.kyori.adventure.util.RGBLike; -import org.core.adventureText.AText; -import org.core.adventureText.format.NamedTextColours; -import org.core.adventureText.format.TextColour; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; - -@Deprecated(forRemoval = true) -public class AdventureText implements AText { - - private final Component component; - - public AdventureText(Component component) { - this.component = component; - } - - private AdventureText toAdventure(AText aText) { - if (aText instanceof AdventureText) { - return (AdventureText) aText; - } - throw new IllegalStateException("text needs to be adventureText to interact with adventureText, found " + aText - .getClass() - .getSimpleName()); - } - - public @NotNull Component getComponent() { - return this.component; - } - - @Override - public @NotNull AText append(@NotNull AText aText) { - return new AdventureText(this.component.append(this.toAdventure(aText).component)); - } - - @Override - public boolean contains(@NotNull AText aText) { - return this.component.contains(this.toAdventure(aText).component); - } - - @Override - public boolean containsIgnoreCase(@NotNull String s) { - return this.toPlain().toLowerCase().contains(s.toLowerCase()); - } - - @Override - public @NotNull AText withAllAs(@NotNull String containing, @Nullable AText aText) { - return new AdventureText(this.component.replaceText(TextReplacementConfig - .builder() - .matchLiteral(containing) - .replacement(this.toAdventure(aText).component) - .build())); - } - - @Override - public @NotNull AText withAllAsIgnoreCase(@NotNull String containing, @Nullable AText aText) { - String asPlain = PlainComponentSerializer.plain().serialize(this.component); - Component component = this.component; - - int containingLength = containing.length(); - int plainLength = asPlain.length(); - - for (int plain = 0; plain < asPlain.length(); plain++) { - int testingLength = (plain + containingLength); - if (plainLength < testingLength) { - break; - } - String contains = asPlain.substring(plain, plain + containingLength); - if (!contains.equalsIgnoreCase(containing)) { - continue; - } - Component replacement = Component.empty(); - if (aText != null) { - replacement = this.toAdventure(aText).component; - } - - component = component.replaceText( - TextReplacementConfig.builder().matchLiteral(contains).replacement(replacement).build()); - } - return new AdventureText(component); - } - - @Override - public Optional getColour() { - TextColor colour = this.component.color(); - if (colour == null) { - return Optional.empty(); - } - if (colour instanceof NamedTextColor) { - Optional opText = NamedTextColours - .colours() - .parallelStream() - .filter(tc -> tc.getBlue() == ((RGBLike) colour).blue()) - .filter(tc -> tc.getGreen() == ((RGBLike) colour).green()) - .filter(tc -> tc.getRed() == ((RGBLike) colour).red()) - .findAny(); - if (opText.isPresent()) { - return opText; - } - } - return Optional.of(new TextColour(colour.red(), colour.green(), colour.blue())); - } - - @Override - public @NotNull AText withColour(@Nullable TextColour colour) { - if (colour == null) { - return new AdventureText(this.component.color(null)); - } - return new AdventureText( - this.component.color(TextColor.color(colour.getRed(), colour.getGreen(), colour.getBlue()))); - } - - @Override - public @NotNull List getChildren() { - return this.component.children().stream().map(AdventureText::new).collect(Collectors.toList()); - } - - @Override - public @NotNull String toPlain() { - return PlainComponentSerializer.plain().serialize(this.component); - } - - @Override - public @NotNull String toLegacy() { - return LegacyComponentSerializer.legacySection().serialize(this.component); - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof AText)) { - return false; - } - return this.toPlain().equals(((AText) obj).toPlain()); - } - - public static AdventureText plain(@NotNull String text) { - return new AdventureText(PlainComponentSerializer.plain().deserialize(text)); - } - - public static AdventureText legacy(@NotNull String text) { - return new AdventureText(LegacyComponentSerializer.legacySection().deserialize(text)); - } -} diff --git a/src/main/java/org/core/adventureText/format/NamedTextColours.java b/src/main/java/org/core/adventureText/format/NamedTextColours.java deleted file mode 100644 index 45cdf70e..00000000 --- a/src/main/java/org/core/adventureText/format/NamedTextColours.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.core.adventureText.format; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -/** - * A list of known legacy colours that can be used with {@link org.core.adventureText.AText} - */ -@Deprecated(forRemoval = true) -public interface NamedTextColours { - - TextColour AQUA = new TextColour("AQUA", 'b', 85, 255, 255); - TextColour BLACK = new TextColour("BLACK", '0', 0, 0, 0); - TextColour BLUE = new TextColour("BLUE", '9', 85, 85, 255); - TextColour DARK_AQUA = new TextColour("DARK_AQUA", '3', 0, 170, 170); - TextColour DARK_BLUE = new TextColour("DARK_BLUE", '1', 0, 0, 170); - TextColour DARK_GRAY = new TextColour("DARK_GRAY", '8', 85, 85, 85); - TextColour DARK_GREEN = new TextColour("DARK_GREEN", '2', 0, 170, 0); - TextColour DARK_PURPLE = new TextColour("DARK_PURPLE", '5', 170, 0, 170); - TextColour DARK_RED = new TextColour("DARK_RED", '4', 170, 0, 0); - TextColour GOLD = new TextColour("GOLD", '6', 255, 170, 0); - TextColour GRAY = new TextColour("GRAY", '7', 170, 170, 170); - TextColour GREEN = new TextColour("GREEN", 'a', 85, 255, 85); - TextColour LIGHT_PURPLE = new TextColour("LIGHT_PURPLE", 'd', 255, 85, 255); - TextColour RED = new TextColour("RED", 'c', 255, 85, 85); - TextColour WHITE = new TextColour("WHITE", 'f', 255, 255, 255); - TextColour YELLOW = new TextColour("YELLOW", 'e', 255, 255, 85); - - - static Set colours() { - return new HashSet<>(Arrays.asList( - AQUA, - BLACK, - BLUE, - DARK_AQUA, - DARK_BLUE, - DARK_GRAY, - DARK_GREEN, - DARK_PURPLE, - DARK_RED, - GOLD, - GRAY, - GREEN, - LIGHT_PURPLE, - RED, - WHITE, - YELLOW - )); - } -} diff --git a/src/main/java/org/core/adventureText/format/TextColour.java b/src/main/java/org/core/adventureText/format/TextColour.java deleted file mode 100644 index 0ec714e5..00000000 --- a/src/main/java/org/core/adventureText/format/TextColour.java +++ /dev/null @@ -1,83 +0,0 @@ -package org.core.adventureText.format; - -import org.jetbrains.annotations.Nullable; - -import java.util.Optional; - -/** - * A text colour with RGB ability - */ -@Deprecated(forRemoval = true) -public class TextColour { - - public static final char SYMBOL = 'ยง'; - private final int red; - private final int green; - private final int blue; - private final String name; - private final Character legacy; - - /** - * Creates a text colour using RGB. Note that this will only work if AdventureComponent is enabled - * - * @param red The red colour, between 0-255 - * @param green The green colour, between 0-255 - * @param blue The blue colour, between 0-255 - */ - public TextColour(int red, int green, int blue) { - this(null, null, red, green, blue); - } - - TextColour(@Nullable String name, @Nullable Character legacy, int red, int green, int blue) { - this.red = red; - this.green = green; - this.blue = blue; - this.name = name; - this.legacy = legacy; - } - - /** - * The red colour - * - * @return The red colour between 0-255 - */ - public int getRed() { - return this.red; - } - - /** - * The green colour - * - * @return The green colour between 0-255 - */ - public int getGreen() { - return this.green; - } - - /** - * The blue colour - * - * @return The blue colour between 0-255 - */ - public int getBlue() { - return this.blue; - } - - /** - * If a legacy colour, a name will be present - * - * @return The name of the colour, {@link Optional#empty()} if no name - */ - public Optional getName() { - return Optional.ofNullable(this.name); - } - - /** - * If a legacy colour, a charact will be present (typically a hex number) - * - * @return The legacy colour code of the colour, {@link Optional#empty()} if no character - */ - public Optional getLegacy() { - return Optional.ofNullable(this.legacy); - } -} diff --git a/src/main/java/org/core/adventureText/legacy/LegacyText.java b/src/main/java/org/core/adventureText/legacy/LegacyText.java deleted file mode 100644 index 4e0ad753..00000000 --- a/src/main/java/org/core/adventureText/legacy/LegacyText.java +++ /dev/null @@ -1,183 +0,0 @@ -package org.core.adventureText.legacy; - -import org.core.adventureText.AText; -import org.core.adventureText.format.NamedTextColours; -import org.core.adventureText.format.TextColour; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.*; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -@Deprecated(forRemoval = true) -public class LegacyText implements AText { - - private final @Nullable String text; - private final @Nullable TextColour colour; - private final @NotNull List children = new ArrayList<>(); - - public LegacyText(@Nullable TextColour colour, @Nullable String text, @NotNull Collection children) { - this.text = text; - this.colour = colour; - this.children.addAll(children); - } - - private LegacyText toLegacy(AText text) { - if (text instanceof LegacyText) { - return (LegacyText) text; - } - return new LegacyText(null, text.toLegacy(), Collections.emptyList()); - } - - @Override - public @NotNull LegacyText append(@NotNull AText aText) { - this.children.add(this.toLegacy(aText)); - return this; - } - - @Override - public boolean contains(@NotNull AText aText) { - if (this.text != null) { - LegacyText legacy = this.toLegacy(aText); - if (legacy.text != null && this.text.contains(legacy.text)) { - return true; - } - } - return this.children.stream().anyMatch(t -> t.contains(aText)); - } - - @Override - public boolean containsIgnoreCase(@NotNull String s) { - if (this.text != null) { - if (this.text.toLowerCase().contains(s.toLowerCase())) { - return true; - } - } - return this.children.parallelStream().anyMatch(t -> t.containsIgnoreCase(s)); - } - - @Override - public @NotNull LegacyText withAllAs(@NotNull String containing, @Nullable AText aText) { - String text = null; - if (aText == null) { - aText = AText.ofPlain(""); - } - if (this.text != null) { - //SOMETHING ISNT RIGHT HERE - String legacyText = aText.toLegacy(); - text = this.text.replaceAll(containing, legacyText); - } - final AText finalText = aText; - List children = this.children - .stream() - .map(lt -> lt.withAllAs(containing, finalText)) - .collect(Collectors.toList()); - return new LegacyText(this.colour, text, children); - } - - @Override - public @NotNull AText withAllAsIgnoreCase(@NotNull String containing, @Nullable AText aText) { - String text = this.text; - if (this.text != null && this.text.toLowerCase().contains(containing.toLowerCase())) { - text = this.text.replaceAll("(?i)" + containing, aText == null ? "" : aText.toLegacy()); - } - List children = this.children - .parallelStream() - .map(lt -> (LegacyText) lt.withAllAsIgnoreCase(containing, aText)) - .collect(Collectors.toList()); - return new LegacyText(this.colour, text, children); - } - - @Override - public Optional getColour() { - return Optional.ofNullable(this.colour); - } - - @Override - public @NotNull LegacyText withColour(@Nullable TextColour colour) { - return new LegacyText(colour, this.text, this.children); - } - - @Override - public @NotNull List getChildren() { - return this.children.stream().map(this::toLegacy).collect(Collectors.toList()); - } - - @Override - public @NotNull String toPlain() { - if (this.text != null) { - String text = this.text; - - for (TextColour colour : NamedTextColours.colours()) { - if (colour.getLegacy().isEmpty()) { - continue; - } - text = text.replaceAll(TextColour.SYMBOL + "" + colour.getLegacy().get(), ""); - } - return text + this.children.stream().map(LegacyText::toPlain).collect(Collectors.joining("")); - - } - return this.children.stream().map(LegacyText::toPlain).collect(Collectors.joining("")); - } - - @Override - public @NotNull String toLegacy() { - StringBuilder builder = new StringBuilder(); - if (this.colour != null) { - builder.append(this.colour.getLegacy().map(c -> TextColour.SYMBOL + "" + c).orElse("")); - } - if (this.text != null) { - builder.append(this.text); - } - String children = this.children.stream().map(LegacyText::toLegacy).collect(Collectors.joining("")); - builder.append(children); - return builder.toString(); - } - - public LegacyText plain(@NotNull CharSequence text) { - StringBuilder builder = new StringBuilder(); - int previous = 0; - for (int index = 0; index < text.length(); index++) { - char at = text.charAt(index); - if (at != TextColour.SYMBOL) { - continue; - } - builder.append(text, previous, index - 1); - index++; - previous = index; - } - return new LegacyText(null, builder.toString(), Collections.emptyList()); - } - - public LegacyText legacy(@NotNull String text) { - String[] split = text.split("" + TextColour.SYMBOL); - if (split.length == 0 || split.length == 1) { - return new LegacyText(null, text, Collections.emptyList()); - } - List collection = Stream.of(split).filter(v -> !v.isEmpty()).map(v -> { - char at = v.charAt(0); - Optional opLegacy = NamedTextColours - .colours() - .parallelStream() - .filter(tc -> tc.getLegacy().map(c -> c == at).orElse(false)) - .findAny(); - return opLegacy - .map(textColour -> new LegacyText(textColour, v.substring(1), Collections.emptyList())) - .orElseGet(() -> new LegacyText(null, v, Collections.emptyList())); - }).collect(Collectors.toList()); - - return new LegacyText(null, null, collection); - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof AText)) { - return false; - } - String plain = ((AText) obj).toPlain(); - String thisPlain = this.toPlain(); - - return thisPlain.equals(plain); - } -} diff --git a/src/main/java/org/core/command/argument/SuggestCommandArgument.java b/src/main/java/org/core/command/argument/SuggestCommandArgument.java index 26ac9dd2..75a8c90e 100644 --- a/src/main/java/org/core/command/argument/SuggestCommandArgument.java +++ b/src/main/java/org/core/command/argument/SuggestCommandArgument.java @@ -1,6 +1,6 @@ package org.core.command.argument; -import org.core.adventureText.AText; +import net.kyori.adventure.text.Component; import org.core.command.argument.context.CommandArgumentContext; import org.core.command.argument.context.CommandContext; import org.core.exceptions.NotEnoughArguments; @@ -10,10 +10,11 @@ public interface SuggestCommandArgument { - default Optional errorMessage(CommandContext context, CommandArgumentContext argument) { + default Optional errorMessage(CommandContext context, CommandArgumentContext argument) { return Optional.empty(); } - Collection suggest(CommandContext commandContext, CommandArgumentContext argument) throws NotEnoughArguments; + Collection suggest(CommandContext commandContext, CommandArgumentContext argument) + throws NotEnoughArguments; } diff --git a/src/main/java/org/core/command/argument/arguments/id/BlockGroupArgument.java b/src/main/java/org/core/command/argument/arguments/id/BlockGroupArgument.java index a7a1606d..4737a573 100644 --- a/src/main/java/org/core/command/argument/arguments/id/BlockGroupArgument.java +++ b/src/main/java/org/core/command/argument/arguments/id/BlockGroupArgument.java @@ -4,6 +4,7 @@ import org.core.world.position.block.grouptype.BlockGroup; import java.util.Collection; +import java.util.stream.Collectors; /** * Gets a block group from a single string argument @@ -16,6 +17,6 @@ public BlockGroupArgument(String id) { @Override public Collection getAll() { - return TranslateCore.getPlatform().getBlockGroups(); + return TranslateCore.getPlatform().getAllBlockGroups().collect(Collectors.toSet()); } } diff --git a/src/main/java/org/core/command/commands/timings/TimingsCommand.java b/src/main/java/org/core/command/commands/timings/TimingsCommand.java index 809f9a64..cba31b5c 100644 --- a/src/main/java/org/core/command/commands/timings/TimingsCommand.java +++ b/src/main/java/org/core/command/commands/timings/TimingsCommand.java @@ -1,8 +1,8 @@ package org.core.command.commands.timings; import com.sun.management.OperatingSystemMXBean; +import net.kyori.adventure.text.Component; import org.core.TranslateCore; -import org.core.adventureText.AText; import org.core.command.argument.ArgumentCommand; import org.core.command.argument.CommandArgument; import org.core.command.argument.arguments.operation.ExactArgument; @@ -40,27 +40,27 @@ public Optional getPermissionNode() { public boolean run(CommandContext commandContext, String... args) throws NotEnoughArguments { CommandSource viewer = commandContext.getSource(); OperatingSystemMXBean osBean = ManagementFactory.getPlatformMXBean(OperatingSystemMXBean.class); - viewer.sendMessage(AText.ofPlain("Getting timings")); - viewer.sendMessage(AText.ofPlain("CPU usage: " + osBean.getProcessCpuLoad())); - viewer.sendMessage(AText.ofPlain("CPU process usage: " + osBean.getProcessCpuLoad())); + viewer.sendMessage(Component.text("Getting timings")); + viewer.sendMessage(Component.text("CPU usage: " + osBean.getProcessCpuLoad())); + viewer.sendMessage(Component.text("CPU process usage: " + osBean.getProcessCpuLoad())); new Thread(() -> { Collection schedules = TranslateCore.getScheduleManager().getSchedules(); - viewer.sendMessage(AText.ofPlain("Scheduled tasks: " + schedules.size())); + viewer.sendMessage(Component.text("Scheduled tasks: " + schedules.size())); for (Scheduler scheduler : schedules) { - viewer.sendMessage(AText.ofPlain( + viewer.sendMessage(Component.text( "|---|" + scheduler.getDisplayName() + " - " + scheduler.getPlugin().getPluginId() + " |---|")); - viewer.sendMessage(AText.ofPlain(" - ASync: " + scheduler.isAsync())); + viewer.sendMessage(Component.text(" - ASync: " + scheduler.isAsync())); Optional startRunner = scheduler.getStartRunnerTime(); if (startRunner.isEmpty()) { - viewer.sendMessage(AText.ofPlain(" - Run Time: Not started")); + viewer.sendMessage(Component.text(" - Run Time: Not started")); } else { int duration = scheduler.getEndTime().orElseGet(LocalTime::now).getNano() - (startRunner.get().getNano()); - viewer.sendMessage(AText.ofPlain(" - Run Time: " + duration)); + viewer.sendMessage(Component.text(" - Run Time: " + duration)); } - viewer.sendMessage(AText.ofPlain(" - Has Ended: " + scheduler.getEndTime().isPresent())); + viewer.sendMessage(Component.text(" - Has Ended: " + scheduler.getEndTime().isPresent())); } }).start(); return true; diff --git a/src/main/java/org/core/config/parser/Parser.java b/src/main/java/org/core/config/parser/Parser.java index 65a78d37..fa8a976e 100644 --- a/src/main/java/org/core/config/parser/Parser.java +++ b/src/main/java/org/core/config/parser/Parser.java @@ -23,7 +23,6 @@ public interface Parser { StringToMinecraftTimeUnitParser STRING_TO_MINECRAFT_TIME_UNIT = new StringToMinecraftTimeUnitParser(); StringToBlockPosition STRING_TO_BLOCK_POSITION = new StringToBlockPosition(); StringToExactPosition STRING_TO_EXACT_POSITION = new StringToExactPosition(); - StringToATextLegacyParser STRING_TO_TEXT = new StringToATextLegacyParser(); StringToComponentGsonParser STRING_TO_COMPONENT = new StringToComponentGsonParser(); StringToTimeParser STRING_TO_TIME = new StringToTimeParser(); diff --git a/src/main/java/org/core/config/parser/parsers/StringToATextLegacyParser.java b/src/main/java/org/core/config/parser/parsers/StringToATextLegacyParser.java deleted file mode 100644 index 9ec94973..00000000 --- a/src/main/java/org/core/config/parser/parsers/StringToATextLegacyParser.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.core.config.parser.parsers; - -import org.core.adventureText.AText; -import org.core.adventureText.format.TextColour; -import org.core.config.parser.StringParser; - -import java.util.Optional; - -@Deprecated(forRemoval = true) -public class StringToATextLegacyParser implements StringParser { - @Override - public Optional parse(String original) { - return Optional.of(AText.ofLegacy(original.replaceAll("&", TextColour.SYMBOL + ""))); - } - - @Override - public String unparse(AText value) { - return value.toLegacy().replaceAll(TextColour.SYMBOL + "", "&"); - } -} diff --git a/src/main/java/org/core/entity/Entity.java b/src/main/java/org/core/entity/Entity.java index ce5887eb..be969b52 100644 --- a/src/main/java/org/core/entity/Entity.java +++ b/src/main/java/org/core/entity/Entity.java @@ -2,8 +2,6 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.ComponentLike; -import org.core.adventureText.AText; -import org.core.adventureText.adventure.AdventureText; import org.core.vector.type.Vector3; import org.core.world.direction.Direction; import org.core.world.direction.EightFacingDirection; @@ -83,29 +81,6 @@ default Optional getAttachedTo() { return Optional.of(block); } - /** - * Gets the custom name of the entity, even - * if the custom name is not visible - * - * @return Optional of the custom name, if the custom name has not been set it will return a Optional.empty - */ - @Deprecated(forRemoval = true) - default Optional getCustomName() { - return this.getCustomNameComponent().map(AdventureText::new); - } - - /** - * Sets the custom name of the entity. - * For players this is the display name. - * - * @param text the name to be - * @return itself for chaining - */ - @Deprecated(forRemoval = true) - default Entity setCustomName(@Nullable AText text) { - return setCustomName((ComponentLike) text); - } - Entity setCustomName(@Nullable Component component); default Entity setCustomName(@Nullable ComponentLike like) { diff --git a/src/main/java/org/core/entity/living/human/player/LivePlayer.java b/src/main/java/org/core/entity/living/human/player/LivePlayer.java index 7eed631d..972f6b38 100644 --- a/src/main/java/org/core/entity/living/human/player/LivePlayer.java +++ b/src/main/java/org/core/entity/living/human/player/LivePlayer.java @@ -6,7 +6,7 @@ import org.core.entity.EntityType; import org.core.entity.LiveEntity; import org.core.permission.Permission; -import org.core.source.viewer.CommandViewer; +import org.core.source.command.CommandSource; import org.core.world.position.impl.BlockPosition; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.UnmodifiableView; @@ -15,7 +15,7 @@ import java.util.stream.Stream; import java.util.stream.StreamSupport; -public interface LivePlayer extends Player, LiveEntity, Audience, CommandViewer { +public interface LivePlayer extends Player, LiveEntity, Audience, CommandSource { Optional getBlockLookingAt(int scanLength); diff --git a/src/main/java/org/core/event/events/connection/ClientConnectionEvent.java b/src/main/java/org/core/event/events/connection/ClientConnectionEvent.java index 9757b364..e6a4fab8 100644 --- a/src/main/java/org/core/event/events/connection/ClientConnectionEvent.java +++ b/src/main/java/org/core/event/events/connection/ClientConnectionEvent.java @@ -1,8 +1,6 @@ package org.core.event.events.connection; import net.kyori.adventure.text.Component; -import org.core.adventureText.AText; -import org.core.adventureText.adventure.AdventureText; import org.core.entity.living.human.player.LivePlayer; import org.core.event.events.entity.EntityEvent; import org.core.utils.ComponentUtils; @@ -28,19 +26,6 @@ interface Kick extends Leave { } - @Deprecated(forRemoval = true) - default AText getLeavingMessage() { - return new AdventureText(getLeaveMessage()); - } - - @Deprecated(forRemoval = true) - default Leave setLeavingMessage(AText message) { - if (message instanceof AdventureText) { - return this.setLeaveMessage(((AdventureText) message).getComponent()); - } - return this.setLeaveMessage(ComponentUtils.fromLegacy(message.toLegacy())); - } - @NotNull Component getLeaveMessage(); Leave setLeaveMessage(@NotNull Component message); diff --git a/src/main/java/org/core/inventory/Inventory.java b/src/main/java/org/core/inventory/Inventory.java index 59136413..54e39012 100644 --- a/src/main/java/org/core/inventory/Inventory.java +++ b/src/main/java/org/core/inventory/Inventory.java @@ -5,20 +5,23 @@ import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; public interface Inventory { interface Parent extends Inventory { - Set getFirstChildren(); + @Deprecated(forRemoval = true) + default Set getFirstChildren() { + return getParts().collect(Collectors.toSet()); + } + + Stream getParts(); @Override default Optional getSlot(int slotPos) { - Optional opPart = this - .getFirstChildren() - .stream() - .filter(c -> c.getSlot(slotPos).isPresent()) - .findFirst(); + Optional opPart = this.getParts().filter(c -> c.getSlot(slotPos).isPresent()).findFirst(); if (opPart.isEmpty()) { return Optional.empty(); } @@ -27,13 +30,18 @@ default Optional getSlot(int slotPos) { } - Set getSlots(); + @Deprecated(forRemoval = true) + default Set getSlots() { + return getItemSlots().collect(Collectors.toSet()); + } + + Stream getItemSlots(); Optional getSlot(int slotPos); Inventory createSnapshot(); default int getSlotCount() { - return this.getSlots().size(); + return (int) getItemSlots().count(); } } diff --git a/src/main/java/org/core/inventory/inventories/BasicEntityInventory.java b/src/main/java/org/core/inventory/inventories/BasicEntityInventory.java index 6e4e8596..84cb96da 100644 --- a/src/main/java/org/core/inventory/inventories/BasicEntityInventory.java +++ b/src/main/java/org/core/inventory/inventories/BasicEntityInventory.java @@ -11,6 +11,7 @@ import java.util.HashSet; import java.util.Optional; import java.util.Set; +import java.util.stream.Stream; public interface BasicEntityInventory extends Inventory.Parent { @@ -25,7 +26,7 @@ public interface BasicEntityInventory extends Inventory.Pa Optional getAttachedEntity(); @Override - default Set getFirstChildren() { - return new HashSet<>(Arrays.asList(this.getArmor(), this.getMainHoldingItem(), this.getOffHoldingItem())); + default Stream getParts() { + return Stream.of(this.getArmor(), this.getMainHoldingItem(), this.getOffHoldingItem()); } } diff --git a/src/main/java/org/core/inventory/inventories/general/block/FurnaceInventory.java b/src/main/java/org/core/inventory/inventories/general/block/FurnaceInventory.java index 86f98347..532d3462 100644 --- a/src/main/java/org/core/inventory/inventories/general/block/FurnaceInventory.java +++ b/src/main/java/org/core/inventory/inventories/general/block/FurnaceInventory.java @@ -10,6 +10,8 @@ import java.util.HashSet; import java.util.Set; +import java.util.function.Supplier; +import java.util.stream.Stream; public interface FurnaceInventory extends BlockAttachedInventory, Inventory.Parent { @@ -25,20 +27,15 @@ default BlockType[] getAllowedBlockType() { } @Override - default Set getFirstChildren() { - Set set = new HashSet<>(); - set.add(this.getFuelSlot()); - set.add(this.getResultsSlot()); - return set; + default Stream getParts() { + return this.getItemSlots().map(slot -> slot); } @Override - default Set getSlots() { - Set slots = new HashSet<>(); - slots.add(this.getFuelSlot()); - slots.add(this.getResultsSlot()); - slots.add(this.getSmeltingSlot()); - return slots; + default Stream getItemSlots() { + return Stream + .>of(this::getFuelSlot, this::getResultsSlot, this::getSmeltingSlot) + .map(Supplier::get); } @Override diff --git a/src/main/java/org/core/inventory/inventories/general/entity/PlayerInventory.java b/src/main/java/org/core/inventory/inventories/general/entity/PlayerInventory.java index 9dd77ade..c3ca0be8 100644 --- a/src/main/java/org/core/inventory/inventories/general/entity/PlayerInventory.java +++ b/src/main/java/org/core/inventory/inventories/general/entity/PlayerInventory.java @@ -8,6 +8,7 @@ import java.util.Arrays; import java.util.HashSet; import java.util.Set; +import java.util.stream.Stream; public interface PlayerInventory extends BasicEntityInventory { @@ -18,14 +19,13 @@ public interface PlayerInventory extends BasicEntityInventory { MainPlayerInventory getMainInventory(); @Override - default Set getSlots() { - Set slots = new HashSet<>(); - slots.addAll(this.getHotbar().getSlots()); - slots.addAll(this.getMainInventory().getSlots()); - slots.addAll(this.getArmor().getSlots()); - slots.add(this.getOffHoldingItem()); - slots.addAll(this.getCraftingGrid().getSlots()); - return slots; + default Stream getItemSlots() { + Stream stream = this.getHotbar().getItemSlots(); + stream = Stream.concat(stream, this.getMainInventory().getItemSlots()); + stream = Stream.concat(stream, this.getArmor().getItemSlots()); + stream = Stream.concat(stream, Stream.of(this.getOffHoldingItem())); + stream = Stream.concat(stream, this.getCraftingGrid().getItemSlots()); + return stream; } @Override @@ -37,12 +37,8 @@ default Slot getMainHoldingItem() { } @Override - default Set getFirstChildren() { - return new HashSet<>(Arrays.asList( - this.getArmor(), - this.getOffHoldingItem(), - this.getCraftingGrid(), - this.getMainInventory(), - this.getHotbar())); + default Stream getParts() { + return Stream.of(this.getArmor(), this.getOffHoldingItem(), this.getCraftingGrid(), + this.getMainInventory(), this.getHotbar()); } } diff --git a/src/main/java/org/core/inventory/inventories/general/entity/ZombieInventory.java b/src/main/java/org/core/inventory/inventories/general/entity/ZombieInventory.java index 0a5b7b24..bedd0501 100644 --- a/src/main/java/org/core/inventory/inventories/general/entity/ZombieInventory.java +++ b/src/main/java/org/core/inventory/inventories/general/entity/ZombieInventory.java @@ -8,6 +8,7 @@ import java.util.HashSet; import java.util.Set; +import java.util.stream.Stream; public interface ZombieInventory & LiveEntity> extends BasicEntityInventory { @@ -15,10 +16,8 @@ public interface ZombieInventory & LiveEntity> exte ZombieInventorySnapshot createSnapshot(); @Override - default Set getSlots() { - Set slots = new HashSet<>(this.getArmor().getSlots()); - slots.add(this.getMainHoldingItem()); - slots.add(this.getOffHoldingItem()); - return slots; + default Stream getItemSlots() { + Stream stream = this.getArmor().getItemSlots(); + return Stream.concat(stream, Stream.of(this.getMainHoldingItem(), this.getOffHoldingItem())); } } diff --git a/src/main/java/org/core/inventory/inventories/snapshots/UnknownInventorySnapshot.java b/src/main/java/org/core/inventory/inventories/snapshots/UnknownInventorySnapshot.java index 1e15b90f..6d2ac24d 100644 --- a/src/main/java/org/core/inventory/inventories/snapshots/UnknownInventorySnapshot.java +++ b/src/main/java/org/core/inventory/inventories/snapshots/UnknownInventorySnapshot.java @@ -9,17 +9,19 @@ import java.util.HashSet; import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; public class UnknownInventorySnapshot implements InventorySnapshot { - private final Set slots = new HashSet<>(); + private final Collection slots = new HashSet<>(); public UnknownInventorySnapshot() { } public UnknownInventorySnapshot(Inventory inventory) { - this.slots.addAll(inventory.getSlots()); + this.slots.addAll(inventory.getItemSlots().collect(Collectors.toList())); } public UnknownInventorySnapshot(Collection collection) { @@ -32,8 +34,13 @@ public void apply() { } @Override - public Set getSlots() { - return this.slots; + public Stream getItemSlots() { + return this.slots.stream(); + } + + @Override + public int getSlotCount() { + return this.slots.size(); } @Override diff --git a/src/main/java/org/core/inventory/inventories/snapshots/block/dispenser/DispenserBasedInventorySnapshot.java b/src/main/java/org/core/inventory/inventories/snapshots/block/dispenser/DispenserBasedInventorySnapshot.java index ad4cc9b0..0c5a1b7d 100644 --- a/src/main/java/org/core/inventory/inventories/snapshots/block/dispenser/DispenserBasedInventorySnapshot.java +++ b/src/main/java/org/core/inventory/inventories/snapshots/block/dispenser/DispenserBasedInventorySnapshot.java @@ -3,6 +3,7 @@ import org.core.inventory.Inventory; import org.core.inventory.InventorySnapshot; import org.core.inventory.inventories.general.block.dispenser.DispenserBasedInventory; +import org.core.inventory.item.stack.ItemStack; import org.core.inventory.parts.Grid3x3; import org.core.inventory.parts.InventoryPart; import org.core.inventory.parts.Slot; @@ -10,7 +11,9 @@ import java.util.Collections; import java.util.HashSet; +import java.util.Objects; import java.util.Set; +import java.util.stream.Stream; public abstract class DispenserBasedInventorySnapshot implements DispenserBasedInventory, InventorySnapshot, Inventory.Parent { @@ -29,26 +32,23 @@ public Grid3x3 getItems() { } @Override - public Set getFirstChildren() { - return new HashSet<>(Collections.singletonList(this.grid)); + public Stream getParts() { + return Stream.of(this.grid); } @Override - public Set getSlots() { - return this.grid.getSlots(); + public Stream getItemSlots() { + return this.grid.getItemSlots(); } public void apply(Inventory inv) { - for (Slot slot : this.getSlots()) { - slot - .getItem() - .ifPresent(f -> - inv - .getSlot(slot.getPosition().orElseThrow(() -> new IllegalStateException( - "Unknown slot position"))) - .orElseThrow(() -> new IllegalStateException("Unknown slot position")) - .setItem(f)); - } + this.getItemSlots().filter(slot -> slot.getItem().isPresent()).forEach(slot -> { + ItemStack item = slot.getItem().orElseThrow(); + Slot inventorySlot = inv + .getSlot(slot.getPosition().orElseThrow(() -> new IllegalStateException("Unknown slot position"))) + .orElseThrow(() -> new IllegalStateException("Unknown slot position")); + inventorySlot.setItem(item); + }); } } diff --git a/src/main/java/org/core/inventory/item/stack/ItemStack.java b/src/main/java/org/core/inventory/item/stack/ItemStack.java index 61fbfce2..8ef67c63 100644 --- a/src/main/java/org/core/inventory/item/stack/ItemStack.java +++ b/src/main/java/org/core/inventory/item/stack/ItemStack.java @@ -2,8 +2,6 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.ComponentLike; -import org.core.adventureText.AText; -import org.core.adventureText.adventure.AdventureText; import org.core.inventory.item.ItemType; import org.core.inventory.item.stack.data.ItemStackData; import org.jetbrains.annotations.NotNull; @@ -30,40 +28,6 @@ public interface ItemStack { */ int getQuantity(); - /** - * Gets the lore of the item - * - * @return The lore of the item - * @deprecated use {@link ItemStack#getLore} instead - */ - @Deprecated(forRemoval = true) - default List getLoreText() { - return this.getLore().stream().map(AdventureText::new).collect(Collectors.toList()); - } - - /** - * Sets the lore of the item - * - * @param lore The new lore to be - * @return itself for chaining - * @deprecated use {@link ItemStack#setLore} instead - */ - @Deprecated(forRemoval = true) - default ItemStack setLoreText(Collection lore) { - return setLore(lore.stream().map(AText::asComponent).collect(Collectors.toList())); - } - - /** - * Sets the lore of the item via varargs - * - * @param text The text to set - * @return itself for chaining - * @deprecated use {@link ItemStack#setLore} instead - */ - default ItemStack setLoreText(AText... text) { - return this.setLoreText(Arrays.asList(text)); - } - /** * Gets the lore of the item * diff --git a/src/main/java/org/core/inventory/item/stack/LiveItemStack.java b/src/main/java/org/core/inventory/item/stack/LiveItemStack.java index 325429b8..89604b8d 100644 --- a/src/main/java/org/core/inventory/item/stack/LiveItemStack.java +++ b/src/main/java/org/core/inventory/item/stack/LiveItemStack.java @@ -1,12 +1,15 @@ package org.core.inventory.item.stack; import org.core.TranslateCore; +import org.core.entity.Entity; import org.core.entity.InventoryHoldingEntity; import org.core.entity.ItemHoldingEntity; import org.core.entity.LiveEntity; +import org.core.world.Extent; import org.core.world.WorldExtent; import org.core.world.position.block.entity.LiveTileEntity; import org.core.world.position.block.entity.container.ContainerTileEntity; +import org.core.world.position.impl.sync.SyncBlockPosition; import org.core.world.position.impl.sync.SyncExactPosition; import java.util.Optional; @@ -14,45 +17,38 @@ public interface LiveItemStack extends ItemStack { default Optional getPosition() { - for (WorldExtent extent : TranslateCore.getServer().getWorlds()) { - for (LiveTileEntity tile : extent.getTileEntities()) { - if (!(tile instanceof ContainerTileEntity)) { - continue; - } - ContainerTileEntity cTile = (ContainerTileEntity) tile; - if (cTile + Optional opPositionFromTile = TranslateCore + .getServer() + .getWorldExtent() + .flatMap(Extent::getLiveTileEntities) + .filter(entity -> entity instanceof ContainerTileEntity) + .map(entity -> (ContainerTileEntity) entity) + .filter(entity -> entity .getInventory() - .getSlots() - .stream() - .filter(i -> i.getItem().isPresent()) - .anyMatch(i -> i.getItem().get().equals(this))) { - return Optional.of(tile.getPosition().toExactPosition()); + .getItemSlots() + .anyMatch(slot -> slot.getItem().map(item -> item.equals(this)).orElse(false))) + .map(entity -> ((LiveTileEntity) entity).getPosition()) + .map(SyncBlockPosition::toExactPosition) + .findFirst(); + if (opPositionFromTile.isPresent()) { + return opPositionFromTile; + } + return TranslateCore.getServer().getWorldExtent().flatMap(Extent::getLiveEntities).filter(entity -> { + if (entity instanceof ItemHoldingEntity) { + ItemHoldingEntity ihEntity = (ItemHoldingEntity) entity; + if (ihEntity.getHoldingItem().getItem().map(item -> item.equals(this)).orElse(false)) { + return true; } } - for (LiveEntity entity : extent.getEntities()) { - if (entity instanceof ItemHoldingEntity) { - ItemHoldingEntity ihEntity = (ItemHoldingEntity) entity; - Optional opItem = ihEntity.getHoldingItem().getItem(); - if (opItem.isEmpty()) { - continue; - } - if (opItem.get().equals(this)) { - return Optional.of(entity.getPosition()); - } - } - if (entity instanceof InventoryHoldingEntity) { - InventoryHoldingEntity ihEntity = (InventoryHoldingEntity) entity; - if (ihEntity - .getInventory() - .getSlots() - .stream() - .filter(slot -> slot.getItem().isPresent()) - .anyMatch(slot -> slot.getItem().get().equals(this))) { - return Optional.of(entity.getPosition()); - } - } + if (entity instanceof InventoryHoldingEntity) { + InventoryHoldingEntity ihEntity = (InventoryHoldingEntity) entity; + return ihEntity + .getInventory() + .getItemSlots() + .filter(slot -> slot.getItem().isPresent()) + .anyMatch(slot -> slot.getItem().get().equals(this)); } - } - return Optional.empty(); + return false; + }).findFirst().map(Entity::getPosition); } } diff --git a/src/main/java/org/core/inventory/parts/ArmorPart.java b/src/main/java/org/core/inventory/parts/ArmorPart.java index b49f7c7d..9fec69d4 100644 --- a/src/main/java/org/core/inventory/parts/ArmorPart.java +++ b/src/main/java/org/core/inventory/parts/ArmorPart.java @@ -2,9 +2,7 @@ import org.core.inventory.parts.snapshot.ArmorPartSnapshot; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; +import java.util.stream.Stream; public interface ArmorPart extends InventoryPart { @@ -22,11 +20,12 @@ default ArmorPartSnapshot createSnapshot() { } @Override - default Set getSlots() { - return new HashSet<>(Arrays.asList( - this.getHelmetSlot(), - this.getArmorSlot(), - this.getLeggingsSlot(), - this.getShoesSlot())); + default Stream getItemSlots() { + return Stream.of(this.getHelmetSlot(), this.getArmorSlot(), this.getLeggingsSlot(), this.getShoesSlot()); + } + + @Override + default int getSlotCount() { + return 4; } } diff --git a/src/main/java/org/core/inventory/parts/InventoryPart.java b/src/main/java/org/core/inventory/parts/InventoryPart.java index 28a271af..e9298920 100644 --- a/src/main/java/org/core/inventory/parts/InventoryPart.java +++ b/src/main/java/org/core/inventory/parts/InventoryPart.java @@ -9,8 +9,7 @@ public interface InventoryPart extends Inventory { @Override default Optional getSlot(int slotPos) { return this - .getSlots() - .stream() + .getItemSlots() .filter(s -> s.getPosition().isPresent()) .filter(s -> s.getPosition().get() == slotPos) .findFirst(); diff --git a/src/main/java/org/core/inventory/parts/Slot.java b/src/main/java/org/core/inventory/parts/Slot.java index 7886ac92..9515593a 100644 --- a/src/main/java/org/core/inventory/parts/Slot.java +++ b/src/main/java/org/core/inventory/parts/Slot.java @@ -8,6 +8,7 @@ import java.util.HashSet; import java.util.Optional; import java.util.Set; +import java.util.stream.Stream; public interface Slot extends InventoryPart { @@ -27,7 +28,7 @@ default SlotSnapshot createSnapshot() { } @Override - default Set getSlots() { - return new HashSet<>(Collections.singletonList(this)); + default Stream getItemSlots() { + return Stream.of(this); } } diff --git a/src/main/java/org/core/inventory/parts/snapshot/Grid2x2Snapshot.java b/src/main/java/org/core/inventory/parts/snapshot/Grid2x2Snapshot.java index 637ef8ff..efd51232 100644 --- a/src/main/java/org/core/inventory/parts/snapshot/Grid2x2Snapshot.java +++ b/src/main/java/org/core/inventory/parts/snapshot/Grid2x2Snapshot.java @@ -9,13 +9,14 @@ import java.util.HashSet; import java.util.Set; import java.util.stream.Collectors; +import java.util.stream.Stream; public class Grid2x2Snapshot implements InventoryPartSnapshot, Grid2x2 { protected final Set slots = new HashSet<>(); public Grid2x2Snapshot(Inventory part) { - this(part.getSlots()); + this(part.getItemSlots().collect(Collectors.toSet())); } public Grid2x2Snapshot(Slot... slots) { @@ -30,12 +31,17 @@ public Grid2x2Snapshot(Collection slots) { } @Override - public Set getSlots() { - return this.slots; + public Stream getItemSlots() { + return this.slots.stream(); } @Override public Grid2x2Snapshot createSnapshot() { return new Grid2x2Snapshot(this); } + + @Override + public int getSlotCount() { + return this.slots.size(); + } } diff --git a/src/main/java/org/core/inventory/parts/snapshot/Grid3x3Snapshot.java b/src/main/java/org/core/inventory/parts/snapshot/Grid3x3Snapshot.java index 0f836a00..48918ccc 100644 --- a/src/main/java/org/core/inventory/parts/snapshot/Grid3x3Snapshot.java +++ b/src/main/java/org/core/inventory/parts/snapshot/Grid3x3Snapshot.java @@ -9,13 +9,14 @@ import java.util.HashSet; import java.util.Set; import java.util.stream.Collectors; +import java.util.stream.Stream; public class Grid3x3Snapshot implements Grid3x3, InventoryPartSnapshot { protected final Set slots = new HashSet<>(); public Grid3x3Snapshot(Inventory grid) { - this(grid.getSlots()); + this(grid.getItemSlots().collect(Collectors.toList())); } public Grid3x3Snapshot(Slot... slots) { @@ -30,12 +31,17 @@ public Grid3x3Snapshot(Collection slots) { } @Override - public Set getSlots() { - return this.slots; + public Stream getItemSlots() { + return this.slots.stream(); } @Override public Grid3x3Snapshot createSnapshot() { return new Grid3x3Snapshot(this); } + + @Override + public int getSlotCount() { + return this.slots.size(); + } } diff --git a/src/main/java/org/core/inventory/parts/snapshot/HotbarSnapshot.java b/src/main/java/org/core/inventory/parts/snapshot/HotbarSnapshot.java index a5307ee3..88e86c49 100644 --- a/src/main/java/org/core/inventory/parts/snapshot/HotbarSnapshot.java +++ b/src/main/java/org/core/inventory/parts/snapshot/HotbarSnapshot.java @@ -8,6 +8,7 @@ import java.util.HashSet; import java.util.Set; import java.util.stream.Collectors; +import java.util.stream.Stream; public class HotbarSnapshot implements Hotbar, InventoryPartSnapshot { @@ -15,7 +16,7 @@ public class HotbarSnapshot implements Hotbar, InventoryPartSnapshot { protected final Set slots = new HashSet<>(); public HotbarSnapshot(Hotbar bar) { - this(bar.getSelectedSlotPos(), bar.getSlots()); + this(bar.getSelectedSlotPos(), bar.getItemSlots().collect(Collectors.toList())); } public HotbarSnapshot(int selected, Slot... slots) { @@ -33,12 +34,17 @@ public int getSelectedSlotPos() { } @Override - public Set getSlots() { - return this.slots; + public Stream getItemSlots() { + return this.slots.stream(); } @Override public HotbarSnapshot createSnapshot() { return new HotbarSnapshot(this); } + + @Override + public int getSlotCount() { + return this.slots.size(); + } } diff --git a/src/main/java/org/core/inventory/parts/snapshot/MainPlayerInventorySnapshot.java b/src/main/java/org/core/inventory/parts/snapshot/MainPlayerInventorySnapshot.java index 69f1e67a..02eb4c0f 100644 --- a/src/main/java/org/core/inventory/parts/snapshot/MainPlayerInventorySnapshot.java +++ b/src/main/java/org/core/inventory/parts/snapshot/MainPlayerInventorySnapshot.java @@ -8,13 +8,14 @@ import java.util.HashSet; import java.util.Set; import java.util.stream.Collectors; +import java.util.stream.Stream; public class MainPlayerInventorySnapshot implements MainPlayerInventory, InventoryPartSnapshot { protected final Set slots = new HashSet<>(); public MainPlayerInventorySnapshot(Inventory snapshot) { - this(snapshot.getSlots()); + this(snapshot.getItemSlots().collect(Collectors.toList())); } public MainPlayerInventorySnapshot(Collection slots) { @@ -22,12 +23,17 @@ public MainPlayerInventorySnapshot(Collection slots) { } @Override - public Set getSlots() { - return this.slots; + public Stream getItemSlots() { + return this.slots.stream(); } @Override public MainPlayerInventorySnapshot createSnapshot() { return new MainPlayerInventorySnapshot(this); } + + @Override + public int getSlotCount() { + return this.slots.size(); + } } diff --git a/src/main/java/org/core/inventory/parts/snapshot/SlotSnapshot.java b/src/main/java/org/core/inventory/parts/snapshot/SlotSnapshot.java index afefad67..5edde63c 100644 --- a/src/main/java/org/core/inventory/parts/snapshot/SlotSnapshot.java +++ b/src/main/java/org/core/inventory/parts/snapshot/SlotSnapshot.java @@ -46,4 +46,9 @@ public SlotSnapshot setItem(ItemStack stack) { public SlotSnapshot createSnapshot() { return new SlotSnapshot(this); } + + @Override + public int getSlotCount() { + return 1; + } } diff --git a/src/main/java/org/core/logger/Logger.java b/src/main/java/org/core/logger/Logger.java index bc3b9229..bae98e4d 100644 --- a/src/main/java/org/core/logger/Logger.java +++ b/src/main/java/org/core/logger/Logger.java @@ -1,17 +1,11 @@ package org.core.logger; -import org.core.adventureText.AText; import org.jetbrains.annotations.NotNull; public interface Logger { void log(@NotNull String log); - @Deprecated(forRemoval = true) - default void log(@NotNull AText log) { - log(log.toLegacy()); - } - void warning(@NotNull String log); void error(@NotNull String log); diff --git a/src/main/java/org/core/platform/Platform.java b/src/main/java/org/core/platform/Platform.java index 48df4175..d2282457 100644 --- a/src/main/java/org/core/platform/Platform.java +++ b/src/main/java/org/core/platform/Platform.java @@ -22,8 +22,6 @@ import org.core.platform.update.PlatformUpdate; import org.core.platform.update.UpdateOption; import org.core.utils.Singleton; -import org.core.world.boss.colour.BossColour; -import org.core.world.boss.colour.BossColours; import org.core.world.position.block.BlockType; import org.core.world.position.block.entity.TileEntity; import org.core.world.position.block.entity.TileEntitySnapshot; @@ -42,6 +40,8 @@ import java.util.Collection; import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; /** * Info about the platform TranslateCore is running on @@ -56,8 +56,6 @@ public interface Platform { @NotNull Collection> getUpdateCheckers(); - @NotNull Singleton get(BossColours colours); - @NotNull Singleton get(ApplyPhysicsFlags flags); @NotNull Singleton get(ItemTypeCommon itemId); @@ -83,8 +81,6 @@ public interface Platform { @NotNull Optional getPatternLayerType(String id); - @NotNull Optional getBossColour(String id); - @NotNull Optional getParrotType(String id); @NotNull Optional getApplyPhysics(String id); @@ -92,26 +88,48 @@ public interface Platform { @Deprecated @NotNull Optional> getUnspecifiedParser(String id); - @NotNull Collection>> getEntityTypes(); + @Deprecated(forRemoval = true) + default @NotNull Collection>> getEntityTypes() { + return getAllEntityTypes().collect(Collectors.toSet()); + } + + Stream>> getAllEntityTypes(); - @NotNull Collection getBlockTypes(); + @Deprecated(forRemoval = true) + default @NotNull Collection getBlockTypes() { + return getAllBlockTypes().collect(Collectors.toSet()); + } + + Stream getAllBlockTypes(); + + @Deprecated(forRemoval = true) + default @NotNull Collection getItemTypes() { + return getAllItemTypes().collect(Collectors.toSet()); + } - @NotNull Collection getItemTypes(); + Stream getAllItemTypes(); @NotNull Collection getDyeTypes(); @NotNull Collection getPatternLayerTypes(); - @NotNull Collection getBlockGroups(); - @Deprecated(forRemoval = true) - @NotNull Collection getBossColours(); + default @NotNull Collection getBlockGroups() { + return getAllBlockGroups().collect(Collectors.toSet()); + } + + Stream getAllBlockGroups(); @NotNull Collection getParrotType(); @NotNull Collection getApplyPhysics(); - @NotNull Collection getPermissions(); + @Deprecated(forRemoval = true) + default @NotNull Collection getPermissions() { + return getAllPermissions().collect(Collectors.toSet()); + } + + Stream getAllPermissions(); @NotNull Collection getStructures(); @@ -135,7 +153,12 @@ public interface Platform { @NotNull ConfigurationFormat getConfigFormat(); - @NotNull Set getPlugins(); + @Deprecated(forRemoval = true) + default @NotNull Set getPlugins() { + return getAllPlugins().collect(Collectors.toSet()); + } + + Stream getAllPlugins(); @NotNull File getPlatformPluginsFolder(); @@ -158,11 +181,11 @@ public interface Platform { @NotNull E callEvent(E event); default @NotNull Optional getBlockGroup(@NotNull String id) { - return this.getBlockGroups().stream().filter(g -> g.getId().equals(id)).findFirst(); + return this.getAllBlockGroups().filter(g -> g.getId().equals(id)).findFirst(); } default @NotNull Optional getPlugin(@NotNull String name) { - return this.getPlugins().stream().filter(p -> p.getPluginName().equals(name)).findAny(); + return this.getAllPlugins().filter(p -> p.getPluginName().equals(name)).findAny(); } default @NotNull Optional> getDefaultTileEntity(@NotNull BlockType type) { diff --git a/src/main/java/org/core/platform/PlatformServer.java b/src/main/java/org/core/platform/PlatformServer.java index 69e45d22..7b9f6b8f 100644 --- a/src/main/java/org/core/platform/PlatformServer.java +++ b/src/main/java/org/core/platform/PlatformServer.java @@ -12,14 +12,26 @@ import java.util.Set; import java.util.UUID; import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; +import java.util.stream.Stream; public interface PlatformServer { - @NotNull Set getWorlds(); + @Deprecated(forRemoval = true) + default @NotNull Set getWorlds() { + return getWorldExtent().collect(Collectors.toSet()); + } + + Stream getWorldExtent(); @NotNull Optional getWorldByPlatformSpecific(String name); - @NotNull Collection getOnlinePlayers(); + @Deprecated(forRemoval = true) + default @NotNull Collection getOnlinePlayers() { + return getLivePlayers().collect(Collectors.toSet()); + } + + Stream getLivePlayers(); void applyBlockSnapshots(@NotNull Collection collection, @NotNull Plugin plugin, diff --git a/src/main/java/org/core/source/Messageable.java b/src/main/java/org/core/source/Messageable.java index f1a76741..0a7f9df1 100644 --- a/src/main/java/org/core/source/Messageable.java +++ b/src/main/java/org/core/source/Messageable.java @@ -2,7 +2,6 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.JoinConfiguration; -import org.core.adventureText.AText; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -10,12 +9,6 @@ public interface Messageable { - @Deprecated(forRemoval = true) - Messageable sendMessage(AText message, UUID uuid); - - @Deprecated(forRemoval = true) - Messageable sendMessage(AText message); - void sendMessage(@NotNull Component message, @Nullable UUID uuid); void sendMessage(@NotNull Component message); diff --git a/src/main/java/org/core/source/command/ConsoleSource.java b/src/main/java/org/core/source/command/ConsoleSource.java index d1bd1d75..d6dc31b5 100644 --- a/src/main/java/org/core/source/command/ConsoleSource.java +++ b/src/main/java/org/core/source/command/ConsoleSource.java @@ -1,6 +1,4 @@ package org.core.source.command; -import org.core.source.viewer.CommandViewer; - -public interface ConsoleSource extends CommandViewer { +public interface ConsoleSource extends CommandSource { } diff --git a/src/main/java/org/core/source/viewer/CommandViewer.java b/src/main/java/org/core/source/viewer/CommandViewer.java deleted file mode 100644 index 94cd26be..00000000 --- a/src/main/java/org/core/source/viewer/CommandViewer.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.core.source.viewer; - -import org.core.adventureText.AText; -import org.core.source.command.CommandSource; - -import java.util.UUID; - -/** - * @deprecated Removing due to all command sources now allowing text to be displayed - */ -@Deprecated(forRemoval = true) -public interface CommandViewer extends CommandSource { - - @Override - CommandViewer sendMessage(AText message, UUID uuid); - - @Override - CommandViewer sendMessage(AText message); - -} diff --git a/src/main/java/org/core/utils/BarUtils.java b/src/main/java/org/core/utils/BarUtils.java index 960a7b4d..6e85c469 100644 --- a/src/main/java/org/core/utils/BarUtils.java +++ b/src/main/java/org/core/utils/BarUtils.java @@ -16,8 +16,7 @@ public BarUtils() { public static Stream getPlayers(@NotNull BossBar bar) { return TranslateCore .getServer() - .getOnlinePlayers() - .stream() + .getLivePlayers() .filter(player -> player.bossBarsStream().anyMatch(boss -> boss.equals(bar))); } diff --git a/src/main/java/org/core/world/Extent.java b/src/main/java/org/core/world/Extent.java index ec180836..83ad8773 100644 --- a/src/main/java/org/core/world/Extent.java +++ b/src/main/java/org/core/world/Extent.java @@ -14,8 +14,11 @@ import org.core.world.position.impl.sync.SyncBlockPosition; import org.core.world.position.impl.sync.SyncExactPosition; import org.core.world.position.impl.sync.SyncPosition; +import org.jetbrains.annotations.NotNull; import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; public interface Extent { @@ -31,11 +34,22 @@ public interface Extent { boolean isLoaded(); - Set getEntities(); + @Deprecated(forRemoval = true) + default Set getEntities() { + return getLiveEntities().collect(Collectors.toSet()); + } + + Stream getLiveEntities(); + + @Deprecated(forRemoval = true) + default Set getTileEntities() { + return getLiveTileEntities().collect(Collectors.toSet()); + } - Set getTileEntities(); + Stream getLiveTileEntities(); - default SyncPosition getPosition(Vector3 vector) { + @NotNull + default SyncPosition getPosition(@NotNull Vector3 vector) { if (vector.getX() instanceof Integer) { return (SyncPosition) this.getPosition(vector.getX().intValue(), vector.getY().intValue(), vector.getZ().intValue()); @@ -54,7 +68,8 @@ default SyncPosition getPosition(Vector3 vector) { vector.getZ().doubleValue()); } - default ASyncPosition getAsyncPosition(Vector3 vector) { + @NotNull + default ASyncPosition getAsyncPosition(@NotNull Vector3 vector) { if (vector.getX() instanceof Integer) { return (ASyncPosition) this.getAsyncPosition(vector.getX().intValue(), vector.getY().intValue(), vector.getZ().intValue()); diff --git a/src/main/java/org/core/world/WorldExtent.java b/src/main/java/org/core/world/WorldExtent.java index d01f8183..266b8412 100644 --- a/src/main/java/org/core/world/WorldExtent.java +++ b/src/main/java/org/core/world/WorldExtent.java @@ -1,11 +1,14 @@ package org.core.world; import org.core.vector.type.Vector3; +import org.jetbrains.annotations.NotNull; import java.util.Optional; import java.util.Set; import java.util.UUID; import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; +import java.util.stream.Stream; public interface WorldExtent extends Extent { @@ -15,21 +18,26 @@ public interface WorldExtent extends Extent { String getPlatformUniqueId(); - Set getChunks(); + @Deprecated(forRemoval = true) + default Set getChunks() { + return getChunkExtents().collect(Collectors.toSet()); + } + + Stream getChunkExtents(); - Optional getChunk(Vector3 vector); + @NotNull Optional getChunk(@NotNull Vector3 vector); - CompletableFuture loadChunkAsynced(Vector3 vector); + @NotNull CompletableFuture loadChunkAsynced(@NotNull Vector3 vector); - ChunkExtent loadChunk(Vector3 vector); + @NotNull ChunkExtent loadChunk(@NotNull Vector3 vector); int getMinimumBlockHeight(); - default CompletableFuture loadChunkAtAsynced(Vector3 position) { + default CompletableFuture loadChunkAtAsynced(@NotNull Vector3 position) { return this.loadChunkAsynced(this.getAsyncPosition(position).getChunkPosition()); } - default ChunkExtent loadChunkAt(Vector3 position) { + default ChunkExtent loadChunkAt(@NotNull Vector3 position) { return this.loadChunk(this.getAsyncPosition(position).getChunkPosition()); } } diff --git a/src/main/java/org/core/world/boss/ServerBossBar.java b/src/main/java/org/core/world/boss/ServerBossBar.java deleted file mode 100644 index 553d1ea7..00000000 --- a/src/main/java/org/core/world/boss/ServerBossBar.java +++ /dev/null @@ -1,100 +0,0 @@ -package org.core.world.boss; - -import net.kyori.adventure.bossbar.BossBar; -import org.core.TranslateCore; -import org.core.adventureText.AText; -import org.core.adventureText.adventure.AdventureText; -import org.core.entity.living.human.player.LivePlayer; -import org.core.world.boss.colour.BossColour; -import org.core.world.boss.colour.BossColours; - -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.StreamSupport; - -@Deprecated(forRemoval = true) -public interface ServerBossBar { - - BossBar bossBar(); - - default AText getTitle() { - return new AdventureText(bossBar().name()); - } - - default ServerBossBar setTitle(AText text) { - bossBar().name(text); - return this; - } - - default BossColour getColour() { - switch (bossBar().color()) { - case PINK: - return BossColours.PINK.get(); - case BLUE: - return BossColours.BLUE.get(); - case RED: - return BossColours.RED.get(); - case GREEN: - return BossColours.GREEN.get(); - case YELLOW: - return BossColours.YELLOW.get(); - case PURPLE: - return BossColours.PURPLE.get(); - case WHITE: - return BossColours.WHITE.get(); - } - throw new RuntimeException("legacy colour not accepted"); - } - - default ServerBossBar setColour(BossColour colour) { - BossBar.Color.valueOf(colour.getName().toUpperCase()); - return this; - } - - default int getValue() { - return (int) (this.bossBar().progress() * 100); - } - - default ServerBossBar setValue(int value) { - this.bossBar().progress((float) (value / 100.0)); - return this; - } - - default Set getPlayers() { - return TranslateCore - .getServer() - .getOnlinePlayers() - .stream() - .filter(player -> StreamSupport - .stream(player.bossBars().spliterator(), true) - .anyMatch(boss -> boss.equals(this.bossBar()))) - .collect(Collectors.toSet()); - } - - default ServerBossBar register(LivePlayer... players) { - for (LivePlayer player : players) { - player.showBossBar(bossBar()); - } - return this; - } - - default ServerBossBar deregister(LivePlayer... players) { - for (LivePlayer player : players) { - player.hideBossBar(bossBar()); - } - return this; - } - - default ServerBossBar setValue(int min, int value, int max) { - return this.setValue(value - min, value - max); - } - - default ServerBossBar setValue(int value, int max) { - int percent = (int) ((value * 100.0f) / max); - return this.setValue(percent); - } - - default ServerBossBar deregisterPlayers() { - return this.deregister(this.getPlayers().toArray(new LivePlayer[0])); - } -} diff --git a/src/main/java/org/core/world/boss/colour/BossColour.java b/src/main/java/org/core/world/boss/colour/BossColour.java deleted file mode 100644 index 7cfa5585..00000000 --- a/src/main/java/org/core/world/boss/colour/BossColour.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.core.world.boss.colour; - -import org.core.utils.Identifiable; - -@Deprecated(forRemoval = true) -public interface BossColour extends Identifiable {} diff --git a/src/main/java/org/core/world/boss/colour/BossColours.java b/src/main/java/org/core/world/boss/colour/BossColours.java deleted file mode 100644 index c2c3c4b8..00000000 --- a/src/main/java/org/core/world/boss/colour/BossColours.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.core.world.boss.colour; - -import org.core.TranslateCore; -import org.core.utils.Guaranteed; -import org.core.utils.Singleton; - -@Deprecated(forRemoval = true) -@SuppressWarnings("unused") -public class BossColours implements Guaranteed { - - public static final Singleton BLUE = TranslateCore.getPlatform().get(new BossColours("Blue")); - public static final Singleton GREEN = TranslateCore.getPlatform().get(new BossColours("Green")); - public static final Singleton PINK = TranslateCore.getPlatform().get(new BossColours("Pink")); - public static final Singleton PURPLE = TranslateCore.getPlatform().get(new BossColours("Purple")); - public static final Singleton RED = TranslateCore.getPlatform().get(new BossColours("Red")); - public static final Singleton WHITE = TranslateCore.getPlatform().get(new BossColours("White")); - public static final Singleton YELLOW = TranslateCore.getPlatform().get(new BossColours("Yellow")); - - - private final String name; - - public BossColours(String name) { - this.name = name; - } - - @Override - public String getId() { - return "minecraft." + this.getName().toLowerCase().replaceAll(" ", "_"); - } - - @Override - public String getName() { - return this.name; - } -} diff --git a/src/main/java/org/core/world/expload/Explosion.java b/src/main/java/org/core/world/expload/Explosion.java index 064c9e45..c05fce9d 100644 --- a/src/main/java/org/core/world/expload/Explosion.java +++ b/src/main/java/org/core/world/expload/Explosion.java @@ -8,6 +8,7 @@ import java.util.Collection; import java.util.stream.Collectors; +import java.util.stream.Stream; public interface Explosion extends Positionable { @@ -27,13 +28,18 @@ interface ExplosionSnapshot extends Explosion { Collection getBlocks(); @Override - default Collection getAffectedPositions() { - return this.getBlocks().parallelStream().map(Positionable::getPosition).collect(Collectors.toSet()); + default Stream getAffectedBlockPositions() { + return this.getBlocks().parallelStream().map(Positionable::getPosition); } } - Collection getAffectedPositions(); + @Deprecated(forRemoval = true) + default Collection getAffectedPositions() { + return getAffectedBlockPositions().collect(Collectors.toSet()); + } + + Stream getAffectedBlockPositions(); Object getSource(); } diff --git a/src/main/java/org/core/world/position/block/BlockType.java b/src/main/java/org/core/world/position/block/BlockType.java index 6723d04c..d4a60ca1 100644 --- a/src/main/java/org/core/world/position/block/BlockType.java +++ b/src/main/java/org/core/world/position/block/BlockType.java @@ -4,11 +4,14 @@ import org.core.utils.Identifiable; import org.core.world.position.block.details.BlockDetails; import org.core.world.position.block.grouptype.BlockGroup; +import org.jetbrains.annotations.NotNull; import java.util.Arrays; import java.util.HashSet; import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; /** *

Very basic info of a block

@@ -22,7 +25,12 @@ public interface BlockType extends Identifiable { */ BlockDetails getDefaultBlockDetails(); - Set getGroups(); + @Deprecated(forRemoval = true) + default Set getGroups() { + return this.getBlockGroups().collect(Collectors.toSet()); + } + + Stream getBlockGroups(); /** *

If the current has an ItemType variant, this will return it

@@ -37,8 +45,8 @@ public interface BlockType extends Identifiable { * @param type a block type to check if it like the current * @return returns true if the type is found in the like list, false if not */ - default boolean isLike(BlockType type) { - return this.getGroups().stream().anyMatch(t -> Arrays.asList(t.getGrouped()).contains(type)); + default boolean isLike(@NotNull BlockType type) { + return this.getAlike().anyMatch(t -> t.equals(type)); } /** @@ -47,6 +55,7 @@ default boolean isLike(BlockType type) { * * @return All blocks types that are like the current block type. */ + @Deprecated(forRemoval = true) default Set getLike() { Set set = new HashSet<>(); this.getGroups().forEach(g -> { @@ -59,4 +68,8 @@ default Set getLike() { return set; } + default Stream getAlike() { + return this.getGroups().stream().flatMap(blockGroup -> Stream.of(blockGroup.getGrouped())).distinct(); + } + } diff --git a/src/main/java/org/core/world/position/block/details/BlockDetails.java b/src/main/java/org/core/world/position/block/details/BlockDetails.java index be2a7578..a423353e 100644 --- a/src/main/java/org/core/world/position/block/details/BlockDetails.java +++ b/src/main/java/org/core/world/position/block/details/BlockDetails.java @@ -5,6 +5,7 @@ import org.core.world.position.block.details.data.keyed.KeyedData; import org.core.world.position.impl.async.ASyncBlockPosition; import org.core.world.position.impl.sync.SyncBlockPosition; +import org.jetbrains.annotations.NotNull; import java.util.Collection; import java.util.Collections; @@ -22,9 +23,9 @@ public interface BlockDetails { */ BlockType getType(); - BlockSnapshot.AsyncBlockSnapshot createSnapshot(ASyncBlockPosition position); + BlockSnapshot.AsyncBlockSnapshot createSnapshot(@NotNull ASyncBlockPosition position); - BlockSnapshot.SyncBlockSnapshot createSnapshot(SyncBlockPosition position); + BlockSnapshot.SyncBlockSnapshot createSnapshot(@NotNull SyncBlockPosition position); Optional getDirectionalData(); @@ -35,15 +36,15 @@ public interface BlockDetails { */ BlockDetails createCopyOf(); - Optional get(Class> data); + Optional get(@NotNull Class> data); default > Collection getAll(Class> data) { return this.get(data).map(t -> (Collection) t).orElseGet(Collections::emptySet); } - BlockDetails set(Class> data, T value); + BlockDetails set(@NotNull Class> data, T value); - default Optional getUnspecified(Class> dataClass) { + default Optional getUnspecified(@NotNull Class> dataClass) { return this.get((Class>) dataClass); } } diff --git a/src/main/java/org/core/world/position/block/entity/TileEntitySnapshot.java b/src/main/java/org/core/world/position/block/entity/TileEntitySnapshot.java index 7ca03d34..1d6cb93d 100644 --- a/src/main/java/org/core/world/position/block/entity/TileEntitySnapshot.java +++ b/src/main/java/org/core/world/position/block/entity/TileEntitySnapshot.java @@ -3,9 +3,13 @@ import org.core.exceptions.BlockNotSupported; import org.core.world.position.block.BlockType; import org.core.world.position.impl.sync.SyncBlockPosition; +import org.jetbrains.annotations.NotNull; import java.util.Collection; import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import java.util.stream.StreamSupport; public interface TileEntitySnapshot extends TileEntity { @@ -13,9 +17,14 @@ public interface TileEntitySnapshot extends TileEntity E apply(E tileEntity); - Collection getSupportedBlocks(); + @Deprecated(forRemoval = true) + default Collection getSupportedBlocks() { + return this.getApplicableBlocks().collect(Collectors.toSet()); + } + + Stream getApplicableBlocks(); - default E apply(SyncBlockPosition position) throws BlockNotSupported { + default E apply(@NotNull SyncBlockPosition position) throws BlockNotSupported { if (this.getSupportedBlocks().stream().noneMatch(b -> position.getBlockType().equals(b))) { throw new BlockNotSupported(position.getBlockType(), this.getClass().getTypeName()); } diff --git a/src/main/java/org/core/world/position/block/entity/sign/SignTileEntity.java b/src/main/java/org/core/world/position/block/entity/sign/SignTileEntity.java index c8b47772..11d40df5 100644 --- a/src/main/java/org/core/world/position/block/entity/sign/SignTileEntity.java +++ b/src/main/java/org/core/world/position/block/entity/sign/SignTileEntity.java @@ -1,6 +1,5 @@ package org.core.world.position.block.entity.sign; -import org.core.adventureText.AText; import org.core.world.position.block.entity.TileEntity; import java.util.*; @@ -25,31 +24,4 @@ default Optional getBack() { return Optional.empty(); } - @Deprecated(forRemoval = true) - List getText(); - - @Deprecated(forRemoval = true) - SignTileEntity setText(Collection text); - - @Deprecated(forRemoval = true) - default SignTileEntity setText(AText... text) { - return this.setText(Arrays.asList(text)); - } - - @Deprecated(forRemoval = true) - default Optional getTextAt(int a) throws IndexOutOfBoundsException { - List lines = this.getText(); - if (a >= lines.size()) { - return Optional.empty(); - } - return Optional.ofNullable(lines.get(a)); - } - - @Deprecated(forRemoval = true) - default SignTileEntity setTextAt(int a, AText text) throws IndexOutOfBoundsException { - List lines = new ArrayList<>(this.getText()); - lines.set(a, text); - return this.setText(lines); - } - } diff --git a/src/main/java/org/core/world/position/block/grouptype/BlockGroup.java b/src/main/java/org/core/world/position/block/grouptype/BlockGroup.java index 92bf0305..8077b706 100644 --- a/src/main/java/org/core/world/position/block/grouptype/BlockGroup.java +++ b/src/main/java/org/core/world/position/block/grouptype/BlockGroup.java @@ -2,21 +2,41 @@ import org.core.utils.Identifiable; import org.core.world.position.block.BlockType; +import org.jetbrains.annotations.UnmodifiableView; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.function.Supplier; +import java.util.stream.Stream; public class BlockGroup implements Identifiable { private final String id; private final String name; - private final BlockType[] grouped; + private final Supplier> grouped; public BlockGroup(String id, String name, BlockType... types) { + this(id, name, () -> Stream.of(types)); + } + + public BlockGroup(String id, String name, Collection types) { + this(id, name, types::stream); + } + + public BlockGroup(String id, String name, Supplier> types) { this.id = id; this.name = name; this.grouped = types; } + @Deprecated(forRemoval = true) public BlockType[] getGrouped() { - return this.grouped; + return this.grouped.get().toArray(BlockType[]::new); + } + + public Stream getBlocks() { + return this.grouped.get(); } @Override diff --git a/src/main/java/org/core/world/position/block/grouptype/BlockGroups.java b/src/main/java/org/core/world/position/block/grouptype/BlockGroups.java index 83b58815..9cc424cc 100644 --- a/src/main/java/org/core/world/position/block/grouptype/BlockGroups.java +++ b/src/main/java/org/core/world/position/block/grouptype/BlockGroups.java @@ -1,61 +1,31 @@ package org.core.world.position.block.grouptype; import org.core.TranslateCore; -import org.core.platform.plugin.details.CorePluginVersion; -import org.core.world.position.block.grouptype.versions.BlockGroups1V13; -import org.core.world.position.block.grouptype.versions.CommonBlockGroups; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.*; +import java.util.function.Supplier; -public class BlockGroups { +public final class BlockGroups { - private static final BlockGroups IMPLEMENTATION; + public static final Supplier CARPET = createGroup("minecraft:carpets"); + public static final Supplier BUTTONS = createGroup("minecraft:buttons"); + public static final Supplier SIGNS = createGroup("minecraft:signs"); + public static final Supplier FENCES = createGroup("minecraft:fences"); + public static final Supplier FENCE_GATES = createGroup("minecraft:fence_gates"); + public static final Supplier DOORS = createGroup("minecraft:doors"); + public static final Supplier SHULKER_BOXES = createGroup("minecraft:shulker_boxes"); + public static final Supplier ANVIL = createGroup("minecraft:anvil"); - static { - IMPLEMENTATION = new BlockGroups().registerFields(CommonBlockGroups.class); - CorePluginVersion version = TranslateCore.getPlatform().getMinecraftVersion(); - if (version.getMajor() == 1) { - IMPLEMENTATION.registerFields(BlockGroups1V13.class); - - } + private BlockGroups() { + throw new RuntimeException("Do not create"); } - private final Collection groups = new HashSet<>(); - - public static Optional getFromId(String id) { - return values().stream().filter(v -> v.getId().equals(id)).findAny(); - } - public static Collection values() { - return Collections.unmodifiableCollection(IMPLEMENTATION.groups); + private static Supplier createGroup(String id) { + return () -> TranslateCore + .getPlatform() + .getBlockGroup(id) + .orElseThrow(() -> new RuntimeException("Cannot find the Block Tag of " + id)); } - public BlockGroups register(BlockGroup... groups) { - this.groups.addAll(Arrays.asList(groups)); - return this; - } - public BlockGroups register(Collection groups) { - this.groups.addAll(groups); - return this; - } - - public BlockGroups registerFields(Class clazz) { - for (Field field : clazz.getDeclaredFields()) { - if (!Modifier.isStatic(field.getModifiers())) { - continue; - } - if (!BlockGroup.class.isAssignableFrom(field.getType())) { - continue; - } - try { - BlockGroup group = (BlockGroup) field.get(null); - this.groups.add(group); - } catch (IllegalAccessException ignored) { - } - } - return this; - } } diff --git a/src/main/java/org/core/world/position/block/grouptype/versions/BlockGroups1V13.java b/src/main/java/org/core/world/position/block/grouptype/versions/BlockGroups1V13.java deleted file mode 100644 index 4529abf1..00000000 --- a/src/main/java/org/core/world/position/block/grouptype/versions/BlockGroups1V13.java +++ /dev/null @@ -1,336 +0,0 @@ -package org.core.world.position.block.grouptype.versions; - -import org.core.world.position.block.blocktypes.CommonBlockTypes; -import org.core.world.position.block.blocktypes.post.BlockTypes1V13; - -@SuppressWarnings("unused") -public interface BlockGroups1V13 { - - CoreBlockGroup AIR = new CoreBlockGroup("Air", BlockTypes1V13.AIR, BlockTypes1V13.CAVE_AIR, - BlockTypes1V13.VOID_AIR); - CoreBlockGroup TRAP_WOOD_DOOR = new CoreBlockGroup("Trap Wood Door", - BlockTypes1V13.ACACIA_TRAPDOOR, - CommonBlockTypes.OAK_TRAPDOOR, - BlockTypes1V13.BIRCH_TRAPDOOR, - BlockTypes1V13.DARK_OAK_TRAPDOOR, - BlockTypes1V13.JUNGLE_TRAPDOOR, - BlockTypes1V13.SPRUCE_TRAPDOOR); - CoreBlockGroup TRAP_DOOR = new CoreBlockGroup("Trap Door", - BlockTypes1V13.IRON_TRAPDOOR, - BlockTypes1V13.ACACIA_TRAPDOOR, - BlockTypes1V13.OAK_TRAPDOOR, - BlockTypes1V13.BIRCH_TRAPDOOR, - BlockTypes1V13.DARK_OAK_TRAPDOOR, - BlockTypes1V13.JUNGLE_TRAPDOOR, - BlockTypes1V13.SPRUCE_TRAPDOOR); - CoreBlockGroup STAIRS = new CoreBlockGroup("Stairs", - CommonBlockTypes.ACACIA_STAIRS, - CommonBlockTypes.BIRCH_STAIRS, - CommonBlockTypes.DARK_OAK_STAIRS, - CommonBlockTypes.JUNGLE_STAIRS, - CommonBlockTypes.OAK_STAIRS, - CommonBlockTypes.SPRUCE_STAIRS, - BlockTypes1V13.COBBLESTONE_STAIRS, - CommonBlockTypes.BRICK_STAIRS, - BlockTypes1V13.DARK_PRISMARINE_STAIRS, - CommonBlockTypes.NETHER_BRICK_STAIRS, - BlockTypes1V13.PRISMARINE_BRICK_STAIRS, - BlockTypes1V13.PRISMARINE_STAIRS, - CommonBlockTypes.PURPUR_STAIRS, - CommonBlockTypes.QUARTZ_STAIRS, - CommonBlockTypes.RED_SANDSTONE_STAIRS, - CommonBlockTypes.SANDSTONE_STAIRS, - CommonBlockTypes.STONE_BRICK_STAIRS); - CoreBlockGroup WOOD_SLAB = new CoreBlockGroup("Wood Slab", - BlockTypes1V13.SPRUCE_SLAB, - BlockTypes1V13.OAK_SLAB, - BlockTypes1V13.JUNGLE_SLAB, - BlockTypes1V13.BIRCH_SLAB, - BlockTypes1V13.DARK_OAK_SLAB, - BlockTypes1V13.ACACIA_SLAB); - CoreBlockGroup WOOD_PLANKS = new CoreBlockGroup("Wood Planks", - BlockTypes1V13.SPRUCE_PLANKS, - BlockTypes1V13.OAK_PLANKS, - BlockTypes1V13.JUNGLE_PLANKS, - BlockTypes1V13.BIRCH_PLANKS, - BlockTypes1V13.DARK_OAK_PLANKS, - BlockTypes1V13.ACACIA_PLANKS); - CoreBlockGroup WOOD_LOG = new CoreBlockGroup("Wood Log", - BlockTypes1V13.SPRUCE_LOG, - BlockTypes1V13.OAK_LOG, - BlockTypes1V13.JUNGLE_LOG, - BlockTypes1V13.BIRCH_LOG, - BlockTypes1V13.DARK_OAK_LOG, - BlockTypes1V13.ACACIA_LOG); - CoreBlockGroup STRIPPED_LOG = new CoreBlockGroup("Stripped Log", - BlockTypes1V13.STRIPPED_SPRUCE_LOG, - BlockTypes1V13.STRIPPED_OAK_LOG, - BlockTypes1V13.STRIPPED_JUNGLE_LOG, - BlockTypes1V13.STRIPPED_BIRCH_LOG, - BlockTypes1V13.STRIPPED_DARK_OAK_LOG, - BlockTypes1V13.STRIPPED_ACACIA_LOG); - CoreBlockGroup LOG = new CoreBlockGroup("Log", WOOD_LOG.getGrouped(), STRIPPED_LOG.getGrouped()); - CoreBlockGroup SLAB = new CoreBlockGroup("Slab", - BlockTypes1V13.SPRUCE_SLAB, - BlockTypes1V13.OAK_SLAB, - BlockTypes1V13.JUNGLE_SLAB, - BlockTypes1V13.BIRCH_SLAB, - BlockTypes1V13.DARK_OAK_SLAB, - BlockTypes1V13.ACACIA_SLAB, - BlockTypes1V13.BRICK_SLAB, - BlockTypes1V13.COBBLESTONE_SLAB, - BlockTypes1V13.DARK_PRISMARINE_SLAB, - BlockTypes1V13.NETHER_BRICK_SLAB, - BlockTypes1V13.PETRIFIED_OAK_SLAB, - BlockTypes1V13.PRISMARINE_BRICK_SLAB, - BlockTypes1V13.PRISMARINE_SLAB, - CommonBlockTypes.PURPUR_SLAB, - BlockTypes1V13.QUARTZ_SLAB, - BlockTypes1V13.RED_SANDSTONE_SLAB, - BlockTypes1V13.SANDSTONE_SLAB, - BlockTypes1V13.STONE_BRICK_SLAB, - CommonBlockTypes.STONE_SLAB); - CoreBlockGroup WOOD_BUTTON = new CoreBlockGroup("Wood Button", - BlockTypes1V13.ACACIA_BUTTON, - BlockTypes1V13.BIRCH_BUTTON, - BlockTypes1V13.DARK_OAK_BUTTON, - BlockTypes1V13.JUNGLE_BUTTON, - BlockTypes1V13.OAK_BUTTON, - BlockTypes1V13.SPRUCE_BUTTON); - CoreBlockGroup BUTTON = new CoreBlockGroup("Button", - BlockTypes1V13.ACACIA_BUTTON, - BlockTypes1V13.BIRCH_BUTTON, - BlockTypes1V13.DARK_OAK_BUTTON, - BlockTypes1V13.JUNGLE_BUTTON, - BlockTypes1V13.OAK_BUTTON, - BlockTypes1V13.SPRUCE_BUTTON, - CommonBlockTypes.STONE_BUTTON); - CoreBlockGroup STAINED_GLASS = new CoreBlockGroup("Stained Glass", - BlockTypes1V13.BLACK_STAINED_GLASS, - BlockTypes1V13.BLUE_STAINED_GLASS, - BlockTypes1V13.BROWN_STAINED_GLASS, - BlockTypes1V13.CYAN_STAINED_GLASS, - BlockTypes1V13.GRAY_STAINED_GLASS, - BlockTypes1V13.GREEN_STAINED_GLASS, - BlockTypes1V13.LIGHT_BLUE_STAINED_GLASS, - BlockTypes1V13.LIGHT_GRAY_STAINED_GLASS, - BlockTypes1V13.LIME_STAINED_GLASS, - BlockTypes1V13.MAGENTA_STAINED_GLASS, - BlockTypes1V13.ORANGE_STAINED_GLASS, - BlockTypes1V13.PINK_STAINED_GLASS, - BlockTypes1V13.PURPLE_STAINED_GLASS, - BlockTypes1V13.RED_STAINED_GLASS, - BlockTypes1V13.WHITE_STAINED_GLASS, - BlockTypes1V13.YELLOW_STAINED_GLASS); - CoreBlockGroup STAINED_GLASS_PANE = new CoreBlockGroup("Stained Glass", - BlockTypes1V13.BLACK_STAINED_GLASS_PANE, - BlockTypes1V13.BLUE_STAINED_GLASS_PANE, - BlockTypes1V13.BROWN_STAINED_GLASS_PANE, - BlockTypes1V13.CYAN_STAINED_GLASS_PANE, - BlockTypes1V13.GRAY_STAINED_GLASS_PANE, - BlockTypes1V13.GREEN_STAINED_GLASS_PANE, - BlockTypes1V13.LIGHT_BLUE_STAINED_GLASS_PANE, - BlockTypes1V13.LIGHT_GRAY_STAINED_GLASS_PANE, - BlockTypes1V13.LIME_STAINED_GLASS_PANE, - BlockTypes1V13.MAGENTA_STAINED_GLASS_PANE, - BlockTypes1V13.ORANGE_STAINED_GLASS_PANE, - BlockTypes1V13.PINK_STAINED_GLASS_PANE, - BlockTypes1V13.PURPLE_STAINED_GLASS_PANE, - BlockTypes1V13.RED_STAINED_GLASS_PANE, - BlockTypes1V13.WHITE_STAINED_GLASS_PANE, - BlockTypes1V13.YELLOW_STAINED_GLASS_PANE); - CoreBlockGroup SAPLING = new CoreBlockGroup("Sapling", - BlockTypes1V13.ACACIA_SAPLING, - BlockTypes1V13.BIRCH_SAPLING, - BlockTypes1V13.DARK_OAK_SAPLING, - BlockTypes1V13.JUNGLE_SAPLING, - BlockTypes1V13.OAK_SAPLING, - BlockTypes1V13.SPRUCE_SAPLING); - CoreBlockGroup POTTED_SAPLING = new CoreBlockGroup("Potted Sapling", - BlockTypes1V13.POTTED_ACACIA_SAPLING, - BlockTypes1V13.POTTED_BIRCH_SAPLING, - BlockTypes1V13.POTTED_DARK_OAK_SAPLING, - BlockTypes1V13.POTTED_JUNGLE_SAPLING, - BlockTypes1V13.POTTED_OAK_SAPLING, - BlockTypes1V13.POTTED_SPRUCE_SAPLING); - CoreBlockGroup WOOD_PRESSURE_PLATE = new CoreBlockGroup("Wood Pressure Plate", - BlockTypes1V13.ACACIA_PRESSURE_PLATE, - BlockTypes1V13.BIRCH_PRESSURE_PLATE, - BlockTypes1V13.DARK_OAK_PRESSURE_PLATE, - BlockTypes1V13.JUNGLE_PRESSURE_PLATE, - BlockTypes1V13.OAK_PRESSURE_PLATE, - BlockTypes1V13.SPRUCE_PRESSURE_PLATE); - CoreBlockGroup WALL_BANNER = new CoreBlockGroup("Wall Banner", - BlockTypes1V13.BLACK_WALL_BANNER, - BlockTypes1V13.BLUE_WALL_BANNER, - BlockTypes1V13.BROWN_WALL_BANNER, - BlockTypes1V13.CYAN_WALL_BANNER, - BlockTypes1V13.GRAY_WALL_BANNER, - BlockTypes1V13.GREEN_WALL_BANNER, - BlockTypes1V13.LIGHT_BLUE_WALL_BANNER, - BlockTypes1V13.LIGHT_GRAY_WALL_BANNER, - BlockTypes1V13.LIME_WALL_BANNER, - BlockTypes1V13.MAGENTA_WALL_BANNER, - BlockTypes1V13.ORANGE_WALL_BANNER, - BlockTypes1V13.PINK_WALL_BANNER, - BlockTypes1V13.PURPLE_WALL_BANNER, - BlockTypes1V13.RED_WALL_BANNER, - BlockTypes1V13.WHITE_WALL_BANNER, - BlockTypes1V13.YELLOW_WALL_BANNER); - CoreBlockGroup FREE_STANDING_BANNER = new CoreBlockGroup("Free Standing Banner", - BlockTypes1V13.BLACK_BANNER, - BlockTypes1V13.BLUE_BANNER, - BlockTypes1V13.BROWN_BANNER, - BlockTypes1V13.CYAN_BANNER, - BlockTypes1V13.GRAY_BANNER, - BlockTypes1V13.GREEN_BANNER, - BlockTypes1V13.LIGHT_BLUE_BANNER, - BlockTypes1V13.LIGHT_GRAY_BANNER, - BlockTypes1V13.LIME_BANNER, - BlockTypes1V13.MAGENTA_BANNER, - BlockTypes1V13.ORANGE_BANNER, - BlockTypes1V13.PINK_BANNER, - BlockTypes1V13.PURPLE_BANNER, - BlockTypes1V13.RED_BANNER, - BlockTypes1V13.WHITE_BANNER, - BlockTypes1V13.YELLOW_BANNER); - CoreBlockGroup BANNER = new CoreBlockGroup("Banner", FREE_STANDING_BANNER.getGrouped(), WALL_BANNER.getGrouped()); - CoreBlockGroup CARPET = new CoreBlockGroup("Carpet", - BlockTypes1V13.BLACK_CARPET, - BlockTypes1V13.BLUE_CARPET, - BlockTypes1V13.BROWN_CARPET, - BlockTypes1V13.CYAN_CARPET, - BlockTypes1V13.GRAY_CARPET, - BlockTypes1V13.GREEN_CARPET, - BlockTypes1V13.LIGHT_BLUE_CARPET, - BlockTypes1V13.LIGHT_GRAY_CARPET, - BlockTypes1V13.LIME_CARPET, - BlockTypes1V13.MAGENTA_CARPET, - BlockTypes1V13.ORANGE_CARPET, - BlockTypes1V13.PINK_CARPET, - BlockTypes1V13.PURPLE_CARPET, - BlockTypes1V13.RED_CARPET, - BlockTypes1V13.WHITE_CARPET, - BlockTypes1V13.YELLOW_CARPET); - CoreBlockGroup WOOL = new CoreBlockGroup("Wool", - BlockTypes1V13.BLACK_WOOL, - BlockTypes1V13.BLUE_WOOL, - BlockTypes1V13.BROWN_WOOL, - BlockTypes1V13.CYAN_WOOL, - BlockTypes1V13.GRAY_WOOL, - BlockTypes1V13.GREEN_WOOL, - BlockTypes1V13.LIGHT_BLUE_WOOL, - BlockTypes1V13.LIGHT_GRAY_WOOL, - BlockTypes1V13.LIME_WOOL, - BlockTypes1V13.MAGENTA_WOOL, - BlockTypes1V13.ORANGE_WOOL, - BlockTypes1V13.PINK_WOOL, - BlockTypes1V13.PURPLE_WOOL, - BlockTypes1V13.RED_WOOL, - BlockTypes1V13.WHITE_WOOL, - BlockTypes1V13.YELLOW_WOOL); - CoreBlockGroup PRESSURE_PLATE = new CoreBlockGroup("Pressure Plate", - BlockTypes1V13.ACACIA_PRESSURE_PLATE, - BlockTypes1V13.BIRCH_PRESSURE_PLATE, - BlockTypes1V13.DARK_OAK_PRESSURE_PLATE, - BlockTypes1V13.JUNGLE_PRESSURE_PLATE, - BlockTypes1V13.OAK_PRESSURE_PLATE, - BlockTypes1V13.SPRUCE_PRESSURE_PLATE, - CommonBlockTypes.HEAVY_WEIGHTED_PRESSURE_PLATE, - CommonBlockTypes.LIGHT_WEIGHTED_PRESSURE_PLATE, - CommonBlockTypes.STONE_PRESSURE_PLATE); - CoreBlockGroup WALL_HEAD = new CoreBlockGroup("Wall Head", - BlockTypes1V13.CREEPER_WALL_HEAD, - BlockTypes1V13.DRAGON_WALL_HEAD, - BlockTypes1V13.PLAYER_WALL_HEAD, - BlockTypes1V13.ZOMBIE_WALL_HEAD); - CoreBlockGroup STANDARD_HEAD = new CoreBlockGroup("Standard Head", - BlockTypes1V13.CREEPER_HEAD, - BlockTypes1V13.DRAGON_HEAD, - BlockTypes1V13.PLAYER_HEAD, - BlockTypes1V13.ZOMBIE_HEAD); - CoreBlockGroup REDSTONE_TORCH = new CoreBlockGroup("Redstone Torch", - CommonBlockTypes.REDSTONE_TORCH, - BlockTypes1V13.REDSTONE_WALL_TORCH); - CoreBlockGroup STANDARD_TORCH = new CoreBlockGroup("Standard Torch", - CommonBlockTypes.TORCH, - BlockTypes1V13.WALL_TORCH); - CoreBlockGroup WALL_TORCH = new CoreBlockGroup("Wall Torch", - BlockTypes1V13.WALL_TORCH, - BlockTypes1V13.REDSTONE_WALL_TORCH); - CoreBlockGroup STANDING_TORCH = new CoreBlockGroup("Standing Torch", - CommonBlockTypes.TORCH, - CommonBlockTypes.REDSTONE_TORCH); - CoreBlockGroup TORCH = new CoreBlockGroup("Torch", - CommonBlockTypes.TORCH, - BlockTypes1V13.WALL_TORCH, - CommonBlockTypes.REDSTONE_TORCH, - BlockTypes1V13.REDSTONE_WALL_TORCH); - CoreBlockGroup CONCRETE = new CoreBlockGroup("Concrete", - BlockTypes1V13.BLACK_CONCRETE, - BlockTypes1V13.BLUE_CONCRETE, - BlockTypes1V13.BROWN_CONCRETE, - BlockTypes1V13.CYAN_CONCRETE, - BlockTypes1V13.GRAY_CONCRETE, - BlockTypes1V13.GREEN_CONCRETE, - BlockTypes1V13.LIGHT_BLUE_CONCRETE, - BlockTypes1V13.LIGHT_GRAY_CONCRETE, - BlockTypes1V13.LIME_CONCRETE, - BlockTypes1V13.MAGENTA_CONCRETE, - BlockTypes1V13.ORANGE_CONCRETE, - BlockTypes1V13.PINK_CONCRETE, - BlockTypes1V13.PURPLE_CONCRETE, - BlockTypes1V13.RED_CONCRETE, - BlockTypes1V13.WHITE_CONCRETE, - BlockTypes1V13.YELLOW_CONCRETE); - CoreBlockGroup CONCRETE_POWDER = new CoreBlockGroup("Concrete Powder", - BlockTypes1V13.BLACK_CONCRETE_POWDER, - BlockTypes1V13.BLUE_CONCRETE_POWDER, - BlockTypes1V13.BROWN_CONCRETE_POWDER, - BlockTypes1V13.CYAN_CONCRETE_POWDER, - BlockTypes1V13.GRAY_CONCRETE_POWDER, - BlockTypes1V13.GREEN_CONCRETE_POWDER, - BlockTypes1V13.LIGHT_BLUE_CONCRETE_POWDER, - BlockTypes1V13.LIGHT_GRAY_CONCRETE_POWDER, - BlockTypes1V13.LIME_CONCRETE_POWDER, - BlockTypes1V13.MAGENTA_CONCRETE_POWDER, - BlockTypes1V13.ORANGE_CONCRETE_POWDER, - BlockTypes1V13.PINK_CONCRETE_POWDER, - BlockTypes1V13.PURPLE_CONCRETE_POWDER, - BlockTypes1V13.RED_CONCRETE_POWDER, - BlockTypes1V13.WHITE_CONCRETE_POWDER, - BlockTypes1V13.YELLOW_CONCRETE_POWDER); - CoreBlockGroup BED = new CoreBlockGroup("Bed", - BlockTypes1V13.BLACK_BED, - BlockTypes1V13.BLUE_BED, - BlockTypes1V13.BROWN_BED, - BlockTypes1V13.CYAN_BED, - BlockTypes1V13.GRAY_BED, - BlockTypes1V13.GREEN_BED, - BlockTypes1V13.LIME_BED, - BlockTypes1V13.MAGENTA_BED, - BlockTypes1V13.ORANGE_BED, - BlockTypes1V13.PINK_BED, - BlockTypes1V13.PURPLE_BED, - BlockTypes1V13.RED_BED, - BlockTypes1V13.WHITE_BED, - BlockTypes1V13.YELLOW_BED, - BlockTypes1V13.LIGHT_BLUE_BED, - BlockTypes1V13.LIGHT_GRAY_BED, - BlockTypes1V13.LIGHT_BLUE_BED); - CoreBlockGroup TERRACOTTA = new CoreBlockGroup("Terracotta", - BlockTypes1V13.BLACK_TERRACOTTA, - BlockTypes1V13.BLUE_TERRACOTTA, - BlockTypes1V13.BROWN_TERRACOTTA, - BlockTypes1V13.CYAN_TERRACOTTA, - BlockTypes1V13.GRAY_TERRACOTTA, - BlockTypes1V13.GREEN_TERRACOTTA, - BlockTypes1V13.LIME_TERRACOTTA, - BlockTypes1V13.MAGENTA_TERRACOTTA, - BlockTypes1V13.ORANGE_TERRACOTTA, - BlockTypes1V13.PINK_TERRACOTTA, - BlockTypes1V13.PURPLE_TERRACOTTA, - BlockTypes1V13.RED_TERRACOTTA, - BlockTypes1V13.WHITE_TERRACOTTA, - BlockTypes1V13.YELLOW_TERRACOTTA); -} diff --git a/src/main/java/org/core/world/position/block/grouptype/versions/CommonBlockGroups.java b/src/main/java/org/core/world/position/block/grouptype/versions/CommonBlockGroups.java deleted file mode 100644 index 46cff0e1..00000000 --- a/src/main/java/org/core/world/position/block/grouptype/versions/CommonBlockGroups.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.core.world.position.block.grouptype.versions; - -import org.core.world.position.block.blocktypes.CommonBlockTypes; - -@SuppressWarnings("unused") -public interface CommonBlockGroups { - - CoreBlockGroup OAK_SIGN = new CoreBlockGroup("Oak Sign", - CommonBlockTypes.OAK_SIGN, - CommonBlockTypes.OAK_WALL_SIGN); - CoreBlockGroup FENCE_GATE = new CoreBlockGroup("Fence Gate", - CommonBlockTypes.ACACIA_FENCE_GATE, - CommonBlockTypes.BIRCH_FENCE_GATE, - CommonBlockTypes.DARK_OAK_FENCE_GATE, - CommonBlockTypes.JUNGLE_FENCE_GATE, - CommonBlockTypes.OAK_FENCE_GATE, - CommonBlockTypes.SPRUCE_FENCE_GATE); - CoreBlockGroup FENCE = new CoreBlockGroup("Fence", - CommonBlockTypes.ACACIA_FENCE, - CommonBlockTypes.BIRCH_FENCE, - CommonBlockTypes.DARK_OAK_FENCE, - CommonBlockTypes.JUNGLE_FENCE, - CommonBlockTypes.NETHER_BRICK_FENCE, - CommonBlockTypes.OAK_FENCE, - CommonBlockTypes.SPRUCE_FENCE); - CoreBlockGroup SHULKER_BOX = new CoreBlockGroup("Shulker Box", - CommonBlockTypes.BLACK_SHULKER_BOX, - CommonBlockTypes.BLUE_SHULKER_BOX, - CommonBlockTypes.BROWN_SHULKER_BOX, - CommonBlockTypes.CYAN_SHULKER_BOX, - CommonBlockTypes.GRAY_SHULKER_BOX, - CommonBlockTypes.GREEN_SHULKER_BOX, - CommonBlockTypes.LIGHT_BLUE_SHULKER_BOX, - CommonBlockTypes.LIME_SHULKER_BOX, - CommonBlockTypes.MAGENTA_SHULKER_BOX, - CommonBlockTypes.ORANGE_SHULKER_BOX, - CommonBlockTypes.PINK_SHULKER_BOX, - CommonBlockTypes.PURPLE_SHULKER_BOX, - CommonBlockTypes.RED_SHULKER_BOX, - CommonBlockTypes.WHITE_SHULKER_BOX, - CommonBlockTypes.YELLOW_SHULKER_BOX); - CoreBlockGroup WEIGHTED_PRESSURE_PLATE = new CoreBlockGroup("Wood Pressure Plate", - CommonBlockTypes.HEAVY_WEIGHTED_PRESSURE_PLATE, - CommonBlockTypes.LIGHT_WEIGHTED_PRESSURE_PLATE); - CoreBlockGroup PISTON = new CoreBlockGroup("Piston", - CommonBlockTypes.STICKY_PISTON, - CommonBlockTypes.PISTON_HEAD, - CommonBlockTypes.STICKY_PISTON, - CommonBlockTypes.MOVING_PISTON); - CoreBlockGroup DOOR = new CoreBlockGroup("Door", - CommonBlockTypes.IRON_DOOR, - CommonBlockTypes.DARK_OAK_DOOR, - CommonBlockTypes.OAK_DOOR, - CommonBlockTypes.ACACIA_DOOR, - CommonBlockTypes.BIRCH_DOOR, - CommonBlockTypes.JUNGLE_DOOR, - CommonBlockTypes.SPRUCE_DOOR); - CoreBlockGroup WOOD_DOOR = new CoreBlockGroup("Wood Door", - CommonBlockTypes.DARK_OAK_DOOR, - CommonBlockTypes.OAK_DOOR, - CommonBlockTypes.ACACIA_DOOR, - CommonBlockTypes.BIRCH_DOOR, - CommonBlockTypes.JUNGLE_DOOR, - CommonBlockTypes.SPRUCE_DOOR); - CoreBlockGroup PISTON_BLOCK = new CoreBlockGroup("Piston Block", - CommonBlockTypes.PISTON, - CommonBlockTypes.STICKY_PISTON); - CoreBlockGroup WOOD_STAIRS = new CoreBlockGroup("Wood Stairs", - CommonBlockTypes.ACACIA_STAIRS, - CommonBlockTypes.BIRCH_STAIRS, - CommonBlockTypes.DARK_OAK_STAIRS, - CommonBlockTypes.JUNGLE_STAIRS, - CommonBlockTypes.OAK_STAIRS, - CommonBlockTypes.SPRUCE_STAIRS); -} diff --git a/src/main/java/org/core/world/position/block/grouptype/versions/CoreBlockGroup.java b/src/main/java/org/core/world/position/block/grouptype/versions/CoreBlockGroup.java deleted file mode 100644 index d8d5178c..00000000 --- a/src/main/java/org/core/world/position/block/grouptype/versions/CoreBlockGroup.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.core.world.position.block.grouptype.versions; - -import org.array.utils.ArrayUtils; -import org.core.world.position.block.BlockType; -import org.core.world.position.block.grouptype.BlockGroup; - -public class CoreBlockGroup extends BlockGroup { - - CoreBlockGroup(String name, BlockType... types) { - super("core:" + name.toLowerCase().replace(" ", "_"), name, types); - } - - CoreBlockGroup(String name, BlockType[]... types) { - this(name, ArrayUtils.join(BlockType.class, types)); - } -} diff --git a/src/main/java/org/core/world/position/impl/BlockPosition.java b/src/main/java/org/core/world/position/impl/BlockPosition.java index ea94c1a3..df710bda 100644 --- a/src/main/java/org/core/world/position/impl/BlockPosition.java +++ b/src/main/java/org/core/world/position/impl/BlockPosition.java @@ -15,6 +15,7 @@ import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; +import java.util.stream.Stream; public interface BlockPosition extends Position { @@ -45,11 +46,16 @@ default BlockPosition getRelative(Direction direction) { return (BlockPosition) this.getRelative(vector.getX(), vector.getY(), vector.getZ()); } + @Deprecated(forRemoval = true) default Set getAttachedEntities() { - return this.getWorld().getEntities().stream().filter(e -> { + return getAttachedLiveEntities().collect(Collectors.toSet()); + } + + default Stream getAttachedLiveEntities() { + return this.getWorld().getLiveEntities().filter(e -> { Optional opAttached = e.getAttachedTo(); return opAttached.map(syncBlockPosition -> syncBlockPosition.equals(this)).orElse(false); - }).collect(Collectors.toSet()); + }); } default boolean isInLineOfSight(final Vector3 vector, FourFacingDirection direction) { diff --git a/src/main/java/org/core/world/structure/Structure.java b/src/main/java/org/core/world/structure/Structure.java index 36d88493..3af76752 100644 --- a/src/main/java/org/core/world/structure/Structure.java +++ b/src/main/java/org/core/world/structure/Structure.java @@ -10,6 +10,8 @@ import java.io.IOException; import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; public interface Structure { @@ -21,7 +23,12 @@ public interface Structure { Set> getEntities(); - Set getBlocks(); + @Deprecated(forRemoval = true) + default Set getBlocks() { + return getBlockDetails().collect(Collectors.toSet()); + } + + Stream getBlockDetails(); Vector3 getSize();