Skip to content

Commit

Permalink
Update to 1.19.3
Browse files Browse the repository at this point in the history
Disable origins support
  • Loading branch information
PotatoPresident committed Dec 20, 2022
1 parent 653f487 commit 04cd4bd
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 84 deletions.
16 changes: 4 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '0.12.+'
id 'fabric-loom' version '1.0.+'
id 'maven-publish'
}

Expand Down Expand Up @@ -48,18 +48,10 @@ dependencies {
modImplementation include("eu.pb4:sgui:${project.sgui_version}")

modImplementation "dev.emi:trinkets:${project.trinkets_version}"
modImplementation "com.github.apace100:apoli:${project.apoli_version}"
/*
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:apoli:${project.apoli_version}"

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"
modImplementation "me.lucko:fabric-permissions-api:0.2-SNAPSHOT"
include "me.lucko:fabric-permissions-api:0.2-SNAPSHOT"

compileOnly 'net.luckperms:api:5.3'
}
Expand Down
16 changes: 8 additions & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://fabricmc.net/develop/
minecraft_version=1.19
yarn_mappings=1.19+build.1
loader_version=0.14.6
minecraft_version=1.19.3
yarn_mappings=1.19.3+build.3
loader_version=0.14.11
# Mod Properties
mod_version=1.4.9
mod_version=1.4.10
maven_group=us.potatoboy
archives_base_name=InvView
# Dependencies
# check this on https://fabricmc.net/develop/
fabric_version=0.55.2+1.19
trinkets_version=3.4.0
apoli_version=2.5.0
sgui_version=1.1.3+1.19
fabric_version=0.69.1+1.19.3
trinkets_version=3.5.0
apoli_version=e8b66eb
sgui_version=1.2.0+1.19.3
2 changes: 1 addition & 1 deletion src/main/java/us/potatoboy/invview/InvView.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void onInitialize() {
viewNode.addChild(trinketNode);
}
if (isOrigins) {
viewNode.addChild(originNode);
//viewNode.addChild(originNode);
}
});

Expand Down
105 changes: 42 additions & 63 deletions src/main/java/us/potatoboy/invview/ViewCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@
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 me.lucko.fabric.api.permissions.v0.Permissions;
import net.luckperms.api.LuckPermsProvider;
import net.luckperms.api.cacheddata.CachedPermissionData;
import net.luckperms.api.util.Tristate;
import net.minecraft.command.argument.GameProfileArgumentType;
import net.minecraft.inventory.EnderChestInventory;
import net.minecraft.nbt.NbtCompound;
Expand All @@ -29,23 +24,24 @@
import us.potatoboy.invview.gui.SavingPlayerDataGui;
import us.potatoboy.invview.gui.UnmodifiableSlot;

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


public class ViewCommand {
private static MinecraftServer minecraftServer = InvView.getMinecraftServer();

private static final String permProtected = "invview.protected";
private static final String permModify = "invview.can_modify";
private static final String msgProtected = "Requested inventory is protected";

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

boolean canModify = Permissions.check(context.getSource(), "invview.can_modify", true);
boolean canModify = Permissions.check(context.getSource(), permModify, true);

isProtected(requestedPlayer).thenAcceptAsync(isProtected -> {
Permissions.check(requestedPlayer.getUuid(), permProtected, false).thenAcceptAsync(isProtected -> {
if (isProtected) {
context.getSource().sendError(Text.literal("Requested inventory is protected"));
context.getSource().sendError(Text.literal(msgProtected));
} else {
SimpleGui gui = new SavingPlayerDataGui(ScreenHandlerType.GENERIC_9X5, player, requestedPlayer);
gui.setTitle(requestedPlayer.getName());
Expand All @@ -65,11 +61,11 @@ public static int eChest(CommandContext<ServerCommandSource> context) throws Com
ServerPlayerEntity requestedPlayer = getRequestedPlayer(context);
EnderChestInventory requestedEchest = requestedPlayer.getEnderChestInventory();

boolean canModify = Permissions.check(context.getSource(), "invview.can_modify", true);
boolean canModify = Permissions.check(context.getSource(), permModify, true);

isProtected(requestedPlayer).thenAcceptAsync(isProtected -> {
Permissions.check(requestedPlayer.getUuid(), permProtected, false).thenAcceptAsync(isProtected -> {
if (isProtected) {
context.getSource().sendError(Text.literal("Requested inventory is protected"));
context.getSource().sendError(Text.literal(msgProtected));
} else {
SimpleGui gui = new SavingPlayerDataGui(ScreenHandlerType.GENERIC_9X3, player, requestedPlayer);
gui.setTitle(requestedPlayer.getName());
Expand All @@ -89,11 +85,11 @@ public static int trinkets(CommandContext<ServerCommandSource> context) throws C
ServerPlayerEntity requestedPlayer = getRequestedPlayer(context);
TrinketComponent requestedComponent = TrinketsApi.getTrinketComponent(requestedPlayer).get();

boolean canModify = Permissions.check(context.getSource(), "invview.can_modify", true);
boolean canModify = Permissions.check(context.getSource(), permModify, true);

isProtected(requestedPlayer).thenAcceptAsync(isProtected -> {
Permissions.check(requestedPlayer.getUuid(), permProtected, false).thenAcceptAsync(isProtected -> {
if (isProtected) {
context.getSource().sendError(Text.literal("Requested inventory is protected"));
context.getSource().sendError(Text.literal(msgProtected));
} else {
SimpleGui gui = new SavingPlayerDataGui(ScreenHandlerType.GENERIC_9X2, player, requestedPlayer);
gui.setTitle(requestedPlayer.getName());
Expand All @@ -115,34 +111,34 @@ public static int trinkets(CommandContext<ServerCommandSource> context) throws C
}

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

boolean canModify = Permissions.check(context.getSource(), "invview.can_modify", true);

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

gui.open();
}
}
});
// ServerPlayerEntity player = context.getSource().getPlayer();
// ServerPlayerEntity requestedPlayer = getRequestedPlayer(context);
//
// boolean canModify = Permissions.check(context.getSource(), permModify, true);
//
// Permissions.check(requestedPlayer.getUuid(), permProtected, false).thenAcceptAsync(isProtected -> {
// if (isProtected) {
// context.getSource().sendError(Text.literal(msgProtected));
// } else {
// List<InventoryPower> inventories = PowerHolderComponent.getPowers(requestedPlayer,
// InventoryPower.class);
// if (inventories.isEmpty()) {
// context.getSource().sendError(Text.literal("Requested player has no inventory power"));
// } else {
// SimpleGui gui = new SavingPlayerDataGui(ScreenHandlerType.GENERIC_9X5, player, requestedPlayer);
// gui.setTitle(requestedPlayer.getName());
// int index = 0;
// for (InventoryPower inventory : inventories) {
// for (int i = 0; i < inventory.size(); i++) {
// gui.setSlotRedirect(index, canModify ? new Slot(inventory, i, 0, 0) : new UnmodifiableSlot(inventory, i));
// index += 1;
// }
// }
//
// gui.open();
// }
// }
// });

return 1;
}
Expand All @@ -153,7 +149,7 @@ private static ServerPlayerEntity getRequestedPlayer(CommandContext<ServerComman
ServerPlayerEntity requestedPlayer = minecraftServer.getPlayerManager().getPlayer(requestedProfile.getName());

if (requestedPlayer == null) {
requestedPlayer = minecraftServer.getPlayerManager().createPlayer(requestedProfile, null);
requestedPlayer = minecraftServer.getPlayerManager().createPlayer(requestedProfile);
NbtCompound compound = minecraftServer.getPlayerManager().loadPlayerData(requestedPlayer);
if (compound != null) {
ServerWorld world = minecraftServer.getWorld(
Expand All @@ -168,21 +164,4 @@ private static ServerPlayerEntity getRequestedPlayer(CommandContext<ServerComman

return requestedPlayer;
}

private static CompletableFuture<Boolean> isProtected(ServerPlayerEntity playerEntity) {
if (!InvView.isLuckPerms)
return CompletableFuture.completedFuture(false);

return LuckPermsProvider.get().getUserManager().loadUser(playerEntity.getUuid())
.thenApplyAsync(user -> {
CachedPermissionData permissionData = user.getCachedData()
.getPermissionData(user.getQueryOptions());
Tristate tristate = permissionData.checkPermission("invview.protected");
if (tristate.equals(Tristate.UNDEFINED)) {
return false;
}

return tristate.asBoolean();
});
}
}

0 comments on commit 04cd4bd

Please sign in to comment.