Skip to content

Commit

Permalink
Works again
Browse files Browse the repository at this point in the history
  • Loading branch information
mosemister committed Jun 28, 2024
1 parent 0e81a24 commit 544f3e7
Show file tree
Hide file tree
Showing 52 changed files with 248 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.core.world.position.block.BlockType;

import java.util.Collection;
import java.util.stream.Collectors;

/**
* Gets a single BlockType from a single string argument
Expand All @@ -16,6 +17,6 @@ public BlockTypeArgument(String id) {

@Override
public Collection<BlockType> getAll() {
return TranslateCore.getPlatform().getBlockTypes();
return TranslateCore.getPlatform().getAllBlockTypes().collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import org.core.command.argument.arguments.operation.MappedArgumentWrapper;
import org.core.world.position.block.BlockType;

import java.util.Arrays;
import java.util.Collections;
import java.util.stream.Collectors;

/**
* Gets a list of blocks from the remaining string arguments. This can accept either {@link BlockTypeArgument} or
Expand All @@ -14,10 +14,9 @@
public class BlockTypesArgument extends FlatRemainingArgument<BlockType> {

public BlockTypesArgument(String id) {
super(
id,
new MappedArgumentWrapper<>(new BlockGroupArgument(id), g -> Arrays.asList(g.getGrouped())),
new MappedArgumentWrapper<>(new BlockTypeArgument(id), Collections::singletonList));
super(id,
new MappedArgumentWrapper<>(new BlockGroupArgument(id), g -> g.getBlocks().collect(Collectors.toList())),
new MappedArgumentWrapper<>(new BlockTypeArgument(id), Collections::singletonList));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ public Set<String> suggest(CommandContext commandContext, CommandArgumentContext
String worldPeek = commandContext.getCommand()[argument.getFirstArgument()];
return TranslateCore
.getServer()
.getWorlds()
.stream()
.getWorldExtents()
.map(WorldExtent::getName)
.filter(n -> n.toLowerCase().startsWith(worldPeek))
.collect(Collectors.toSet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public CommandArgumentResult<LivePlayer> parse(CommandContext context, CommandAr
String command = context.getCommand()[argument.getFirstArgument()];
Optional<LivePlayer> opPlayer = TranslateCore
.getServer()
.getOnlinePlayers()
.stream()
.getLivePlayers()
.filter(p -> p.getName().equalsIgnoreCase(command))
.findFirst();
if (opPlayer.isEmpty()) {
Expand All @@ -48,8 +47,7 @@ public Set<String> suggest(CommandContext commandContext, CommandArgumentContext
String command = commandContext.getCommand()[argument.getFirstArgument()];
return TranslateCore
.getServer()
.getOnlinePlayers()
.stream()
.getLivePlayers()
.map(AbstractHuman::getName)
.filter(p -> p.toLowerCase().startsWith(command.toLowerCase()))
.collect(Collectors.toSet());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/core/config/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface ConfigManager {
ConfigurationStream.ConfigurationFile read(@NotNull File file, @Nullable ConfigurationFormat format);

default ConfigurationStream.ConfigurationFile read(@NotNull File file) {
return read(file, ConfigurationFormat
return this.read(file, ConfigurationFormat
.forFile(file.getName())
.orElseThrow(() -> new IllegalArgumentException("Unknown file extension for " + file.getName())));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ public String unparse(BlockType value) {
public List<BlockType> getSuggestions(String peek) {
return TranslateCore
.getPlatform()
.getBlockTypes()
.stream()
.getAllBlockTypes()
.filter(bt -> bt.getId().toLowerCase().startsWith(peek.toLowerCase()))
.collect(Collectors.toList());
}

@Override
public List<BlockType> getSuggestions() {
return new ArrayList<>(TranslateCore.getPlatform().getBlockTypes());
return TranslateCore.getPlatform().getAllBlockTypes().collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.core.inventory.item.ItemType;
import org.core.platform.Platform;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
Expand All @@ -26,14 +25,13 @@ public String unparse(ItemType value) {
public List<ItemType> getSuggestions(String peek) {
return TranslateCore
.getPlatform()
.getItemTypes()
.stream()
.getAllItemTypes()
.filter(it -> it.getId().toLowerCase().startsWith(peek.toLowerCase()))
.collect(Collectors.toList());
}

@Override
public List<ItemType> getSuggestions() {
return new ArrayList<>(TranslateCore.getPlatform().getItemTypes());
return TranslateCore.getPlatform().getAllItemTypes().collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
import org.core.utils.Guaranteed;

@Deprecated
public class UnspecificParsers<T> implements Guaranteed<UnspecificParser<T>> {
public final class UnspecificParsers<T> implements Guaranteed<UnspecificParser<T>> {

@Deprecated
public static final UnspecificParser<ItemStack> ITEM_STACK = TranslateCore
.getPlatform()
.get(new UnspecificParsers<>("coreto" + TranslateCore.getPlatform().getDetails().getIdName() + ":itemstack",
"ItemStack"));
"ItemStack"));

@Deprecated
public static final UnspecificParser<Inventory> INVENTORY = TranslateCore
.getPlatform()
.get(new UnspecificParsers<>("coreto" + TranslateCore.getPlatform().getDetails().getIdName() + ":inventory",
"Inventory"));
"Inventory"));

private final String name;
private final String idName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@

import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

@Deprecated
public class InventoryParser implements UnspecificParser<InventorySnapshot> {

@Override
public void set(ConfigurationStream file, InventorySnapshot value, ConfigurationNode node) {
int slotCount = value.getSlotCount();
Set<Slot> slots = value.getSlots();
Set<Slot> slots = value.getItemSlots().collect(Collectors.toSet());
for (int index = 0; index < slotCount; index++) {
final int finalIndex = index;
Slot slot = slots
Expand All @@ -43,7 +44,7 @@ public void set(ConfigurationStream file, InventorySnapshot value, Configuration

@Override
public Optional<InventorySnapshot> parse(ConfigurationStream file, ConfigurationNode node) {
InventorySnapshot inv = new UnknownInventorySnapshot();
UnknownInventorySnapshot inv = new UnknownInventorySnapshot();
file.getChildren(node).forEach(i -> {
String[] totalPath = i.getPath();
try {
Expand All @@ -52,12 +53,12 @@ public Optional<InventorySnapshot> parse(ConfigurationStream file, Configuration
if (opStack.isEmpty()) {
return;
}
Slot snapshot = new SlotSnapshot(slotIndex, opStack.get());
inv.getSlots().add(snapshot);
SlotSnapshot snapshot = new SlotSnapshot(slotIndex, opStack.get());
inv.getSlotSnapshots().add(snapshot);
} catch (NumberFormatException ignore) {
}
});
if (inv.getSlots().isEmpty()) {
if (inv.getSlotSnapshots().isEmpty()) {
return Optional.empty();
}
return Optional.of(inv);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/core/eco/account/AccountSnapshot.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public class AccountSnapshot implements Account {

private final Account account;
private Map<Currency, BigDecimal> cachedAmount = new HashMap<>();
private final Map<Currency, BigDecimal> cachedAmount = new HashMap<>();

public AccountSnapshot(Account account) {
this.account = account;
Expand Down Expand Up @@ -56,9 +56,9 @@ public AccountSnapshot(Account account) {

private PendingTransaction transaction(@NotNull Transaction transaction,
BiFunction<BigDecimal, BigDecimal, BigDecimal> action) {
BigDecimal current = cachedAmount.get(transaction.getCurrency());
BigDecimal current = this.cachedAmount.get(transaction.getCurrency());
if (current == null) {
current = account.getBalance(transaction.getCurrency());
current = this.account.getBalance(transaction.getCurrency());
}
BigDecimal newValue = action.apply(current, transaction.getAmount());
if (newValue.compareTo(BigDecimal.ZERO) < 0) {
Expand All @@ -67,7 +67,7 @@ private PendingTransaction transaction(@NotNull Transaction transaction,
return new PendingSingleTransactionImpl(this, transaction,
CompletableFuture.completedFuture(transactionResult));
}
cachedAmount.put(transaction.getCurrency(), newValue);
this.cachedAmount.put(transaction.getCurrency(), newValue);
TransactionResult transactionResult = new TransactionResultImpl(transaction, current, newValue);
return new PendingSingleTransactionImpl(this, transaction,
CompletableFuture.completedFuture(transactionResult));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,4 @@ default Optional<Transaction> getCurrentTransaction() {
}
return Optional.of(remaining.get(0));
}

;

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public interface TransactionsResult {

default boolean wasSuccessful() {
return getTransactions().stream().allMatch(TransactionResult::wasSuccessful);
return this.getTransactions().stream().allMatch(TransactionResult::wasSuccessful);
}

List<TransactionResult> getTransactions();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/core/entity/EntityTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* @param <T> The LiveEntity of the EntityType
* @param <S> The EntitySnapshot of the EntityType
*/
public class EntityTypes<T extends LiveEntity, S extends EntitySnapshot<T>> implements Guaranteed<EntityType<T, S>> {
public final class EntityTypes<T extends LiveEntity, S extends EntitySnapshot<T>> implements Guaranteed<EntityType<T, S>> {

public static final Singleton<EntityType<LiveClassicZombie, ClassicZombieSnapshot>> ZOMBIE = TranslateCore
.getPlatform()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.core.entity.LiveEntity;
import org.core.permission.Permission;
import org.core.source.command.CommandSource;
import org.core.vector.type.Vector3;
import org.core.world.position.block.details.BlockDetails;
import org.core.world.position.impl.BlockPosition;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.UnmodifiableView;
Expand All @@ -28,9 +30,13 @@ default EntityType<LivePlayer, PlayerSnapshot> getType() {
return Player.super.getType();
}

void setBlock(@NotNull BlockDetails details, @NotNull Vector3<Integer> position);

boolean hasPermission(Permission permission);

@NotNull @UnmodifiableView Iterable<? extends BossBar> bossBars();
@NotNull
@UnmodifiableView
Iterable<? extends BossBar> bossBars();

default Stream<? extends BossBar> bossBarsStream() {
return StreamSupport.stream(this.bossBars().spliterator(), false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ default SignTileEntitySnapshot getTo(){

@Deprecated(forRemoval = true)
default SignChangeEvent setTo(SignTileEntitySnapshot snapshot) {
SignSide side = getChangingSide();
SignSide side = this.getChangingSide();
SignSide snapshotSide = snapshot.getSide(side.isFront());
side.setLines(snapshotSide.getLines());
return this;
}

@Deprecated(forRemoval = true)
default SignTileEntitySnapshot getFrom() {
return getSign();
return this.getSign();
}

SignTileEntitySnapshot getSign();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/core/inventory/Inventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface Parent extends Inventory {

@Deprecated(forRemoval = true)
default Set<InventoryPart> getFirstChildren() {
return getParts().collect(Collectors.toSet());
return this.getParts().collect(Collectors.toSet());
}

Stream<InventoryPart> getParts();
Expand All @@ -32,7 +32,7 @@ default Optional<Slot> getSlot(int slotPos) {

@Deprecated(forRemoval = true)
default Set<Slot> getSlots() {
return getItemSlots().collect(Collectors.toSet());
return this.getItemSlots().collect(Collectors.toSet());
}

Stream<Slot> getItemSlots();
Expand All @@ -42,6 +42,6 @@ default Set<Slot> getSlots() {
Inventory createSnapshot();

default int getSlotCount() {
return (int) getItemSlots().count();
return (int) this.getItemSlots().count();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import org.core.inventory.parts.InventoryPart;
import org.core.inventory.parts.Slot;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Supplier;
import java.util.stream.Stream;

public interface CraftingInventory extends Inventory.Parent, BlockAttachedInventory {

Expand All @@ -16,7 +15,7 @@ public interface CraftingInventory extends Inventory.Parent, BlockAttachedInvent
Slot getResult();

@Override
default Set<InventoryPart> getFirstChildren() {
return new HashSet<>(Arrays.asList(this.getCraftingGrid(), this.getResult()));
default Stream<InventoryPart> getParts() {
return Stream.<Supplier<? extends InventoryPart>>of(this::getCraftingGrid, this::getResult).map(Supplier::get);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

public class UnknownInventorySnapshot implements InventorySnapshot {

private final Collection<Slot> slots = new HashSet<>();
private final Set<SlotSnapshot> slots = new HashSet<>();

public UnknownInventorySnapshot() {

}

public UnknownInventorySnapshot(Inventory inventory) {
this.slots.addAll(inventory.getItemSlots().collect(Collectors.toList()));
this.slots.addAll(inventory.getItemSlots().map(Slot::createSnapshot).collect(Collectors.toList()));
}

public UnknownInventorySnapshot(Collection<? extends SlotSnapshot> collection) {
Expand All @@ -33,14 +33,13 @@ public UnknownInventorySnapshot(Collection<? extends SlotSnapshot> collection) {
public void apply() {
}

@Override
public Stream<Slot> getItemSlots() {
return this.slots.stream();
public Collection<SlotSnapshot> getSlotSnapshots() {
return this.slots;
}

@Override
public int getSlotCount() {
return this.slots.size();
public Stream<Slot> getItemSlots() {
return this.slots.stream().map(t -> t);
}

@Override
Expand All @@ -49,11 +48,17 @@ public Optional<Slot> getSlot(int slotPos) {
.stream()
.filter(s -> s.getPosition().isPresent())
.filter(s -> s.getPosition().get() == slotPos)
.findAny();
.findAny()
.map(t -> t);
}

@Override
public UnknownInventorySnapshot createSnapshot() {
return new UnknownInventorySnapshot(this);
}

@Override
public int getSlotCount() {
return this.slots.size();
}
}
Loading

0 comments on commit 544f3e7

Please sign in to comment.