Skip to content

Commit

Permalink
fix: repeated permission checker fix and other small durability/wrap …
Browse files Browse the repository at this point in the history
…ownership stuff

Signed-off-by: Skyslycer <[email protected]>
  • Loading branch information
Skyslycer committed Dec 19, 2023
1 parent 9dbad7b commit d341531
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class PermissionUtil {
* @param player The player
* @return If the player has permission to use the wrap on the item
*/
static boolean hasPermission(HMCWraps plugin, Wrap wrap, ItemStack item, Player player) {
public static boolean hasPermission(HMCWraps plugin, Wrap wrap, ItemStack item, Player player) {
var wrapper = plugin.getWrapper();
if (wrapper.isPhysical(item) && plugin.getConfiguration().getPermissions().isCheckPermissionPhysical() && !wrap.hasPermission(player)
&& !wrapper.isOwningPlayer(item, player)) {
Expand Down Expand Up @@ -48,7 +48,8 @@ public static ItemStack hasPermission(HMCWraps plugin, ItemStack item, Player pl
return null;
}
if (!hasPermission(plugin, wrap, item, player)) {
return plugin.getWrapper().removeWrap(item, player, plugin.getConfiguration().getPermissions().isPermissionPhysical());
return plugin.getWrapper().removeWrap(item, player, plugin.getConfiguration().getPermissions().isPermissionPhysical()
&& (wrap.getPhysical() != null && wrap.getPhysical().isKeepAfterUnwrap()));
}
return null;
}
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/de/skyslycer/hmcwraps/HMCWrapsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,20 @@ private void startCheckTask() {
if (item == null || item.getType().isAir()) {
continue;
}
var updatedItem = PermissionUtil.check(this, player, item);
if (updatedItem.equals(item)) {
var wrap = getWrapper().getWrap(item);
if (wrap == null) {
continue;
}
int finalI = i; // this isn't fun
Bukkit.getScheduler().runTask(this, () -> player.getInventory().setItem(finalI, updatedItem));
if (!PermissionUtil.hasPermission(this, wrap, item, player)) {
int finalI = i; // ;(
Bukkit.getScheduler().runTask(this, () -> {
var newItem = getWrapper().removeWrap(item, player, getConfiguration().getPermissions().isPermissionPhysical()
&& (wrap.getPhysical() != null && wrap.getPhysical().isKeepAfterUnwrap()));
player.getInventory().setItem(finalI, newItem);
});
}
}
}), 0L, config.getPermissions().getInventoryCheckInterval() < 1 ? 10L : config.getPermissions().getInventoryCheckInterval() * 20L * 60L);
}), 0L, config.getPermissions().getInventoryCheckInterval() < 1 ? 10L * 20 * 60 : config.getPermissions().getInventoryCheckInterval() * 20L * 60L);
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/de/skyslycer/hmcwraps/wrap/WrapperImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ private ItemStack setWrapPrivate(@Nullable Wrap wrap, ItemStack item, boolean ph
originalModelId = meta.getCustomModelData();
}
meta.getPersistentDataContainer().set(wrapIdKey, PersistentDataType.STRING, wrap == null ? "-" : wrap.getUuid());
meta.getPersistentDataContainer().remove(playerKey);
meta.setCustomModelData(wrap == null ? originalData.modelId() : wrap.getModelId());
if (wrap != null) {
if (currentWrap != null && originalData.material() != null && !originalData.material().isBlank()) {
Expand Down Expand Up @@ -153,7 +154,7 @@ private ItemStack setWrapPrivate(@Nullable Wrap wrap, ItemStack item, boolean ph
var newMeta = ((Damageable) editing.getItemMeta());
newMeta.setDamage(newDurability - (int) modelDurability);
newMeta.getPersistentDataContainer().set(fakeDurabilityKey, PersistentDataType.INTEGER, currentDurability);
newMeta.getPersistentDataContainer().set(fakeMaxDurabilityKey, PersistentDataType.INTEGER, newDurability);
newMeta.getPersistentDataContainer().set(fakeMaxDurabilityKey, PersistentDataType.INTEGER, (int) maxDurability);
editing.setItemMeta(newMeta);
originalMaterial = temp;
changedDurability = true;
Expand Down

0 comments on commit d341531

Please sign in to comment.