This commit is contained in:
TheTealViper 2020-03-27 13:42:26 -07:00
commit b92c6948d0
22 changed files with 1901 additions and 0 deletions

25
.classpath Normal file
View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="spigot-1.14.4.jar">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="HolographicDisplaysAPI-2.3.3-SNAPSHOT.jar">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="Vault.jar">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/bin/

17
.project Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Spigot_EnderBank</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding//src/me/TheTealViper/enderbank/utils/ViperStringUtils.java=UTF-8

View File

@ -0,0 +1,112 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull
org.eclipse.jdt.core.compiler.annotation.nonnull.secondary=
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary=
org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.APILeak=warning
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
org.eclipse.jdt.core.compiler.problem.deadCode=warning
org.eclipse.jdt.core.compiler.problem.deprecation=warning
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled
org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore
org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled
org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning
org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning
org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error
org.eclipse.jdt.core.compiler.problem.nullReference=warning
org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error
org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore
org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning
org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore
org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled
org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning
org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType=warning
org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict=disabled
org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=info
org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
org.eclipse.jdt.core.compiler.problem.unstableAutoModuleName=ignore
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedImport=warning
org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore
org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=11

Binary file not shown.

BIN
Vault.jar Normal file

Binary file not shown.

21
config.yml Normal file
View File

@ -0,0 +1,21 @@
##########################################################
# EnderBank Config #
##########################################################
Default_Page_Price: 10
#This is how much the first bank page will cost
Page_Price_Multiplier: 1
#This is how much the bank page cost will be multiplied
#by for every additional page.
Page_Price_Addition: 0
#This is how much the bank page cost will be increased
#by for every additional page.
##########################################################
# Version #
##########################################################
VERSION: 1
#Do not touch this. No touchy.

8
plugin.yml Normal file
View File

@ -0,0 +1,8 @@
name: "EnderBank"
author: TheTealViper
version: "1.15.1.a.4"
api-version: 1.13
description: "Bank system from popular RPG's."
main: me.TheTealViper.enderbank.EnderBank
commands:
enderbank:

BIN
spigot-1.14.4.jar Normal file

Binary file not shown.

View File

@ -0,0 +1,282 @@
package me.TheTealViper.enderbank;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import me.TheTealViper.enderbank.utils.PluginFile;
public class BankStorage {
public static Map<Player, BankStorage> bankDatabase = new HashMap<Player, BankStorage>(); // This links players to THEIR own bank
public static Map<Player, BankStorage> openBankDatabase = new HashMap<Player, BankStorage>(); // This links players to the bank they are viewing
public static Map<Player, BankStorage> searchDatabase = new HashMap<Player, BankStorage>(); // This links players to the last bank they tried to search
public static EnderBank plugin;
public List<ItemStack> items;
public int unlockedPages;
public PluginFile pf;
public Inventory lastOpenedInventory;
public int lastOpenedPage;
public List<Integer> itemIdentifiers;
public Player bankOwner;
public static void setup(EnderBank plugin) {
BankStorage.plugin = plugin;
}
public static BankStorage getBank(Player bankOwner) {
if(bankDatabase.containsKey(bankOwner))
return bankDatabase.get(bankOwner);
else
return new BankStorage(bankOwner);
}
public BankStorage(Player bankOwner) {
bankDatabase.put(bankOwner, this);
this.bankOwner = bankOwner;
pf = new PluginFile(plugin, "banks/banks." + bankOwner.getUniqueId().toString() + ".yml");
//Load in defaults if not saved yet
if(!pf.contains("unlockedPages")) {
for(int i = 0;i < 42;i++) {
pf.set("inventory." + i, new ItemStack(Material.AIR));
}
pf.set("unlockedPages", 1);
pf.save();
}
//Load in items
items = new ArrayList<ItemStack>();
ConfigurationSection sec = pf.getConfigurationSection("inventory");
for(int i = 0;i < sec.getKeys(false).size();i++) {
items.add(sec.getItemStack(i + ""));
}
//Blah
this.unlockedPages = pf.getInt("unlockedPages");
}
public void openPage(int page, Player opener) {
openBankDatabase.put(opener, this);
Inventory inv = Bukkit.createInventory(null, 54, bankOwner.getName() + "'s Bank [Pg. " + page + "]");
int startingIndex = (page - 1) * 42;
// int endingIndex = page * 42 - 1;
for(int row = 0;row < 6;row++) {
for(int column = 0;column < 7;column++) {
if(items.size() - 1 < startingIndex + column + 7 * row) { //If open a page whose inventory isn't in config yet
ItemStack air = new ItemStack(Material.AIR);
for(int i = 0; i < 42;i++) {
items.add(items.size() - 1, air);
}
}
inv.setItem(row * 9 + column, items.get(startingIndex + column + 7 * row));
}
}
ItemStack nextPage = new ItemStack(Material.PAPER);
ItemMeta nextPageMeta = Bukkit.getItemFactory().getItemMeta(Material.STICK);
List<String> nextPageLore = new ArrayList<String>();
if(unlockedPages > page) {
nextPageMeta.setDisplayName("Next Page");
nextPage.setItemMeta(nextPageMeta);
}else {
nextPageMeta.setDisplayName("Next Page");
nextPageLore.add(ChatColor.RESET + "Click to Purchase");
nextPageLore.add(ChatColor.RESET + "Cost: " + getPageCost(page + 1));
nextPageMeta.setLore(nextPageLore);
nextPage.setItemMeta(nextPageMeta);
}
inv.setItem(8, nextPage);
ItemStack previousPage = new ItemStack(Material.PAPER);
ItemMeta previousPageMeta = Bukkit.getItemFactory().getItemMeta(Material.STICK);
previousPageMeta.setDisplayName("Previous Page");
previousPage.setItemMeta(previousPageMeta);
inv.setItem(17, previousPage);
ItemStack dumpEquipment = new ItemStack(Material.IRON_HELMET);
ItemMeta dumpEquipmentMeta = Bukkit.getItemFactory().getItemMeta(Material.STICK);
List<String> dumpEquipmentLore = new ArrayList<String>();
dumpEquipmentLore.add(ChatColor.RESET + "" + ChatColor.GRAY + "Click to dump all equipment");
dumpEquipmentMeta.setDisplayName("Dump Equipment");
dumpEquipmentMeta.setLore(dumpEquipmentLore);
dumpEquipmentMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
dumpEquipment.setItemMeta(dumpEquipmentMeta);
inv.setItem(35, dumpEquipment);
ItemStack dumpItems = new ItemStack(Material.CHEST);
ItemMeta dumpItemsMeta = Bukkit.getItemFactory().getItemMeta(Material.STICK);
List<String> dumpItemsLore = new ArrayList<String>();
dumpItemsLore.add(ChatColor.RESET + "" + ChatColor.GRAY + "Left click to dump all items in inventory (excluding the hotbar)");
dumpItemsLore.add(ChatColor.RESET + "" + ChatColor.GRAY + "Right click to dump all items in inventory (including the hotbar)");
dumpItemsMeta.setDisplayName("Dump Items");
dumpItemsMeta.setLore(dumpItemsLore);
dumpItems.setItemMeta(dumpItemsMeta);
inv.setItem(44, dumpItems);
ItemStack search = new ItemStack(Material.COMPASS);
ItemMeta searchMeta = Bukkit.getItemFactory().getItemMeta(Material.STICK);
List<String> searchLore = new ArrayList<String>();
searchLore.add(ChatColor.RESET + "" + ChatColor.GRAY + "Click to search your bank");
searchMeta.setDisplayName("Search");
searchMeta.setLore(searchLore);
search.setItemMeta(searchMeta);
inv.setItem(53, search);
for(int row = 0;row < 6;row++) {
inv.setItem(7 + 9 * row, CustomItemHandler.GetBankSeparator());
}
inv.setItem(26, CustomItemHandler.GetBankSeparator());
lastOpenedInventory = inv;
lastOpenedPage = page;
opener.openInventory(inv);
}
public void savePage(int page, Inventory inv) {
int startingIndex = (page - 1) * 42;
for(int row = 0;row < 6;row++) {
for(int column = 0;column < 7;column++) {
ItemStack item = inv.getItem(row * 9 + column);
if(item == null)
item = new ItemStack(Material.AIR);
items.set(startingIndex + column + 7 * row, item);
}
}
save();
}
public void save() {
pf.set("inventory", null);
for(int i = 0;i < items.size();i++) {
pf.set("inventory." + i, items.get(i));
}
pf.set("unlockedPages", unlockedPages);
pf.save();
}
public static int getPageCost(int page) {
int starter = plugin.getConfig().getInt("Default_Page_Price");
double multiplier = plugin.getConfig().getDouble("Page_Price_Multiplier");
int addition = plugin.getConfig().getInt("Page_Price_Addition");
int partOne = (int) (starter * Math.pow(multiplier, page - 2));
int price = partOne + (addition * (page - 2));
return price;
}
public void attemptToAddToBank(int playerInvSlotNumber, Player opener) {
ItemStack pItem = opener.getInventory().getItem(playerInvSlotNumber);
int pAmount = pItem.getAmount();
int maxAmount = pItem.getMaxStackSize();
boolean replaced = false;
for(int i = 0;i < items.size();i++) {
if(replaced)
continue;
//First check for same items
if(items.get(i).isSimilar(pItem)) { //If there is empty space in the bank
ItemStack bItem = items.get(i);
int bAmount = bItem.getAmount();
int originalBAmount = bAmount;
if(bAmount < maxAmount) { //If there is room to merge stacks
bAmount += pAmount;
bAmount = bAmount > maxAmount ? maxAmount : bAmount;
bItem.setAmount(bAmount);
items.set(i, bItem);
pAmount -= maxAmount - originalBAmount;
}
if(pAmount == 0)
replaced = true;
}
//Then check for air
if(items.get(i) == null || items.get(i).getType().equals(Material.AIR)) { //If there is empty space in the bank
ItemStack bItem = pItem.clone();
bItem.setAmount(pAmount);
items.set(i, bItem);
pAmount = 0;
replaced = true;
}
}
pItem.setAmount(pAmount);
opener.getInventory().setItem(playerInvSlotNumber, pItem);
if(playerInvSlotNumber == 40 && pAmount == 0)
opener.getInventory().setItemInOffHand(new ItemStack(Material.AIR));
}
public void openSearch(String search, Player opener) {
//Load up inventory
this.itemIdentifiers = new ArrayList<Integer>();
for(int i = 0;i < items.size();i++) {
ItemStack item = items.get(i);
if(itemIdentifiers.size() < 54) {
boolean found = false;
//Check item custom names first
if(item.hasItemMeta() && item.getItemMeta().hasDisplayName() && item.getItemMeta().getDisplayName().toLowerCase().contains(search.toLowerCase())) {
found = true;
itemIdentifiers.add(i);
}
//Check item default names next
if(item.getType().toString().replace("_", " ").toLowerCase().contains(search.toLowerCase()) && !found) {
found = true;
itemIdentifiers.add(i);
}
//Check lores next
if(item.hasItemMeta() && item.getItemMeta().hasLore() && !found) {
boolean loreFound = false;
for(String s : item.getItemMeta().getLore()) {
if(loreFound)
continue;
if(s.toLowerCase().contains(search.toLowerCase())) {
loreFound = true;
}
}
if(loreFound) {
itemIdentifiers.add(i);
}
}
}
}
//Display inventory
Inventory inv = Bukkit.createInventory(null, 54, "Bank Search");
for(int i = 0;i < 54;i++) {
if(i < itemIdentifiers.size()) {
inv.setItem(i, items.get(itemIdentifiers.get(i)));
}else {
ItemStack filler = new ItemStack(Material.LIGHT_GRAY_STAINED_GLASS_PANE);
ItemMeta meta = Bukkit.getItemFactory().getItemMeta(Material.STICK);
meta.setDisplayName(" ");
filler.setItemMeta(meta);
inv.setItem(i, filler);
}
}
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {public void run() {
opener.closeInventory();
opener.openInventory(inv);
}}, 0);
}
}

