Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add toggle for simplified hopper logic #322

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public final class DefaultConfig extends BlockProtConfig {

private final List<String> excludedWorlds;

private final boolean simpleHopperProtection;

/**
* Create a new default configuration from given {@code config}.
*
Expand All @@ -98,6 +100,7 @@ public DefaultConfig(@NotNull final FileConfiguration config) {
super(config);

this.excludedWorlds = config.getStringList("excluded_worlds");
this.simpleHopperProtection = config.getBoolean("simple_hopper_protection");
this.removeBlockDefaults();
this.loadBlocksFromConfig();
}
Expand Down Expand Up @@ -404,4 +407,8 @@ public boolean isLockableShulkerBox(Material type) {
public boolean isLockableInventory(InventoryType type) {
return lockableInventories.contains(type);
}

public boolean isSimpleHopperProtection() {
return simpleHopperProtection;
}
Comment on lines +411 to +413
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you perhaps have any information on the performance of config.getX functions, given that I usually just call them instead of caching the variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Config gets stored in memory when the load is called, so from there everything is memory only anyways - moving over to having the bool in a dedicated variable might be a bit of an improvement but certainly not by much

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public void onItemMove(InventoryMoveItemEvent event) {
if (source != null && BlockProt.getDefaultConfig().isLockable(source.getType())) {
BlockNBTHandler sourceHandler = new BlockNBTHandler(source);
if (sourceHandler.isProtected()) {
// Check if simple hopper protection is enabled, if so we can skip the rest
if (BlockProt.getDefaultConfig().isSimpleHopperProtection()) {
event.setCancelled(true);
return;
}
// The source chest is owned by someone. Check if the hopper block is also owned by
// the same player and if so, allow this event to happen, regardless of the hopper
// protection.
Expand Down
7 changes: 7 additions & 0 deletions spigot/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ notify_op_of_updates: false
# placed block, if the player has lock on place enabled.
redstone_disallowed_by_default: false

# Toggle simple hopper protection, meaning any protected chest
# can not be interacted with by any hopper. Should significantly
# improve performance in some cases.
# WARNING: Will fully disable hoppers moving items from ANY
# protected container
simple_hopper_protection: false

# A list of world names the plugin should not be usable in.
# The case of each name is ignored.
# Useful for a mining-only world where a block should not be
Expand Down