Added Brand New F Audit Base.

This commit is contained in:
Driftay
2019-12-24 22:19:49 -05:00
parent 5d1e1ea6ed
commit cda1610a58
46 changed files with 1452 additions and 46 deletions

View File

@@ -0,0 +1,95 @@
package com.massivecraft.factions.util;
/**
* @author Saser
*/
import org.bukkit.ChatColor;
public class CC {
public static String Black = ChatColor.BLACK.toString();
public static String BlackB = ChatColor.BLACK + ChatColor.BOLD.toString();
public static String BlackI = ChatColor.BLACK + ChatColor.ITALIC.toString();;
public static String BlackU = ChatColor.BLACK + ChatColor.UNDERLINE.toString();
public static String DarkBlue = ChatColor.DARK_BLUE.toString();
public static String DarkBlueB = ChatColor.DARK_BLUE + ChatColor.BOLD.toString();
public static String DarkBlueI = ChatColor.DARK_BLUE + ChatColor.ITALIC.toString();
public static String DarkBlueU = ChatColor.DARK_BLUE + ChatColor.UNDERLINE.toString();
public static String DarkGreen = ChatColor.DARK_GREEN.toString();
public static String DarkGreenB = ChatColor.DARK_GREEN + ChatColor.BOLD.toString();
public static String DarkGreenI = ChatColor.DARK_GREEN + ChatColor.ITALIC.toString();
public static String DarkGreenU = ChatColor.DARK_GREEN + ChatColor.UNDERLINE.toString();
public static String DarkAqua = ChatColor.DARK_AQUA.toString();
public static String DarkAquaB = ChatColor.DARK_AQUA + ChatColor.BOLD.toString();
public static String DarkAquaI = ChatColor.DARK_AQUA + ChatColor.ITALIC.toString();
public static String DarkAquaU = ChatColor.DARK_AQUA + ChatColor.UNDERLINE.toString();
public static String DarkRed = ChatColor.DARK_RED.toString();
public static String DarkRedB = ChatColor.DARK_RED + ChatColor.BOLD.toString();
public static String DarkRedI = ChatColor.DARK_RED + ChatColor.ITALIC.toString();
public static String DarkRedU = ChatColor.DARK_RED + ChatColor.UNDERLINE.toString();
public static String DarkPurple = ChatColor.DARK_PURPLE.toString();
public static String DarkPurpleB = ChatColor.DARK_PURPLE + ChatColor.BOLD.toString();
public static String DarkPurpleI = ChatColor.DARK_PURPLE + ChatColor.ITALIC.toString();
public static String DarkPurpleU = ChatColor.DARK_PURPLE + ChatColor.UNDERLINE.toString();
public static String Gold = ChatColor.GOLD.toString();
public static String GoldB = ChatColor.GOLD + ChatColor.BOLD.toString();
public static String GoldI = ChatColor.GOLD + ChatColor.ITALIC.toString();
public static String GoldU = ChatColor.GOLD + ChatColor.UNDERLINE.toString();
public static String Gray = ChatColor.GRAY.toString();
public static String GrayB = ChatColor.GRAY + ChatColor.BOLD.toString();
public static String GrayI = ChatColor.GRAY + ChatColor.ITALIC.toString();
public static String GrayU = ChatColor.GRAY + ChatColor.UNDERLINE.toString();
public static String DarkGray = ChatColor.DARK_GRAY.toString();
public static String DarkGrayB = ChatColor.DARK_GRAY + ChatColor.BOLD.toString();
public static String DarkGrayI = ChatColor.DARK_GRAY + ChatColor.ITALIC.toString();
public static String DarkGrayU = ChatColor.DARK_GRAY + ChatColor.UNDERLINE.toString();
public static String Blue = ChatColor.BLUE.toString();
public static String BlueB = ChatColor.BLUE + ChatColor.BOLD.toString();
public static String BlueI = ChatColor.BLUE + ChatColor.ITALIC.toString();
public static String BlueU = ChatColor.BLUE + ChatColor.UNDERLINE.toString();
public static String Green = ChatColor.GREEN.toString();
public static String GreenB = ChatColor.GREEN + ChatColor.BOLD.toString();
public static String GreenI = ChatColor.GREEN + ChatColor.ITALIC.toString();
public static String GreenU = ChatColor.GREEN + ChatColor.UNDERLINE.toString();
public static String Aqua = ChatColor.AQUA.toString();
public static String AquaB = ChatColor.AQUA + ChatColor.BOLD.toString();
public static String AquaI = ChatColor.AQUA + ChatColor.ITALIC.toString();
public static String AquaU = ChatColor.AQUA + ChatColor.UNDERLINE.toString();
public static String Red = ChatColor.RED.toString();
public static String RedB = ChatColor.RED + ChatColor.BOLD.toString();
public static String RedI = ChatColor.RED + ChatColor.ITALIC.toString();
public static String RedU = ChatColor.RED + ChatColor.UNDERLINE.toString();
public static String LightPurple = ChatColor.LIGHT_PURPLE.toString();
public static String LightPurpleB = ChatColor.LIGHT_PURPLE + ChatColor.BOLD.toString();
public static String LightPurpleI = ChatColor.LIGHT_PURPLE + ChatColor.ITALIC.toString();
public static String LightPurpleU = ChatColor.LIGHT_PURPLE + ChatColor.UNDERLINE.toString();
public static String Yellow = ChatColor.YELLOW.toString();
public static String YellowB = ChatColor.YELLOW + ChatColor.BOLD.toString();
public static String YellowI = ChatColor.YELLOW + ChatColor.ITALIC.toString();
public static String YellowU = ChatColor.YELLOW + ChatColor.UNDERLINE.toString();
public static String White = ChatColor.WHITE.toString();
public static String WhiteB = ChatColor.WHITE + ChatColor.BOLD.toString();
public static String WhiteI = ChatColor.WHITE + ChatColor.ITALIC.toString();
public static String WhiteU = ChatColor.WHITE + ChatColor.UNDERLINE.toString();
public static String Bold = ChatColor.BOLD.toString();
public static String Strike = ChatColor.STRIKETHROUGH.toString();
public static String Underline = ChatColor.UNDERLINE.toString();
public static String Magic = ChatColor.MAGIC.toString();
public static String Italic = ChatColor.ITALIC.toString();
public static String Reset = ChatColor.RESET.toString();
public static String Go = GreenB + "<!> " + Green;
public static String Wait = YellowB + "<!> " + Yellow;
public static String Stop = RedB + "<!> " + Red;
public static String prefix(char color) {
return translate("&" + color + "&l<!> &" + color);
}
public static String translate(String string) {
return ChatColor.translateAlternateColorCodes('&', string);
}
public static String strip(String string) {
return ChatColor.stripColor(string);
}
}

