Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import net.hollowcube.canvas.internal.Context;
import net.hollowcube.posthog.PostHog;
import net.minestom.server.MinecraftServer;
import net.minestom.server.entity.Player;
import org.jetbrains.annotations.*;
import org.slf4j.Logger;
Expand Down Expand Up @@ -121,6 +120,9 @@ public void popView(@NotNull String signal, Object... args) {
context.performSignal(signal, args);
}

public final void setDirty() {
context.markDirty();
}

/**
* Called when this view is mounted (shown to a player).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ public interface Context {

void popView();

void markDirty();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ public interface ElementContext extends Context {
/**
* Signals that this context has been modified and should be updated.
*/
@Override
void markDirty();
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ public void pushView(@NotNull View view, boolean isTransient) {
public void popView() {
throw new UnsupportedOperationException("Cannot pop view on root context");
}

@Override
public void markDirty() {
throw new UnsupportedOperationException("Cannot mark dirty on root context");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ public boolean addViewer(@NotNull Player player) {

@Override
public boolean removeViewer(@NotNull Player player) {
player.getInventory().setCursorItem(ItemStack.AIR);

var result = super.removeViewer(player);
if (result) {
player.getInventory().update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public static <E extends Enum<?>> ArgumentEnum<E> Enum(@NotNull String id, Class
return new ArgumentItemStack(id);
}

public static @NotNull ArgumentUUID UUID(@NotNull String id) {
return new ArgumentUUID(id);
}


// Impl

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package net.hollowcube.command.arg;

import net.hollowcube.command.util.StringReader;
import net.hollowcube.command.util.WordType;
import net.minestom.server.command.CommandSender;
import org.jetbrains.annotations.NotNull;

import java.util.UUID;

public class ArgumentUUID extends Argument<UUID> {

protected ArgumentUUID(@NotNull String id) {
super(id);
}

@Override
public @NotNull ParseResult<UUID> parse(@NotNull CommandSender sender, @NotNull StringReader reader) {
var word = reader.readWord(WordType.BRIGADIER);
try {
return success(UUID.fromString(word));
} catch (IllegalArgumentException e) {
return syntaxError();
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package net.hollowcube.mapmaker.command.map;

import net.hollowcube.canvas.internal.Controller;
import net.hollowcube.command.CommandContext;
import net.hollowcube.command.arg.Argument;
import net.hollowcube.command.dsl.CommandDsl;
import net.hollowcube.mapmaker.ExceptionReporter;
import net.hollowcube.mapmaker.gui.play.collection.MapCollectionView;
import net.hollowcube.mapmaker.gui.play.collection.list.EditMapCollectionListView;
import net.hollowcube.mapmaker.map.MapService;
import net.minestom.server.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.UUID;

public class MapCollectionCommand extends CommandDsl {

private final Argument<UUID> idArg = Argument.UUID("id")
.description("The ID of the collection to view")
.defaultValue((UUID) null);

private final Controller controller;
private final MapService maps;

public MapCollectionCommand(@NotNull Controller controller, @NotNull MapService maps) {
super("collection");
this.controller = controller;
this.maps = maps;

addSyntax(playerOnly(this::handleViewCollections));
addSyntax(playerOnly(this::handleViewCollection), idArg);
}

private void handleViewCollections(@NotNull Player player, @NotNull CommandContext ctx) {
this.controller.show(player, EditMapCollectionListView::new);
}

private void handleViewCollection(@NotNull Player player, @NotNull CommandContext ctx) {
var collectionId = ctx.get(idArg);
if (collectionId == null) {
player.sendMessage("No collection ID specified");
return;
}

try {
var collection = this.maps.getMapCollection(player.getUuid().toString(), collectionId.toString());
this.controller.show(player, c -> new MapCollectionView(c, collection));
} catch (MapService.NotFoundError e) {
player.sendMessage("No collection found for ID " + collectionId);
} catch (Exception e) {
player.sendMessage("Failed to load collection");
ExceptionReporter.reportException(e, player);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public MapCommand(
.build()
);

addSubcommand(new MapCollectionCommand(guiController, mapService));

// Permissioned commands
addSubcommand(this.delete = new MapDeleteCommand(mapService, permManager));
addSubcommand(this.edit = new MapEditCommand(mapService, permManager, bridge));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.hollowcube.mapmaker.gui.common.anvil;
package net.hollowcube.mapmaker.gui.common.search;

import net.hollowcube.canvas.Element;
import net.hollowcube.canvas.Label;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package net.hollowcube.mapmaker.gui.common.search;

import net.hollowcube.canvas.Label;
import net.hollowcube.canvas.View;
import net.hollowcube.canvas.annotation.Action;
import net.hollowcube.canvas.annotation.Outlet;
import net.hollowcube.canvas.internal.Context;
import net.hollowcube.common.lang.LanguageProviderV2;
import net.hollowcube.mapmaker.util.ItemUtils;
import net.minestom.server.item.Material;
import org.jetbrains.annotations.NotNull;

public class ItemSearchEntry extends View {

public static final String SIGNAL = "search.selected";

private @Outlet("label") Label label;
private final @NotNull Material material;

public ItemSearchEntry(@NotNull Context context, @NotNull Material material) {
super(context);

this.material = material;

this.label.setItemSprite(ItemUtils.asDisplay(material));
this.label.setArgs(LanguageProviderV2.getVanillaTranslation(material));
}

@Action("label")
private void handleSelect() {
performSignal(SIGNAL, this.material);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package net.hollowcube.mapmaker.gui.common.search;

import net.hollowcube.canvas.annotation.Signal;
import net.hollowcube.canvas.internal.Context;
import net.hollowcube.mapmaker.util.Autocompletors;
import net.minestom.server.item.Material;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.Objects;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.Consumer;
import java.util.function.Predicate;

public class ItemSearchView extends AbstractSearchView<ItemSearchEntry> {

private final Predicate<Material> filter;
private final Consumer<Material> callback;

public ItemSearchView(@NotNull Context context, Predicate<Material> filter, Consumer<Material> callback) {
super(context);

this.filter = filter;
this.callback = callback;
}

@Override
protected List<ItemSearchEntry> search(@NotNull Context context, int page, int size, @NotNull String input) {
if (input.isEmpty()) {
return ThreadLocalRandom.current().ints(1, Material.values().size())
.mapToObj(Material::fromId)
.filter(Objects::nonNull)
.filter(this.filter)
.limit(size)
.map(m -> new ItemSearchEntry(context, m))
.toList();
} else {
return Autocompletors.searchMaterials(input, size, this.filter)
.stream()
.map(m -> new ItemSearchEntry(context, m))
.toList();
}
}

@Signal(ItemSearchEntry.SIGNAL)
private void handleSelectIcon(@NotNull Material material) {
this.callback.accept(material);
popView();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.hollowcube.common.lang.LanguageProviderV2;
import net.hollowcube.common.lang.TimeComponent;
import net.hollowcube.mapmaker.ExceptionReporter;
import net.hollowcube.mapmaker.gui.play.collection.list.AddMapCollectionListView;
import net.hollowcube.mapmaker.gui.play.details.DetailsTimesTabView;
import net.hollowcube.mapmaker.map.*;
import net.hollowcube.mapmaker.map.runtime.ServerBridge;
Expand Down Expand Up @@ -363,6 +364,11 @@ public void handlePlayMap(@NotNull Player player) {
}
}

@Action("add_to_collection")
public void handleAddToCollection(@NotNull Player player) {
pushTransientView(context -> new AddMapCollectionListView(context, map.id()));
}

@Action(value = "leave_map", async = true)
public void handleLeaveMap(@NotNull Player player) {
bridge.joinHub(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.List;
import java.util.Map;

public class MapEntry extends View {
public class MapEntry extends View implements ProgressMapEntry {

private @ContextObject PlayerService playerService;
private @ContextObject ServerBridge bridge;
Expand All @@ -44,10 +44,12 @@ public MapEntry(@NotNull Context context, @NotNull MapData map) {
async(this::updateIcon);
}

@Override
public @NotNull MapData map() {
return map;
}

@Override
public void setProgress(PersonalizedMapData.Progress progress, int playtime) {
this.progress = progress;
this.playtime = playtime;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package net.hollowcube.mapmaker.gui.play;

import net.hollowcube.mapmaker.map.MapData;
import net.hollowcube.mapmaker.map.PersonalizedMapData;

public interface ProgressMapEntry {

MapData map();

void setProgress(PersonalizedMapData.Progress progress, int playtime);
}
Loading