mirror of
https://github.com/Crazy-Crew/CrazyAuctions.git
synced 2025-01-21 21:31:40 +01:00
add new filemanager
This commit is contained in:
parent
f794bb9409
commit
e502057fb9
@ -1,25 +1,23 @@
|
||||
package com.badbones69.crazyauctions;
|
||||
|
||||
import com.badbones69.crazyauctions.api.CrazyManager;
|
||||
import com.badbones69.crazyauctions.api.FileManager;
|
||||
import com.badbones69.crazyauctions.api.enums.Files;
|
||||
import com.badbones69.crazyauctions.api.enums.Messages;
|
||||
import com.badbones69.crazyauctions.api.support.PluginSupport;
|
||||
import com.badbones69.crazyauctions.api.support.MetricsWrapper;
|
||||
import com.badbones69.crazyauctions.commands.AuctionCommand;
|
||||
import com.badbones69.crazyauctions.commands.AuctionTab;
|
||||
import com.badbones69.crazyauctions.controllers.GuiListener;
|
||||
import com.badbones69.crazyauctions.controllers.MarcoListener;
|
||||
import com.badbones69.crazyauctions.currency.VaultSupport;
|
||||
import com.ryderbelserion.vital.paper.files.config.FileManager;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Base64;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
@ -42,7 +40,7 @@ public class CrazyAuctions extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
if (!PluginSupport.VAULT.isPluginEnabled()) {
|
||||
if (!getServer().getPluginManager().isPluginEnabled("Vault")) {
|
||||
getLogger().severe("Vault was not found so the plugin will now disable.");
|
||||
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
@ -55,9 +53,13 @@ public class CrazyAuctions extends JavaPlugin {
|
||||
this.fileManager = new FileManager();
|
||||
this.crazyManager = new CrazyManager();
|
||||
|
||||
this.fileManager.setup();
|
||||
this.fileManager.addFile("config.yml")
|
||||
.addFile("data.yml")
|
||||
.addFile("messages.yml")
|
||||
.addFile("test-file.yml")
|
||||
.init();
|
||||
|
||||
FileConfiguration configuration = FileManager.Files.DATA.getFile();
|
||||
FileConfiguration configuration = Files.data.getConfiguration();
|
||||
|
||||
if (configuration.contains("OutOfTime/Cancelled")) {
|
||||
for (String key : configuration.getConfigurationSection("OutOfTime/Cancelled").getKeys(false)) {
|
||||
@ -66,7 +68,7 @@ public class CrazyAuctions extends JavaPlugin {
|
||||
if (itemStack != null) {
|
||||
configuration.set("OutOfTime/Cancelled." + key + ".Item", Base64.getEncoder().encodeToString(itemStack.serializeAsBytes()));
|
||||
|
||||
FileManager.Files.DATA.saveFile();
|
||||
Files.data.save();
|
||||
}
|
||||
|
||||
final String uuid = configuration.getString("OutOfTime/Cancelled." + key + ".Seller");
|
||||
@ -76,7 +78,7 @@ public class CrazyAuctions extends JavaPlugin {
|
||||
|
||||
configuration.set("OutOfTime/Cancelled." + key + ".Seller", player.getUniqueId().toString());
|
||||
|
||||
FileManager.Files.DATA.saveFile();
|
||||
Files.data.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -88,7 +90,7 @@ public class CrazyAuctions extends JavaPlugin {
|
||||
if (itemStack != null) {
|
||||
configuration.set("Items." + key + ".Item", Base64.getEncoder().encodeToString(itemStack.serializeAsBytes()));
|
||||
|
||||
FileManager.Files.DATA.saveFile();
|
||||
Files.data.save();
|
||||
}
|
||||
|
||||
final String uuid = configuration.getString("Items." + key + ".Seller");
|
||||
@ -99,7 +101,7 @@ public class CrazyAuctions extends JavaPlugin {
|
||||
if (!uuid.equals(player.getUniqueId().toString())) {
|
||||
configuration.set("Items." + key + ".Seller", player.getUniqueId().toString());
|
||||
|
||||
FileManager.Files.DATA.saveFile();
|
||||
Files.data.save();
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,7 +113,7 @@ public class CrazyAuctions extends JavaPlugin {
|
||||
if (!bidder.equals(player.getUniqueId().toString())) {
|
||||
configuration.set("Items." + key + ".TopBidder", player.getUniqueId().toString());
|
||||
|
||||
FileManager.Files.DATA.saveFile();
|
||||
Files.data.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -160,30 +162,15 @@ public class CrazyAuctions extends JavaPlugin {
|
||||
if (this.crazyManager != null) this.crazyManager.unload();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Timer getTimer() {
|
||||
return this.timer;
|
||||
}
|
||||
|
||||
public VaultSupport getSupport() {
|
||||
public final VaultSupport getSupport() {
|
||||
return this.support;
|
||||
}
|
||||
|
||||
public MetricsWrapper getMetrics() {
|
||||
return this.metrics;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CrazyManager getCrazyManager() {
|
||||
public final CrazyManager getCrazyManager() {
|
||||
return this.crazyManager;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public FileManager getFileManager() {
|
||||
public final FileManager getFileManager() {
|
||||
return this.fileManager;
|
||||
}
|
||||
|
||||
public boolean isLogging() {
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package com.badbones69.crazyauctions;
|
||||
|
||||
import com.badbones69.crazyauctions.api.FileManager.Files;
|
||||
import com.badbones69.crazyauctions.api.enums.Files;
|
||||
import com.badbones69.crazyauctions.api.enums.Messages;
|
||||
import com.badbones69.crazyauctions.api.events.AuctionExpireEvent;
|
||||
import com.badbones69.crazyauctions.api.events.AuctionWinBidEvent;
|
||||
@ -10,7 +10,6 @@ import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@ -33,11 +32,11 @@ public class Methods {
|
||||
}
|
||||
|
||||
public static String getPrefix() {
|
||||
return color(Files.CONFIG.getFile().getString("Settings.Prefix", ""));
|
||||
return color(Files.config.getConfiguration().getString("Settings.Prefix", ""));
|
||||
}
|
||||
|
||||
public static String getPrefix(String msg) {
|
||||
return color(Files.CONFIG.getFile().getString("Settings.Prefix", "") + msg);
|
||||
return color(Files.config.getConfiguration().getString("Settings.Prefix", "") + msg);
|
||||
}
|
||||
|
||||
public static String removeColor(String msg) {
|
||||
@ -109,13 +108,13 @@ public class Methods {
|
||||
}
|
||||
}
|
||||
|
||||
p.sendMessage(Messages.NOT_ONLINE.getMessage());
|
||||
p.sendMessage(Messages.NOT_ONLINE.getMessage(p));
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean hasPermission(Player player, String perm) {
|
||||
if (!player.hasPermission("crazyauctions." + perm)) {
|
||||
player.sendMessage(Messages.NO_PERMISSION.getMessage());
|
||||
player.sendMessage(Messages.NO_PERMISSION.getMessage(player));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -125,7 +124,7 @@ public class Methods {
|
||||
public static boolean hasPermission(CommandSender sender, String perm) {
|
||||
if (sender instanceof Player player) {
|
||||
if (!player.hasPermission("crazyauctions." + perm)) {
|
||||
player.sendMessage(Messages.NO_PERMISSION.getMessage());
|
||||
player.sendMessage(Messages.NO_PERMISSION.getMessage(player));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -229,7 +228,7 @@ public class Methods {
|
||||
}
|
||||
|
||||
public static void updateAuction() {
|
||||
FileConfiguration data = Files.DATA.getFile();
|
||||
FileConfiguration data = Files.data.getConfiguration();
|
||||
Calendar cal = Calendar.getInstance();
|
||||
Calendar expireTime = Calendar.getInstance();
|
||||
Calendar fullExpireTime = Calendar.getInstance();
|
||||
@ -271,12 +270,16 @@ public class Methods {
|
||||
if (isOnline(winner) && getPlayer(winner) != null) {
|
||||
Player player = getPlayer(winner);
|
||||
Bukkit.getPluginManager().callEvent(new AuctionWinBidEvent(player, Methods.fromBase64(data.getString("Items." + i + ".Item")), price));
|
||||
player.sendMessage(Messages.WIN_BIDDING.getMessage(placeholders));
|
||||
if (player != null) {
|
||||
player.sendMessage(Messages.WIN_BIDDING.getMessage(player, placeholders));
|
||||
}
|
||||
}
|
||||
|
||||
if (isOnline(seller) && getPlayer(seller) != null) {
|
||||
Player player = getPlayer(seller);
|
||||
player.sendMessage(Messages.SOMEONE_WON_PLAYERS_BID.getMessage(placeholders));
|
||||
if (player != null) {
|
||||
player.sendMessage(Messages.SOMEONE_WON_PLAYERS_BID.getMessage(player, placeholders));
|
||||
}
|
||||
}
|
||||
|
||||
data.set("OutOfTime/Cancelled." + num + ".Seller", winner);
|
||||
@ -287,8 +290,8 @@ public class Methods {
|
||||
String seller = data.getString("Items." + i + ".Seller");
|
||||
Player player = getPlayer(seller);
|
||||
|
||||
if (isOnline(seller) && getPlayer(seller) != null) {
|
||||
player.sendMessage(Messages.ITEM_HAS_EXPIRED.getMessage());
|
||||
if (isOnline(seller) && player != null) {
|
||||
player.sendMessage(Messages.ITEM_HAS_EXPIRED.getMessage(player));
|
||||
}
|
||||
|
||||
AuctionExpireEvent event = new AuctionExpireEvent(player, Methods.fromBase64(data.getString("Items." + i + ".Item")));
|
||||
@ -305,19 +308,23 @@ public class Methods {
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldSave) Files.DATA.saveFile();
|
||||
if (shouldSave) Files.data.save();
|
||||
}
|
||||
|
||||
public static String getPrice(String ID, Boolean Expired) {
|
||||
long price = 0L;
|
||||
|
||||
if (Expired) {
|
||||
if (Files.DATA.getFile().contains("OutOfTime/Cancelled." + ID + ".Price")) {
|
||||
price = Files.DATA.getFile().getLong("OutOfTime/Cancelled." + ID + ".Price");
|
||||
FileConfiguration configuration = Files.data.getConfiguration();
|
||||
|
||||
if (configuration.contains("OutOfTime/Cancelled." + ID + ".Price")) {
|
||||
price = configuration.getLong("OutOfTime/Cancelled." + ID + ".Price");
|
||||
}
|
||||
} else {
|
||||
if (Files.DATA.getFile().contains("Items." + ID + ".Price")) {
|
||||
price = Files.DATA.getFile().getLong("Items." + ID + ".Price");
|
||||
FileConfiguration configuration = Files.data.getConfiguration();
|
||||
|
||||
if (configuration.contains("Items." + ID + ".Price")) {
|
||||
price = configuration.getLong("Items." + ID + ".Price");
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.badbones69.crazyauctions.api;
|
||||
|
||||
import com.badbones69.crazyauctions.Methods;
|
||||
import com.badbones69.crazyauctions.api.FileManager.Files;
|
||||
import com.badbones69.crazyauctions.api.enums.Files;
|
||||
import com.badbones69.crazyauctions.api.enums.ShopType;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -14,13 +14,13 @@ public class CrazyManager {
|
||||
private boolean biddingEnabled;
|
||||
|
||||
public void load() {
|
||||
this.sellingEnabled = Files.CONFIG.getFile().getBoolean("Settings.Feature-Toggle.Selling", true);
|
||||
this.sellingEnabled = Files.config.getConfiguration().getBoolean("Settings.Feature-Toggle.Selling", true);
|
||||
|
||||
this.biddingEnabled = Files.CONFIG.getFile().getBoolean("Settings.Feature-Toggle.Bidding", true);
|
||||
this.biddingEnabled = Files.config.getConfiguration().getBoolean("Settings.Feature-Toggle.Bidding", true);
|
||||
}
|
||||
|
||||
public void unload() {
|
||||
Files.DATA.saveFile();
|
||||
Files.data.save();
|
||||
}
|
||||
|
||||
public boolean isSellingEnabled() {
|
||||
@ -32,7 +32,7 @@ public class CrazyManager {
|
||||
}
|
||||
|
||||
public ArrayList<ItemStack> getItems(Player player, ShopType type) {
|
||||
FileConfiguration data = Files.DATA.getFile();
|
||||
FileConfiguration data = Files.data.getConfiguration();
|
||||
ArrayList<ItemStack> items = new ArrayList<>();
|
||||
|
||||
if (data.contains("Items")) {
|
@ -0,0 +1,52 @@
|
||||
package com.badbones69.crazyauctions.api.enums;
|
||||
|
||||
import com.badbones69.crazyauctions.CrazyAuctions;
|
||||
import com.ryderbelserion.vital.paper.files.config.FileManager;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public enum Files {
|
||||
|
||||
config("config.yml"),
|
||||
messages("messages.yml"),
|
||||
test_file("test-file.yml"),
|
||||
data("data.yml");
|
||||
|
||||
private final String fileName;
|
||||
private final String strippedName;
|
||||
|
||||
private @NotNull final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class);
|
||||
|
||||
private @NotNull final FileManager fileManager = this.plugin.getFileManager();
|
||||
|
||||
/**
|
||||
* A constructor to build a file
|
||||
*
|
||||
* @param fileName the name of the file
|
||||
*/
|
||||
Files(final String fileName) {
|
||||
this.fileName = fileName;
|
||||
this.strippedName = this.fileName.replace(".yml", "");
|
||||
}
|
||||
|
||||
public final YamlConfiguration getConfiguration() {
|
||||
return this.fileManager.getFile(this.fileName);
|
||||
}
|
||||
|
||||
public final String getStrippedName() {
|
||||
return this.strippedName;
|
||||
}
|
||||
|
||||
public final String getFileName() {
|
||||
return this.fileName;
|
||||
}
|
||||
|
||||
public void save() {
|
||||
this.fileManager.saveFile(this.fileName);
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
this.fileManager.reloadFile(this.fileName);
|
||||
}
|
||||
}
|
@ -1,8 +1,11 @@
|
||||
package com.badbones69.crazyauctions.api.enums;
|
||||
|
||||
import com.badbones69.crazyauctions.Methods;
|
||||
import com.badbones69.crazyauctions.api.FileManager.Files;
|
||||
import com.ryderbelserion.vital.paper.enums.Support;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -58,25 +61,29 @@ public enum Messages {
|
||||
private String defaultMessage;
|
||||
private List<String> defaultListMessage;
|
||||
|
||||
Messages(String path, String defaultMessage) {
|
||||
Messages(final String path, final String defaultMessage) {
|
||||
this.path = path;
|
||||
this.defaultMessage = defaultMessage;
|
||||
}
|
||||
|
||||
Messages(String path, List<String> defaultListMessage) {
|
||||
Messages(final String path, final List<String> defaultListMessage) {
|
||||
this.path = path;
|
||||
this.defaultListMessage = defaultListMessage;
|
||||
}
|
||||
|
||||
public static final FileConfiguration messages = Files.messages.getConfiguration();
|
||||
|
||||
public static String convertList(List<String> list) {
|
||||
String message = "";
|
||||
public static String convertList(final List<String> list) {
|
||||
StringBuilder message = new StringBuilder();
|
||||
|
||||
for (String m : list) {
|
||||
message += Methods.color(m) + "\n";
|
||||
message.append(Methods.color(m)).append("\n");
|
||||
}
|
||||
return message;
|
||||
|
||||
return message.toString();
|
||||
}
|
||||
|
||||
public static String convertList(List<String> list, Map<String, String> placeholders) {
|
||||
public static String convertList(final List<String> list, final Map<String, String> placeholders) {
|
||||
String message = convertList(list);
|
||||
|
||||
for (String ph : placeholders.keySet()) {
|
||||
@ -87,11 +94,12 @@ public enum Messages {
|
||||
}
|
||||
|
||||
public static void addMissingMessages() {
|
||||
FileConfiguration messages = Files.MESSAGES.getFile();
|
||||
boolean saveFile = false;
|
||||
|
||||
for (Messages message : values()) {
|
||||
if (!messages.contains("Messages." + message.getPath())) {
|
||||
saveFile = true;
|
||||
|
||||
if (message.getDefaultMessage() != null) {
|
||||
messages.set("Messages." + message.getPath(), message.getDefaultMessage());
|
||||
} else {
|
||||
@ -101,83 +109,35 @@ public enum Messages {
|
||||
}
|
||||
|
||||
if (saveFile) {
|
||||
Files.MESSAGES.saveFile();
|
||||
Files.messages.save();
|
||||
}
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
if (isList()) {
|
||||
if (exists()) {
|
||||
return Methods.color(convertList(Files.MESSAGES.getFile().getStringList("Messages." + path)));
|
||||
} else {
|
||||
return Methods.color(convertList(getDefaultListMessage()));
|
||||
}
|
||||
} else {
|
||||
if (exists()) {
|
||||
return Methods.getPrefix(Files.MESSAGES.getFile().getString("Messages." + path));
|
||||
} else {
|
||||
return Methods.getPrefix(getDefaultMessage());
|
||||
}
|
||||
}
|
||||
public String getMessage(final CommandSender sender) {
|
||||
return getMessage(sender, new HashMap<>());
|
||||
}
|
||||
|
||||
public String getMessage(Map<String, String> placeholders) {
|
||||
public String getMessage(final CommandSender sender, final Map<String, String> placeholders) {
|
||||
String message;
|
||||
|
||||
if (isList()) {
|
||||
if (exists()) {
|
||||
message = Methods.color(convertList(Files.MESSAGES.getFile().getStringList("Messages." + path), placeholders));
|
||||
message = Methods.color(convertList(messages.getStringList("Messages." + this.path), placeholders));
|
||||
} else {
|
||||
message = Methods.color(convertList(getDefaultListMessage(), placeholders));
|
||||
}
|
||||
} else {
|
||||
if (exists()) {
|
||||
message = Methods.getPrefix(Files.MESSAGES.getFile().getString("Messages." + path));
|
||||
message = Methods.getPrefix(messages.getString("Messages." + this.path));
|
||||
} else {
|
||||
message = Methods.getPrefix(getDefaultMessage());
|
||||
}
|
||||
|
||||
for (String ph : placeholders.keySet()) {
|
||||
if (message.contains(ph)) {
|
||||
message = message.replace(ph, placeholders.get(ph)).replace(ph, placeholders.get(ph).toLowerCase());
|
||||
if (sender instanceof Player player) {
|
||||
if (Support.placeholder_api.isEnabled()) {
|
||||
message = PlaceholderAPI.setPlaceholders(player, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
public String getMessageNoPrefix() {
|
||||
if (isList()) {
|
||||
if (exists()) {
|
||||
return Methods.color(convertList(Files.MESSAGES.getFile().getStringList("Messages." + path)));
|
||||
} else {
|
||||
return Methods.color(convertList(getDefaultListMessage()));
|
||||
}
|
||||
} else {
|
||||
if (exists()) {
|
||||
return Methods.color(Files.MESSAGES.getFile().getString("Messages." + path));
|
||||
} else {
|
||||
return Methods.color(getDefaultMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getMessageNoPrefix(HashMap<String, String> placeholders) {
|
||||
String message;
|
||||
|
||||
if (isList()) {
|
||||
if (exists()) {
|
||||
message = Methods.color(convertList(Files.MESSAGES.getFile().getStringList("Messages." + path), placeholders));
|
||||
} else {
|
||||
message = Methods.color(convertList(getDefaultListMessage(), placeholders));
|
||||
}
|
||||
} else {
|
||||
if (exists()) {
|
||||
message = Methods.color(Files.MESSAGES.getFile().getString("Messages." + path));
|
||||
} else {
|
||||
message = Methods.color(getDefaultMessage());
|
||||
}
|
||||
|
||||
for (String ph : placeholders.keySet()) {
|
||||
if (message.contains(ph)) {
|
||||
@ -189,27 +149,27 @@ public enum Messages {
|
||||
return message;
|
||||
}
|
||||
|
||||
private Boolean exists() {
|
||||
return Files.MESSAGES.getFile().contains("Messages." + path);
|
||||
private boolean exists() {
|
||||
return messages.contains("Messages." + this.path);
|
||||
}
|
||||
|
||||
private Boolean isList() {
|
||||
if (Files.MESSAGES.getFile().contains("Messages." + path)) {
|
||||
return !Files.MESSAGES.getFile().getStringList("Messages." + path).isEmpty();
|
||||
private boolean isList() {
|
||||
if (messages.contains("Messages." + this.path)) {
|
||||
return !messages.getStringList("Messages." + this.path).isEmpty();
|
||||
} else {
|
||||
return defaultMessage == null;
|
||||
return this.defaultMessage == null;
|
||||
}
|
||||
}
|
||||
|
||||
private String getPath() {
|
||||
return path;
|
||||
return this.path;
|
||||
}
|
||||
|
||||
private String getDefaultMessage() {
|
||||
return defaultMessage;
|
||||
return this.defaultMessage;
|
||||
}
|
||||
|
||||
private List<String> getDefaultListMessage() {
|
||||
return defaultListMessage;
|
||||
return this.defaultListMessage;
|
||||
}
|
||||
}
|
@ -3,13 +3,13 @@ package com.badbones69.crazyauctions.commands;
|
||||
import com.badbones69.crazyauctions.CrazyAuctions;
|
||||
import com.badbones69.crazyauctions.Methods;
|
||||
import com.badbones69.crazyauctions.api.CrazyManager;
|
||||
import com.badbones69.crazyauctions.api.FileManager;
|
||||
import com.badbones69.crazyauctions.api.FileManager.Files;
|
||||
import com.badbones69.crazyauctions.api.enums.Category;
|
||||
import com.badbones69.crazyauctions.api.enums.Files;
|
||||
import com.badbones69.crazyauctions.api.enums.Messages;
|
||||
import com.badbones69.crazyauctions.api.enums.ShopType;
|
||||
import com.badbones69.crazyauctions.api.events.AuctionListEvent;
|
||||
import com.badbones69.crazyauctions.controllers.GuiListener;
|
||||
import com.ryderbelserion.vital.paper.files.config.FileManager;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@ -18,13 +18,13 @@ import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.yaml.snakeyaml.error.YAMLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class AuctionCommand implements CommandExecutor {
|
||||
@ -37,12 +37,12 @@ public class AuctionCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String commandLabel, String[] args) {
|
||||
FileConfiguration config = Files.CONFIG.getFile();
|
||||
FileConfiguration data = Files.DATA.getFile();
|
||||
FileConfiguration config = Files.config.getConfiguration();
|
||||
FileConfiguration data = Files.data.getConfiguration();
|
||||
|
||||
if (args.length == 0) {
|
||||
if (!(sender instanceof Player player)) {
|
||||
sender.sendMessage(Messages.PLAYERS_ONLY.getMessage());
|
||||
sender.sendMessage(Messages.PLAYERS_ONLY.getMessage(sender));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -73,97 +73,21 @@ public class AuctionCommand implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
sender.sendMessage(Messages.HELP.getMessage());
|
||||
sender.sendMessage(Messages.HELP.getMessage(sender));
|
||||
return true;
|
||||
}
|
||||
|
||||
case "test" -> {
|
||||
if (!Methods.hasPermission(sender, "test")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int times = 1;
|
||||
|
||||
if (args.length >= 2) {
|
||||
if (!Methods.isInt(args[1])) {
|
||||
HashMap<String, String> placeholders = new HashMap<>();
|
||||
placeholders.put("%Arg%", args[1]);
|
||||
placeholders.put("%arg%", args[1]);
|
||||
sender.sendMessage(Messages.NOT_A_NUMBER.getMessage(placeholders));
|
||||
return true;
|
||||
}
|
||||
|
||||
times = Integer.parseInt(args[1]);
|
||||
}
|
||||
|
||||
int price = 10;
|
||||
int amount = 1;
|
||||
ItemStack item = Methods.getItemInHand((Player) sender);
|
||||
|
||||
if (item != null && item.getType() != Material.AIR) {
|
||||
// For testing as another player
|
||||
String seller = UUID.randomUUID().toString();
|
||||
|
||||
for (int it = 1; it <= times; it++) {
|
||||
int num = 1;
|
||||
|
||||
Random random = new Random();
|
||||
|
||||
for (; data.contains("Items." + num); num++) ;
|
||||
|
||||
data.set("Items." + num + ".Price", price);
|
||||
data.set("Items." + num + ".Seller", seller);
|
||||
|
||||
if (args[0].equalsIgnoreCase("bid")) {
|
||||
data.set("Items." + num + ".Time-Till-Expire", Methods.convertToMill(config.getString("Settings.Bid-Time", "2m 30s")));
|
||||
} else {
|
||||
data.set("Items." + num + ".Time-Till-Expire", Methods.convertToMill(config.getString("Settings.Sell-Time", "2d")));
|
||||
}
|
||||
|
||||
data.set("Items." + num + ".Full-Time", Methods.convertToMill(config.getString("Settings.Full-Expire-Time", "10d")));
|
||||
int id = random.nextInt(Integer.MAX_VALUE);
|
||||
|
||||
for (String i : data.getConfigurationSection("Items").getKeys(false))
|
||||
if (data.getInt("Items." + i + ".StoreID") == id)
|
||||
id = random.nextInt(Integer.MAX_VALUE);
|
||||
|
||||
data.set("Items." + num + ".StoreID", id);
|
||||
data.set("Items." + num + ".Biddable", args[0].equalsIgnoreCase("Bid"));
|
||||
data.set("Items." + num + ".TopBidder", "None");
|
||||
|
||||
ItemStack stack = item.clone();
|
||||
stack.setAmount(amount);
|
||||
|
||||
data.set("Items." + num + ".Item", Methods.toBase64(stack));
|
||||
}
|
||||
|
||||
Files.DATA.saveFile();
|
||||
|
||||
HashMap<String, String> placeholders = new HashMap<>();
|
||||
placeholders.put("%Price%", String.valueOf(price));
|
||||
placeholders.put("%price%", String.valueOf(price));
|
||||
|
||||
sender.sendMessage(Messages.ADDED_ITEM_TO_AUCTION.getMessage(placeholders));
|
||||
|
||||
if (item.getAmount() <= 1 || (item.getAmount() - amount) <= 0) {
|
||||
Methods.setItemInHand((Player) sender, new ItemStack(Material.AIR));
|
||||
} else {
|
||||
item.setAmount(item.getAmount() - amount);
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(Messages.DOESNT_HAVE_ITEM_IN_HAND.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
case "reload" -> {
|
||||
if (!Methods.hasPermission(sender, "reload")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
this.fileManager.setup();
|
||||
this.fileManager.reloadFiles();
|
||||
|
||||
this.fileManager.init();
|
||||
this.crazyManager.load();
|
||||
|
||||
sender.sendMessage(Messages.RELOAD.getMessage());
|
||||
sender.sendMessage(Messages.RELOAD.getMessage(sender));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -173,7 +97,7 @@ public class AuctionCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
if (!(sender instanceof Player player)) {
|
||||
sender.sendMessage(Messages.PLAYERS_ONLY.getMessage());
|
||||
sender.sendMessage(Messages.PLAYERS_ONLY.getMessage(sender));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -182,7 +106,7 @@ public class AuctionCommand implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
sender.sendMessage(Messages.CRAZYAUCTIONS_VIEW.getMessage());
|
||||
sender.sendMessage(Messages.CRAZYAUCTIONS_VIEW.getMessage(sender));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -192,7 +116,7 @@ public class AuctionCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
if (!(sender instanceof Player player)) {
|
||||
sender.sendMessage(Messages.PLAYERS_ONLY.getMessage());
|
||||
sender.sendMessage(Messages.PLAYERS_ONLY.getMessage(sender));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -204,7 +128,7 @@ public class AuctionCommand implements CommandExecutor {
|
||||
if (!Methods.hasPermission(sender, "access")) return true;
|
||||
|
||||
if (!(sender instanceof Player player)) {
|
||||
sender.sendMessage(Messages.PLAYERS_ONLY.getMessage());
|
||||
sender.sendMessage(Messages.PLAYERS_ONLY.getMessage(sender));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -214,14 +138,14 @@ public class AuctionCommand implements CommandExecutor {
|
||||
|
||||
case "sell", "bid" -> {
|
||||
if (!(sender instanceof Player player)) {
|
||||
sender.sendMessage(Messages.PLAYERS_ONLY.getMessage());
|
||||
sender.sendMessage(Messages.PLAYERS_ONLY.getMessage(sender));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length >= 2) {
|
||||
if (args[0].equalsIgnoreCase("sell")) {
|
||||
if (!crazyManager.isSellingEnabled()) {
|
||||
player.sendMessage(Messages.SELLING_DISABLED.getMessage());
|
||||
player.sendMessage(Messages.SELLING_DISABLED.getMessage(sender));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -230,7 +154,7 @@ public class AuctionCommand implements CommandExecutor {
|
||||
|
||||
if (args[0].equalsIgnoreCase("bid")) {
|
||||
if (!crazyManager.isBiddingEnabled()) {
|
||||
player.sendMessage(Messages.BIDDING_DISABLED.getMessage());
|
||||
player.sendMessage(Messages.BIDDING_DISABLED.getMessage(sender));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -245,7 +169,7 @@ public class AuctionCommand implements CommandExecutor {
|
||||
HashMap<String, String> placeholders = new HashMap<>();
|
||||
placeholders.put("%Arg%", args[2]);
|
||||
placeholders.put("%arg%", args[2]);
|
||||
player.sendMessage(Messages.NOT_A_NUMBER.getMessage(placeholders));
|
||||
player.sendMessage(Messages.NOT_A_NUMBER.getMessage(sender, placeholders));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -258,12 +182,12 @@ public class AuctionCommand implements CommandExecutor {
|
||||
HashMap<String, String> placeholders = new HashMap<>();
|
||||
placeholders.put("%Arg%", args[1]);
|
||||
placeholders.put("%arg%", args[1]);
|
||||
player.sendMessage(Messages.NOT_A_NUMBER.getMessage(placeholders));
|
||||
player.sendMessage(Messages.NOT_A_NUMBER.getMessage(sender, placeholders));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Methods.getItemInHand(player).getType() == Material.AIR) {
|
||||
player.sendMessage(Messages.DOESNT_HAVE_ITEM_IN_HAND.getMessage());
|
||||
player.sendMessage(Messages.DOESNT_HAVE_ITEM_IN_HAND.getMessage(sender));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -271,21 +195,21 @@ public class AuctionCommand implements CommandExecutor {
|
||||
|
||||
if (args[0].equalsIgnoreCase("bid")) {
|
||||
if (price < config.getLong("Settings.Minimum-Bid-Price", 100)) {
|
||||
player.sendMessage(Messages.BID_PRICE_TO_LOW.getMessage());
|
||||
player.sendMessage(Messages.BID_PRICE_TO_LOW.getMessage(sender));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (price > config.getLong("Settings.Max-Beginning-Bid-Price", 1000000)) {
|
||||
player.sendMessage(Messages.BID_PRICE_TO_HIGH.getMessage());
|
||||
player.sendMessage(Messages.BID_PRICE_TO_HIGH.getMessage(sender));
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (price < config.getLong("Settings.Minimum-Sell-Price", 10)) {
|
||||
player.sendMessage(Messages.SELL_PRICE_TO_LOW.getMessage());
|
||||
player.sendMessage(Messages.SELL_PRICE_TO_LOW.getMessage(sender));
|
||||
return true;
|
||||
}
|
||||
if (price > config.getLong("Settings.Max-Beginning-Sell-Price", 1000000)) {
|
||||
player.sendMessage(Messages.SELL_PRICE_TO_HIGH.getMessage());
|
||||
player.sendMessage(Messages.SELL_PRICE_TO_HIGH.getMessage(sender));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -333,37 +257,39 @@ public class AuctionCommand implements CommandExecutor {
|
||||
|
||||
if (args[0].equalsIgnoreCase("sell")) {
|
||||
if (crazyManager.getItems(player, ShopType.SELL).size() >= SellLimit) {
|
||||
player.sendMessage(Messages.MAX_ITEMS.getMessage());
|
||||
player.sendMessage(Messages.MAX_ITEMS.getMessage(sender));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("bid")) {
|
||||
if (crazyManager.getItems(player, ShopType.BID).size() >= BidLimit) {
|
||||
player.sendMessage(Messages.MAX_ITEMS.getMessage());
|
||||
player.sendMessage(Messages.MAX_ITEMS.getMessage(sender));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (config.getStringList("Settings.BlackList").contains(item.getType().getKey().getKey())) {
|
||||
player.sendMessage(Messages.ITEM_BLACKLISTED.getMessage());
|
||||
player.sendMessage(Messages.ITEM_BLACKLISTED.getMessage(sender));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!config.getBoolean("Settings.Allow-Damaged-Items", false)) {
|
||||
for (Material i : getDamageableItems()) {
|
||||
if (item.getType() == i) {
|
||||
if (item.getDurability() > 0) {
|
||||
player.sendMessage(Messages.ITEM_DAMAGED.getMessage());
|
||||
return true;
|
||||
if (item instanceof Damageable damageable) {
|
||||
if (damageable.getDamage() > 0) {
|
||||
player.sendMessage(Messages.ITEM_DAMAGED.getMessage(sender));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!allowBook(item)) {
|
||||
player.sendMessage(Messages.BOOK_NOT_ALLOWED.getMessage());
|
||||
player.sendMessage(Messages.BOOK_NOT_ALLOWED.getMessage(sender));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -408,7 +334,7 @@ public class AuctionCommand implements CommandExecutor {
|
||||
|
||||
data.set("Items." + num + ".Item", Methods.toBase64(stack));
|
||||
|
||||
Files.DATA.saveFile();
|
||||
Files.data.save();
|
||||
|
||||
this.plugin.getServer().getPluginManager().callEvent(new AuctionListEvent(player, type, stack, price));
|
||||
|
||||
@ -416,7 +342,7 @@ public class AuctionCommand implements CommandExecutor {
|
||||
|
||||
placeholders.put("%Price%", String.valueOf(price));
|
||||
placeholders.put("%price%", String.valueOf(price));
|
||||
player.sendMessage(Messages.ADDED_ITEM_TO_AUCTION.getMessage(placeholders));
|
||||
player.sendMessage(Messages.ADDED_ITEM_TO_AUCTION.getMessage(sender, placeholders));
|
||||
|
||||
if (item.getAmount() <= 1 || (item.getAmount() - amount) <= 0) {
|
||||
Methods.setItemInHand(player, new ItemStack(Material.AIR));
|
||||
@ -427,7 +353,7 @@ public class AuctionCommand implements CommandExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
sender.sendMessage(Messages.CRAZYAUCTIONS_SELL_BID.getMessage());
|
||||
sender.sendMessage(Messages.CRAZYAUCTIONS_SELL_BID.getMessage(sender));
|
||||
}
|
||||
|
||||
default -> {
|
||||
@ -501,12 +427,12 @@ public class AuctionCommand implements CommandExecutor {
|
||||
if (item != null && item.hasItemMeta() && item.getItemMeta() instanceof BookMeta bookMeta) {
|
||||
this.plugin.getLogger().info("Checking " + item.getType() + " for illegal unicode.");
|
||||
|
||||
FileConfiguration file = Files.TEST_FILE.getFile();
|
||||
FileConfiguration file = Files.test_file.getConfiguration();
|
||||
|
||||
try {
|
||||
file.set("Test", item);
|
||||
|
||||
Files.TEST_FILE.saveFile();
|
||||
Files.test_file.save();
|
||||
|
||||
this.plugin.getLogger().info(item.getType() + " has passed unicode checks.");
|
||||
} catch (YAMLException exception) {
|
@ -3,9 +3,9 @@ package com.badbones69.crazyauctions.controllers;
|
||||
import com.badbones69.crazyauctions.CrazyAuctions;
|
||||
import com.badbones69.crazyauctions.Methods;
|
||||
import com.badbones69.crazyauctions.api.*;
|
||||
import com.badbones69.crazyauctions.api.FileManager.Files;
|
||||
import com.badbones69.crazyauctions.api.builders.ItemBuilder;
|
||||
import com.badbones69.crazyauctions.api.enums.Category;
|
||||
import com.badbones69.crazyauctions.api.enums.Files;
|
||||
import com.badbones69.crazyauctions.api.enums.Messages;
|
||||
import com.badbones69.crazyauctions.api.enums.Reasons;
|
||||
import com.badbones69.crazyauctions.api.enums.ShopType;
|
||||
@ -48,14 +48,14 @@ public class GuiListener implements Listener {
|
||||
|
||||
public static void openShop(Player player, ShopType sell, Category cat, int page) {
|
||||
Methods.updateAuction();
|
||||
FileConfiguration config = Files.CONFIG.getFile();
|
||||
FileConfiguration data = Files.DATA.getFile();
|
||||
FileConfiguration config = Files.config.getConfiguration();
|
||||
FileConfiguration data = Files.data.getConfiguration();
|
||||
List<ItemStack> items = new ArrayList<>();
|
||||
List<Integer> ID = new ArrayList<>();
|
||||
|
||||
if (!data.contains("Items")) {
|
||||
data.set("Items.Clear", null);
|
||||
Files.DATA.saveFile();
|
||||
Files.data.save();
|
||||
}
|
||||
|
||||
if (cat != null) {
|
||||
@ -212,7 +212,7 @@ public class GuiListener implements Listener {
|
||||
|
||||
public static void openCategories(Player player, ShopType shop) {
|
||||
Methods.updateAuction();
|
||||
FileConfiguration config = Files.CONFIG.getFile();
|
||||
FileConfiguration config = Files.config.getConfiguration();
|
||||
|
||||
Inventory inv = plugin.getServer().createInventory(null, 54, Methods.color(config.getString("Settings.Categories")));
|
||||
List<String> options = new ArrayList<>();
|
||||
@ -254,8 +254,8 @@ public class GuiListener implements Listener {
|
||||
|
||||
public static void openPlayersCurrentList(Player player, int page) {
|
||||
Methods.updateAuction();
|
||||
FileConfiguration config = Files.CONFIG.getFile();
|
||||
FileConfiguration data = Files.DATA.getFile();
|
||||
FileConfiguration config = Files.config.getConfiguration();
|
||||
FileConfiguration data = Files.data.getConfiguration();
|
||||
List<ItemStack> items = new ArrayList<>();
|
||||
List<Integer> ID = new ArrayList<>();
|
||||
|
||||
@ -323,8 +323,8 @@ public class GuiListener implements Listener {
|
||||
|
||||
public static void openPlayersExpiredList(Player player, int page) {
|
||||
Methods.updateAuction();
|
||||
FileConfiguration config = Files.CONFIG.getFile();
|
||||
FileConfiguration data = Files.DATA.getFile();
|
||||
FileConfiguration config = Files.config.getConfiguration();
|
||||
FileConfiguration data = Files.data.getConfiguration();
|
||||
List<ItemStack> items = new ArrayList<>();
|
||||
List<Integer> ID = new ArrayList<>();
|
||||
|
||||
@ -401,12 +401,12 @@ public class GuiListener implements Listener {
|
||||
public static void openBuying(Player player, String ID) {
|
||||
Methods.updateAuction();
|
||||
|
||||
FileConfiguration config = Files.CONFIG.getFile();
|
||||
FileConfiguration data = Files.DATA.getFile();
|
||||
FileConfiguration config = Files.config.getConfiguration();
|
||||
FileConfiguration data = Files.data.getConfiguration();
|
||||
|
||||
if (!data.contains("Items." + ID)) {
|
||||
openShop(player, ShopType.SELL, shopCategory.get(player.getUniqueId()), 1);
|
||||
player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage());
|
||||
player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage(player));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -477,12 +477,12 @@ public class GuiListener implements Listener {
|
||||
|
||||
public static void openBidding(Player player, String ID) {
|
||||
Methods.updateAuction();
|
||||
FileConfiguration config = Files.CONFIG.getFile();
|
||||
FileConfiguration data = Files.DATA.getFile();
|
||||
FileConfiguration config = Files.config.getConfiguration();
|
||||
FileConfiguration data = Files.data.getConfiguration();
|
||||
|
||||
if (!data.contains("Items." + ID)) {
|
||||
openShop(player, ShopType.BID, shopCategory.get(player.getUniqueId()), 1);
|
||||
player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage());
|
||||
player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage(player));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -510,14 +510,14 @@ public class GuiListener implements Listener {
|
||||
public static void openViewer(Player player, String other, int page) {
|
||||
Methods.updateAuction();
|
||||
|
||||
FileConfiguration config = Files.CONFIG.getFile();
|
||||
FileConfiguration data = Files.DATA.getFile();
|
||||
FileConfiguration config = Files.config.getConfiguration();
|
||||
FileConfiguration data = Files.data.getConfiguration();
|
||||
List<ItemStack> items = new ArrayList<>();
|
||||
List<Integer> ID = new ArrayList<>();
|
||||
|
||||
if (!data.contains("Items")) {
|
||||
data.set("Items.Clear", null);
|
||||
Files.DATA.saveFile();
|
||||
Files.data.save();
|
||||
}
|
||||
|
||||
if (data.contains("Items")) {
|
||||
@ -615,7 +615,7 @@ public class GuiListener implements Listener {
|
||||
}
|
||||
|
||||
private static ItemStack getBiddingGlass(Player player, String ID) {
|
||||
FileConfiguration config = Files.CONFIG.getFile();
|
||||
FileConfiguration config = Files.config.getConfiguration();
|
||||
|
||||
String id = config.getString("Settings.GUISettings.OtherSettings.Bidding.Item");
|
||||
String name = config.getString("Settings.GUISettings.OtherSettings.Bidding.Name");
|
||||
@ -642,8 +642,8 @@ public class GuiListener implements Listener {
|
||||
}
|
||||
|
||||
private static ItemStack getBiddingItem(String ID) {
|
||||
FileConfiguration config = Files.CONFIG.getFile();
|
||||
FileConfiguration data = Files.DATA.getFile();
|
||||
FileConfiguration config = Files.config.getConfiguration();
|
||||
FileConfiguration data = Files.data.getConfiguration();
|
||||
ItemStack item = Methods.fromBase64(data.getString("Items." + ID + ".Item"));
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
@ -683,7 +683,7 @@ public class GuiListener implements Listener {
|
||||
}
|
||||
|
||||
private static void playClick(Player player) {
|
||||
FileConfiguration config = Files.CONFIG.getFile();
|
||||
FileConfiguration config = Files.config.getConfiguration();
|
||||
|
||||
if (config.getBoolean("Settings.Sounds.Toggle", false)) {
|
||||
String sound = config.getString("Settings.Sounds.Sound");
|
||||
@ -697,7 +697,7 @@ public class GuiListener implements Listener {
|
||||
}
|
||||
|
||||
private void playSoldSound(@NotNull Player player) {
|
||||
FileConfiguration config = Files.CONFIG.getFile();
|
||||
FileConfiguration config = Files.config.getConfiguration();
|
||||
String sound = config.getString("Settings.Sold-Item-Sound", "");
|
||||
if (sound.isEmpty()) return;
|
||||
|
||||
@ -708,7 +708,7 @@ public class GuiListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInvClose(InventoryCloseEvent e) {
|
||||
FileConfiguration config = Files.CONFIG.getFile();
|
||||
FileConfiguration config = Files.config.getConfiguration();
|
||||
Player player = (Player) e.getPlayer();
|
||||
|
||||
if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Bidding-On-Item")))) bidding.remove(player);
|
||||
@ -716,8 +716,8 @@ public class GuiListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInvClick(InventoryClickEvent e) {
|
||||
FileConfiguration config = Files.CONFIG.getFile();
|
||||
FileConfiguration data = Files.DATA.getFile();
|
||||
FileConfiguration config = Files.config.getConfiguration();
|
||||
FileConfiguration data = Files.data.getConfiguration();
|
||||
Player player = (Player) e.getWhoClicked();
|
||||
final Inventory inv = e.getClickedInventory();
|
||||
|
||||
@ -770,17 +770,17 @@ public class GuiListener implements Listener {
|
||||
HashMap<String, String> placeholders = new HashMap<>();
|
||||
placeholders.put("%Money_Needed%", (bid - plugin.getSupport().getMoney(player)) + "");
|
||||
placeholders.put("%money_needed%", (bid - plugin.getSupport().getMoney(player)) + "");
|
||||
player.sendMessage(Messages.NEED_MORE_MONEY.getMessage(placeholders));
|
||||
player.sendMessage(Messages.NEED_MORE_MONEY.getMessage(player, placeholders));
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.getLong("Items." + ID + ".Price") > bid) {
|
||||
player.sendMessage(Messages.BID_MORE_MONEY.getMessage());
|
||||
player.sendMessage(Messages.BID_MORE_MONEY.getMessage(player));
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.getLong("Items." + ID + ".Price") >= bid && !topBidder.equalsIgnoreCase("None")) {
|
||||
player.sendMessage(Messages.BID_MORE_MONEY.getMessage());
|
||||
player.sendMessage(Messages.BID_MORE_MONEY.getMessage(player));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -791,9 +791,9 @@ public class GuiListener implements Listener {
|
||||
Map<String, String> placeholders = new HashMap<>();
|
||||
placeholders.put("%Bid%", bid + "");
|
||||
|
||||
player.sendMessage(Messages.BID_MESSAGE.getMessage(placeholders));
|
||||
player.sendMessage(Messages.BID_MESSAGE.getMessage(player, placeholders));
|
||||
|
||||
Files.DATA.saveFile();
|
||||
Files.data.save();
|
||||
|
||||
bidding.put(player.getUniqueId(), 0);
|
||||
player.closeInventory();
|
||||
@ -821,7 +821,7 @@ public class GuiListener implements Listener {
|
||||
return;
|
||||
} catch (Exception ex) {
|
||||
player.closeInventory();
|
||||
player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage());
|
||||
player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage(player));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -934,7 +934,7 @@ public class GuiListener implements Listener {
|
||||
Player sellerPlayer = Methods.getPlayer(seller);
|
||||
|
||||
if (Methods.isOnline(seller) && sellerPlayer != null) {
|
||||
sellerPlayer.sendMessage(Messages.ADMIN_FORCE_CANCELLED_TO_PLAYER.getMessage());
|
||||
sellerPlayer.sendMessage(Messages.ADMIN_FORCE_CANCELLED_TO_PLAYER.getMessage(player));
|
||||
}
|
||||
|
||||
AuctionCancelledEvent event = new AuctionCancelledEvent((sellerPlayer != null ? sellerPlayer : Methods.getOfflinePlayer(seller)), Methods.fromBase64(data.getString("Items." + ID + ".Item")), Reasons.ADMIN_FORCE_CANCEL);
|
||||
@ -944,8 +944,8 @@ public class GuiListener implements Listener {
|
||||
data.set("OutOfTime/Cancelled." + num + ".StoreID", data.getInt("Items." + i + ".StoreID"));
|
||||
data.set("OutOfTime/Cancelled." + num + ".Item", data.getString("Items." + ID + ".Item"));
|
||||
data.set("Items." + i, null);
|
||||
Files.DATA.saveFile();
|
||||
player.sendMessage(Messages.ADMIN_FORCE_CANCELLED.getMessage());
|
||||
Files.data.save();
|
||||
player.sendMessage(Messages.ADMIN_FORCE_CANCELLED.getMessage(player));
|
||||
playClick(player);
|
||||
int page = Integer.parseInt(e.getView().getTitle().split("#")[1]);
|
||||
openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), page);
|
||||
@ -1022,7 +1022,7 @@ public class GuiListener implements Listener {
|
||||
if (!T) {
|
||||
playClick(player);
|
||||
openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), 1);
|
||||
player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage());
|
||||
player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage(player));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -1050,14 +1050,14 @@ public class GuiListener implements Listener {
|
||||
if (!data.contains("Items." + ID)) {
|
||||
playClick(player);
|
||||
openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), 1);
|
||||
player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage());
|
||||
player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage(player));
|
||||
return;
|
||||
}
|
||||
|
||||
if (Methods.isInvFull(player)) {
|
||||
playClick(player);
|
||||
player.closeInventory();
|
||||
player.sendMessage(Messages.INVENTORY_FULL.getMessage());
|
||||
player.sendMessage(Messages.INVENTORY_FULL.getMessage(player));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1067,7 +1067,7 @@ public class GuiListener implements Listener {
|
||||
HashMap<String, String> placeholders = new HashMap<>();
|
||||
placeholders.put("%Money_Needed%", (cost - plugin.getSupport().getMoney(player)) + "");
|
||||
placeholders.put("%money_needed%", (cost - plugin.getSupport().getMoney(player)) + "");
|
||||
player.sendMessage(Messages.NEED_MORE_MONEY.getMessage(placeholders));
|
||||
player.sendMessage(Messages.NEED_MORE_MONEY.getMessage(player, placeholders));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1086,20 +1086,20 @@ public class GuiListener implements Listener {
|
||||
placeholders.put("%Player%", player.getName());
|
||||
placeholders.put("%player%", player.getName());
|
||||
|
||||
player.sendMessage(Messages.BOUGHT_ITEM.getMessage(placeholders));
|
||||
player.sendMessage(Messages.BOUGHT_ITEM.getMessage(player, placeholders));
|
||||
|
||||
if (seller != null && Methods.isOnline(seller) && Methods.getPlayer(seller) != null) {
|
||||
Player sell = Methods.getPlayer(seller);
|
||||
|
||||
if (sell != null) {
|
||||
sell.sendMessage(Messages.PLAYER_BOUGHT_ITEM.getMessage(placeholders));
|
||||
sell.sendMessage(Messages.PLAYER_BOUGHT_ITEM.getMessage(player, placeholders));
|
||||
playSoldSound(sell);
|
||||
}
|
||||
}
|
||||
|
||||
player.getInventory().addItem(i);
|
||||
data.set("Items." + ID, null);
|
||||
Files.DATA.saveFile();
|
||||
Files.data.save();
|
||||
playClick(player);
|
||||
openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), 1);
|
||||
return;
|
||||
@ -1141,7 +1141,7 @@ public class GuiListener implements Listener {
|
||||
for (String i : data.getConfigurationSection("Items").getKeys(false)) {
|
||||
int ID = data.getInt("Items." + i + ".StoreID");
|
||||
if (id == ID) {
|
||||
player.sendMessage(Messages.CANCELLED_ITEM.getMessage());
|
||||
player.sendMessage(Messages.CANCELLED_ITEM.getMessage(player));
|
||||
AuctionCancelledEvent event = new AuctionCancelledEvent(player, Methods.fromBase64(data.getString("Items." + i + ".Item")), Reasons.PLAYER_FORCE_CANCEL);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
int num = 1;
|
||||
@ -1151,7 +1151,7 @@ public class GuiListener implements Listener {
|
||||
data.set("OutOfTime/Cancelled." + num + ".StoreID", data.getInt("Items." + i + ".StoreID"));
|
||||
data.set("OutOfTime/Cancelled." + num + ".Item", data.getString("Items." + i + ".Item"));
|
||||
data.set("Items." + i, null);
|
||||
Files.DATA.saveFile();
|
||||
Files.data.save();
|
||||
playClick(player);
|
||||
openPlayersCurrentList(player, 1);
|
||||
return;
|
||||
@ -1162,7 +1162,7 @@ public class GuiListener implements Listener {
|
||||
if (!T) {
|
||||
playClick(player);
|
||||
openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), 1);
|
||||
player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage());
|
||||
player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage(player));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -1203,7 +1203,7 @@ public class GuiListener implements Listener {
|
||||
for (String i : data.getConfigurationSection("OutOfTime/Cancelled").getKeys(false)) {
|
||||
if (data.getString("OutOfTime/Cancelled." + i + ".Seller").equalsIgnoreCase(player.getUniqueId().toString())) {
|
||||
if (Methods.isInvFull(player)) {
|
||||
player.sendMessage(Messages.INVENTORY_FULL.getMessage());
|
||||
player.sendMessage(Messages.INVENTORY_FULL.getMessage(player));
|
||||
break;
|
||||
} else {
|
||||
player.getInventory().addItem(Methods.fromBase64(data.getString("OutOfTime/Cancelled." + i + ".Item")));
|
||||
@ -1213,8 +1213,8 @@ public class GuiListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
player.sendMessage(Messages.GOT_ITEM_BACK.getMessage());
|
||||
Files.DATA.saveFile();
|
||||
player.sendMessage(Messages.GOT_ITEM_BACK.getMessage(player));
|
||||
Files.data.save();
|
||||
playClick(player);
|
||||
openPlayersExpiredList(player, page);
|
||||
return;
|
||||
@ -1238,14 +1238,14 @@ public class GuiListener implements Listener {
|
||||
int ID = data.getInt("OutOfTime/Cancelled." + i + ".StoreID");
|
||||
if (id == ID) {
|
||||
if (!Methods.isInvFull(player)) {
|
||||
player.sendMessage(Messages.GOT_ITEM_BACK.getMessage());
|
||||
player.sendMessage(Messages.GOT_ITEM_BACK.getMessage(player));
|
||||
player.getInventory().addItem(Methods.fromBase64(data.getString("OutOfTime/Cancelled." + i + ".Item")));
|
||||
data.set("OutOfTime/Cancelled." + i, null);
|
||||
Files.DATA.saveFile();
|
||||
Files.data.save();
|
||||
playClick(player);
|
||||
openPlayersExpiredList(player, 1);
|
||||
} else {
|
||||
player.sendMessage(Messages.INVENTORY_FULL.getMessage());
|
||||
player.sendMessage(Messages.INVENTORY_FULL.getMessage(player));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -1255,7 +1255,7 @@ public class GuiListener implements Listener {
|
||||
if (!T) {
|
||||
playClick(player);
|
||||
openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), 1);
|
||||
player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage());
|
||||
player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage(player));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package com.badbones69.crazyauctions.controllers;
|
||||
|
||||
import com.badbones69.crazyauctions.api.FileManager.Files;
|
||||
import com.badbones69.crazyauctions.api.enums.Files;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -13,7 +13,7 @@ public class MarcoListener implements Listener {
|
||||
public void onPreCommand(PlayerCommandPreprocessEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
boolean macro = Files.CONFIG.getFile().getBoolean("Settings.Patches.Macro-Dupe", true);
|
||||
boolean macro = Files.config.getConfiguration().getBoolean("Settings.Patches.Macro-Dupe", true);
|
||||
|
||||
if (!macro) return;
|
||||
|
Loading…
Reference in New Issue
Block a user