View File

@@ -116,17 +116,21 @@ public class ClipPlaceholderAPIManager extends PlaceholderExpansion implements R
case "faction_description":
return faction.getDescription();
case "faction_claims":
return String.valueOf(faction.getAllClaims().size());
return fPlayer.hasFaction() ? String.valueOf(faction.getAllClaims().size()) : "0";
case "faction_maxclaims":
return String.valueOf(Conf.claimedLandsMax);
case "faction_founded":
return TL.sdf.format(faction.getFoundedDate());
case "faction_joining":
return (faction.getOpen() ? TL.COMMAND_SHOW_UNINVITED.toString() : TL.COMMAND_SHOW_INVITATION.toString());
case "faction_strikes":
return fPlayer.hasFaction() ? String.valueOf(faction.getStrikes()) : "0";
case "faction_peaceful":
return faction.isPeaceful() ? Conf.colorNeutral + TL.COMMAND_SHOW_PEACEFUL.toString() : "";
case "faction_tntbank_balance":
return String.valueOf(faction.getTnt());
case "faction_points":
return String.valueOf(faction.getPoints());
return fPlayer.hasFaction() ? String.valueOf(faction.getPoints()) : "0";
case "faction_powerboost":
double powerBoost = faction.getPowerBoost();
return (powerBoost == 0.0) ? "" : (powerBoost > 0.0 ? TL.COMMAND_SHOW_BONUS.toString() : TL.COMMAND_SHOW_PENALTY.toString()) + powerBoost + ")";

View File

