This repository has been archived by the owner on Jun 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redid economy system and added PlayerPoints support
- Loading branch information
1 parent
0ea7b95
commit 77ab4a2
Showing
38 changed files
with
264 additions
and
2,153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
core/src/main/java/be/isach/ultracosmetics/economy/EconomyHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
core/src/main/java/be/isach/ultracosmetics/economy/EconomyHook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
69 changes: 69 additions & 0 deletions
69
core/src/main/java/be/isach/ultracosmetics/economy/PlayerPointsHook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.