View File

@ -0,0 +1,31 @@
package me.TheTealViper.enderbank;
import org.bukkit.Material;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
public class CustomItemHandler implements Listener{
public static EnderBank plugin;
public static void setup(EnderBank plugin) {
plugin.getServer().getPluginManager().registerEvents(new CustomItemHandler(), plugin);
CustomItemHandler.plugin = plugin;
}
static ItemStack BankSeparator = null;
public static ItemStack GetBankSeparator(){
if(BankSeparator == null) {
ItemStack customItem = new ItemStack(Material.BLACK_STAINED_GLASS_PANE);
ItemMeta meta = customItem.getItemMeta();
meta.setDisplayName(" ");
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
customItem.setItemMeta(meta);
BankSeparator = customItem;
}
return BankSeparator;
}
}

View File

@ -0,0 +1,349 @@
package me.TheTealViper.enderbank;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import me.TheTealViper.enderbank.utils.EnableShit;
import me.TheTealViper.enderbank.utils.VersionType;
import me.TheTealViper.enderbank.utils.ViperStringUtils;
import net.milkbowl.vault.economy.Economy;
public class EnderBank extends JavaPlugin implements Listener {
//general
public static EnderBank plugin;
public static VersionType version;
public static String notificationString = ChatColor.BOLD + "[" + ChatColor.AQUA + ChatColor.BOLD + "!" + ChatColor.WHITE + ChatColor.BOLD + "]" + ChatColor.RESET
, questionString = ChatColor.BOLD + "[" + ChatColor.AQUA + ChatColor.BOLD + "?" + ChatColor.WHITE + ChatColor.BOLD + "]" + ChatColor.RESET;
//Chat Queue (for asking which tracker you'd like to add)
public static Map<Player, List<String>> chatHandlerQueue = new HashMap<Player, List<String>>();
//plugin specific variables
public static ItemStack confirmBuy;
public static Map<Player, String> pendingResponseDatabase = new HashMap<Player, String>();
public static List<Material> equipmentTypes = new ArrayList<Material>();
private static Economy econ = null;
public void onEnable() {
// Do cleanup in case this is a reload
Bukkit.getServer().getScheduler().cancelTasks(this);
// Register this plugin
EnableShit.handleOnEnable(this, this, "-1");
plugin = this;
//Setup modules
BankStorage.setup(this);
CustomItemHandler.setup(this);
//Load values from config
saveDefaultConfig();
//Set initial values
ItemMeta meta = Bukkit.getItemFactory().getItemMeta(Material.STICK);
confirmBuy = new ItemStack(Material.YELLOW_STAINED_GLASS_PANE);
meta = Bukkit.getItemFactory().getItemMeta(Material.STICK);
meta.setDisplayName("Confirm Purchase");
List<String> lore = new ArrayList<String>();
lore.add(ChatColor.RESET + "" + ChatColor.ITALIC + "Click again to confirm purchase!");
meta.setLore(lore);
confirmBuy.setItemMeta(meta);
equipmentTypes.add(Material.CHAINMAIL_BOOTS);
equipmentTypes.add(Material.CHAINMAIL_CHESTPLATE);
equipmentTypes.add(Material.CHAINMAIL_HELMET);
equipmentTypes.add(Material.CHAINMAIL_LEGGINGS);
equipmentTypes.add(Material.LEATHER_BOOTS);
equipmentTypes.add(Material.LEATHER_CHESTPLATE);
equipmentTypes.add(Material.LEATHER_HELMET);
equipmentTypes.add(Material.LEATHER_LEGGINGS);
equipmentTypes.add(Material.IRON_BOOTS);
equipmentTypes.add(Material.IRON_CHESTPLATE);
equipmentTypes.add(Material.IRON_HELMET);
equipmentTypes.add(Material.IRON_LEGGINGS);
equipmentTypes.add(Material.GOLDEN_BOOTS);
equipmentTypes.add(Material.GOLDEN_CHESTPLATE);
equipmentTypes.add(Material.GOLDEN_HELMET);
equipmentTypes.add(Material.GOLDEN_LEGGINGS);
equipmentTypes.add(Material.DIAMOND_BOOTS);
equipmentTypes.add(Material.DIAMOND_CHESTPLATE);
equipmentTypes.add(Material.DIAMOND_HELMET);
equipmentTypes.add(Material.DIAMOND_LEGGINGS);
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
if (rsp != null)
econ = rsp.getProvider();
}
public void onDisable() {
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
if(sender instanceof Player){
Player p = (Player) sender;
boolean explain = false;
boolean warnmissingperms = false;
if(args.length == 0) {
if(p.hasPermission("enderbank.staff")) {
explain = true;
}else {
warnmissingperms = true;
}
} else if(args.length == 1){
if(p.hasPermission("enderbank.staff")){
explain = true;
}else
warnmissingperms = true;
}else if(args.length == 2){
if(args[0].equalsIgnoreCase("open")){
if(p.hasPermission("enderbank.staff")) {
String oPlayerName = args[1];
@SuppressWarnings("deprecation")
OfflinePlayer oPlayerOffline = Bukkit.getOfflinePlayer(oPlayerName);
if(oPlayerOffline.isOnline()) {
Player oPlayer = oPlayerOffline.getPlayer();
BankStorage bank = BankStorage.getBank(oPlayer);
bank.openPage(1, p);
}else {
p.sendMessage("That player is not online.");
}
}else {
warnmissingperms = true;
}
}else
explain = true;
}else if(args.length > 2) {
if(p.hasPermission("enderbank.staff")) {
explain = true;
}else {
warnmissingperms = true;
}
}
if(warnmissingperms) {
p.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "You are missing permissions!");
}
if(!warnmissingperms && explain){
p.sendMessage("EnderBank Commands");
p.sendMessage("/enderbank open <name>" + ChatColor.GRAY + " - Opens online player's inventory.");
}
}else{
//Not a player
sender.sendMessage("Commands can only be typed by in game players for this plugin!");
}
return true;
}
public void log(String s) {
getServer().getConsoleSender().sendMessage(ViperStringUtils.makeColors(s));
}
@SuppressWarnings("deprecation")
@EventHandler
public void onInventoryClick(InventoryClickEvent e) {
Player opener = (Player) e.getWhoClicked();
if(!BankStorage.openBankDatabase.containsKey(opener))
return;
BankStorage bank = BankStorage.openBankDatabase.get(opener);
if(e.getView().getTitle().equals("Bank Search") && e.getClickedInventory() != null && e.getClickedInventory().equals(e.getView().getTopInventory())) {
if(e.getSlot() >= bank.itemIdentifiers.size()) {
e.setCancelled(true);
}
}else if(e.getSlot() != -1 && e.getClickedInventory() != null && e.getView().getTitle().contains("'s Bank [Pg. ")) {
if(e.getSlot() == 7 || e.getSlot() == 16 || e.getSlot() == 25 || e.getSlot() == 26 || e.getSlot() == 34 || e.getSlot() == 43 || e.getSlot() == 52) {
e.setCancelled(true);
}else if(e.getSlot() == 8) { //next page
e.setCancelled(true);
if(pendingResponseDatabase.containsKey(opener) && pendingResponseDatabase.get(opener).equals("buypage")) { //If responding to confirm purchase
//Confirm if have the funds
if(econ.has(opener.getName(), BankStorage.getPageCost(bank.unlockedPages + 1))) {
econ.withdrawPlayer(opener.getName(), BankStorage.getPageCost(bank.unlockedPages + 1));
pendingResponseDatabase.remove(opener);
bank.unlockedPages = bank.pf.getInt("unlockedPages") + 1;
bank.savePage(bank.lastOpenedPage, e.getInventory());
bank.openPage(bank.lastOpenedPage + 1, opener);
}else {
opener.sendMessage(EnderBank.notificationString + " You don't have enough money!");
}
}else if(bank.lastOpenedPage == bank.unlockedPages) { //If clicking buy ask to confirm
e.getInventory().setItem(8, confirmBuy.clone());
pendingResponseDatabase.put(opener, "buypage");
}else{ //If clicking next page
pendingResponseDatabase.remove(opener);
bank.savePage(bank.lastOpenedPage, e.getInventory());
bank.openPage(bank.lastOpenedPage + 1, opener);
}
e.setCancelled(true);
}else if(e.getSlot() == 17) { //prev page
e.setCancelled(true);
if(bank.lastOpenedPage != 1) {
pendingResponseDatabase.remove(opener);
bank.savePage(bank.lastOpenedPage, e.getInventory());
bank.openPage(bank.lastOpenedPage - 1, opener);
}
}else if(e.getSlot() == 26) {
e.setCancelled(true);
}else if(e.getSlot() == 35) {
e.setCancelled(true);
bank.savePage(bank.lastOpenedPage, e.getInventory());
for(int j = 9;j < 13;j++) {
if(opener.getInventory().getItem(j) != null) {
//Check if rune filler
// boolean currentIsTome = false;
// if(!p.getInventory().getItem(j).getType().toString().equals("AIR")) {
// if(p.getInventory().getItem(j).hasItemMeta()) {
// if(p.getInventory().getItem(j).getItemMeta().hasDisplayName()) {
// if(p.getInventory().getItem(j).getItemMeta().getDisplayName().contains("Tome")) {
// currentIsTome = true;
// }else {
//
// }
// }else {
//
// }
// }else {
//
// }
// }
//
// if(currentIsTome) {
// bank.attemptToAddToBank(j);
// p.getInventory().setItem(j, CustomItemHandler.GetRelicFiller());
// }
}
}
for(int j = 36;j < 40;j++) {
if(opener.getInventory().getItem(j) != null) {
bank.attemptToAddToBank(j, opener);
}
}
bank.openPage(bank.lastOpenedPage, opener);
}else if(e.getSlot() == 44) { //Dump all items
e.setCancelled(true);
bank.savePage(bank.lastOpenedPage, e.getInventory());
if(e.getAction().equals(InventoryAction.PICKUP_ALL)) { //Encluding hotbar
for(int j = 9;j < 36;j++) {
if(opener.getInventory().getItem(j) != null) {
bank.attemptToAddToBank(j, opener);
}
}
}else if(e.getAction().equals(InventoryAction.PICKUP_HALF)) { //Including Hotbar
for(int j = 0;j < 9;j++) {
if(opener.getInventory().getItem(j) != null) {
bank.attemptToAddToBank(j, opener);
}
}
for(int j = 9;j < 36;j++) {
if(opener.getInventory().getItem(j) != null) {
bank.attemptToAddToBank(j, opener);
}
}
if(opener.getInventory().getItem(40) != null) {
bank.attemptToAddToBank(40, opener);
}
}
bank.openPage(bank.lastOpenedPage, opener);
}else if(e.getSlot() == 53) {
e.setCancelled(true);
BankStorage.searchDatabase.put(opener, bank);
opener.closeInventory();
if(!chatHandlerQueue.containsKey(opener))
chatHandlerQueue.put(opener, new ArrayList<String>());
List<String> queue = chatHandlerQueue.get(opener);
queue.add("banksearch");
chatHandlerQueue.put(opener, queue);
opener.sendMessage(EnderBank.questionString + " Please search in chat."
+ "\nType 'cancel' to cancel.");
}else{
e.setCancelled(false);
}
}
}
@EventHandler
public void onInventoryClose(InventoryCloseEvent e) {
Player opener = (Player) e.getPlayer();
if(!BankStorage.openBankDatabase.containsKey(opener))
return;
BankStorage bank = BankStorage.openBankDatabase.get(opener);
if(e.getView().getTitle().equals("Bank Search")) {
Inventory inv = e.getInventory();
for(int i = 0;i < inv.getSize();i++) {
if(i <= bank.itemIdentifiers.size() - 1) {
//Update item in bank
bank.items.set(bank.itemIdentifiers.get(i), inv.getItem(i));
}
}
}else if(bank.lastOpenedInventory != null && e.getInventory().equals(bank.lastOpenedInventory)) {
int page = bank.lastOpenedPage;
bank.savePage(page, e.getInventory());
}
if(pendingResponseDatabase.containsKey(opener))
pendingResponseDatabase.remove(opener);
}
@EventHandler
public void onInventoryOpen(InventoryOpenEvent e) {
if(e.getInventory().getType().equals(InventoryType.ENDER_CHEST)) {
e.setCancelled(true);
Player p = (Player) e.getPlayer();
BankStorage bank = BankStorage.getBank(p);
bank.openPage(1, p);
}
}
@EventHandler
public void onChat(AsyncPlayerChatEvent e) {
Player p = e.getPlayer();
if(!chatHandlerQueue.containsKey(p))
return;
List<String> queue = chatHandlerQueue.get(p);
if(queue.size() == 0)
return;
String handler = queue.get(queue.size() - 1);
if(e.getMessage().equalsIgnoreCase("cancel")) {
queue.remove(queue.size() - 1);
e.setCancelled(true);
p.sendMessage(EnderBank.notificationString + " Cancelled successfully.");
return;
}
if(handler.equals("banksearch")) {
queue.remove(queue.size() - 1);
e.setCancelled(true);
String search = e.getMessage();
BankStorage bank = BankStorage.searchDatabase.get(p);
bank.openSearch(search, p);
BankStorage.searchDatabase.remove(p);
}
}
}