@@ -38,7 +38,11 @@ public class FactionWarpsFrame {
GUIItems.add(new GuiItem(buildDummyItem(), e -> e.setCancelled(true)));
slots.forEach(slot -> GUIItems.set(slot, new GuiItem(XMaterial.AIR.parseItem())));
for (final Map.Entry<String, LazyLocation> warp : fplayer.getFaction().getWarps().entrySet()) {
if (count > slots.size()) continue;
if (slots.size() < fplayer.getFaction().getWarps().entrySet().size()){
slots.add(slots.get(slots.size()-1)+1);
FactionsPlugin.instance.log("Automatically setting F WARP GUI slot since slot not specified. Head config.yml and add more entries in warp-slots section.");
}
GUIItems.set(slots.get(count), new GuiItem(buildWarpAsset(warp, fplayer.getFaction()), e -> {
e.setCancelled(true);
fplayer.getPlayer().closeInventory();

View File

@@ -0,0 +1,51 @@
package com.massivecraft.factions.util;
/**
* @author Saser
*/
import com.massivecraft.factions.util.XMaterial;
import org.bukkit.Material;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import java.util.HashMap;
import java.util.Map;
public class ItemUtil {
private static Map<String, ItemStack> cachedSkulls = new HashMap<>();
public ItemUtil() {
}
public static int getItemCount(Inventory inventory) {
if (inventory == null) {
return 0;
} else {
int itemsFound = 0;
for(int i = 0; i < inventory.getSize(); ++i) {
ItemStack item = inventory.getItem(i);
if (item != null && item.getType() != Material.AIR) {
++itemsFound;
}
}
return itemsFound;
}
}
public static ItemStack createPlayerHead(String name) {
ItemStack skull = cachedSkulls.get(name);
if (skull != null) {
return skull.clone();
} else {
skull = new ItemStack(XMaterial.PLAYER_HEAD.parseMaterial());
SkullMeta sm = (SkullMeta)skull.getItemMeta();
sm.setOwner(name);
skull.setItemMeta(sm);
cachedSkulls.put(name, skull.clone());
return skull;
}
}
}

View File

@@ -0,0 +1,101 @@
package com.massivecraft.factions.util;
/**
* @author Saser
*/
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.bukkit.Bukkit;
import java.io.*;
import java.lang.reflect.Type;
public class JSONUtils {
public static Gson gson = (new GsonBuilder()).enableComplexMapKeySerialization().create();
public JSONUtils() {
}
public static File getOrCreateFile(File parent, String string) throws IOException {
if (!parent.exists()) {
parent.mkdir();
Bukkit.getLogger().info("Creating directory " + parent.getName());
}
File f = new File(parent, string);
if (!f.exists()) {
Bukkit.getLogger().info("Creating new file " + string + " due to it not existing!");
f.createNewFile();
}
return f;
}
public static File getOrCreateFile(String fileName) throws IOException {
File f = new File(fileName);
if (!f.exists()) {
Bukkit.getLogger().info("Creating new file " + fileName + " due to it not existing!");
f.createNewFile();
}
return f;
}
public static Object fromJson(String fileName, Object token) throws IOException {
File f = getOrCreateFile(fileName);
return fromJson(f, token);
}
public static Object fromJson(File f, Object clazz) throws FileNotFoundException {
return gson.fromJson(new FileReader(f), getTypeFromObject(clazz));
}
public static Object fromJson(File f, Object clazz, Object defaultObj) throws FileNotFoundException {
Object retr = gson.fromJson(new FileReader(f), getTypeFromObject(clazz));
return retr == null ? defaultObj : retr;
}
public static Object fromJson(File f, Type token) throws FileNotFoundException {
return fromJson(f, token, gson);
}
public static Object fromJson(File f, Type token, Gson gson) throws FileNotFoundException {
return gson.fromJson(new FileReader(f), token);
}
public static String toJSON(Object object, Object token) {
return toJSON(object, token, gson);
}
public static String toJSON(Object object, Object token, Gson gson) {
return gson.toJson(object, getTypeFromObject(token));
}
public static boolean saveJSONToFile(String fileName, Object toSave, Object token) throws IOException {
return saveJSONToFile(getOrCreateFile(fileName), toSave, token);
}
public static boolean saveJSONToFile(File f, Object toSave, Object token, Gson gson) throws IOException {
String str = toJSON(toSave, token, gson);
FileWriter writer = new FileWriter(f);
writer.write(str);
writer.flush();
writer.close();
return true;
}
public static boolean saveJSONToFile(File f, Object toSave, Object token) throws IOException {
try {
return saveJSONToFile(f, toSave, token, gson);
} catch (Throwable var4) {
throw var4;
}
}
private static Type getTypeFromObject(Object object) {
return object instanceof Type ? (Type)object : getTypeFromClass(object.getClass());
}
private static Type getTypeFromClass(Class<?> clazz) {
return TypeToken.of(clazz).getType();
}
}

View File

@@ -0,0 +1,48 @@
package com.massivecraft.factions.util.serializable;
/**
* @author Saser
*/
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.List;
import java.util.function.Consumer;
public class ClickableItemStack extends ItemStack {
private Consumer<InventoryClickEvent> itemCallback;
public ClickableItemStack(ItemStack clone) {
super(clone);
}
public ClickableItemStack setClickCallback(Consumer<InventoryClickEvent> callback) {
this.itemCallback = callback;
return this;
}
public ClickableItemStack setDisplayName(String name) {
ItemMeta im = this.getItemMeta();
im.setDisplayName(name);
this.setItemMeta(im);
return this;
}
public ClickableItemStack setLore(List<String> lore) {
ItemMeta im = this.getItemMeta();
im.setLore(lore);
this.setItemMeta(im);
return this;
}
public ClickableItemStack setDura(short dura) {
this.setDurability(dura);
return this;
}
public Consumer<InventoryClickEvent> getItemCallback() {
return this.itemCallback;
}
}

View File

@@ -0,0 +1,156 @@
package com.massivecraft.factions.util.serializable;
/**
* @author Saser
*/
import com.google.common.collect.Lists;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Role;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.function.Consumer;
public abstract class GUIMenu {
protected Inventory menu;
private Map<Integer, ClickableItemStack> menuItems = new HashMap<>();
private static Map<UUID, GUIMenu> menus = new HashMap<>();
private Consumer<InventoryCloseEvent> closeCallback;
private String name;
private int size;
private GUIMenu previousMenu;
public GUIMenu(String name, int size) {
if (name.length() > 32) {
name = name.substring(0, 32);
}
this.name = name;
this.size = size;
this.menu = Bukkit.createInventory(null, size, name);
}
public void setInventorySize(int size) {
if (this.size != size) {
int oldSize = this.size;
this.size = size;
List<HumanEntity> viewing = Lists.newArrayList(this.menu.getViewers());
this.menu = Bukkit.createInventory(null, size, this.name);
viewing.forEach((pl) -> {
pl.closeInventory();
pl.openInventory(this.menu);
menus.put(pl.getUniqueId(), this);
Bukkit.getLogger().info("Reopening Menu for " + pl.getName() + " due to menu changing size from " + oldSize + " -> " + size);
});
}
}
public GUIMenu setPreviousMenu(GUIMenu menu) {
this.previousMenu = menu;
return this;
}
public void setItem(int slot, ClickableItemStack item) {
this.menu.setItem(slot, item);
this.menuItems.put(slot, item);
}
public abstract void drawItems();
private boolean canEditPermissions(Faction faction, FPlayer player) {
Role role = player.getRole();
if (role != null && role.isAtLeast(Role.COLEADER)) {
Faction theirfac = player.getFaction();
return theirfac != null && theirfac.isNormal() && theirfac.equals(faction);
}
return false;
}
public ClickableItemStack getBackButton(Material data, String name, String... lore) {
return (new ClickableItemStack(new ItemStack(data != null ? data : Material.RED_STAINED_GLASS_PANE, 1, data != null ? (short) 0 : 0 ))).setDisplayName(name != null ? name : ChatColor.RED + ChatColor.BOLD.toString() + "Back").setLore(lore != null ? Lists.newArrayList(lore) : Lists.newArrayList(ChatColor.GRAY + "Click to return to previous menu.")).setClickCallback((e) -> {
if (this.previousMenu != null) {
this.previousMenu.open((Player)e.getWhoClicked());
}
});
}
protected void clearItems() {
this.getMenuItems().clear();
this.menu.clear();
}
public void open(Player player) {
GUIMenu openMenu = menus.get(player.getUniqueId());
if (openMenu != null) {
player.closeInventory();
Bukkit.getScheduler().scheduleSyncDelayedTask(FactionsPlugin.instance, () -> {
this.drawItems();
player.openInventory(this.menu);
menus.put(player.getUniqueId(), this);
}, 1L);
} else {
this.drawItems();
player.openInventory(this.menu);
menus.put(player.getUniqueId(), this);
}
}
public void fillEmpty(ClickableItemStack item) {
for(int i = 0; i < this.menu.getSize(); ++i) {
ItemStack is = this.menu.getItem(i);
if (is == null || is.getType() == Material.AIR) {
this.setItem(i, item);
}
}
}
public static int fitSlots(int size) {
return size <= 9 ? 9 : (size <= 18 ? 18 : (size <= 27 ? 27 : (size <= 36 ? 36 : (size <= 45 ? 45 : (size <= 54 ? 54 : 54)))));
}
public Map<Integer, ClickableItemStack> getMenuItems() {
return this.menuItems;
}
public static Map<UUID, GUIMenu> getMenus() {
return menus;
}
public Consumer<InventoryCloseEvent> getCloseCallback() {
return this.closeCallback;
}
public void setCloseCallback(Consumer<InventoryCloseEvent> closeCallback) {
this.closeCallback = closeCallback;
}
public String getName() {
return this.name;
}
public int getSize() {
return this.size;
}
public GUIMenu getPreviousMenu() {
return this.previousMenu;
}
}