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

Adds the ability to have per item transaction permissions & applies enchantment permissions to signs #5976

Open
wants to merge 2 commits into
base: 2.x
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 @@ -196,6 +196,8 @@ public interface ISettings extends IConf {

boolean useBukkitPermissions();

boolean perItemTransactionPermissions();

boolean addPrefixSuffix();

boolean disablePrefix();
Expand Down Expand Up @@ -358,6 +360,8 @@ public interface ISettings extends IConf {

List<EssentialsSign> getUnprotectedSignNames();

boolean isEnchantSignRestricted();

boolean isKitAutoEquip();

boolean isPastebinCreateKit();
Expand Down
10 changes: 10 additions & 0 deletions Essentials/src/main/java/com/earth2me/essentials/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,16 @@ public boolean useBukkitPermissions() {
return config.getBoolean("use-bukkit-permissions", false);
}

@Override
public boolean perItemTransactionPermissions() {
return config.getBoolean("per-item-transaction-permissions", false);
}

@Override
public boolean isEnchantSignRestricted(){
return config.getBoolean("enchant-sign-restrictions", false);
}

private boolean _addPrefixSuffix() {
return config.getBoolean("add-prefix-suffix", false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ public void run(final Server server, final User user, final String commandLabel,
}
}
try {
if (!user.isAuthorized("essentials.item.sell."+ stack.getType()) && ess.getSettings().perItemTransactionPermissions()){
if (isBulk) {
notSold.add(stack);
continue;
}
throw new TranslatableException("sellSpecificItemPermission", stack.getType().toString());
}
if (stack.getAmount() > 0) {
totalWorth = totalWorth.add(sellItem(user, stack, args, isBulk));
stack = stack.clone();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ protected boolean onSignInteract(final ISign sign, final User player, final Stri
Trade items = getTrade(sign, 1, 2, player, ess);
Trade charge = getTrade(sign, 3, ess);

if (!player.isAuthorized("essentials.item.buy."+ items.getItemStack().getType()) && ess.getSettings().perItemTransactionPermissions()){
throw new SignException("buySpecificItemPermission", items.getItemStack().getType());
}
// Check if the player is trying to buy in bulk.
if (ess.getSettings().isAllowBulkBuySell() && player.getBase().isSneaking()) {
final ItemStack heldItem = player.getItemInHand();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.User;
import com.earth2me.essentials.craftbukkit.Inventories;
import com.earth2me.essentials.utils.NumberUtil;
import net.ess3.api.IEssentials;
import net.ess3.provider.MaterialTagProvider;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;

import java.math.BigDecimal;
import java.util.Locale;

public class SignEnchant extends EssentialsSign {
Expand Down Expand Up @@ -46,8 +48,8 @@ protected boolean onSignCreate(final ISign sign, final User player, final String
final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments() && player.isAuthorized("essentials.enchantments.allowunsafe") && player.isAuthorized("essentials.signs.enchant.allowunsafe");
if (level < 0 || (!allowUnsafe && level > enchantment.getMaxLevel())) {
level = enchantment.getMaxLevel();
sign.setLine(2, enchantLevel[0] + ":" + level);
}
sign.setLine(2, enchantLevel[0].toLowerCase().replaceFirst("^[a-zA-Z]", enchantLevel[0].substring(0,1).toUpperCase()) + ":" + level);
try {
if (stack != null) {
if (allowUnsafe) {
Expand All @@ -59,7 +61,11 @@ protected boolean onSignCreate(final ISign sign, final User player, final String
} catch (final Throwable ex) {
throw new SignException(ex, "errorWithMessage", ex.getMessage());
}
getTrade(sign, 3, ess);
final Trade trade = getTrade(sign, 3, 0, ess);
final BigDecimal money = trade.getMoney();
if (money != null) {
sign.setLine(3, NumberUtil.shortCurrency(money, ess));
}
return true;
}

Expand All @@ -76,6 +82,11 @@ protected boolean onSignInteract(final ISign sign, final User player, final Stri
if (enchantment == null) {
throw new SignException("enchantmentNotFound");
}

if (!player.isAuthorized("essentials.enchantments."+enchantment.getKey().getKey()) && ess.getSettings().isEnchantSignRestricted()){
throw new SignException("enchantmentPerm", enchantment.getKey().getKey());
}

int level = 1;
if (enchantLevel.length > 1) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ protected boolean onSignInteract(final ISign sign, final User player, final Stri
itemStack = getItemMeta(player.getSource(), itemStack, sign.getLine(2), ess);
final ItemStack item = getItemMeta(player.getSource(), itemStack, sign.getLine(3), ess);

if (!player.isAuthorized("essentials.item.free."+ item.getType()) && ess.getSettings().perItemTransactionPermissions()){
throw new SignException("freeSpecificItemPermission", item.getType().toString());
}

if (item.getType() == Material.AIR) {
throw new SignException("cantSpawnItem", "Air");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ protected boolean onSignInteract(final ISign sign, final User player, final Stri
Trade charge = getTrade(sign, 1, 2, player, ess);
Trade money = getTrade(sign, 3, ess);

if (!player.isAuthorized("essentials.item.sell."+ charge.getItemStack().getType()) && ess.getSettings().perItemTransactionPermissions()){
throw new SignException("sellSpecificItemPermission", charge.getItemStack().getType().toString());
}

// Check if the player is trying to sell in bulk.
if (ess.getSettings().isAllowBulkBuySell() && player.getBase().isSneaking()) {
final ItemStack heldItem = player.getItemInHand();
Expand Down
7 changes: 7 additions & 0 deletions Essentials/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,10 @@ player-commands:
# Default is true.
use-bukkit-permissions: true

# When set to true, a player will need the permission essentials.item.<buy|sell|free>.[itemName] in order to buy and
# sell items by command and sign.
per-item-transaction-permissions: false

# When this option is enabled, one-time use kits (ie. delay < 0) will be
# removed from the /kit list when a player can no longer use it
skip-used-one-time-kits-from-kit-list: false
Expand Down Expand Up @@ -408,6 +412,9 @@ allow-old-id-signs: false
unprotected-sign-names:
#- kit

# When set to true, users will also need the permission essentials.enchantments.[enchantmentName] to use an enchantment sign.
enchant-sign-restrictions: false

# Backup runs a custom batch/bash command at a specified interval.
# The server will save the world before executing the backup command, and disable
# saving during the backup to prevent world corruption or other conflicts.
Expand Down
3 changes: 3 additions & 0 deletions Essentials/src/main/resources/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ burnCommandDescription=Set a player on fire.
burnCommandUsage=/<command> <player> <seconds>
burnCommandUsage1Description=Sets the specified player on fire for the specified amount of seconds
burnMsg=<primary>You set<secondary> {0} <primary>on fire for<secondary> {1} seconds<primary>.
buySpecificItemPermission=<primary>You do not have permission to buy <Secondary>{0}
cannotSellNamedItem=<primary>You are not allowed to sell named items.
cannotSellTheseNamedItems=<primary>You are not allowed to sell these named items\: <dark_red>{0}
cannotStackMob=<dark_red>You do not have permission to stack multiple mobs.
Expand Down Expand Up @@ -375,6 +376,7 @@ flyCommandUsage1Description=Toggles fly for yourself or another player if specif
flying=flying
flyMode=<primary>Set fly mode<secondary> {0} <primary>for {1}<primary>.
foreverAlone=<dark_red>You have nobody to whom you can reply.
freeSpecificItemPermission=<primary>You do not have permission to accept the free offer of <Secondary>{0}
fullStack=<dark_red>You already have a full stack.
fullStackDefault=<primary>Your stack has been set to its default size, <secondary>{0}<primary>.
fullStackDefaultOversize=<primary>Your stack has been set to its maximum size, <secondary>{0}<primary>.
Expand Down Expand Up @@ -980,6 +982,7 @@ sellCommandUsage3Description=Sells all possible items in your inventory
sellCommandUsage4=/<command> blocks [amount]
sellCommandUsage4Description=Sells all (or the given amount, if specified) of blocks in your inventory
sellHandPermission=<primary>You do not have permission to hand sell.
sellSpecificItemPermission=<primary>You do not have permission to sell <Secondary>{0}
serverFull=Server is full\!
serverReloading=There''s a good chance you''re reloading your server right now. If that''s the case, why do you hate yourself? Expect no support from the EssentialsX team when using /reload.
serverTotal=<primary>Server Total\:<secondary> {0}
Expand Down