diff --git a/pom.xml b/pom.xml
index 5a3885a2..a2a7f48a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,7 +31,7 @@
org.shanerx
tradeshop
- 2.3.2-STABLE
+ 2.4.0-DEV
jar
TradeShop
https://tradeshop.github.io/
diff --git a/src/main/java/org/shanerx/tradeshop/commands/CommandCaller.java b/src/main/java/org/shanerx/tradeshop/commands/CommandCaller.java
index 21b8188d..d4611a92 100644
--- a/src/main/java/org/shanerx/tradeshop/commands/CommandCaller.java
+++ b/src/main/java/org/shanerx/tradeshop/commands/CommandCaller.java
@@ -160,6 +160,9 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
case CREATE_ITRADE:
cmdRnnr.createITrade();
break;
+ case TOGGLE_ADMIN:
+ cmdRnnr.toggleAdmin();
+ break;
}
return true;
diff --git a/src/main/java/org/shanerx/tradeshop/commands/CommandPass.java b/src/main/java/org/shanerx/tradeshop/commands/CommandPass.java
index 1ebf34b1..c4131c0a 100644
--- a/src/main/java/org/shanerx/tradeshop/commands/CommandPass.java
+++ b/src/main/java/org/shanerx/tradeshop/commands/CommandPass.java
@@ -28,7 +28,6 @@
import com.google.common.collect.Lists;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
-import org.shanerx.tradeshop.enumys.Message;
import org.shanerx.tradeshop.utils.Utils;
import java.util.ArrayList;
@@ -91,13 +90,4 @@ public boolean hasArgs() {
public void sendMessage(String message) {
getSender().sendMessage((new Utils()).colorize(message));
}
-
- /**
- * Colors and sends the Message to the sender
- *
- * @param message Message to send to the sender
- */
- public void sendMessage(Message message) {
- getSender().sendMessage((new Utils()).colorize(message.getPrefixed()));
- }
}
diff --git a/src/main/java/org/shanerx/tradeshop/commands/CommandRunner.java b/src/main/java/org/shanerx/tradeshop/commands/CommandRunner.java
index 4800fb4a..f189eae5 100644
--- a/src/main/java/org/shanerx/tradeshop/commands/CommandRunner.java
+++ b/src/main/java/org/shanerx/tradeshop/commands/CommandRunner.java
@@ -123,7 +123,7 @@ public void bugs() {
* Sends the sender the setup message
*/
public void setup() {
- command.sendMessage(Message.SETUP_HELP);
+ Message.SETUP_HELP.sendMessage(pSender);
}
/**
@@ -164,7 +164,7 @@ public void listProduct() {
counter++;
}
- command.sendMessage(Message.SHOP_ITEM_LIST.getPrefixed().replaceAll("%type%", "products").replaceAll("%list%", sb.toString()));
+ Message.SHOP_ITEM_LIST.sendMessage(pSender, new Tuple<>("%type%", "products"), new Tuple<>("%list%", sb.toString()));
}
/**
@@ -184,7 +184,7 @@ public void listCost() {
counter++;
}
- command.sendMessage(Message.SHOP_ITEM_LIST.getPrefixed().replaceAll("%type%", "products").replaceAll("%list%", sb.toString()));
+ Message.SHOP_ITEM_LIST.sendMessage(pSender, new Tuple<>("%type%", "costs"), new Tuple<>("%list%", sb.toString()));
}
/**
@@ -201,23 +201,23 @@ public void removeProduct() {
if (isInt(command.getArgAt(1))) {
index = Integer.parseInt(command.getArgAt(1)) - 1;
} else {
- command.sendMessage(Message.INVALID_ARGUMENTS);
+ Message.INVALID_ARGUMENTS.sendMessage(pSender);
return;
}
if (!(shop.getOwner().getUUID().equals(pSender.getUniqueId()) || shop.getManagersUUID().contains(pSender.getUniqueId()))) {
- command.sendMessage(Message.NO_SHOP_PERMISSION);
+ Message.NO_SHOP_PERMISSION.sendMessage(pSender);
return;
}
-
+
PlayerShopChangeEvent changeEvent = new PlayerShopChangeEvent(pSender, shop, ShopChange.REMOVE_PRODUCT, new ObjectHolder(index));
Bukkit.getPluginManager().callEvent(changeEvent);
if (changeEvent.isCancelled()) return;
if (shop.removeProduct(index))
- command.sendMessage(Message.ITEM_REMOVED);
+ Message.ITEM_REMOVED.sendMessage(pSender);
else
- command.sendMessage(Message.ITEM_NOT_REMOVED);
+ Message.ITEM_NOT_REMOVED.sendMessage(pSender);
}
/**
@@ -234,23 +234,23 @@ public void removeCost() {
if (isInt(command.getArgAt(1))) {
index = Integer.parseInt(command.getArgAt(1)) - 1;
} else {
- command.sendMessage(Message.INVALID_ARGUMENTS);
+ Message.INVALID_ARGUMENTS.sendMessage(pSender);
return;
}
if (!(shop.getOwner().getUUID().equals(pSender.getUniqueId()) || shop.getManagersUUID().contains(pSender.getUniqueId()))) {
- command.sendMessage(Message.NO_SHOP_PERMISSION);
+ Message.NO_SHOP_PERMISSION.sendMessage(pSender);
return;
}
-
+
PlayerShopChangeEvent changeEvent = new PlayerShopChangeEvent(pSender, shop, ShopChange.REMOVE_COST, new ObjectHolder(index));
Bukkit.getPluginManager().callEvent(changeEvent);
if (changeEvent.isCancelled()) return;
if (shop.removeCost(index))
- command.sendMessage(Message.ITEM_REMOVED);
+ Message.ITEM_REMOVED.sendMessage(pSender);
else
- command.sendMessage(Message.ITEM_NOT_REMOVED);
+ Message.ITEM_NOT_REMOVED.sendMessage(pSender);
}
/**
@@ -283,7 +283,7 @@ public void setProduct() {
}
if (!(shop.getOwner().getUUID().equals(pSender.getUniqueId()) || shop.getManagersUUID().contains(pSender.getUniqueId()))) {
- command.sendMessage(Message.NO_SHOP_PERMISSION);
+ Message.NO_SHOP_PERMISSION.sendMessage(pSender);
return;
}
@@ -296,17 +296,17 @@ public void setProduct() {
}
if (itemInHand.getType() == Material.AIR) {
- command.sendMessage(Message.HELD_EMPTY);
+ Message.HELD_EMPTY.sendMessage(pSender);
return;
}
if (!isValidType(itemInHand.getType())) {
- command.sendMessage(Message.ILLEGAL_ITEM);
+ Message.ILLEGAL_ITEM.sendMessage(pSender);
return;
}
if (!(shop.getShopType().isITrade() && shop.getInventoryLocation() == null) && itemInHand.getType().toString().endsWith("SHULKER_BOX") && shop.getInventoryLocation().getBlock().getType().toString().endsWith("SHULKER_BOX")) {
- command.sendMessage(Message.NO_SHULKER_COST);
+ Message.NO_SHULKER_COST.sendMessage(pSender);
return;
}
@@ -315,7 +315,7 @@ public void setProduct() {
}
if (Math.ceil((double) itemInHand.getAmount() / (double) itemInHand.getMaxStackSize()) > Setting.MAX_ITEMS_PER_TRADE_SIDE.getInt()) {
- command.sendMessage(Message.TOO_MANY_ITEMS.getPrefixed().replaceAll("%side%", "products"));
+ Message.TOO_MANY_ITEMS.sendMessage(pSender, new Tuple<>("%side%", "products"));
return;
}
@@ -325,7 +325,7 @@ public void setProduct() {
shop.setProduct(itemInHand);
- command.sendMessage(Message.ITEM_ADDED);
+ Message.ITEM_ADDED.sendMessage(pSender);
}
/**
@@ -358,7 +358,7 @@ public void addProduct() {
}
if (!(shop.getOwner().getUUID().equals(pSender.getUniqueId()) || shop.getManagersUUID().contains(pSender.getUniqueId()))) {
- command.sendMessage(Message.NO_SHOP_PERMISSION);
+ Message.NO_SHOP_PERMISSION.sendMessage(pSender);
return;
}
@@ -371,17 +371,17 @@ public void addProduct() {
}
if (itemInHand.getType() == Material.AIR) {
- command.sendMessage(Message.HELD_EMPTY);
+ Message.HELD_EMPTY.sendMessage(pSender);
return;
}
if (!isValidType(itemInHand.getType())) {
- command.sendMessage(Message.ILLEGAL_ITEM);
+ Message.ILLEGAL_ITEM.sendMessage(pSender);
return;
}
if (!(shop.getShopType().isITrade() && shop.getInventoryLocation() == null) && itemInHand.getType().toString().endsWith("SHULKER_BOX") && shop.getInventoryLocation().getBlock().getType().toString().endsWith("SHULKER_BOX")) {
- command.sendMessage(Message.NO_SHULKER_COST);
+ Message.NO_SHULKER_COST.sendMessage(pSender);
return;
}
@@ -390,7 +390,7 @@ public void addProduct() {
}
if (shop.getProduct().size() + Math.ceil((double) itemInHand.getAmount() / (double) itemInHand.getMaxStackSize()) > Setting.MAX_ITEMS_PER_TRADE_SIDE.getInt()) {
- command.sendMessage(Message.TOO_MANY_ITEMS.getPrefixed().replaceAll("%side%", "products"));
+ Message.TOO_MANY_ITEMS.sendMessage(pSender, new Tuple<>("%side%", "products"));
return;
}
@@ -400,7 +400,7 @@ public void addProduct() {
shop.addProduct(itemInHand);
- command.sendMessage(Message.ITEM_ADDED);
+ Message.ITEM_ADDED.sendMessage(pSender);
}
/**
@@ -433,7 +433,7 @@ public void setCost() {
}
if (!(shop.getOwner().getUUID().equals(pSender.getUniqueId()) || shop.getManagersUUID().contains(pSender.getUniqueId()))) {
- command.sendMessage(Message.NO_SHOP_PERMISSION);
+ Message.NO_SHOP_PERMISSION.sendMessage(pSender);
return;
}
@@ -446,17 +446,17 @@ public void setCost() {
}
if (costItem.getType() == Material.AIR) {
- command.sendMessage(Message.HELD_EMPTY);
+ Message.HELD_EMPTY.sendMessage(pSender);
return;
}
if (!isValidType(costItem.getType())) {
- command.sendMessage(Message.ILLEGAL_ITEM);
+ Message.ILLEGAL_ITEM.sendMessage(pSender);
return;
}
if (!(shop.getShopType().isITrade() && shop.getInventoryLocation() == null) && costItem.getType().toString().endsWith("SHULKER_BOX") && shop.getInventoryLocation().getBlock().getType().toString().endsWith("SHULKER_BOX")) {
- command.sendMessage(Message.NO_SHULKER_COST);
+ Message.NO_SHULKER_COST.sendMessage(pSender);
return;
}
@@ -465,7 +465,7 @@ public void setCost() {
}
if (Math.ceil((double) costItem.getAmount() / (double) costItem.getMaxStackSize()) > Setting.MAX_ITEMS_PER_TRADE_SIDE.getInt()) {
- command.sendMessage(Message.TOO_MANY_ITEMS.getPrefixed().replaceAll("%side%", "costs"));
+ Message.TOO_MANY_ITEMS.sendMessage(pSender, new Tuple<>("%side%", "costs"));
return;
}
@@ -475,7 +475,7 @@ public void setCost() {
shop.setCost(costItem);
- command.sendMessage(Message.ITEM_ADDED);
+ Message.ITEM_ADDED.sendMessage(pSender);
}
/**
@@ -508,7 +508,7 @@ public void addCost() {
}
if (!(shop.getOwner().getUUID().equals(pSender.getUniqueId()) || shop.getManagersUUID().contains(pSender.getUniqueId()))) {
- command.sendMessage(Message.NO_SHOP_PERMISSION);
+ Message.NO_SHOP_PERMISSION.sendMessage(pSender);
return;
}
@@ -521,17 +521,17 @@ public void addCost() {
}
if (itemInHand.getType() == Material.AIR) {
- command.sendMessage(Message.HELD_EMPTY);
+ Message.HELD_EMPTY.sendMessage(pSender);
return;
}
if (!isValidType(itemInHand.getType())) {
- command.sendMessage(Message.ILLEGAL_ITEM);
+ Message.ILLEGAL_ITEM.sendMessage(pSender);
return;
}
if (!(shop.getShopType().isITrade() && shop.getInventoryLocation() == null) && itemInHand.getType().toString().endsWith("SHULKER_BOX") && shop.getInventoryLocation().getBlock().getType().toString().endsWith("SHULKER_BOX")) {
- command.sendMessage(Message.NO_SHULKER_COST);
+ Message.NO_SHULKER_COST.sendMessage(pSender);
return;
}
@@ -540,7 +540,7 @@ public void addCost() {
}
if (shop.getCost().size() + Math.ceil((double) itemInHand.getAmount() / (double) itemInHand.getMaxStackSize()) > Setting.MAX_ITEMS_PER_TRADE_SIDE.getInt()) {
- command.sendMessage(Message.TOO_MANY_ITEMS.getPrefixed().replaceAll("%side%", "costs"));
+ Message.TOO_MANY_ITEMS.sendMessage(pSender, new Tuple<>("%side%", "costs"));
return;
}
@@ -550,7 +550,7 @@ public void addCost() {
shop.addCost(itemInHand);
- command.sendMessage(Message.ITEM_ADDED);
+ Message.ITEM_ADDED.sendMessage(pSender);
}
/**
@@ -564,11 +564,11 @@ public void open() {
if (!(shop.getOwner().getUUID().equals(pSender.getUniqueId()) ||
shop.getManagersUUID().contains(pSender.getUniqueId()) ||
- Permissions.hasPermission(pSender, Permissions.ADMIN))) {
- command.sendMessage(Message.NO_SHOP_PERMISSION);
+ Permissions.isAdminEnabled(pSender))) {
+ Message.NO_SHOP_PERMISSION.sendMessage(pSender);
return;
}
-
+
PlayerShopOpenEvent event = new PlayerShopOpenEvent(pSender, shop);
if (event.isCancelled()) return;
@@ -576,16 +576,16 @@ public void open() {
switch (status) {
case OPEN:
- command.sendMessage(Message.CHANGE_OPEN);
+ Message.CHANGE_OPEN.sendMessage(pSender);
break;
case INCOMPLETE:
if (shop.isMissingItems())
- command.sendMessage(Message.MISSING_ITEM);
+ Message.MISSING_ITEM.sendMessage(pSender);
else if (shop.getChestAsSC() == null)
- command.sendMessage(Message.MISSING_CHEST);
+ Message.MISSING_CHEST.sendMessage(pSender);
break;
case OUT_OF_STOCK:
- command.sendMessage(Message.SHOP_EMPTY);
+ Message.SHOP_EMPTY.sendMessage(pSender);
break;
}
}
@@ -601,8 +601,8 @@ public void close() {
if (!(shop.getOwner().getUUID().equals(pSender.getUniqueId()) ||
shop.getManagersUUID().contains(pSender.getUniqueId()) ||
- Permissions.hasPermission(pSender, Permissions.ADMIN))) {
- command.sendMessage(Message.NO_SHOP_PERMISSION);
+ Permissions.isAdminEnabled(pSender))) {
+ Message.NO_SHOP_PERMISSION.sendMessage(pSender);
return;
}
@@ -613,7 +613,7 @@ public void close() {
shop.updateSign();
shop.saveShop();
- command.sendMessage(Message.CHANGE_CLOSED);
+ Message.CHANGE_CLOSED.sendMessage(pSender);
}
/**
@@ -626,31 +626,31 @@ public void switchShop() {
return;
if (!Permissions.hasPermission(pSender, Permissions.EDIT)) {
- command.sendMessage(Message.NO_COMMAND_PERMISSION);
+ Message.NO_COMMAND_PERMISSION.sendMessage(pSender);
return;
}
switch (shop.getShopType()) {
case TRADE:
if (!Permissions.hasPermission(pSender, Permissions.CREATEBI)) {
- command.sendMessage(Message.NO_COMMAND_PERMISSION);
+ Message.NO_COMMAND_PERMISSION.sendMessage(pSender);
return;
}
case BITRADE:
if (!Permissions.hasPermission(pSender, Permissions.CREATE)) {
- command.sendMessage(Message.NO_COMMAND_PERMISSION);
+ Message.NO_COMMAND_PERMISSION.sendMessage(pSender);
return;
}
}
if (!(shop.getOwner().getUUID().equals(pSender.getUniqueId()) || shop.getManagersUUID().contains(pSender.getUniqueId()))) {
- command.sendMessage(Message.NO_SHOP_PERMISSION);
+ Message.NO_SHOP_PERMISSION.sendMessage(pSender);
return;
}
shop.switchType();
- command.sendMessage(Message.SHOP_TYPE_SWITCHED.getPrefixed().replace("%newtype%", shop.getShopType().toHeader()));
+ Message.SHOP_TYPE_SWITCHED.sendMessage(pSender, new Tuple<>("%newtype%", shop.getShopType().toHeader()));
}
/**
@@ -666,10 +666,10 @@ public void who() {
return;
if (shop.getShopType().isITrade()) {
- command.sendMessage(Message.WHO_MESSAGE.getPrefixed()
- .replace("{OWNER}", Setting.ITRADESHOP_OWNER.getString())
- .replace("{MANAGERS}", "None")
- .replace("{MEMBERS}", "None"));
+ Message.WHO_MESSAGE.sendMessage(pSender,
+ new Tuple<>("{OWNER}", Setting.ITRADESHOP_OWNER.getString()),
+ new Tuple<>("{MANAGERS}", "None"),
+ new Tuple<>("{MEMBERS}", "None"));
return;
}
@@ -700,10 +700,10 @@ public void who() {
if (members.toString().equals("")) {
members = new StringBuilder("None");
}
- command.sendMessage(Message.WHO_MESSAGE.getPrefixed()
- .replace("{OWNER}", owner)
- .replace("{MANAGERS}", managers.toString())
- .replace("{MEMBERS}", members.toString()));
+ Message.WHO_MESSAGE.sendMessage(pSender,
+ new Tuple<>("{OWNER}", owner),
+ new Tuple<>("{MANAGERS}", managers.toString()),
+ new Tuple<>("{MEMBERS}", members.toString()));
}
/**
@@ -716,18 +716,18 @@ public void addManager() {
return;
if (!shop.getOwner().getUUID().equals(pSender.getUniqueId())) {
- command.sendMessage(Message.NO_SHOP_PERMISSION);
+ Message.NO_SHOP_PERMISSION.sendMessage(pSender);
return;
}
OfflinePlayer target = Bukkit.getOfflinePlayer(command.getArgAt(1));
if (!target.hasPlayedBefore()) {
- command.sendMessage(Message.PLAYER_NOT_FOUND);
+ Message.PLAYER_NOT_FOUND.sendMessage(pSender);
return;
}
if (shop.getUsersUUID().contains(target.getUniqueId())) {
- command.sendMessage(Message.UNSUCCESSFUL_SHOP_MEMBERS);
+ Message.UNSUCCESSFUL_SHOP_MEMBERS.sendMessage(pSender);
return;
}
@@ -737,7 +737,7 @@ public void addManager() {
shop.addManager(target.getUniqueId());
- command.sendMessage(Message.UPDATED_SHOP_MEMBERS);
+ Message.UPDATED_SHOP_MEMBERS.sendMessage(pSender);
}
/**
@@ -750,13 +750,13 @@ public void removeUser() {
return;
if (!shop.getOwner().getUUID().equals(pSender.getUniqueId())) {
- command.sendMessage(Message.NO_SHOP_PERMISSION);
+ Message.NO_SHOP_PERMISSION.sendMessage(pSender);
return;
}
OfflinePlayer target = Bukkit.getOfflinePlayer(command.getArgAt(1));
if (!target.hasPlayedBefore()) {
- command.sendMessage(Message.PLAYER_NOT_FOUND);
+ Message.PLAYER_NOT_FOUND.sendMessage(pSender);
return;
}
@@ -765,11 +765,11 @@ public void removeUser() {
if (changeEvent.isCancelled()) return;
if (!shop.removeUser(target.getUniqueId())) {
- command.sendMessage(Message.UNSUCCESSFUL_SHOP_MEMBERS);
+ Message.UNSUCCESSFUL_SHOP_MEMBERS.sendMessage(pSender);
return;
}
- command.sendMessage(Message.UPDATED_SHOP_MEMBERS);
+ Message.UPDATED_SHOP_MEMBERS.sendMessage(pSender);
}
/**
@@ -782,19 +782,19 @@ public void addMember() {
return;
if (!shop.getOwner().getUUID().equals(pSender.getUniqueId())) {
- command.sendMessage(Message.NO_SHOP_PERMISSION);
+ Message.NO_SHOP_PERMISSION.sendMessage(pSender);
return;
}
OfflinePlayer target = Bukkit.getOfflinePlayer(command.getArgAt(1));
if (!target.hasPlayedBefore()) {
- command.sendMessage(Message.PLAYER_NOT_FOUND);
+ Message.PLAYER_NOT_FOUND.sendMessage(pSender);
return;
}
if (shop.getUsersUUID().contains(target.getUniqueId())) {
- command.sendMessage(Message.UNSUCCESSFUL_SHOP_MEMBERS);
+ Message.UNSUCCESSFUL_SHOP_MEMBERS.sendMessage(pSender);
return;
}
@@ -804,7 +804,7 @@ public void addMember() {
shop.addMember(target.getUniqueId());
- command.sendMessage(Message.UPDATED_SHOP_MEMBERS);
+ Message.UPDATED_SHOP_MEMBERS.sendMessage(pSender);
}
/**
@@ -812,14 +812,14 @@ public void addMember() {
*/
public void multi() {
if (!Setting.ALLOW_MULTI_TRADE.getBoolean()) {
- command.sendMessage(Message.FEATURE_DISABLED);
+ Message.FEATURE_DISABLED.sendMessage(pSender);
return;
}
PlayerSetting playerSetting = plugin.getDataStorage().loadPlayer(pSender.getUniqueId());
if (command.argsSize() == 1) {
- command.sendMessage(Message.MULTI_AMOUNT.getPrefixed().replaceAll("%amount%", String.valueOf(playerSetting.getMulti())));
+ Message.MULTI_AMOUNT.sendMessage(pSender, new Tuple<>("%amount%", String.valueOf(playerSetting.getMulti())));
} else {
int amount = Setting.MULTI_TRADE_DEFAULT.getInt();
@@ -834,23 +834,35 @@ else if (amount > Setting.MULTI_TRADE_MAX.getInt())
playerSetting.setMulti(amount);
plugin.getDataStorage().savePlayer(playerSetting);
- command.sendMessage(Message.MULTI_UPDATE.getPrefixed().replaceAll("%amount%", String.valueOf(amount)));
+ Message.MULTI_UPDATE.sendMessage(pSender, new Tuple<>("%amount%", String.valueOf(amount)));
}
}
+ /**
+ * Changes the players with the ADMIN permission to toggle whether it is enable for them
+ */
+ public void toggleAdmin() {
+ PlayerSetting playerSetting = plugin.getDataStorage().loadPlayer(pSender.getUniqueId());
+
+ playerSetting.setAdminEnabled(!playerSetting.isAdminEnabled());
+ plugin.getDataStorage().savePlayer(playerSetting);
+
+ Message.ADMIN_TOGGLED.sendMessage(pSender, new Tuple<>("{STATE}", playerSetting.isAdminEnabled() ? "enabled" : "disabled"));
+ }
+
/**
* Toggles the join status message for the player
*/
public void toggleStatus() {
if (!Setting.ALLOW_TOGGLE_STATUS.getBoolean()) {
- command.sendMessage(Message.FEATURE_DISABLED);
+ Message.FEATURE_DISABLED.sendMessage(pSender);
return;
}
PlayerSetting playerSetting = plugin.getDataStorage().loadPlayer(pSender.getUniqueId());
playerSetting.setShowInvolvedStatus(!playerSetting.showInvolvedStatus());
plugin.getDataStorage().savePlayer(playerSetting);
- command.sendMessage(Message.TOGGLED_STATUS.getPrefixed().replace("%status%", playerSetting.showInvolvedStatus() ? "on" : "off"));
+ Message.TOGGLED_STATUS.sendMessage(pSender, new Tuple<>("%status%", playerSetting.showInvolvedStatus() ? "on" : "off"));
}
/**
@@ -863,7 +875,6 @@ public void createTrade() {
return;
createShop(sign, ShopType.TRADE);
-
}
/**
@@ -876,7 +887,6 @@ public void createBiTrade() {
return;
createShop(sign, ShopType.BITRADE);
-
}
/**
@@ -889,7 +899,6 @@ public void createITrade() {
return;
createShop(sign, ShopType.ITRADE);
-
}
@@ -901,19 +910,19 @@ public void createITrade() {
*/
private void createShop(Sign shopSign, ShopType shopType) {
if (ShopType.isShop(shopSign)) {
- command.sendMessage(Message.EXISTING_SHOP);
+ Message.EXISTING_SHOP.sendMessage(pSender);
return;
}
ShopUser owner = new ShopUser(pSender, ShopRole.OWNER);
if (!checkShopChest(shopSign.getBlock()) && !shopType.isITrade()) {
- command.sendMessage(Message.NO_CHEST);
+ Message.NO_CHEST.sendMessage(pSender);
return;
}
if (Setting.MAX_SHOPS_PER_CHUNK.getInt() <= plugin.getDataStorage().getShopCountInChunk(shopSign.getChunk())) {
- command.sendMessage(Message.TOO_MANY_CHESTS);
+ Message.TOO_MANY_CHESTS.sendMessage(pSender);
return;
}
@@ -929,12 +938,12 @@ private void createShop(Sign shopSign, ShopType shopType) {
}
if (shopChest.hasOwner() && !shopChest.getOwner().equals(owner.getUUID())) {
- command.sendMessage(Message.NO_SHOP_PERMISSION);
+ Message.NO_SHOP_PERMISSION.sendMessage(pSender);
return;
}
if (shopChest.hasShopSign() && !shopChest.getShopSign().getLocation().equals(shopSign.getLocation())) {
- command.sendMessage(Message.EXISTING_SHOP);
+ Message.EXISTING_SHOP.sendMessage(pSender);
return;
}
@@ -943,7 +952,7 @@ private void createShop(Sign shopSign, ShopType shopType) {
if (shopChest.isEmpty() && shop.hasProduct()) {
- command.sendMessage(Message.EMPTY_TS_ON_SETUP);
+ Message.EMPTY_TS_ON_SETUP.sendMessage(pSender);
}
} else {
shop = new Shop(shopSign.getLocation(), shopType, owner);
@@ -958,11 +967,9 @@ private void createShop(Sign shopSign, ShopType shopType) {
shopSign.setLine(0, shopType.toHeader());
shopSign.update();
- shop.updateSign();
- shop.removeEvent();
shop.saveShop();
- command.sendMessage(Message.SUCCESSFUL_SETUP);
+ Message.SUCCESSFUL_SETUP.sendMessage(pSender);
}
/**
@@ -972,9 +979,9 @@ public void playerLevel() {
if (Bukkit.getOfflinePlayer(command.getArgAt(1)).hasPlayedBefore()) {
PlayerSetting playerSetting = plugin.getDataStorage().loadPlayer(Bukkit.getOfflinePlayer(command.getArgAt(1)).getUniqueId());
if (command.argsSize() == 2) {
- command.sendMessage(Message.VIEW_PLAYER_LEVEL.getMessage()
- .replace("%player%", Bukkit.getOfflinePlayer(command.getArgAt(1)).getName())
- .replace("%level%", playerSetting.getType() + ""));
+ Message.VIEW_PLAYER_LEVEL.sendMessage(pSender,
+ new Tuple<>("%player%", Bukkit.getOfflinePlayer(command.getArgAt(1)).getName()),
+ new Tuple<>("%level%", playerSetting.getType() + ""));
} else {
if (isInt(command.getArgAt(2))) {
int newLevel = Integer.parseInt(command.getArgAt(2));
@@ -982,15 +989,15 @@ public void playerLevel() {
playerSetting.setType(newLevel);
plugin.getDataStorage().savePlayer(playerSetting);
- command.sendMessage(Message.SET_PLAYER_LEVEL.getMessage()
- .replace("%player%", Bukkit.getOfflinePlayer(command.getArgAt(1)).getName())
- .replace("%level%", playerSetting.getType() + ""));
+ Message.SET_PLAYER_LEVEL.sendMessage(pSender,
+ new Tuple<>("%player%", Bukkit.getOfflinePlayer(command.getArgAt(1)).getName()),
+ new Tuple<>("%level%", playerSetting.getType() + ""));
} else {
- command.sendMessage(Message.INVALID_ARGUMENTS.getMessage());
+ Message.INVALID_ARGUMENTS.sendMessage(pSender);
}
}
} else {
- command.sendMessage(Message.PLAYER_NOT_FOUND.getMessage());
+ Message.PLAYER_NOT_FOUND.sendMessage(pSender);
}
}
@@ -999,15 +1006,15 @@ public void playerLevel() {
*/
public void status() {
if (command.hasArgAt(1)) {
- if (!Permissions.hasPermission(pSender, Permissions.ADMIN)) {
- command.sendMessage(Message.NO_COMMAND_PERMISSION);
+ if (!Permissions.isAdminEnabled(pSender)) {
+ Message.NO_COMMAND_PERMISSION.sendMessage(pSender);
return;
}
if (Bukkit.getOfflinePlayer(command.getArgAt(1)).hasPlayedBefore()) {
plugin.getDataStorage().loadPlayer(Bukkit.getOfflinePlayer(command.getArgAt(1)).getUniqueId())
.getInvolvedStatusesInventory().show(pSender.getPlayer());
} else {
- command.sendMessage(Message.PLAYER_NOT_FOUND.getMessage());
+ Message.PLAYER_NOT_FOUND.sendMessage(pSender);
}
} else {
plugin.getDataStorage().loadPlayer(pSender.getUniqueId()).getInvolvedStatusesInventory().show(pSender.getPlayer());
@@ -1021,7 +1028,7 @@ public void status() {
*/
protected Shop findShop() {
if (pSender == null) {
- command.sendMessage(Message.PLAYER_ONLY_COMMAND);
+ Message.PLAYER_ONLY_COMMAND.sendMessage(pSender);
return null;
}
@@ -1043,7 +1050,7 @@ protected Shop findShop() {
throw new NoSuchFieldException();
} catch (NoSuchFieldException ex) {
- command.sendMessage(Message.NO_SIGHTED_SHOP);
+ Message.NO_SIGHTED_SHOP.sendMessage(pSender);
return null;
}
}
@@ -1055,7 +1062,7 @@ protected Shop findShop() {
*/
protected Sign findSign() {
if (pSender == null) {
- command.sendMessage(Message.PLAYER_ONLY_COMMAND);
+ Message.PLAYER_ONLY_COMMAND.sendMessage(pSender);
return null;
}
@@ -1071,7 +1078,7 @@ protected Sign findSign() {
throw new NoSuchFieldException();
} catch (NoSuchFieldException ex) {
- command.sendMessage(Message.NO_SIGN_FOUND);
+ Message.NO_SIGN_FOUND.sendMessage(pSender);
return null;
}
}
diff --git a/src/main/java/org/shanerx/tradeshop/commands/EditCommand.java b/src/main/java/org/shanerx/tradeshop/commands/EditCommand.java
index 283d40a2..f93853c6 100644
--- a/src/main/java/org/shanerx/tradeshop/commands/EditCommand.java
+++ b/src/main/java/org/shanerx/tradeshop/commands/EditCommand.java
@@ -79,14 +79,9 @@ public void edit() {
if (shop == null)
return;
- if (!Permissions.hasPermission(pSender, Permissions.EDIT)) {
- command.sendMessage(Message.NO_COMMAND_PERMISSION.getPrefixed());
- return;
- }
-
if (!(shop.getOwner().getUUID().equals(pSender.getUniqueId()) ||
shop.getManagersUUID().contains(pSender.getUniqueId()) ||
- Permissions.hasPermission(pSender, Permissions.ADMIN))) {
+ Permissions.isAdminEnabled(pSender))) {
command.sendMessage(Message.NO_SHOP_PERMISSION.getPrefixed());
return;
}
diff --git a/src/main/java/org/shanerx/tradeshop/enumys/Commands.java b/src/main/java/org/shanerx/tradeshop/enumys/Commands.java
index 6de9c9c4..2ae8f85c 100644
--- a/src/main/java/org/shanerx/tradeshop/enumys/Commands.java
+++ b/src/main/java/org/shanerx/tradeshop/enumys/Commands.java
@@ -76,6 +76,7 @@ public enum Commands {
SETUP(Lists.newArrayList("setup", "start", "create", "make"), Permissions.HELP, 1, 1, false, "Display shop setup tutorial", "/tradeshop $cmd$"),
BUGS(Lists.newArrayList("bugs", "bug"), Permissions.NONE, 1, 1, false, "Report bugs to the developers", "/tradeshop $cmd$"),
PLAYER_LEVEL(Lists.newArrayList("playerlevel", "pl"), Permissions.MANAGE_PLUGIN, 2, 3, false, "If Internal Permissions is enable this allows the getting and setting of player permission levels.", "/tradeshop $cmd$ "),
+ TOGGLE_ADMIN(Lists.newArrayList("toggleadmin", "admin"), Permissions.ADMIN, 1, 1, true, "Toggles Admin mode for players with the admin permission", "/tradeshop $cmd$"),
RELOAD(Lists.newArrayList("reload"), Permissions.MANAGE_PLUGIN, 1, 1, false, "Reload configuration files", "/tradeshop $cmd$");
diff --git a/src/main/java/org/shanerx/tradeshop/enumys/Message.java b/src/main/java/org/shanerx/tradeshop/enumys/Message.java
index 323e8696..e4787710 100644
--- a/src/main/java/org/shanerx/tradeshop/enumys/Message.java
+++ b/src/main/java/org/shanerx/tradeshop/enumys/Message.java
@@ -36,11 +36,10 @@
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.shanerx.tradeshop.TradeShop;
+import org.shanerx.tradeshop.utils.Tuple;
import org.yaml.snakeyaml.Yaml;
import java.io.*;
-import java.util.Collections;
-import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
@@ -110,7 +109,8 @@ public enum Message {
SET_PLAYER_LEVEL(MessageSectionKeys.NONE, "&aYou have set the level of %player% to %level%!", "Text to display after setting a players level"),
VARIOUS_ITEM_TYPE(MessageSectionKeys.NONE, "Various", "Text to display when a message uses an Item Type and the Type varies"),
TOGGLED_STATUS(MessageSectionKeys.NONE, "Toggled status: &c%status%"),
- NO_SIGN_FOUND(MessageSectionKeys.NONE, "&cNo sign in range!\", \"Text to display when a player is too far from a sign\"");
+ NO_SIGN_FOUND(MessageSectionKeys.NONE, "&cNo sign in range!", "Text to display when a player is too far from a sign"),
+ ADMIN_TOGGLED(MessageSectionKeys.NONE, "&aYour Admin mode is now &e{STATE}&a.", "Text to display when an admin toggles their Admin abilities. \"{STATE}\" will be replaced by the state that the player is in after the command.");
private static final char COLOUR_CHAR = '&';
private static final TradeShop plugin = (TradeShop) Bukkit.getPluginManager().getPlugin("TradeShop");
@@ -240,39 +240,62 @@ public String getPrefixed() {
return colour(PREFIX + this);
}
- public void sendMessage(Player player, Map replacements) {
- String message = getPrefixed();
- replacements.forEach(message::replaceAll);
+ private void sendMessageDirect(CommandSender sendTo, String message) {
+ sendTo.sendMessage(colour(message));
+ }
+
+ //Not currently working
+ private void sendMessageDirectJson(Player sendTo, String message) {
+ sendTo.sendRawMessage(colour(message));
+ }
+
+ public void sendMessage(Player player) {
+ String message = getPrefixed();
if (getMessage().startsWith("#json ")) {
message.replaceFirst("#json ", "");
- player.sendRawMessage(colour(message));
+ sendMessageDirectJson(player, message);
} else {
- player.sendMessage(colour(message));
+ sendMessageDirect(player, message);
}
}
- public void sendMessage(Player player) {
- sendMessage(player, Collections.emptyMap());
+ public void sendMessage(CommandSender sender) {
+ sendMessageDirect(sender, getPrefixed());
}
- public void sendMessage(CommandSender sender) {
- sendMessage(sender, Collections.emptyMap());
+ @SafeVarargs
+ public final void sendMessage(Player player, Tuple... replacements) {
+ String message = getPrefixed();
+ for (Tuple replace : replacements) {
+ message = message.replace(replace.getLeft(), replace.getRight());
+ }
+
+ if (getMessage().startsWith("#json ")) {
+ message = message.replaceFirst("#json ", "");
+ sendMessageDirectJson(player, message);
+ } else {
+ sendMessageDirect(player, message);
+ }
}
- public void sendMessage(CommandSender sender, Map replacements) {
+ @SafeVarargs
+ public final void sendMessage(CommandSender sender, Tuple... replacements) {
if (sender instanceof Player) {
sendMessage((Player) sender, replacements);
return;
}
+
String message = getPrefixed();
- replacements.forEach(message::replaceAll);
+ for (Tuple replace : replacements) {
+ message = message.replace(replace.getLeft(), replace.getRight());
+ }
if (getMessage().startsWith("#json ")) {
- message.replaceFirst("#json ", "");
+ message = message.replaceFirst("#json ", "");
}
- sender.sendMessage(colour(message));
+ sendMessageDirect(sender, message);
}
}
diff --git a/src/main/java/org/shanerx/tradeshop/enumys/Permissions.java b/src/main/java/org/shanerx/tradeshop/enumys/Permissions.java
index ee9c59b3..203353a6 100644
--- a/src/main/java/org/shanerx/tradeshop/enumys/Permissions.java
+++ b/src/main/java/org/shanerx/tradeshop/enumys/Permissions.java
@@ -80,6 +80,11 @@ public static boolean hasPermission(Player player, Permissions permission) {
}
}
+
+ public static boolean isAdminEnabled(Player player) {
+ return hasPermission(player, Permissions.ADMIN) && plugin.getDataStorage().loadPlayer(player.getUniqueId()).isAdminEnabled();
+ }
+
public int getLevel() {
return level;
}
diff --git a/src/main/java/org/shanerx/tradeshop/enumys/Setting.java b/src/main/java/org/shanerx/tradeshop/enumys/Setting.java
index f64afbe4..a414e709 100644
--- a/src/main/java/org/shanerx/tradeshop/enumys/Setting.java
+++ b/src/main/java/org/shanerx/tradeshop/enumys/Setting.java
@@ -85,10 +85,6 @@ public enum Setting {
ALLOW_USER_PURCHASING(SettingSectionKeys.SHOP_OPTIONS, "allow-user-purchasing", false, "Can players purchase from a shop in which they are a user of (true/false)"),
MULTIPLE_ITEMS_ON_SIGN(SettingSectionKeys.SHOP_OPTIONS, "multiple-items-on-sign", "Use '/ts what'", "Text that shows on trade signs that contain more than 1 item", "\n"),
- // Item Options
- FIREWORK_COMPARE_DURATION(SettingSectionKeys.ITEM_OPTIONS, "firework-compare-duration", true, "Must trades involving a firework rocket match the correct flight duration?"),
- FIREWORK_COMPARE_EFFECTS(SettingSectionKeys.ITEM_OPTIONS, "firework-compare-effects", false, "Must trades involving a firework rocket match the exact firework effects?"),
-
// Trade Shop Options
TRADESHOP_HEADER(SettingSectionKeys.TRADE_SHOP_OPTIONS, "header", "Trade", "The header that appears at the top of the shop signs, this is also what the player types to create the sign"),
TRADESHOP_EXPLODE(SettingSectionKeys.TRADE_SHOP_OPTIONS, "allow-explode", false, "Can explosions damage the shop sign/storage (true/false)"),
diff --git a/src/main/java/org/shanerx/tradeshop/listeners/ShopCreateListener.java b/src/main/java/org/shanerx/tradeshop/listeners/ShopCreateListener.java
index 6b63a77b..3d856696 100644
--- a/src/main/java/org/shanerx/tradeshop/listeners/ShopCreateListener.java
+++ b/src/main/java/org/shanerx/tradeshop/listeners/ShopCreateListener.java
@@ -64,6 +64,7 @@ public void onSignChange(SignChangeEvent event) {
if (!ShopType.isShop(shopSign)) {
return;
}
+
ShopType shopType = ShopType.getType(shopSign);
Player p = event.getPlayer();
ShopUser owner = new ShopUser(p, ShopRole.OWNER);
diff --git a/src/main/java/org/shanerx/tradeshop/listeners/ShopProtectionListener.java b/src/main/java/org/shanerx/tradeshop/listeners/ShopProtectionListener.java
index 80c79d37..8d0a41a4 100644
--- a/src/main/java/org/shanerx/tradeshop/listeners/ShopProtectionListener.java
+++ b/src/main/java/org/shanerx/tradeshop/listeners/ShopProtectionListener.java
@@ -108,7 +108,7 @@ else if (plugin.getListManager().isInventory(destLoc.getBlock())) {
return;
}
- ((TradeShop) Bukkit.getPluginManager().getPlugin("TradeShop")).setFrozen(true);
+ plugin.setFrozen(true);
Shop shop = new ShopChest(invBlock.getLocation()).getShop();
boolean isForbidden = !Setting.findSetting(shop.getShopType().name() + (fromHopper ? "SHOP_HOPPER_IMPORT" : "SHOP_HOPPER_EXPORT")).getBoolean();
@@ -132,7 +132,7 @@ else if (plugin.getListManager().isInventory(destLoc.getBlock())) {
debugger.log("ShopProtectionListener: (TSAF) HopperEvent recovered! ", DebugLevels.PROTECTION);
event.setCancelled(hopperEvent.isForbidden());
debugger.log("ShopProtectionListener: (TSAF) HopperEvent isForbidden: " + hopperEvent.isForbidden(), DebugLevels.PROTECTION);
- ((TradeShop) Bukkit.getPluginManager().getPlugin("TradeShop")).setFrozen(false);
+ plugin.setFrozen(false);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@@ -202,7 +202,7 @@ public void onBlockBreak(BlockBreakEvent event) {
shop = Shop.loadShop((Sign) block.getState());
if (shop == null)
return;
- if (Permissions.hasPermission(player, Permissions.ADMIN) || player.getUniqueId().equals(shop.getOwner().getUUID())) {
+ if (Permissions.isAdminEnabled(player) || player.getUniqueId().equals(shop.getOwner().getUUID())) {
PlayerShopDestroyEvent destroyEvent = new PlayerShopDestroyEvent(player, shop);
Bukkit.getPluginManager().callEvent(destroyEvent);
if (destroyEvent.isCancelled()) {
@@ -224,7 +224,7 @@ public void onBlockBreak(BlockBreakEvent event) {
shop = new ShopChest(block.getLocation()).getShop();
if (shop == null)
return;
- if (Permissions.hasPermission(player, Permissions.ADMIN) || player.getUniqueId().equals(shop.getOwner().getUUID())) {
+ if (Permissions.isAdminEnabled(player) || player.getUniqueId().equals(shop.getOwner().getUUID())) {
PlayerShopDestroyEvent destroyEvent = new PlayerShopDestroyEvent(player, shop);
Bukkit.getPluginManager().callEvent(destroyEvent);
if (destroyEvent.isCancelled()) {
@@ -290,7 +290,7 @@ public void onChestOpen(PlayerInteractEvent e) {
return;
}
- if (!Permissions.hasPermission(e.getPlayer(), Permissions.ADMIN) && !shop.getUsersUUID().contains(e.getPlayer().getUniqueId())) {
+ if (!Permissions.isAdminEnabled(e.getPlayer()) && !shop.getUsersUUID().contains(e.getPlayer().getUniqueId())) {
openEvent.setCancelled(true);
}
diff --git a/src/main/java/org/shanerx/tradeshop/objects/PlayerSetting.java b/src/main/java/org/shanerx/tradeshop/objects/PlayerSetting.java
index 110364e2..c284a41a 100644
--- a/src/main/java/org/shanerx/tradeshop/objects/PlayerSetting.java
+++ b/src/main/java/org/shanerx/tradeshop/objects/PlayerSetting.java
@@ -49,7 +49,7 @@ public class PlayerSetting implements Serializable {
private final String uuidString;
private final Set ownedShops;
- private boolean showInvolvedStatus;
+ private boolean showInvolvedStatus, adminEnabled = false;
private int type = 0, multi = Setting.MULTI_TRADE_DEFAULT.getInt();
private final Set staffShops;
@@ -84,6 +84,14 @@ public static PlayerSetting deserialize(String serialized) {
return playerSetting;
}
+ public boolean isAdminEnabled() {
+ return adminEnabled;
+ }
+
+ public void setAdminEnabled(boolean adminEnabled) {
+ this.adminEnabled = adminEnabled;
+ }
+
public int getType() {
return type;
}
diff --git a/src/main/java/org/shanerx/tradeshop/objects/Shop.java b/src/main/java/org/shanerx/tradeshop/objects/Shop.java
index 5b2f32d5..5daddb67 100644
--- a/src/main/java/org/shanerx/tradeshop/objects/Shop.java
+++ b/src/main/java/org/shanerx/tradeshop/objects/Shop.java
@@ -703,12 +703,13 @@ public List getUsersUUID() {
}
/**
- * Saves the shop too file
+ * Saves the shop to file
*/
public void saveShop() {
updateFullTradeCount();
utils.plugin.getDataStorage().saveShop(this);
- updateUserFiles();
+ updateUserFiles();
+ updateSign();
}
/**
@@ -730,15 +731,16 @@ public Sign getShopSign() {
* Updates the text on the shops sign
*/
public void updateSign() {
- if (((TradeShop) Bukkit.getPluginManager().getPlugin("TradeShop")).isFrozen()) return;
- if (signChangeEvent != null)
+ if (utils.plugin.isFrozen()) return;
+ if (signChangeEvent != null) {
updateSign(signChangeEvent);
- else {
+ removeEvent();
+ } else {
Sign s = getShopSign();
- String[] signLines = updateSignLines();
+ String[] signLines = updateSignLines();
- for (int i = 0; i < 4; i++) {
+ for (int i = 0; i < 4; i++) {
if (signLines[i] != null && s != null)
s.setLine(i, signLines[i]);
}
diff --git a/src/main/java/org/shanerx/tradeshop/objects/ShopItemStack.java b/src/main/java/org/shanerx/tradeshop/objects/ShopItemStack.java
index 9a89a596..8d297654 100644
--- a/src/main/java/org/shanerx/tradeshop/objects/ShopItemStack.java
+++ b/src/main/java/org/shanerx/tradeshop/objects/ShopItemStack.java
@@ -36,7 +36,6 @@
import org.bukkit.util.io.BukkitObjectInputStream;
import org.bukkit.util.io.BukkitObjectOutputStream;
import org.shanerx.tradeshop.enumys.DebugLevels;
-import org.shanerx.tradeshop.enumys.Setting;
import org.shanerx.tradeshop.enumys.ShopItemStackSettingKeys;
import org.shanerx.tradeshop.utils.ObjectHolder;
import org.shanerx.tradeshop.utils.Utils;
@@ -425,13 +424,13 @@ public boolean isSimilar(ItemStack toCompare) {
FireworkMeta toCompareFireworkMeta = (FireworkMeta) toCompareMeta;
// If server compare firework duration is disabled local setting is ignores
- if (getShopSettingAsBoolean(ShopItemStackSettingKeys.COMPARE_FIREWORK_DURATION) && Setting.FIREWORK_COMPARE_DURATION.getBoolean()) {
+ if (getShopSettingAsBoolean(ShopItemStackSettingKeys.COMPARE_FIREWORK_DURATION)) {
if (fireworkMeta.getPower() != toCompareFireworkMeta.getPower()) {
return false;
}
}
- if (getShopSettingAsBoolean(ShopItemStackSettingKeys.COMPARE_FIREWORK_EFFECTS) && Setting.FIREWORK_COMPARE_EFFECTS.getBoolean()) {
+ if (getShopSettingAsBoolean(ShopItemStackSettingKeys.COMPARE_FIREWORK_EFFECTS)) {
if (fireworkMeta.hasEffects()) {
if (fireworkMeta.getEffects().size() != toCompareFireworkMeta.getEffects().size()) {
return false;