Skip to content
This repository has been archived by the owner on Jun 29, 2023. It is now read-only.

Commit

Permalink
Redid economy system and added PlayerPoints support
Browse files Browse the repository at this point in the history
  • Loading branch information
RadBuilder committed Nov 4, 2017
1 parent 0ea7b95 commit 77ab4a2
Show file tree
Hide file tree
Showing 38 changed files with 264 additions and 2,153 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
allprojects { apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'idea' group = 'be.isach' version = '2.5.0' compileJava.options.encoding = 'UTF-8' sourceCompatibility = 1.8 targetCompatibility = 1.8 configurations { shaded compile.extendsFrom shaded } afterEvaluate { jar { dependsOn configurations.shaded from configurations.shaded.collect { it.isDirectory() ? it : zipTree(it) } } }}boolean local = falseif (local) libsDirName = '/Users/sacha/Documents/Development/Java/UC_1_11/testserver/plugins'dependencies { subprojects.each { p -> shaded(p) { transitive false } }}subprojects { repositories { mavenLocal() mavenCentral() // Vault maven { url 'http://nexus.hc.to/content/repositories/pub_releases' } // Lib's Disguises maven { url 'http://repo.md-5.net/content/groups/public/' } maven { url 'https://repo.isach.be' } // BungeeCord maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } }}
allprojects { apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'idea' group = 'be.isach' version = '2.5.0' compileJava.options.encoding = 'UTF-8' sourceCompatibility = 1.8 targetCompatibility = 1.8 configurations { shaded compile.extendsFrom shaded } afterEvaluate { jar { dependsOn configurations.shaded from configurations.shaded.collect { it.isDirectory() ? it : zipTree(it) } } }}boolean local = falseif (local) libsDirName = '/Users/sacha/Documents/Development/Java/UC_1_11/testserver/plugins'dependencies { subprojects.each { p -> shaded(p) { transitive false } }}subprojects { repositories { mavenLocal() mavenCentral() // Vault maven { url 'http://nexus.hc.to/content/repositories/pub_releases' } // Lib's Disguises maven { url 'http://repo.md-5.net/content/groups/public/' } maven { url 'https://repo.isach.be' } // BungeeCord maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } // PlayerPoints maven { url 'https://repo.dakanilabs.com/repository/public/' } }}
Expand Down
1 change: 1 addition & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dependencies {
compile('net.milkbowl.vault:VaultAPI:1.6') {
exclude group: 'org.bukkit'
}
compile 'org.black_ixx:PlayerPoints:2.1.3'
}

processResources {
Expand Down
52 changes: 13 additions & 39 deletions core/src/main/java/be/isach/ultracosmetics/UltraCosmetics.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import be.isach.ultracosmetics.config.MessageManager;
import be.isach.ultracosmetics.config.SettingsManager;
import be.isach.ultracosmetics.config.TreasureManager;
import be.isach.ultracosmetics.economy.EconomyHandler;
import be.isach.ultracosmetics.economy.EconomyHook;
import be.isach.ultracosmetics.listeners.MainListener;
import be.isach.ultracosmetics.listeners.PlayerListener;
import be.isach.ultracosmetics.listeners.v1_9.PlayerSwapItemListener;
Expand All @@ -14,6 +16,7 @@
import be.isach.ultracosmetics.mysql.MySqlConnectionManager;
import be.isach.ultracosmetics.player.UltraPlayer;
import be.isach.ultracosmetics.player.UltraPlayerManager;
import be.isach.ultracosmetics.economy.PlayerPointsHook;
import be.isach.ultracosmetics.run.FallDamageManager;
import be.isach.ultracosmetics.run.InvalidWorldChecker;
import be.isach.ultracosmetics.run.MovingChecker;
Expand Down Expand Up @@ -45,7 +48,6 @@
* @since 08-03-2015
*/
public class UltraCosmetics extends JavaPlugin {

/**
* Manages sub commands.
*/
Expand All @@ -61,11 +63,6 @@ public class UltraCosmetics extends JavaPlugin {
*/
private File file;

/**
* Economy, used only if Vault is enabled.
*/
private Economy economy = null;

/**
* Player Manager instance.
*/
Expand Down Expand Up @@ -100,9 +97,9 @@ public class UltraCosmetics extends JavaPlugin {
* Manages armor stands.
*/
private ArmorStandManager armorStandManager;
private boolean vaultLoaded = false;



private EconomyHandler economyHandler;
/**
* Called when plugin is enabled.
*/
Expand Down Expand Up @@ -167,7 +164,7 @@ public void onEnable() {
getSmartLogger().write("Morphs disabled.");
getSmartLogger().write("");
}

// Set up economy if needed.
setupEconomy();

Expand Down Expand Up @@ -246,27 +243,11 @@ private void registerListeners() {
}

/**
* Sets Vault up.
* Sets the economy up.
*/
private void setupEconomy() {
economyHandler = new EconomyHandler(this, getConfig().getString("Economy"));
UltraCosmeticsData.get().checkTreasureChests();
if (!(UltraCosmeticsData.get().isAmmoEnabled()
|| (SettingsManager.getConfig().getBoolean("Pets-Rename.Enabled") && SettingsManager.getConfig().getBoolean("Pets-Rename.Requires-Money.Enabled"))
|| UltraCosmeticsData.get().areTreasureChestsEnabled())) {
return;
}

if (!Bukkit.getPluginManager().isPluginEnabled("Vault")) {
return;
}

RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
if (economyProvider != null) {
economy = economyProvider.getProvider();
UltraCosmeticsData.get().setUsingVaultEconomy(true);
}

vaultLoaded = true;
}

private void setUpConfig() {
Expand Down Expand Up @@ -375,13 +356,6 @@ public SmartLogger getSmartLogger() {
return smartLogger;
}

/**
* @return Vault Economy.
*/
public Economy getEconomy() {
return economy;
}

/**
* @return The Update CheckerC.
*/
Expand Down Expand Up @@ -414,10 +388,6 @@ public ArmorStandManager getArmorStandManager() {
return armorStandManager;
}

public boolean isVaultLoaded() {
return vaultLoaded;
}

public void openMainMenu(UltraPlayer ultraPlayer) {
if (getConfig().getBoolean("Categories.Back-To-Main-Menu-Custom-Command.Enabled")) {
String command = getConfig().getString("Categories.Back-To-Main-Menu-Custom-Command.Command").replace("/", "").replace("{player}", ultraPlayer.getBukkitPlayer().getName()).replace("{playeruuid}", ultraPlayer.getUuid().toString());
Expand All @@ -426,4 +396,8 @@ public void openMainMenu(UltraPlayer ultraPlayer) {
getMenus().getMainMenu().open(ultraPlayer);
}
}

public EconomyHandler getEconomyHandler() {
return economyHandler;
}
}
22 changes: 2 additions & 20 deletions core/src/main/java/be/isach/ultracosmetics/UltraCosmeticsData.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ public static UltraCosmeticsData get() {
*/
private boolean moneyTreasureLoot;

/**
* If a Vault economy is being used.
*/
private boolean usingVaultEconomy;

/**
* Determines if Gadget Cooldown should be shown in action bar.
*/
Expand Down Expand Up @@ -116,13 +111,8 @@ void checkTreasureChests() {
moneyTreasureLoot = SettingsManager.getConfig().getBoolean("TreasureChests.Loots.Money.Enabled");
if (SettingsManager.getConfig().getBoolean("TreasureChests.Enabled")) {
treasureChests = true;
if (!Bukkit.getPluginManager().isPluginEnabled("Vault")
&& (boolean) SettingsManager.getConfig().get("TreasureChests.Loots.Money.Enabled")) {
ultraCosmetics.getSmartLogger().write("-------------------------");
ultraCosmetics.getSmartLogger().write("Treasure Chests' Money Loot requires Vault!");
ultraCosmetics.getSmartLogger().write("Money Loot is turned off!");
ultraCosmetics.getSmartLogger().write("-------------------------");
moneyTreasureLoot = false;
if ((boolean) SettingsManager.getConfig().get("TreasureChests.Loots.Money.Enabled")) {
moneyTreasureLoot = true;
}
}
}
Expand Down Expand Up @@ -248,14 +238,6 @@ public void setServerVersion(ServerVersion serverVersion) {
this.serverVersion = serverVersion;
}

public void setUsingVaultEconomy(boolean usingVaultEconomy) {
this.usingVaultEconomy = usingVaultEconomy;
}

public boolean isUsingVaultEconomy() {
return this.usingVaultEconomy;
}

public final String getItemNoPickupString() {
return this.itemNoPickupString;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
import be.isach.ultracosmetics.util.SoundUtil;
import be.isach.ultracosmetics.util.Sounds;
import be.isach.ultracosmetics.util.TextUtil;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Locale;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
Expand All @@ -38,11 +42,6 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;

import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Locale;
import java.util.UUID;

/**
* Represents an instance of a Gadget summoned by a player.
*
Expand Down Expand Up @@ -329,7 +328,7 @@ public void onInventoryClickAmmo(final InventoryClickEvent event) {
if (displayName.equals(purchase)) {
if (getUltraCosmetics().getPlayerManager().getUltraPlayer((Player) event.getWhoClicked())
.getBalance() >= getPrice()) {
getUltraCosmetics().getEconomy().withdrawPlayer((Player) event.getWhoClicked(), getPrice());
getUltraCosmetics().getEconomyHandler().withdraw((Player) event.getWhoClicked(), getPrice());
getUltraCosmetics().getPlayerManager().getUltraPlayer((Player) event.getWhoClicked())
.addAmmo(getType().toString().toLowerCase(), getResultAmmoAmount());
event.getWhoClicked().sendMessage(MessageManager.getMessage("Successful-Purchase"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package be.isach.ultracosmetics.economy;

import be.isach.ultracosmetics.UltraCosmetics;
import org.bukkit.entity.Player;

/**
* Handles the current economy being used.
*
* @author RadBuilder
* @since 2.5
*/
public class EconomyHandler {
private UltraCosmetics ultraCosmetics;
private EconomyHook economyHook;
private boolean usingEconomy;

public EconomyHandler(UltraCosmetics ultraCosmetics, String economy) {
this.ultraCosmetics = ultraCosmetics;
if (economy.equalsIgnoreCase("vault")) {
economyHook = new VaultHook(ultraCosmetics);
} else if (economy.equalsIgnoreCase("playerpoints")) {
economyHook = new PlayerPointsHook(ultraCosmetics);
} else {
usingEconomy = false;
}
}

public void withdraw(Player player, int amount) {
economyHook.withdraw(player, amount);
}

public void deposit(Player player, int amount) {
economyHook.deposit(player, amount);
}

public double balance(Player player) {
return economyHook.balance(player);
}

public String getName() {
return economyHook.getName();
}

public boolean isUsingEconomy() {
return usingEconomy && economyHook.economyEnabled();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package be.isach.ultracosmetics.economy;

import org.bukkit.entity.Player;

/**
* Economy hook interface.
*
* @author RadBuilder
* @since 2.5
*/
public interface EconomyHook {
/**
* Withdraws the specified amount of money from the specified player.
*
* @param player The player to withdraw money from.
* @param amount The amount to withdraw from the player.
*/
void withdraw(Player player, int amount);

/**
* Gives the specified amount of money to the specified player.
*
* @param player The player to give money to.
* @param amount The amount to give to the player.
*/
void deposit(Player player, int amount);

/**
* Gets the balance of the specified player.
*
* @param player The player to get the balance of.
* @return The player's balance.
*/
double balance(Player player);

/**
* Gets the name of the economy being used.
*
* @return The name of the economy being used.
*/
String getName();

/**
* Gets if the economy is enabled and functioning.
*
* @return True if the economy is enabled and functioning, false otherwise.
*/
boolean economyEnabled();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package be.isach.ultracosmetics.economy;

import be.isach.ultracosmetics.UltraCosmetics;
import org.black_ixx.playerpoints.PlayerPoints;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;

/**
* PlayerPoints economy hook.
*
* @author RadBuilder
* @since 2.5
*/
public class PlayerPointsHook implements EconomyHook {
private UltraCosmetics ultraCosmetics;
private PlayerPoints playerPoints;
private boolean economyEnabled;

public PlayerPointsHook(UltraCosmetics ultraCosmetics) {
this.ultraCosmetics = ultraCosmetics;
if (hookPlayerPoints()) {
ultraCosmetics.getSmartLogger().write("");
ultraCosmetics.getSmartLogger().write("Hooked into PlayerPoints for economy.");
ultraCosmetics.getSmartLogger().write("");
economyEnabled = true;
} else {
ultraCosmetics.getSmartLogger().write("");
ultraCosmetics.getSmartLogger().write("Something happened while hooking into PlayerPoints for economy.");
ultraCosmetics.getSmartLogger().write("");
economyEnabled = false;
}
}

/**
* Validate that there's access to PlayerPoints.
*
* @return True if there is access to PlayerPoints, otherwise false.
*/
private boolean hookPlayerPoints() {
final Plugin plugin = ultraCosmetics.getServer().getPluginManager().getPlugin("PlayerPoints");
playerPoints = PlayerPoints.class.cast(plugin);
return playerPoints != null;
}

@Override
public void withdraw(Player player, int amount) {
playerPoints.getAPI().take(player.getUniqueId(), amount);
}

@Override
public void deposit(Player player, int amount) {
playerPoints.getAPI().give(player.getUniqueId(), amount);
}

@Override
public double balance(Player player) {
return playerPoints.getAPI().look(player.getUniqueId());
}

@Override
public String getName() {
return "PlayerPoints";
}

@Override
public boolean economyEnabled() {
return economyEnabled;
}
}
Loading

0 comments on commit 77ab4a2

Please sign in to comment.