View File

@ -0,0 +1,54 @@
package me.TheTealViper.enderbank.utils;
import java.lang.reflect.Field;
import java.util.UUID;
import org.bukkit.craftbukkit.libs.org.apache.commons.codec.binary.Base64;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
public class Base64Skull {
// public static ItemStack getSkull(String base64) {
// ItemStack item = new ItemStack(Material.PLAYER_HEAD);
// SkullMeta meta = (SkullMeta) item.getItemMeta();
//
// GameProfile profile = new GameProfile(UUID.randomUUID(), "");
// profile.getProperties().put("textures", new Property("textures", base64));
// Field profileField = null;
// try {
// profileField = meta.getClass().getDeclaredField("profile");
// profileField.setAccessible(true);
// profileField.set(meta, profile);
// } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
// e.printStackTrace();
// }
//
// item.setItemMeta(meta);
// return item;
// }
public static ItemStack getSkull(ItemStack head, String uuid, String url) {
if(url == null)return head;
if(url.isEmpty())return head;
SkullMeta headMeta = (SkullMeta) head.getItemMeta();
GameProfile profile = new GameProfile(UUID.fromString(uuid), null);
byte[] encodedData = Base64.encodeBase64(String.format("{textures:{SKIN:{url:\"%s\"}}}", url).getBytes());
profile.getProperties().put("textures", new Property("textures", new String(encodedData)));
Field profileField = null;
try {
profileField = headMeta.getClass().getDeclaredField("profile");
profileField.setAccessible(true);
profileField.set(headMeta, profile);
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e1) {
e1.printStackTrace();
}
head.setItemMeta(headMeta);
return head;
}
}

View File

@ -0,0 +1,86 @@
package me.TheTealViper.enderbank.utils;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
public class EnableShit {
public static void handleOnEnable(JavaPlugin plugin, Listener pluginL, String spigotID){
plugin.saveDefaultConfig();
checkUpdates(plugin, spigotID);
Bukkit.getPluginManager().registerEvents(pluginL, plugin);
Bukkit.getPluginManager().registerEvents(new ItemCreator(), plugin);
//Bukkit.getLogger().info(plugin.getDescription().getName() + " from TheTealViper powered ON!");
}
static void checkUpdates(JavaPlugin plugin, String spigotID){
if(!spigotID.equals("-1"))
updatePlugin(plugin, spigotID);
updateConfig(plugin);
}
static void updatePlugin(JavaPlugin plugin, String spigotID){
String installed = plugin.getDescription().getVersion();
String[] installed_Arr = installed.split("[.]");
String posted = getSpigotVersion(spigotID);
if(posted == null)
return;
String[] posted_Arr = posted.split("[.]");
for(int i = 0;i < posted_Arr.length;i++){
if(installed_Arr.length <= i || Integer.valueOf(installed_Arr[i]) < Integer.valueOf(posted_Arr[i])){
//Bukkit.getLogger().info(plugin.getDescription().getName() + " has an update ready [" + installed + " -> " + posted + "]!");
break;
}
}
}
static void updateConfig(JavaPlugin plugin){
YamlConfiguration compareTo = YamlConfiguration.loadConfiguration(new InputStreamReader(plugin.getResource("config.yml")));
boolean update = false;
if(!plugin.getConfig().contains("VERSION"))
update = true;
String oldVersion = plugin.getConfig().getString("VERSION");
String[] oldVersion_Arr = oldVersion.split("[.]");
String newVersion = compareTo.getString("VERSION");
String[] newVersion_Arr = newVersion.split("[.]");
for(int i = 0;i < newVersion_Arr.length;i++){
if(oldVersion_Arr.length <= i || Integer.valueOf(oldVersion_Arr[i]) < Integer.valueOf(newVersion_Arr[i])){
update = true;
break;
}
}
if(update){
File file = new File("plugins/" + plugin.getDescription().getName() + "/config.yml");
try {
com.google.common.io.Files.copy(file, new File("plugins/" + plugin.getDescription().getName() + "/configBACKUP_" + oldVersion + ".yml"));
} catch (IOException e) {
e.printStackTrace();
}
if(file.exists())
file.delete();
plugin.saveDefaultConfig();
//Bukkit.getLogger().info(plugin.getDescription().getName() + " config.yml has been updated [" + oldVersion + " -> " + newVersion + "] and a backup created of old configuration!");
}
}
static String getSpigotVersion(String spigotID) {
try {
HttpURLConnection con = (HttpURLConnection) new URL("http://www.spigotmc.org/api/general.php").openConnection();
con.setDoOutput(true);
con.setRequestMethod("POST");
con.getOutputStream().write(
("key=98BE0FE67F88AB82B4C197FAF1DC3B69206EFDCC4D3B80FC83A00037510B99B4&resource=" + spigotID).getBytes("UTF-8"));
String version = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine();
return version;
} catch (Exception ex) {
}
return null;
}
}

