Initial commit
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>ProjectCranked</artifactId>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>Vouchers</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<artifactId>Utils</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,45 @@
|
||||
package net.crankedpvp.vouchers;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.mattstudios.mf.base.CommandManager;
|
||||
import net.crankedpvp.vouchers.commands.VoucherCommand;
|
||||
import net.crankedpvp.vouchers.listeners.VoucherListener;
|
||||
import net.crankedpvp.vouchers.struct.VoucherRegister;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class VouchersPlugin extends JavaPlugin {
|
||||
|
||||
@Getter
|
||||
private static VouchersPlugin instance;
|
||||
|
||||
@Getter
|
||||
private VoucherRegister voucherRegister;
|
||||
|
||||
@Getter
|
||||
private CommandManager commandManager;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
this.voucherRegister = new VoucherRegister(this);
|
||||
this.voucherRegister.createDefaultConfig("-example");
|
||||
this.voucherRegister.initializeVouchers();
|
||||
|
||||
this.commandManager = new CommandManager(this);
|
||||
this.commandManager.register(new VoucherCommand(this));
|
||||
|
||||
this.registerListeners();
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
PluginManager pluginManager = this.getServer().getPluginManager();
|
||||
pluginManager.registerEvents(new VoucherListener(this), this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
instance = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
package net.crankedpvp.vouchers.commands;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import me.mattstudios.mf.annotations.*;
|
||||
import me.mattstudios.mf.base.CommandBase;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.vouchers.VouchersPlugin;
|
||||
import net.crankedpvp.vouchers.inventory.AdminInventory;
|
||||
import net.crankedpvp.vouchers.struct.VoucherRegister;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
|
||||
@Command("voucher")
|
||||
@Alias({"vouchers", "cv", "crankedvoucher"})
|
||||
public class VoucherCommand extends CommandBase {
|
||||
|
||||
private final VouchersPlugin plugin;
|
||||
private final VoucherRegister voucherRegister;
|
||||
public VoucherCommand(VouchersPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.voucherRegister = plugin.getVoucherRegister();
|
||||
}
|
||||
|
||||
@Default
|
||||
@Permission("vouchers.*")
|
||||
public void defaultCommand(CommandSender commandSender) {
|
||||
Player player = (Player)commandSender;
|
||||
AdminInventory adminInventory = new AdminInventory(player);
|
||||
adminInventory.getUI().open(player);
|
||||
}
|
||||
|
||||
|
||||
@SubCommand("list")
|
||||
@Permission("vouchers.*")
|
||||
public void listCommand(CommandSender commandSender) {
|
||||
Player player = (Player)commandSender;
|
||||
commandSender.sendMessage("");
|
||||
commandSender.sendMessage(CC.translate("&bVouchers"));
|
||||
this.voucherRegister.getVoucherObjects().forEach(voucher -> commandSender.sendMessage(CC.translate(" &b* &f" + voucher.getId())));
|
||||
player.playSound(player.getLocation(), Sound.FIREWORK_LAUNCH, 2.0F, 2.0F);
|
||||
}
|
||||
|
||||
@SubCommand("reload")
|
||||
@Permission("vouchers.*")
|
||||
public void reloadCommand(CommandSender commandSender, @Optional String voucher) {
|
||||
Player sender = (Player) commandSender;
|
||||
sender.playSound(sender.getLocation(), Sound.SUCCESSFUL_HIT, 2.0F, 2.0F);
|
||||
if (voucher == null) {
|
||||
this.voucherRegister.clearVouchersMap();
|
||||
this.voucherRegister.initializeVouchers();
|
||||
sender.sendMessage(CC.translate("&aYou have successfully reloaded all vouchers"));
|
||||
return;
|
||||
}
|
||||
|
||||
this.voucherRegister.reloadVoucher(voucher);
|
||||
sender.sendMessage(CC.translate("&aYou have successfully reloaded the " + voucher + " voucher"));
|
||||
|
||||
}
|
||||
|
||||
@SubCommand("create")
|
||||
@Permission("vouchers.*")
|
||||
public void createCommand(CommandSender commandSender, String name) {
|
||||
Player sender = (Player)commandSender;
|
||||
if (this.voucherRegister.isVoucher(name)) {
|
||||
sender.sendMessage(CC.translate("&cThis is already a registered voucher"));
|
||||
sender.playSound(sender.getLocation(), Sound.ANVIL_LAND, 2.0F, 2.0F);
|
||||
return;
|
||||
}
|
||||
|
||||
this.voucherRegister.createDefaultConfig(name);
|
||||
this.voucherRegister.initialize(name);
|
||||
sender.sendMessage(CC.translate("&aSuccessfully created the voucher of name: " + name));
|
||||
sender.playSound(sender.getLocation(), Sound.SUCCESSFUL_HIT, 2.0F, 2.0F);
|
||||
}
|
||||
|
||||
@SubCommand("delete")
|
||||
@Permission("vouchers.*")
|
||||
public void deleteCommand(CommandSender commandSender, String name) {
|
||||
Player player = (Player)commandSender;
|
||||
if (this.voucherRegister.isVoucher(name)) {
|
||||
this.voucherRegister.removeVoucher(name);
|
||||
this.voucherRegister.deleteConfig(name);
|
||||
player.sendMessage(CC.translate("&cYou have deleted the voucher of name: " + name));
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_BREAK, 2.0F, 2.0F);
|
||||
} else {
|
||||
player.sendMessage(CC.translate("&cThat is not a valid voucher"));
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_LAND, 2.0F, 2.0F);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SubCommand("give")
|
||||
@Permission("vouchers.*")
|
||||
public void giveCommand(CommandSender commandSender, @Completion("#players") final Player player, final String name, @Optional Integer amount) {
|
||||
if(amount == null) amount = 1;
|
||||
if (!player.isOnline()) {
|
||||
commandSender.sendMessage(CC.translate("&cThat player is not online"));
|
||||
if(commandSender instanceof Player)
|
||||
((Player)commandSender).playSound(player.getLocation(), Sound.ANVIL_LAND, 2.0F, 2.0F);
|
||||
return;
|
||||
}
|
||||
if (!this.voucherRegister.isVoucher(name)) {
|
||||
commandSender.sendMessage(CC.translate("&cThe voucher by name " + name + " is not a valid voucher"));
|
||||
if(commandSender instanceof Player)
|
||||
((Player)commandSender).playSound(player.getLocation(), Sound.ANVIL_LAND, 2.0F, 2.0F);
|
||||
return;
|
||||
}
|
||||
amount = (amount <= 0) ? 1 : amount;
|
||||
player.getInventory().addItem(this.voucherRegister.getVoucher(name).createVoucherItem(amount));
|
||||
commandSender.sendMessage(CC.translate("&cGiven voucher to " + player.getName()));
|
||||
player.sendMessage(CC.translate("&cReceived the " + name + " voucher"));
|
||||
player.playSound(player.getLocation(), Sound.ITEM_PICKUP, 2.0F, 2.0F);
|
||||
}
|
||||
|
||||
@SubCommand("disable")
|
||||
@Permission("vouchers.*")
|
||||
public void disableCommand(CommandSender commandSender, String name) {
|
||||
if (!this.voucherRegister.isVoucher(name))
|
||||
return;
|
||||
File file = new File(this.plugin.getDataFolder() + "/Vouchers/" + name + ".yml");
|
||||
if (file.renameTo(new File(this.plugin.getDataFolder() + "/Vouchers/-" + name + ".yml"))) {
|
||||
this.voucherRegister.removeVoucher(name);
|
||||
commandSender.sendMessage(CC.translate("&cDisabled voucher: " + name));
|
||||
Player player = (Player)commandSender;
|
||||
player.playSound(player.getLocation(), Sound.BAT_TAKEOFF, 2.0F, 2.0F);
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand("enable")
|
||||
@Permission("vouchers.*")
|
||||
public void enableCommand(CommandSender commandSender, String name) {
|
||||
if (this.voucherRegister.isVoucher(name))
|
||||
return;
|
||||
File file = new File(this.plugin.getDataFolder() + "/Vouchers/-" + name + ".yml");
|
||||
if (file.renameTo(new File(this.plugin.getDataFolder() + "/Vouchers/" + name + ".yml"))) {
|
||||
this.voucherRegister.initialize(name);
|
||||
commandSender.sendMessage(CC.translate("&aEnabled voucher: " + name));
|
||||
Player player = (Player)commandSender;
|
||||
player.playSound(player.getLocation(), Sound.SUCCESSFUL_HIT, 2.0F, 2.0F);
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand("help")
|
||||
@Permission("vouchers.*")
|
||||
public void helpMessage(CommandSender commandSender) {
|
||||
commandSender.sendMessage(CC.translate("&a-------[ &2Vouchers &a]-------"));
|
||||
commandSender.sendMessage(CC.translate("&a[] &8- &7Optional argument"));
|
||||
commandSender.sendMessage(CC.translate("&2<> &8- &7Required argument"));
|
||||
commandSender.sendMessage("");
|
||||
commandSender.sendMessage(CC.translate(" &2* &a/voucher create <name>"));
|
||||
commandSender.sendMessage(CC.translate(" &2* &a/voucher delete <name>"));
|
||||
commandSender.sendMessage(CC.translate(" &2* &a/voucher enable <name>"));
|
||||
commandSender.sendMessage(CC.translate(" &2* &a/voucher disable <name>"));
|
||||
commandSender.sendMessage(CC.translate(" &2* &a/voucher reload [voucher]"));
|
||||
commandSender.sendMessage(CC.translate(" &2* &a/voucher list"));
|
||||
commandSender.sendMessage(CC.translate(" &2* &a/voucher give <player> <voucher> [amount]"));
|
||||
commandSender.sendMessage(CC.translate("&a-------[ &2Vouchers &a]-------"));
|
||||
if(commandSender instanceof Player) {
|
||||
Player player = (Player) commandSender;
|
||||
player.playSound(player.getLocation(), Sound.LEVEL_UP, 2.0F, 2.0F);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package net.crankedpvp.vouchers.inventory;
|
||||
|
||||
import dev.triumphteam.gui.guis.GuiItem;
|
||||
import dev.triumphteam.gui.guis.PaginatedGui;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
|
||||
import net.crankedpvp.vouchers.VouchersPlugin;
|
||||
import net.crankedpvp.vouchers.struct.Voucher;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class AdminInventory {
|
||||
private final PaginatedGui adminInventory;
|
||||
|
||||
public PaginatedGui getUI() {
|
||||
return this.adminInventory;
|
||||
}
|
||||
|
||||
Map<String, Voucher> vouchersMap = VouchersPlugin.getInstance().getVoucherRegister().getVouchers();
|
||||
|
||||
public AdminInventory(Player player) {
|
||||
this.adminInventory = new PaginatedGui(6, 36, "Cranked Vouchers");
|
||||
this.adminInventory.setDefaultClickAction(event -> event.setCancelled(true));
|
||||
this.adminInventory.getFiller().fillBottom(new GuiItem(createFillerItem()));
|
||||
ItemStack prevPage = new ItemBuilder(Material.ARROW, "&c<- Previous Page", "&7Right-Click&7 to go to the previous page.").colorize().build();
|
||||
ItemStack nextPage = new ItemBuilder(Material.ARROW, "&aNext Page ->", "&7Right-Click&7 to go to the next page.").colorize().build();
|
||||
this.adminInventory.setItem(6, 1, new GuiItem(prevPage, event -> {
|
||||
this.adminInventory.previous();
|
||||
event.setCancelled(true);
|
||||
}));
|
||||
this.adminInventory.setItem(6, 9, new GuiItem(nextPage, event -> {
|
||||
this.adminInventory.next();
|
||||
event.setCancelled(true);
|
||||
}));
|
||||
for (Voucher voucher : this.vouchersMap.values()) {
|
||||
ItemStack item = voucher.createVoucherItem(1);
|
||||
this.adminInventory.addItem(new GuiItem(item, event -> {
|
||||
if(player.hasPermission("vouchers.*")) player.getInventory().addItem(item);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
private ItemStack createFillerItem() {
|
||||
ItemStack item = new ItemStack(Material.STAINED_GLASS_PANE, 1, DyeColor.GRAY.getData());
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(CC.translate("&cCranked&fPvP"));
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package net.crankedpvp.vouchers.listeners;
|
||||
|
||||
import de.tr7zw.nbtapi.NBTItem;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.vouchers.VouchersPlugin;
|
||||
import net.crankedpvp.vouchers.struct.Voucher;
|
||||
import net.crankedpvp.vouchers.struct.VoucherRegister;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class VoucherListener implements Listener {
|
||||
|
||||
private final VouchersPlugin plugin;
|
||||
public VoucherListener(VouchersPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if(event.getAction() == null) return;
|
||||
if(event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.RIGHT_CLICK_AIR) return;
|
||||
if(event.getItem() == null) return;
|
||||
|
||||
ItemStack itemStack = event.getItem();
|
||||
if(!VoucherRegister.isVoucher(itemStack)) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
NBTItem nbtItem = new NBTItem(itemStack);
|
||||
Voucher voucher = this.plugin.getVoucherRegister().getVoucher(nbtItem.getString("voucherType"));
|
||||
|
||||
Player player = event.getPlayer();
|
||||
for(String permission : voucher.getBlockedPermissions()) {
|
||||
if(player.hasPermission(permission)) {
|
||||
player.sendMessage(CC.translate("&cYou cannot redeem this due to your current permission set"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int amount = itemStack.getAmount();
|
||||
if (amount <= 1) {
|
||||
event.getPlayer().setItemInHand(null);
|
||||
} else {
|
||||
itemStack.setAmount(amount - 1);
|
||||
event.getPlayer().setItemInHand(itemStack);
|
||||
}
|
||||
|
||||
voucher.getExecuteCommands().forEach(command -> plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), command.replace("%player%", event.getPlayer().getName())));
|
||||
voucher.getMessages().forEach(message -> player.sendMessage(CC.translate(message)));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package net.crankedpvp.vouchers.struct;
|
||||
|
||||
import de.tr7zw.nbtapi.NBTItem;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter @AllArgsConstructor
|
||||
public class Voucher {
|
||||
private final String id;
|
||||
private final Material material;
|
||||
private final String displayName;
|
||||
private final List<String> displayLore;
|
||||
private final boolean glowing;
|
||||
private final List<String> executeCommands;
|
||||
private final List<String> blockedPermissions;
|
||||
private final List<String> messages;
|
||||
|
||||
public ItemStack createVoucherItem(int amount) {
|
||||
ItemBuilder itemBuilder = new ItemBuilder(material, amount, (short)0, displayName).setLore(getDisplayLore());
|
||||
if(this.glowing) itemBuilder.setGlowing();
|
||||
NBTItem nbtItem = new NBTItem(itemBuilder.colorize().build());
|
||||
nbtItem.setString("crankedCustomItem", "voucher");
|
||||
nbtItem.setString("voucherType", getId());
|
||||
return nbtItem.getItem();
|
||||
}
|
||||
|
||||
public ItemStack createVoucherItem() {
|
||||
return createVoucherItem(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
package net.crankedpvp.vouchers.struct;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Maps;
|
||||
import de.tr7zw.nbtapi.NBTItem;
|
||||
import lombok.Getter;
|
||||
import net.crankedpvp.vouchers.VouchersPlugin;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class VoucherRegister {
|
||||
|
||||
private final VouchersPlugin plugin;
|
||||
public VoucherRegister(VouchersPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.vouchers = Maps.newConcurrentMap();
|
||||
}
|
||||
|
||||
@Getter
|
||||
private final Map<String, Voucher> vouchers;
|
||||
|
||||
public void initializeVouchers() {
|
||||
File[] files = (new File(this.plugin.getDataFolder(), "Vouchers")).listFiles();
|
||||
assert files != null;
|
||||
Arrays.stream(files)
|
||||
.filter(file -> !file.getName().startsWith("-"))
|
||||
.forEach(file -> {
|
||||
try {
|
||||
initialize(file.getName().replace(".yml", ""));
|
||||
} catch (NullPointerException exception) {
|
||||
System.out.println("[Vouchers] Failed to register voucher: " + file.getName().replace(".yml", ""));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void initialize(String name) {
|
||||
File file = new File(this.plugin.getDataFolder(), "Vouchers/" + name + ".yml");
|
||||
YamlConfiguration yamlConfiguration = new YamlConfiguration();
|
||||
try {
|
||||
yamlConfiguration.load(file);
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String displayName = yamlConfiguration.getString("Item.Display.Name");
|
||||
List<String> displayLore = yamlConfiguration.getStringList("Item.Display.Lore");
|
||||
boolean glowing = yamlConfiguration.contains("Item.Display.Glowing") && yamlConfiguration.getBoolean("Item.Display.Glowing");
|
||||
List<String> executeCommands = yamlConfiguration.getStringList("Misc.Commands");
|
||||
List<String> blockedPermissions = yamlConfiguration.getStringList("Misc.BlockedPermissions");
|
||||
List<String> messages = yamlConfiguration.getStringList("Misc.Messages");
|
||||
Material material = Material.valueOf(yamlConfiguration.getString("Item.Material").toUpperCase());
|
||||
Voucher voucher = new Voucher(name, material, displayName, displayLore, glowing, executeCommands, blockedPermissions, messages);
|
||||
register(voucher);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void createDefaultConfig(String name) {
|
||||
File file = new File(this.plugin.getDataFolder(), "Vouchers/" + name + ".yml");
|
||||
if (!file.exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
YamlConfiguration yamlConfiguration = new YamlConfiguration();
|
||||
yamlConfiguration.set("Item.Display.Name", "&7[Default Voucher Name]");
|
||||
yamlConfiguration.set("Item.Display.Lore", Arrays.asList("Lore Line One", "Lore Line Two"));
|
||||
yamlConfiguration.set("Item.Display.Glowing", true);
|
||||
yamlConfiguration.set("Item.Material", Material.ENDER_CHEST.name());
|
||||
yamlConfiguration.set("Misc.Commands", Arrays.asList("command to execute on %player%", "command to execute on %player% 2"));
|
||||
yamlConfiguration.set("Misc.BlockedPermissions", Arrays.asList("luckperms.rank.example"));
|
||||
yamlConfiguration.set("Misc.Messages", Arrays.asList("message 1"));
|
||||
try {
|
||||
yamlConfiguration.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void reloadVoucher(String voucher) {
|
||||
if (isVoucher(voucher)) {
|
||||
removeVoucher(voucher);
|
||||
initialize(voucher);
|
||||
} else {
|
||||
System.out.println("[-] Failure reloading voucher, " + voucher);
|
||||
}
|
||||
}
|
||||
|
||||
public void register(Voucher voucher) {
|
||||
try {
|
||||
this.vouchers.put(voucher.getId(), voucher);
|
||||
this.plugin.getLogger().info("Successfully registered voucher: " + voucher.getId());
|
||||
} catch (Exception var3) {
|
||||
System.err.println("&8(&c!&8) Failed to register voucher, " + voucher.getId());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isVoucher(String name) {
|
||||
return (getVoucher(name) != null);
|
||||
}
|
||||
|
||||
public Voucher getVoucher(String name) {
|
||||
Validate.notNull(name);
|
||||
Validate.notEmpty(name);
|
||||
return this.vouchers.get(name);
|
||||
}
|
||||
|
||||
public void clearVouchersMap() {
|
||||
this.vouchers.clear();
|
||||
}
|
||||
|
||||
public void removeVoucher(String voucher) {
|
||||
this.vouchers.remove(voucher);
|
||||
}
|
||||
|
||||
public Collection<Voucher> getVoucherObjects() {
|
||||
return Collections.unmodifiableCollection(this.vouchers.values());
|
||||
}
|
||||
|
||||
public Voucher select(Collection<Voucher> voucherCollection) {
|
||||
return (voucherCollection.size() > 0) ? ImmutableList.copyOf(voucherCollection).get(ThreadLocalRandom.current().nextInt(voucherCollection.size())) : null;
|
||||
}
|
||||
|
||||
public static boolean isVoucher(ItemStack itemStack) {
|
||||
if (itemStack == null || itemStack.getType() == Material.AIR) return false;
|
||||
NBTItem nbtItem = new NBTItem(itemStack);
|
||||
if (nbtItem.hasNBTData()) {
|
||||
if (nbtItem.hasKey("crankedCustomItem")) {
|
||||
return nbtItem.getString("crankedCustomItem").equalsIgnoreCase("voucher");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void deleteConfig(String name) {
|
||||
File file = new File(this.plugin.getDataFolder(), "Vouchers/" + name + ".yml");
|
||||
if (file.exists())
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
name: CrankedVouchers
|
||||
main: net.crankedpvp.vouchers.VouchersPlugin
|
||||
version: ${git.total.commit.count}.0
|
||||
description: "§fCommit ID: §a${git.commit.id.abbrev}"
|
||||
website: https://crankedpvp.net/
|
||||
depend:
|
||||
- CrankedUtils
|
||||
Reference in New Issue
Block a user