Skip to content

Commit

Permalink
Fix bug re-creating keys on your own shops
Browse files Browse the repository at this point in the history
  • Loading branch information
leddy231 committed Jan 18, 2022
1 parent 9a60b26 commit 84b5971
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx1G


# Mod Properties
mod_version = 1.2.0
mod_version = 1.2.1
maven_group = se.leddy231
archives_base_name = leddy231-player-trading
minecraft_version=1.18.1
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions src/main/java/se/leddy231/playertrading/ShopKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public static void makeIntoKeyForPlayer(ItemStack stack, PlayerEntity player) {
stack.setCustomName(new LiteralText(name + "'s Shop key"));
}

public static boolean isKey(ItemStack stack) {
return stack.isOf(Items.GOLD_INGOT) && stack.getOrCreateNbt().contains(KEY_TAG);
}

public static boolean isKeyForUUID(ItemStack stack, UUID uuid) {
String key_uuid = stack.getOrCreateNbt().getString(KEY_TAG);
return stack.isOf(Items.GOLD_INGOT) && key_uuid.equals(uuid.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ private void onUse(BlockState state, World world, BlockPos pos, PlayerEntity pla
IAugmentedBarrelEntity barrelEntity = (IAugmentedBarrelEntity) (Object) entity;

if (barrelEntity.getType() != BarrelType.NONE) {
ItemStack usedItem = player.getMainHandStack();
boolean isOwner = barrelEntity.getOwner().equals(player.getUuid());
boolean makeKey = isOwner && player.getMainHandStack().isOf(Items.GOLD_INGOT);
boolean makeKey = isOwner && usedItem.isOf(Items.GOLD_INGOT) && !ShopKey.isKey(usedItem);

if (makeKey) {
ShopKey.makeIntoKeyForPlayer(player.getMainHandStack(), player);
ShopKey.makeIntoKeyForPlayer(usedItem, player);
ci.setReturnValue(ActionResult.SUCCESS);
return;
}
Expand All @@ -53,8 +54,8 @@ private void onUse(BlockState state, World world, BlockPos pos, PlayerEntity pla
}

boolean ownerBypass = isOwner && !player.isSneaking();
boolean keyBypass = ShopKey.isKeyForUUID(player.getMainHandStack(), barrelEntity.getOwner());
boolean opDebugBypass = player.hasPermissionLevel(4) && ItemStack.areNbtEqual(player.getMainHandStack(), DebugStickCommand.STICK);
boolean keyBypass = ShopKey.isKeyForUUID(usedItem, barrelEntity.getOwner());
boolean opDebugBypass = player.hasPermissionLevel(4) && ItemStack.areNbtEqual(usedItem, DebugStickCommand.STICK);
if (ownerBypass || keyBypass || opDebugBypass) {
//Close the trade window if a customer is using the shop
shop.getShopMerchant().forceCloseShop();
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "leddy231-playertrading",
"version": "1.2.0",
"version": "1.2.1",

"name": "Player Trading",
"description": "Allows player-to-player trading posts / shops from just barrels and a sign!",
Expand Down

0 comments on commit 84b5971

Please sign in to comment.