use of com.almuradev.almura.feature.store.Store in project Almura by AlmuraDev.
the class ClientStoreManager method handleBuyingItems.
public void handleBuyingItems(final String id, @Nullable final List<BuyingItem> items) {
checkNotNull(id);
// Ensure we have the store screen open
final GuiScreen currentScreen = Minecraft.getMinecraft().currentScreen;
if (!(currentScreen instanceof StoreScreen)) {
return;
}
// Update our local store
final Store store = this.stores.stream().filter(s -> s.getId().equals(id)).findAny().orElse(null);
if (store != null) {
// Clear existing items
store.getBuyingItems().clear();
if (items != null) {
// Add new items
store.getBuyingItems().addAll(items);
}
// Refresh the screen and create controls
((StoreScreen) currentScreen).refresh(true);
} else {
// Refresh the screen
((StoreScreen) currentScreen).refresh(false);
}
}
use of com.almuradev.almura.feature.store.Store in project Almura by AlmuraDev.
the class ClientboundStoresRegistryPacket method writeTo.
@Override
public void writeTo(final ChannelBuf buf) {
buf.writeInteger(this.stores == null ? 0 : this.stores.size());
if (this.stores != null) {
for (final Store store : this.stores) {
buf.writeString(store.getId());
buf.writeString(store.getName());
try {
final byte[] createdData = SerializationUtil.objectToBytes(store.getCreated());
buf.writeInteger(createdData.length);
buf.writeBytes(createdData);
} catch (IOException e) {
e.printStackTrace();
continue;
}
final byte[] creatorData = SerializationUtil.toBytes(store.getCreator());
buf.writeInteger(creatorData.length);
buf.writeBytes(creatorData);
final String creatorName = store.getCreatorName().orElse(null);
buf.writeBoolean(creatorName != null);
if (creatorName != null) {
buf.writeString(creatorName);
}
buf.writeString(store.getPermission());
buf.writeBoolean(store.isHidden());
}
}
}
use of com.almuradev.almura.feature.store.Store in project Almura by AlmuraDev.
the class ClientStoreManager method handleSellingItems.
public void handleSellingItems(final String id, @Nullable final List<SellingItem> items) {
checkNotNull(id);
// Ensure we have the store screen open
final GuiScreen currentScreen = Minecraft.getMinecraft().currentScreen;
if (!(currentScreen instanceof StoreScreen)) {
return;
}
// Update our local store
final Store store = this.stores.stream().filter(s -> s.getId().equals(id)).findAny().orElse(null);
if (store != null) {
// Clear existing items
store.getSellingItems().clear();
if (items != null) {
// Add new items
store.getSellingItems().addAll(items);
}
// Refresh the screen and create controls
((StoreScreen) currentScreen).refresh(true);
} else {
// Refresh the screen
((StoreScreen) currentScreen).refresh(false);
}
}
use of com.almuradev.almura.feature.store.Store in project Almura by AlmuraDev.
the class ClientStoreManager method filterLocalItems.
@SuppressWarnings("unchecked")
public <T extends StoreItem> List<T> filterLocalItems(final String id, @Nullable final String filter, @Nullable final String sort, final SideType targetSide) {
checkNotNull(id);
checkNotNull(targetSide);
final Store axs = this.getStore(id);
checkNotNull(axs);
Stream<T> stream = targetSide == SideType.BUY ? (Stream<T>) axs.getBuyingItems().stream() : (Stream<T>) axs.getSellingItems().stream();
if (filter != null) {
final List<FilterRegistry.FilterElement<StoreItem>> elements = FilterRegistry.instance.getFilterElements(filter);
stream = stream.filter(storeItem -> elements.stream().allMatch(element -> element.getFilter().test(storeItem, element.getValue())));
}
if (sort != null) {
final List<FilterRegistry.SorterElement<StoreItem>> elements = FilterRegistry.instance.getSortingElements(sort);
final Comparator<StoreItem> comparator = FilterRegistry.instance.buildSortingComparator(elements).orElse(null);
if (comparator != null) {
stream = stream.sorted(comparator);
}
}
return stream.collect(Collectors.toList());
}
Aggregations