Compare commits

...

10 Commits
2.0.5 ... 2.0.6

Author SHA1 Message Date
Driftay
ac859db55f TntFill Logic Fixed 2019-11-14 04:23:35 -05:00
Driftay
8c7addb68e F Home and ClaimAt Fix 2019-11-14 03:44:35 -05:00
Driftay
d808bac17b Merge remote-tracking branch 'origin/1.6.x' into 1.6.x
# Conflicts:
#	src/main/java/com/massivecraft/factions/cmd/CmdHome.java
2019-11-14 03:43:06 -05:00
Driftay
d3a7fc67a5 F Home and ClaimAt Fix 2019-11-14 03:42:47 -05:00
DroppingAnvil
bd77c8266c Small bug fix + Code added to run randomized missions
Signed-off-by: DroppingAnvil <dr0pping.4nvi1@gmail.com>
2019-11-14 02:27:41 -06:00
Driftay
8bde1385fc Few Fixes 2019-11-09 15:20:25 -05:00
Driftay
472cb86465 TNT Dialog Fixed 2019-11-07 13:17:59 -05:00
Driftay
d77ee76ea7 Blacklisted Names & Misc changes to setup for new revamp 2019-11-07 07:09:45 -05:00
DroppingAnvil
441382acdc Fix issues with 1.13+
Signed-off-by: DroppingAnvil <dr0pping.4nvi1@gmail.com>
2019-11-05 18:31:17 -06:00
DroppingAnvil
d3870731f4 Introduced updater for config.yml
Signed-off-by: DroppingAnvil <dr0pping.4nvi1@gmail.com>
2019-11-05 17:15:42 -06:00
23 changed files with 436 additions and 186 deletions

21
pom.xml
View File

@@ -4,7 +4,7 @@
<groupId>com.massivecraft</groupId>
<artifactId>Factions</artifactId>
<version>1.6.9.5-U0.2.1-2.0.5-BETA</version>
<version>1.6.9.5-U0.2.1-2.0.6-STABLE</version>
<packaging>jar</packaging>
<name>SaberFactions</name>
@@ -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

