list) {
return list.stream().map(ChatUtil::color).collect(Collectors.toList());
}
+ /**
+ * Sends message to command sender
+ * @param player executor
+ * @param message to send
+ */
+ public static void sendMessage(@NotNull CommandSender player, String message) {
+ player.sendMessage(ChatUtil.color(replacePlaceholders(message, new Placeholder("{prefix}",
+ Main.getInstance().getLangFile().getMessages().getPrefix()))));
+ }
+
/**
* Replaces placeholder data on string
* also format chat messages too @see ChatUtil#color(String)
diff --git a/bukkit/src/main/java/net/leaderos/plugin/helpers/GuiHelper.java b/bukkit/src/main/java/net/leaderos/plugin/helpers/GuiHelper.java
index 26992de40..7286cd3a9 100644
--- a/bukkit/src/main/java/net/leaderos/plugin/helpers/GuiHelper.java
+++ b/bukkit/src/main/java/net/leaderos/plugin/helpers/GuiHelper.java
@@ -3,11 +3,10 @@
import com.cryptomorin.xseries.XMaterial;
import de.themoep.inventorygui.GuiElement;
import de.themoep.inventorygui.GuiPageElement;
+import net.leaderos.plugin.Main;
import net.leaderos.shared.Shared;
-import net.leaderos.shared.helpers.ChatUtil;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
-import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
@@ -35,8 +34,8 @@ public GuiHelper() {}
public static ItemStack getFiller() {
ItemStack item;
// If enabled
- if (Shared.getInstance().getLangFile().getGui().getDefaultGui().getFillerItem().isUseFiller())
- item = XMaterial.matchXMaterial(Shared.getInstance().getLangFile().getGui().getDefaultGui().getFillerItem().getMaterial()).get().parseItem();
+ if (Main.getInstance().getLangFile().getGui().getDefaultGui().getFillerItem().isUseFiller())
+ item = XMaterial.matchXMaterial(Main.getInstance().getLangFile().getGui().getDefaultGui().getFillerItem().getMaterial()).get().parseItem();
else
item = new ItemStack(Material.AIR);
return item;
@@ -52,7 +51,7 @@ public static ItemStack getFiller() {
return new GuiPageElement('b',
new ItemStack(Material.ARROW),
GuiPageElement.PageAction.PREVIOUS,
- Shared.getInstance().getLangFile().getGui().getDefaultGui().getPreviousPage().getName()
+ Main.getInstance().getLangFile().getGui().getDefaultGui().getPreviousPage().getName()
);
}
@@ -66,7 +65,7 @@ public static ItemStack getFiller() {
return new GuiPageElement('n',
new ItemStack(Material.ARROW),
GuiPageElement.PageAction.NEXT,
- Shared.getInstance().getLangFile().getGui().getDefaultGui().getPreviousPage().getName()
+ Main.getInstance().getLangFile().getGui().getDefaultGui().getPreviousPage().getName()
);
}
@@ -77,9 +76,9 @@ public static ItemStack getFiller() {
* @return add item icon
*/
public static ItemStack addItemIcon() {
- String displayName = ChatUtil.color(Shared.getInstance().getLangFile().getGui().getBazaarGui().getAddItemName());
- XMaterial material = XMaterial.matchXMaterial(Shared.getInstance().getLangFile().getGui().getBazaarGui().getMaterial()).orElse(XMaterial.GREEN_WOOL);
- List lore = ChatUtil.color(Shared.getInstance().getLangFile().getGui().getBazaarGui().getAddItemLore());
+ String displayName = ChatUtil.color(Main.getInstance().getLangFile().getGui().getBazaarGui().getAddItemName());
+ XMaterial material = XMaterial.matchXMaterial(Main.getInstance().getLangFile().getGui().getBazaarGui().getMaterial()).orElse(XMaterial.GREEN_WOOL);
+ List lore = ChatUtil.color(Main.getInstance().getLangFile().getGui().getBazaarGui().getAddItemLore());
return ItemUtils.getItem(material, displayName, lore);
}
}
diff --git a/bukkit/src/main/java/net/leaderos/plugin/helpers/ItemUtils.java b/bukkit/src/main/java/net/leaderos/plugin/helpers/ItemUtils.java
index 4ccf69bc0..deb747dac 100644
--- a/bukkit/src/main/java/net/leaderos/plugin/helpers/ItemUtils.java
+++ b/bukkit/src/main/java/net/leaderos/plugin/helpers/ItemUtils.java
@@ -1,21 +1,14 @@
package net.leaderos.plugin.helpers;
-import com.cryptomorin.xseries.SkullUtils;
import com.cryptomorin.xseries.XMaterial;
-import net.leaderos.plugin.Main;
-import net.leaderos.plugin.modules.donators.model.RecentDonationData;
-import net.leaderos.shared.Shared;
-import net.leaderos.shared.helpers.ChatUtil;
-import net.leaderos.shared.helpers.Placeholder;
-import org.bukkit.Bukkit;
+import org.apache.commons.lang3.text.WordUtils;
import org.bukkit.Material;
-import org.bukkit.OfflinePlayer;
import org.bukkit.enchantments.Enchantment;
+import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.ItemMeta;
-import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.util.io.BukkitObjectInputStream;
import org.bukkit.util.io.BukkitObjectOutputStream;
import org.jetbrains.annotations.NotNull;
@@ -23,8 +16,10 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.*;
-import java.util.stream.Collectors;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
/**
* @author hyperion, poyrazinan
@@ -136,4 +131,36 @@ public static int getDurability(ItemStack item, int maxDurability) {
result.setItemMeta(meta);
return result;
}
+
+ /**
+ * Check for material and
+ * get item with a material.
+ * @param material of item
+ * @param name of item
+ * @param lore of item
+ * @param glow glow status of item
+ * @return ItemStack of destination item
+ */
+ public static @NotNull ItemStack getItem(XMaterial material, String name, List lore, boolean glow) {
+ ItemStack result = getItem(material, name, lore);
+ ItemMeta meta = result.getItemMeta();
+ if (glow) {
+ meta.addEnchant(Enchantment.DURABILITY, 1, true);
+ meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
+ }
+ result.setItemMeta(meta);
+ return result;
+ }
+
+ /**
+ * converts xmaterial to string
+ * @param item Item
+ */
+ public static String getName(ItemStack item) {
+ XMaterial material = XMaterial.matchXMaterial(item);
+ String name = (item.hasItemMeta() && item.getItemMeta().hasDisplayName()) ?
+ item.getItemMeta().getDisplayName() :
+ WordUtils.capitalize(material.name().replace('_', ' ').toLowerCase(Locale.ENGLISH));;
+ return name;
+ }
}
diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/auth/AuthLogin.java b/bukkit/src/main/java/net/leaderos/plugin/modules/auth/AuthLogin.java
index 72d9cfd60..9fee66489 100644
--- a/bukkit/src/main/java/net/leaderos/plugin/modules/auth/AuthLogin.java
+++ b/bukkit/src/main/java/net/leaderos/plugin/modules/auth/AuthLogin.java
@@ -2,18 +2,7 @@
import net.leaderos.plugin.Main;
import net.leaderos.plugin.modules.auth.commands.Commands;
-import net.leaderos.shared.Shared;
-import net.leaderos.shared.helpers.ChatUtil;
-import net.leaderos.shared.helpers.MDChat.MDChatAPI;
-import net.leaderos.shared.model.request.PostRequest;
import net.leaderos.shared.module.LeaderOSModule;
-import net.leaderos.shared.exceptions.RequestException;
-import org.bukkit.entity.Player;
-import org.json.JSONObject;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
/**
* Auth module of leaderos-plugin
@@ -37,58 +26,6 @@ public void onDisable() {
Main.getCommandManager().unregisterCommand(new Commands());
}
-
- /**
- * Generates user login link
- *
- * @param username of player
- * @param uuid of player
- * @return String of url
- * @throws IOException request exception
- */
- public static String generateLink(String username, String uuid) throws IOException {
- Map formData = new HashMap<>();
- formData.put("username", username);
- formData.put("uuid", uuid);
- PostRequest postRequest = new PostRequest("auth/generate-link", formData);
- JSONObject response = postRequest.getResponse().getResponseMessage().getJSONObject("data");
- return response.getString("url");
- }
-
- /**
- * sends auth command message
- * @param player executor
- */
- public static void sendAuthCommandMessage(Player player) {
- try {
- String link = generateLink(player.getName(), player.getUniqueId().toString());
- player.spigot().sendMessage(
- MDChatAPI.getFormattedMessage(ChatUtil.color(Shared.getInstance()
- .getLangFile().getMessages()
- .getAuth().getCommandMessage().replace("%link%", link))));
- } catch (Exception e) {
- e.printStackTrace();
- // TODO Exception
- }
- }
-
- /**
- * sends auth module error message
- * @param player executor
- */
- public static void sendAuthModuleError(Player player) {
- try {
- String link = generateLink(player.getName(), player.getUniqueId().toString());
- player.spigot().sendMessage(
- MDChatAPI.getFormattedMessage(ChatUtil.color(Shared.getInstance()
- .getLangFile().getMessages()
- .getAuth().getModuleError().replace("%link%", link))));
- } catch (Exception e) {
- e.printStackTrace();
- // TODO Exception
- }
- }
-
/**
* Constructor of Auth
*/
diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/auth/commands/Commands.java b/bukkit/src/main/java/net/leaderos/plugin/modules/auth/commands/Commands.java
index ec49d0d3c..2c7def177 100644
--- a/bukkit/src/main/java/net/leaderos/plugin/modules/auth/commands/Commands.java
+++ b/bukkit/src/main/java/net/leaderos/plugin/modules/auth/commands/Commands.java
@@ -5,7 +5,10 @@
import dev.triumphteam.cmd.core.annotation.Command;
import dev.triumphteam.cmd.core.annotation.Default;
import lombok.RequiredArgsConstructor;
-import net.leaderos.plugin.modules.auth.AuthLogin;
+import net.leaderos.plugin.Main;
+import net.leaderos.plugin.helpers.ChatUtil;
+import net.leaderos.shared.helpers.MDChat.MDChatAPI;
+import net.leaderos.shared.module.auth.AuthHelper;
import org.bukkit.entity.Player;
/**
@@ -24,7 +27,15 @@ public class Commands extends BaseCommand {
@Default
@Permission("leaderos.auth")
public void defaultCommand(Player player) {
- AuthLogin.sendAuthCommandMessage(player);
- // TODO Else
+ String link = AuthHelper.getAuthLink(player);
+ if (link != null)
+ player.spigot().sendMessage(
+ MDChatAPI.getFormattedMessage(ChatUtil.color(Main.getInstance()
+ .getLangFile().getMessages()
+ .getAuth().getCommandMessage()
+ .replace("%link%", link)
+ .replace("{prefix}", Main.getInstance().getLangFile().getMessages().getPrefix()))));
+ else
+ ChatUtil.sendMessage(player, Main.getInstance().getLangFile().getMessages().getAuth().getNoLink());
}
}
\ No newline at end of file
diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/bazaar/Bazaar.java b/bukkit/src/main/java/net/leaderos/plugin/modules/bazaar/Bazaar.java
index 732655dcd..59755a309 100644
--- a/bukkit/src/main/java/net/leaderos/plugin/modules/bazaar/Bazaar.java
+++ b/bukkit/src/main/java/net/leaderos/plugin/modules/bazaar/Bazaar.java
@@ -24,7 +24,7 @@ public class Bazaar extends LeaderOSModule {
*/
public void onEnable() {
// TODO check dependency
- serverId = Main.getShared().getModulesFile().getBazaar().getServerId();
+ serverId = Main.getInstance().getModulesFile().getBazaar().getServerId();
Main.getCommandManager().registerCommand(new Commands());
}
diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/bazaar/gui/BazaarAddItemGui.java b/bukkit/src/main/java/net/leaderos/plugin/modules/bazaar/gui/BazaarAddItemGui.java
index 0674847f3..cde3b90a2 100644
--- a/bukkit/src/main/java/net/leaderos/plugin/modules/bazaar/gui/BazaarAddItemGui.java
+++ b/bukkit/src/main/java/net/leaderos/plugin/modules/bazaar/gui/BazaarAddItemGui.java
@@ -1,16 +1,20 @@
package net.leaderos.plugin.modules.bazaar.gui;
+import com.cryptomorin.xseries.XMaterial;
import de.themoep.inventorygui.*;
+import dev.s7a.base64.Base64ItemStack;
import lombok.SneakyThrows;
import net.leaderos.plugin.Main;
+import net.leaderos.plugin.helpers.ChatUtil;
import net.leaderos.plugin.helpers.GuiHelper;
import net.leaderos.plugin.modules.bazaar.model.PlayerBazaar;
import net.leaderos.plugin.modules.cache.model.User;
import net.leaderos.plugin.modules.bazaar.Bazaar;
-import net.leaderos.shared.helpers.ChatUtil;
import net.leaderos.shared.helpers.GameUtils;
import net.leaderos.plugin.helpers.ItemUtils;
+import net.leaderos.shared.model.Response;
import net.leaderos.shared.model.request.PostRequest;
+import org.apache.commons.lang3.text.WordUtils;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@@ -22,6 +26,7 @@
import java.net.HttpURLConnection;
import java.text.SimpleDateFormat;
import java.util.*;
+import java.util.stream.Collectors;
/**
* @author poyrazinan
@@ -40,11 +45,11 @@ public BazaarAddItemGui() {}
* @param player to show gui
*/
@SneakyThrows
- public static void showGui(Player player) {
+ public static void showGui(Player player, int itemAmount) {
// Gui template as array
- String[] layout = Main.getShared().getLangFile().getGui().getBazaarGui().getAddItemLayout().toArray(new String[0]);
+ String[] layout = Main.getInstance().getLangFile().getGui().getBazaarGui().getAddItemLayout().toArray(new String[0]);
// Inventory object
- String guiName = ChatUtil.color(Main.getShared().getLangFile().getGui().getBazaarGui().getGuiName());
+ String guiName = ChatUtil.color(Main.getInstance().getLangFile().getGui().getBazaarGui().getGuiName());
InventoryGui gui = new InventoryGui(Main.getInstance(), null, guiName, layout);
// Filler item for empty slots
ItemStack fillerItem = GuiHelper.getFiller();
@@ -58,12 +63,11 @@ public static void showGui(Player player) {
// Calculating storage amounts
int maxStorageAmount = GameUtils.getAmountFromPerm(player,
"bazaar.maxstorage.",
- Main.getShared().getModulesFile().getBazaar().getDefaultStorageSize());
+ Main.getInstance().getModulesFile().getBazaar().getDefaultStorageSize());
- int storedItemAmount = PlayerBazaar.getBazaarStorage(User.getUser(player.getName()).getId()).size();
- int canStoreAmount = maxStorageAmount - storedItemAmount;
+ int canStoreAmount = maxStorageAmount - itemAmount;
// Items which stored (airs included)
- ItemStack[] items = inv.getContents();
+ List items = Arrays.stream(inv.getContents()).collect(Collectors.toList());
String userId = User.getUser(player.getName()).getId();
int serverId = Bazaar.getServerId();
@@ -93,15 +97,14 @@ public static void showGui(Player player) {
continue;
}
// Item info
- String material = item.getType().name();
- String name = (item.hasItemMeta() && item.getItemMeta().hasDisplayName()) ?
- item.getItemMeta().getDisplayName() : material;
+ XMaterial material = XMaterial.matchXMaterial(item);
+ String name = ItemUtils.getName(item);
String lore = (item.hasItemMeta() && item.getItemMeta().hasLore()) ?
String.join("\n", item.getItemMeta().getLore()) : null;
int amount = item.getAmount();
int maxDurability = item.getType().getMaxDurability();
int durability = ItemUtils.getDurability(item, maxDurability);
- String base64 = ItemUtils.toBase64(item);
+ String base64 = Base64ItemStack.encode(item);
double price = 0.0;
String creationDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
String modelId = ItemUtils.getModelId(item);
@@ -115,22 +118,25 @@ public static void showGui(Player player) {
body.put("amount", amount+"");
body.put("maxDurability", maxDurability+"");
body.put("durability", durability+"");
+
body.put("base64", base64);
body.put("price", price+"");
body.put("creationDate", creationDate);
// TODO Check
- body.put("modelID", modelId);
+ if (modelId != null)
+ body.put("modelID", modelId);
if (enchantment != null)
body.put("enchantment", enchantment);
body.put("serverID", serverId+"");
- body.put("itemID", item.getType().name());
+ body.put("itemID", material.name());
// Sends response
try {
- PostRequest postItem = new PostRequest("bazaar/storages/" + userId + "/items", body);
- if (postItem.getResponse().getResponseCode() == HttpURLConnection.HTTP_OK) {
+ Response postBazaarItem = new PostRequest("bazaar/storages/" + userId + "/items", body).getResponse();
+ if (postBazaarItem.getResponseCode() == HttpURLConnection.HTTP_OK
+ && postBazaarItem.getResponseMessage().getBoolean("status")) {
// TODO Success
- BazaarGui.showGui(player);
+
}
else throw new Exception();
// TODO Else
@@ -143,7 +149,7 @@ public static void showGui(Player player) {
if (!returnItems.isEmpty()) {
PlayerInventory playerInventory = player.getInventory();
returnItems.forEach(playerInventory::addItem);
- String returnMessage = Main.getShared().getLangFile().getGui().getBazaarGui().getReturnItemMessage();
+ String returnMessage = Main.getInstance().getLangFile().getGui().getBazaarGui().getReturnItemMessage();
returnMessage = returnMessage.replace("%max_amount%", maxStorageAmount+"")
.replace("%amount%", returnItems.size()+"");
ChatUtil.sendMessage(player, returnMessage);
diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/bazaar/gui/BazaarGui.java b/bukkit/src/main/java/net/leaderos/plugin/modules/bazaar/gui/BazaarGui.java
index f8c685714..471a0a1fc 100644
--- a/bukkit/src/main/java/net/leaderos/plugin/modules/bazaar/gui/BazaarGui.java
+++ b/bukkit/src/main/java/net/leaderos/plugin/modules/bazaar/gui/BazaarGui.java
@@ -5,14 +5,15 @@
import de.themoep.inventorygui.InventoryGui;
import de.themoep.inventorygui.StaticGuiElement;
import lombok.SneakyThrows;
+import net.leaderos.plugin.helpers.ChatUtil;
import net.leaderos.plugin.modules.bazaar.model.PlayerBazaar;
import net.leaderos.plugin.modules.cache.model.User;
import net.leaderos.plugin.Main;
import net.leaderos.shared.Shared;
import net.leaderos.shared.exceptions.CacheNotFoundException;
-import net.leaderos.shared.helpers.ChatUtil;
import net.leaderos.plugin.helpers.GuiHelper;
import org.bukkit.entity.Player;
+import org.bukkit.inventory.ItemStack;
import java.util.List;
@@ -35,9 +36,9 @@ public BazaarGui() {}
@SneakyThrows
public static void showGui(Player player) {
// Gui template as array
- String[] layout = Main.getShared().getLangFile().getGui().getBazaarGui().getLayout().toArray(new String[0]);
+ String[] layout = Main.getInstance().getLangFile().getGui().getBazaarGui().getLayout().toArray(new String[0]);
// Inventory object
- String guiName = ChatUtil.color(Main.getShared().getLangFile().getGui().getBazaarGui().getGuiName());
+ String guiName = ChatUtil.color(Main.getInstance().getLangFile().getGui().getBazaarGui().getGuiName());
InventoryGui gui = new InventoryGui(Main.getInstance(), null, guiName, layout);
// Filler item for empty slots
gui.setFiller(GuiHelper.getFiller());
@@ -52,38 +53,42 @@ public static void showGui(Player player) {
// Add item icon
gui.addElement(new StaticGuiElement('a', GuiHelper.addItemIcon(), 1, click -> {
+ gui.close();
click.getEvent().setCancelled(true);
- BazaarAddItemGui.showGui(player);
+ BazaarAddItemGui.showGui(player, playerBazaarList.size());
return false;
}));
// Bazaar group creator
GuiElementGroup bazaarGui = new GuiElementGroup('i');
if (!playerBazaarList.isEmpty())
- playerBazaarList.forEach(playerBazaarItem -> bazaarGui.addElement(new DynamicGuiElement('s', (viewer)
- -> new StaticGuiElement('s',
- playerBazaarItem.getItem(),
- 1,
- click -> {
- click.getEvent().setCancelled(true);
- gui.close();
- if (player.getInventory().firstEmpty() == -1) {
- ChatUtil.sendMessage(player, Shared.getInstance().getLangFile().getMessages().getCannotCreateFull());
+ playerBazaarList.forEach(playerBazaarItem -> {
+ ItemStack bazaarItem = playerBazaarItem.getItem();
+ bazaarGui.addElement(new DynamicGuiElement('s', (viewer)
+ -> new StaticGuiElement('s',
+ bazaarItem,
+ bazaarItem.getAmount(),
+ click -> {
+ click.getEvent().setCancelled(true);
+ gui.close();
+ if (player.getInventory().firstEmpty() == -1) {
+ ChatUtil.sendMessage(player, Main.getInstance().getLangFile().getMessages().getCannotCreateFull());
+ return false;
+ }
+ String title = ChatUtil.color(Main.getInstance().getLangFile().getGui().getBazaarGui().getWithdrawTitle());
+ String subtitleError = ChatUtil.color(Main.getInstance().getLangFile().getGui().getBazaarGui().getWithdrawErrorSubtitle());
+ String subtitleSuccess = ChatUtil.color(Main.getInstance().getLangFile().getGui().getBazaarGui().getWithdrawSuccessSubtitle());
+ String subtitleProgress = ChatUtil.color(Main.getInstance().getLangFile().getGui().getBazaarGui().getWithdrawProgressSubtitle());
+ player.sendTitle(title, subtitleProgress);
+ boolean withdrawStatus = playerBazaarItem.withdrawItem(player);
+ // TODO Title edit
+ if (withdrawStatus)
+ player.sendTitle(title, subtitleSuccess);
+ else
+ player.sendTitle(title, subtitleError);
return false;
- }
- String title = ChatUtil.color(Main.getShared().getLangFile().getGui().getBazaarGui().getWithdrawTitle());
- String subtitleError = ChatUtil.color(Main.getShared().getLangFile().getGui().getBazaarGui().getWithdrawErrorSubtitle());
- String subtitleSuccess = ChatUtil.color(Main.getShared().getLangFile().getGui().getBazaarGui().getWithdrawSuccessSubtitle());
- String subtitleProgress = ChatUtil.color(Main.getShared().getLangFile().getGui().getBazaarGui().getWithdrawProgressSubtitle());
- player.sendTitle(title, subtitleProgress);
- boolean withdrawStatus = playerBazaarItem.withdrawItem(player);
- // TODO Title edit
- if (withdrawStatus)
- player.sendTitle(title, subtitleSuccess);
- else
- player.sendTitle(title, subtitleError);
- return false;
- })))
+ })));
+ }
);
gui.addElement(bazaarGui);
diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/bazaar/model/PlayerBazaar.java b/bukkit/src/main/java/net/leaderos/plugin/modules/bazaar/model/PlayerBazaar.java
index 582fde1ba..583dd7341 100644
--- a/bukkit/src/main/java/net/leaderos/plugin/modules/bazaar/model/PlayerBazaar.java
+++ b/bukkit/src/main/java/net/leaderos/plugin/modules/bazaar/model/PlayerBazaar.java
@@ -1,12 +1,14 @@
package net.leaderos.plugin.modules.bazaar.model;
+import dev.s7a.base64.Base64ItemStack;
import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;
import net.leaderos.plugin.Main;
+import net.leaderos.plugin.helpers.ChatUtil;
import net.leaderos.plugin.modules.bazaar.Bazaar;
-import net.leaderos.shared.helpers.ChatUtil;
import net.leaderos.plugin.helpers.ItemUtils;
+import net.leaderos.shared.model.Response;
import net.leaderos.shared.model.request.DeleteRequest;
import net.leaderos.shared.model.request.GetRequest;
import org.bukkit.Bukkit;
@@ -59,12 +61,12 @@ public PlayerBazaar(JSONObject response, String userId) {
* @return ItemStack of bazaar item
*/
public ItemStack getItem() {
- ItemStack item = ItemUtils.fromBase64(getBase64());
+ ItemStack item = Base64ItemStack.decode(getBase64());
ItemMeta meta = item.getItemMeta();
List lore = new ArrayList<>();
if (meta != null && meta.getLore() != null)
lore = meta.getLore();
- lore.add(ChatUtil.color(Main.getShared().getLangFile().getGui().getBazaarGui().getClickLore()));
+ lore.add(ChatUtil.color(Main.getInstance().getLangFile().getGui().getBazaarGui().getClickLore()));
meta.setLore(lore);
item.setItemMeta(meta);
return item;
@@ -77,10 +79,9 @@ public ItemStack getItem() {
*/
@SneakyThrows
public boolean withdrawItem(Player player) {
- DeleteRequest deleteRequest = new DeleteRequest("bazaar/storage/" + getUserId() + "/items/" + getId());
- // TODO Remove
- Bukkit.broadcastMessage(deleteRequest.getResponse().getResponseCode() + "");
- if (deleteRequest.getResponse().getResponseCode() == HttpURLConnection.HTTP_OK) {
+ Response deleteRequest = new DeleteRequest("bazaar/storages/" + getUserId() + "/items/" + getId()).getResponse();
+ if (deleteRequest.getResponseCode() == HttpURLConnection.HTTP_OK
+ && deleteRequest.getResponseMessage().getBoolean("status")) {
ItemStack item = ItemUtils.fromBase64(getBase64());
player.getInventory().addItem(item);
return true;
diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/cache/Cache.java b/bukkit/src/main/java/net/leaderos/plugin/modules/cache/Cache.java
index 29a3b6750..17b2dd826 100644
--- a/bukkit/src/main/java/net/leaderos/plugin/modules/cache/Cache.java
+++ b/bukkit/src/main/java/net/leaderos/plugin/modules/cache/Cache.java
@@ -35,7 +35,7 @@ public void onEnable() {
Bukkit.getPluginManager().registerEvents(loginListener, Main.getInstance());
Bukkit.getPluginManager().registerEvents(quitListener, Main.getInstance());
// Loads all player data
- User.loginAllOnlinePlayers();
+ User.loadAllPlayers();
// Placeholder loader
if( Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI"))
new Placeholders().register();
diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/cache/Placeholders.java b/bukkit/src/main/java/net/leaderos/plugin/modules/cache/Placeholders.java
index 3c6476cc0..2e1b3bf0a 100644
--- a/bukkit/src/main/java/net/leaderos/plugin/modules/cache/Placeholders.java
+++ b/bukkit/src/main/java/net/leaderos/plugin/modules/cache/Placeholders.java
@@ -18,7 +18,7 @@ public class Placeholders extends PlaceholderExpansion {
* Date formatter for placeholders
*/
private static SimpleDateFormat dateFormat = new SimpleDateFormat(
- Main.getShared().getConfigFile().getSettings().getTimeFormat());
+ Main.getInstance().getConfigFile().getSettings().getTimeFormat());
/**
* identifier of placeholder
@@ -34,7 +34,7 @@ public String getIdentifier() {
* @return author name
*/
public String getAuthor() {
- return "Geik";
+ return "leaderos";
}
/**
diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/cache/handlers/LoginListener.java b/bukkit/src/main/java/net/leaderos/plugin/modules/cache/handlers/LoginListener.java
index 9724e92ec..0bad9cab8 100644
--- a/bukkit/src/main/java/net/leaderos/plugin/modules/cache/handlers/LoginListener.java
+++ b/bukkit/src/main/java/net/leaderos/plugin/modules/cache/handlers/LoginListener.java
@@ -20,8 +20,6 @@ public class LoginListener implements Listener {
*/
@EventHandler
public void playerLoginEvent(PlayerLoginEvent event) {
- Bukkit.getScheduler().runTaskAsynchronously(Main.getInstance(), () -> {
- User.loadPlayerCache(event.getPlayer());
- });
+ Bukkit.getScheduler().runTaskAsynchronously(Main.getInstance(), () -> User.loadPlayerCache(event.getPlayer()));
}
}
diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/cache/handlers/QuitListener.java b/bukkit/src/main/java/net/leaderos/plugin/modules/cache/handlers/QuitListener.java
index 3ff7f0b31..49e960521 100644
--- a/bukkit/src/main/java/net/leaderos/plugin/modules/cache/handlers/QuitListener.java
+++ b/bukkit/src/main/java/net/leaderos/plugin/modules/cache/handlers/QuitListener.java
@@ -26,9 +26,7 @@ public QuitListener(){}
*/
@EventHandler
public void quitListener(PlayerQuitEvent event) {
- Bukkit.getScheduler().runTaskAsynchronously(Main.getInstance(), () -> {
- User.unloadPlayerCache(event.getPlayer().getName());
- });
+ Bukkit.getScheduler().runTaskAsynchronously(Main.getInstance(), () -> User.unloadPlayerCache(event.getPlayer().getName()));
}
}
diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/cache/model/User.java b/bukkit/src/main/java/net/leaderos/plugin/modules/cache/model/User.java
index 999e0f5fe..dcf185abd 100644
--- a/bukkit/src/main/java/net/leaderos/plugin/modules/cache/model/User.java
+++ b/bukkit/src/main/java/net/leaderos/plugin/modules/cache/model/User.java
@@ -108,7 +108,7 @@ public static boolean isPlayerAuthed(Player player) {
/**
* loads all player data
*/
- public static void loginAllOnlinePlayers() {
+ public static void loadAllPlayers() {
Bukkit.getScheduler().runTaskAsynchronously(Main.getInstance(), () ->
Bukkit.getOnlinePlayers().forEach(User::loadPlayerCache));
}
@@ -122,10 +122,7 @@ public static void loadPlayerCache(Player player) {
GetRequest getRequest = new GetRequest("users/" + player.getName());
new User(getRequest.getResponse().getResponseMessage());
}
- catch (Exception e) {
- // TODO No user exception
- e.printStackTrace();
- }
+ catch (Exception ignored) {}
}
/**
diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/credit/Credit.java b/bukkit/src/main/java/net/leaderos/plugin/modules/credit/Credit.java
index e2b16359f..406319bb4 100644
--- a/bukkit/src/main/java/net/leaderos/plugin/modules/credit/Credit.java
+++ b/bukkit/src/main/java/net/leaderos/plugin/modules/credit/Credit.java
@@ -33,95 +33,6 @@ public void onDisable() {
Main.getCommandManager().unregisterCommand(new Commands());
}
- /**
- * Send credit to another player
- * @param sender executor
- * @param target player
- * @param amount of currency
- * @return response of request
- */
- public static @Nullable Response sendCreditRequest(String sender, String target, Double amount) {
- try {
- Map list = new HashMap<>();
- list.put("target", target);
- list.put("amount", amount+"");
- PostRequest postSendCredit = new PostRequest("credits/" + sender + "/send", list);
- return postSendCredit.getResponse();
- }
- catch (Exception e) {
- return null;
- }
- }
-
- /**
- * Gets currency of player as a response
- * @param sender executor
- * @return response of request
- */
- public static @Nullable Response currencyRequest(String sender) {
- try {
- GetRequest getCurrency = new GetRequest("credits/" + sender);
- return getCurrency.getResponse();
- }
- catch (Exception e) {
- return null;
- }
- }
-
- /**
- * Adds credit to target player
- * @param target to deposit
- * @param amount amount of currency
- * @return Response of request
- */
- public static @Nullable Response addCreditRequest(String target, double amount) {
- try {
- Map list = new HashMap<>();
- list.put("amount", amount+"");
- PostRequest postAddCredit = new PostRequest("credits/" + target + "/add", list);
- return postAddCredit.getResponse();
- }
- catch (Exception e) {
- return null;
- }
- }
-
- /**
- * Removes credit to target player
- * @param target to deposit
- * @param amount amount of currency
- * @return Response of request
- */
- public static @Nullable Response removeCreditRequest(String target, double amount) {
- try {
- Map list = new HashMap<>();
- list.put("amount", amount+"");
- PostRequest postRemoveCredit = new PostRequest("credits/" + target + "/remove", list);
- return postRemoveCredit.getResponse();
- }
- catch (Exception e) {
- return null;
- }
- }
-
- /**
- * Sets credit to target player
- * @param target to deposit
- * @param amount amount of deposit
- * @return Response of request
- */
- public static @Nullable Response setCreditRequest(String target, double amount) {
- try {
- Map list = new HashMap<>();
- list.put("amount", amount+"");
- PostRequest postSetCredit = new PostRequest("credits/" + target + "/set", list);
- return postSetCredit.getResponse();
- }
- catch (Exception e) {
- return null;
- }
- }
-
/**
* Constructor of Credit
*/
diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/credit/commands/Commands.java b/bukkit/src/main/java/net/leaderos/plugin/modules/credit/commands/Commands.java
index 84f17c739..19bbc59f9 100644
--- a/bukkit/src/main/java/net/leaderos/plugin/modules/credit/commands/Commands.java
+++ b/bukkit/src/main/java/net/leaderos/plugin/modules/credit/commands/Commands.java
@@ -7,12 +7,12 @@
import dev.triumphteam.cmd.core.annotation.SubCommand;
import lombok.RequiredArgsConstructor;
import net.leaderos.plugin.Main;
-import net.leaderos.plugin.modules.credit.Credit;
-import net.leaderos.shared.Shared;
-import net.leaderos.shared.helpers.ChatUtil;
+import net.leaderos.plugin.api.handlers.UpdateCacheEvent;
+import net.leaderos.plugin.helpers.ChatUtil;
import net.leaderos.shared.helpers.MoneyUtils;
import net.leaderos.shared.helpers.Placeholder;
import net.leaderos.shared.model.Response;
+import net.leaderos.shared.module.credit.CreditHelper;
import org.bukkit.command.CommandSender;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@@ -35,10 +35,10 @@ public class Commands extends BaseCommand {
@Default
@Permission("credits.see")
public void defaultCommand(Player player) {
- Response targetCurrency = Credit.currencyRequest(player.getName());
+ Response targetCurrency = CreditHelper.currencyRequest(player.getName());
if (Objects.requireNonNull(targetCurrency).getResponseCode() == HttpURLConnection.HTTP_OK) {
ChatUtil.sendMessage(player, ChatUtil.replacePlaceholders(
- Main.getShared().getLangFile().getMessages().getCreditInfo(),
+ Main.getInstance().getLangFile().getMessages().getCreditInfo(),
new Placeholder("{amount}", MoneyUtils.format(targetCurrency.getResponseMessage().getDouble("raw_credits")))
));
}
@@ -57,48 +57,53 @@ public void sendCommand(Player player, String target, Double amount) {
Player targetPlayer = Bukkit.getPlayerExact(target);
if (player.getName().equalsIgnoreCase(target)) {
- ChatUtil.sendMessage(player, Shared.getInstance().getLangFile().getMessages().getCannotSendCreditYourself());
+ ChatUtil.sendMessage(player, Main.getInstance().getLangFile().getMessages().getCannotSendCreditYourself());
return;
}
if (amount <= 0) {
- ChatUtil.sendMessage(player, Shared.getInstance().getLangFile().getMessages().getCannotSendCreditNegative());
+ ChatUtil.sendMessage(player, Main.getInstance().getLangFile().getMessages().getCannotSendCreditNegative());
return;
}
/* TODO
long userId = plugin.getPluginDatabase().getUserId(player.getName());
if (userId == 0) {
- ChatUtil.sendMessage(player, Shared.getInstance().getLangFile().getMessages().getPlayerNotAvailable());
+ ChatUtil.sendMessage(player, Main.getInstance().getLangFile().getMessages().getPlayerNotAvailable());
return;
}
long otherUserId = plugin.getPluginDatabase().getUserId(target);
if (otherUserId == 0) {
- ChatUtil.sendMessage(player, Shared.getInstance().getLangFile().getMessages().getTargetPlayerNotAvailable());
+ ChatUtil.sendMessage(player, Main.getInstance().getLangFile().getMessages().getTargetPlayerNotAvailable());
return;
}
double credit = plugin.getPluginDatabase().getCredits(player.getName());
if (credit < amount) {
- ChatUtil.sendMessage(player, Shared.getInstance().getLangFile().getMessages().getCannotSendCreditNotEnough());
+ ChatUtil.sendMessage(player, Main.getInstance().getLangFile().getMessages().getCannotSendCreditNotEnough());
return;
}
*/
- Response sendCreditResponse = Credit.sendCreditRequest(player.getName(), target, amount);
+ Response sendCreditResponse = CreditHelper.sendCreditRequest(player.getName(), target, amount);
- if (Objects.requireNonNull(sendCreditResponse).getResponseCode() == HttpURLConnection.HTTP_OK) {
+ if (Objects.requireNonNull(sendCreditResponse).getResponseCode() == HttpURLConnection.HTTP_OK
+ && sendCreditResponse.getResponseMessage().getBoolean("status")) {
+ // Calls UpdateCache event for update player's cache
+ Bukkit.getPluginManager().callEvent(new UpdateCacheEvent(player.getName()));
ChatUtil.sendMessage(player, ChatUtil.replacePlaceholders(
- Main.getShared().getLangFile().getMessages().getSuccessfullySentCredit(),
+ Main.getInstance().getLangFile().getMessages().getSuccessfullySentCredit(),
new Placeholder("{amount}", MoneyUtils.format(amount)),
new Placeholder("{target}", target)
));
if (targetPlayer != null) {
+ // Calls UpdateCache event for update player's cache
+ Bukkit.getPluginManager().callEvent(new UpdateCacheEvent(target));
ChatUtil.sendMessage(Objects.requireNonNull(targetPlayer), ChatUtil.replacePlaceholders(
- Main.getShared().getLangFile().getMessages().getReceivedCredit(),
+ Main.getInstance().getLangFile().getMessages().getReceivedCredit(),
new Placeholder("{amount}", MoneyUtils.format(amount)),
new Placeholder("{player}", player.getName())
));
@@ -106,7 +111,7 @@ public void sendCommand(Player player, String target, Double amount) {
}
else
// TODO Make else
- ChatUtil.sendMessage(player, Shared.getInstance().getLangFile().getMessages().getCannotSendCreditNotEnough());
+ ChatUtil.sendMessage(player, Main.getInstance().getLangFile().getMessages().getCannotSendCreditNotEnough());
}
/**
@@ -117,10 +122,10 @@ public void sendCommand(Player player, String target, Double amount) {
@SubCommand(value = "see", alias = {"göster", "goster", "gör", "gor", "bak"})
@Permission("credits.see.other")
public void showCommand(CommandSender sender, String target) {
- Response targetCurrency = Credit.currencyRequest(target);
+ Response targetCurrency = CreditHelper.currencyRequest(target);
if (Objects.requireNonNull(targetCurrency).getResponseCode() == HttpURLConnection.HTTP_OK) {
ChatUtil.sendMessage(sender, ChatUtil.replacePlaceholders(
- Main.getShared().getLangFile().getMessages().getCreditInfoOther(),
+ Main.getInstance().getLangFile().getMessages().getCreditInfoOther(),
new Placeholder("{amount}", MoneyUtils.format(targetCurrency.getResponseMessage().getDouble("raw_credits"))),
new Placeholder("{target}", target)
));
@@ -139,18 +144,22 @@ public void addCommand(CommandSender sender, String target, Double amount) {
amount = MoneyUtils.parseDouble(amount);
if (amount <= 0) {
- ChatUtil.sendMessage(sender, Shared.getInstance().getLangFile().getMessages().getCannotSendCreditNegative());
+ ChatUtil.sendMessage(sender, Main.getInstance().getLangFile().getMessages().getCannotSendCreditNegative());
return;
}
- Response addCreditResponse = Credit.addCreditRequest(target, amount);
+ Response addCreditResponse = CreditHelper.addCreditRequest(target, amount);
- if (Objects.requireNonNull(addCreditResponse).getResponseCode() == HttpURLConnection.HTTP_OK)
+ if (Objects.requireNonNull(addCreditResponse).getResponseCode() == HttpURLConnection.HTTP_OK) {
+ if (Bukkit.getPlayerExact(target) != null)
+ // Calls UpdateCache event for update player's cache
+ Bukkit.getPluginManager().callEvent(new UpdateCacheEvent(target));
ChatUtil.sendMessage(sender, ChatUtil.replacePlaceholders(
- Main.getShared().getLangFile().getMessages().getSuccessfullyAddedCredit(),
+ Main.getInstance().getLangFile().getMessages().getSuccessfullyAddedCredit(),
new Placeholder("{amount}", MoneyUtils.format(amount)),
new Placeholder("{target}", target)
));
+ }
}
/**
@@ -165,24 +174,22 @@ public void removeCommand(CommandSender sender, String target, Double amount) {
amount = MoneyUtils.parseDouble(amount);
if (amount <= 0) {
- ChatUtil.sendMessage(sender, Shared.getInstance().getLangFile().getMessages().getCannotSendCreditNotEnough());
- return;
- }
-/* TODO look at all of them in this class
- long userId = plugin.getPluginDatabase().getUserId(target);
- if (userId == 0) {
- ChatUtil.sendMessage(sender, Shared.getInstance().getLangFile().getMessages().getTargetPlayerNotAvailable());
+ ChatUtil.sendMessage(sender, Main.getInstance().getLangFile().getMessages().getCannotSendCreditNotEnough());
return;
}
- */
- Response removeCreditResponse = Credit.removeCreditRequest(target, amount);
+ Response removeCreditResponse = CreditHelper.removeCreditRequest(target, amount);
if (Objects.requireNonNull(removeCreditResponse).getResponseCode() == HttpURLConnection.HTTP_OK) {
+ if (Bukkit.getPlayerExact(target) != null)
+ // Calls UpdateCache event for update player's cache
+ Bukkit.getPluginManager().callEvent(new UpdateCacheEvent(target));
ChatUtil.sendMessage(sender, ChatUtil.replacePlaceholders(
- Main.getShared().getLangFile().getMessages().getSuccessfullyRemovedCredit(),
+ Main.getInstance().getLangFile().getMessages().getSuccessfullyRemovedCredit(),
new Placeholder("{amount}", MoneyUtils.format(amount)),
new Placeholder("{target}", target)
));
}
+ else
+ ChatUtil.sendMessage(sender, Main.getInstance().getLangFile().getMessages().getTargetPlayerNotAvailable());
}
/**
@@ -195,23 +202,19 @@ public void removeCommand(CommandSender sender, String target, Double amount) {
@Permission("credits.set")
public void setCommand(CommandSender sender, String target, Double amount) {
amount = MoneyUtils.parseDouble(amount);
-
- /*
- long userId = plugin.getPluginDatabase().getUserId(target);
- if (userId == 0) {
- ChatUtil.sendMessage(sender, Shared.getInstance().getLangFile().getMessages().getTargetPlayerNotAvailable());
- return;
- }
- */
-
- Response setCreditResponse = Credit.setCreditRequest(target, amount);
+ Response setCreditResponse = CreditHelper.setCreditRequest(target, amount);
if (Objects.requireNonNull(setCreditResponse).getResponseCode() == HttpURLConnection.HTTP_OK) {
+ if (Bukkit.getPlayerExact(target) != null)
+ // Calls UpdateCache event for update player's cache
+ Bukkit.getPluginManager().callEvent(new UpdateCacheEvent(target));
ChatUtil.sendMessage(sender, ChatUtil.replacePlaceholders(
- Main.getShared().getLangFile().getMessages().getSuccessfullySetCredit(),
+ Main.getInstance().getLangFile().getMessages().getSuccessfullySetCredit(),
new Placeholder("{amount}", MoneyUtils.format(amount)),
new Placeholder("{target}", target)
));
}
+ else
+ ChatUtil.sendMessage(sender, Main.getInstance().getLangFile().getMessages().getTargetPlayerNotAvailable());
}
}
diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/donators/Placeholders.java b/bukkit/src/main/java/net/leaderos/plugin/modules/donators/Placeholders.java
index 68e999070..9a16e0247 100644
--- a/bukkit/src/main/java/net/leaderos/plugin/modules/donators/Placeholders.java
+++ b/bukkit/src/main/java/net/leaderos/plugin/modules/donators/Placeholders.java
@@ -72,7 +72,7 @@ else if (identifier.startsWith("credit_")) {
String[] parts = identifier.split("_");
String lastPart = parts[parts.length - 1];
int donatorLine = Integer.parseInt(lastPart);
- if (donatorLine > Main.getShared().getModulesFile().getRecentDonations().getRecentDonationLimit())
+ if (donatorLine > Main.getInstance().getModulesFile().getRecentDonations().getRecentDonationLimit())
return null;
return RecentDonationData.getRecentDonation(donatorLine-1);
diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/donators/RecentDonations.java b/bukkit/src/main/java/net/leaderos/plugin/modules/donators/RecentDonations.java
index 1ac926fae..8857869ad 100644
--- a/bukkit/src/main/java/net/leaderos/plugin/modules/donators/RecentDonations.java
+++ b/bukkit/src/main/java/net/leaderos/plugin/modules/donators/RecentDonations.java
@@ -3,14 +3,14 @@
import com.cryptomorin.xseries.SkullUtils;
import com.cryptomorin.xseries.XMaterial;
import net.leaderos.plugin.Main;
+import net.leaderos.plugin.helpers.ChatUtil;
+import net.leaderos.plugin.modules.donators.commands.Commands;
import net.leaderos.plugin.modules.donators.model.RecentDonationData;
import net.leaderos.plugin.modules.donators.timer.Timer;
-import net.leaderos.shared.helpers.ChatUtil;
import net.leaderos.shared.helpers.Placeholder;
import net.leaderos.shared.module.LeaderOSModule;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
-import org.bukkit.command.CommandSender;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import org.jetbrains.annotations.NotNull;
@@ -29,6 +29,7 @@ public class RecentDonations extends LeaderOSModule {
* onEnable method of module
*/
public void onEnable() {
+ Main.getCommandManager().registerCommand(new Commands());
Timer.run();
if( Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI"))
new Placeholders().register();
@@ -38,6 +39,7 @@ public void onEnable() {
* onDisable method of module
*/
public void onDisable() {
+ Main.getCommandManager().unregisterCommand(new Commands());
Timer.taskid.cancel();
if( Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI"))
new Placeholders().unregister();
@@ -62,14 +64,16 @@ public RecentDonations() {}
UUID playerUUID = player.getUniqueId();
SkullMeta meta = SkullUtils.applySkin(Objects.requireNonNull(item.getItemMeta()), playerUUID);
meta.setDisplayName(ChatUtil.replacePlaceholders(
- Main.getShared().getLangFile().getGui().getDonationsGui().getDisplayName(),
+ Main.getInstance().getLangFile().getGui().getDonationsGui().getDisplayName(),
new Placeholder("%player%", donationData.getUserName()),
- new Placeholder("%credit%", donationData.getCredit()+"")
+ new Placeholder("%credit%", donationData.getCredit()+""),
+ new Placeholder("%symbol%", donationData.getSymbol())
));
meta.setLore(ChatUtil.replacePlaceholders(
- Main.getShared().getLangFile().getGui().getDonationsGui().getLore(),
+ Main.getInstance().getLangFile().getGui().getDonationsGui().getLore(),
new Placeholder("%player%", donationData.getUserName()),
- new Placeholder("%credit%", donationData.getCredit()+"")
+ new Placeholder("%credit%", donationData.getCredit()+""),
+ new Placeholder("%symbol%", donationData.getSymbol())
));
item.setItemMeta(meta);
return item;
diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/donators/commands/Commands.java b/bukkit/src/main/java/net/leaderos/plugin/modules/donators/commands/Commands.java
index 86effde82..f23d94ba7 100644
--- a/bukkit/src/main/java/net/leaderos/plugin/modules/donators/commands/Commands.java
+++ b/bukkit/src/main/java/net/leaderos/plugin/modules/donators/commands/Commands.java
@@ -4,9 +4,14 @@
import dev.triumphteam.cmd.core.BaseCommand;
import dev.triumphteam.cmd.core.annotation.Command;
import dev.triumphteam.cmd.core.annotation.Default;
+import dev.triumphteam.cmd.core.annotation.SubCommand;
import lombok.RequiredArgsConstructor;
+import net.leaderos.plugin.Main;
import net.leaderos.plugin.api.managers.ModuleManager;
+import net.leaderos.plugin.helpers.ChatUtil;
import net.leaderos.plugin.modules.donators.gui.RecentDonationGui;
+import net.leaderos.plugin.modules.donators.timer.Timer;
+import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
@@ -23,9 +28,20 @@ public class Commands extends BaseCommand {
* @param player executor
*/
@Default
- @Permission("recent.donations.open")
+ @Permission("donations.open")
public void defaultCommand(Player player) {
if (ModuleManager.getModule("RecentDonations").isEnabled())
RecentDonationGui.showGui(player);
}
+
+ /**
+ * updateCache command
+ * @param sender executor
+ */
+ @SubCommand(value = "update", alias = {"güncelle"})
+ @Permission("donations.update")
+ public void updateCacheCommand(CommandSender sender) {
+ ChatUtil.sendMessage(sender, Main.getInstance().getLangFile().getGui().getDonationsGui().getUpdatedDonationDataMessage());
+ Timer.run();
+ }
}
diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/donators/gui/RecentDonationGui.java b/bukkit/src/main/java/net/leaderos/plugin/modules/donators/gui/RecentDonationGui.java
index 05f86a561..ef90b23e2 100644
--- a/bukkit/src/main/java/net/leaderos/plugin/modules/donators/gui/RecentDonationGui.java
+++ b/bukkit/src/main/java/net/leaderos/plugin/modules/donators/gui/RecentDonationGui.java
@@ -6,10 +6,10 @@
import de.themoep.inventorygui.StaticGuiElement;
import lombok.SneakyThrows;
import net.leaderos.plugin.Main;
+import net.leaderos.plugin.helpers.ChatUtil;
import net.leaderos.plugin.helpers.GuiHelper;
import net.leaderos.plugin.modules.donators.RecentDonations;
import net.leaderos.plugin.modules.donators.model.RecentDonationData;
-import net.leaderos.shared.helpers.ChatUtil;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@@ -35,9 +35,9 @@ public RecentDonationGui() {}
@SneakyThrows
public static void showGui(Player player) {
// Gui template as array
- String[] layout = Main.getShared().getLangFile().getGui().getDonationsGui().getLayout().toArray(new String[0]);
+ String[] layout = Main.getInstance().getLangFile().getGui().getDonationsGui().getLayout().toArray(new String[0]);
// Inventory object
- String guiName = ChatUtil.color(Main.getShared().getLangFile().getGui().getDonationsGui().getGuiName());
+ String guiName = ChatUtil.color(Main.getInstance().getLangFile().getGui().getDonationsGui().getGuiName());
InventoryGui gui = new InventoryGui(Main.getInstance(), null, guiName, layout);
// Filler item for empty slots
gui.setFiller(GuiHelper.getFiller());
diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/donators/model/RecentDonationData.java b/bukkit/src/main/java/net/leaderos/plugin/modules/donators/model/RecentDonationData.java
index a89e026f4..d7de32ae2 100644
--- a/bukkit/src/main/java/net/leaderos/plugin/modules/donators/model/RecentDonationData.java
+++ b/bukkit/src/main/java/net/leaderos/plugin/modules/donators/model/RecentDonationData.java
@@ -40,25 +40,24 @@ public class RecentDonationData {
*/
private double credit;
+ /**
+ * Credits symbol for placeholder
+ */
+ private String symbol;
+
/**
* Updates all recent donations data
*/
public static void updateAllRecentDonationsData() {
- // TODO Update request
List donationDataList = new ArrayList<>();
try {
- Response recentDonationResponse = new GetRequest("donations/" + Main.getShared().getModulesFile().getRecentDonations().getRecentDonationLimit()).getResponse();
+ Response recentDonationResponse = new GetRequest("store/donates/?type=latest&limit=" + Main.getInstance().getModulesFile().getRecentDonations().getRecentDonationLimit()).getResponse();
if (recentDonationResponse.getResponseCode() == HttpURLConnection.HTTP_OK)
recentDonationResponse.getResponseMessage().getJSONArray("array").forEach(recentDonation -> {
JSONObject donation = (JSONObject) recentDonation;
- donationDataList.add(new RecentDonationData(donation.getString("username"), donation.getDouble("credit")));
+ donationDataList.add(new RecentDonationData(donation.getString("username"), donation.getDouble("raw_total"), donation.getString("currency")));
});
- else
- // TODO Exception handling
- throw new IOException();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
+ } catch (IOException ignored) {}
recentDonationDataList = donationDataList;
}
diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/donators/timer/Timer.java b/bukkit/src/main/java/net/leaderos/plugin/modules/donators/timer/Timer.java
index 4b456006c..d9e85259a 100644
--- a/bukkit/src/main/java/net/leaderos/plugin/modules/donators/timer/Timer.java
+++ b/bukkit/src/main/java/net/leaderos/plugin/modules/donators/timer/Timer.java
@@ -2,6 +2,7 @@
import net.leaderos.plugin.Main;
import net.leaderos.plugin.modules.donators.model.RecentDonationData;
+import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitRunnable;
/**
@@ -32,8 +33,8 @@ public void run() {
};
taskid.runTaskTimerAsynchronously(Main.getInstance(),
- 20*Main.getShared().getModulesFile().getRecentDonations().getUpdateSecond(),
- 20*Main.getShared().getModulesFile().getRecentDonations().getUpdateSecond());
+ 1L,
+ 20*Main.getInstance().getModulesFile().getRecentDonations().getUpdateSecond());
}
}
diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/voucher/commands/Commands.java b/bukkit/src/main/java/net/leaderos/plugin/modules/voucher/commands/Commands.java
index 251109293..a44a120d4 100644
--- a/bukkit/src/main/java/net/leaderos/plugin/modules/voucher/commands/Commands.java
+++ b/bukkit/src/main/java/net/leaderos/plugin/modules/voucher/commands/Commands.java
@@ -9,14 +9,17 @@
import dev.triumphteam.cmd.core.annotation.SubCommand;
import lombok.RequiredArgsConstructor;
import net.leaderos.plugin.Main;
+import net.leaderos.plugin.api.handlers.UpdateCacheEvent;
+import net.leaderos.plugin.helpers.ChatUtil;
import net.leaderos.plugin.helpers.ItemUtils;
import net.leaderos.plugin.modules.credit.Credit;
import net.leaderos.plugin.modules.voucher.Voucher;
import net.leaderos.shared.Shared;
-import net.leaderos.shared.helpers.ChatUtil;
import net.leaderos.shared.helpers.MoneyUtils;
import net.leaderos.shared.helpers.Placeholder;
import net.leaderos.shared.model.Response;
+import net.leaderos.shared.module.credit.CreditHelper;
+import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@@ -42,10 +45,10 @@ public class Commands extends BaseCommand {
@Default
public void defaultCommand(CommandSender sender) {
if (sender.hasPermission("credits.voucher.give")) {
- ChatUtil.sendMessage(sender, Shared.getInstance().getLangFile().getMessages().getVouchers().getHelpStaff());
+ ChatUtil.sendMessage(sender, Main.getInstance().getLangFile().getMessages().getVouchers().getHelpStaff());
}
if (sender.hasPermission("credits.voucher.create")) {
- ChatUtil.sendMessage(sender, Shared.getInstance().getLangFile().getMessages().getVouchers().getHelp());
+ ChatUtil.sendMessage(sender, Main.getInstance().getLangFile().getMessages().getVouchers().getHelp());
}
}
@@ -62,7 +65,7 @@ public void giveCommand(CommandSender sender, Player player, Double amount) {
giveVoucher(player, amount);
ChatUtil.sendMessage(sender, ChatUtil.replacePlaceholders(
- Main.getShared().getLangFile().getMessages().getVouchers().getSuccessfullyGave(),
+ Main.getInstance().getLangFile().getMessages().getVouchers().getSuccessfullyGave(),
new Placeholder("{target}", player.getName()),
new Placeholder("{amount}", MoneyUtils.format(amount))
));
@@ -79,49 +82,38 @@ public void createCommand(Player player, Double amount) {
amount = MoneyUtils.parseDouble(amount);
if (amount <= 0) {
- ChatUtil.sendMessage(player, Shared.getInstance().getLangFile().getMessages().getVouchers().getCannotCreateNegative());
+ ChatUtil.sendMessage(player, Main.getInstance().getLangFile().getMessages().getVouchers().getCannotCreateNegative());
return;
}
if (player.getInventory().firstEmpty() == -1) {
- ChatUtil.sendMessage(player, Shared.getInstance().getLangFile().getMessages().getCannotCreateFull());
+ ChatUtil.sendMessage(player, Main.getInstance().getLangFile().getMessages().getCannotCreateFull());
return;
}
- /*
- long userId = plugin.getPluginDatabase().getUserId(player.getName());
- if (userId == 0) {
- ChatUtil.sendMessage(player, Shared.getInstance().getLangFile().getMessages().getPlayerNotAvailable());
- return;
- }
- */
-
try {
- Response removeCreditRequest = Credit.removeCreditRequest(player.getName(), amount);
+ Response removeCreditRequest = CreditHelper.removeCreditRequest(player.getName(), amount);
- if (Objects.requireNonNull(removeCreditRequest).getResponseCode() == HttpURLConnection.HTTP_OK) {
+ if (Objects.requireNonNull(removeCreditRequest).getResponseCode() == HttpURLConnection.HTTP_OK
+ && removeCreditRequest.getResponseMessage().getBoolean("status")) {
+ // Calls UpdateCache event for update player's cache
+ Bukkit.getPluginManager().callEvent(new UpdateCacheEvent(player.getName()));
ChatUtil.sendMessage(player, ChatUtil.replacePlaceholders(
- Main.getShared().getLangFile().getMessages().getVouchers().getSuccessfullyCreated(),
+ Main.getInstance().getLangFile().getMessages().getVouchers().getSuccessfullyCreated(),
new Placeholder("{amount}", MoneyUtils.format(amount))
));
giveVoucher(player, amount);
}
- // TODO ELIF CODE == Cannot afford
- /*
- if (credit < amount) {
+ // TODO if code not afforded or not ok
+ else
ChatUtil.sendMessage(player, ChatUtil.replacePlaceholders(
- Shared.getInstance().getLangFile().getMessages().getVouchers().getCannotCreateNotEnough(),
+ Main.getInstance().getLangFile().getMessages().getVouchers().getCannotCreateNotEnough(),
new Placeholder("{amount}", MoneyUtils.format(amount))
));
- return;
- }
- */
-
}
- catch (Exception e) {
- // TODO HERE
+ catch (Exception ignored) {
+ ChatUtil.sendMessage(player, Main.getInstance().getLangFile().getMessages().getPlayerNotAvailable());
}
-
}
/**
@@ -133,7 +125,7 @@ private void giveVoucher(Player player, Double amount) {
amount = MoneyUtils.parseDouble(amount);
if (amount <= 0) {
- ChatUtil.sendMessage(player, Shared.getInstance().getLangFile().getMessages().getVouchers().getCannotCreateNegative());
+ ChatUtil.sendMessage(player, Main.getInstance().getLangFile().getMessages().getVouchers().getCannotCreateNegative());
return;
}
@@ -141,11 +133,11 @@ private void giveVoucher(Player player, Double amount) {
Voucher.getVoucherData().set("lastCreated", id);
Voucher.getVoucherData().save();
- String name = ChatUtil.replacePlaceholders(Main.getShared().getLangFile().getMessages().getVouchers().getItemDisplayName(),
+ String name = ChatUtil.replacePlaceholders(Main.getInstance().getLangFile().getMessages().getVouchers().getItemDisplayName(),
new Placeholder("{id}", id + ""), new Placeholder("{amount}", MoneyUtils.format(amount)));
- List lore = ChatUtil.replacePlaceholders(Main.getShared().getLangFile().getMessages().getVouchers().getItemLore(),
+ List lore = ChatUtil.replacePlaceholders(Main.getInstance().getLangFile().getMessages().getVouchers().getItemLore(),
new Placeholder("{id}", id + ""), new Placeholder("{amount}", MoneyUtils.format(amount)));
- ItemStack item = ItemUtils.getItem(XMaterial.PAPER, name, lore);
+ ItemStack item = ItemUtils.getItem(XMaterial.PAPER, name, lore, true);
NBTItem nbtItem = new NBTItem(item);
nbtItem.setBoolean("voucher", true);
diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/voucher/handlers/VoucherListener.java b/bukkit/src/main/java/net/leaderos/plugin/modules/voucher/handlers/VoucherListener.java
index f6cd034f8..0888ebb46 100644
--- a/bukkit/src/main/java/net/leaderos/plugin/modules/voucher/handlers/VoucherListener.java
+++ b/bukkit/src/main/java/net/leaderos/plugin/modules/voucher/handlers/VoucherListener.java
@@ -3,13 +3,17 @@
import com.cryptomorin.xseries.XMaterial;
import de.tr7zw.nbtapi.NBTItem;
import net.leaderos.plugin.Main;
+import net.leaderos.plugin.api.handlers.ModuleEnableEvent;
+import net.leaderos.plugin.api.handlers.UpdateCacheEvent;
+import net.leaderos.plugin.helpers.ChatUtil;
import net.leaderos.plugin.modules.credit.Credit;
import net.leaderos.plugin.modules.voucher.Voucher;
import net.leaderos.shared.Shared;
-import net.leaderos.shared.helpers.ChatUtil;
import net.leaderos.shared.helpers.MoneyUtils;
import net.leaderos.shared.helpers.Placeholder;
import net.leaderos.shared.model.Response;
+import net.leaderos.shared.module.credit.CreditHelper;
+import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@@ -55,36 +59,33 @@ public void onRightClick(PlayerInteractEvent event) {
double amount = MoneyUtils.parseDouble(nbtItem.getDouble("voucher:amount"));
// Checks amount just in case
if (amount <= 0) {
- ChatUtil.sendMessage(player, Shared.getInstance().getLangFile().getMessages().getVouchers().getCannotCreateNegative());
+ ChatUtil.sendMessage(player, Main.getInstance().getLangFile().getMessages().getVouchers().getCannotCreateNegative());
return;
}
// Checks is voucher has been used before
List list = Voucher.getVoucherData().getIntegerList("used");
if (list.contains(id)) {
- ChatUtil.sendMessage(player, Shared.getInstance().getLangFile().getMessages().getVouchers().getAlreadyUsed());
+ ChatUtil.sendMessage(player, Main.getInstance().getLangFile().getMessages().getVouchers().getAlreadyUsed());
return;
}
- Response depositResponse = Credit.addCreditRequest(player.getName(), amount);
- if (Objects.requireNonNull(depositResponse).getResponseCode() == HttpURLConnection.HTTP_OK) {
+ Response depositResponse = CreditHelper.addCreditRequest(player.getName(), amount);
+ if (Objects.requireNonNull(depositResponse).getResponseCode() == HttpURLConnection.HTTP_OK
+ && depositResponse.getResponseMessage().getBoolean("status")) {
remove(player, id);
list.add(id);
Voucher.getVoucherData().set("used", list);
Voucher.getVoucherData().save();
- // TODO update cache event
+ // Calls UpdateCache event for update player's cache
+ Bukkit.getPluginManager().callEvent(new UpdateCacheEvent(player.getName()));
ChatUtil.sendMessage(player, ChatUtil.replacePlaceholders(
- Main.getShared().getLangFile().getMessages().getVouchers()
+ Main.getInstance().getLangFile().getMessages().getVouchers()
.getSuccessfullyUsed(), new Placeholder("{amount}", MoneyUtils.format(amount) + "")
));
}
- /* TODO else
- long userId = plugin.getPluginDatabase().getUserId(player.getName());
- if (userId == 0) {
- ChatUtils.sendMessage(player, Shared.getInstance().getLangFile().getMessages().getPlayerNotAvailable());
- return;
- }
- */
+ else
+ ChatUtil.sendMessage(player, Main.getInstance().getLangFile().getMessages().getPlayerNotAvailable());
}
/**
diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/WebStore.java b/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/WebStore.java
index 021175abb..47707b6b2 100644
--- a/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/WebStore.java
+++ b/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/WebStore.java
@@ -23,9 +23,7 @@ public void onEnable() {
Main.getCommandManager().registerCommand(new Commands());
try {
Category.loadAllCategories();
- } catch (IOException e) {
- throw new RuntimeException(e);
- } catch (RequestException e) {
+ } catch (IOException | RequestException e) {
throw new RuntimeException(e);
}
}
@@ -40,5 +38,7 @@ public void onDisable() {
/**
* Constructor of WebStore
*/
- public WebStore() {}
+ public WebStore() {
+ addDependency("Cache");
+ }
}
diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/command/Commands.java b/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/command/Commands.java
index 36b36992c..0d351de0b 100644
--- a/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/command/Commands.java
+++ b/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/command/Commands.java
@@ -5,6 +5,7 @@
import dev.triumphteam.cmd.core.annotation.Command;
import dev.triumphteam.cmd.core.annotation.Default;
import lombok.RequiredArgsConstructor;
+import net.leaderos.plugin.api.managers.ModuleManager;
import net.leaderos.plugin.modules.webstore.gui.MainWebStoreGui;
import net.leaderos.plugin.api.LeaderOSAPI;
import org.bukkit.entity.Player;
@@ -26,7 +27,8 @@ public class Commands extends BaseCommand {
@Permission("webshop.open")
public void defaultCommand(Player player) {
// TODO Open gui
- if (LeaderOSAPI.getModuleManager().getModule("WebStore").isEnabled())
+ LeaderOSAPI.getModuleManager();
+ if (ModuleManager.getModule("WebStore").isEnabled())
MainWebStoreGui.showGui(player);
}
}
diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/gui/MainWebStoreGui.java b/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/gui/MainWebStoreGui.java
index 7c57d1f80..73ff91f69 100644
--- a/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/gui/MainWebStoreGui.java
+++ b/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/gui/MainWebStoreGui.java
@@ -4,9 +4,9 @@
import de.themoep.inventorygui.GuiElementGroup;
import de.themoep.inventorygui.InventoryGui;
import de.themoep.inventorygui.StaticGuiElement;
+import net.leaderos.plugin.helpers.ChatUtil;
import net.leaderos.plugin.modules.webstore.model.Category;
import net.leaderos.plugin.Main;
-import net.leaderos.shared.helpers.ChatUtil;
import net.leaderos.plugin.helpers.GuiHelper;
import org.bukkit.entity.Player;
@@ -32,9 +32,9 @@ public MainWebStoreGui() {
*/
public static void showGui(Player player) {
// Gui template as array
- String[] layout = Main.getShared().getLangFile().getGui().getWebStoreGui().getLandingGuiLayout().toArray(new String[0]);
+ String[] layout = Main.getInstance().getLangFile().getGui().getWebStoreGui().getLandingGuiLayout().toArray(new String[0]);
// Inventory object
- String guiName = ChatUtil.color(Main.getShared().getLangFile().getGui().getWebStoreGui().getGuiName());
+ String guiName = ChatUtil.color(Main.getInstance().getLangFile().getGui().getWebStoreGui().getGuiName());
InventoryGui gui = new InventoryGui(Main.getInstance(), null, guiName, layout);
// Filler item for empty slots
gui.setFiller(GuiHelper.getFiller());
diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/gui/WebStoreGui.java b/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/gui/WebStoreGui.java
index 9479bc686..3212842bb 100644
--- a/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/gui/WebStoreGui.java
+++ b/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/gui/WebStoreGui.java
@@ -4,15 +4,19 @@
import de.themoep.inventorygui.GuiElementGroup;
import de.themoep.inventorygui.InventoryGui;
import de.themoep.inventorygui.StaticGuiElement;
+import net.leaderos.plugin.api.handlers.UpdateCacheEvent;
+import net.leaderos.plugin.api.managers.ModuleManager;
+import net.leaderos.plugin.helpers.ChatUtil;
import net.leaderos.plugin.modules.cache.model.User;
import net.leaderos.plugin.modules.webstore.model.Category;
import net.leaderos.plugin.Main;
import net.leaderos.plugin.modules.webstore.model.Product;
-import net.leaderos.shared.helpers.ChatUtil;
import net.leaderos.plugin.helpers.GuiHelper;
-import net.leaderos.plugin.modules.auth.AuthLogin;
+import net.leaderos.shared.helpers.MDChat.MDChatAPI;
import net.leaderos.shared.model.Response;
import net.leaderos.shared.model.request.PostRequest;
+import net.leaderos.shared.module.auth.AuthHelper;
+import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.io.IOException;
@@ -38,9 +42,9 @@ public WebStoreGui() {}
*/
public static void showGui(Player player, Category categoryObj) {
// Gui template as array
- String[] layout = Main.getShared().getLangFile().getGui().getWebStoreGui().getLayout().toArray(new String[0]);
+ String[] layout = Main.getInstance().getLangFile().getGui().getWebStoreGui().getLayout().toArray(new String[0]);
// Inventory object
- String guiName = ChatUtil.color(Main.getShared().getLangFile().getGui().getWebStoreGui().getGuiName());
+ String guiName = ChatUtil.color(Main.getInstance().getLangFile().getGui().getWebStoreGui().getGuiName());
InventoryGui gui = new InventoryGui(Main.getInstance(), null, guiName, layout);
// Filler item for empty slots
gui.setFiller(GuiHelper.getFiller());
@@ -51,76 +55,123 @@ public static void showGui(Player player, Category categoryObj) {
if (categoryObj == null) {
categoryList = Category.getCategories();
productList = new ArrayList<>();
- }
- else {
+ } else {
categoryList = categoryObj.getSubCategories();
productList = categoryObj.getProductList();
}
+ GuiElementGroup elementGroup = new GuiElementGroup('e');
// Category group creator
GuiElementGroup categoryGroup = new GuiElementGroup('c');
- if (!categoryList.isEmpty())
- categoryList.stream().forEach(category -> categoryGroup.addElement(new DynamicGuiElement('s', (viewer)
- -> new StaticGuiElement('s',
- category.getCategoryIcon(),
- 1,
- click -> {
- click.getEvent().setCancelled(true);
- showGui(player, category);
- return true;
- })))
- );
- gui.addElement(categoryGroup);
+ if (!categoryList.isEmpty()) {
+ // Element group
+ addCategoriesToGroup(categoryList, elementGroup, player);
+ // Category group
+ addCategoriesToGroup(categoryList, categoryGroup, player);
+ categoryGroup.setFiller(GuiHelper.getFiller());
+ gui.addElement(categoryGroup);
+ }
// Product group creator
GuiElementGroup productGroup = new GuiElementGroup('p');
- if (!productList.isEmpty())
+ if (!productList.isEmpty()) {
+ // Element group
+ addProductsToGroup(productList, elementGroup, player, gui);
+
// Product Group
- productList.forEach(product -> productGroup.addElement(new DynamicGuiElement('e', (viewer)
- -> new StaticGuiElement('e',
- product.getProductIcon(),
- 1,
- click -> {
- click.getEvent().setCancelled(true);
- gui.close();
- // TODO Product click event
- if (User.isPlayerAuthed(player)) {
- User user = User.getUser(player.getName());
- Map body = new HashMap<>();
- body.put("user", user.getId());
- String[] products = new String[1];
- products[0] = product.getProductId();
- body.put("products", Arrays.toString(products));
+ addProductsToGroup(productList, productGroup, player, gui);
+ productGroup.setFiller(GuiHelper.getFiller());
+ gui.addElement(productGroup);
+ }
+ elementGroup.setFiller(GuiHelper.getFiller());
+ gui.addElement(elementGroup);
- // Titles
- String title = ChatUtil.color(Main.getShared().getLangFile().getGui().getWebStoreGui().getBuyWebStoreTitle());
- String subtitleError = ChatUtil.color(Main.getShared().getLangFile().getGui().getWebStoreGui().getBuyWebStoreError());
- String subtitleProgress = ChatUtil.color(Main.getShared().getLangFile().getGui().getWebStoreGui().getBuyWebStoreProgress());
- String subtitleSuccess = ChatUtil.color(Main.getShared().getLangFile().getGui().getWebStoreGui().getBuyWebStoreSuccess());
- player.sendTitle(title, subtitleProgress);
- try {
- // TODO FIRAT HERE
- Response buyRequest = new PostRequest("store/buy", body).getResponse();
- // TODO CODE
- if (buyRequest.getResponseCode() == HttpURLConnection.HTTP_CREATED)
- player.sendTitle(title, subtitleSuccess);
- else throw new IOException();
- } catch (IOException e) {
- // TODO Handling
- player.sendTitle(title, subtitleError);
- throw new RuntimeException(e);
- }
- }
- else
- AuthLogin.sendAuthModuleError(player);
- return false;
- })))
- );
- gui.addElement(productGroup);
// Next and previos page icons
gui.addElement(GuiHelper.createNextPage());
gui.addElement(GuiHelper.createPreviousPage());
gui.show(player);
}
+
+ /**
+ * Adds product to gui element group
+ * @param productList list of product
+ * @param group element group of gui
+ * @param player inventory holder
+ * @param gui opened gui
+ */
+ private static void addProductsToGroup(List productList, GuiElementGroup group, Player player, InventoryGui gui) {
+ productList.forEach(product -> group.addElement(new DynamicGuiElement('e', (viewer)
+ -> new StaticGuiElement('e',
+ product.getProductIcon(),
+ 1,
+ click -> {
+ click.getEvent().setCancelled(true);
+ gui.close();
+ if (User.isPlayerAuthed(player)) {
+ User user = User.getUser(player.getName());
+ Map body = new HashMap<>();
+ body.put("user", user.getId());
+ body.put("products[]", product.getProductId());
+
+ // Titles
+ String title = ChatUtil.color(Main.getInstance().getLangFile().getGui().getWebStoreGui().getBuyWebStoreTitle());
+ String subtitleError = ChatUtil.color(Main.getInstance().getLangFile().getGui().getWebStoreGui().getBuyWebStoreError());
+ String subtitleProgress = ChatUtil.color(Main.getInstance().getLangFile().getGui().getWebStoreGui().getBuyWebStoreProgress());
+ String subtitleSuccess = ChatUtil.color(Main.getInstance().getLangFile().getGui().getWebStoreGui().getBuyWebStoreSuccess());
+ String subtitleNotEnoughCredit = ChatUtil.color(Main.getInstance().getLangFile().getGui().getWebStoreGui().getBuyWebStoreNotEnoughCredit());
+ player.sendTitle(title, subtitleProgress);
+ // Buy progress
+ try {
+ Response buyRequest = new PostRequest("store/buy", body).getResponse();
+ if (buyRequest.getResponseCode() == HttpURLConnection.HTTP_OK) {
+ // Calls UpdateCache event for update player's cache
+ Bukkit.getPluginManager().callEvent(new UpdateCacheEvent(player.getName()));
+ player.sendTitle(title, subtitleSuccess);
+ }
+ else if (buyRequest.getResponseCode() == HttpURLConnection.HTTP_BAD_REQUEST)
+ player.sendTitle(title, subtitleNotEnoughCredit);
+ else throw new IOException();
+ } catch (IOException e) {
+ player.sendTitle(title, subtitleError);
+ }
+ }
+ else {
+ // If auth login is enabled
+ if (ModuleManager.getModule("AuthLogin").getStatus()) {
+ String authLink = AuthHelper.getAuthLink(player);
+ if (authLink != null)
+ player.spigot().sendMessage(
+ MDChatAPI.getFormattedMessage(
+ ChatUtil.color(Main.getInstance().getLangFile().getMessages().getAuth().getModuleError()
+ .replace("%link%", authLink)
+ .replace("{prefix}", Main.getInstance().getLangFile().getMessages().getPrefix()))));
+ }
+ // If cache not found and authlogin is disabled situation
+ else
+ ChatUtil.sendMessage(player, Main.getInstance().getLangFile().getGui().getWebStoreGui().getBuyWebStoreNoAuthLinkError());
+ }
+ return false;
+ })))
+ );
+ }
+
+ /**
+ * Adds category object to element group
+ * @param categoryList list of category
+ * @param group element group
+ * @param player gui opener
+ */
+ private static void addCategoriesToGroup(List categoryList, GuiElementGroup group, Player player) {
+ categoryList.forEach(category -> group.addElement(new DynamicGuiElement('s', (viewer)
+ -> new StaticGuiElement('s',
+ category.getCategoryIcon(),
+ 1,
+ click -> {
+ click.getEvent().setCancelled(true);
+ showGui(player, category);
+ return true;
+ })))
+ );
+ }
}
diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/model/Category.java b/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/model/Category.java
index a5a9d506b..386e2b433 100644
--- a/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/model/Category.java
+++ b/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/model/Category.java
@@ -4,10 +4,9 @@
import lombok.Getter;
import lombok.Setter;
import net.leaderos.plugin.Main;
+import net.leaderos.plugin.helpers.ChatUtil;
import net.leaderos.plugin.helpers.ItemUtils;
import net.leaderos.shared.exceptions.RequestException;
-import net.leaderos.shared.helpers.ChatUtil;
-import net.leaderos.plugin.helpers.GuiHelper;
import net.leaderos.shared.model.request.GetRequest;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
@@ -100,7 +99,7 @@ public Category(@NotNull JSONObject category) {
throw new Exception();
}
catch (Exception e) {
- this.categoryLore = Main.getShared().getLangFile().getGui().getDefaultGui().getDefaultCategory().getLore();
+ this.categoryLore = Main.getInstance().getLangFile().getGui().getDefaultGui().getDefaultCategory().getLore();
}
String materialName = category.getString("minecraftItem");
@@ -108,7 +107,7 @@ public Category(@NotNull JSONObject category) {
this.material = XMaterial.matchXMaterial(category.getString("minecraftItem")).get();
if (material == null || !material.isSupported())
- this.material = XMaterial.matchXMaterial(Main.getShared().getLangFile().getGui()
+ this.material = XMaterial.matchXMaterial(Main.getInstance().getLangFile().getGui()
.getDefaultGui().getDefaultCategory().getMaterial()).get();
// products
diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/model/Product.java b/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/model/Product.java
index 2fe214554..6f403586b 100644
--- a/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/model/Product.java
+++ b/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/model/Product.java
@@ -5,9 +5,8 @@
import lombok.Setter;
import lombok.SneakyThrows;
import net.leaderos.plugin.Main;
+import net.leaderos.plugin.helpers.ChatUtil;
import net.leaderos.plugin.helpers.ItemUtils;
-import net.leaderos.shared.helpers.ChatUtil;
-import net.leaderos.plugin.helpers.GuiHelper;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.json.JSONObject;
@@ -105,7 +104,7 @@ public Product(@NotNull JSONObject product) {
throw new Exception();
}
catch (Exception e) {
- this.productLore = Main.getShared().getLangFile().getGui().getDefaultGui().getDefaultProduct().getLore();
+ this.productLore = Main.getInstance().getLangFile().getGui().getDefaultGui().getDefaultProduct().getLore();
}
// price, discountedPrice, stock data
@@ -129,7 +128,7 @@ public Product(@NotNull JSONObject product) {
this.material = XMaterial.matchXMaterial(product.getString("minecraftItem")).get();
if (material == null || !material.isSupported())
- this.material = XMaterial.matchXMaterial(Main.getShared().getLangFile().getGui()
+ this.material = XMaterial.matchXMaterial(Main.getInstance().getLangFile().getGui()
.getDefaultGui().getDefaultProduct().getMaterial()).get();
}
@@ -152,12 +151,12 @@ public ItemStack getProductIcon() {
int discountAmount = (int) (((getPrice() - getDiscountedPrice()) / getPrice()) * 100);
// Formatters of discount
- String discountedPriceFormat = Main.getShared().getLangFile().getGui().getWebStoreGui().getDiscountedPriceFormat()
+ String discountedPriceFormat = Main.getInstance().getLangFile().getGui().getWebStoreGui().getDiscountedPriceFormat()
.replace("{price}", price+"")
.replace("{discountedPrice}", discountedPrice+"");
- String discountAmountFormat = Main.getShared().getLangFile().getGui().getWebStoreGui().getDiscountAmountFormat()
+ String discountAmountFormat = Main.getInstance().getLangFile().getGui().getWebStoreGui().getDiscountAmountFormat()
.replace("{discount}", discountAmount+"");
- String stockUnlimited = Main.getShared().getLangFile().getGui().getWebStoreGui().getStockUnlimited();
+ String stockUnlimited = Main.getInstance().getLangFile().getGui().getWebStoreGui().getStockUnlimited();
// Discount modifier of item
diff --git a/bungee.iml b/bungee.iml
new file mode 100644
index 000000000..1f4702c39
--- /dev/null
+++ b/bungee.iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+ BUNGEECORD
+ SPIGOT
+
+
+
+
+
\ No newline at end of file
diff --git a/bungee/pom.xml b/bungee/pom.xml
new file mode 100644
index 000000000..a41025dd8
--- /dev/null
+++ b/bungee/pom.xml
@@ -0,0 +1,43 @@
+
+
+ 4.0.0
+
+ net.leaderos
+ leaderos
+ 1.0-SNAPSHOT
+
+
+ bungee
+
+
+ 8
+ 8
+ UTF-8
+
+
+
+
+
+ net.md-5
+ bungeecord-api
+ 1.20-R0.1-SNAPSHOT
+ provided
+
+
+
+ net.leaderos
+ shared
+ 1.0-SNAPSHOT
+ compile
+
+
+
+ eu.okaeri
+ okaeri-configs-yaml-bungee
+ 5.0.0-beta.5
+
+
+
+
\ No newline at end of file
diff --git a/bungee/src/main/java/net/leaderos/Bungee.java b/bungee/src/main/java/net/leaderos/Bungee.java
new file mode 100644
index 000000000..f531d2d06
--- /dev/null
+++ b/bungee/src/main/java/net/leaderos/Bungee.java
@@ -0,0 +1,33 @@
+package net.leaderos;
+
+import lombok.Getter;
+import net.md_5.bungee.api.plugin.Plugin;
+
+/**
+ * Bungeecord main class
+ * @author poyrazinan
+ * @since 1.0
+ */
+public class Bungee extends Plugin {
+
+ /**
+ * Instance of plugin
+ */
+ @Getter
+ private static Bungee instance;
+
+ /**
+ * onEnable method of bungeecord
+ */
+ public void onEnable() {
+ instance = this;
+
+ }
+
+ /**
+ * onDisable method of bungeecord
+ */
+ public void onDisable() {
+ }
+
+}
\ No newline at end of file
diff --git a/bungee/src/main/java/net/leaderos/modules/auth/AuthLogin.java b/bungee/src/main/java/net/leaderos/modules/auth/AuthLogin.java
new file mode 100644
index 000000000..af4932fbd
--- /dev/null
+++ b/bungee/src/main/java/net/leaderos/modules/auth/AuthLogin.java
@@ -0,0 +1,109 @@
+package net.leaderos.modules.auth;
+
+import net.leaderos.Bungee;
+import net.leaderos.modules.auth.commands.Commands;
+import net.leaderos.shared.model.request.PostRequest;
+import net.leaderos.shared.module.LeaderOSModule;
+import net.md_5.bungee.api.connection.ProxiedPlayer;
+import org.json.JSONObject;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Auth module of leaderos-plugin
+ *
+ * @author poyrazinan
+ * @since 1.0
+ */
+public class AuthLogin extends LeaderOSModule {
+
+ /**
+ * Commands of module
+ */
+ private Commands commands;
+
+ /**
+ * onEnable method of module
+ */
+ public void onEnable() {
+ this.commands = new Commands("auth");
+ Bungee.getInstance().getProxy().getPluginManager().registerCommand(Bungee.getInstance(), commands);
+ }
+
+ /**
+ * onDisable method of module
+ */
+ public void onDisable() {
+ Bungee.getInstance().getProxy().getPluginManager().unregisterCommand(commands);
+ }
+
+
+ /**
+ * Generates user login link
+ *
+ * @param username of player
+ * @param uuid of player
+ * @return String of url
+ * @throws IOException request exception
+ */
+ public static String generateLink(String username, String uuid) throws IOException {
+ Map formData = new HashMap<>();
+ formData.put("username", username);
+ formData.put("uuid", uuid);
+ PostRequest postRequest = new PostRequest("auth/generate-link", formData);
+ JSONObject response = postRequest.getResponse().getResponseMessage().getJSONObject("data");
+ return response.getString("url");
+ }
+
+ /**
+ * sends auth command message
+ *
+ * @param player executor
+ */
+ public static void sendAuthCommandMessage(ProxiedPlayer player) {
+ try {
+ String link = generateLink(player.getName(), player.getUniqueId().toString());
+ player.sendMessage(link);
+ /* TODO
+ player.sendMessage(
+ MDChatAPI.getFormattedMessage(ChatUtil.color(Shared.getInstance()
+ .getLangFile().getMessages()
+ .getAuth().getCommandMessage().replace("%link%", link))));
+
+ */
+ } catch (Exception e) {
+ e.printStackTrace();
+ // TODO Exception
+ }
+ }
+
+ /**
+ * sends auth module error message
+ *
+ * @param player executor
+ */
+ public static void sendAuthModuleError(ProxiedPlayer player) {
+ try {
+ String link = generateLink(player.getName(), player.getUniqueId().toString());
+ player.sendMessage(link);
+ /* TODO
+ player.sendMessage(
+ MDChatAPI.getFormattedMessage(ChatUtil.color(Shared.getInstance()
+ .getLangFile().getMessages()
+ .getAuth().getModuleError().replace("%link%", link))));
+
+ */
+ } catch (Exception e) {
+ e.printStackTrace();
+ // TODO Exception
+ }
+ }
+
+ /**
+ * Constructor of Auth
+ */
+ public AuthLogin() {
+ }
+}
diff --git a/bungee/src/main/java/net/leaderos/modules/auth/commands/Commands.java b/bungee/src/main/java/net/leaderos/modules/auth/commands/Commands.java
new file mode 100644
index 000000000..7378e1016
--- /dev/null
+++ b/bungee/src/main/java/net/leaderos/modules/auth/commands/Commands.java
@@ -0,0 +1,33 @@
+package net.leaderos.modules.auth.commands;
+
+import net.leaderos.modules.auth.AuthLogin;
+import net.md_5.bungee.api.CommandSender;
+import net.md_5.bungee.api.connection.ProxiedPlayer;
+import net.md_5.bungee.api.plugin.Command;
+
+/**
+ * Auth commands
+ * @author poyrazinan
+ * @since 1.0
+ */
+public class Commands extends Command {
+
+ /**
+ * Constructor of author command
+ * @param name of command
+ */
+ public Commands(String name) {
+ super(name);
+ }
+
+ /**
+ * Default command of auth
+ * @param sender executor
+ * @param args command args
+ */
+ @Override
+ public void execute(CommandSender sender, String[] args) {
+ if (sender instanceof ProxiedPlayer)
+ AuthLogin.sendAuthCommandMessage((ProxiedPlayer) sender);
+ }
+}
\ No newline at end of file
diff --git a/bungee/src/main/java/net/leaderos/modules/credits/Credit.java b/bungee/src/main/java/net/leaderos/modules/credits/Credit.java
new file mode 100644
index 000000000..7d249d51e
--- /dev/null
+++ b/bungee/src/main/java/net/leaderos/modules/credits/Credit.java
@@ -0,0 +1,41 @@
+package net.leaderos.modules.credits;
+
+import net.leaderos.Bungee;
+import net.leaderos.modules.credits.commands.Commands;
+import net.leaderos.shared.module.LeaderOSModule;
+
+/**
+ * Credit module of leaderos-plugin
+ *
+ * @author poyrazinan
+ * @since 1.0
+ */
+public class Credit extends LeaderOSModule {
+
+ /**
+ * Commands of module
+ */
+ private Commands commands;
+
+ /**
+ * onEnable method of module
+ */
+ public void onEnable() {
+ this.commands = new Commands("credits");
+ Bungee.getInstance().getProxy().getPluginManager().registerCommand(Bungee.getInstance(), commands);
+ }
+
+ /**
+ * onDisable method of module
+ */
+ public void onDisable() {
+ Bungee.getInstance().getProxy().getPluginManager().unregisterCommand(commands);
+ }
+
+
+ /**
+ * Constructor of Credit
+ */
+ public Credit() {
+ }
+}
diff --git a/bungee/src/main/java/net/leaderos/modules/credits/commands/Commands.java b/bungee/src/main/java/net/leaderos/modules/credits/commands/Commands.java
new file mode 100644
index 000000000..96522eeff
--- /dev/null
+++ b/bungee/src/main/java/net/leaderos/modules/credits/commands/Commands.java
@@ -0,0 +1,236 @@
+package net.leaderos.modules.credits.commands;
+
+import net.leaderos.shared.helpers.MoneyUtils;
+import net.leaderos.shared.model.Response;
+import net.leaderos.shared.module.credit.CreditHelper;
+import net.md_5.bungee.api.CommandSender;
+import net.md_5.bungee.api.plugin.Command;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+
+import java.net.HttpURLConnection;
+import java.util.Objects;
+
+/**
+ * Credit module proxy commands
+ * @author poyrazinan
+ * @since 1.0
+ */
+public class Commands extends Command {
+
+
+ /**
+ * Constructor of credit commands
+ * @param name of command
+ */
+ public Commands(String name) {
+ super(name);
+ }
+
+ /**
+ * Execute method for command
+ * @param sender the executor of this command
+ * @param args arguments used to invoke this command
+ */
+ @Override
+ public void execute(CommandSender sender, String[] args) {
+ if (args.length == 0) {
+ Response targetCurrency = CreditHelper.currencyRequest(sender.getName());
+ if (Objects.requireNonNull(targetCurrency).getResponseCode() == HttpURLConnection.HTTP_OK) {
+ sender.sendMessage("ok");
+ /* TODO ChatUtil.sendMessage(player, ChatUtil.replacePlaceholders(
+ Main.getShared().getLangFile().getMessages().getCreditInfo(),
+ new Placeholder("{amount}", MoneyUtils.format(targetCurrency.getResponseMessage().getDouble("raw_credits")))
+ ));
+
+ */
+ }
+ return;
+ }
+ if (args.length == 2 && sender.hasPermission("leaderos.admin")) {
+ if (args[0].equalsIgnoreCase("see")) {
+ showCommand(sender, args[1]);
+ }
+ return;
+ }
+
+ if (args.length == 3) {
+ double value = Double.parseDouble(args[2]);
+ String target = args[1];
+ if (args[0].equalsIgnoreCase("send")) {
+ if (sender.hasPermission("leaderos.credit.send")) {
+ sendCommand(sender, target, value);
+ }
+ else
+ sender.sendMessage("test");
+ // TODO no perm
+ return;
+ }
+ if (!sender.hasPermission("leaderos.admin")) {
+ return;
+ }
+
+ if (args[0].equalsIgnoreCase("add")) {
+ addCommand(sender, target, value);
+ }
+ else if (args[0].equalsIgnoreCase("set")) {
+ setCommand(sender, target, value);
+ }
+ else if (args[0].equalsIgnoreCase("remove")) {
+ removeCommand(sender, target, value);
+ }
+ }
+ }
+
+ /**
+ * Adds credit to targeted player
+ * @param sender executor
+ * @param target to deposit
+ * @param amount of credit
+ */
+ public void addCommand(CommandSender sender, String target, Double amount) {
+ amount = MoneyUtils.parseDouble(amount);
+
+ if (amount <= 0) {
+ // TODO ChatUtil.sendMessage(sender, Shared.getInstance().getLangFile().getMessages().getCannotSendCreditNegative());
+ return;
+ }
+
+ Response addCreditResponse = CreditHelper.addCreditRequest(target, amount);
+
+ if (Objects.requireNonNull(addCreditResponse).getResponseCode() == HttpURLConnection.HTTP_OK)
+ // TODO MSG
+ sender.sendMessage("ok");
+ /* ChatUtil.sendMessage(sender, ChatUtil.replacePlaceholders(
+ Main.getShared().getLangFile().getMessages().getSuccessfullyAddedCredit(),
+ new Placeholder("{amount}", MoneyUtils.format(amount)),
+ new Placeholder("{target}", target)
+ ));*/
+ }
+
+ /**
+ * Show credit command
+ * @param sender executor
+ * @param target player
+ */
+ public void showCommand(CommandSender sender, String target) {
+ Response targetCurrency = CreditHelper.currencyRequest(target);
+ if (Objects.requireNonNull(targetCurrency).getResponseCode() == HttpURLConnection.HTTP_OK) {
+ sender.sendMessage("ok");
+ /*TODO ChatUtil.sendMessage(sender, ChatUtil.replacePlaceholders(
+ Main.getShared().getLangFile().getMessages().getCreditInfoOther(),
+ new Placeholder("{amount}", MoneyUtils.format(targetCurrency.getResponseMessage().getDouble("raw_credits"))),
+ new Placeholder("{target}", target)
+ ));
+
+ */
+ }
+ }
+
+ /**
+ * Send credit command
+ * @param player executor
+ * @param target player
+ * @param amount of credit
+ */
+ public void sendCommand(CommandSender player, String target, Double amount) {
+ amount = MoneyUtils.parseDouble(amount);
+ Player targetPlayer = Bukkit.getPlayerExact(target);
+
+ if (player.getName().equalsIgnoreCase(target)) {
+ // TODO ChatUtil.sendMessage(player, Shared.getInstance().getLangFile().getMessages().getCannotSendCreditYourself());
+ return;
+ }
+
+ if (amount <= 0) {
+ // TODO ChatUtil.sendMessage(player, Shared.getInstance().getLangFile().getMessages().getCannotSendCreditNegative());
+ return;
+ }
+
+ Response sendCreditResponse = CreditHelper.sendCreditRequest(player.getName(), target, amount);
+
+ if (Objects.requireNonNull(sendCreditResponse).getResponseCode() == HttpURLConnection.HTTP_OK) {
+ /*TODO ChatUtil.sendMessage(player, ChatUtil.replacePlaceholders(
+ Main.getShared().getLangFile().getMessages().getSuccessfullySentCredit(),
+ new Placeholder("{amount}", MoneyUtils.format(amount)),
+ new Placeholder("{target}", target)
+ ));
+
+ if (targetPlayer != null) {
+ ChatUtil.sendMessage(Objects.requireNonNull(targetPlayer), ChatUtil.replacePlaceholders(
+ Main.getShared().getLangFile().getMessages().getReceivedCredit(),
+ new Placeholder("{amount}", MoneyUtils.format(amount)),
+ new Placeholder("{player}", player.getName())
+ ));
+ }*/
+ }
+ else
+ player.sendMessage("error");
+ // TODO Make else
+ //ChatUtil.sendMessage(player, Shared.getInstance().getLangFile().getMessages().getCannotSendCreditNotEnough());
+ }
+
+
+ /**
+ * Removes credit from targeted user
+ * @param sender executor
+ * @param target player
+ * @param amount of currency
+ */
+ public void removeCommand(CommandSender sender, String target, Double amount) {
+ amount = MoneyUtils.parseDouble(amount);
+
+ if (amount <= 0) {
+ // TODO ChatUtil.sendMessage(sender, Shared.getInstance().getLangFile().getMessages().getCannotSendCreditNotEnough());
+ return;
+ }
+/* TODO look at all of them in this class
+ long userId = plugin.getPluginDatabase().getUserId(target);
+ if (userId == 0) {
+ ChatUtil.sendMessage(sender, Shared.getInstance().getLangFile().getMessages().getTargetPlayerNotAvailable());
+ return;
+ }
+ */
+ Response removeCreditResponse = CreditHelper.removeCreditRequest(target, amount);
+ if (Objects.requireNonNull(removeCreditResponse).getResponseCode() == HttpURLConnection.HTTP_OK) {
+ sender.sendMessage("ok");
+ /* TODO ChatUtil.sendMessage(sender, ChatUtil.replacePlaceholders(
+ Main.getShared().getLangFile().getMessages().getSuccessfullyRemovedCredit(),
+ new Placeholder("{amount}", MoneyUtils.format(amount)),
+ new Placeholder("{target}", target)
+ ));
+
+ */
+ }
+ }
+
+ /**
+ * Sets credit for target player
+ * @param sender executor
+ * @param target player
+ * @param amount new currency
+ */
+ public void setCommand(CommandSender sender, String target, Double amount) {
+ amount = MoneyUtils.parseDouble(amount);
+
+ /*
+ long userId = plugin.getPluginDatabase().getUserId(target);
+ if (userId == 0) {
+ ChatUtil.sendMessage(sender, Shared.getInstance().getLangFile().getMessages().getTargetPlayerNotAvailable());
+ return;
+ }
+ */
+
+ Response setCreditResponse = CreditHelper.setCreditRequest(target, amount);
+
+ if (Objects.requireNonNull(setCreditResponse).getResponseCode() == HttpURLConnection.HTTP_OK) {
+ sender.sendMessage("ok");
+ /* ChatUtil.sendMessage(sender, ChatUtil.replacePlaceholders(
+ Main.getShared().getLangFile().getMessages().getSuccessfullySetCredit(),
+ new Placeholder("{amount}", MoneyUtils.format(amount)),
+ new Placeholder("{target}", target)
+ ));
+ */
+ }
+ }
+}
diff --git a/bukkit/src/main/resources/bungee.yml b/bungee/src/main/resources/bungee.yml
similarity index 100%
rename from bukkit/src/main/resources/bungee.yml
rename to bungee/src/main/resources/bungee.yml
diff --git a/pom.xml b/pom.xml
index 19d96b12e..7d4f226e5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -11,6 +11,7 @@
shared
bukkit
+ bungee
@@ -29,13 +30,6 @@
1.20.1-R0.1-SNAPSHOT
provided
-
-
- net.md-5
- bungeecord-api
- 1.20-R0.1-SNAPSHOT
- provided
-
org.projectlombok
@@ -43,37 +37,7 @@
1.18.30
provided
-
-
- de.themoep
- inventorygui
-
- 1.5-SNAPSHOT
-
-
-
- com.github.cryptomorin
- XSeries
- 9.4.0
-
-
-
- de.tr7zw
- item-nbt-api-plugin
- 2.11.3
-
-
-
- dev.triumphteam
- triumph-cmd-bukkit
- 2.0.0-SNAPSHOT
-
-
-
- eu.okaeri
- okaeri-configs-yaml-bukkit
- 4.0.4
-
+
org.jetbrains
@@ -87,13 +51,6 @@
json
20230618
-
-
- me.clip
- placeholderapi
- 2.11.1
- provided
-
@@ -182,6 +139,10 @@
eu.okaeri
net.leaderos.plugin.shades.okaeri
+
+ dev.s7a
+ net.leaderos.plugin.shades.s7a
+
diff --git a/shared/pom.xml b/shared/pom.xml
index d0a0f10a1..533ce9fb8 100644
--- a/shared/pom.xml
+++ b/shared/pom.xml
@@ -14,6 +14,7 @@
8
8
+ UTF-8
diff --git a/shared/src/main/java/net/leaderos/shared/Shared.java b/shared/src/main/java/net/leaderos/shared/Shared.java
index 86b4013ef..fd12f3b3e 100644
--- a/shared/src/main/java/net/leaderos/shared/Shared.java
+++ b/shared/src/main/java/net/leaderos/shared/Shared.java
@@ -1,93 +1,47 @@
package net.leaderos.shared;
-import eu.okaeri.configs.ConfigManager;
-import eu.okaeri.configs.yaml.bukkit.YamlBukkitConfigurer;
import lombok.Getter;
-import net.leaderos.shared.configuration.Config;
-import net.leaderos.shared.configuration.Language;
-import net.leaderos.shared.configuration.Modules;
import org.bukkit.plugin.java.JavaPlugin;
-import java.io.File;
-
/**
* @author poyrazinan
* @since 1.0
*/
+@Getter
public class Shared {
/**
* Instance of plugin
*/
- @Getter
private JavaPlugin plugin;
/**
- * Config file of plugin
+ * Shared instance
*/
@Getter
- private Config configFile;
+ private static Shared instance;
/**
- * Lang file of plugin
+ * Link of request
*/
@Getter
- private Language langFile;
+ private static String link;
/**
- * Module file of plugin
+ * ApiKey for request
*/
@Getter
- private Modules modulesFile;
-
- /**
- * Shared instance
- */
- @Getter
- private static Shared instance;
+ private static String apiKey;
/**
* Constructor of shared
*
* @param plugin Main instance
*/
- public Shared(JavaPlugin plugin) {
+ public Shared(JavaPlugin plugin, String link, String apiKey) {
this.plugin = plugin;
+ Shared.link = link;
+ Shared.apiKey = apiKey;
instance = this;
- setupFiles();
- }
-
-
- /**
- * Setups config, lang and modules file file
- */
- public void setupFiles() {
- try {
- this.configFile = ConfigManager.create(Config.class, (it) -> {
- it.withConfigurer(new YamlBukkitConfigurer());
- it.withBindFile(new File(getPlugin().getDataFolder(), "config.yml"));
- it.saveDefaults();
- it.load(true);
- });
- this.modulesFile = ConfigManager.create(Modules.class, (it) -> {
- it.withConfigurer(new YamlBukkitConfigurer());
- it.withBindFile(new File(getPlugin().getDataFolder(), "modules.yml"));
- it.saveDefaults();
- it.load(true);
- });
- String langName = configFile.getSettings().getLang();
- // TODO MULTI LANG
- // Class langClass = Class.forName("net.leaderos.plugin.bukkit.configuration.lang." + langName);
- // Class languageClass = langClass;
- this.langFile = ConfigManager.create(Language.class, (it) -> {
- it.withConfigurer(new YamlBukkitConfigurer());
- it.withBindFile(new File(getPlugin().getDataFolder() + "/lang", langName + ".yml"));
- it.saveDefaults();
- it.load(true);
- });
- } catch (Exception exception) {
- getPlugin().getPluginLoader().disablePlugin(getPlugin());
- throw new RuntimeException("Error loading config.yml");
- }
}
}
diff --git a/shared/src/main/java/net/leaderos/shared/model/Request.java b/shared/src/main/java/net/leaderos/shared/model/Request.java
index 06bc7b24b..1b6744160 100644
--- a/shared/src/main/java/net/leaderos/shared/model/Request.java
+++ b/shared/src/main/java/net/leaderos/shared/model/Request.java
@@ -59,8 +59,8 @@ public abstract class Request {
*/
public Request(String api, Map body, @NotNull RequestType type) throws IOException {
this.body = encodeFormData(body);
- this.url = new URL( Shared.getInstance().getConfigFile().getSettings().getUrl()+ "/api/" + api);
- this.apiKey = Shared.getInstance().getConfigFile().getSettings().getApiKey();
+ this.url = new URL( Shared.getLink()+ "/api/" + api);
+ this.apiKey = Shared.getApiKey();
this.connection = (HttpURLConnection) this.url.openConnection();
// Request type selector
connection.setRequestMethod(type.name().toUpperCase());
diff --git a/shared/src/main/java/net/leaderos/shared/module/auth/AuthHelper.java b/shared/src/main/java/net/leaderos/shared/module/auth/AuthHelper.java
new file mode 100644
index 000000000..ab5dec873
--- /dev/null
+++ b/shared/src/main/java/net/leaderos/shared/module/auth/AuthHelper.java
@@ -0,0 +1,49 @@
+package net.leaderos.shared.module.auth;
+
+import net.leaderos.shared.Shared;
+import net.leaderos.shared.helpers.MDChat.MDChatAPI;
+import net.leaderos.shared.model.request.PostRequest;
+import org.bukkit.entity.Player;
+import org.json.JSONObject;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Auth module helper class, share methods over platforms
+ * @author poyrazinan
+ * @since 1.0
+ */
+public class AuthHelper {
+
+ /**
+ * Generates user login link
+ *
+ * @param username of player
+ * @param uuid of player
+ * @return String of url
+ * @throws IOException request exception
+ */
+ private static String generateLink(String username, String uuid) throws IOException {
+ Map formData = new HashMap<>();
+ formData.put("username", username);
+ formData.put("uuid", uuid);
+ PostRequest postRequest = new PostRequest("auth/generate-link", formData);
+ JSONObject response = postRequest.getResponse().getResponseMessage().getJSONObject("data");
+ return response.getString("url");
+ }
+
+ /**
+ * sends auth command message
+ * @param player executor
+ */
+ public static String getAuthLink(Player player) {
+ try {
+ String link = generateLink(player.getName(), player.getUniqueId().toString());
+ return link;
+ } catch (Exception e) {
+ return null;
+ }
+ }
+}
diff --git a/shared/src/main/java/net/leaderos/shared/module/credit/CreditHelper.java b/shared/src/main/java/net/leaderos/shared/module/credit/CreditHelper.java
new file mode 100644
index 000000000..05622e03c
--- /dev/null
+++ b/shared/src/main/java/net/leaderos/shared/module/credit/CreditHelper.java
@@ -0,0 +1,107 @@
+package net.leaderos.shared.module.credit;
+
+import net.leaderos.shared.model.Response;
+import net.leaderos.shared.model.request.GetRequest;
+import net.leaderos.shared.model.request.PostRequest;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Helper Class for auth module
+ * @author poyrazinan
+ * @since 1.0
+ */
+public class CreditHelper {
+
+
+ /**
+ * Send credit to another player
+ * @param sender executor
+ * @param target player
+ * @param amount of currency
+ * @return response of request
+ */
+ public static @Nullable Response sendCreditRequest(String sender, String target, Double amount) {
+ try {
+ Map list = new HashMap<>();
+ list.put("target", target);
+ list.put("amount", amount+"");
+ PostRequest postSendCredit = new PostRequest("credits/" + sender + "/send", list);
+ return postSendCredit.getResponse();
+ }
+ catch (Exception e) {
+ return null;
+ }
+ }
+
+ /**
+ * Gets currency of player as a response
+ * @param sender executor
+ * @return response of request
+ */
+ public static @Nullable Response currencyRequest(String sender) {
+ try {
+ GetRequest getCurrency = new GetRequest("credits/" + sender);
+ return getCurrency.getResponse();
+ }
+ catch (Exception e) {
+ return null;
+ }
+ }
+
+ /**
+ * Adds credit to target player
+ * @param target to deposit
+ * @param amount amount of currency
+ * @return Response of request
+ */
+ public static @Nullable Response addCreditRequest(String target, double amount) {
+ try {
+ Map list = new HashMap<>();
+ list.put("amount", amount+"");
+ PostRequest postAddCredit = new PostRequest("credits/" + target + "/add", list);
+ return postAddCredit.getResponse();
+ }
+ catch (Exception e) {
+ return null;
+ }
+ }
+
+ /**
+ * Removes credit to target player
+ * @param target to deposit
+ * @param amount amount of currency
+ * @return Response of request
+ */
+ public static @Nullable Response removeCreditRequest(String target, double amount) {
+ try {
+ Map list = new HashMap<>();
+ list.put("amount", amount+"");
+ PostRequest postRemoveCredit = new PostRequest("credits/" + target + "/remove", list);
+ return postRemoveCredit.getResponse();
+ }
+ catch (Exception e) {
+ return null;
+ }
+ }
+
+ /**
+ * Sets credit to target player
+ * @param target to deposit
+ * @param amount amount of deposit
+ * @return Response of request
+ */
+ public static @Nullable Response setCreditRequest(String target, double amount) {
+ try {
+ Map list = new HashMap<>();
+ list.put("amount", amount+"");
+ PostRequest postSetCredit = new PostRequest("credits/" + target + "/set", list);
+ return postSetCredit.getResponse();
+ }
+ catch (Exception e) {
+ return null;
+ }
+ }
+}