mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2025-02-18 19:11:19 +01:00
Switch Vault from names to UUIDs
This commit is contained in:
parent
a158b7eb4a
commit
9fa2f92ef8
@ -39,7 +39,6 @@ import com.Acrobot.ChestShop.UUIDs.NameManager;
|
|||||||
import com.Acrobot.ChestShop.Updater.Updater;
|
import com.Acrobot.ChestShop.Updater.Updater;
|
||||||
import com.avaje.ebean.EbeanServer;
|
import com.avaje.ebean.EbeanServer;
|
||||||
import com.lennardf1989.bukkitex.Database;
|
import com.lennardf1989.bukkitex.Database;
|
||||||
import com.nijikokun.register.payment.forChestShop.Methods;
|
|
||||||
import org.apache.logging.log4j.Level;
|
import org.apache.logging.log4j.Level;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Marker;
|
import org.apache.logging.log4j.Marker;
|
||||||
@ -105,8 +104,6 @@ public class ChestShop extends JavaPlugin {
|
|||||||
|
|
||||||
NameManager.load();
|
NameManager.load();
|
||||||
|
|
||||||
Methods.setPreferred(Properties.PREFERRED_ECONOMY_PLUGIN);
|
|
||||||
|
|
||||||
Dependencies.loadPlugins();
|
Dependencies.loadPlugins();
|
||||||
|
|
||||||
registerEvents();
|
registerEvents();
|
||||||
|
@ -11,6 +11,7 @@ import org.bukkit.World;
|
|||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Acrobot
|
* @author Acrobot
|
||||||
@ -25,21 +26,21 @@ public class Economy {
|
|||||||
return !ChestShopSign.isAdminShop(inventory) || !getServerAccountName().isEmpty();
|
return !ChestShopSign.isAdminShop(inventory) || !getServerAccountName().isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean add(String name, World world, double amount) {
|
public static boolean add(UUID name, World world, double amount) {
|
||||||
CurrencyAddEvent event = new CurrencyAddEvent(BigDecimal.valueOf(amount), name, world);
|
CurrencyAddEvent event = new CurrencyAddEvent(BigDecimal.valueOf(amount), name, world);
|
||||||
ChestShop.callEvent(event);
|
ChestShop.callEvent(event);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean subtract(String name, World world, double amount) {
|
public static boolean subtract(UUID name, World world, double amount) {
|
||||||
CurrencySubtractEvent event = new CurrencySubtractEvent(BigDecimal.valueOf(amount), name, world);
|
CurrencySubtractEvent event = new CurrencySubtractEvent(BigDecimal.valueOf(amount), name, world);
|
||||||
ChestShop.callEvent(event);
|
ChestShop.callEvent(event);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasEnough(String name, World world, double amount) {
|
public static boolean hasEnough(UUID name, World world, double amount) {
|
||||||
CurrencyCheckEvent event = new CurrencyCheckEvent(BigDecimal.valueOf(amount), name, world);
|
CurrencyCheckEvent event = new CurrencyCheckEvent(BigDecimal.valueOf(amount), name, world);
|
||||||
ChestShop.callEvent(event);
|
ChestShop.callEvent(event);
|
||||||
|
|
||||||
|
@ -4,6 +4,8 @@ import org.bukkit.World;
|
|||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks for the existence of an account
|
* Checks for the existence of an account
|
||||||
*
|
*
|
||||||
@ -14,15 +16,15 @@ public class AccountCheckEvent extends Event {
|
|||||||
|
|
||||||
boolean outcome;
|
boolean outcome;
|
||||||
|
|
||||||
private String account;
|
private UUID account;
|
||||||
private World world;
|
private World world;
|
||||||
|
|
||||||
public AccountCheckEvent(String account, World world) {
|
public AccountCheckEvent(UUID account, World world) {
|
||||||
this.account = account;
|
this.account = account;
|
||||||
this.world = world;
|
this.world = world;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AccountCheckEvent(String account) {
|
public AccountCheckEvent(UUID account) {
|
||||||
this.account = account;
|
this.account = account;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +47,7 @@ public class AccountCheckEvent extends Event {
|
|||||||
/**
|
/**
|
||||||
* @return Account which is being checked
|
* @return Account which is being checked
|
||||||
*/
|
*/
|
||||||
public String getAccount() {
|
public UUID getAccount() {
|
||||||
return account;
|
return account;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package com.Acrobot.ChestShop.Events.Economy;
|
package com.Acrobot.ChestShop.Events.Economy;
|
||||||
|
|
||||||
import com.Acrobot.ChestShop.UUIDs.NameManager;
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an addition of goods to entity
|
* Represents an addition of goods to entity
|
||||||
@ -19,17 +19,17 @@ public class CurrencyAddEvent extends Event {
|
|||||||
boolean added;
|
boolean added;
|
||||||
|
|
||||||
private BigDecimal amount;
|
private BigDecimal amount;
|
||||||
private String target;
|
private UUID target;
|
||||||
private World world;
|
private World world;
|
||||||
|
|
||||||
public CurrencyAddEvent(BigDecimal amount, String target, World world) {
|
public CurrencyAddEvent(BigDecimal amount, UUID target, World world) {
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
this.target = target;
|
this.target = target;
|
||||||
this.world = world;
|
this.world = world;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CurrencyAddEvent(BigDecimal amount, Player target) {
|
public CurrencyAddEvent(BigDecimal amount, Player target) {
|
||||||
this(amount, NameManager.getUsername(target.getUniqueId()), target.getWorld());
|
this(amount, target.getUniqueId(), target.getWorld());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -92,7 +92,7 @@ public class CurrencyAddEvent extends Event {
|
|||||||
/**
|
/**
|
||||||
* @return Account from which the currency is subtracted
|
* @return Account from which the currency is subtracted
|
||||||
*/
|
*/
|
||||||
public String getTarget() {
|
public UUID getTarget() {
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package com.Acrobot.ChestShop.Events.Economy;
|
package com.Acrobot.ChestShop.Events.Economy;
|
||||||
|
|
||||||
import com.Acrobot.ChestShop.UUIDs.NameManager;
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks the amount of currency available
|
* Checks the amount of currency available
|
||||||
@ -17,16 +17,16 @@ public class CurrencyAmountEvent extends Event {
|
|||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
private BigDecimal amount = BigDecimal.ZERO;
|
private BigDecimal amount = BigDecimal.ZERO;
|
||||||
private String account;
|
private UUID account;
|
||||||
private World world;
|
private World world;
|
||||||
|
|
||||||
public CurrencyAmountEvent(String account, World world) {
|
public CurrencyAmountEvent(UUID account, World world) {
|
||||||
this.account = account;
|
this.account = account;
|
||||||
this.world = world;
|
this.world = world;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CurrencyAmountEvent(Player player) {
|
public CurrencyAmountEvent(Player player) {
|
||||||
this(NameManager.getUsername(player.getUniqueId()), player.getWorld());
|
this(player.getUniqueId(), player.getWorld());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -73,7 +73,7 @@ public class CurrencyAmountEvent extends Event {
|
|||||||
/**
|
/**
|
||||||
* @return Account that is checked
|
* @return Account that is checked
|
||||||
*/
|
*/
|
||||||
public String getAccount() {
|
public UUID getAccount() {
|
||||||
return account;
|
return account;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package com.Acrobot.ChestShop.Events.Economy;
|
package com.Acrobot.ChestShop.Events.Economy;
|
||||||
|
|
||||||
import com.Acrobot.ChestShop.UUIDs.NameManager;
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a check for the existence of specified currency amount
|
* Represents a check for the existence of specified currency amount
|
||||||
@ -19,17 +19,17 @@ public class CurrencyCheckEvent extends Event {
|
|||||||
boolean outcome;
|
boolean outcome;
|
||||||
|
|
||||||
private BigDecimal amount;
|
private BigDecimal amount;
|
||||||
private String account;
|
private UUID account;
|
||||||
private World world;
|
private World world;
|
||||||
|
|
||||||
public CurrencyCheckEvent(BigDecimal amount, String account, World world) {
|
public CurrencyCheckEvent(BigDecimal amount, UUID account, World world) {
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
this.account = account;
|
this.account = account;
|
||||||
this.world = world;
|
this.world = world;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CurrencyCheckEvent(BigDecimal amount, Player player) {
|
public CurrencyCheckEvent(BigDecimal amount, Player player) {
|
||||||
this(amount, NameManager.getUsername(player.getUniqueId()), player.getWorld());
|
this(amount, player.getUniqueId(), player.getWorld());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -92,7 +92,7 @@ public class CurrencyCheckEvent extends Event {
|
|||||||
/**
|
/**
|
||||||
* @return Account that is checked
|
* @return Account that is checked
|
||||||
*/
|
*/
|
||||||
public String getAccount() {
|
public UUID getAccount() {
|
||||||
return account;
|
return account;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ public class CurrencyCheckEvent extends Event {
|
|||||||
*
|
*
|
||||||
* @param account Account name
|
* @param account Account name
|
||||||
*/
|
*/
|
||||||
public void setAccount(String account) {
|
public void setAccount(UUID account) {
|
||||||
this.account = account;
|
this.account = account;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package com.Acrobot.ChestShop.Events.Economy;
|
package com.Acrobot.ChestShop.Events.Economy;
|
||||||
|
|
||||||
import com.Acrobot.ChestShop.UUIDs.NameManager;
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the account can hold the amount of currency
|
* Checks if the account can hold the amount of currency
|
||||||
@ -19,17 +19,17 @@ public class CurrencyHoldEvent extends Event {
|
|||||||
boolean canHold = true;
|
boolean canHold = true;
|
||||||
|
|
||||||
private BigDecimal amount;
|
private BigDecimal amount;
|
||||||
private String account;
|
private UUID account;
|
||||||
private World world;
|
private World world;
|
||||||
|
|
||||||
public CurrencyHoldEvent(BigDecimal amount, String account, World world) {
|
public CurrencyHoldEvent(BigDecimal amount, UUID account, World world) {
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
this.account = account;
|
this.account = account;
|
||||||
this.world = world;
|
this.world = world;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CurrencyHoldEvent(BigDecimal amount, Player target) {
|
public CurrencyHoldEvent(BigDecimal amount, Player target) {
|
||||||
this(amount, NameManager.getUsername(target.getUniqueId()), target.getWorld());
|
this(amount, target.getUniqueId(), target.getWorld());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -92,7 +92,7 @@ public class CurrencyHoldEvent extends Event {
|
|||||||
/**
|
/**
|
||||||
* @return Account that is checked
|
* @return Account that is checked
|
||||||
*/
|
*/
|
||||||
public String getAccount() {
|
public UUID getAccount() {
|
||||||
return account;
|
return account;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ public class CurrencyHoldEvent extends Event {
|
|||||||
*
|
*
|
||||||
* @param account Account name
|
* @param account Account name
|
||||||
*/
|
*/
|
||||||
public void setAccount(String account) {
|
public void setAccount(UUID account) {
|
||||||
this.account = account;
|
this.account = account;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package com.Acrobot.ChestShop.Events.Economy;
|
package com.Acrobot.ChestShop.Events.Economy;
|
||||||
|
|
||||||
import com.Acrobot.ChestShop.UUIDs.NameManager;
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a subtraction of goods from entity
|
* Represents a subtraction of goods from entity
|
||||||
@ -19,17 +19,17 @@ public class CurrencySubtractEvent extends Event {
|
|||||||
boolean subtracted;
|
boolean subtracted;
|
||||||
|
|
||||||
private BigDecimal amount;
|
private BigDecimal amount;
|
||||||
private String target;
|
private UUID target;
|
||||||
private World world;
|
private World world;
|
||||||
|
|
||||||
public CurrencySubtractEvent(BigDecimal amount, String target, World world) {
|
public CurrencySubtractEvent(BigDecimal amount, UUID target, World world) {
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
this.target = target;
|
this.target = target;
|
||||||
this.world = world;
|
this.world = world;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CurrencySubtractEvent(BigDecimal amount, Player target) {
|
public CurrencySubtractEvent(BigDecimal amount, Player target) {
|
||||||
this(amount, NameManager.getUsername(target.getUniqueId()), target.getWorld());
|
this(amount, target.getUniqueId(), target.getWorld());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -92,7 +92,7 @@ public class CurrencySubtractEvent extends Event {
|
|||||||
/**
|
/**
|
||||||
* @return Account from which the currency is subtracted
|
* @return Account from which the currency is subtracted
|
||||||
*/
|
*/
|
||||||
public String getTarget() {
|
public UUID getTarget() {
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import org.bukkit.event.Event;
|
|||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a transaction of goods between two entities
|
* Represents a transaction of goods between two entities
|
||||||
@ -16,11 +17,11 @@ public class CurrencyTransferEvent extends Event {
|
|||||||
|
|
||||||
private BigDecimal amount;
|
private BigDecimal amount;
|
||||||
private World world;
|
private World world;
|
||||||
private String sender;
|
private UUID sender;
|
||||||
private String receiver;
|
private UUID receiver;
|
||||||
private boolean success;
|
private boolean success;
|
||||||
|
|
||||||
public CurrencyTransferEvent(BigDecimal amount, String sender, String receiver, World world) {
|
public CurrencyTransferEvent(BigDecimal amount, UUID sender, UUID receiver, World world) {
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
this.world = world;
|
this.world = world;
|
||||||
|
|
||||||
@ -28,7 +29,7 @@ public class CurrencyTransferEvent extends Event {
|
|||||||
this.receiver = receiver;
|
this.receiver = receiver;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CurrencyTransferEvent(double amount, String sender, String receiver, World world) {
|
public CurrencyTransferEvent(double amount, UUID sender, UUID receiver, World world) {
|
||||||
this(BigDecimal.valueOf(amount), sender, receiver, world);
|
this(BigDecimal.valueOf(amount), sender, receiver, world);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,14 +93,14 @@ public class CurrencyTransferEvent extends Event {
|
|||||||
/**
|
/**
|
||||||
* @return Sender of the money
|
* @return Sender of the money
|
||||||
*/
|
*/
|
||||||
public String getSender() {
|
public UUID getSender() {
|
||||||
return sender;
|
return sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Receiver of the money
|
* @return Receiver of the money
|
||||||
*/
|
*/
|
||||||
public String getReceiver() {
|
public UUID getReceiver() {
|
||||||
return receiver;
|
return receiver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ public class VaultListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
double balance = provider.getBalance(event.getAccount(), event.getWorld().getName());
|
double balance = provider.getBalance(Bukkit.getOfflinePlayer(event.getAccount()), event.getWorld().getName());
|
||||||
|
|
||||||
if (balance > Double.MAX_VALUE) {
|
if (balance > Double.MAX_VALUE) {
|
||||||
balance = Double.MAX_VALUE;
|
balance = Double.MAX_VALUE;
|
||||||
@ -77,7 +77,7 @@ public class VaultListener implements Listener {
|
|||||||
|
|
||||||
World world = event.getWorld();
|
World world = event.getWorld();
|
||||||
|
|
||||||
if (provider.has(event.getAccount(), world.getName(), event.getDoubleAmount())) {
|
if (provider.has(Bukkit.getOfflinePlayer(event.getAccount()), world.getName(), event.getDoubleAmount())) {
|
||||||
event.hasEnough(true);
|
event.hasEnough(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,7 +90,7 @@ public class VaultListener implements Listener {
|
|||||||
|
|
||||||
World world = event.getWorld();
|
World world = event.getWorld();
|
||||||
|
|
||||||
if (!provider.hasAccount(event.getAccount(), world.getName())) {
|
if (!provider.hasAccount(Bukkit.getOfflinePlayer(event.getAccount()), world.getName())) {
|
||||||
event.hasAccount(false);
|
event.hasAccount(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -114,7 +114,7 @@ public class VaultListener implements Listener {
|
|||||||
|
|
||||||
World world = event.getWorld();
|
World world = event.getWorld();
|
||||||
|
|
||||||
provider.depositPlayer(event.getTarget(), world.getName(), event.getDoubleAmount());
|
provider.depositPlayer(Bukkit.getOfflinePlayer(event.getTarget()), world.getName(), event.getDoubleAmount());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -125,7 +125,7 @@ public class VaultListener implements Listener {
|
|||||||
|
|
||||||
World world = event.getWorld();
|
World world = event.getWorld();
|
||||||
|
|
||||||
provider.withdrawPlayer(event.getTarget(), world.getName(), event.getDoubleAmount());
|
provider.withdrawPlayer(Bukkit.getOfflinePlayer(event.getTarget()), world.getName(), event.getDoubleAmount());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -147,22 +147,22 @@ public class VaultListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onCurrencyHoldCheck(CurrencyHoldEvent event) {
|
public void onCurrencyHoldCheck(CurrencyHoldEvent event) {
|
||||||
if (event.getAccount().isEmpty() || !transactionCanFail()) {
|
if (event.getAccount() == null || !transactionCanFail()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!provider.hasAccount(event.getAccount(), event.getWorld().getName())) {
|
if (!provider.hasAccount(Bukkit.getOfflinePlayer(event.getAccount()), event.getWorld().getName())) {
|
||||||
event.canHold(false);
|
event.canHold(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
EconomyResponse response = provider.depositPlayer(event.getAccount(), event.getWorld().getName(), event.getDoubleAmount());
|
EconomyResponse response = provider.depositPlayer(Bukkit.getOfflinePlayer(event.getAccount()), event.getWorld().getName(), event.getDoubleAmount());
|
||||||
|
|
||||||
if (!response.transactionSuccess()) {
|
if (!response.transactionSuccess()) {
|
||||||
event.canHold(false);
|
event.canHold(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
provider.withdrawPlayer(event.getAccount(), event.getWorld().getName(), event.getDoubleAmount());
|
provider.withdrawPlayer(Bukkit.getOfflinePlayer(event.getAccount()), event.getWorld().getName(), event.getDoubleAmount());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,14 @@ package com.Acrobot.ChestShop.Listeners.Economy;
|
|||||||
|
|
||||||
import com.Acrobot.ChestShop.ChestShop;
|
import com.Acrobot.ChestShop.ChestShop;
|
||||||
import com.Acrobot.ChestShop.Events.Economy.*;
|
import com.Acrobot.ChestShop.Events.Economy.*;
|
||||||
import com.Acrobot.ChestShop.Signs.ChestShopSign;
|
import com.Acrobot.ChestShop.UUIDs.NameManager;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import static com.Acrobot.ChestShop.Configuration.Properties.SERVER_ECONOMY_ACCOUNT;
|
import static com.Acrobot.ChestShop.Configuration.Properties.SERVER_ECONOMY_ACCOUNT;
|
||||||
|
|
||||||
@ -18,9 +20,9 @@ public class ServerAccountCorrector implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public static void onCurrencyAdd(CurrencyAddEvent event) {
|
public static void onCurrencyAdd(CurrencyAddEvent event) {
|
||||||
String target = event.getTarget();
|
UUID target = event.getTarget();
|
||||||
|
|
||||||
if (!ChestShopSign.isAdminShop(target) || event.getTarget().equals(SERVER_ECONOMY_ACCOUNT)) {
|
if (!NameManager.isAdminShop(target) || Bukkit.getOfflinePlayer(target).getName().equals(SERVER_ECONOMY_ACCOUNT)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,7 +30,7 @@ public class ServerAccountCorrector implements Listener {
|
|||||||
event.setAdded(true);
|
event.setAdded(true);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
target = SERVER_ECONOMY_ACCOUNT;
|
target = Bukkit.getOfflinePlayer(SERVER_ECONOMY_ACCOUNT).getUniqueId();
|
||||||
}
|
}
|
||||||
|
|
||||||
event.setAdded(true);
|
event.setAdded(true);
|
||||||
@ -39,9 +41,9 @@ public class ServerAccountCorrector implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public static void onCurrencySubtract(CurrencySubtractEvent event) {
|
public static void onCurrencySubtract(CurrencySubtractEvent event) {
|
||||||
String target = event.getTarget();
|
UUID target = event.getTarget();
|
||||||
|
|
||||||
if (!ChestShopSign.isAdminShop(target) || event.getTarget().equals(SERVER_ECONOMY_ACCOUNT)) {
|
if (!NameManager.isAdminShop(target) || Bukkit.getOfflinePlayer(target).getName().equals(SERVER_ECONOMY_ACCOUNT)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,7 +51,7 @@ public class ServerAccountCorrector implements Listener {
|
|||||||
event.setSubtracted(true);
|
event.setSubtracted(true);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
target = SERVER_ECONOMY_ACCOUNT;
|
target = Bukkit.getOfflinePlayer(SERVER_ECONOMY_ACCOUNT).getUniqueId();
|
||||||
}
|
}
|
||||||
|
|
||||||
event.setSubtracted(true);
|
event.setSubtracted(true);
|
||||||
@ -60,9 +62,9 @@ public class ServerAccountCorrector implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public static void onCurrencyCheck(CurrencyCheckEvent event) {
|
public static void onCurrencyCheck(CurrencyCheckEvent event) {
|
||||||
String target = event.getAccount();
|
UUID target = event.getAccount();
|
||||||
|
|
||||||
if (!ChestShopSign.isAdminShop(target) || event.getAccount().equals(SERVER_ECONOMY_ACCOUNT)) {
|
if (!NameManager.isAdminShop(target) || Bukkit.getOfflinePlayer(target).getName().equals(SERVER_ECONOMY_ACCOUNT)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +72,7 @@ public class ServerAccountCorrector implements Listener {
|
|||||||
event.hasEnough(true);
|
event.hasEnough(true);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
target = SERVER_ECONOMY_ACCOUNT;
|
target = Bukkit.getOfflinePlayer(SERVER_ECONOMY_ACCOUNT).getUniqueId();
|
||||||
}
|
}
|
||||||
|
|
||||||
CurrencyCheckEvent currencyCheckEvent = new CurrencyCheckEvent(event.getAmount(), target, event.getWorld());
|
CurrencyCheckEvent currencyCheckEvent = new CurrencyCheckEvent(event.getAmount(), target, event.getWorld());
|
||||||
@ -81,21 +83,21 @@ public class ServerAccountCorrector implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public static void onCurrencyHoldCheck(CurrencyHoldEvent event) {
|
public static void onCurrencyHoldCheck(CurrencyHoldEvent event) {
|
||||||
String target = event.getAccount();
|
UUID target = event.getAccount();
|
||||||
|
|
||||||
if (!ChestShopSign.isAdminShop(target) || event.getAccount().equals(SERVER_ECONOMY_ACCOUNT)) {
|
if (!NameManager.isAdminShop(target) || Bukkit.getOfflinePlayer(target).getName().equals(SERVER_ECONOMY_ACCOUNT)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
event.canHold(true);
|
event.canHold(true);
|
||||||
event.setAccount("");
|
event.setAccount(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public static void onBalanceCheck(CurrencyAmountEvent event) {
|
public static void onBalanceCheck(CurrencyAmountEvent event) {
|
||||||
String target = event.getAccount();
|
UUID target = event.getAccount();
|
||||||
|
|
||||||
if (!ChestShopSign.isAdminShop(target) || event.getAccount().equals(SERVER_ECONOMY_ACCOUNT)) {
|
if (!NameManager.isAdminShop(target) || Bukkit.getOfflinePlayer(target).getName().equals(SERVER_ECONOMY_ACCOUNT)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,7 +105,7 @@ public class ServerAccountCorrector implements Listener {
|
|||||||
event.setAmount(BigDecimal.valueOf(Double.MAX_VALUE));
|
event.setAmount(BigDecimal.valueOf(Double.MAX_VALUE));
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
target = SERVER_ECONOMY_ACCOUNT;
|
target = Bukkit.getOfflinePlayer(SERVER_ECONOMY_ACCOUNT).getUniqueId();
|
||||||
}
|
}
|
||||||
|
|
||||||
CurrencyAmountEvent currencyAmountEvent = new CurrencyAmountEvent(target, event.getWorld());
|
CurrencyAmountEvent currencyAmountEvent = new CurrencyAmountEvent(target, event.getWorld());
|
||||||
|
@ -4,12 +4,14 @@ import com.Acrobot.ChestShop.ChestShop;
|
|||||||
import com.Acrobot.ChestShop.Configuration.Properties;
|
import com.Acrobot.ChestShop.Configuration.Properties;
|
||||||
import com.Acrobot.ChestShop.Economy.Economy;
|
import com.Acrobot.ChestShop.Economy.Economy;
|
||||||
import com.Acrobot.ChestShop.Events.Economy.CurrencyAddEvent;
|
import com.Acrobot.ChestShop.Events.Economy.CurrencyAddEvent;
|
||||||
import com.Acrobot.ChestShop.Signs.ChestShopSign;
|
import com.Acrobot.ChestShop.UUIDs.NameManager;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Acrobot
|
* @author Acrobot
|
||||||
@ -20,8 +22,8 @@ public class TaxModule implements Listener {
|
|||||||
return price.multiply(BigDecimal.valueOf(taxAmount).divide(BigDecimal.valueOf(100)));
|
return price.multiply(BigDecimal.valueOf(taxAmount).divide(BigDecimal.valueOf(100)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isServerAccount(String name) {
|
private static boolean isServerAccount(UUID name) {
|
||||||
return ChestShopSign.isAdminShop(name);
|
return NameManager.isAdminShop(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW)
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
@ -30,9 +32,9 @@ public class TaxModule implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String target = event.getTarget();
|
UUID target = event.getTarget();
|
||||||
|
|
||||||
if (target.equals(Economy.getServerAccountName())) {
|
if (Bukkit.getOfflinePlayer(target).getName().equals(Economy.getServerAccountName())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +47,7 @@ public class TaxModule implements Listener {
|
|||||||
BigDecimal tax = getTax(event.getAmount(), taxAmount);
|
BigDecimal tax = getTax(event.getAmount(), taxAmount);
|
||||||
|
|
||||||
if (!Economy.getServerAccountName().isEmpty()) {
|
if (!Economy.getServerAccountName().isEmpty()) {
|
||||||
CurrencyAddEvent currencyAddEvent = new CurrencyAddEvent(tax, Economy.getServerAccountName(), event.getWorld());
|
CurrencyAddEvent currencyAddEvent = new CurrencyAddEvent(tax, Bukkit.getOfflinePlayer(Economy.getServerAccountName()).getUniqueId(), event.getWorld());
|
||||||
ChestShop.callEvent(currencyAddEvent);
|
ChestShop.callEvent(currencyAddEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ import com.Acrobot.ChestShop.ChestShop;
|
|||||||
import com.Acrobot.ChestShop.Events.Economy.CurrencyAddEvent;
|
import com.Acrobot.ChestShop.Events.Economy.CurrencyAddEvent;
|
||||||
import com.Acrobot.ChestShop.Events.Economy.CurrencySubtractEvent;
|
import com.Acrobot.ChestShop.Events.Economy.CurrencySubtractEvent;
|
||||||
import com.Acrobot.ChestShop.Events.TransactionEvent;
|
import com.Acrobot.ChestShop.Events.TransactionEvent;
|
||||||
import com.Acrobot.ChestShop.UUIDs.NameManager;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
@ -24,7 +23,7 @@ public class EconomicModule implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CurrencyAddEvent currencyAddEvent = new CurrencyAddEvent(BigDecimal.valueOf(event.getPrice()),
|
CurrencyAddEvent currencyAddEvent = new CurrencyAddEvent(BigDecimal.valueOf(event.getPrice()),
|
||||||
NameManager.getUsername(event.getOwner().getUniqueId()),
|
event.getOwner().getUniqueId(),
|
||||||
event.getSign().getWorld());
|
event.getSign().getWorld());
|
||||||
ChestShop.callEvent(currencyAddEvent);
|
ChestShop.callEvent(currencyAddEvent);
|
||||||
|
|
||||||
@ -39,7 +38,7 @@ public class EconomicModule implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CurrencySubtractEvent currencySubtractEvent = new CurrencySubtractEvent(BigDecimal.valueOf(event.getPrice()),
|
CurrencySubtractEvent currencySubtractEvent = new CurrencySubtractEvent(BigDecimal.valueOf(event.getPrice()),
|
||||||
NameManager.getUsername(event.getOwner().getUniqueId()),
|
event.getOwner().getUniqueId(),
|
||||||
event.getSign().getWorld());
|
event.getSign().getWorld());
|
||||||
ChestShop.callEvent(currencySubtractEvent);
|
ChestShop.callEvent(currencySubtractEvent);
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ import com.Acrobot.Breeze.Utils.InventoryUtil;
|
|||||||
import com.Acrobot.ChestShop.ChestShop;
|
import com.Acrobot.ChestShop.ChestShop;
|
||||||
import com.Acrobot.ChestShop.Events.Economy.CurrencyCheckEvent;
|
import com.Acrobot.ChestShop.Events.Economy.CurrencyCheckEvent;
|
||||||
import com.Acrobot.ChestShop.Events.PreTransactionEvent;
|
import com.Acrobot.ChestShop.Events.PreTransactionEvent;
|
||||||
import com.Acrobot.ChestShop.UUIDs.NameManager;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
@ -53,7 +52,7 @@ public class AmountAndPriceChecker implements Listener {
|
|||||||
Inventory clientInventory = event.getClientInventory();
|
Inventory clientInventory = event.getClientInventory();
|
||||||
|
|
||||||
CurrencyCheckEvent currencyCheckEvent = new CurrencyCheckEvent(BigDecimal.valueOf(event.getPrice()),
|
CurrencyCheckEvent currencyCheckEvent = new CurrencyCheckEvent(BigDecimal.valueOf(event.getPrice()),
|
||||||
NameManager.getUsername(event.getOwner().getUniqueId()),
|
event.getOwner().getUniqueId(),
|
||||||
event.getSign().getWorld());
|
event.getSign().getWorld());
|
||||||
ChestShop.callEvent(currencyCheckEvent);
|
ChestShop.callEvent(currencyCheckEvent);
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ import com.Acrobot.ChestShop.Events.Economy.CurrencyAmountEvent;
|
|||||||
import com.Acrobot.ChestShop.Events.Economy.CurrencyCheckEvent;
|
import com.Acrobot.ChestShop.Events.Economy.CurrencyCheckEvent;
|
||||||
import com.Acrobot.ChestShop.Events.Economy.CurrencyHoldEvent;
|
import com.Acrobot.ChestShop.Events.Economy.CurrencyHoldEvent;
|
||||||
import com.Acrobot.ChestShop.Events.PreTransactionEvent;
|
import com.Acrobot.ChestShop.Events.PreTransactionEvent;
|
||||||
import com.Acrobot.ChestShop.UUIDs.NameManager;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
@ -19,6 +18,7 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import static com.Acrobot.ChestShop.Events.PreTransactionEvent.TransactionOutcome.*;
|
import static com.Acrobot.ChestShop.Events.PreTransactionEvent.TransactionOutcome.*;
|
||||||
import static com.Acrobot.ChestShop.Events.TransactionEvent.TransactionType.BUY;
|
import static com.Acrobot.ChestShop.Events.TransactionEvent.TransactionType.BUY;
|
||||||
@ -61,7 +61,7 @@ public class PartialTransactionModule implements Listener {
|
|||||||
event.setStock(getCountedItemStack(stock, amountAffordable));
|
event.setStock(getCountedItemStack(stock, amountAffordable));
|
||||||
}
|
}
|
||||||
|
|
||||||
String seller = NameManager.getUsername(event.getOwner().getUniqueId());
|
UUID seller = event.getOwner().getUniqueId();
|
||||||
|
|
||||||
CurrencyHoldEvent currencyHoldEvent = new CurrencyHoldEvent(BigDecimal.valueOf(price), seller, client.getWorld());
|
CurrencyHoldEvent currencyHoldEvent = new CurrencyHoldEvent(BigDecimal.valueOf(price), seller, client.getWorld());
|
||||||
ChestShop.callEvent(currencyHoldEvent);
|
ChestShop.callEvent(currencyHoldEvent);
|
||||||
@ -94,19 +94,19 @@ public class PartialTransactionModule implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Player client = event.getClient();
|
Player client = event.getClient();
|
||||||
String ownerName = NameManager.getUsername(event.getOwner().getUniqueId());
|
UUID owner = event.getOwner().getUniqueId();
|
||||||
ItemStack[] stock = event.getStock();
|
ItemStack[] stock = event.getStock();
|
||||||
|
|
||||||
double price = event.getPrice();
|
double price = event.getPrice();
|
||||||
double pricePerItem = event.getPrice() / InventoryUtil.countItems(stock);
|
double pricePerItem = event.getPrice() / InventoryUtil.countItems(stock);
|
||||||
|
|
||||||
CurrencyAmountEvent currencyAmountEvent = new CurrencyAmountEvent(ownerName, client.getWorld());
|
CurrencyAmountEvent currencyAmountEvent = new CurrencyAmountEvent(owner, client.getWorld());
|
||||||
ChestShop.callEvent(currencyAmountEvent);
|
ChestShop.callEvent(currencyAmountEvent);
|
||||||
|
|
||||||
BigDecimal walletMoney = currencyAmountEvent.getAmount();
|
BigDecimal walletMoney = currencyAmountEvent.getAmount();
|
||||||
|
|
||||||
if (Economy.isOwnerEconomicallyActive(event.getOwnerInventory())) {
|
if (Economy.isOwnerEconomicallyActive(event.getOwnerInventory())) {
|
||||||
CurrencyCheckEvent currencyCheckEvent = new CurrencyCheckEvent(BigDecimal.valueOf(price), ownerName, client.getWorld());
|
CurrencyCheckEvent currencyCheckEvent = new CurrencyCheckEvent(BigDecimal.valueOf(price), owner, client.getWorld());
|
||||||
ChestShop.callEvent(currencyCheckEvent);
|
ChestShop.callEvent(currencyCheckEvent);
|
||||||
|
|
||||||
if (!currencyCheckEvent.hasEnough()) {
|
if (!currencyCheckEvent.hasEnough()) {
|
||||||
|
@ -13,6 +13,7 @@ import org.bukkit.event.EventPriority;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import static com.Acrobot.ChestShop.Permission.NOFEE;
|
import static com.Acrobot.ChestShop.Permission.NOFEE;
|
||||||
import static com.Acrobot.ChestShop.Signs.ChestShopSign.NAME_LINE;
|
import static com.Acrobot.ChestShop.Signs.ChestShopSign.NAME_LINE;
|
||||||
@ -29,7 +30,7 @@ public class ShopRefundListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String owner = NameManager.getFullUsername(event.getSign().getLine(NAME_LINE));
|
UUID owner = NameManager.getUUID(event.getSign().getLine(NAME_LINE));
|
||||||
|
|
||||||
CurrencyAddEvent currencyEvent = new CurrencyAddEvent(BigDecimal.valueOf(refundPrice), owner, event.getSign().getWorld());
|
CurrencyAddEvent currencyEvent = new CurrencyAddEvent(BigDecimal.valueOf(refundPrice), owner, event.getSign().getWorld());
|
||||||
ChestShop.callEvent(currencyEvent);
|
ChestShop.callEvent(currencyEvent);
|
||||||
|
@ -158,6 +158,10 @@ public class NameManager {
|
|||||||
return shortenedName.equals(name) || Permission.otherName(player, name);
|
return shortenedName.equals(name) || Permission.otherName(player, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isAdminShop(UUID uuid) {
|
||||||
|
return getUsername(uuid).equals(Properties.ADMIN_SHOP_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
public static void load() {
|
public static void load() {
|
||||||
File databaseFile = ChestShop.loadFile("users.db");
|
File databaseFile = ChestShop.loadFile("users.db");
|
||||||
String uri = ConnectionManager.getURI(databaseFile);
|
String uri = ConnectionManager.getURI(databaseFile);
|
||||||
|
Loading…
Reference in New Issue
Block a user