diff --git a/ERCoupons/resources/server.yml b/ERCoupons/resources/server.yml index 06af435..5bda88c 100644 --- a/ERCoupons/resources/server.yml +++ b/ERCoupons/resources/server.yml @@ -1,5 +1,29 @@ +# ______ _____ _____ +# | ____| __ \ / ____| +# | |__ | |__) | | ___ _ _ _ __ ___ _ __ ___ +# | __| | _ /| | / _ \| | | | '_ \ / _ \| '_ \/ __| +# | |____| | \ \| |___| (_) | |_| | |_) | (_) | | | \__ \ +# |______|_| \_\\_____\___/ \__,_| .__/ \___/|_| |_|___/ +# | | +# |_| # Plugin config + +# You can use any craftingstore server api key. You need at least silver plan. api-key: "CRAFTINGSTORE KEY HERE" +settings: + # Settings for redeeming credits for store money. + redeem: + # What is the minimum credits to redeem in a coupon? + min: 100 + # What is the maximum credits to redeem in a coupon? + max: 50000 + # Settings for virtual coupon players can use for safe trading, bragging, etc. + virtual: + # What is the minimum currency to hold in an item? + min: 50 + # What is the maximum currency to hold in an item? + max: 5000 + # Version is used for future updates version: 1 \ No newline at end of file diff --git a/ERCoupons/src/com/entryrise/coupons/Data.java b/ERCoupons/src/com/entryrise/coupons/Data.java index 606b433..185dda5 100644 --- a/ERCoupons/src/com/entryrise/coupons/Data.java +++ b/ERCoupons/src/com/entryrise/coupons/Data.java @@ -80,21 +80,24 @@ public class Data { final UUID u = p.getUniqueId(); final long available = getCredits(u); - if (credits > 5000) { - p.sendMessage("§2§lER§f§lCoupons §e» §fYou can make a coupon holding a maximum of 5000 credits"); + int min = Main.config.getInt("settings.virtual.min"); + int max = Main.config.getInt("settings.virtual.max"); + + if (credits > max) { + p.sendMessage(Main.PREFIX + "You can make a coupon holding a maximum of " + max + " credits"); return; } - if (credits < 50) { - p.sendMessage("§2§lER§f§lCoupons §e» §fYou can't make a coupon holding under 50 credits"); + if (credits < min) { + p.sendMessage(Main.PREFIX + "You can't make a coupon holding under " + min + " credits"); return; } if (available < credits) { - p.sendMessage("§2§lER§f§lCoupons §e» §fYou need another " + (available - credits) + p.sendMessage(Main.PREFIX + "You need another " + (available - credits) + " credits to afford creating this coupon."); return; } if (p.getInventory().firstEmpty() == -1) { - p.sendMessage("§2§lER§f§lCoupons §e» §fYou need to make space in your inventory to create a coupon."); + p.sendMessage(Main.PREFIX + "You need to make space in your inventory to create a coupon."); return; } @@ -174,7 +177,7 @@ public class Data { } long current = getCredits(u); setCredits(u, current + credits); - p.sendMessage("§2§lER§f§lCoupons §e» §fYou have redeemed a coupon worth " + credits + " credits. Current: " + p.sendMessage(Main.PREFIX + "You have redeemed a coupon worth " + credits + " credits. Current: " + (current + credits)); return true; } diff --git a/ERCoupons/src/com/entryrise/coupons/Main.java b/ERCoupons/src/com/entryrise/coupons/Main.java index 7c5832b..15e0a05 100644 --- a/ERCoupons/src/com/entryrise/coupons/Main.java +++ b/ERCoupons/src/com/entryrise/coupons/Main.java @@ -17,7 +17,7 @@ import com.entryrise.coupons.utils.Others; public class Main extends JavaPlugin implements Listener { public static String USER = "%%__USER__%%"; - public static final String PREFIX = "§c§lTemplate§f§lPlugin §e» §f"; + public static final String PREFIX = "§2§lER§f§lCoupons §e» §f"; public static JavaPlugin p; diff --git a/ERCoupons/src/com/entryrise/coupons/cmd/CommandListener.java b/ERCoupons/src/com/entryrise/coupons/cmd/CommandListener.java index 6a88b9e..91e12c3 100644 --- a/ERCoupons/src/com/entryrise/coupons/cmd/CommandListener.java +++ b/ERCoupons/src/com/entryrise/coupons/cmd/CommandListener.java @@ -9,6 +9,8 @@ import java.util.UUID; import com.entryrise.coupons.utils.CSUtils; import com.entryrise.coupons.utils.MathUtils; import com.entryrise.coupons.Data; +import com.entryrise.coupons.Main; + import org.bukkit.entity.Player; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -20,20 +22,25 @@ public class CommandListener implements CommandExecutor { final Player p = (sender instanceof Player) ? (Player) sender : null; if (args.length == 0) { if (p == null) { - sender.sendMessage("§2§lER§f§lCoupons §e» §f"); + sender.sendMessage(Main.PREFIX + ""); return true; } - sender.sendMessage("§2§lER§f§lCoupons §e» §fYou have " + Data.getCredits(p.getUniqueId()) + sender.sendMessage(Main.PREFIX + "You have " + Data.getCredits(p.getUniqueId()) + " credits in your account."); return true; } else { - if (args.length == 1) { - final int count = MathUtils.isInt(args[0]) ? Integer.valueOf(args[0]) : -1; + if (args.length == 1 && MathUtils.isInt(args[0])) { + final int count = Integer.valueOf(args[0]); Data.createCoupon(p, count); return true; - } - if (args.length == 2) { - if (args[0].equalsIgnoreCase("store")) { + } else if (args.length == 1 && args[0].equalsIgnoreCase("version")) { + sender.sendMessage(Main.PREFIX + "You are using ERCoupons v" + Main.p.getDescription().getVersion() + " by EntryRise: https://git.entryrise.com/EntryRise/ERCoupons"); + return true; + } else if (args.length == 1) { + sender.sendMessage(Main.PREFIX + "To create a virtual coupon, please use /coupons (AMOUNT)"); + return true; + } else if (args.length == 2) { + if (args[0].equalsIgnoreCase("redeem")) { final int count = MathUtils.isInt(args[1]) ? Integer.valueOf(args[1]) : -1; CSUtils.redeemStore(p, (long) count); return true; @@ -46,9 +53,9 @@ public class CommandListener implements CommandExecutor { } catch (Exception e) { u = Bukkit.getOfflinePlayer(args[1]).getUniqueId(); } - final int amount = MathUtils.isInt(args[2]) ? Integer.valueOf(args[2]) : 0; + int amount = MathUtils.isInt(args[2]) ? Integer.valueOf(args[2]) : 0; if (amount == 0) { - sender.sendMessage("§2§lER§f§lCoupons §e» §fMUST BE NEGATIVE OR POSITIVE NUMBER."); + sender.sendMessage(Main.PREFIX + "MUST BE NEGATIVE OR POSITIVE NUMBER."); return true; } Data.setCredits(u, Data.getCredits(u) + amount); @@ -60,12 +67,12 @@ public class CommandListener implements CommandExecutor { } catch (Exception e) { u = Bukkit.getOfflinePlayer(args[1]).getUniqueId(); } - final double amount2 = MathUtils.isDouble(args[2]) ? Double.valueOf(args[2]) : -1.0; - if (amount2 == -1.0) { - sender.sendMessage("§2§lER§f§lCoupons §e» §fMUST BE NEGATIVE OR POSITIVE NUMBER."); + double amount = MathUtils.isDouble(args[2]) ? Double.valueOf(args[2]) : -1.0; + if (amount == -1.0) { + sender.sendMessage(Main.PREFIX + "MUST BE NEGATIVE OR POSITIVE NUMBER."); return true; } - Data.setCredits(u, Data.getCredits(u) + (long) (amount2 * 100.0)); + Data.setCredits(u, Data.getCredits(u) + (long) (amount * 100.0)); return true; } } diff --git a/ERCoupons/src/com/entryrise/coupons/utils/CSUtils.java b/ERCoupons/src/com/entryrise/coupons/utils/CSUtils.java index b069059..c16b087 100644 --- a/ERCoupons/src/com/entryrise/coupons/utils/CSUtils.java +++ b/ERCoupons/src/com/entryrise/coupons/utils/CSUtils.java @@ -27,30 +27,39 @@ import net.md_5.bungee.api.chat.BaseComponent; public class CSUtils { private static String url = "https://api.craftingstore.net/v7/gift-cards"; - + public static void redeemStore(final Player p, final long credits) { if (p == null) { return; } if (credits < 1L) { - p.sendMessage("§2§lER§f§lCoupons §e» §fYou need to specify the amount of credits to redeem your credits."); + p.sendMessage(Main.PREFIX + "You need to specify the amount of credits to redeem your credits."); return; } if (credits % 100L != 0L) { - p.sendMessage("§2§lER§f§lCoupons §e» §fYou can only redeem multiples of 100 credits."); + p.sendMessage(Main.PREFIX + "You can only redeem multiples of 100 credits."); + return; + } + + int max = Main.config.getInt("settings.redeem.max"); + int min = Main.config.getInt("settings.redeem.min"); + + if (min > credits || max < credits) { + p.sendMessage( + Main.PREFIX + "You can only redeem coupons valuing between " + min + " and " + max + " coupons."); return; } + final UUID u = p.getUniqueId(); final long available = Data.getCredits(u); final long rem = available - credits; if (rem < 0L) { - p.sendMessage("§2§lER§f§lCoupons §e» §fYou need " + -rem - + " more credits to be able to create this store giftcard"); + p.sendMessage(Main.PREFIX + "You need " + -rem + " more credits to be able to create this store giftcard"); return; } Data.setCredits(u, rem); final long dollars = credits / 100L; - p.sendMessage("§2§lER§f§lCoupons §e» §fWe're currently contacting the store and creating your coupon..."); + p.sendMessage(Main.PREFIX + "We're currently contacting the store and creating your coupon..."); Bukkit.getScheduler().runTaskAsynchronously(Main.p, () -> CSUtils.giveCoupon(p, dollars)); } @@ -59,11 +68,11 @@ public class CSUtils { Bukkit.getLogger().info("STORE TRANSACTION " + transactionid.toString() + " with " + p.getName() + " STARTED!"); try { final URL u = new URL(CSUtils.url); - + final HttpsURLConnection conn = (HttpsURLConnection) u.openConnection(); final String urlParameters = "{\"amount\": \"" + dollars + "\"}"; final byte[] postData = urlParameters.getBytes(StandardCharsets.UTF_8); - + conn.setDoOutput(true); conn.setInstanceFollowRedirects(false); conn.setRequestMethod("POST"); @@ -81,17 +90,18 @@ public class CSUtils { final String stg = (conn.getResponseCode() == 200) ? getInputStreamString(conn.getInputStream()) : getInputStreamString(conn.getErrorStream()); - final JsonParser parser = new JsonParser(); - final JsonObject o = parser.parse(stg).getAsJsonObject(); - final String code = ((JsonObject) o.get("data")).get("code").getAsString(); + System.out.println(stg); - p.sendMessage("§2§lER§f§lCoupons §e» §fGIFT-CARD Succesfully printed below."); - p.spigot().sendMessage((BaseComponent) Chat.genHoverAndSuggestTextComponent( - "§2§lER§f§lCoupons §e» §f§c" + code, "Click, CTRL+A, CTRL+C, and paste with CTRL+V", code)); + JsonParser parser = new JsonParser(); + JsonObject o = parser.parse(stg).getAsJsonObject(); + String code = ((JsonObject) o.get("data")).get("code").getAsString(); + + p.sendMessage(Main.PREFIX + "GIFT-CARD Succesfully printed below."); + p.spigot().sendMessage((BaseComponent) Chat.genHoverAndSuggestTextComponent(Main.PREFIX + "§c" + code, + "Click, CTRL+A, CTRL+C, and paste with CTRL+V", code)); } catch (Exception e) { - p.sendMessage( - "§2§lER§f§lCoupons §e» §fSomething went wrong with creating your store coupon. Urgently contact staff. " - + transactionid.toString()); + p.sendMessage(Main.PREFIX + "Something went wrong with creating your store coupon. Urgently contact staff. " + + transactionid.toString()); Bukkit.getLogger() .warning("STORE TRANSACTION " + transactionid.toString() + " with " + p.getName() + " WENT WRONG!"); e.printStackTrace(); diff --git a/ERCoupons/src/com/entryrise/coupons/utils/Chat.java b/ERCoupons/src/com/entryrise/coupons/utils/Chat.java index 81838a6..ba97a43 100644 --- a/ERCoupons/src/com/entryrise/coupons/utils/Chat.java +++ b/ERCoupons/src/com/entryrise/coupons/utils/Chat.java @@ -1,30 +1,30 @@ -package com.entryrise.coupons.utils; - -import net.md_5.bungee.api.chat.ClickEvent; -import net.md_5.bungee.api.chat.ComponentBuilder; -import net.md_5.bungee.api.chat.HoverEvent; -import net.md_5.bungee.api.chat.TextComponent; - -public class Chat { - - public static TextComponent genHoverAndSuggestTextComponent(String show, String hover, String click) { - TextComponent msg = new TextComponent(show); - msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(hover).create())); - msg.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/" + click)); - return msg; - } - - public static TextComponent genHoverAndRunCommandTextComponent(String show, String hover, String click) { - TextComponent msg = new TextComponent(show); - msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(hover).create())); - msg.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/" + click)); - return msg; - } - - public static TextComponent genHoverTextComponent(String show, String hover) { - TextComponent msg = new TextComponent(show); - msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(hover).create())); - return msg; - } - -} +package com.entryrise.coupons.utils; + +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; + +public class Chat { + + public static TextComponent genHoverAndSuggestTextComponent(String show, String hover, String click) { + TextComponent msg = new TextComponent(show); + msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(hover).create())); + msg.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, click)); + return msg; + } + + public static TextComponent genHoverAndRunCommandTextComponent(String show, String hover, String click) { + TextComponent msg = new TextComponent(show); + msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(hover).create())); + msg.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/" + click)); + return msg; + } + + public static TextComponent genHoverTextComponent(String show, String hover) { + TextComponent msg = new TextComponent(show); + msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(hover).create())); + return msg; + } + +}