Skip to content

Commit

Permalink
Added support for origins inventory power - implements #18
Browse files Browse the repository at this point in the history
  • Loading branch information
PotatoPresident committed Jul 11, 2021
1 parent 7db3ede commit 743e1c3
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 3 deletions.
15 changes: 14 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@ repositories {
name = "Ladysnake Libs"
url = "https://ladysnake.jfrog.io/artifactory/mods"
}
maven {
url = 'https://maven.cafeteria.dev'
content {
includeGroup 'net.adriantodt.fabricmc'
}
}
maven { url "https://maven.jamieswhiteshirt.com/libs-release/" }
maven { url "https://maven.shedaniel.me/" }
maven { url 'https://maven.nucleoid.xyz' }
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
mavenCentral()
maven { url 'https://api.modrinth.com/maven' }
maven { url 'https://jitpack.io' }
}

sourceCompatibility = JavaVersion.VERSION_1_8
Expand All @@ -34,10 +43,14 @@ dependencies {
// You may need to force-disable transitiveness on them.
modImplementation include("eu.pb4:sgui:${project.sgui_version}")

modImplementation "maven.modrinth:trinkets:${project.trinkets_version}"
modImplementation "com.github.emilyalexandra:trinkets:main-SNAPSHOT"
modImplementation "io.github.onyxstudios.Cardinal-Components-API:cardinal-components-base:3.0.0"
modImplementation "io.github.onyxstudios.Cardinal-Components-API:cardinal-components-entity:3.0.0"

modImplementation ("com.github.apace100:origins-fabric:${project.origins_version}") {
exclude group: "com.terraformersmc"
}

modImplementation "me.lucko:fabric-permissions-api:0.1-SNAPSHOT"
include "me.lucko:fabric-permissions-api:0.1-SNAPSHOT"

Expand Down
5 changes: 3 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.17.1
yarn_mappings=1.17.1+build.1
yarn_mappings=1.17.1+build.10
loader_version=0.11.6
# Mod Properties
mod_version=1.4.4
mod_version=1.4.5
maven_group=us.potatoboy
archives_base_name=InvView
# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.36.1+1.17
trinkets_version=3.0.0
origins_version=v1.0.2
sgui_version=1.0.0-rc3-1.17.1
12 changes: 12 additions & 0 deletions src/main/java/us/potatoboy/invview/InvView.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ public class InvView implements ModInitializer {
private static MinecraftServer minecraftServer;
public static boolean isTrinkets = false;
public static boolean isLuckPerms = false;
public static boolean isOrigins = false;

@Override
public void onInitialize() {
isTrinkets = FabricLoader.getInstance().isModLoaded("trinkets");
isLuckPerms = FabricLoader.getInstance().isModLoaded("luckperms");
isOrigins = FabricLoader.getInstance().isModLoaded("origins");

CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {

Expand Down Expand Up @@ -57,13 +59,23 @@ public void onInitialize() {
.executes(ViewCommand::trinkets))
.build();

LiteralCommandNode<ServerCommandSource> originNode = CommandManager
.literal("origin-inv")
.requires(Permissions.require("invview.command.origin", 2))
.then(CommandManager.argument("target", GameProfileArgumentType.gameProfile())
.executes(ViewCommand::origin))
.build();


dispatcher.getRoot().addChild(viewNode);
viewNode.addChild(invNode);
viewNode.addChild(echestNode);
if (isTrinkets) {
viewNode.addChild(trinketNode);
}
if (isOrigins) {
viewNode.addChild(originNode);
}
});

ServerLifecycleEvents.SERVER_STARTING.register(this::onLogicalServerStarting);
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/us/potatoboy/invview/ViewCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import dev.emi.trinkets.api.TrinketInventory;
import dev.emi.trinkets.api.TrinketsApi;
import eu.pb4.sgui.api.gui.SimpleGui;
import io.github.apace100.apoli.component.PowerHolderComponent;
import io.github.apace100.apoli.power.InventoryPower;
import net.luckperms.api.LuckPermsProvider;
import net.luckperms.api.cacheddata.CachedPermissionData;
import net.luckperms.api.util.Tristate;
Expand All @@ -25,6 +27,7 @@
import net.minecraft.world.dimension.DimensionType;
import us.potatoboy.invview.gui.SavingPlayerDataGui;

import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;

Expand Down Expand Up @@ -103,6 +106,36 @@ public static int trinkets(CommandContext<ServerCommandSource> context) throws C
return 1;
}

public static int origin(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
ServerPlayerEntity player = context.getSource().getPlayer();
ServerPlayerEntity requestedPlayer = getRequestedPlayer(context);

isProtected(requestedPlayer).thenAcceptAsync(isProtected -> {
if (isProtected) {
context.getSource().sendError(new LiteralText("Requested inventory is protected"));
} else {
List<InventoryPower> inventories = PowerHolderComponent.getPowers(requestedPlayer, InventoryPower.class);
if (inventories.isEmpty()) {
context.getSource().sendError(new LiteralText("Requested player has no inventory power"));
} else {
SimpleGui gui = new SavingPlayerDataGui(ScreenHandlerType.GENERIC_9X5, player, requestedPlayer);
gui.setTitle(requestedPlayer.getDisplayName());
int index = 0;
for (InventoryPower inventory : inventories) {
for (int i = 0; i < inventory.size(); i++) {
gui.setSlotRedirect(index, new Slot(inventory, index, 0, 0));
index += 1;
}
}

gui.open();
}
}
});

return 1;
}

private static ServerPlayerEntity getRequestedPlayer(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
GameProfile requestedProfile = GameProfileArgumentType.getProfileArgument(context, "target").iterator().next();
ServerPlayerEntity requestedPlayer = minecraftServer.getPlayerManager().getPlayer(requestedProfile.getName());
Expand Down

0 comments on commit 743e1c3

Please sign in to comment.