Blacklisted Names & Misc changes to setup for new revamp

This commit is contained in:
Driftay 2019-11-07 07:09:45 -05:00
parent 441382acdc
commit d77ee76ea7
11 changed files with 225 additions and 126 deletions

19
pom.xml
View File

@ -126,6 +126,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.ocpsoft.prettytime</groupId>
<artifactId>prettytime</artifactId>
<version>4.0.0.Final</version>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>VaultAPI</artifactId>
@ -376,6 +381,12 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>me.rayzr522</groupId>
<artifactId>jsonmessage</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.codemc.worldguardwrapper</groupId>
<artifactId>worldguardwrapper</artifactId>
@ -411,6 +422,14 @@
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
<repository>
<id>org.ocpsoft.prettytime</id>
<url>https://mvnrepository.com/artifact/org.ocpsoft.prettytime/prettytime</url>
</repository>
<repository>
<id>rayzr-repo</id>
<url>https://cdn.rawgit.com/Rayzr522/maven-repo/master/</url>
</repository>
<repository>
<id>maven.sk89q.com</id>
<url>http://maven.sk89q.com/repo/</url>

View File

@ -70,6 +70,7 @@ public class Conf {
public static boolean chatTagEnabled = true;
public static transient boolean chatTagHandledByAnotherPlugin = false;
public static boolean chatTagRelationColored = true;
public static List<String> blacklistedFactionNames = new ArrayList<>();
public static String chatTagReplaceString = "[FACTION]";
public static String chatTagInsertAfterString = "";
public static String chatTagInsertBeforeString = "";
@ -378,6 +379,8 @@ public class Conf {
static {
baseCommandAliases.add("f");
blacklistedFactionNames.add("somenamehere");
territoryEnemyDenyCommands.add("home");
territoryEnemyDenyCommands.add("sethome");
territoryEnemyDenyCommands.add("spawn");

View File

@ -11,7 +11,6 @@ import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.cmd.check.CheckTask;
import com.massivecraft.factions.cmd.check.WeeWooTask;
import com.massivecraft.factions.cmd.chest.AntiChestListener;
import com.massivecraft.factions.cmd.chest.ChestLogsHandler;
import com.massivecraft.factions.discord.DiscordListener;
import com.massivecraft.factions.discord.FactionChatHandler;
import com.massivecraft.factions.integration.Econ;
@ -288,8 +287,7 @@ public class FactionsPlugin extends MPlugin {
new FUpgradesGUI(),
new UpgradesListener(),
new MissionHandler(this),
new AntiChestListener(),
new ChestLogsHandler()
new AntiChestListener()
};
for (Listener eventListener : eventsListener)

View File

@ -1,123 +0,0 @@
package com.massivecraft.factions.cmd.chest;
import com.massivecraft.factions.FPlayers;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ChestLogsHandler implements Listener {
public static HashMap<String, List<String>> removeMap = new HashMap<>();
public static HashMap<String, List<String>> addMap = new HashMap<>();
public static HashMap<String, Integer> totalMap = new HashMap<>();
public static int getAll(String uuid) {
int t = 0;
t = t + removeMap.get(uuid).size();
t = t + addMap.get(uuid).size();
return t;
}
public static int getAll() {
int t = 0;
for (Map.Entry<String, List<String>> entry : removeMap.entrySet()) {
t = t + entry.getValue().size();
}
for (Map.Entry<String, List<String>> entry : addMap.entrySet()) {
t = t + entry.getValue().size();
}
return t;
}
public void mapAdd(String uuid, String string) {
List<String> list = new ArrayList<>();
if (addMap.get(uuid) != null) {
list = addMap.get(uuid);
}
list.add(string);
addMap.remove(uuid);
addMap.put(uuid, list);
if (totalMap.get(uuid) == null) {
totalMap.put(uuid, 1);
} else {
int t = totalMap.get(uuid);
totalMap.remove(uuid);
totalMap.put(uuid, t + 1);
}
}
public void mapRemove(String uuid, String string) {
List<String> list = new ArrayList<>();
if (removeMap.get(uuid) != null) {
list = removeMap.get(uuid);
}
list.add(string);
removeMap.remove(uuid);
removeMap.put(uuid, list);
if (totalMap.get(uuid) == null) {
totalMap.put(uuid, 1);
} else {
int t = totalMap.get(uuid);
totalMap.remove(uuid);
totalMap.put(uuid, t + 1);
}
}
public String itemString(ItemStack itemStack) {
String s = "x" + itemStack.getAmount() + " " + itemStack.getType().name().toLowerCase();
if (itemStack.hasItemMeta() && itemStack.getItemMeta().hasDisplayName()) {
s = s + " (" + itemStack.getItemMeta().getDisplayName() + ")";
}
return s.replace("_", " ");
}
@EventHandler
public void fChestInventoryClick(InventoryClickEvent e) {
Player p = (Player) e.getWhoClicked();
Inventory topInventory = p.getOpenInventory().getTopInventory();
Inventory bottomInventory = p.getOpenInventory().getBottomInventory();
if (topInventory != null) {
if (topInventory.equals(FPlayers.getInstance().getByPlayer(p).getFaction().getChestInventory())) {
if (e.getClickedInventory() != null) {
if (e.getClickedInventory().equals(topInventory)) {
ItemStack current = e.getCurrentItem();
if (current == null) return;
ItemStack cursor = e.getCursor();
if (e.getClick().isShiftClick()) return;
if (cursor != null) {
if (current.getType().equals(Material.AIR)) {
if (!cursor.getType().equals(Material.AIR)) {
mapAdd(p.getName(), itemString(cursor));
}
} else {
if (!current.getType().equals(Material.AIR)) {
mapRemove(p.getName(), itemString(current));
}
}
}
} else {
if (e.getClickedInventory().equals(bottomInventory)) {
//clicking from bottom inventory
if (e.getClick().isShiftClick()) {
}
}
}
}
}
}
}
}

View File

@ -3,6 +3,7 @@ package com.massivecraft.factions.util;
import com.massivecraft.factions.*;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.tag.Tag;
import com.massivecraft.factions.zcore.util.TL;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import me.clip.placeholderapi.expansion.Relational;
@ -104,6 +105,10 @@ public class ClipPlaceholderAPIManager extends PlaceholderExpansion implements R
// Then Faction stuff
case "faction_name":
return fPlayer.hasFaction() ? faction.getTag() : TL.NOFACTION_PREFIX.toString();
case "faction_name_custom":
return fPlayer.hasFaction() ? Tag.parsePlain(fPlayer, TL.PLACEHOLDER_CUSTOM_FACTION.toString()) : "";
case "faction_only_space":
return fPlayer.hasFaction() ? " " : "";
case "faction_power":
return String.valueOf(faction.getPowerRounded());
case "faction_powermax":

View File

@ -0,0 +1,97 @@
package com.massivecraft.factions.util;
import com.massivecraft.factions.FactionsPlugin;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List;
public class ItemBuilder {
private ItemMeta meta;
private ItemStack item;
public ItemBuilder(ItemStack item) {
this.item = item;
this.meta = item.getItemMeta();
}
public ItemBuilder(Material material, int amount, int durability) {
this(new ItemStack(material, amount, (short) durability));
}
public ItemBuilder(Material material, int amount) {
this(material, amount, 0);
}
public ItemBuilder(Material material) {
this(material, 1);
}
public static List<String> color(List<String> string) {
List<String> colored = new ArrayList<>();
for (String line : string) {
colored.add(FactionsPlugin.instance.color(line));
}
return colored;
}
public ItemBuilder durability(short durability) {
this.item.setDurability(durability);
return this;
}
public ItemBuilder lore(String... lore) {
if (lore != null) {
ArrayList<String> arrayList = new ArrayList<>();
for (String line : lore) {
arrayList.add(FactionsPlugin.instance.color(line));
}
this.meta.setLore(arrayList);
}
return this;
}
public ItemBuilder lore(List<String> lore) {
this.meta.setLore(color(lore));
return this;
}
public ItemBuilder name(String name) {
this.meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
return this;
}
public ItemStack build() {
this.item.setItemMeta(this.meta);
return this.item;
}
public ItemBuilder amount(int amount) {
this.item.setAmount(amount);
return this;
}
public ItemBuilder glowing(boolean status) {
if (status) {
this.meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
this.meta.addEnchant(Enchantment.DURABILITY, 1, true);
} else {
this.meta.removeItemFlags(ItemFlag.HIDE_ENCHANTS);
this.meta.removeEnchant(Enchantment.DURABILITY);
}
return this;
}
public ItemBuilder addLineToLore(String line) {
List<String> lore = this.meta.getLore();
lore.add(FactionsPlugin.instance.color(line));
this.meta.setLore(lore);
return this;
}
}

View File

@ -67,6 +67,13 @@ public class MiscUtil {
public static ArrayList<String> validateTag(String str) {
ArrayList<String> errors = new ArrayList<>();
for (String blacklistItem : Conf.blacklistedFactionNames) {
if (str.toLowerCase().contains(blacklistItem.toLowerCase())) {
errors.add(FactionsPlugin.instance.txt.parse(TL.GENERIC_FACTIONTAG_BLACKLIST.toString()));
break;
}
}
if (getComparisonString(str).length() < Conf.factionTagLengthMin) {
errors.add(FactionsPlugin.getInstance().txt.parse(TL.GENERIC_FACTIONTAG_TOOSHORT.toString(), Conf.factionTagLengthMin));
}

View File

@ -0,0 +1,31 @@
package com.massivecraft.factions.util;
import java.util.TreeMap;
public class RomanNumber {
private static TreeMap<Integer, String> map;
static {
(map = new TreeMap<>()).put(1000, "M");
RomanNumber.map.put(900, "CM");
RomanNumber.map.put(500, "D");
RomanNumber.map.put(400, "CD");
RomanNumber.map.put(100, "C");
RomanNumber.map.put(90, "XC");
RomanNumber.map.put(50, "L");
RomanNumber.map.put(40, "XL");
RomanNumber.map.put(10, "X");
RomanNumber.map.put(9, "IX");
RomanNumber.map.put(5, "V");
RomanNumber.map.put(4, "IV");
RomanNumber.map.put(1, "I");
}
public static String toRoman(int number) {
int l = RomanNumber.map.floorKey(number);
if (number == l) {
return RomanNumber.map.get(number);
}
return RomanNumber.map.get(l) + toRoman(number - l);
}
}

View File

@ -0,0 +1,20 @@
package com.massivecraft.factions.util.serializable;
public class InventoryUtils {
private int x;
private int y;
private int rows;
public InventoryUtils(int x, int y, int rows) {
this.x = x;
this.y = y;
this.rows = rows;
}
public void increment() {
if (this.x == 9) {
this.x = 0;
++this.y;
}
}
}

View File

@ -0,0 +1,40 @@
package com.massivecraft.factions.util.serializable;
import com.massivecraft.factions.util.ItemBuilder;
import com.massivecraft.factions.util.XMaterial;
import org.bukkit.inventory.ItemStack;
import java.util.List;
public class Item {
private String name;
private List<String> lore;
private XMaterial material;
private int amount;
private int slot;
public Item(String name, List<String> lore, XMaterial material, int amount, int slot) {
this.name = name;
this.lore = lore;
this.material = material;
this.amount = amount;
this.slot = slot;
}
public ItemStack buildItemStack(boolean isSelected) {
return new ItemBuilder(material.parseItem()).name(name).lore(lore).glowing(isSelected).amount(amount).build();
}
public int getAmount() {
return this.amount;
}
public String getName() {
return this.name;
}
public int getSlot() {
return this.slot;
}
}

View File

@ -1020,6 +1020,7 @@ public enum TL {
GENERIC_TRANSLATION_VERSION("Translation: %1$s(%2$s,%3$s) State: %4$s"),
GENERIC_TRANSLATION_CONTRIBUTORS("Translation contributors: %1$s"),
GENERIC_TRANSLATION_RESPONSIBLE("Responsible for translation: %1$s"),
GENERIC_FACTIONTAG_BLACKLIST("&cThat faction tag is blacklisted."),
GENERIC_FACTIONTAG_TOOSHORT("The faction tag can't be shorter than %1$s chars."),
GENERIC_FACTIONTAG_TOOLONG("The faction tag can't be longer than %s chars."),
GENERIC_FACTIONTAG_ALPHANUMERIC("Faction tag must be alphanumeric. \"%s\" is not allowed."),
@ -1043,6 +1044,7 @@ public enum TL {
PLAYER_NOT_FOUND("&c&l[!] &b%1$s &7is either not online or not in your faction!"),
PLACEHOLDER_ROLE_NAME("None"),
PLACEHOLDER_CUSTOM_FACTION("{faction} "),
WARBANNER_NOFACTION("&cYou need a faction to use a warbanner!"),