Changed: Creative mode players are ignored when checking for entity interactions with the shop creation item.

Also, the permission check is performed first now since we expect this check to be quite fast.
master
blablubbabc 2020-06-25 18:50:38 +02:00
parent c68be20af5
commit da290f9f1a
2 changed files with 18 additions and 14 deletions

View File

@ -9,7 +9,7 @@ Date format: (YYYY-MM-DD)
* Changed: When checking if the player is able to bypass the restriction of not being able to trade with shops while their owner is online, we only check for the bypass permission now after checking if the shop owner is actually online currently.
* Added: The variant of rabbit shopkeepers can now be changed. Any existing rabbit shopkeepers will use the brown variant (the default). This also resolves an issue with the rabbit type randomly changing whenever the shopkeeper is respawned.
* Added: Added a header comment to the top of the save.yml file mentioning the risk of manually editing this file while the server is still running or without making a backup first.
* Fixed: If regular item usage is disabled we also prevent any kind of entity interaction now while holding the shop creation item in hand. Players with the 'shopkeeper.bypass' permission are exempt from this restriction.
* Fixed: If regular item usage is disabled we also prevent any kind of entity interaction now while holding the shop creation item in hand. Players in creative mode or with the 'shopkeeper.bypass' permission are exempt from this restriction.
* Fixed: Checking the WorldGuard allow-shop flag now takes into account the player for whom the flag is being queried.
* Fixed: The returned shop creation item would get dropped twice under certain conditions.
* Fixed: The shop creation item is now also returned if a player deletes his own shops via command.

View File

@ -228,19 +228,23 @@ class CreateListener implements Listener {
private void handleEntityInteraction(PlayerInteractEntityEvent event) {
if (!Settings.preventShopCreationItemRegularUsage) return;
Player player = event.getPlayer();
if (player.getGameMode() == GameMode.CREATIVE) return; // creative mode players are ignored
// We check the permission first since this check is fast:
if (PermissionUtils.hasPermission(player, ShopkeepersPlugin.BYPASS_PERMISSION)) return;
ItemStack itemInHand = ItemUtils.getItem(player.getInventory(), event.getHand());
if (Settings.isShopCreationItem(itemInHand) && !PermissionUtils.hasPermission(player, ShopkeepersPlugin.BYPASS_PERMISSION)) {
// TODO Only prevent the entity interaction if the item actually has a special entity interaction behavior.
// The interaction result may also depend on the interacted entity. However, there is no Bukkit API yet to
// check for this.
Log.debug(() -> {
if (event instanceof PlayerInteractAtEntityEvent) {
return "Preventing interaction at entity with shop creation item for player " + TextUtils.getPlayerString(player);
} else {
return "Preventing entity interaction with shop creation item for player " + TextUtils.getPlayerString(player);
}
});
event.setCancelled(true);
}
if (!Settings.isShopCreationItem(itemInHand)) return;
// Prevent the entity interaction:
// TODO Only prevent the entity interaction if the item actually has a special entity interaction behavior.
// The interaction result may also depend on the interacted entity. However, there is no Bukkit API yet to
// check for this.
Log.debug(() -> {
if (event instanceof PlayerInteractAtEntityEvent) {
return "Preventing interaction at entity with shop creation item for player " + TextUtils.getPlayerString(player);
} else {
return "Preventing entity interaction with shop creation item for player " + TextUtils.getPlayerString(player);
}
});
event.setCancelled(true);
}
}