View File

@ -0,0 +1,261 @@
package me.TheTealViper.enderbank.utils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.material.MaterialData;
@SuppressWarnings("deprecation")
public class ItemCreator implements Listener{
private static List<Material> durMats = new ArrayList<Material>();
public static Map<ItemStack, Integer> damageInfo = new HashMap<ItemStack, Integer>();
public static Map<ItemStack, Integer> forceStackInfo = new HashMap<ItemStack, Integer>();
public static ItemStack createItemFromConfiguration(String foodName, ConfigurationSection sec){
if(durMats.isEmpty())
loadDurMats();
ItemStack item = null;
if(sec == null || !sec.contains("id"))
return null;
if(sec.getString("id").startsWith("DIAMOND_SWORD:")) {
item = new ItemStack(Material.DIAMOND_SWORD);
item.setDurability(Short.valueOf(sec.getString("id").replace("DIAMOND_SWORD:", "")));
}else {
item = new ItemStack(Material.getMaterial(sec.getString("id")));
}
List<String> tags = sec.contains("tags") ? sec.getStringList("tags") : new ArrayList<String>();
if(sec.contains("amount"))
item.setAmount(sec.getInt("amount"));
ItemMeta meta = Bukkit.getItemFactory().getItemMeta(Material.STICK);
if(sec.contains("name") && !sec.getString("name").equals("")){
meta.setDisplayName(ViperStringUtils.makeColors(sec.getString("name")));
item.setItemMeta(meta);
}
List<String> enchantmentStrings = sec.contains("enchantments") ? sec.getStringList("enchantments") : new ArrayList<String>();
for(String enchantmentString : enchantmentStrings){
String enchantment = enchantmentString.split(":")[0];
int level = Integer.valueOf(enchantmentString.split(":")[1]);
if(enchantment.equalsIgnoreCase("arrowdamage")){
item.addEnchantment(Enchantment.ARROW_DAMAGE, level);
}else if(enchantment.equalsIgnoreCase("arrowfire")){
item.addUnsafeEnchantment(Enchantment.ARROW_FIRE, level);
}else if(enchantment.equalsIgnoreCase("arrowinfinite")){
item.addUnsafeEnchantment(Enchantment.ARROW_INFINITE, level);
}else if(enchantment.equalsIgnoreCase("arrowknockback")){
item.addUnsafeEnchantment(Enchantment.ARROW_KNOCKBACK, level);
}else if(enchantment.equalsIgnoreCase("damage")){
item.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, level);
}else if(enchantment.equalsIgnoreCase("digspeed")){
item.addUnsafeEnchantment(Enchantment.DIG_SPEED, level);
}else if(enchantment.equalsIgnoreCase("durability")){
item.addUnsafeEnchantment(Enchantment.DURABILITY, level);
}else if(enchantment.equalsIgnoreCase("fireaspect")){
item.addUnsafeEnchantment(Enchantment.FIRE_ASPECT, level);
}else if(enchantment.equalsIgnoreCase("knockback")){
item.addUnsafeEnchantment(Enchantment.KNOCKBACK, level);
}else if(enchantment.equalsIgnoreCase("lootbonusblock")){
item.addUnsafeEnchantment(Enchantment.LOOT_BONUS_BLOCKS, level);
}else if(enchantment.equalsIgnoreCase("lootbonusmob")){
item.addUnsafeEnchantment(Enchantment.LOOT_BONUS_MOBS, level);
}else if(enchantment.equalsIgnoreCase("luck")){
item.addUnsafeEnchantment(Enchantment.LUCK, level);
}else if(enchantment.equalsIgnoreCase("protectionfall")){
item.addUnsafeEnchantment(Enchantment.PROTECTION_FALL, level);
}else if(enchantment.equalsIgnoreCase("protectionfire")){
item.addUnsafeEnchantment(Enchantment.PROTECTION_FALL, level);
}else if(enchantment.equalsIgnoreCase("silktouch")){
item.addUnsafeEnchantment(Enchantment.SILK_TOUCH, level);
}
}
for(String s : tags){
if(s.startsWith("skullskin") && item.getType().equals(Material.PLAYER_HEAD)){
SkullMeta skull = (SkullMeta) item.getData();
skull.setOwner(s.replace("skullskin:", ""));
item.setData((MaterialData) skull);
}else if(s.startsWith("durability") && durMats.contains(item.getType())){
item.getData().setData(Byte.valueOf(s.replace("durability:", "")));
item.setDurability(Short.valueOf(s.replace("durability:", "")));
}else if(s.equalsIgnoreCase("unbreakable")){
meta = item.getItemMeta();
meta.setUnbreakable(true);
item.setItemMeta(meta);
}
}
for(String s : tags) {
if(s.startsWith("skulltexture") && item.getType().equals(Material.PLAYER_HEAD)){
item = Base64Skull.getSkull(item, s.replace("skulltexture:", "").split(";")[1], "http://textures.minecraft.net/texture/" + s.replace("skulltexture:", "").split(";")[0]);
}
}
List<String> lore = sec.contains("lore") ? sec.getStringList("lore") : new ArrayList<String>();
if(!lore.isEmpty()){
for(int i = 0;i < lore.size();i++){
lore.set(i, ViperStringUtils.makeColors(lore.get(i)));
}
meta = item.getItemMeta();
meta.setLore(lore);
item.setItemMeta(meta);
}
if(sec.contains("flags")){
meta = item.getItemMeta();
for(String s : sec.getStringList("flags")){
meta.addItemFlags(ItemFlag.valueOf(s));
}
item.setItemMeta(meta);
}
for(String s : tags){//Item modification is complete by now
if(s.startsWith("damage")){
damageInfo.put(item.clone(), Integer.valueOf(s.replace("damage:", "")));
}else if(s.startsWith("forcestack")){
forceStackInfo.put(item.clone(), Integer.valueOf(s.replace("forcestack:", "")));
}
}
return item;
}
@EventHandler
public void onDamage(EntityDamageByEntityEvent e){
if(e.getDamager() instanceof Player){
Player p = (Player) e.getDamager();
ItemStack item = p.getItemInHand();
if(p.getItemInHand() != null && !p.getItemInHand().getType().equals(Material.AIR)){
for(ItemStack i : damageInfo.keySet()){
if(item.isSimilar(i)){
e.setDamage(damageInfo.get(i));
return;
}
}
}
}
}
@EventHandler(ignoreCancelled = false)
public void onPickup(PlayerPickupItemEvent e){
Player p = e.getPlayer();
ItemStack forceStack = null;
for(ItemStack i : forceStackInfo.keySet()){
if(e.getItem().getItemStack().isSimilar(i)){
forceStack = e.getItem().getItemStack();
}
}
if(forceStack != null){
e.setCancelled(true);
e.getItem().remove();
giveCustomItem(p, forceStack);
}
}
public static void giveCustomItem(Player p, ItemStack item){
int amount = item.getAmount();//Start at the item's amount because they're picking it up
for(int i = 0;i < 36;i++){
if(p.getInventory().getItem(i) != null && p.getInventory().getItem(i).isSimilar(item)){
amount += p.getInventory().getItem(i).getAmount();
p.getInventory().getItem(i).setAmount(0);
}
}
int stackSize = forceStackInfo.get(item);
while(amount > 0){
if(amount >= stackSize){
ItemStack temp = item.clone();
temp.setAmount(stackSize);
p.getInventory().setItem(p.getInventory().firstEmpty(), temp);
amount -= stackSize;
}else{
ItemStack temp = item.clone();
temp.setAmount(amount);
p.getInventory().setItem(p.getInventory().firstEmpty(), temp);
amount = 0;
}
}
}
private static void loadDurMats(){
durMats.add(Material.DIAMOND_SHOVEL);durMats.add(Material.GOLDEN_SHOVEL);durMats.add(Material.IRON_SHOVEL);
durMats.add(Material.STONE_SHOVEL);durMats.add(Material.WOODEN_SHOVEL);
durMats.add(Material.DIAMOND_PICKAXE);durMats.add(Material.GOLDEN_PICKAXE);durMats.add(Material.IRON_PICKAXE);
durMats.add(Material.STONE_PICKAXE);durMats.add(Material.WOODEN_PICKAXE);
durMats.add(Material.DIAMOND_AXE);durMats.add(Material.GOLDEN_AXE);durMats.add(Material.IRON_AXE);
durMats.add(Material.STONE_AXE);durMats.add(Material.WOODEN_AXE);
durMats.add(Material.DIAMOND_HOE);durMats.add(Material.GOLDEN_HOE);durMats.add(Material.IRON_HOE);
durMats.add(Material.STONE_HOE);durMats.add(Material.WOODEN_HOE);
durMats.add(Material.DIAMOND_SWORD);durMats.add(Material.GOLDEN_SWORD);durMats.add(Material.IRON_SWORD);
durMats.add(Material.STONE_SWORD);durMats.add(Material.WOODEN_SWORD);
durMats.add(Material.CHAINMAIL_HELMET);durMats.add(Material.DIAMOND_HELMET);durMats.add(Material.GOLDEN_HELMET);
durMats.add(Material.IRON_HELMET);durMats.add(Material.LEATHER_HELMET);
durMats.add(Material.CHAINMAIL_CHESTPLATE);durMats.add(Material.DIAMOND_CHESTPLATE);durMats.add(Material.GOLDEN_CHESTPLATE);
durMats.add(Material.IRON_CHESTPLATE);durMats.add(Material.LEATHER_CHESTPLATE);
durMats.add(Material.CHAINMAIL_LEGGINGS);durMats.add(Material.DIAMOND_LEGGINGS);durMats.add(Material.LEATHER_LEGGINGS);
durMats.add(Material.IRON_LEGGINGS);durMats.add(Material.GOLDEN_LEGGINGS);
durMats.add(Material.CHAINMAIL_BOOTS);durMats.add(Material.DIAMOND_BOOTS);durMats.add(Material.GOLDEN_BOOTS);
durMats.add(Material.IRON_BOOTS);durMats.add(Material.LEATHER_BOOTS);
durMats.add(Material.BOW);
}
public static boolean isSimilar(ItemStack item1, ItemStack item2) {
if (item2.getType() == item1.getType() && item2.getDurability() == item1.getDurability()) {
ItemMeta item1Meta = item1.getItemMeta();
ItemMeta item2Meta = item2.getItemMeta();
if (item1Meta.hasDisplayName() != item2Meta.hasDisplayName()) {
return false;
}
if (item1Meta.hasDisplayName()) {
if (!item1Meta.getDisplayName().equals(item2Meta.getDisplayName())) {
return false;
}
}
if (item1Meta.hasLore() != item2Meta.hasLore()) {
return false;
}
if (item1Meta.hasLore()) {
if (item1Meta.getLore().size() != item2Meta.getLore().size()) {
return false;
}
for (int index = 0; index < item1Meta.getLore().size(); index++) {
if (item1Meta.getLore().get(index).equals(item2Meta.getLore().get(index))) {
return false;
}
}
}
if (item1Meta.hasEnchants() != item2Meta.hasEnchants()) {
return false;
}
if (item1Meta.hasEnchants()) {
if (item1Meta.getEnchants().size() != item2Meta.getEnchants().size()) {
return false;
}
for (Entry<Enchantment, Integer> enchantInfo : item1Meta.getEnchants().entrySet()) {
if (item1Meta.getEnchantLevel(enchantInfo.getKey()) != item2Meta.getEnchantLevel(enchantInfo.getKey())) {
return false;
}
}
}
if (item1Meta.getItemFlags().size() != item2Meta.getItemFlags().size()) {
return false;
}
for (ItemFlag flag : item1Meta.getItemFlags()) {
if (!item2Meta.hasItemFlag(flag)) {
return false;
}
}
return true;
}
return false;
}
}

