From 3d85050e0ff48033f522aa6be46432d9069916ce Mon Sep 17 00:00:00 2001 From: TheLonelyWolf1 <42873246+TheLonelyWolf1@users.noreply.github.com> Date: Fri, 6 Aug 2021 16:22:43 +0200 Subject: [PATCH 1/5] Add xp-points-paywall= Functions Add Functions used by the new CommandTag: `xp-points-paywall=` --- src/me/rockyhawk/commandpanels/Utils.java | 57 +++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/me/rockyhawk/commandpanels/Utils.java b/src/me/rockyhawk/commandpanels/Utils.java index 919cd9a..f6c0e97 100644 --- a/src/me/rockyhawk/commandpanels/Utils.java +++ b/src/me/rockyhawk/commandpanels/Utils.java @@ -151,4 +151,61 @@ public class Utils implements Listener { } return false; } + // START - PATCH + // @author thelonelywolf@https://github.com/TheLonelyWolf1 + // @date 06 August 2021 + + // Calculate amount of EXP needed to level up + public static int getExpToLevelUp(int level){ + if(level <= 15){ + return 2*level+7; + } else if(level <= 30){ + return 5*level-38; + } else { + return 9*level-158; + } + } + + // Calculate total experience up to a level + public static int getExpAtLevel(int level){ + if(level <= 16){ + return (int) (Math.pow(level,2) + 6*level); + } else if(level <= 31){ + return (int) (2.5*Math.pow(level,2) - 40.5*level + 360.0); + } else { + return (int) (4.5*Math.pow(level,2) - 162.5*level + 2220.0); + } + } + + // Calculate player's current EXP amount + public static int getPlayerExp(Player player){ + int exp = 0; + int level = player.getLevel(); + + // Get the amount of XP in past levels + exp += getExpAtLevel(level); + + // Get amount of XP towards next level + exp += Math.round(getExpToLevelUp(level) * player.getExp()); + + return exp; + } + + // Give or take EXP + public static int changePlayerExp(Player player, int exp){ + // Get player's current exp + int currentExp = getPlayerExp(player); + + // Reset player's current exp to 0 + player.setExp(0); + player.setLevel(0); + + // Give the player their exp back, with the difference + int newExp = currentExp - exp; + player.giveExp(newExp); + + // Return the player's new exp amount + return newExp; + } + // END - PATCH } From f9d3b9780cbb9c4e8306ffa0f307c963a81af7fb Mon Sep 17 00:00:00 2001 From: TheLonelyWolf1 <42873246+TheLonelyWolf1@users.noreply.github.com> Date: Fri, 6 Aug 2021 16:27:22 +0200 Subject: [PATCH 2/5] Add xp-points-paywall= --- .../commandtags/CommandTags.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java b/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java index c702485..6987e9e 100644 --- a/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java +++ b/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java @@ -304,6 +304,27 @@ public class CommandTags { return PaywallOutput.Blocked; } } + case "xp-points-paywall=": { + //if player uses xp-points-paywall= [price] + try { + int balance = Utils.getPlayerExp(p); + if (balance >= Integer.parseInt(command.split("\\s")[1])) { + Utils.changePlayerExp(p, Integer.parseInt(command.split("\\s")[1])); + //if the message is empty don't send + plugin.tex.sendString(p,Objects.requireNonNull(plugin.config.getString("purchase.xppoints.success")).replaceAll("%cp-args%", command.split("\\s")[1])); + return PaywallOutput.Passed; + } else { + plugin.tex.sendString(p, plugin.config.getString("purchase.xppoints.failure")); + return PaywallOutput.Blocked; + } + + } catch (Exception buyc) { + plugin.debug(buyc,p); + plugin.tex.sendString(p, tag + plugin.config.getString("config.format.error") + " " + "commands: " + command); + return PaywallOutput.Blocked; + } + + } } return PaywallOutput.NotApplicable; } From 7e4609efbfa1eccd5cf86c69be8ab3748b80e174 Mon Sep 17 00:00:00 2001 From: TheLonelyWolf1 <42873246+TheLonelyWolf1@users.noreply.github.com> Date: Fri, 6 Aug 2021 16:28:21 +0200 Subject: [PATCH 3/5] Add xp-points-paywall= Messages --- resource/config.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/resource/config.yml b/resource/config.yml index db5a65d..ca28a6e 100644 --- a/resource/config.yml +++ b/resource/config.yml @@ -62,3 +62,6 @@ purchase: xp: success: '&aSuccessfully Bought For %cp-args% xp level.' failure: '&cInsufficient xp levels!' + xppoints: + success: '&aSuccessfully Bought For %cp-args% xp points.' + failure: '&cInsufficient xp points!' From d0c8939a35187ceb03e461c7ae7804eeb6d5f4ef Mon Sep 17 00:00:00 2001 From: RockyHawk Date: Tue, 10 Aug 2021 17:00:08 +1000 Subject: [PATCH 4/5] Update Utils.java --- src/me/rockyhawk/commandpanels/Utils.java | 57 ----------------------- 1 file changed, 57 deletions(-) diff --git a/src/me/rockyhawk/commandpanels/Utils.java b/src/me/rockyhawk/commandpanels/Utils.java index 35ca676..c4ad32a 100644 --- a/src/me/rockyhawk/commandpanels/Utils.java +++ b/src/me/rockyhawk/commandpanels/Utils.java @@ -152,61 +152,4 @@ public class Utils implements Listener { } return false; } - // START - PATCH - // @author thelonelywolf@https://github.com/TheLonelyWolf1 - // @date 06 August 2021 - - // Calculate amount of EXP needed to level up - public static int getExpToLevelUp(int level){ - if(level <= 15){ - return 2*level+7; - } else if(level <= 30){ - return 5*level-38; - } else { - return 9*level-158; - } - } - - // Calculate total experience up to a level - public static int getExpAtLevel(int level){ - if(level <= 16){ - return (int) (Math.pow(level,2) + 6*level); - } else if(level <= 31){ - return (int) (2.5*Math.pow(level,2) - 40.5*level + 360.0); - } else { - return (int) (4.5*Math.pow(level,2) - 162.5*level + 2220.0); - } - } - - // Calculate player's current EXP amount - public static int getPlayerExp(Player player){ - int exp = 0; - int level = player.getLevel(); - - // Get the amount of XP in past levels - exp += getExpAtLevel(level); - - // Get amount of XP towards next level - exp += Math.round(getExpToLevelUp(level) * player.getExp()); - - return exp; - } - - // Give or take EXP - public static int changePlayerExp(Player player, int exp){ - // Get player's current exp - int currentExp = getPlayerExp(player); - - // Reset player's current exp to 0 - player.setExp(0); - player.setLevel(0); - - // Give the player their exp back, with the difference - int newExp = currentExp - exp; - player.giveExp(newExp); - - // Return the player's new exp amount - return newExp; - } - // END - PATCH } From 5542a1f0f200ef03a0350c3d965a247a35b9a0e4 Mon Sep 17 00:00:00 2001 From: RockyHawk Date: Tue, 10 Aug 2021 17:00:49 +1000 Subject: [PATCH 5/5] Update CommandTags.java --- .../commandtags/CommandTags.java | 24 +++---------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java b/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java index 0d20e76..a354843 100644 --- a/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java +++ b/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java @@ -313,33 +313,15 @@ public class CommandTags { return PaywallOutput.Blocked; } } - case "xp-points-paywall=": { - //if player uses xp-points-paywall= [price] - try { - int balance = Utils.getPlayerExp(p); - if (balance >= Integer.parseInt(command.split("\\s")[1])) { - Utils.changePlayerExp(p, Integer.parseInt(command.split("\\s")[1])); - //if the message is empty don't send - plugin.tex.sendString(p,Objects.requireNonNull(plugin.config.getString("purchase.xppoints.success")).replaceAll("%cp-args%", command.split("\\s")[1])); - return PaywallOutput.Passed; - } else { - plugin.tex.sendString(p, plugin.config.getString("purchase.xppoints.failure")); - return PaywallOutput.Blocked; - } - - } catch (Exception buyc) { - plugin.debug(buyc,p); - plugin.tex.sendString(p, tag + plugin.config.getString("config.format.error") + " " + "commands: " + command); - return PaywallOutput.Blocked; - } - - } } return PaywallOutput.NotApplicable; } //Experience math is a bit doggy doo doo so these will help to calculate values // Calculate total experience up to a level + + // @author thelonelywolf@https://github.com/TheLonelyWolf1 + // @date 06 August 2021 private int getExpAtLevel(int level){ if(level <= 16){ return (int) (Math.pow(level,2) + 6*level);