Merge branch '1.12' into 1.8.8

# Conflicts:
#	pom.xml
This commit is contained in:
Phoenix616 2018-08-22 00:30:38 +01:00
commit 7d406fc2dc
31 changed files with 429 additions and 53 deletions

13
pom.xml
View File

@ -6,7 +6,7 @@
<groupId>com.acrobot.chestshop</groupId>
<artifactId>chestshop</artifactId>
<version>3.9.2-1.8.8-hotfix</version>
<version>3.9.2-1.8.8</version>
<description>Chest-and-sign shop plugin for Bukkit</description>
<name>ChestShop</name>
@ -49,6 +49,10 @@
<id>local_repo</id>
<url>file://${project.basedir}/repo/</url>
</repository>
<repository>
<id>reserve-repo</id>
<url>https://dl.bintray.com/theneweconomy/java/</url>
</repository>
</repositories>
<dependencies>
@ -274,6 +278,13 @@
<version>1.2.24</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.tnemc</groupId>
<artifactId>Reserve</artifactId>
<version>0.1.0.10</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata modelVersion="1.1.0">
<groupId>org.mcstats.bukkit</groupId>
<artifactId>metrics</artifactId>
<version>R8-SNAPSHOT</version>
<versioning>
<snapshot>
<localCopy>true</localCopy>
</snapshot>
<lastUpdated>20180711163419</lastUpdated>
<snapshotVersions>
<snapshotVersion>
<extension>jar</extension>
<value>R8-SNAPSHOT</value>
<updated>20180711163419</updated>
</snapshotVersion>
<snapshotVersion>
<extension>pom</extension>
<value>R8-SNAPSHOT</value>
<updated>20180711163419</updated>
</snapshotVersion>
</snapshotVersions>
</versioning>
</metadata>

View File

@ -0,0 +1 @@
46632b59c9d3d47442b77c0554325496

View File

@ -0,0 +1 @@
20541fa3752c0169c1ac8af2232281ccb1e01969

View File

@ -0,0 +1 @@
d0916f0631371e2cd1ba27b7a24e9528

View File

@ -0,0 +1 @@
c473200c17a6157d7f59f5935df2169088a78d8e

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.mcstats.bukkit</groupId>
<artifactId>metrics</artifactId>
<version>R8-SNAPSHOT</version>
<description>POM was created from install:install-file</description>
</project>

View File

@ -0,0 +1 @@
209c9099f021a6a85d1d337de6c2e74a

View File

@ -0,0 +1 @@
38207d9da32bb25d60da9676d1d34966567d62e5

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>org.mcstats.bukkit</groupId>
<artifactId>metrics</artifactId>
<versioning>
<versions>
<version>R8-SNAPSHOT</version>
</versions>
<lastUpdated>20180711163419</lastUpdated>
</versioning>
</metadata>

View File

@ -0,0 +1 @@
52f4c1a0347427b995125e438ea9b81d

View File

@ -0,0 +1 @@
ce375488dc6366cc09efdc249006b25ff0dec3cf

View File