View File

@ -0,0 +1,100 @@
package me.TheTealViper.enderbank.utils;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
public class PluginFile extends YamlConfiguration {
private File file;
private String defaults;
private JavaPlugin plugin;
/**
* Creates new PluginFile, without defaults
* @param plugin - Your plugin
* @param fileName - Name of the file
*/
public PluginFile(JavaPlugin plugin, String fileName) {
this(plugin, fileName, null);
}
/**
* Creates new PluginFile, with defaults
* @param plugin - Your plugin
* @param fileName - Name of the file
* @param defaultsName - Name of the defaults
*/
public PluginFile(JavaPlugin plugin, String fileName, String defaultsName) {
this.plugin = plugin;
this.defaults = defaultsName;
this.file = new File(plugin.getDataFolder(), fileName);
reload();
}
/**
* Reload configuration
*/
public void reload() {
if (!file.exists()) {
try {
file.getParentFile().mkdirs();
file.createNewFile();
} catch (IOException exception) {
exception.printStackTrace();
//plugin.getLogger().severe("Error while creating file " + file.getName());
}
}
try {
load(file);
if (defaults != null) {
InputStreamReader reader = new InputStreamReader(plugin.getResource(defaults));
FileConfiguration defaultsConfig = YamlConfiguration.loadConfiguration(reader);
setDefaults(defaultsConfig);
options().copyDefaults(true);
reader.close();
save();
}
} catch (IOException exception) {
exception.printStackTrace();
//plugin.getLogger().severe("Error while loading file " + file.getName());
} catch (InvalidConfigurationException exception) {
exception.printStackTrace();
//plugin.getLogger().severe("Error while loading file " + file.getName());
}
}
/**
* Save configuration
*/
public void save() {
try {
options().indent(2);
save(file);
} catch (IOException exception) {
exception.printStackTrace();
//plugin.getLogger().severe("Error while saving file " + file.getName());
}
}
}

View File

@ -0,0 +1,99 @@
package me.TheTealViper.enderbank.utils;
import java.util.ArrayList;
import org.bukkit.util.BoundingBox;
import org.bukkit.util.Vector;
public class RayTrace {
//origin = start position
//direction = direction in which the raytrace will go
Vector origin, direction;
public RayTrace(Vector origin, Vector direction) {
this.origin = origin;
this.direction = direction;
}
//get a point on the raytrace at X blocks away
public Vector getPostion(double blocksAway) {
return origin.clone().add(direction.clone().multiply(blocksAway));
}
//checks if a position is on contained within the position
public boolean isOnLine(Vector position) {
double t = (position.getX() - origin.getX()) / direction.getX();
;
if (position.getBlockY() == origin.getY() + (t * direction.getY()) && position.getBlockZ() == origin.getZ() + (t * direction.getZ())) {
return true;
}
return false;
}
//get all postions on a raytrace
public ArrayList<Vector> traverse(double blocksAway, double accuracy) {
ArrayList<Vector> positions = new ArrayList<>();
for (double d = 0; d <= blocksAway; d += accuracy) {
positions.add(getPostion(d));
}
return positions;
}
//intersection detection for current raytrace with return
public Vector positionOfIntersection(Vector min, Vector max, double blocksAway, double accuracy) {
ArrayList<Vector> positions = traverse(blocksAway, accuracy);
for (Vector position : positions) {
if (intersects(position, min, max)) {
return position;
}
}
return null;
}
//intersection detection for current raytrace
public boolean intersects(Vector min, Vector max, double blocksAway, double accuracy) {
ArrayList<Vector> positions = traverse(blocksAway, accuracy);
for (Vector position : positions) {
if (intersects(position, min, max)) {
return true;
}
}
return false;
}
//bounding box instead of vector
public Vector positionOfIntersection(BoundingBox boundingBox, double blocksAway, double accuracy) {
ArrayList<Vector> positions = traverse(blocksAway, accuracy);
for (Vector position : positions) {
if (intersects(position, boundingBox.getMin(), boundingBox.getMax())) {
return position;
}
}
return null;
}
//bounding box instead of vector
public boolean intersects(BoundingBox boundingBox, double blocksAway, double accuracy) {
ArrayList<Vector> positions = traverse(blocksAway, accuracy);
for (Vector position : positions) {
if (intersects(position, boundingBox.getMin(), boundingBox.getMax())) {
return true;
}
}
return false;
}
//general intersection detection
public static boolean intersects(Vector position, Vector min, Vector max) {
if (position.getX() < min.getX() || position.getX() > max.getX()) {
return false;
} else if (position.getY() < min.getY() || position.getY() > max.getY()) {
return false;
} else if (position.getZ() < min.getZ() || position.getZ() > max.getZ()) {
return false;
}
return true;
}
}

View File

