Skip to content

Commit 9956098

Browse files
committed
Fix @2212
Added per-item-transaction-permissions and enchant-sign-restrictions to config file. When true, it requires users to have specific commands to enchant or to buy and sell. Enchant sign tweaked a bit to make it auto adjust.
1 parent c7cc1b4 commit 9956098

File tree

9 files changed

+55
-2
lines changed

9 files changed

+55
-2
lines changed

Essentials/src/main/java/com/earth2me/essentials/ISettings.java

+4
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ public interface ISettings extends IConf {
193193

194194
boolean useBukkitPermissions();
195195

196+
boolean perItemTransactionPermissions();
197+
196198
boolean addPrefixSuffix();
197199

198200
boolean disablePrefix();
@@ -355,6 +357,8 @@ public interface ISettings extends IConf {
355357

356358
List<EssentialsSign> getUnprotectedSignNames();
357359

360+
boolean isEnchantSignRestricted();
361+
358362
boolean isKitAutoEquip();
359363

360364
boolean isPastebinCreateKit();

Essentials/src/main/java/com/earth2me/essentials/Settings.java

+10
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,16 @@ public boolean useBukkitPermissions() {
10911091
return config.getBoolean("use-bukkit-permissions", false);
10921092
}
10931093

1094+
@Override
1095+
public boolean perItemTransactionPermissions() {
1096+
return config.getBoolean("per-item-transaction-permissions", false);
1097+
}
1098+
1099+
@Override
1100+
public boolean isEnchantSignRestricted(){
1101+
return config.getBoolean("enchant-sign-restrictions", false);
1102+
}
1103+
10941104
private boolean _addPrefixSuffix() {
10951105
return config.getBoolean("add-prefix-suffix", false);
10961106
}

Essentials/src/main/java/com/earth2me/essentials/commands/Commandsell.java

+7
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ public void run(final Server server, final User user, final String commandLabel,
5656
}
5757
}
5858
try {
59+
if (!user.isAuthorized("essentials.item.sell."+ stack.getType()) && ess.getSettings().perItemTransactionPermissions()){
60+
if (isBulk) {
61+
notSold.add(stack);
62+
continue;
63+
}
64+
throw new TranslatableException("sellSpecificItemPermission", stack.getType().toString());
65+
}
5966
if (stack.getAmount() > 0) {
6067
totalWorth = totalWorth.add(sellItem(user, stack, args, isBulk));
6168
stack = stack.clone();

Essentials/src/main/java/com/earth2me/essentials/signs/SignBuy.java

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ protected boolean onSignInteract(final ISign sign, final User player, final Stri
2626
Trade items = getTrade(sign, 1, 2, player, ess);
2727
Trade charge = getTrade(sign, 3, ess);
2828

29+
if (!player.isAuthorized("essentials.item.buy."+ items.getItemStack().getType()) && ess.getSettings().perItemTransactionPermissions()){
30+
throw new SignException("buySpecificItemPermission", items.getItemStack().getType());
31+
}
2932
// Check if the player is trying to buy in bulk.
3033
if (ess.getSettings().isAllowBulkBuySell() && player.getBase().isSneaking()) {
3134
final ItemStack heldItem = player.getItemInHand();

Essentials/src/main/java/com/earth2me/essentials/signs/SignEnchant.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
import com.earth2me.essentials.Trade;
66
import com.earth2me.essentials.User;
77
import com.earth2me.essentials.craftbukkit.Inventories;
8+
import com.earth2me.essentials.utils.NumberUtil;
89
import net.ess3.api.IEssentials;
910
import net.ess3.provider.MaterialTagProvider;
1011
import org.bukkit.enchantments.Enchantment;
1112
import org.bukkit.inventory.ItemStack;
1213

14+
import java.math.BigDecimal;
1315
import java.util.Locale;
1416

1517
public class SignEnchant extends EssentialsSign {
@@ -46,8 +48,8 @@ protected boolean onSignCreate(final ISign sign, final User player, final String
4648
final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments() && player.isAuthorized("essentials.enchantments.allowunsafe") && player.isAuthorized("essentials.signs.enchant.allowunsafe");
4749
if (level < 0 || (!allowUnsafe && level > enchantment.getMaxLevel())) {
4850
level = enchantment.getMaxLevel();
49-
sign.setLine(2, enchantLevel[0] + ":" + level);
5051
}
52+
sign.setLine(2, enchantLevel[0].toLowerCase().replaceFirst("^[a-zA-Z]", enchantLevel[0].substring(0,1).toUpperCase()) + ":" + level);
5153
try {
5254
if (stack != null) {
5355
if (allowUnsafe) {
@@ -59,7 +61,11 @@ protected boolean onSignCreate(final ISign sign, final User player, final String
5961
} catch (final Throwable ex) {
6062
throw new SignException(ex, "errorWithMessage", ex.getMessage());
6163
}
62-
getTrade(sign, 3, ess);
64+
final Trade trade = getTrade(sign, 3, 0, ess);
65+
final BigDecimal money = trade.getMoney();
66+
if (money != null) {
67+
sign.setLine(3, NumberUtil.shortCurrency(money, ess));
68+
}
6369
return true;
6470
}
6571

@@ -76,6 +82,11 @@ protected boolean onSignInteract(final ISign sign, final User player, final Stri
7682
if (enchantment == null) {
7783
throw new SignException("enchantmentNotFound");
7884
}
85+
86+
if (!player.isAuthorized("essentials.enchantments."+enchantment.getKey().getKey()) && ess.getSettings().isEnchantSignRestricted()){
87+
throw new SignException("enchantmentPerm", enchantment.getKey().getKey());
88+
}
89+
7990
int level = 1;
8091
if (enchantLevel.length > 1) {
8192
try {

Essentials/src/main/java/com/earth2me/essentials/signs/SignFree.java

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ protected boolean onSignInteract(final ISign sign, final User player, final Stri
3232
itemStack = getItemMeta(player.getSource(), itemStack, sign.getLine(2), ess);
3333
final ItemStack item = getItemMeta(player.getSource(), itemStack, sign.getLine(3), ess);
3434

35+
if (!player.isAuthorized("essentials.item.free."+ item.getType()) && ess.getSettings().perItemTransactionPermissions()){
36+
throw new SignException("freeSpecificItemPermission", item.getType().toString());
37+
}
38+
3539
if (item.getType() == Material.AIR) {
3640
throw new SignException("cantSpawnItem", "Air");
3741
}

Essentials/src/main/java/com/earth2me/essentials/signs/SignSell.java

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ protected boolean onSignInteract(final ISign sign, final User player, final Stri
2727
Trade charge = getTrade(sign, 1, 2, player, ess);
2828
Trade money = getTrade(sign, 3, ess);
2929

30+
if (!player.isAuthorized("essentials.item.sell."+ charge.getItemStack().getType()) && ess.getSettings().perItemTransactionPermissions()){
31+
throw new SignException("sellSpecificItemPermission", charge.getItemStack().getType().toString());
32+
}
33+
3034
// Check if the player is trying to sell in bulk.
3135
if (ess.getSettings().isAllowBulkBuySell() && player.getBase().isSneaking()) {
3236
final ItemStack heldItem = player.getItemInHand();

Essentials/src/main/resources/config.yml

+7
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,10 @@ player-commands:
334334
# Default is true.
335335
use-bukkit-permissions: true
336336

337+
# When set to true, a player will need the permission essentials.item.<buy|sell|free>.[itemName] in order to buy and
338+
# sell items by command and sign.
339+
per-item-transaction-permissions: false
340+
337341
# When this option is enabled, one-time use kits (ie. delay < 0) will be
338342
# removed from the /kit list when a player can no longer use it
339343
skip-used-one-time-kits-from-kit-list: false
@@ -408,6 +412,9 @@ allow-old-id-signs: false
408412
unprotected-sign-names:
409413
#- kit
410414

415+
# When set to true, users will also need the permission essentials.enchantments.[enchantmentName] to use an enchantment sign.
416+
enchant-sign-restrictions: false
417+
411418
# Backup runs a custom batch/bash command at a specified interval.
412419
# The server will save the world before executing the backup command, and disable
413420
# saving during the backup to prevent world corruption or other conflicts.

Essentials/src/main/resources/messages_en.properties

+3
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ burnCommandDescription=Set a player on fire.
9797
burnCommandUsage=/<command> <player> <seconds>
9898
burnCommandUsage1Description=Sets the specified player on fire for the specified amount of seconds
9999
burnMsg=<primary>You set<secondary> {0} <primary>on fire for<secondary> {1} seconds<primary>.
100+
buySpecificItemPermission=<primary>You do not have permission to buy <Secondary>{0}
100101
cannotSellNamedItem=<primary>You are not allowed to sell named items.
101102
cannotSellTheseNamedItems=<primary>You are not allowed to sell these named items\: <dark_red>{0}
102103
cannotStackMob=<dark_red>You do not have permission to stack multiple mobs.
@@ -375,6 +376,7 @@ flyCommandUsage1Description=Toggles fly for yourself or another player if specif
375376
flying=flying
376377
flyMode=<primary>Set fly mode<secondary> {0} <primary>for {1}<primary>.
377378
foreverAlone=<dark_red>You have nobody to whom you can reply.
379+
freeSpecificItemPermission=<primary>You do not have permission to accept the free offer of <Secondary>{0}
378380
fullStack=<dark_red>You already have a full stack.
379381
fullStackDefault=<primary>Your stack has been set to its default size, <secondary>{0}<primary>.
380382
fullStackDefaultOversize=<primary>Your stack has been set to its maximum size, <secondary>{0}<primary>.
@@ -980,6 +982,7 @@ sellCommandUsage3Description=Sells all possible items in your inventory
980982
sellCommandUsage4=/<command> blocks [amount]
981983
sellCommandUsage4Description=Sells all (or the given amount, if specified) of blocks in your inventory
982984
sellHandPermission=<primary>You do not have permission to hand sell.
985+
sellSpecificItemPermission=<primary>You do not have permission to sell <Secondary>{0}
983986
serverFull=Server is full\!
984987
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.
985988
serverTotal=<primary>Server Total\:<secondary> {0}

0 commit comments

Comments
 (0)