diff --git a/build.gradle b/build.gradle index 0684e89b..94e49e40 100644 --- a/build.gradle +++ b/build.gradle @@ -12,7 +12,9 @@ repositories { group = 'org.core' version = '1.0-SNAPSHOT' description = 'TranslateCore' -java.sourceCompatibility = JavaVersion.VERSION_16 +java { + sourceCompatibility = JavaLanguageVersion.of(11); +} compileJava.options.encoding = 'UTF-8' diff --git a/src/main/java/org/core/adventureText/AText.java b/src/main/java/org/core/adventureText/AText.java index c7cb1442..774855b8 100644 --- a/src/main/java/org/core/adventureText/AText.java +++ b/src/main/java/org/core/adventureText/AText.java @@ -31,8 +31,8 @@ public interface AText extends ComponentLike { @Override default @NotNull Component asComponent() { - if (this instanceof AdventureText adventureText) { - return adventureText.getComponent(); + if (this instanceof AdventureText) { + return ((AdventureText) this).getComponent(); } return ComponentUtils.fromLegacy(this.toLegacy()); } diff --git a/src/main/java/org/core/adventureText/adventure/AdventureText.java b/src/main/java/org/core/adventureText/adventure/AdventureText.java index 773dac7c..903afec6 100644 --- a/src/main/java/org/core/adventureText/adventure/AdventureText.java +++ b/src/main/java/org/core/adventureText/adventure/AdventureText.java @@ -6,6 +6,7 @@ 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; @@ -96,13 +97,13 @@ public Optional getColour() { if (colour == null) { return Optional.empty(); } - if (colour instanceof NamedTextColor namedTextColor) { + if (colour instanceof NamedTextColor) { Optional opText = NamedTextColours .colours() .parallelStream() - .filter(tc -> tc.getBlue() == namedTextColor.blue()) - .filter(tc -> tc.getGreen() == namedTextColor.green()) - .filter(tc -> tc.getRed() == namedTextColor.red()) + .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; 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 ec29cb23..2bea6036 100644 --- a/src/main/java/org/core/command/commands/timings/TimingsCommand.java +++ b/src/main/java/org/core/command/commands/timings/TimingsCommand.java @@ -10,7 +10,7 @@ import org.core.permission.CorePermission; import org.core.permission.Permission; import org.core.schedule.Scheduler; -import org.core.source.viewer.CommandViewer; +import org.core.source.command.CommandSource; import java.lang.management.ManagementFactory; import java.time.LocalTime; @@ -37,9 +37,7 @@ public Optional getPermissionNode() { @Override public boolean run(CommandContext commandContext, String... args) throws NotEnoughArguments { - if (!(commandContext.getSource() instanceof CommandViewer viewer)) { - return false; - } + CommandSource viewer = commandContext.getSource(); OperatingSystemMXBean osBean = ManagementFactory.getPlatformMXBean(OperatingSystemMXBean.class); viewer.sendMessage(AText.ofPlain("Getting timings")); viewer.sendMessage(AText.ofPlain("CPU usage: " + osBean.getCpuLoad())); diff --git a/src/main/java/org/core/eco/account/AccountSnapshot.java b/src/main/java/org/core/eco/account/AccountSnapshot.java index fef241ab..87e94554 100644 --- a/src/main/java/org/core/eco/account/AccountSnapshot.java +++ b/src/main/java/org/core/eco/account/AccountSnapshot.java @@ -31,20 +31,29 @@ public AccountSnapshot(Account account) { @Override public @NotNull PendingTransaction transact(@NotNull Transaction transaction) { switch (transaction.getType()) { - case DEPOSIT -> { + case DEPOSIT: return this.transaction(transaction, BigDecimal::add); - } - case WITHDRAW -> { + case WITHDRAW: return this.transaction(transaction, BigDecimal::subtract); - } - case SET -> { + case SET: return this.transaction(transaction, (current, newValue) -> newValue); - } - default -> throw new IllegalArgumentException( - "Unknown transaction type of '" + transaction.getType().name() + "'"); + default: + throw new IllegalArgumentException( + "Unknown transaction type of '" + transaction.getType().name() + "'"); } } + @Override + public @NotNull BigDecimal getBalance(@NotNull Currency currency) { + BigDecimal amount = this.cachedAmount.get(currency); + if (amount != null) { + return amount; + } + amount = this.account.getBalance(currency); + this.cachedAmount.put(currency, amount); + return amount; + } + private PendingTransaction transaction(@NotNull Transaction transaction, BiFunction action) { BigDecimal current = cachedAmount.get(transaction.getCurrency()); @@ -63,15 +72,4 @@ private PendingTransaction transaction(@NotNull Transaction transaction, return new PendingSingleTransactionImpl(this, transaction, CompletableFuture.completedFuture(transactionResult)); } - - @Override - public @NotNull BigDecimal getBalance(@NotNull Currency currency) { - BigDecimal amount = this.cachedAmount.get(currency); - if (amount != null) { - return amount; - } - amount = this.account.getBalance(currency); - this.cachedAmount.put(currency, amount); - return amount; - } } diff --git a/src/main/java/org/core/entity/Entity.java b/src/main/java/org/core/entity/Entity.java index 6877d4e0..ce5887eb 100644 --- a/src/main/java/org/core/entity/Entity.java +++ b/src/main/java/org/core/entity/Entity.java @@ -129,24 +129,40 @@ default Direction getFacingDirection() { } yaw = yaw % 360; int i = (int) ((yaw + 8) / 22.5); - return switch (i) { - case 1 -> SixteenFacingDirection.WEST_NORTH_WEST; - case 2 -> EightFacingDirection.NORTH_WEST; - case 3 -> SixteenFacingDirection.NORTH_NORTH_WEST; - case 4 -> FourFacingDirection.NORTH; - case 5 -> SixteenFacingDirection.NORTH_NORTH_EAST; - case 6 -> EightFacingDirection.NORTH_EAST; - case 7 -> SixteenFacingDirection.EAST_NORTH_EAST; - case 8 -> FourFacingDirection.EAST; - case 9 -> SixteenFacingDirection.EAST_SOUTH_EAST; - case 10 -> EightFacingDirection.SOUTH_EAST; - case 11 -> SixteenFacingDirection.SOUTH_SOUTH_EAST; - case 12 -> FourFacingDirection.SOUTH; - case 13 -> SixteenFacingDirection.SOUTH_SOUTH_WEST; - case 14 -> EightFacingDirection.SOUTH_WEST; - case 15 -> SixteenFacingDirection.WEST_SOUTH_WEST; - default -> FourFacingDirection.WEST; - }; + switch (i) { + case 1: + return SixteenFacingDirection.WEST_NORTH_WEST; + case 2: + return EightFacingDirection.NORTH_WEST; + case 3: + return SixteenFacingDirection.NORTH_NORTH_WEST; + case 4: + return FourFacingDirection.NORTH; + case 5: + return SixteenFacingDirection.NORTH_NORTH_EAST; + case 6: + return EightFacingDirection.NORTH_EAST; + case 7: + return SixteenFacingDirection.EAST_NORTH_EAST; + case 8: + return FourFacingDirection.EAST; + case 9: + return SixteenFacingDirection.EAST_SOUTH_EAST; + case 10: + return EightFacingDirection.SOUTH_EAST; + case 11: + return SixteenFacingDirection.SOUTH_SOUTH_EAST; + case 12: + return FourFacingDirection.SOUTH; + case 13: + return SixteenFacingDirection.SOUTH_SOUTH_WEST; + case 14: + return EightFacingDirection.SOUTH_WEST; + case 15: + return SixteenFacingDirection.WEST_SOUTH_WEST; + default: + return FourFacingDirection.WEST; + } } /** 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 f329f006..9757b364 100644 --- a/src/main/java/org/core/event/events/connection/ClientConnectionEvent.java +++ b/src/main/java/org/core/event/events/connection/ClientConnectionEvent.java @@ -35,8 +35,8 @@ default AText getLeavingMessage() { @Deprecated(forRemoval = true) default Leave setLeavingMessage(AText message) { - if (message instanceof AdventureText adventureText) { - return this.setLeaveMessage(adventureText.getComponent()); + if (message instanceof AdventureText) { + return this.setLeaveMessage(((AdventureText) message).getComponent()); } return this.setLeaveMessage(ComponentUtils.fromLegacy(message.toLegacy())); } 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 aeb460a1..325429b8 100644 --- a/src/main/java/org/core/inventory/item/stack/LiveItemStack.java +++ b/src/main/java/org/core/inventory/item/stack/LiveItemStack.java @@ -16,9 +16,10 @@ public interface LiveItemStack extends ItemStack { default Optional getPosition() { for (WorldExtent extent : TranslateCore.getServer().getWorlds()) { for (LiveTileEntity tile : extent.getTileEntities()) { - if (!(tile instanceof ContainerTileEntity cTile)) { + if (!(tile instanceof ContainerTileEntity)) { continue; } + ContainerTileEntity cTile = (ContainerTileEntity) tile; if (cTile .getInventory() .getSlots() diff --git a/src/main/java/org/core/platform/update/bukkit/DevBukkitUpdateOption.java b/src/main/java/org/core/platform/update/bukkit/DevBukkitUpdateOption.java index 7480db9a..ae86c890 100644 --- a/src/main/java/org/core/platform/update/bukkit/DevBukkitUpdateOption.java +++ b/src/main/java/org/core/platform/update/bukkit/DevBukkitUpdateOption.java @@ -2,6 +2,16 @@ import org.core.platform.update.UpdateOption; -public record DevBukkitUpdateOption(int numberId) implements UpdateOption { +public class DevBukkitUpdateOption implements UpdateOption { + + private final int numberId; + + public DevBukkitUpdateOption(int numberId) { + this.numberId = numberId; + } + + public int numberId() { + return this.numberId; + } } diff --git a/src/main/java/org/core/vector/Vector.java b/src/main/java/org/core/vector/Vector.java index 4d40f491..0083cbe6 100644 --- a/src/main/java/org/core/vector/Vector.java +++ b/src/main/java/org/core/vector/Vector.java @@ -98,9 +98,10 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (!(obj instanceof Vector vector)) { + if (!(obj instanceof Vector)) { return false; } + Vector vector = (Vector) obj; if (vector.getPointCount() != this.getPointCount()) { return false; } diff --git a/src/main/java/org/core/world/boss/ServerBossBar.java b/src/main/java/org/core/world/boss/ServerBossBar.java index 69131bd5..553d1ea7 100644 --- a/src/main/java/org/core/world/boss/ServerBossBar.java +++ b/src/main/java/org/core/world/boss/ServerBossBar.java @@ -28,27 +28,20 @@ default ServerBossBar setTitle(AText text) { default BossColour getColour() { switch (bossBar().color()) { - case PINK -> { + case PINK: return BossColours.PINK.get(); - } - case BLUE -> { + case BLUE: return BossColours.BLUE.get(); - } - case RED -> { + case RED: return BossColours.RED.get(); - } - case GREEN -> { + case GREEN: return BossColours.GREEN.get(); - } - case YELLOW -> { + case YELLOW: return BossColours.YELLOW.get(); - } - case PURPLE -> { + case PURPLE: return BossColours.PURPLE.get(); - } - case WHITE -> { + case WHITE: return BossColours.WHITE.get(); - } } throw new RuntimeException("legacy colour not accepted"); }