@ -21,7 +21,7 @@ import com.Acrobot.ChestShop.Listeners.ItemInfoListener;
import com.Acrobot.ChestShop.Listeners.Modules.DiscountModule;
import com.Acrobot.ChestShop.Listeners.Modules.PriceRestrictionModule;
import com.Acrobot.ChestShop.Listeners.Player.*;
import com.Acrobot.ChestShop.Listeners.PostShopCreation.CreationFeeGetter;
import com.Acrobot.ChestShop.Listeners.PreShopCreation.CreationFeeGetter;
import com.Acrobot.ChestShop.Listeners.PostShopCreation.MessageSender;
import com.Acrobot.ChestShop.Listeners.PostShopCreation.ShopCreationLogger;
import com.Acrobot.ChestShop.Listeners.PostShopCreation.SignSticker;
@ -99,7 +99,9 @@ public class ChestShop extends JavaPlugin {
NameManager.load();
Dependencies.loadPlugins();
if (!Dependencies.loadPlugins()) {
return;
}
registerEvents();

View File

@ -2,9 +2,11 @@ package com.Acrobot.ChestShop;
import com.Acrobot.Breeze.Utils.MaterialUtil;
import com.Acrobot.ChestShop.Configuration.Properties;
import com.Acrobot.ChestShop.Listeners.Economy.Plugins.ReserveListener;
import com.Acrobot.ChestShop.Listeners.Economy.Plugins.VaultListener;
import com.Acrobot.ChestShop.Plugins.*;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import net.tnemc.core.Reserve;
import org.bukkit.Bukkit;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
@ -15,7 +17,7 @@ import org.bukkit.plugin.PluginManager;
* @author Acrobot
*/
public class Dependencies {
public static void loadPlugins() {
public static boolean loadPlugins() {
PluginManager pluginManager = Bukkit.getPluginManager();
for (String dependency : ChestShop.getDependencies()) {
@ -26,19 +28,32 @@ public class Dependencies {
}
}
loadEconomy();
return loadEconomy();
}
private static void loadEconomy() {
String plugin = "Vault";
Listener economy = VaultListener.initializeVault();
private static boolean loadEconomy() {
String plugin = "none";
Listener economy = null;
if(Bukkit.getPluginManager().getPlugin("Reserve") != null) {
plugin = "Reserve";
economy = ReserveListener.prepareListener();
}
if(Bukkit.getPluginManager().getPlugin("Vault") != null) {
plugin = "Vault";
economy = VaultListener.initializeVault();
}
if (economy == null) {
return;
ChestShop.getBukkitLogger().severe("No Economy plugin found! You need to install either Vault or Reserve and a compatible economy!");
return false;
}
ChestShop.registerListener(economy);
ChestShop.getBukkitLogger().info(plugin + " loaded! Found an economy plugin!");
return true;
}
private static void initializePlugin(String name, Plugin plugin) { //Really messy, right? But it's short and fast :)

View File

@ -37,14 +37,14 @@ public class Economy {
CurrencyAddEvent event = new CurrencyAddEvent(BigDecimal.valueOf(amount), name, world);
ChestShop.callEvent(event);
return true;
return event.isAdded();
}
public static boolean subtract(UUID name, World world, double amount) {
CurrencySubtractEvent event = new CurrencySubtractEvent(BigDecimal.valueOf(amount), name, world);
ChestShop.callEvent(event);
return true;
return event.isSubtracted();
}
public static boolean hasEnough(UUID name, World world, double amount) {

View File

@ -2,6 +2,7 @@ package com.Acrobot.ChestShop.Events;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
@ -10,7 +11,7 @@ import org.bukkit.event.HandlerList;
*
* @author Acrobot
*/
public class PreShopCreationEvent extends Event {
public class PreShopCreationEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private Player creator;
@ -30,10 +31,21 @@ public class PreShopCreationEvent extends Event {
*
* @return Is event cancelled?
*/
@Override
public boolean isCancelled() {
return outcome != CreationOutcome.SHOP_CREATED_SUCCESSFULLY;
}
/**
* Set if event is cancelled. This sets a generic {@link CreationOutcome#OTHER};
*
* @param cancel Cancel the event?
*/
@Override
public void setCancelled(boolean cancel) {
outcome = CreationOutcome.OTHER;
}
/**
* Returns the outcome of the event
*

View File

@ -5,6 +5,7 @@ import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.Inventory;
@ -15,7 +16,7 @@ import org.bukkit.inventory.ItemStack;
*
* @author Acrobot
*/
public class TransactionEvent extends Event {
public class TransactionEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private final TransactionType type;
@ -30,6 +31,8 @@ public class TransactionEvent extends Event {
private final Sign sign;
private boolean cancelled = false;
public TransactionEvent(PreTransactionEvent event, Sign sign) {
this.type = event.getTransactionType();
@ -133,6 +136,16 @@ public class TransactionEvent extends Event {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
/**
* Possible transaction types
*/

View File

@ -0,0 +1,181 @@
package com.Acrobot.ChestShop.Listeners.Economy.Plugins;
import com.Acrobot.ChestShop.Events.Economy.AccountCheckEvent;
import com.Acrobot.ChestShop.Events.Economy.CurrencyAddEvent;
import com.Acrobot.ChestShop.Events.Economy.CurrencyAmountEvent;
import com.Acrobot.ChestShop.Events.Economy.CurrencyCheckEvent;
import com.Acrobot.ChestShop.Events.Economy.CurrencyFormatEvent;
import com.Acrobot.ChestShop.Events.Economy.CurrencyHoldEvent;
import com.Acrobot.ChestShop.Events.Economy.CurrencySubtractEvent;
import com.Acrobot.ChestShop.Events.Economy.CurrencyTransferEvent;
import net.tnemc.core.Reserve;
import net.tnemc.core.economy.EconomyAPI;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import javax.annotation.Nullable;
import java.math.BigDecimal;
/**
* Represents a Reserve connector
*
* @author creatorfromhell
*/
public class ReserveListener implements Listener {
private static @Nullable EconomyAPI economyAPI;
public ReserveListener(EconomyAPI api) {
ReserveListener.economyAPI = api;
}
public static EconomyAPI getProvider() {
return economyAPI;
}
public boolean provided() {
return economyAPI != null;
}
public boolean transactionCanFail() {
if (economyAPI == null) {
return false;
}
return economyAPI.name().equals("Gringotts")
|| economyAPI.name().equals("GoldIsMoney")
|| economyAPI.name().equals("MultiCurrency")
|| economyAPI.name().equalsIgnoreCase("TheNewEconomy");
}
public static @Nullable ReserveListener prepareListener() {
if (Bukkit.getPluginManager().getPlugin("Reserve") == null || Reserve.instance().economyProvided()) {
return null;
}
EconomyAPI api = Reserve.instance().economy();
if (api == null) {
return null;
} else {
return new ReserveListener(api);
}
}
@EventHandler
public void onAmountCheck(CurrencyAmountEvent event) {
if (!event.getAmount().equals(BigDecimal.ZERO)) {
return;
}
final OfflinePlayer lastSeen = Bukkit.getOfflinePlayer(event.getAccount());
if (lastSeen != null && provided()) {
event.setAmount(economyAPI.getHoldings(event.getAccount(), event.getWorld().getName()));
}
}
@EventHandler
public void onCurrencyCheck(CurrencyCheckEvent event) {
if (event.hasEnough()) {
return;
}
final OfflinePlayer lastSeen = Bukkit.getOfflinePlayer(event.getAccount());
if (lastSeen != null && provided()) {
event.hasEnough(economyAPI.hasHoldings(event.getAccount(),
event.getAmount(),
event.getWorld().getName()));
}
}
@EventHandler
public void onAccountCheck(AccountCheckEvent event) {
if (event.hasAccount()) {
return;
}
final OfflinePlayer lastSeen = Bukkit.getOfflinePlayer(event.getAccount());
event.hasAccount(lastSeen != null && provided() && economyAPI.hasAccount(event.getAccount()));
}
@EventHandler
public void onCurrencyFormat(CurrencyFormatEvent event) {
if (!event.getFormattedAmount().isEmpty()) {
return;
}
if (provided()) {
event.setFormattedAmount(economyAPI.format(event.getAmount()));
}
}
@EventHandler
public void onCurrencyAdd(CurrencyAddEvent event) {
if (event.isAdded()) {
return;
}
final OfflinePlayer lastSeen = Bukkit.getOfflinePlayer(event.getTarget());
if (lastSeen != null && provided()) {
event.setAdded(economyAPI.addHoldings(event.getTarget(), event.getAmount(), event.getWorld().getName()));
}
}
@EventHandler
public void onCurrencySubtraction(CurrencySubtractEvent event) {
if (event.isSubtracted()) {
return;
}
final OfflinePlayer lastSeen = Bukkit.getOfflinePlayer(event.getTarget());
if (lastSeen != null && provided()) {
event.setSubtracted(economyAPI.removeHoldings(event.getTarget(), event.getAmount(), event.getWorld().getName()));
}
}
@EventHandler
public void onCurrencyTransfer(CurrencyTransferEvent event) {
if (event.hasBeenTransferred()) {
return;
}
CurrencySubtractEvent currencySubtractEvent = new CurrencySubtractEvent(event.getAmount(), event.getSender(), event.getWorld());
onCurrencySubtraction(currencySubtractEvent);
if (!currencySubtractEvent.isSubtracted()) {
return;
}
CurrencyAddEvent currencyAddEvent = new CurrencyAddEvent(currencySubtractEvent.getAmount(), event.getReceiver(), event.getWorld());
onCurrencyAdd(currencyAddEvent);
event.setTransferred(currencyAddEvent.isAdded());
}
@EventHandler
public void onCurrencyHoldCheck(CurrencyHoldEvent event) {
if (event.getAccount() == null || !transactionCanFail()) {
return;
}
final OfflinePlayer lastSeen = Bukkit.getOfflinePlayer(event.getAccount());
if (lastSeen == null || !provided()) {
event.canHold(false);
return;
}
final String world = event.getWorld().getName();
if (!economyAPI.hasAccount(event.getAccount())) {
event.canHold(false);
return;
}
if (!economyAPI.addHoldings(event.getAccount(), event.getAmount(), world)) {
event.canHold(false);
return;
}
economyAPI.removeHoldings(event.getAccount(), event.getAmount(), world);
}
}

View File

@ -37,7 +37,14 @@ public class VaultListener implements Listener {
public static Economy getProvider() { return provider; }
public boolean transactionCanFail() {
return provider.getName().equals("Gringotts") || provider.getName().equals("GoldIsMoney") || provider.getName().equals("MultiCurrency");
if (provider == null) {
return false;
}
return provider.getName().equals("Gringotts")
|| provider.getName().equals("GoldIsMoney")
|| provider.getName().equals("MultiCurrency")
|| provider.getName().equalsIgnoreCase("TheNewEconomy");
}
/**
@ -139,7 +146,8 @@ public class VaultListener implements Listener {
OfflinePlayer lastSeen = Bukkit.getOfflinePlayer(event.getTarget());
if (lastSeen != null) {
provider.depositPlayer(lastSeen, world.getName(), event.getDoubleAmount());
EconomyResponse response = provider.depositPlayer(lastSeen, world.getName(), event.getDoubleAmount());
event.setAdded(response.type == EconomyResponse.ResponseType.SUCCESS);
}
}
@ -154,25 +162,28 @@ public class VaultListener implements Listener {
OfflinePlayer lastSeen = Bukkit.getOfflinePlayer(event.getTarget());
if (lastSeen != null) {
provider.withdrawPlayer(lastSeen, world.getName(), event.getDoubleAmount());
EconomyResponse response = provider.withdrawPlayer(lastSeen, world.getName(), event.getDoubleAmount());
event.setSubtracted(response.type == EconomyResponse.ResponseType.SUCCESS);
}
}
@EventHandler
public static void onCurrencyTransfer(CurrencyTransferEvent event) {
public void onCurrencyTransfer(CurrencyTransferEvent event) {
if (event.hasBeenTransferred()) {
return;
}
CurrencySubtractEvent currencySubtractEvent = new CurrencySubtractEvent(event.getAmount(), event.getSender(), event.getWorld());
ChestShop.callEvent(currencySubtractEvent);
onCurrencySubtraction(currencySubtractEvent);
if (!currencySubtractEvent.isSubtracted()) {
return;
}
CurrencyAddEvent currencyAddEvent = new CurrencyAddEvent(currencySubtractEvent.getAmount(), event.getReceiver(), event.getWorld());
ChestShop.callEvent(currencyAddEvent);
onCurrencyAdd(currencyAddEvent);
event.setTransferred(currencyAddEvent.isAdded());
}
@EventHandler

View File

@ -34,6 +34,8 @@ public class ServerAccountCorrector implements Listener {
CurrencyAddEvent currencyAddEvent = new CurrencyAddEvent(event.getAmount(), target, event.getWorld());
ChestShop.callEvent(currencyAddEvent);
event.setAdded(currencyAddEvent.isAdded());
}
@EventHandler(priority = EventPriority.LOWEST)
@ -54,6 +56,8 @@ public class ServerAccountCorrector implements Listener {
CurrencySubtractEvent currencySubtractEvent = new CurrencySubtractEvent(event.getAmount(), target, event.getWorld());
ChestShop.callEvent(currencySubtractEvent);
event.setSubtracted(currencySubtractEvent.isSubtracted());
}
@EventHandler(priority = EventPriority.LOWEST)

View File

@ -5,9 +5,9 @@ import com.Acrobot.ChestShop.Configuration.Messages;
import com.Acrobot.ChestShop.Configuration.Properties;
import com.Acrobot.ChestShop.Containers.AdminInventory;
import com.Acrobot.ChestShop.Database.Account;
import com.Acrobot.ChestShop.Events.Economy.AccountCheckEvent;
import com.Acrobot.ChestShop.Events.PreTransactionEvent;
import com.Acrobot.ChestShop.Events.TransactionEvent;
import com.Acrobot.ChestShop.Listeners.Economy.Plugins.VaultListener;
import com.Acrobot.ChestShop.Permission;
import com.Acrobot.ChestShop.Plugins.ChestShop;
import com.Acrobot.ChestShop.Security;
@ -147,9 +147,13 @@ public class PlayerInteract implements Listener {
boolean adminShop = ChestShopSign.isAdminShop(sign);
// check if player exists in economy
if (!adminShop && !VaultListener.getProvider().hasAccount(account.getName())) {
player.sendMessage(Messages.prefix(Messages.NO_ECONOMY_ACCOUNT));
return null;
if (!adminShop) {
AccountCheckEvent event = new AccountCheckEvent(account.getUuid(), player.getWorld());
Bukkit.getPluginManager().callEvent(event);
if(!event.hasAccount()) {
player.sendMessage(Messages.prefix(Messages.NO_ECONOMY_ACCOUNT));
return null;
}
}
Action buy = Properties.REVERSE_BUTTONS ? LEFT_CLICK_BLOCK : RIGHT_CLICK_BLOCK;

View File

@ -16,33 +16,60 @@ import static com.Acrobot.ChestShop.Events.TransactionEvent.TransactionType.SELL
* @author Acrobot
*/
public class EconomicModule implements Listener {
@EventHandler
@EventHandler(ignoreCancelled = true)
public static void onBuyTransaction(TransactionEvent event) {
if (event.getTransactionType() != BUY) {
return;
}
CurrencyAddEvent currencyAddEvent = new CurrencyAddEvent(BigDecimal.valueOf(event.getPrice()),
event.getOwnerAccount().getUuid(),
event.getSign().getWorld());
ChestShop.callEvent(currencyAddEvent); // java.lang.StackOverflowError
CurrencyAddEvent currencyAddEvent = new CurrencyAddEvent(
BigDecimal.valueOf(event.getPrice()),
event.getOwnerAccount().getUuid(),
event.getSign().getWorld());
ChestShop.callEvent(currencyAddEvent);
if (!currencyAddEvent.isAdded()) {
event.setCancelled(true);
return;
}
CurrencySubtractEvent currencySubtractEvent = new CurrencySubtractEvent(BigDecimal.valueOf(event.getPrice()), event.getClient());
ChestShop.callEvent(currencySubtractEvent);
if (!currencySubtractEvent.isSubtracted()) {
event.setCancelled(true);
CurrencySubtractEvent currencyResetEvent = new CurrencySubtractEvent(
BigDecimal.valueOf(event.getPrice()),
event.getOwnerAccount().getUuid(),
event.getSign().getWorld());
ChestShop.callEvent(currencyResetEvent);
}
}
@EventHandler
@EventHandler(ignoreCancelled = true)
public static void onSellTransaction(TransactionEvent event) {
if (event.getTransactionType() != SELL) {
return;
}
CurrencySubtractEvent currencySubtractEvent = new CurrencySubtractEvent(BigDecimal.valueOf(event.getPrice()),
event.getOwnerAccount().getUuid(),
event.getSign().getWorld());
CurrencySubtractEvent currencySubtractEvent = new CurrencySubtractEvent(
BigDecimal.valueOf(event.getPrice()),
event.getOwnerAccount().getUuid(),
event.getSign().getWorld());
ChestShop.callEvent(currencySubtractEvent);
if (!currencySubtractEvent.isSubtracted()) {
event.setCancelled(true);
return;
}
CurrencyAddEvent currencyAddEvent = new CurrencyAddEvent(BigDecimal.valueOf(event.getPrice()), event.getClient());
ChestShop.callEvent(currencyAddEvent);
if (!currencyAddEvent.isAdded()) {
event.setCancelled(true);
CurrencyAddEvent currencyResetEvent = new CurrencyAddEvent(
BigDecimal.valueOf(event.getPrice()),
event.getOwnerAccount().getUuid(),
event.getSign().getWorld());
ChestShop.callEvent(currencyResetEvent);
}
}
}

View File

@ -21,7 +21,7 @@ import org.bukkit.inventory.ItemStack;
*/
public class EmptyShopDeleter implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public static void onTransaction(TransactionEvent event) {
if (event.getTransactionType() != TransactionEvent.TransactionType.BUY) {
return;

View File

@ -4,6 +4,7 @@ import com.Acrobot.Breeze.Utils.InventoryUtil;
import com.Acrobot.ChestShop.Configuration.Properties;
import com.Acrobot.ChestShop.Events.TransactionEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
@ -15,7 +16,7 @@ import static com.Acrobot.ChestShop.Events.TransactionEvent.TransactionType.SELL
* @author Acrobot
*/
public class ItemManager implements Listener {
@EventHandler
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public static void shopItemRemover(TransactionEvent event) {
if (event.getTransactionType() != BUY) {
return;
@ -27,7 +28,7 @@ public class ItemManager implements Listener {
event.getClient().updateInventory();
}
@EventHandler
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public static void inventoryItemRemover(TransactionEvent event) {
if (event.getTransactionType() != SELL) {
return;

View File

@ -19,7 +19,7 @@ public class TransactionLogger implements Listener {
private static final String BUY_MESSAGE = "%1$s bought %2$s for %3$.2f from %4$s at %5$s";
private static final String SELL_MESSAGE = "%1$s sold %2$s for %3$.2f to %4$s at %5$s";
@EventHandler(priority = EventPriority.MONITOR)
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public static void onTransaction(final TransactionEvent event) {
String template = (event.getTransactionType() == BUY ? BUY_MESSAGE : SELL_MESSAGE);

View File

@ -24,7 +24,7 @@ import java.util.UUID;
* @author Acrobot
*/
public class TransactionMessageSender implements Listener {
@EventHandler(priority = EventPriority.MONITOR)
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public static void onTransaction(TransactionEvent event) {
if (event.getTransactionType() == TransactionEvent.TransactionType.BUY) {
sendBuyMessage(event);

View File

@ -1,4 +1,4 @@
package com.Acrobot.ChestShop.Listeners.PostShopCreation;
package com.Acrobot.ChestShop.Listeners.PreShopCreation;
import com.Acrobot.ChestShop.ChestShop;
import com.Acrobot.ChestShop.Configuration.Messages;
@ -6,12 +6,13 @@ import com.Acrobot.ChestShop.Configuration.Properties;
import com.Acrobot.ChestShop.Economy.Economy;
import com.Acrobot.ChestShop.Events.Economy.CurrencyAddEvent;
import com.Acrobot.ChestShop.Events.Economy.CurrencySubtractEvent;
import com.Acrobot.ChestShop.Events.ShopCreatedEvent;
import com.Acrobot.ChestShop.Events.PreShopCreationEvent;
import com.Acrobot.ChestShop.Permission;
import com.Acrobot.ChestShop.Signs.ChestShopSign;
import com.Acrobot.ChestShop.UUIDs.NameManager;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import java.math.BigDecimal;
@ -24,8 +25,8 @@ import static com.Acrobot.ChestShop.Signs.ChestShopSign.NAME_LINE;
*/
public class CreationFeeGetter implements Listener {
@EventHandler
public static void onShopCreation(ShopCreatedEvent event) {
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public static void onShopCreation(PreShopCreationEvent event) {
double shopCreationPrice = Properties.SHOP_CREATION_PRICE;
if (shopCreationPrice == 0) {
@ -45,6 +46,12 @@ public class CreationFeeGetter implements Listener {
CurrencySubtractEvent subtractionEvent = new CurrencySubtractEvent(BigDecimal.valueOf(shopCreationPrice), player);
ChestShop.callEvent(subtractionEvent);
if (!subtractionEvent.isSubtracted()) {
event.setOutcome(PreShopCreationEvent.CreationOutcome.NOT_ENOUGH_MONEY);
event.setSignLines(new String[4]);
return;
}
if (NameManager.getServerEconomyAccount() != null) {
CurrencyAddEvent currencyAddEvent = new CurrencyAddEvent(
BigDecimal.valueOf(shopCreationPrice),

View File

@ -24,26 +24,39 @@ public class PermissionChecker implements Listener {
public static void onPreShopCreation(PreShopCreationEvent event) {
Player player = event.getPlayer();
if (Permission.has(player, ADMIN)) {
return;
}
String priceLine = event.getSignLine(PRICE_LINE);
String itemLine = event.getSignLine(ITEM_LINE);
ItemStack item = MaterialUtil.getItem(itemLine);
if (item == null || Permission.has(player, SHOP_CREATION_ID + item.getType().toString().toLowerCase())) {
if (item == null) {
if (!Permission.has(player, SHOP_CREATION)) {
event.setOutcome(NO_PERMISSION);
}
return;
}
if (PriceUtil.hasBuyPrice(priceLine) && !Permission.has(player, SHOP_CREATION_BUY)) {
String matID = item.getType().toString().toLowerCase();
if (PriceUtil.hasBuyPrice(priceLine)) {
if (Permission.has(player, SHOP_CREATION_BUY_ID + matID)) {
return;
}
if (Permission.has(player, SHOP_CREATION) || (Permission.has(player, SHOP_CREATION_ID + matID) && Permission.has(player, SHOP_CREATION_BUY))) {
return;
}
event.setOutcome(NO_PERMISSION);
return;
}
if (PriceUtil.hasSellPrice(priceLine) && !Permission.has(player, SHOP_CREATION_SELL)) {
if (PriceUtil.hasSellPrice(priceLine)) {
if (Permission.has(player, SHOP_CREATION_SELL_ID + matID)) {
return;
}
if (Permission.has(player, SHOP_CREATION) || (Permission.has(player, SHOP_CREATION_ID + matID) && Permission.has(player, SHOP_CREATION_SELL))) {
return;
}
event.setOutcome(NO_PERMISSION);
return;
}
}
}

View File

@ -1,5 +1,6 @@
package com.Acrobot.ChestShop;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -8,8 +9,12 @@ import org.bukkit.entity.Player;
*/
public enum Permission {
SHOP_CREATION_BUY("ChestShop.shop.create.buy"),
SHOP_CREATION_SELL("ChestShop.shop.create.sell"),
SHOP_CREATION_BUY_ID("ChestShop.shop.create.buy."),
SHOP_CREATION_SELL("ChestShop.shop.create.sell"),
SHOP_CREATION_SELL_ID("ChestShop.shop.create.sell."),
SHOP_CREATION("ChestShop.shop.create"),
SHOP_CREATION_ID("ChestShop.shop.create."),
BUY("ChestShop.shop.buy"),
@ -54,6 +59,21 @@ public enum Permission {
return sender.isPermissionSet(permission) && sender.hasPermission(permission);
}
public static org.bukkit.permissions.Permission getPermission(Permission permission) {
org.bukkit.permissions.Permission bukkitPerm = Bukkit.getServer().getPluginManager().getPermission(permission.permission);
if (bukkitPerm == null) {
bukkitPerm = permission.getPermission();
try {
Bukkit.getServer().getPluginManager().addPermission(bukkitPerm);
} catch (IllegalArgumentException ignored) {} // this should never happen
}
return bukkitPerm;
}
public org.bukkit.permissions.Permission getPermission() {
return new org.bukkit.permissions.Permission(permission);
}
public String toString() {
return permission;
}

View File

@ -4,8 +4,7 @@ version: '${bukkit.plugin.version}'
author: Acrobot
authors: ['https://github.com/ChestShop-authors/ChestShop-3/contributors']
description: A chest shop for economy plugins.
depend: [Vault]
softdepend: [LWC, Lockette, Deadbolt, OddItem, WorldGuard, Heroes, SimpleChestLock, Residence, ShowItem]
softdepend: [Vault, Reserve, LWC, Lockette, Deadbolt, OddItem, WorldGuard, Heroes, SimpleChestLock, Residence, ShowItem]
commands:
iteminfo:
@ -47,10 +46,14 @@ permissions:
ChestShop.shop.create.sell: true
ChestShop.shop.create.buy:
description: Allows the user to create a shop that sells any item
ChestShop.shop.create.buy.(itemType):
description: Allows the user to create a shop that sells items with itemType like in the permission node (replace (itemType) with Material item name)
ChestShop.shop.create.sell:
description: Allows the user to create a shop that buy any item
description: Allows the user to create a shop that buys any item
ChestShop.shop.create.sell.(itemType):
description: Allows the user to create a shop that buys items with itemType like in the permission node (replace (itemType) with Material item name)
ChestShop.shop.create.(itemType):
description: Allows user to create a shop that sells item with itemType like in the permission node (replace (itemType) with Material item name)
description: Allows user to create a shop that sells items with itemType like in the permission node (replace (itemType) with Material item name)
ChestShop.shop.buy.(itemType):
description: Allows user to buy certain (itemType) from a shop (replace (itemType) with the Material item name)
ChestShop.shop.sell.(itemType):