@ -0,0 +1,229 @@
package me.TheTealViper.enderbank.utils;
/**
* Version independent spigot sounds.
*
* Enum mapping to sound names for different
* minecraft versions.
*/
public enum Sound {
AMBIENCE_CAVE("AMBIENCE_CAVE", "AMBIENT_CAVE"),
AMBIENCE_RAIN("AMBIENCE_RAIN", "WEATHER_RAIN"),
AMBIENCE_THUNDER("AMBIENCE_THUNDER", "ENTITY_LIGHTNING_THUNDER", "ENTITY_LIGHTNING_BOLT_THUNDER"),
ANVIL_BREAK("ANVIL_BREAK", "BLOCK_ANVIL_BREAK"),
ANVIL_LAND("ANVIL_LAND", "BLOCK_ANVIL_LAND"),
ANVIL_USE("ANVIL_USE", "BLOCK_ANVIL_USE"),
ARROW_HIT("ARROW_HIT", "ENTITY_ARROW_HIT"),
BURP("BURP", "ENTITY_PLAYER_BURP"),
CHEST_CLOSE("CHEST_CLOSE", "ENTITY_CHEST_CLOSE", "BLOCK_CHEST_CLOSE"),
CHEST_OPEN("CHEST_OPEN", "ENTITY_CHEST_OPEN", "BLOCK_CHEST_OPEN"),
CLICK("CLICK", "UI_BUTTON_CLICK"),
DOOR_CLOSE("DOOR_CLOSE", "BLOCK_WOODEN_DOOR_CLOSE"),
DOOR_OPEN("DOOR_OPEN", "BLOCK_WOODEN_DOOR_OPEN"),
DRINK("DRINK", "ENTITY_GENERIC_DRINK"),
EAT("EAT", "ENTITY_GENERIC_EAT"),
EXPLODE("EXPLODE", "ENTITY_GENERIC_EXPLODE"),
FALL_BIG("FALL_BIG", "ENTITY_GENERIC_BIG_FALL"),
FALL_SMALL("FALL_SMALL", "ENTITY_GENERIC_SMALL_FALL"),
FIRE("FIRE", "BLOCK_FIRE_AMBIENT"),
FIRE_IGNITE("FIRE_IGNITE", "ITEM_FLINTANDSTEEL_USE"),
FIZZ("FIZZ", "BLOCK_FIRE_EXTINGUISH"),
FUSE("FUSE", "ENTITY_TNT_PRIMED"),
GLASS("GLASS", "BLOCK_GLASS_BREAK"),
HURT_FLESH("HURT_FLESH", "ENTITY_PLAYER_HURT"),
ITEM_BREAK("ITEM_BREAK", "ENTITY_ITEM_BREAK"),
ITEM_PICKUP("ITEM_PICKUP", "ENTITY_ITEM_PICKUP"),
LAVA("LAVA", "BLOCK_LAVA_AMBIENT"),
LAVA_POP("LAVA_POP", "BLOCK_LAVA_POP"),
LEVEL_UP("LEVEL_UP", "ENTITY_PLAYER_LEVELUP"),
MINECART_BASE("MINECART_BASE", "ENTITY_MINECART_RIDING"),
MINECART_INSIDE("MINECART_INSIDE", "ENTITY_MINECART_RIDING"),
NOTE_BASS("NOTE_BASS", "BLOCK_NOTE_BASS", "BLOCK_NOTE_BLOCK_BASS"),
NOTE_PIANO("NOTE_PIANO", "BLOCK_NOTE_HARP", "BLOCK_NOTE_BLOCK_HARP"),
NOTE_BASS_DRUM("NOTE_BASS_DRUM", "BLOCK_NOTE_BASEDRUM", "BLOCK_NOTE_BLOCK_BASEDRUM"),
NOTE_STICKS("NOTE_STICKS", "BLOCK_NOTE_HAT", "BLOCK_NOTE_BLOCK_HAT"),
NOTE_BASS_GUITAR("NOTE_BASS_GUITAR", "BLOCK_NOTE_GUITAR", "BLOCK_NOTE_BLOCK_GUITAR", "BLOCK_NOTE_BASS" /* 1.10 doesn't know guitar... */),
NOTE_SNARE_DRUM("NOTE_SNARE_DRUM", "BLOCK_NOTE_SNARE", "BLOCK_NOTE_BLOCK_SNARE"),
NOTE_PLING("NOTE_PLING", "BLOCK_NOTE_PLING", "BLOCK_NOTE_BLOCK_PLING"),
ORB_PICKUP("ORB_PICKUP", "ENTITY_EXPERIENCE_ORB_PICKUP"),
PISTON_EXTEND("PISTON_EXTEND", "BLOCK_PISTON_EXTEND"),
PISTON_RETRACT("PISTON_RETRACT", "BLOCK_PISTON_CONTRACT"),
PORTAL("PORTAL", "BLOCK_PORTAL_AMBIENT"),
PORTAL_TRAVEL("PORTAL_TRAVEL", "BLOCK_PORTAL_TRAVEL"),
PORTAL_TRIGGER("PORTAL_TRIGGER", "BLOCK_PORTAL_TRIGGER"),
SHOOT_ARROW("SHOOT_ARROW", "ENTITY_ARROW_SHOOT"),
SPLASH("SPLASH", "ENTITY_GENERIC_SPLASH"),
SPLASH2("SPLASH2", "ENTITY_BOBBER_SPLASH", "ENTITY_FISHING_BOBBER_SPLASH"),
STEP_GRASS("STEP_GRASS", "BLOCK_GRASS_STEP"),
STEP_GRAVEL("STEP_GRAVEL", "BLOCK_GRAVEL_STEP"),
STEP_LADDER("STEP_LADDER", "BLOCK_LADDER_STEP"),
STEP_SAND("STEP_SAND", "BLOCK_SAND_STEP"),
STEP_SNOW("STEP_SNOW", "BLOCK_SNOW_STEP"),
STEP_STONE("STEP_STONE", "BLOCK_STONE_STEP"),
STEP_WOOD("STEP_WOOD", "BLOCK_WOOD_STEP"),
STEP_WOOL("STEP_WOOL", "BLOCK_CLOTH_STEP", "BLOCK_WOOL_STEP"),
SWIM("SWIM", "ENTITY_GENERIC_SWIM"),
WATER("WATER", "BLOCK_WATER_AMBIENT"),
WOOD_CLICK("WOOD_CLICK", "BLOCK_WOOD_BUTTON_CLICK_ON", "BLOCK_WOODEN_BUTTON_CLICK_ON"),
BAT_DEATH("BAT_DEATH", "ENTITY_BAT_DEATH"),
BAT_HURT("BAT_HURT", "ENTITY_BAT_HURT"),
BAT_IDLE("BAT_IDLE", "ENTITY_BAT_AMBIENT"),
BAT_LOOP("BAT_LOOP", "ENTITY_BAT_LOOP"),
BAT_TAKEOFF("BAT_TAKEOFF", "ENTITY_BAT_TAKEOFF"),
BLAZE_BREATH("BLAZE_BREATH", "ENTITY_BLAZE_AMBIENT"),
BLAZE_DEATH("BLAZE_DEATH", "ENTITY_BLAZE_DEATH"),
BLAZE_HIT("BLAZE_HIT", "ENTITY_BLAZE_HURT"),
CAT_HISS("CAT_HISS", "ENTITY_CAT_HISS"),
CAT_HIT("CAT_HIT", "ENTITY_CAT_HURT"),
CAT_MEOW("CAT_MEOW", "ENTITY_CAT_AMBIENT"),
CAT_PURR("CAT_PURR", "ENTITY_CAT_PURR"),
CAT_PURREOW("CAT_PURREOW", "ENTITY_CAT_PURREOW"),
CHICKEN_IDLE("CHICKEN_IDLE", "ENTITY_CHICKEN_AMBIENT"),
CHICKEN_HURT("CHICKEN_HURT", "ENTITY_CHICKEN_HURT"),
CHICKEN_EGG_POP("CHICKEN_EGG_POP", "ENTITY_CHICKEN_EGG"),
CHICKEN_WALK("CHICKEN_WALK", "ENTITY_CHICKEN_STEP"),
COW_IDLE("COW_IDLE", "ENTITY_COW_AMBIENT"),
COW_HURT("COW_HURT", "ENTITY_COW_HURT"),
COW_WALK("COW_WALK", "ENTITY_COW_STEP"),
CREEPER_HISS("CREEPER_HISS", "ENTITY_CREEPER_PRIMED"),
CREEPER_DEATH("CREEPER_DEATH", "ENTITY_CREEPER_DEATH"),
ENDERDRAGON_DEATH("ENDERDRAGON_DEATH", "ENTITY_ENDERDRAGON_DEATH", "ENTITY_ENDER_DRAGON_DEATH"),
ENDERDRAGON_GROWL("ENDERDRAGON_GROWL", "ENTITY_ENDERDRAGON_GROWL", "ENTITY_ENDER_DRAGON_GROWL"),
ENDERDRAGON_HIT("ENDERDRAGON_HIT", "ENTITY_ENDERDRAGON_HURT", "ENTITY_ENDER_DRAGON_HURT"),
ENDERDRAGON_WINGS("ENDERDRAGON_WINGS", "ENTITY_ENDERDRAGON_FLAP", "ENTITY_ENDER_DRAGON_FLAP"),
ENDERMAN_DEATH("ENDERMAN_DEATH", "ENTITY_ENDERMEN_DEATH", "ENTITY_ENDERMAN_DEATH"),
ENDERMAN_HIT("ENDERMAN_HIT", "ENTITY_ENDERMEN_HURT", "ENTITY_ENDERMAN_HURT"),
ENDERMAN_IDLE("ENDERMAN_IDLE", "ENTITY_ENDERMEN_AMBIENT", "ENTITY_ENDERMAN_AMBIENT"),
ENDERMAN_TELEPORT("ENDERMAN_TELEPORT", "ENTITY_ENDERMEN_TELEPORT", "ENTITY_ENDERMAN_TELEPORT"),
ENDERMAN_SCREAM("ENDERMAN_SCREAM", "ENTITY_ENDERMEN_SCREAM", "ENTITY_ENDERMAN_SCREAM"),
ENDERMAN_STARE("ENDERMAN_STARE", "ENTITY_ENDERMEN_STARE", "ENTITY_ENDERMAN_STARE"),
GHAST_SCREAM("GHAST_SCREAM", "ENTITY_GHAST_SCREAM"),
GHAST_SCREAM2("GHAST_SCREAM2", "ENTITY_GHAST_HURT"),
GHAST_CHARGE("GHAST_CHARGE", "ENTITY_GHAST_WARN"),
GHAST_DEATH("GHAST_DEATH", "ENTITY_GHAST_DEATH"),
GHAST_FIREBALL("GHAST_FIREBALL", "ENTITY_GHAST_SHOOT"),
GHAST_MOAN("GHAST_MOAN", "ENTITY_GHAST_AMBIENT"),
IRONGOLEM_ATTACK("IRONGOLEM_THROW", "ENTITY_IRONGOLEM_ATTACK", "ENTITY_IRON_GOLEM_ATTACK"),
IRONGOLEM_DEATH("IRONGOLEM_DEATH", "ENTITY_IRONGOLEM_DEATH", "ENTITY_IRON_GOLEM_DEATH"),
IRONGOLEM_HIT("IRONGOLEM_HIT", "ENTITY_IRONGOLEM_HURT", "ENTITY_IRON_GOLEM_HURT"),
IRONGOLEM_WALK("IRONGOLEM_WALK", "ENTITY_IRONGOLEM_STEP", "ENTITY_IRON_GOLEM_STEP"),
MAGMACUBE_WALK("MAGMACUBE_WALK", "ENTITY_MAGMACUBE_SQUISH", "ENTITY_MAGMA_CUBE_SQUISH"),
MAGMACUBE_WALK2("MAGMACUBE_WALK2", "ENTITY_MAGMACUBE_SQUISH", "ENTITY_MAGMA_CUBE_SQUISH_SMALL"),
MAGMACUBE_JUMP("MAGMACUBE_JUMP", "ENTITY_MAGMACUBE_JUMP", "ENTITY_MAGMA_CUBE_JUMP"),
PIG_IDLE("PIG_IDLE", "ENTITY_PIG_AMBIENT"),
PIG_DEATH("PIG_DEATH", "ENTITY_PIG_DEATH"),
PIG_WALK("PIG_WALK", "ENTITY_PIG_STEP"),
SHEEP_IDLE("SHEEP_IDLE", "ENTITY_SHEEP_AMBIENT"),
SHEEP_SHEAR("SHEEP_SHEAR", "ENTITY_SHEEP_SHEAR"),
SHEEP_WALK("SHEEP_WALK", "ENTITY_SHEEP_STEP"),
SILVERFISH_HIT("SILVERFISH_HIT", "ENTITY_SILVERFISH_HURT"),
SILVERFISH_KILL("SILVERFISH_KILL", "ENTITY_SILVERFISH_DEATH"),
SILVERFISH_IDLE("SILVERFISH_IDLE", "ENTITY_SILVERFISH_AMBIENT"),
SILVERFISH_WALK("SILVERFISH_WALK", "ENTITY_SILVERFISH_STEP"),
SKELETON_IDLE("SKELETON_IDLE", "ENTITY_SKELETON_AMBIENT"),
SKELETON_DEATH("SKELETON_DEATH", "ENTITY_SKELETON_DEATH"),
SKELETON_HURT("SKELETON_HURT", "ENTITY_SKELETON_HURT"),
SKELETON_WALK("SKELETON_WALK", "ENTITY_SKELETON_STEP"),
SLIME_ATTACK("SLIME_ATTACK", "ENTITY_SLIME_ATTACK"),
SLIME_WALK("SLIME_WALK", "ENTITY_SLIME_JUMP"),
SLIME_WALK2("SLIME_WALK2", "ENTITY_SLIME_SQUISH"),
SPIDER_IDLE("SPIDER_IDLE", "ENTITY_SPIDER_AMBIENT"),
SPIDER_DEATH("SPIDER_DEATH", "ENTITY_SPIDER_DEATH"),
SPIDER_WALK("SPIDER_WALK", "ENTITY_SPIDER_STEP"),
WITHER_DEATH("WITHER_DEATH", "ENTITY_WITHER_DEATH"),
WITHER_HURT("WITHER_HURT", "ENTITY_WITHER_HURT"),
WITHER_IDLE("WITHER_IDLE", "ENTITY_WITHER_AMBIENT"),
WITHER_SHOOT("WITHER_SHOOT", "ENTITY_WITHER_SHOOT"),
WITHER_SPAWN("WITHER_SPAWN", "ENTITY_WITHER_SPAWN"),
WOLF_BARK("WOLF_BARK", "ENTITY_WOLF_AMBIENT"),
WOLF_DEATH("WOLF_DEATH", "ENTITY_WOLF_DEATH"),
WOLF_GROWL("WOLF_GROWL", "ENTITY_WOLF_GROWL"),
WOLF_HOWL("WOLF_HOWL", "ENTITY_WOLF_HOWL"),
WOLF_HURT("WOLF_HURT", "ENTITY_WOLF_HURT"),
WOLF_PANT("WOLF_PANT", "ENTITY_WOLF_PANT"),
WOLF_SHAKE("WOLF_SHAKE", "ENTITY_WOLF_SHAKE"),
WOLF_WALK("WOLF_WALK", "ENTITY_WOLF_STEP"),
WOLF_WHINE("WOLF_WHINE", "ENTITY_WOLF_WHINE"),
ZOMBIE_METAL("ZOMBIE_METAL", "ENTITY_ZOMBIE_ATTACK_IRON_DOOR"),
ZOMBIE_WOOD("ZOMBIE_WOOD", "ENTITY_ZOMBIE_ATTACK_DOOR_WOOD", "ENTITY_ZOMBIE_ATTACK_WOODEN_DOOR"),
ZOMBIE_WOODBREAK("ZOMBIE_WOODBREAK", "ENTITY_ZOMBIE_BREAK_DOOR_WOOD", "ENTITY_ZOMBIE_BREAK_WOODEN_DOOR"),
ZOMBIE_IDLE("ZOMBIE_IDLE", "ENTITY_ZOMBIE_AMBIENT"),
ZOMBIE_DEATH("ZOMBIE_DEATH", "ENTITY_ZOMBIE_DEATH"),
ZOMBIE_HURT("ZOMBIE_HURT", "ENTITY_ZOMBIE_HURT"),
ZOMBIE_INFECT("ZOMBIE_INFECT", "ENTITY_ZOMBIE_INFECT"),
ZOMBIE_UNFECT("ZOMBIE_UNFECT", "ENTITY_ZOMBIE_VILLAGER_CONVERTED"),
ZOMBIE_REMEDY("ZOMBIE_REMEDY", "ENTITY_ZOMBIE_VILLAGER_CURE"),
ZOMBIE_WALK("ZOMBIE_WALK", "ENTITY_ZOMBIE_STEP"),
ZOMBIE_PIG_IDLE("ZOMBIE_PIG_IDLE", "ENTITY_ZOMBIE_PIG_AMBIENT", "ENTITY_ZOMBIE_PIGMAN_AMBIENT"),
ZOMBIE_PIG_ANGRY("ZOMBIE_PIG_ANGRY", "ENTITY_ZOMBIE_PIG_ANGRY", "ENTITY_ZOMBIE_PIGMAN_ANGRY"),
ZOMBIE_PIG_DEATH("ZOMBIE_PIG_DEATH", "ENTITY_ZOMBIE_PIG_DEATH", "ENTITY_ZOMBIE_PIGMAN_DEATH"),
ZOMBIE_PIG_HURT("ZOMBIE_PIG_HURT", "ENTITY_ZOMBIE_PIG_HURT", "ENTITY_ZOMBIE_PIGMAN_HURT"),
DIG_WOOL("DIG_WOOL", "BLOCK_CLOTH_BREAK", "BLOCK_WOOL_BREAK"),
DIG_GRASS("DIG_GRASS", "BLOCK_GRASS_BREAK"),
DIG_GRAVEL("DIG_GRAVEL", "BLOCK_GRAVEL_BREAK"),
DIG_SAND("DIG_SAND", "BLOCK_SAND_BREAK"),
DIG_SNOW("DIG_SNOW", "BLOCK_SNOW_BREAK"),
DIG_STONE("DIG_STONE", "BLOCK_STONE_BREAK"),
DIG_WOOD("DIG_WOOD", "BLOCK_WOOD_BREAK"),
FIREWORK_BLAST("FIREWORK_BLAST", "ENTITY_FIREWORK_BLAST", "ENTITY_FIREWORK_ROCKET_BLAST"),
FIREWORK_BLAST2("FIREWORK_BLAST2", "ENTITY_FIREWORK_BLAST_FAR", "ENTITY_FIREWORK_ROCKET_BLAST_FAR"),
FIREWORK_LARGE_BLAST("FIREWORK_LARGE_BLAST", "ENTITY_FIREWORK_LARGE_BLAST", "ENTITY_FIREWORK_ROCKET_LARGE_BLAST"),
FIREWORK_LARGE_BLAST2("FIREWORK_LARGE_BLAST2", "ENTITY_FIREWORK_LARGE_BLAST_FAR", "ENTITY_FIREWORK_ROCKET_LARGE_BLAST_FAR"),
FIREWORK_LAUNCH("FIREWORK_LAUNCH", "ENTITY_FIREWORK_LAUNCH", "ENTITY_FIREWORK_ROCKET_LAUNCH"),
FIREWORK_TWINKLE("FIREWORK_TWINKLE", "ENTITY_FIREWORK_TWINKLE", "ENTITY_FIREWORK_ROCKET_TWINKLE"),
FIREWORK_TWINKLE2("FIREWORK_TWINKLE2", "ENTITY_FIREWORK_TWINKLE_FAR", "ENTITY_FIREWORK_ROCKET_TWINKLE_FAR"),
SUCCESSFUL_HIT("SUCCESSFUL_HIT", "ENTITY_PLAYER_ATTACK_STRONG"),
HORSE_ANGRY("HORSE_ANGRY", "ENTITY_HORSE_ANGRY"),
HORSE_ARMOR("HORSE_ARMOR", "ENTITY_HORSE_ARMOR"),
HORSE_BREATHE("HORSE_BREATHE", "ENTITY_HORSE_BREATHE"),
HORSE_DEATH("HORSE_DEATH", "ENTITY_HORSE_DEATH"),
HORSE_GALLOP("HORSE_GALLOP", "ENTITY_HORSE_GALLOP"),
HORSE_HIT("HORSE_HIT", "ENTITY_HORSE_HURT"),
HORSE_IDLE("HORSE_IDLE", "ENTITY_HORSE_AMBIENT"),
HORSE_JUMP("HORSE_JUMP", "ENTITY_HORSE_JUMP"),
HORSE_LAND("HORSE_LAND", "ENTITY_HORSE_LAND"),
HORSE_SADDLE("HORSE_SADDLE", "ENTITY_HORSE_SADDLE"),
HORSE_SOFT("HORSE_SOFT", "ENTITY_HORSE_STEP"),
HORSE_WOOD("HORSE_WOOD", "ENTITY_HORSE_STEP_WOOD"),
DONKEY_ANGRY("DONKEY_ANGRY", "ENTITY_DONKEY_ANGRY"),
DONKEY_DEATH("DONKEY_DEATH", "ENTITY_DONKEY_DEATH"),
DONKEY_HIT("DONKEY_HIT", "ENTITY_DONKEY_HURT"),
DONKEY_IDLE("DONKEY_IDLE", "ENTITY_DONKEY_AMBIENT"),
HORSE_SKELETON_DEATH("HORSE_SKELETON_DEATH", "ENTITY_SKELETON_HORSE_DEATH"),
HORSE_SKELETON_HIT("HORSE_SKELETON_HIT", "ENTITY_SKELETON_HORSE_HURT"),
HORSE_SKELETON_IDLE("HORSE_SKELETON_IDLE", "ENTITY_SKELETON_HORSE_AMBIENT"),
HORSE_ZOMBIE_DEATH("HORSE_ZOMBIE_DEATH", "ENTITY_ZOMBIE_HORSE_DEATH"),
HORSE_ZOMBIE_HIT("HORSE_ZOMBIE_HIT", "ENTITY_ZOMBIE_HORSE_HURT"),
HORSE_ZOMBIE_IDLE("HORSE_ZOMBIE_IDLE", "ENTITY_ZOMBIE_HORSE_AMBIENT"),
VILLAGER_DEATH("VILLAGER_DEATH", "ENTITY_VILLAGER_DEATH"),
VILLAGER_TRADE("VILLAGER_HAGGLE", "ENTITY_VILLAGER_TRADING", "ENTITY_VILLAGER_TRADE"),
VILLAGER_HIT("VILLAGER_HIT", "ENTITY_VILLAGER_HURT"),
VILLAGER_IDLE("VILLAGER_IDLE", "ENTITY_VILLAGER_AMBIENT"),
VILLAGER_NO("VILLAGER_NO", "ENTITY_VILLAGER_NO"),
VILLAGER_YES("VILLAGER_YES", "ENTITY_VILLAGER_YES");
private String[] versionDependentNames;
private org.bukkit.Sound cached = null;
Sound(String... versionDependentNames) {
this.versionDependentNames = versionDependentNames;
}
/**
* Get the bukkit sound for current server version
*
* Caches sound on first call
* @return corresponding {@link org.bukkit.Sound}
*/
public org.bukkit.Sound bukkitSound() {
if (cached != null) return cached;
for (String name : versionDependentNames) {
try {
return cached = org.bukkit.Sound.valueOf(name);
} catch (IllegalArgumentException ignore2) {
// try next
}
}
throw new IllegalArgumentException("Found no valid sound name for " + this.name());
}
}

