Skip to content

Commit

Permalink
Major changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mosemister committed Jan 20, 2024
1 parent 67072a9 commit 67ba007
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 67 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/core/adventureText/AText.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -96,13 +97,13 @@ public Optional<TextColour> getColour() {
if (colour == null) {
return Optional.empty();
}
if (colour instanceof NamedTextColor namedTextColor) {
if (colour instanceof NamedTextColor) {
Optional<TextColour> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,9 +37,7 @@ public Optional<Permission> 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()));
Expand Down
36 changes: 17 additions & 19 deletions src/main/java/org/core/eco/account/AccountSnapshot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<BigDecimal, BigDecimal, BigDecimal> action) {
BigDecimal current = cachedAmount.get(transaction.getCurrency());
Expand All @@ -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;
}
}
52 changes: 34 additions & 18 deletions src/main/java/org/core/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ public interface LiveItemStack extends ItemStack {
default Optional<SyncExactPosition> 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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
3 changes: 2 additions & 1 deletion src/main/java/org/core/vector/Vector.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
21 changes: 7 additions & 14 deletions src/main/java/org/core/world/boss/ServerBossBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down

0 comments on commit 67ba007

Please sign in to comment.