Skip to content

Commit

Permalink
Merge branch 'villiageWalkToggle' of https://github.com/FordFriedel/vane
Browse files Browse the repository at this point in the history
 into villiageWalkToggle
  • Loading branch information
FordFriedel committed Dec 27, 2023
2 parents dc555aa + 80c5c86 commit 785b73d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault;
import org.jetbrains.annotations.NotNull;
import org.oddlama.vane.annotation.config.ConfigBoolean;
import org.oddlama.vane.annotation.config.ConfigInt;
Expand All @@ -31,8 +33,23 @@ public class ItemFinder extends Listener<Trifles> {
@ConfigBoolean(def = true, desc = "Also search entities such as players, mobs, minecarts, ...")
public boolean config_search_entities;

@ConfigBoolean(def = false, desc = "Only allow players to use the shift+rightclick shortcut when they have the shortcut permission `vane.trifles.use_item_find_shortcut`.")
public boolean config_require_permission;

// This permission allows players to use the shift+rightclick.
public final Permission use_item_find_shortcut_permission;

public ItemFinder(Context<Trifles> context) {
super(context.group("item_finder", "Enables players to search for items in nearby containers by either middle-clicking a similar item in their inventory or by using the `/finditem <item>` command."));
super(context.group("item_finder", "Enables players to search for items in nearby containers by either shift-right-clicking a similar item in their inventory or by using the `/finditem <item>` command."));

// Register admin permission
use_item_find_shortcut_permission =
new Permission(
"vane." + get_module().get_name() + ".use_item_find_shortcut",
"Allows a player to use shfit+rightclick to search for items if the require_permission config is set",
PermissionDefault.FALSE
);
get_module().register_permission(use_item_find_shortcut_permission);
}

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
Expand All @@ -41,6 +58,10 @@ public void on_player_click_inventory(final InventoryClickEvent event) {
return;
}

if (config_require_permission && !player.hasPermission(use_item_find_shortcut_permission)) {
return;
}

final var item = event.getCurrentItem();
if (item == null || item.getType() == Material.AIR) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,14 @@ public Location teleport_location(final ItemStack scroll, Player player, boolean
}

final var lodestone_location = get_lodestone_location(scroll);
final var lodestone = lodestone_location == null ? null : lodestone_location.getBlock();
var lodestone = lodestone_location == null ? null : lodestone_location.getBlock();

if (imminent_teleport) {
if (lodestone_location == null) {
lang_teleport_no_bound_lodestone.send_action_bar(player);
} else if (lodestone.getType() != Material.LODESTONE) {
lang_teleport_missing_lodestone.send_action_bar(player);
lodestone = null;
}
}

Expand Down

0 comments on commit 785b73d

Please sign in to comment.