View File

@ -0,0 +1,5 @@
package me.TheTealViper.enderbank.utils;
public enum VersionType {
v1_14_R1;
}

View File

@ -0,0 +1,214 @@
package me.TheTealViper.enderbank.utils;
import java.nio.charset.Charset;
import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
public class ViperStringUtils {
// String constants. TODO Change them to something unique to avoid conflict with other plugins!
private static final String SEQUENCE_HEADER = "" + ChatColor.RESET + ChatColor.UNDERLINE + ChatColor.RESET;
private static final String SEQUENCE_FOOTER = "" + ChatColor.RESET + ChatColor.ITALIC + ChatColor.RESET;
public static String convertToInvisibleString(String s) {
String hidden = "";
for (char c : s.toCharArray()) hidden += ChatColor.COLOR_CHAR+""+c;
return hidden;
}
public static String convertBack(String s){
//String converted = ChatColor.stripColor(s);
String converted = s.replaceAll("<EFBFBD>", "");
return converted;
}
public static String makeColors(String s){
String replaced = s
.replaceAll("&0", "" + ChatColor.BLACK)
.replaceAll("&1", "" + ChatColor.DARK_BLUE)
.replaceAll("&2", "" + ChatColor.DARK_GREEN)
.replaceAll("&3", "" + ChatColor.DARK_AQUA)
.replaceAll("&4", "" + ChatColor.DARK_RED)
.replaceAll("&5", "" + ChatColor.DARK_PURPLE)
.replaceAll("&6", "" + ChatColor.GOLD)
.replaceAll("&7", "" + ChatColor.GRAY)
.replaceAll("&8", "" + ChatColor.DARK_GRAY)
.replaceAll("&9", "" + ChatColor.BLUE)
.replaceAll("&a", "" + ChatColor.GREEN)
.replaceAll("&b", "" + ChatColor.AQUA)
.replaceAll("&c", "" + ChatColor.RED)
.replaceAll("&d", "" + ChatColor.LIGHT_PURPLE)
.replaceAll("&e", "" + ChatColor.YELLOW)
.replaceAll("&f", "" + ChatColor.WHITE)
.replaceAll("&r", "" + ChatColor.RESET)
.replaceAll("&l", "" + ChatColor.BOLD)
.replaceAll("&o", "" + ChatColor.ITALIC)
.replaceAll("&k", "" + ChatColor.MAGIC)
.replaceAll("&m", "" + ChatColor.STRIKETHROUGH)
.replaceAll("&n", "" + ChatColor.UNDERLINE)
.replaceAll("\\\\", " ");
return replaced;
}
public static String randomColor() {
Random random = new Random();
int i = 0;
while(i == 0 || i == 7 || i == 8 || i == 14)
i = random.nextInt(16);
String cdata = i + "";
if(i == 10)
cdata = "a";
else if(i == 11)
cdata = "b";
else if(i == 12)
cdata = "c";
else if(i == 13)
cdata = "d";
else if(i == 15)
cdata = "e";
String color = makeColors("&" + cdata);
return color;
}
public static String toLocString(Location loc, boolean detailed, boolean extended, String[] args){
String locString = loc.getWorld().getName() + "_";
if(detailed)
locString += loc.getX() + "_" + loc.getY() + "_" + loc.getZ();
else
locString += loc.getBlockX() + "_" + loc.getBlockY() + "_" + loc.getBlockZ();
if(extended){
if(detailed)
locString += "_" + loc.getYaw() + "_" + loc.getPitch();
else
locString += "_" + ((int) loc.getYaw()) + "_" + ((int) loc.getPitch());
}
if(args != null){
for(String s : args)
locString += "_" + s;
}
return locString;
}
public static Location fromLocString(String locString, boolean extended){
String[] s = locString.split("_");
if(!extended)
return new Location(Bukkit.getWorld(s[0]), Double.valueOf(s[1]), Double.valueOf(s[2]), Double.valueOf(s[3]));
else
return new Location(Bukkit.getWorld(s[0]), Double.valueOf(s[1]), Double.valueOf(s[2]), Double.valueOf(s[3]), Float.valueOf(s[4]), Float.valueOf(s[5]));
}
public static String encodeString(String hiddenString) {
return quote(stringToColors(hiddenString));
}
public static boolean hasHiddenString(String input) {
if (input == null) return false;
return input.indexOf(SEQUENCE_HEADER) > -1 && input.indexOf(SEQUENCE_FOOTER) > -1;
}
public static String extractHiddenString(String input) {
return colorsToString(extract(input));
}
public static String replaceHiddenString(String input, String hiddenString) {
if (input == null) return null;
int start = input.indexOf(SEQUENCE_HEADER);
int end = input.indexOf(SEQUENCE_FOOTER);
if (start < 0 || end < 0) {
return null;
}
return input.substring(0, start + SEQUENCE_HEADER.length()) + stringToColors(hiddenString) + input.substring(end, input.length());
}
/**
* Internal stuff.
*/
private static String quote(String input) {
if (input == null) return null;
return SEQUENCE_HEADER + input + SEQUENCE_FOOTER;
}
private static String extract(String input) {
if (input == null) return null;
int start = input.indexOf(SEQUENCE_HEADER);
int end = input.indexOf(SEQUENCE_FOOTER);
if (start < 0 || end < 0) {
return null;
}
return input.substring(start + SEQUENCE_HEADER.length(), end);
}
private static String stringToColors(String normal) {
if (normal == null) return null;
byte[] bytes = normal.getBytes(Charset.forName("UTF-8"));
char[] chars = new char[bytes.length * 4];
for (int i = 0; i < bytes.length; i++) {
char[] hex = byteToHex(bytes[i]);
chars[i * 4] = ChatColor.COLOR_CHAR;
chars[i * 4 + 1] = hex[0];
chars[i * 4 + 2] = ChatColor.COLOR_CHAR;
chars[i * 4 + 3] = hex[1];
}
return new String(chars);
}
private static String colorsToString(String colors) {
if (colors == null) return null;
colors = colors.toLowerCase().replace("" + ChatColor.COLOR_CHAR, "");
if (colors.length() % 2 != 0) {
colors = colors.substring(0, (colors.length() / 2) * 2);
}
char[] chars = colors.toCharArray();
byte[] bytes = new byte[chars.length / 2];
for (int i = 0; i < chars.length; i += 2) {
bytes[i / 2] = hexToByte(chars[i], chars[i + 1]);
}
return new String(bytes, Charset.forName("UTF-8"));
}
private static int hexToUnsignedInt(char c) {
if (c >= '0' && c <= '9') {
return c - 48;
} else if (c >= 'a' && c <= 'f') {
return c - 87;
} else {
throw new IllegalArgumentException("Invalid hex char: out of range");
}
}
private static char unsignedIntToHex(int i) {
if (i >= 0 && i <= 9) {
return (char) (i + 48);
} else if (i >= 10 && i <= 15) {
return (char) (i + 87);
} else {
throw new IllegalArgumentException("Invalid hex int: out of range");
}
}
private static byte hexToByte(char hex1, char hex0) {
return (byte) (((hexToUnsignedInt(hex1) << 4) | hexToUnsignedInt(hex0)) + Byte.MIN_VALUE);
}
private static char[] byteToHex(byte b) {
int unsignedByte = (int) b - Byte.MIN_VALUE;
return new char[]{unsignedIntToHex((unsignedByte >> 4) & 0xf), unsignedIntToHex(unsignedByte & 0xf)};
}
}

5
src/module-info.java Normal file
View File

@ -0,0 +1,5 @@
module Spigot_Trackers {
requires spigot;
requires HolographicDisplaysAPI;
requires Vault;
}