mirror of
https://github.com/songoda/EpicHeads.git
synced 2025-02-13 01:51:19 +01:00
Added alternative economy options.
Fixed issue with favorites saving. Changes default heads command syntax.
This commit is contained in:
parent
5b767872bb
commit
0d4120e5fa
@ -4,7 +4,7 @@ stages:
|
||||
variables:
|
||||
name: "EpicHeads"
|
||||
path: "/builds/$CI_PROJECT_PATH"
|
||||
version: "3.0.6"
|
||||
version: "3.0.7"
|
||||
|
||||
build:
|
||||
stage: build
|
||||
|
5
pom.xml
5
pom.xml
@ -74,5 +74,10 @@
|
||||
<version>1.7.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.black_ixx</groupId>
|
||||
<artifactId>playerpoints</artifactId>
|
||||
<version>2.1.4</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -1,6 +1,10 @@
|
||||
package com.songoda.epicheads;
|
||||
|
||||
import com.songoda.epicheads.command.CommandManager;
|
||||
import com.songoda.epicheads.economy.Economy;
|
||||
import com.songoda.epicheads.economy.ItemEconomy;
|
||||
import com.songoda.epicheads.economy.PlayerPointsEconomy;
|
||||
import com.songoda.epicheads.economy.VaultEconomy;
|
||||
import com.songoda.epicheads.head.Category;
|
||||
import com.songoda.epicheads.head.Head;
|
||||
import com.songoda.epicheads.head.HeadManager;
|
||||
@ -31,6 +35,7 @@ import org.json.simple.parser.ParseException;
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -48,6 +53,7 @@ public class EpicHeads extends JavaPlugin {
|
||||
|
||||
private Locale locale;
|
||||
private Storage storage;
|
||||
private Economy economy;
|
||||
|
||||
public static EpicHeads getInstance() {
|
||||
return INSTANCE;
|
||||
@ -88,6 +94,16 @@ public class EpicHeads extends JavaPlugin {
|
||||
Bukkit.getPluginManager().registerEvents(new ItemListeners(this), this);
|
||||
Bukkit.getPluginManager().registerEvents(new LoginListeners(this), this);
|
||||
|
||||
// Setup Economy
|
||||
if (SettingsManager.Setting.VAULT_ECONOMY.getBoolean()
|
||||
&& getServer().getPluginManager().getPlugin("Vault") != null)
|
||||
this.economy = new VaultEconomy(this);
|
||||
else if (SettingsManager.Setting.PLAYER_POINTS_ECONOMY.getBoolean()
|
||||
&& getServer().getPluginManager().getPlugin("PlayerPoints") != null)
|
||||
this.economy = new PlayerPointsEconomy(this);
|
||||
else if (SettingsManager.Setting.ITEM_ECONOMY.getBoolean())
|
||||
this.economy = new ItemEconomy(this);
|
||||
|
||||
// Download Heads
|
||||
downloadHeads();
|
||||
|
||||
@ -122,14 +138,14 @@ public class EpicHeads extends JavaPlugin {
|
||||
|
||||
private void loadData() {
|
||||
// Adding in favorites.
|
||||
if (storage.containsGroup("")) {
|
||||
if (storage.containsGroup("players")) {
|
||||
for (StorageRow row : storage.getRowsByGroup("players")) {
|
||||
if (row.get("uuid").asObject() == null)
|
||||
continue;
|
||||
|
||||
EPlayer player = new EPlayer(
|
||||
UUID.fromString(row.get("uuid").asString()),
|
||||
row.get("favorites").asStringList());
|
||||
(List<String>)row.get("favorites").asObject());
|
||||
|
||||
this.playerManager.addPlayer(player);
|
||||
}
|
||||
@ -267,6 +283,10 @@ public class EpicHeads extends JavaPlugin {
|
||||
return locale;
|
||||
}
|
||||
|
||||
public Economy getEconomy() {
|
||||
return economy;
|
||||
}
|
||||
|
||||
public References getReferences() {
|
||||
return references;
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ public class CommandManager implements CommandExecutor {
|
||||
addCommand(new CommandUrl(commandEpicHeads));
|
||||
addCommand(new CommandBase64(commandEpicHeads));
|
||||
addCommand(new CommandGive(commandEpicHeads));
|
||||
addCommand(new CommandGiveToken(commandEpicHeads));
|
||||
|
||||
for (AbstractCommand abstractCommand : commands) {
|
||||
if (abstractCommand.getParent() != null) continue;
|
||||
|
@ -45,7 +45,7 @@ public class CommandBase64 extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/epicheads base64";
|
||||
return "/heads base64";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,7 +32,7 @@ public class CommandEpicHeads extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/epicheads";
|
||||
return "/heads";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,58 @@
|
||||
package com.songoda.epicheads.command.commands;
|
||||
|
||||
import com.songoda.epicheads.EpicHeads;
|
||||
import com.songoda.epicheads.command.AbstractCommand;
|
||||
import com.songoda.epicheads.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandGiveToken extends AbstractCommand {
|
||||
|
||||
public CommandGiveToken(AbstractCommand parent) {
|
||||
super(parent, false, "givetoken");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicHeads instance, CommandSender sender, String... args) {
|
||||
|
||||
Player player = Bukkit.getPlayer(args[1]);
|
||||
int amount = Integer.valueOf(args[2]);
|
||||
|
||||
if (player == null) {
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.give.notonline", args[1]));
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
player.getInventory().addItem(Methods.createToken(amount));
|
||||
|
||||
player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.givetoken.receive", amount));
|
||||
|
||||
if (player != sender)
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.givetoken.success", player.getName(), amount));
|
||||
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(EpicHeads instance, CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "epicheads.givetoken";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/heads givetoken <player> <amount>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Gives the player a specified amount of player head tokens.";
|
||||
}
|
||||
}
|
@ -43,7 +43,7 @@ public class CommandHelp extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/epicheads help";
|
||||
return "/heads help";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,7 +32,7 @@ public class CommandReload extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/epicheads reload";
|
||||
return "/heads reload";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -46,7 +46,7 @@ public class CommandUrl extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/epicheads url";
|
||||
return "/heads url";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
10
src/main/java/com/songoda/epicheads/economy/Economy.java
Normal file
10
src/main/java/com/songoda/epicheads/economy/Economy.java
Normal file
@ -0,0 +1,10 @@
|
||||
package com.songoda.epicheads.economy;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface Economy {
|
||||
|
||||
boolean hasBalance(Player player, double cost);
|
||||
|
||||
boolean withdrawBalance(Player player, double cost);
|
||||
}
|
67
src/main/java/com/songoda/epicheads/economy/ItemEconomy.java
Normal file
67
src/main/java/com/songoda/epicheads/economy/ItemEconomy.java
Normal file
@ -0,0 +1,67 @@
|
||||
package com.songoda.epicheads.economy;
|
||||
|
||||
import com.songoda.epicheads.EpicHeads;
|
||||
import com.songoda.epicheads.utils.Methods;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class ItemEconomy implements Economy {
|
||||
|
||||
private final EpicHeads plugin;
|
||||
|
||||
public ItemEconomy(EpicHeads plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
||||
public boolean isItem(ItemStack itemStack) {
|
||||
if (itemStack == null)
|
||||
return false;
|
||||
return itemStack.isSimilar(Methods.createToken(1));
|
||||
}
|
||||
|
||||
|
||||
private int convertAmount(double amount) {
|
||||
return (int) Math.ceil(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBalance(Player player, double cost) {
|
||||
int amount = convertAmount(cost);
|
||||
for (ItemStack item : player.getInventory().getContents()) {
|
||||
if (!isItem(item))
|
||||
continue;
|
||||
if (amount <= item.getAmount())
|
||||
return true;
|
||||
amount -= item.getAmount();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean withdrawBalance(Player player, double cost) {
|
||||
int amount = convertAmount(cost);
|
||||
ItemStack[] contents = player.getInventory().getContents();
|
||||
for (int index = 0; index < contents.length; ++index) {
|
||||
ItemStack item = contents[index];
|
||||
if (!isItem(item))
|
||||
continue;
|
||||
if (amount >= item.getAmount()) {
|
||||
amount -= item.getAmount();
|
||||
contents[index] = null;
|
||||
} else {
|
||||
item.setAmount(item.getAmount() - amount);
|
||||
amount = 0;
|
||||
}
|
||||
if (amount == 0)
|
||||
break;
|
||||
}
|
||||
if (amount != 0)
|
||||
return false;
|
||||
player.getInventory().setContents(contents);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.songoda.epicheads.economy;
|
||||
|
||||
import com.songoda.epicheads.EpicHeads;
|
||||
import org.black_ixx.playerpoints.PlayerPoints;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PlayerPointsEconomy implements Economy {
|
||||
|
||||
private final EpicHeads plugin;
|
||||
|
||||
private final PlayerPoints playerPoints;
|
||||
|
||||
public PlayerPointsEconomy(EpicHeads plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
this.playerPoints = (PlayerPoints) plugin.getServer().getPluginManager().getPlugin("PlayerPoints");
|
||||
}
|
||||
|
||||
private int convertAmount(double amount) {
|
||||
return (int) Math.ceil(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBalance(Player player, double cost) {
|
||||
int amount = convertAmount(cost);
|
||||
return playerPoints.getAPI().look(player.getUniqueId()) >= amount;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean withdrawBalance(Player player, double cost) {
|
||||
int amount = convertAmount(cost);
|
||||
return playerPoints.getAPI().take(player.getUniqueId(), amount);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.songoda.epicheads.economy;
|
||||
|
||||
import com.songoda.epicheads.EpicHeads;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class VaultEconomy implements Economy {
|
||||
|
||||
private final EpicHeads plugin;
|
||||
|
||||
private final net.milkbowl.vault.economy.Economy vault;
|
||||
|
||||
public VaultEconomy(EpicHeads plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
this.vault = plugin.getServer().getServicesManager().
|
||||
getRegistration(net.milkbowl.vault.economy.Economy.class).getProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBalance(Player player, double cost) {
|
||||
return vault.has(player, cost);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean withdrawBalance(Player player, double cost) {
|
||||
return vault.withdrawPlayer(player, cost).transactionSuccess();
|
||||
}
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
package com.songoda.epicheads.gui;
|
||||
|
||||
import com.songoda.epicheads.EpicHeads;
|
||||
import com.songoda.epicheads.economy.Economy;
|
||||
import com.songoda.epicheads.head.Category;
|
||||
import com.songoda.epicheads.head.Head;
|
||||
import com.songoda.epicheads.players.EPlayer;
|
||||
import com.songoda.epicheads.utils.AbstractChatConfirm;
|
||||
import com.songoda.epicheads.utils.SettingsManager;
|
||||
import com.songoda.epicheads.utils.gui.AbstractGUI;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
@ -15,7 +15,6 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
@ -161,7 +160,7 @@ public class GUIHeads extends AbstractGUI {
|
||||
|
||||
inventory.setItem(i + 9, item);
|
||||
|
||||
double cost = SettingsManager.Setting.PRICE.getDouble();
|
||||
double cost = SettingsManager.Setting.HEAD_COST.getDouble();
|
||||
|
||||
registerClickable(i + 9, ((player1, inventory1, cursor, slot, type) -> {
|
||||
if (type == ClickType.SHIFT_LEFT || type == ClickType.SHIFT_RIGHT) {
|
||||
@ -180,17 +179,16 @@ public class GUIHeads extends AbstractGUI {
|
||||
|
||||
|
||||
if (!free) {
|
||||
if (plugin.getServer().getPluginManager().getPlugin("Vault") != null) {
|
||||
RegisteredServiceProvider<Economy> rsp = plugin.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||
net.milkbowl.vault.economy.Economy econ = rsp.getProvider();
|
||||
if (econ.has(player, cost)) {
|
||||
econ.withdrawPlayer(player, cost);
|
||||
if (plugin.getEconomy() != null) {
|
||||
Economy economy = plugin.getEconomy();
|
||||
if (economy.hasBalance(player, cost)) {
|
||||
economy.withdrawBalance(player, cost);
|
||||
} else {
|
||||
player.sendMessage(plugin.getLocale().getMessage("event.buyhead.cannotafford"));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
player.sendMessage("Vault is not installed.");
|
||||
player.sendMessage("Economy plugin not setup correctly...");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Head {
|
||||
|
||||
@ -65,7 +64,7 @@ public class Head {
|
||||
ItemStack item = Methods.addTexture(new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13)
|
||||
? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3), this.URL);
|
||||
|
||||
double cost = SettingsManager.Setting.PRICE.getDouble();
|
||||
double cost = SettingsManager.Setting.HEAD_COST.getDouble();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(Methods.formatText((favorite ? "&6⭐ " : "") + "&9" + name));
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
@ -15,7 +15,9 @@ import org.bukkit.inventory.meta.SkullMeta;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Methods {
|
||||
@ -81,6 +83,27 @@ public class Methods {
|
||||
return StringUtils.substringBetween(new String(Base64.getDecoder().decode(encoded)), "texture/", "\"");
|
||||
}
|
||||
|
||||
public static ItemStack createToken(int amount) {
|
||||
ItemStack itemStack = new ItemStack(Material.valueOf(SettingsManager.Setting.ITEM_TOKEN_TYPE.getString()));
|
||||
|
||||
if (itemStack.getType() == (EpicHeads.getInstance().isServerVersionAtLeast(ServerVersion.V1_13)
|
||||
? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"))) {
|
||||
itemStack = EpicHeads.getInstance().getHeadManager().getHeads().stream()
|
||||
.filter(head -> head.getId() == SettingsManager.Setting.ITEM_TOKEN_ID.getInt())
|
||||
.findFirst().get().asItemStack();
|
||||
}
|
||||
itemStack.setAmount(amount);
|
||||
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
meta.setDisplayName(formatText(SettingsManager.Setting.ITEM_TOKEN_NAME.getString()));
|
||||
List<String> lore = new ArrayList<>();
|
||||
for (String line : SettingsManager.Setting.ITEM_TOKEN_LORE.getStringList())
|
||||
lore.add(formatText(line));
|
||||
meta.setLore(lore);
|
||||
itemStack.setItemMeta(meta);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public static ItemStack getGlass() {
|
||||
EpicHeads instance = EpicHeads.getInstance();
|
||||
return Methods.getGlass(instance.getConfig().getBoolean("Interfaces.Replace Glass Type 1 With Rainbow Glass"), instance.getConfig().getInt("Interfaces.Glass Type 1"));
|
||||
|
@ -172,13 +172,21 @@ public class SettingsManager implements Listener {
|
||||
|
||||
AUTOSAVE("Main.Auto Save Interval In Seconds", 15),
|
||||
DISCORD("Main.Show Discord Button", true),
|
||||
PRICE("Main.Head Cost", 24.99),
|
||||
FREE_IN_CREATIVE("Main.Heads Free In Creative Mode", false),
|
||||
|
||||
GLASS_TYPE_1("Interfaces.Glass Type 1", 7),
|
||||
GLASS_TYPE_2("Interfaces.Glass Type 2", 11),
|
||||
GLASS_TYPE_3("Interfaces.Glass Type 3", 3),
|
||||
|
||||
HEAD_COST("Economy.Head Cost", 24.99),
|
||||
VAULT_ECONOMY("Economy.Use Vault Economy", true),
|
||||
PLAYER_POINTS_ECONOMY("Economy.Use Player Points Economy", false),
|
||||
ITEM_ECONOMY("Economy.Use Item Economy", false),
|
||||
ITEM_TOKEN_TYPE("Economy.Item.Type", EpicHeads.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? "PLAYER_HEAD" : "SKULL_ITEM"),
|
||||
ITEM_TOKEN_ID("Economy.Item.Head ID", 14395),
|
||||
ITEM_TOKEN_NAME("Economy.Item.Name", "&6Player Head Token"),
|
||||
ITEM_TOKEN_LORE("Economy.Item.Lore", Arrays.asList("&8Use in /Heads!")),
|
||||
|
||||
LANGUGE_MODE("System.Language Mode", "en_US");
|
||||
|
||||
private String setting;
|
||||
|
@ -17,15 +17,6 @@ public class StorageItem {
|
||||
this.object = object;
|
||||
}
|
||||
|
||||
public StorageItem(String key, List<Integer> integers) {
|
||||
String object = "";
|
||||
for (Integer i : integers) {
|
||||
object += i + ";";
|
||||
}
|
||||
this.key = key;
|
||||
this.object = object;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
@ -59,15 +50,4 @@ public class StorageItem {
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<String> asStringList() {
|
||||
List<String> list = new ArrayList<>();
|
||||
if (object == null) return list;
|
||||
String[] stack = ((String) object).split(";");
|
||||
for (String item : stack) {
|
||||
if (item.equals("")) continue;
|
||||
list.add(item);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
@ -34,4 +34,7 @@ event.buyhead.cannotafford = "&cYou cannot afford this head."
|
||||
command.give.notonline = "&cThe player &4%name% &ccould not be found."
|
||||
command.give.notfound = "&cThe head &4%name%&c could not be found."
|
||||
command.give.success = "&7You have been given &6%player% &7a head named &6%name%&7."
|
||||
command.give.receive = "&7You have been given a head named &6%name%&7."
|
||||
command.give.receive = "&7You have been given a head named &6%name%&7."
|
||||
|
||||
command.givetoken.success = "&7You gave &6%player% %amount% &7player head tokens."
|
||||
command.givetoken.receive = "&7You have been given &6%amount% &7player head tokens."
|
Loading…
Reference in New Issue
Block a user