@@ -30,6 +30,17 @@ public interface FPlayer extends EconomyParticipator {
boolean hasNotificationsEnabled();
/**
* Used to determine if a player is in their faction's chest
* @return if player is in their faction's as a boolean
*/
boolean isInFactionsChest();
/**
* Set if the player is inside of their faction's chest
*/
void setInFactionsChest(boolean b);
boolean isAlt();
void setAlt(boolean alt);

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;
@@ -185,17 +184,19 @@ public class FactionsPlugin extends MPlugin {
// Load Conf from disk
Conf.load();
//Dependency checks
if (Conf.dependencyCheck && (Bukkit.getPluginManager().isPluginEnabled("Vault") && Bukkit.getPluginManager().isPluginEnabled("Essentials"))) {
RegisteredServiceProvider<Economy> rsp = FactionsPlugin.this.getServer().getServicesManager().getRegistration(Economy.class);
FactionsPlugin.econ = rsp.getProvider();
} else if (Conf.dependencyCheck) {
if (Conf.dependencyCheck && (!Bukkit.getPluginManager().isPluginEnabled("Vault") && !Bukkit.getPluginManager().isPluginEnabled("Essentials"))) {
divider();
System.out.println("You are missing dependencies!");
System.out.println("Please verify EssentialsX and Vault are installed!");
Conf.save();
Bukkit.getPluginManager().disablePlugin(instance);
divider();
return;
}
//Update their config if needed
Updater.updateIfNeeded(getConfig());
RegisteredServiceProvider<Economy> rsp = FactionsPlugin.this.getServer().getServicesManager().getRegistration(Economy.class);
FactionsPlugin.econ = rsp.getProvider();
com.massivecraft.factions.integration.Essentials.setup();
hookedPlayervaults = setupPlayervaults();
FPlayers.getInstance().load();
@@ -286,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

@@ -45,10 +45,14 @@ public class CmdHome extends FCommand {
return;
}
if (context.args.size() == 1) {
Faction faction = context.argAsFaction(0);
if (faction == null) return;
context.faction = faction;
if (context.args.size() >= 1) {
Faction target = context.argAsFaction(0);
if (target == null) return;
context.faction = target;
if (target.getAccess(context.fPlayer, PermissableAction.HOME) != Access.ALLOW) {
context.fPlayer.msg(TL.GENERIC_FPERM_NOPERMISSION, "teleport home");
return;
}
}
if (!context.faction.hasHome()) {
@@ -83,9 +87,9 @@ public class CmdHome extends FCommand {
if (Conf.homesTeleportAllowedEnemyDistance > 0
&& !faction.isSafeZone()
&& (!context.fPlayer.isInOwnTerritory()
|| !Conf.homesTeleportIgnoreEnemiesIfInOwnTerritory)
&& (!Conf.homesTeleportIgnoreEnemiesIfInNoClaimingWorld
|| !Conf.worldsNoClaiming.contains(context.fPlayer.getPlayer().getWorld().getName()))) {
|| (context.fPlayer.isInOwnTerritory()
&& !Conf.homesTeleportIgnoreEnemiesIfInOwnTerritory))) {
World w = loc.getWorld();
double x = loc.getX();
double y = loc.getY();

View File

@@ -19,7 +19,7 @@ public class AntiChestListener implements Listener {
public void onInventoryClick(InventoryClickEvent e) {
Player player = (Player) e.getWhoClicked();
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player);
if (!e.getView().getTopInventory().getTitle().equalsIgnoreCase(FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fchest.Inventory-Title")))) return;
if (!fPlayer.isInFactionsChest()) return;
if (e.isCancelled()) return;
@@ -49,7 +49,7 @@ public class AntiChestListener implements Listener {
Player p = (Player) e.getWhoClicked();
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(p);
if (!e.getView().getTopInventory().getTitle().equalsIgnoreCase(FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fchest.Inventory-Title")))) return;
if (!fPlayer.isInFactionsChest()) return;
if (e.isCancelled()) return;
ItemStack dragged = e.getOldCursor();

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

@@ -30,6 +30,7 @@ public class CmdChest extends FCommand {
return;
}
// This permission check is way too explicit but it's clean
context.fPlayer.setInFactionsChest(true);
context.player.openInventory(context.faction.getChestInventory());
}

View File

@@ -31,11 +31,7 @@ public class CmdClaimAt extends FCommand {
int x = context.argAsInt(1);
int z = context.argAsInt(2);
FLocation location = new FLocation(context.argAsString(0), x, z);
if (!((context.player.getLocation().getX() + (x * 16)) > (context.player.getLocation().getX() + (Conf.mapWidth * 16))) &&
!((context.player.getLocation().getZ() + (z * 16)) > (context.player.getLocation().getZ() + (Conf.mapHeight * 16))) &&
!context.argAsString(0).equals(context.player.getLocation().getWorld().getName())) {
context.fPlayer.attemptClaim(context.faction, location, true);
} else context.fPlayer.msg(TL.COMMAND_CLAIM_DENIED);
context.fPlayer.attemptClaim(context.faction, location, true);
}

View File

@@ -29,7 +29,7 @@ public class CmdTnt extends FCommand {
@Override
public void perform(CommandContext context) {
if (!FactionsPlugin.getInstance().getConfig().getBoolean("ftnt.Enabled")) {
if (!FactionsPlugin.instance.getConfig().getBoolean("ftnt.Enabled")) {
context.msg(TL.COMMAND_TNT_DISABLED_MSG);
return;
}
@@ -62,7 +62,7 @@ public class CmdTnt extends FCommand {
return;
}
ItemStack tnt = new ItemStack(Material.TNT, amount);
if (context.faction.getTnt() + amount > FactionsPlugin.getInstance().getConfig().getInt("ftnt.Bank-Limit")) {
if (context.faction.getTnt() + amount > FactionsPlugin.instance.getConfig().getInt("ftnt.Bank-Limit")) {
context.msg(TL.COMMAND_TNT_EXCEEDLIMIT);
return;
}
@@ -71,7 +71,7 @@ public class CmdTnt extends FCommand {
context.faction.addTnt(amount);
context.msg(TL.COMMAND_TNT_DEPOSIT_SUCCESS);
context.fPlayer.sendMessage(FactionsPlugin.getInstance().color(TL.COMMAND_TNT_AMOUNT.toString().replace("{amount}", context.fPlayer.getFaction().getTnt() + "")));
context.fPlayer.sendMessage(FactionsPlugin.instance.color(TL.COMMAND_TNT_AMOUNT.toString().replace("{amount}", context.fPlayer.getFaction().getTnt() + "")));
return;
}
@@ -102,10 +102,8 @@ public class CmdTnt extends FCommand {
return;
}
for (int i = 0; i <= fullStacks - 1; i++)
context.player.getInventory().addItem(new ItemStack(XMaterial.TNT.parseMaterial(), 64));
if (remainderAmt != 0)
context.player.getInventory().addItem(new ItemStack(XMaterial.TNT.parseMaterial(), remainderAmt));
for (int i = 0; i <= fullStacks - 1; i++) context.player.getInventory().addItem(new ItemStack(XMaterial.TNT.parseMaterial(), 64));
if (remainderAmt != 0) context.player.getInventory().addItem(new ItemStack(XMaterial.TNT.parseMaterial(), remainderAmt));
context.faction.takeTnt(amount);
context.player.updateInventory();
@@ -115,7 +113,7 @@ public class CmdTnt extends FCommand {
context.msg(TL.GENERIC_ARGS_TOOFEW);
context.msg(context.args.get(0).equalsIgnoreCase("take") || context.args.get(0).equalsIgnoreCase("t") ? TL.COMMAND_TNT_TAKE_DESCRIPTION : TL.COMMAND_TNT_ADD_DESCRIPTION);
}
context.msg(TL.COMMAND_TNT_AMOUNT, context.faction.getTnt(), context.faction.getTntBankLimit());
context.sendMessage(TL.COMMAND_TNT_AMOUNT.toString().replace("{amount}", context.faction.getTnt() + ""));
}
@@ -134,7 +132,7 @@ public class CmdTnt extends FCommand {
}
public boolean hasAvaliableSlot(Player player, int howmany) {
Integer check = 0;
int check = 0;
for (ItemStack item : player.getInventory().getContents()) {
if (item == null) {
check++;
@@ -168,4 +166,3 @@ public class CmdTnt extends FCommand {
return TL.COMMAND_TNT_DESCRIPTION;
}
}

View File

@@ -18,9 +18,7 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.*;
public class CmdTntFill extends FCommand {
@@ -40,7 +38,7 @@ public class CmdTntFill extends FCommand {
@Override
public void perform(CommandContext context) {
if (!FactionsPlugin.getInstance().getConfig().getBoolean("Tntfill.enabled")) {
if (!FactionsPlugin.instance.getConfig().getBoolean("Tntfill.enabled")) {
context.msg(TL.GENERIC_DISABLED);
return;
}
@@ -62,12 +60,12 @@ public class CmdTntFill extends FCommand {
context.msg(TL.COMMAND_TNT_POSITIVE);
return;
}
if (radius > FactionsPlugin.getInstance().getConfig().getInt("Tntfill.max-radius")) {
context.msg(TL.COMMAND_TNTFILL_RADIUSMAX.toString().replace("{max}", FactionsPlugin.getInstance().getConfig().getInt("Tntfill.max-radius") + ""));
if (radius > FactionsPlugin.instance.getConfig().getInt("Tntfill.max-radius")) {
context.msg(TL.COMMAND_TNTFILL_RADIUSMAX.toString().replace("{max}", FactionsPlugin.instance.getConfig().getInt("Tntfill.max-radius") + ""));
return;
}
if (amount > FactionsPlugin.getInstance().getConfig().getInt("Tntfill.max-amount")) {
context.msg(TL.COMMAND_TNTFILL_AMOUNTMAX.toString().replace("{max}", FactionsPlugin.getInstance().getConfig().getInt("Tntfill.max-amount") + ""));
if (amount > FactionsPlugin.instance.getConfig().getInt("Tntfill.max-amount")) {
context.msg(TL.COMMAND_TNTFILL_AMOUNTMAX.toString().replace("{max}", FactionsPlugin.instance.getConfig().getInt("Tntfill.max-amount") + ""));
return;
}
@@ -108,19 +106,17 @@ public class CmdTntFill extends FCommand {
}
// Take TNT from the bank.
context.faction.takeTnt(getFactionTnt);
removeFromBank(context, getFactionTnt);
}
fillDispensers(context.fPlayer, opDispensers, amount);
// Remove used TNT from player inventory.
context.sendMessage(TL.COMMAND_TNTFILL_SUCCESS.toString().replace("{amount}", requiredTnt + "").replace("{dispensers}", opDispensers.size() + ""));
}
// Actually fill every dispenser with the precise amount.
private void fillDispensers(FPlayer fPlayer, List<Dispenser> dispensers, int count) {
for (Dispenser dispenser : dispensers) {
if (takeTnt(fPlayer, count)) {
dispenser.getInventory().addItem(new ItemStack(Material.TNT, count));
} else {return;}
takeTnt(fPlayer, count);
dispenser.getInventory().addItem(new ItemStack(Material.TNT, count));
}
}
@@ -161,7 +157,7 @@ public class CmdTntFill extends FCommand {
context.player.updateInventory();
}
private boolean takeTnt(FPlayer fme, int amount) {
private void takeTnt(FPlayer fme, int amount) {
Inventory inv = fme.getPlayer().getInventory();
int invTnt = 0;
for (int i = 0; i <= inv.getSize(); i++) {
@@ -174,15 +170,14 @@ public class CmdTntFill extends FCommand {
}
if (amount > invTnt) {
fme.msg(TL.COMMAND_TNTFILL_NOTENOUGH.toString());
return false;
return;
}
ItemStack tnt = new ItemStack(Material.TNT, amount);
if (fme.getFaction().getTnt() + amount > FactionsPlugin.getInstance().getConfig().getInt("ftnt.Bank-Limit")) {
if (fme.getFaction().getTnt() + amount > FactionsPlugin.instance.getConfig().getInt("ftnt.Bank-Limit")) {
fme.msg(TL.COMMAND_TNT_EXCEEDLIMIT.toString());
return false;
return;
}
removeFromInventory(fme.getPlayer().getInventory(), tnt);
return true;
}
// Counts the item type available in the inventory.

View File

@@ -82,7 +82,7 @@ public class FactionsPlayerListener implements Listener {
faction.isWilderness();
}
public static boolean playerCanUseItemHere(Player player, Location location, Material material, boolean justCheck) {
public static boolean playerCanUseItemHere(Player player, Location location, Material material, boolean justCheck, PermissableAction permissableAction) {
String name = player.getName();
if (Conf.playersWhoBypassAllProtection.contains(name)) {
return true;
@@ -163,8 +163,8 @@ public class FactionsPlayerListener implements Listener {
return false;
}
Access access = otherFaction.getAccess(me, PermissableAction.ITEM);
return CheckPlayerAccess(player, me, loc, otherFaction, access, PermissableAction.ITEM, false);
Access access = otherFaction.getAccess(me, permissableAction);
return CheckPlayerAccess(player, me, loc, otherFaction, access, permissableAction, false);
}
@SuppressWarnings("deprecation")
@@ -729,7 +729,7 @@ public class FactionsPlayerListener implements Listener {
(relationTo == Relation.ALLY && me.canflyinAlly()) ||
(relationTo == Relation.TRUCE && me.canflyinTruce()) ||
(relationTo == Relation.NEUTRAL && me.canflyinNeutral() && !isSystemFaction(factionTo))) {
enableFly(me);
Bukkit.getScheduler().runTask(FactionsPlugin.instance, () -> enableFly(me));
}
}
if (me.getAutoClaimFor() != null) {
@@ -791,8 +791,8 @@ public class FactionsPlayerListener implements Listener {
@EventHandler
public void onClose(InventoryCloseEvent e) {
FPlayer fme = FPlayers.getInstance().getById(e.getPlayer().getUniqueId().toString());
if (fme.isInVault())
fme.setInVault(false);
if (fme.isInVault()) fme.setInVault(false);
if (fme.isInFactionsChest()) fme.setInFactionsChest(false);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
@@ -804,6 +804,15 @@ public class FactionsPlayerListener implements Listener {
Player player = event.getPlayer();
// Check if the material is bypassing protection
if (block == null) return; // clicked in air, apparently
Material type;
if (event.getItem() != null) {
// Convert 1.8 Material Names -> 1.14
type = XMaterial.matchXMaterial(event.getItem().getType().toString()).parseMaterial();
} else {
type = null;
}
if (Conf.territoryBypassProtectedMaterials.contains(block.getType())) return;
if (GetPermissionFromUsableBlock(event.getClickedBlock().getType()) != null) {
@@ -824,7 +833,7 @@ public class FactionsPlayerListener implements Listener {
}
if (event.getItem() == null) return;
if (!playerCanUseItemHere(player, block.getLocation(), event.getItem().getType(), false)) {
if (type != null && !playerCanUseItemHere(player, block.getLocation(), event.getItem().getType(), false, PermissableAction.ITEM)) {
event.setCancelled(true);
event.setUseInteractedBlock(Event.Result.DENY);
}
@@ -879,7 +888,7 @@ public class FactionsPlayerListener implements Listener {
Block block = event.getBlockClicked();
Player player = event.getPlayer();
if (!playerCanUseItemHere(player, block.getLocation(), event.getBucket(), false)) {
if (!playerCanUseItemHere(player, block.getLocation(), event.getBucket(), false, PermissableAction.BUILD)) {
event.setCancelled(true);
}
}
@@ -889,7 +898,7 @@ public class FactionsPlayerListener implements Listener {
Block block = event.getBlockClicked();
Player player = event.getPlayer();
if (!playerCanUseItemHere(player, block.getLocation(), event.getBucket(), false)) {
if (!playerCanUseItemHere(player, block.getLocation(), event.getBucket(), false, PermissableAction.DESTROY)) {
event.setCancelled(true);
}
}
@@ -1011,6 +1020,11 @@ public class FactionsPlayerListener implements Listener {
}
}
}
@EventHandler
public void onDisconnect(PlayerQuitEvent e) {
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(e.getPlayer());
if (fPlayer.isInFactionsChest()) fPlayer.setInFactionsChest(false);
}
private static class InteractAttemptSpam {
private int attempts = 0;

View File

@@ -13,7 +13,6 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.*;
public class MissionGUI implements FactionGUI {
@@ -44,6 +43,9 @@ public class MissionGUI implements FactionGUI {
if (missionName == null) {
return;
}
//if (missionName.equals(plugin.color(FactionsPlugin.getInstance().getConfig().getString("Randomization.Start-Item.Disallowed.Name")))) {
//return;
//}
if (fPlayer.getFaction().getMissions().containsKey(missionName)) {
fPlayer.msg(TL.MISSION_MISSION_ACTIVE);
return;
@@ -63,6 +65,24 @@ public class MissionGUI implements FactionGUI {
if (missionSection == null) {
return;
}
//Coming soon (:
//if (missionName.equals(plugin.color(FactionsPlugin.getInstance().getConfig().getString("Randomization.Start-Item.Allowed.Name")))) {
//Mission pickedMission = null;
//Set<String> keys = plugin.getConfig().getConfigurationSection("Missions").getKeys(false);
//while (pickedMission == null) {
//Random r = new Random();
//int pick = r.nextInt(keys.size() - 1);
//if (!keys.toArray()[pick].toString().equals("FillItem")) {
//missionName = keys.toArray()[pick].toString();
//pickedMission = new Mission(missionName, plugin.getConfig().getString("Missions." + missionName + ".Mission.Type"));
//fPlayer.getFaction().getMissions().put(missionName, pickedMission);
//fPlayer.msg(TL.MISSION_MISSION_STARTED, fPlayer.describeTo(fPlayer.getFaction()), plugin.color(plugin.getConfig().getString("Missions." + missionName + ".Name")));
//build();
//fPlayer.getPlayer().openInventory(inventory);
//return;
//}
//}
//}
Mission mission = new Mission(missionName, missionSection.getString("Type"));
fPlayer.getFaction().getMissions().put(missionName, mission);
fPlayer.msg(TL.MISSION_MISSION_STARTED, fPlayer.describeTo(fPlayer.getFaction()), plugin.color(section.getString("Name")));
@@ -110,6 +130,46 @@ public class MissionGUI implements FactionGUI {
slots.put(slot, key);
}
}
if (plugin.getConfig().getBoolean("Randomization.Enabled")) {
ItemStack start = null;
ItemMeta meta;
start = XMaterial.matchXMaterial(plugin.getConfig().getString("Randomization.Start-Item.Allowed.Material")).parseItem();
meta = start.getItemMeta();
meta.setDisplayName(plugin.color(plugin.getConfig().getString("Randomization.Start-Item.Allowed.Name")));
List<String> loree = meta.getLore();
loree.clear();
for (String string : plugin.getConfig().getStringList("Randomization.Start-Item.Allowed.Lore")) {
loree.add(plugin.color(string));
}
meta.setLore(loree);
start.setItemMeta(meta);
if (fPlayer.getFaction().getCompletedMissions().size() >= configurationSection.getKeys(false).size() - 1 && plugin.getConfig().getBoolean("DenyMissionsMoreThenOnce")) {
start = XMaterial.matchXMaterial(plugin.getConfig().getString("Randomization.Start-Item.Disallowed.Material")).parseItem();
meta = start.getItemMeta();
meta.setDisplayName(plugin.color(plugin.getConfig().getString("Randomization.Start-Item.Disallowed.Name")));
List<String> lore = meta.getLore();
lore.clear();
for (String string : plugin.getConfig().getStringList("Randomization.Start-Item.Disallowed.Lore")) {
lore.add(plugin.color(string).replace("%reason%", TL.MISSION_MISSION_ALL_COMPLETED.toString()));
}
meta.setLore(lore);
start.setItemMeta(meta);
}
if (fPlayer.getFaction().getMissions().size() >= plugin.getConfig().getInt("MaximumMissionsAllowedAtOnce")) {
start = XMaterial.matchXMaterial(plugin.getConfig().getString("Randomization.Start-Item.Disallowed.Material")).parseItem();
meta = start.getItemMeta();
meta.setDisplayName(plugin.color(plugin.getConfig().getString("Randomization.Start-Item.Disallowed.Name")));
List<String> lore = meta.getLore();
lore.clear();
for (String string : plugin.getConfig().getStringList("Randomization.Start-Item.Disallowed.Lore")) {
lore.add(plugin.color(string).replace("%reason%", FactionsPlugin.getInstance().txt.parse(TL.MISSION_MISSION_MAX_ALLOWED.toString(), plugin.getConfig().getInt("MaximumMissionsAllowedAtOnce"))));
}
meta.setLore(lore);
start.setItemMeta(meta);
}
inventory.setItem(plugin.getConfig().getInt("Randomization.Start-Item.Slot"), start);
slots.put(plugin.getConfig().getInt("Randomization.Start-Item.Slot"), start.getItemMeta().getDisplayName());
}
}
public Inventory getInventory() {

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":
@@ -141,7 +146,7 @@ public class ClipPlaceholderAPIManager extends PlaceholderExpansion implements R
return faction.hasHome() ? String.valueOf(faction.getHome().getBlockY()) : "";
case "faction_home_z":
return faction.hasHome() ? String.valueOf(faction.getHome().getBlockZ()) : "";
case "facion_land_value":
case "faction_land_value":
return Econ.shouldBeUsed() ? Econ.moneyString(Econ.calculateTotalLandValue(faction.getLandRounded())) : TL.ECON_OFF.format("value");
case "faction_land_refund":
return Econ.shouldBeUsed() ? Econ.moneyString(Econ.calculateTotalLandRefund(faction.getLandRounded())) : TL.ECON_OFF.format("refund");

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,47 @@
package com.massivecraft.factions.util;
import com.massivecraft.factions.FactionsPlugin;
import org.bukkit.configuration.file.FileConfiguration;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class Updater {
public static double currentVersion = 1.1;
public static void updateIfNeeded(FileConfiguration conf) {
double version = conf.getDouble("Config-Version", 0);
//Previous version
if (version == 0) {
//Instructions for this configuration to be updated to current
FactionsPlugin.getInstance().log("Your config.yml is pre-versioning so we are going to assign it version 1.0 \n Please regenerate your config.yml if you run into any errors relating to config.");
conf.set("Config-Version", 1.0);
version = 1.0;
}
if (version == 1.0) {
FactionsPlugin.getInstance().log("Updating config from version 1.0 to 1.1");
FactionsPlugin.getInstance().log("Adding randomization support for f missions...");
conf.set("Randomization.Enabled", false);
conf.set("Randomization.Start-Item.Allowed.Name", "&aStart!");
conf.set("Randomization.Start-Item.Allowed.Material", "GREEN_STAINED_GLASS_PANE");
List<String> lore = new ArrayList<>();
lore.add("&aStart a new mission!");
conf.set("Randomization.Start-Item.Allowed.Lore", lore);
conf.set("Randomization.Start-Item.Disallowed.Name", "&4Cannot start new mission");
conf.set("Randomization.Start-Item.Disallowed.Material", "GRAY_STAINED_GLASS_PANE");
lore.clear();
lore.add("&4%reason%");
conf.set("Randomization.Start-Item.Disallowed.Lore", lore);
conf.set("Randomization.Start-Item.Slot", 23);
conf.set("Config-Version", 1.1);
version = 1.1;
}
//End with save + reload
try {
conf.save(new File("plugins/Factions/config.yml"));
FactionsPlugin.getInstance().reloadConfig();
} catch (IOException e) {e.printStackTrace();}
}
}

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

@@ -41,6 +41,7 @@ import java.util.*;
*/
public abstract class MemoryFPlayer implements FPlayer {
public boolean inChest = false;
public boolean inVault = false;
protected HashMap<String, Long> commandCooldown = new HashMap<>();
protected String factionId;
@@ -963,6 +964,12 @@ public abstract class MemoryFPlayer implements FPlayer {
isFlying = fly;
}
public boolean isInFactionsChest() {
return inChest;
}
public void setInFactionsChest(boolean b) {
inChest = b;
}
public boolean isInVault() {
return inVault;
}

View File

@@ -882,7 +882,7 @@ public enum TL {
COMMAND_TNT_WIDTHDRAW_SUCCESS("&cSuccessfully withdrew tnt."),
COMMAND_TNT_WIDTHDRAW_NOTENOUGH("&cNot enough tnt in bank."),
COMMAND_TNT_DEPOSIT_NOTENOUGH("&cNot enough tnt in tnt inventory."),
COMMAND_TNT_AMOUNT("&cYour faction has %1$s tnt out of %2$s in the tnt bank."),
COMMAND_TNT_AMOUNT("&cYour faction has %1$s tnt in the tnt bank."),
COMMAND_TNT_POSITIVE("&cPlease use positive numbers!"),
COMMAND_TNT_DESCRIPTION("add/widthraw from faction's tnt bank"),
COMMAND_TNT_WIDTHDRAW_NOTENOUGH_SPACE("&cNot enough space in your inventory."),
@@ -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."),
@@ -1035,7 +1036,8 @@ public enum TL {
MISSION_MISSION_STARTED("&f%1$s &dstarted the %2$s &fmission"),
MISSION_ALREAD_COMPLETED("&c&l[!] &7You may not restart a mission you have already completed"),
MISSION_MISSION_ACTIVE("&c&l[!] &7This mission is currently active!"),
MISSION_MISSION_MAX_ALLOWED("&c&l[!] &7You may not have more then &b%1$s &7missions active at once."),
MISSION_MISSION_MAX_ALLOWED("&c&l[!] &7You may not have more than &b%1$s &7missions active at once."),
MISSION_MISSION_ALL_COMPLETED("&c&l[!] &7Your faction has completed all available missions."),
MISSION_MISSION_FINISHED("&c&l[!] &7Your faction has successfully completed %1$s mission!"),
COMMAND_MISSION_DESCRIPTION("Opens missions gui"),
// F Global \\
@@ -1043,6 +1045,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!"),

View File

@@ -1,3 +1,4 @@
Config-Version: 1.1
# SaberFactions by Driftay
# Report issues: https://github.com/Driftay/Saber-Factions/issues/new
# Live support: https://discord.gg/TFxWKeX
@@ -752,6 +753,21 @@ Missions-Enabled: true
Missions-GUI-Title: '&8&lFaction Missions'
MaximumMissionsAllowedAtOnce: 1
Mission-Progress-Format: '&b&lProgression: &f{progress}&7/&e{total}'
Randomization:
Enabled: false
Start-Item:
# Allowed means that they are under maximum allowed missions at one AND if applicable they have not completed every mission more than once
Allowed:
Name: "&aStart!"
Material: GREEN_STAINED_GLASS_PANE
Lore: "&2Start a new mission!"
Disallowed:
# Placeholder %reason% supported throughout this section
Name: "&4Cannot start new mission"
Material: GRAY_STAINED_GLASS_PANE
Lore:
- '&4%reason%'
Slot: 23
DenyMissionsMoreThenOnce: true #this setting to true, means that if they complete a mission they cannot redo the same mission
#Mission Types: KILL, MINE, PLACE, FISH, TAME, ENCHANT, CONSUME