Compare commits

...

15 Commits

Author SHA1 Message Date
DroppingAnvil
90d39a3974 Version change
1.6.9.5-2.2.5-RC -> 1.6.9.5-2.2.6-RC
2020-01-17 18:24:53 -06:00
DroppingAnvil
6544513ca7 Many F Fly bug fixes:
- Async get nearby entities
- Not respecting admin bypass
- Not respecting permissions for system claims
- Not respecting permissions for relations
- Sending fly disabled message when user is not flying
- Sending double messages when disabling
- Sometimes disabling fly while in creative and spectator game modes
2020-01-17 17:55:37 -06:00
DroppingAnvil
f7619f0685 Fixed a few issues with CmdAdmin now being Async 2020-01-15 16:01:32 -06:00
droppinganvil
a20c2ec2eb Tiny bug fix. 2020-01-15 15:21:02 -06:00
DroppingAnvil
028734a42c Shutdown JDA on disable. 2020-01-14 12:57:09 -06:00
DroppingAnvil
29b9eadd57 Fix mistype made in Aliases. 2020-01-10 20:41:12 -06:00
Driftay
83a33c2222 Version Change 2020-01-07 15:38:43 -05:00
Driftay
c274918244 Removed everything shield wise for release with bug fixes 2020-01-07 15:37:46 -05:00
Driftay
57833bee13 Fixed TntFill (Again) -_- 2020-01-04 18:49:55 -05:00
Driftay
0a1346f1c2 Made Scoreboard Dummy Proof & Started Adding Shield Tasks Timers and Objects 2020-01-04 18:29:49 -05:00
Driftay
5145ae1714 Allowed players to continue using Essentials fly is Factions Fly is Disabled 2020-01-04 13:23:55 -05:00
Driftay
086ec3e145 Allowed Custom Heads to be in Faction Upgrades 2020-01-04 12:42:53 -05:00
Driftay
d538502457 Added Enchanting on Level 1 or Higher for Upgrades 2020-01-04 12:26:23 -05:00
Driftay
978782e2fe Remade Faction GUI 2020-01-04 12:23:10 -05:00
Driftay
ce1004d318 Removed Stream Code lol 2020-01-04 11:29:44 -05:00
21 changed files with 398 additions and 950 deletions

12
pom.xml
View File

@@ -4,7 +4,7 @@
<groupId>com.massivecraft</groupId>
<artifactId>Factions</artifactId>
<version>1.6.9.5-2.2.4-RC</version>
<version>1.6.9.5-2.2.6-RC</version>
<packaging>jar</packaging>
<name>SaberFactions</name>
@@ -385,6 +385,12 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.mojang</groupId>
<artifactId>authlib</artifactId>
<version>1.5.21</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>me.rayzr522</groupId>
<artifactId>jsonmessage</artifactId>
@@ -405,6 +411,10 @@
<name>bintray</name>
<url>http://jcenter.bintray.com</url>
</repository>
<repository>
<id>mojang-repo</id>
<url>https://libraries.minecraft.net/</url>
</repository>
<repository>
<id>net.coreprotect</id>
<url>http://maven.playpro.com/</url>

View File

@@ -31,6 +31,19 @@ public interface FPlayer extends EconomyParticipator {
boolean hasNotificationsEnabled();
/**
* Determine if a player has enemies nearby based on the enemy check task in CmdFly
* NOTE: THIS VALUE IS ONLY UPDATED WHEN A USER IS USING FLY
* @return enemiesNearby as a boolean
*/
boolean hasEnemiesNearby();
/**
* Set if this FPlayer has an enemy nearby
* @param b enemiesNearby
*/
void setEnemiesNearby(Boolean b);
/**
* Get if a player has setup their Discord before
* @return if the player setup Discord as a boolean

View File

@@ -441,4 +441,7 @@ public interface Faction extends EconomyParticipator {
void paypalSet(String paypal);
// -------------------------------
// Shields
// -------------------------------
}

View File

@@ -31,7 +31,6 @@ import com.massivecraft.factions.zcore.MPlugin;
import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.Permissable;
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.fupgrades.FUpgradesGUI;
import com.massivecraft.factions.zcore.fupgrades.UpgradesListener;
import com.massivecraft.factions.zcore.util.TextUtil;
import me.lucko.commodore.CommodoreProvider;
@@ -124,21 +123,15 @@ public class FactionsPlugin extends MPlugin {
}
public void playSoundForAll(String sound) {
for (Player pl : Bukkit.getOnlinePlayers()) {
playSound(pl, sound);
}
for (Player pl : Bukkit.getOnlinePlayers()) playSound(pl, sound);
}
public void playSoundForAll(List<String> sounds) {
for (Player pl : Bukkit.getOnlinePlayers()) {
playSound(pl, sounds);
}
for (Player pl : Bukkit.getOnlinePlayers()) playSound(pl, sounds);
}
public void playSound(Player p, List<String> sounds) {
for (String sound : sounds) {
playSound(p, sound);
}
for (String sound : sounds) playSound(p, sound);
}
public void playSound(Player p, String sound) {
@@ -176,9 +169,7 @@ public class FactionsPlugin extends MPlugin {
migrateFPlayerLeaders();
log("==== End Setup ====");
if (!preEnable()) {
return;
}
if (!preEnable()) return;
this.loadSuccessful = false;
if (!new File(this.getDataFolder() + "/config.yml").exists()) {
@@ -201,7 +192,7 @@ public class FactionsPlugin extends MPlugin {
return;
}
//Update their config if needed
// Updater.updateIfNeeded(getConfig());
// Updater.updateIfNeeded(getConfig());
RegisteredServiceProvider<Economy> rsp = FactionsPlugin.this.getServer().getServicesManager().getRegistration(Economy.class);
FactionsPlugin.econ = rsp.getProvider();
com.massivecraft.factions.integration.Essentials.setup();
@@ -216,16 +207,10 @@ public class FactionsPlugin extends MPlugin {
fPlayer.resetFactionData(false);
continue;
}
if (fPlayer.isAlt()) {
faction.addAltPlayer(fPlayer);
} else {
faction.addFPlayer(fPlayer);
}
if (fPlayer.isAlt()) faction.addAltPlayer(fPlayer);
else faction.addFPlayer(fPlayer);
}
if (getConfig().getBoolean("enable-faction-flight", true)) {
UtilFly.run();
}
Board.getInstance().load();
Board.getInstance().clean();
@@ -250,9 +235,7 @@ public class FactionsPlugin extends MPlugin {
log("Minecraft Version 1.9 or higher found, using non packet based particle API");
}
if (getConfig().getBoolean("enable-faction-flight")) {
factionsFlight = true;
}
if (getConfig().getBoolean("enable-faction-flight")) factionsFlight = true;
if (getServer().getPluginManager().getPlugin("Skript") != null) {
log("Skript was found! Registering FactionsPlugin Addon...");
@@ -288,7 +271,6 @@ public class FactionsPlugin extends MPlugin {
new FactionsEntityListener(),
new FactionsExploitListener(),
new FactionsBlockListener(),
new FUpgradesGUI(),
new UpgradesListener(),
new MissionHandler(this),
new FChestListener(),
@@ -317,14 +299,10 @@ public class FactionsPlugin extends MPlugin {
json = "[]";
}
reserveObjects = this.getGsonBuilder().create().fromJson(json, new ListParameterizedType(ReserveObject.class));
if (reserveObjects == null) {
reserveObjects = new ArrayList<>();
}
}
catch (Exception e) {
if (reserveObjects == null) reserveObjects = new ArrayList<>();
} catch (Exception e) {
e.printStackTrace();
}
if (getDescription().getFullName().contains("BETA")) {
divider();
System.out.println("You are using a BETA version of the plugin!");
@@ -381,7 +359,6 @@ public class FactionsPlugin extends MPlugin {
try {
BufferedReader br = new BufferedReader(new FileReader(fplayerFile));
System.out.println("Migrating old players.json file.");
String line;
while ((line = br.readLine()) != null) {
if (line.contains("\"role\": \"ADMIN\"")) {
@@ -413,9 +390,7 @@ public class FactionsPlugin extends MPlugin {
private boolean setupPermissions() {
try {
RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class);
if (rsp != null) {
perms = rsp.getProvider();
}
if (rsp != null) perms = rsp.getProvider();
} catch (NoClassDefFoundError ex) {
return false;
}
@@ -453,15 +428,17 @@ public class FactionsPlugin extends MPlugin {
@Override
public void onDisable() {
// only save data if plugin actually completely loaded successfully
if (this.loadSuccessful) {
Conf.saveSync();
}
if (this.loadSuccessful) Conf.saveSync();
if (AutoLeaveTask != null) {
this.getServer().getScheduler().cancelTask(AutoLeaveTask);
AutoLeaveTask = null;
}
DiscordListener.saveGuilds();
if (Discord.jda != null) {
Discord.jda.shutdownNow();
}
super.onDisable();
try {
fLogManager.saveLogs();
@@ -472,9 +449,7 @@ public class FactionsPlugin extends MPlugin {
public void startAutoLeaveTask(boolean restartIfRunning) {
if (AutoLeaveTask != null) {
if (!restartIfRunning) {
return;
}
if (!restartIfRunning) return;
this.getServer().getScheduler().cancelTask(AutoLeaveTask);
}
@@ -526,9 +501,7 @@ public class FactionsPlugin extends MPlugin {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] split) {
if (split.length == 0) {
return handleCommand(sender, "/f help", false);
}
if (split.length == 0) return handleCommand(sender, "/f help", false);
// otherwise, needs to be handled; presumably another plugin directly ran the command
String cmd = Conf.baseCommandAliases.isEmpty() ? "/f" : "/" + Conf.baseCommandAliases.get(0);
@@ -541,8 +514,6 @@ public class FactionsPlugin extends MPlugin {
// Must be a LinkedList to prevent UnsupportedOperationException.
List<String> argsList = new LinkedList<>(Arrays.asList(args));
CommandContext context = new CommandContext(sender, argsList, alias);
String cmd = Conf.baseCommandAliases.isEmpty() ? "/f" : "/" + Conf.baseCommandAliases.get(0);
// String cmdValid = (cmd + " " + TextUtil.implode(context.args, " ")).trim();
List<FCommand> commandsList = cmdBase.subCommands;
FCommand commandsEx = cmdBase;
List<String> completions = new ArrayList<>();
@@ -571,16 +542,12 @@ public class FactionsPlugin extends MPlugin {
}
}
String lastArg = args[args.length - 1].toLowerCase();
completions = completions.stream()
.filter(m -> m.toLowerCase().startsWith(lastArg))
.collect(Collectors.toList());
return completions;
} else {
String lastArg = args[args.length - 1].toLowerCase();
for (Role value : Role.values()) completions.add(value.nicename);
for (Relation value : Relation.values()) completions.add(value.nicename);
// The stream and foreach from the old implementation looped 2 times, by looping all players -> filtered -> looped filter and added -> filtered AGAIN at the end.
@@ -619,11 +586,8 @@ public class FactionsPlugin extends MPlugin {
// Does player have Faction Chat enabled? If so, chat plugins should preferably not do channels,
// local chat, or anything else which targets individual recipients, so Faction Chat can be done
public boolean isPlayerFactionChatting(Player player) {
if (player == null) {
return false;
}
if (player == null) return false;
FPlayer me = FPlayers.getInstance().getByPlayer(player);
return me != null && me.getChatMode().isAtLeast(ChatMode.ALLIANCE);
}
@@ -644,15 +608,11 @@ public class FactionsPlugin extends MPlugin {
public String getPlayerFactionTagRelation(Player speaker, Player listener) {
String tag = "~";
if (speaker == null) {
return tag;
}
if (speaker == null) return tag;
FPlayer me = FPlayers.getInstance().getByPlayer(speaker);
if (me == null) {
return tag;
}
if (me == null) return tag;
// if listener isn't set, or config option is disabled, give back uncolored tag
if (listener == null || !Conf.chatTagRelationColored) {
tag = me.getChatTag().trim();
@@ -660,15 +620,11 @@ public class FactionsPlugin extends MPlugin {
FPlayer you = FPlayers.getInstance().getByPlayer(listener);
if (you == null) {
tag = me.getChatTag().trim();
} else // everything checks out, give the colored tag
{
} else { // everything checks out, give the colored tag
tag = me.getChatTag(you).trim();
}
}
if (tag.isEmpty()) {
tag = "~";
}
if (tag.isEmpty()) tag = "~";
return tag;
}
@@ -683,15 +639,9 @@ public class FactionsPlugin extends MPlugin {
// Get a player's title within their faction, mainly for usage by chat plugins for local/channel chat
public String getPlayerTitle(Player player) {
if (player == null) {
return "";
}
if (player == null) return "";
FPlayer me = FPlayers.getInstance().getByPlayer(player);
if (me == null) {
return "";
}
if (me == null) return "";
return me.getTitle().trim();
}
@@ -702,9 +652,7 @@ public class FactionsPlugin extends MPlugin {
//colors a string list
public List<String> colorList(List<String> lore) {
for (int i = 0; i <= lore.size() - 1; i++) {
lore.set(i, color(lore.get(i)));
}
for (int i = 0; i <= lore.size() - 1; i++) lore.set(i, color(lore.get(i)));
return lore;
}
@@ -722,9 +670,7 @@ public class FactionsPlugin extends MPlugin {
Set<String> players = new HashSet<>();
Faction faction = Factions.getInstance().getByTag(factionTag);
if (faction != null) {
for (FPlayer fplayer : faction.getFPlayers()) {
players.add(fplayer.getName());
}
for (FPlayer fplayer : faction.getFPlayers()) players.add(fplayer.getName());
}
return players;
}
@@ -734,9 +680,7 @@ public class FactionsPlugin extends MPlugin {
Set<String> players = new HashSet<>();
Faction faction = Factions.getInstance().getByTag(factionTag);
if (faction != null) {
for (FPlayer fplayer : faction.getFPlayersWhereOnline(true)) {
players.add(fplayer.getName());
}
for (FPlayer fplayer : faction.getFPlayersWhereOnline(true)) players.add(fplayer.getName());
}
return players;
}
@@ -756,9 +700,7 @@ public class FactionsPlugin extends MPlugin {
}
public void debug(Level level, String s) {
if (getConfig().getBoolean("debug", false)) {
getLogger().log(level, s);
}
if (getConfig().getBoolean("debug", false)) getLogger().log(level, s);
}
public FactionsPlayerListener getFactionsPlayerListener() {

View File

@@ -46,7 +46,7 @@ public class Aliases {
public static ArrayList<String> relation_truce = new ArrayList<>(Collections.singletonList("truce"));
public static ArrayList<String> reserve = new ArrayList<>(Collections.singletonList("reserve"));
public static ArrayList<String> roles_demote = new ArrayList<>(Collections.singletonList("demote"));
public static ArrayList<String> roles_promote = new ArrayList<>(Collections.singletonList("ally"));
public static ArrayList<String> roles_promote = new ArrayList<>(Collections.singletonList("promote"));
public static ArrayList<String> tnt_tnt = new ArrayList<>(Collections.singletonList("tnt"));
public static ArrayList<String> tnt_tntfill = new ArrayList<>(Collections.singletonList("tntfill"));
public static ArrayList<String> wild = new ArrayList<>(Collections.singletonList("wild"));

View File

@@ -70,7 +70,7 @@ public class CmdAdmin extends FCommand {
// if target player is currently admin, demote and replace him
if (fyou == admin) {
targetFaction.promoteNewLeader();
promoteNewLeader(targetFaction);
context.msg(TL.COMMAND_ADMIN_DEMOTES, fyou.describeTo(context.fPlayer, true));
fyou.msg(TL.COMMAND_ADMIN_DEMOTED, context.player == null ? TL.GENERIC_SERVERADMIN.toString() : context.fPlayer.describeTo(fyou, true));
return;
@@ -78,9 +78,9 @@ public class CmdAdmin extends FCommand {
// promote target player, and demote existing admin if one exists
if (admin != null) {
admin.setRole(Role.COLEADER);
setRole(admin, Role.COLEADER);
}
fyou.setRole(Role.LEADER);
setRole(fyou, Role.LEADER);
context.msg(TL.COMMAND_ADMIN_PROMOTES, fyou.describeTo(context.fPlayer, true));
FactionsPlugin.instance.getFlogManager().log(targetFaction, FLogType.RANK_EDIT, context.fPlayer.getName(), fyou.getName(), ChatColor.RED + "Admin");
@@ -94,6 +94,18 @@ public class CmdAdmin extends FCommand {
});
}
private void setRole(FPlayer fp, Role r) {
FactionsPlugin.getInstance().getServer().getScheduler().runTask(FactionsPlugin.instance, () -> {
fp.setRole(r);
});
}
private void promoteNewLeader(Faction f) {
FactionsPlugin.getInstance().getServer().getScheduler().runTask(FactionsPlugin.instance, () -> {
f.promoteNewLeader();
});
}
public TL getUsageTranslation() {
return TL.COMMAND_ADMIN_DESCRIPTION;
}

View File

@@ -82,19 +82,19 @@ public class CmdDisband extends FCommand {
String amountString = context.sender instanceof ConsoleCommandSender ? TL.GENERIC_SERVERADMIN.toString() : context.fPlayer.describeTo(follower);
if (follower.getFaction() == faction) {
follower.msg(TL.COMMAND_DISBAND_BROADCAST_YOURS, amountString);
if (!follower.canFlyAtLocation()) {
if (!follower.canFlyAtLocation() && FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight")) {
follower.setFFlying(false, false);
}
} else {
follower.msg(TL.COMMAND_DISBAND_BROADCAST_NOTYOURS, amountString, faction.getTag(follower));
}
}
context.fPlayer.setFFlying(false, false);
if(FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight")) context.fPlayer.setFFlying(false, false);
} else {
context.player.sendMessage(String.valueOf(TL.COMMAND_DISBAND_PLAYER));
}
faction.disband(context.player, PlayerDisbandReason.COMMAND);
if (!context.fPlayer.canFlyAtLocation()) {
if (!context.fPlayer.canFlyAtLocation() && FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight")) {
context.fPlayer.setFFlying(false, false);
}
}

View File

@@ -9,6 +9,7 @@ import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
@@ -34,7 +35,7 @@ public class CmdFly extends FCommand {
this.aliases.addAll(Aliases.fly);
this.optionalArgs.put("on/off", "flip");
this.requirements = new CommandRequirements.Builder(Permission.FLY)
this.requirements = new CommandRequirements.Builder(Permission.FLY_FLY)
.playerOnly()
.memberOnly()
.build();
@@ -78,19 +79,15 @@ public class CmdFly extends FCommand {
}
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player);
Faction myFaction = fPlayer.getFaction();
if (myFaction.isWilderness()) {
fPlayer.setFlying(false);
flyMap.remove(name);
continue;
}
if (player.hasPermission("factions.fly.bypassnearbyenemycheck") || fPlayer.checkIfNearbyEnemies()) {
if (!player.hasPermission("factions.fly.bypassnearbyenemycheck") && !fPlayer.isAdminBypassing()) {
if (fPlayer.hasEnemiesNearby()) disableFlightSync(fPlayer);
checkEnemiesSync(fPlayer);
continue;
}
FLocation myFloc = new FLocation(player.getLocation());
if (Board.getInstance().getFactionAt(myFloc) != myFaction) {
if (!checkBypassPerms(fPlayer, player, Board.getInstance().getFactionAt(myFloc))) {
Bukkit.getScheduler().runTask(FactionsPlugin.instance, () -> fPlayer.setFFlying(false, false));
flyMap.remove(name);
if (!checkFly(fPlayer, player, Board.getInstance().getFactionAt(myFloc))) {
disableFlightSync(fPlayer);
}
}
@@ -100,36 +97,15 @@ public class CmdFly extends FCommand {
}, 20L, 20L);
}
public static boolean checkBypassPerms(FPlayer fme, Player me, Faction toFac) {
public static boolean checkFly(FPlayer fme, Player me, Faction toFac) {
if (Conf.denyFlightIfInNoClaimingWorld && !Conf.worldsNoClaiming.isEmpty() && Conf.worldsNoClaiming.stream().anyMatch(me.getWorld().getName()::equalsIgnoreCase))
return false;
if (toFac != fme.getFaction()) {
if (!me.hasPermission(Permission.FLY_WILD.node) && toFac.isWilderness() || !me.hasPermission(Permission.FLY_SAFEZONE.node) && toFac.isSafeZone() || !me.hasPermission(Permission.FLY_WARZONE.node) && toFac.isWarZone()) {
fme.msg(TL.COMMAND_FLY_NO_ACCESS, toFac.getTag(fme));
return false;
}
Access access = toFac.getAccess(fme, PermissableAction.FLY);
if ((!(me.hasPermission(Permission.FLY_ENEMY.node) || access == Access.ALLOW)) && toFac.getRelationTo(fme.getFaction()) == Relation.ENEMY) {
fme.msg(TL.COMMAND_FLY_NO_ACCESS, toFac.getTag(fme));
return false;
}
if (!(me.hasPermission(Permission.FLY_ALLY.node) || access == Access.ALLOW) && toFac.getRelationTo(fme.getFaction()) == Relation.ALLY) {
fme.msg(TL.COMMAND_FLY_NO_ACCESS, toFac.getTag(fme));
return false;
}
if (!(me.hasPermission(Permission.FLY_TRUCE.node) || access == Access.ALLOW) && toFac.getRelationTo(fme.getFaction()) == Relation.TRUCE) {
fme.msg(TL.COMMAND_FLY_NO_ACCESS, toFac.getTag(fme));
return false;
}
if (!(me.hasPermission(Permission.FLY_NEUTRAL.node) || access == Access.ALLOW) && toFac.getRelationTo(fme.getFaction()) == Relation.NEUTRAL && !toFac.isSystemFaction()) {
fme.msg(TL.COMMAND_FLY_NO_ACCESS, toFac.getTag(fme));
return false;
}
return me.hasPermission(Permission.FLY.node) && (access != Access.DENY || toFac.isSystemFaction());
}
return true;
if (toFac.getAccess(fme, PermissableAction.FLY) == Access.ALLOW) return true;
if (fme.getFaction().isWilderness()) return false;
if (toFac.isSystemFaction()) return me.hasPermission(Permission.valueOf("FLY_" + ChatColor.stripColor(toFac.getTag()).toUpperCase()).node);
Relation relationTo = toFac.getRelationTo(fme.getFaction());
if (!relationTo.isEnemy() && !relationTo.isMember()) return me.hasPermission(Permission.valueOf("FLY_" + relationTo.name()).node);
return false;
}
@@ -145,34 +121,43 @@ public class CmdFly extends FCommand {
flyMap.remove(fme.getPlayer().getName());
}
private static void disableFlightSync(FPlayer fme) {
Bukkit.getScheduler().runTask(FactionsPlugin.instance, () -> fme.setFFlying(false, false));
flyMap.remove(fme.getName());
}
public boolean isInFlightChecker(Player player) {
return flyMap.containsKey(player.getName());
}
private static void checkEnemiesSync(FPlayer fp) {
Bukkit.getScheduler().runTask(FactionsPlugin.instance, fp::checkIfNearbyEnemies);
}
@Override
public void perform(CommandContext context) {
// Disabled by default.
if (!FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight", false)) {
context.fPlayer.msg(TL.COMMAND_FLY_DISABLED);
return;
}
if (!context.fPlayer.isAdminBypassing()) {
List<Entity> entities = context.player.getNearbyEntities(16.0D, 256.0D, 16.0D);
FLocation myfloc = new FLocation(context.player.getLocation());
Faction toFac = Board.getInstance().getFactionAt(myfloc);
if (!checkBypassPerms(context.fPlayer, context.player, toFac)) return;
List<Entity> entities = context.player.getNearbyEntities(16.0D, 256.0D, 16.0D);
for (int i = 0; i <= entities.size() - 1; ++i) {
if (entities.get(i) instanceof Player) {
Player eplayer = (Player) entities.get(i);
FPlayer efplayer = FPlayers.getInstance().getByPlayer(eplayer);
if (efplayer.getRelationTo(context.fPlayer) == Relation.ENEMY && !efplayer.isStealthEnabled()) {
context.msg(TL.COMMAND_FLY_CHECK_ENEMY);
return;
for (int i = 0; i <= entities.size() - 1; ++i) {
if (entities.get(i) instanceof Player) {
Player eplayer = (Player) entities.get(i);
FPlayer efplayer = FPlayers.getInstance().getByPlayer(eplayer);
if (efplayer.getRelationTo(context.fPlayer) == Relation.ENEMY && !efplayer.isStealthEnabled()) {
context.msg(TL.COMMAND_FLY_CHECK_ENEMY);
return;
}
context.fPlayer.setEnemiesNearby(false);
}
}
}
FLocation myfloc = new FLocation(context.player.getLocation());
Faction toFac = Board.getInstance().getFactionAt(myfloc);
if (!checkFly(context.fPlayer, context.player, toFac)) {
context.fPlayer.sendMessage(TL.COMMAND_FLY_NO_ACCESS.format(toFac.getTag()));
return;
}
}
if (context.args.size() == 0) {
toggleFlight(context.fPlayer.isFlying(), context.fPlayer, context);
@@ -188,8 +173,6 @@ public class CmdFly extends FCommand {
return;
}
if (fme.canFlyAtLocation()) {
context.doWarmUp(WarmUpUtil.Warmup.FLIGHT, TL.WARMUPS_NOTIFY_FLIGHT, "Fly", () -> {
fme.setFlying(true);
flyMap.put(fme.getPlayer().getName(), true);
@@ -201,9 +184,6 @@ public class CmdFly extends FCommand {
startFlyCheck();
}
}, FactionsPlugin.getInstance().getConfig().getLong("warmups.f-fly", 0));
} else {
fme.msg(TL.COMMAND_FLY_NO_ACCESS, Board.getInstance().getFactionAt(fme.getLastStoodAt()).getTag());
}
}
@Override

View File

@@ -2,7 +2,7 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.fupgrades.FUpgradesGUI;
import com.massivecraft.factions.zcore.fupgrades.FUpgradeFrame;
import com.massivecraft.factions.zcore.util.TL;
public class CmdUpgrades extends FCommand {
@@ -19,7 +19,6 @@ public class CmdUpgrades extends FCommand {
.playerOnly()
.memberOnly()
.build();
}
@Override
@@ -28,7 +27,7 @@ public class CmdUpgrades extends FCommand {
context.fPlayer.msg(TL.COMMAND_UPGRADES_DISABLED);
return;
}
new FUpgradesGUI().openMainMenu(context.fPlayer);
new FUpgradeFrame(context.faction).buildGUI(context.fPlayer);
}
@Override

View File

@@ -268,7 +268,6 @@ public class FCmdRoot extends FCommand implements CommandExecutor {
this.addSubCommand(this.cmdPromote);
this.addSubCommand(this.cmdDebug);
this.addSubCommand(this.cmdDemote);
this.addSubCommand(this.cmdDiscord);
this.addSubCommand(this.cmdSetDefaultRole);
this.addSubCommand(this.cmdMapHeight);
this.addSubCommand(this.cmdClaimAt);

View File

@@ -61,19 +61,20 @@ public class CmdTntFill extends FCommand {
int radius = context.argAsInt(0, 0); // We don't know the max yet, so let's not assume.
int amount = context.argAsInt(1, 0); // We don't know the max yet, so let's not assume.
if (amount < 0) {
if (amount <= 0 || radius <= 0) {
context.msg(TL.COMMAND_TNT_POSITIVE);
return;
}
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.instance.getConfig().getInt("Tntfill.max-amount")) {
context.msg(TL.COMMAND_TNTFILL_AMOUNTMAX.toString().replace("{max}", FactionsPlugin.instance.getConfig().getInt("Tntfill.max-amount") + ""));
return;
}
// How many dispensers are we to fill in?
Location start = context.player.getLocation();
@@ -111,7 +112,7 @@ 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.

View File

@@ -32,7 +32,7 @@ public class FPlayerRoleChangeEvent extends FactionPlayerEvent implements Cancel
@Override
public boolean isCancelled() {
return false;
return cancelled;
}
@Override

View File

@@ -552,7 +552,6 @@ public class FactionsPlayerListener implements Listener {
public String parseAllPlaceholders(String string, Faction faction, Player player) {
string = TagUtil.parsePlaceholders(player, string);
string = string.replace("{Faction}", faction.getTag())
.replace("{online}", faction.getOnlinePlayers().size() + "")
.replace("{offline}", faction.getFPlayers().size() - faction.getOnlinePlayers().size() + "")
@@ -563,27 +562,19 @@ public class FactionsPlayerListener implements Listener {
}
public void checkCanFly(FPlayer me) {
if (!FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight")) return;
if (me.isFlying() && (!me.canFlyAtLocation() || me.checkIfNearbyEnemies())) {
me.setFFlying(false, false);
me.msg(TL.COMMAND_FLY_NO_ACCESS, Board.getInstance().getFactionAt(me.getLastStoodAt()).getTag());
return;
}
if (me.isFlying() || !FactionsPlugin.instance.getConfig().getBoolean("ffly.AutoEnable"))
return;
if (me.isFlying() || !FactionsPlugin.instance.getConfig().getBoolean("ffly.AutoEnable")) return;
me.setFFlying(true, false);
CmdFly.flyMap.put(me.getName(), true);
if (CmdFly.particleTask == null)
CmdFly.startParticles();
}
@EventHandler
public void onCommand(PlayerCommandPreprocessEvent e){
if(e.getMessage().equalsIgnoreCase("/f outpost")){
e.setMessage("/outpost");
}
}
//inspect
@EventHandler
public void onInspect(PlayerInteractEvent e) {
@@ -677,7 +668,7 @@ public class FactionsPlayerListener implements Listener {
if (!fPlayer.checkIfNearbyEnemies()) {
FLocation myFloc = new FLocation(player.getLocation());
if (Board.getInstance().getFactionAt(myFloc) != myFaction) {
if (!CmdFly.checkBypassPerms(fPlayer, player, Board.getInstance().getFactionAt(myFloc))) {
if (!CmdFly.checkFly(fPlayer, player, Board.getInstance().getFactionAt(myFloc))) {
fPlayer.setFFlying(false, false);
CmdFly.flyMap.remove(name);
}

View File

@@ -62,19 +62,12 @@ public class ShopGUIFrame {
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
meta.addEnchant(Enchantment.DURABILITY, 1, true);
}
if (!glowing) {
meta.removeEnchant(Enchantment.DURABILITY);
}
if (!glowing) meta.removeEnchant(Enchantment.DURABILITY);
List<String> replacedLore = lore.stream().map(t -> t.replace("{cost}", cost + "")).collect(Collectors.toList());
meta.setLore(FactionsPlugin.instance.colorList(replacedLore));
item.setItemMeta(meta);
GUIItems.set(slot, new GuiItem(item, e -> {
e.setCancelled(true);
FPlayer fme = FPlayers.getInstance().getByPlayer((Player) e.getWhoClicked());
if (fplayer.getFaction().getPoints() >= cost) {
fplayer.getFaction().setPoints(fplayer.getFaction().getPoints() - cost);

View File

@@ -44,8 +44,8 @@ public enum Permission {
DISBAND_ANY("disband.any"),
DISCORD("discord"),
DRAIN("drain"),
FLY("fly"),
FLY_WILD("fly.wilderness"),
FLY_FLY("fly"),
FLY_WILDERNESS("fly.wilderness"),
FLY_SAFEZONE("fly.safezone"),
FLY_WARZONE("fly.warzone"),
FLY_ENEMY("fly.enemy"),

View File

@@ -10,7 +10,10 @@ import org.bukkit.Bukkit;
public class UtilFly {
/**
* UtilFly is being removed very soon as all of its functionality has been updated and moved to CmdFly
*/
@Deprecated
public static void run() {
if (!FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight"))
return;
@@ -22,7 +25,7 @@ public class UtilFly {
}
}, 0, FactionsPlugin.getInstance().getConfig().getInt("fly-task-interval", 10));
}
@Deprecated
public static void setFly(FPlayer fp, boolean fly, boolean silent, boolean damage) {
if (!FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight"))
return;
@@ -42,7 +45,7 @@ public class UtilFly {
setFallDamage(fp, fly, damage);
}
@Deprecated
public static void checkFly(FPlayer me, Faction factionTo) {
if (!FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight"))
return;

View File

@@ -0,0 +1,113 @@
package com.massivecraft.factions.zcore.fupgrades;
import com.github.stefvanschie.inventoryframework.Gui;
import com.github.stefvanschie.inventoryframework.GuiItem;
import com.github.stefvanschie.inventoryframework.pane.PaginatedPane;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.util.XMaterial;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List;
/**
* @author Saser
*/
public class FUpgradeFrame {
private Gui gui;
public FUpgradeFrame(Faction f) {
this.gui = new Gui(FactionsPlugin.getInstance(),
FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.rows", 5),
FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Title").replace("{faction}", f.getTag()));
}
public void buildGUI(FPlayer fplayer) {
PaginatedPane pane = new PaginatedPane(0, 0, 9, this.gui.getRows());
List<GuiItem> GUIItems = new ArrayList<>();
ItemStack dummy = buildDummyItem();
for (int x = 0; x <= this.gui.getRows() * 9 - 1; ++x)
GUIItems.add(new GuiItem(dummy, (e) -> e.setCancelled(true)));
for (UpgradeType value : UpgradeType.values()) {
if (value.getSlot() != -1) {
GUIItems.set(value.getSlot(), new GuiItem(value.buildAsset(fplayer.getFaction()), (e) -> {
e.setCancelled(true);
FPlayer fme = FPlayers.getInstance().getByPlayer((Player) e.getWhoClicked());
if (fme.getFaction().getUpgrade(value) != value.getMaxLevel()) {
int cost = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu." + value.toString() + ".Cost.level-" + (fme.getFaction().getUpgrade(value) + 1));
if (fme.hasMoney(cost)) {
fme.takeMoney(cost);
if (value == UpgradeType.CHEST)
updateChests(fme.getFaction());
if (value == UpgradeType.POWER)
updateFactionPowerBoost(fme.getFaction());
if (value == UpgradeType.TNT)
updateTNT(fme.getFaction());
if (value == UpgradeType.WARP)
updateWarps(fme.getFaction());
fme.getFaction().setUpgrade(value, fme.getFaction().getUpgrade(value) + 1);
this.buildGUI(fme);
}
}
}));
}
}
pane.populateWithGuiItems(GUIItems);
gui.addPane(pane);
gui.update();
gui.show(fplayer.getPlayer());
}
private void updateWarps(Faction faction) {
int level = faction.getUpgrade(UpgradeType.WARP);
int size = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Warps.warp-limit.level-" + (level + 1));
faction.setWarpsLimit(size);
}
private void updateTNT(Faction faction) {
int level = faction.getUpgrade(UpgradeType.TNT);
int size = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.TNT.tnt-limit.level-" + (level + 1));
faction.setTntBankLimit(size);
}
private void updateChests(Faction faction) {
String invName = FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fchest.Inventory-Title"));
for (Player player : faction.getOnlinePlayers()) {
if (player.getOpenInventory().getTitle().equalsIgnoreCase(invName)) player.closeInventory();
}
int level = faction.getUpgrade(UpgradeType.CHEST);
int size = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Chest.Chest-Size.level-" + (level + 1));
faction.setChestSize(size * 9);
}
private void updateFactionPowerBoost(Faction f) {
double boost = FactionsPlugin.getInstance().getConfig().getDouble("fupgrades.MainMenu.Power.Power-Boost.level-" + (f.getUpgrade(UpgradeType.POWER) + 1));
if (boost < 0.0) return;
f.setPowerBoost(f.getPower() + boost);
}
private ItemStack buildDummyItem() {
ConfigurationSection config = FactionsPlugin.getInstance().getConfig().getConfigurationSection("fupgrades.MainMenu.DummyItem");
ItemStack item = XMaterial.matchXMaterial(config.getString("Type")).parseItem();
ItemMeta meta = item.getItemMeta();
if (meta != null) {
meta.setLore(FactionsPlugin.getInstance().colorList(config.getStringList("Lore")));
meta.setDisplayName(FactionsPlugin.getInstance().color(config.getString("Name")));
item.setItemMeta(meta);
}
return item;
}
}

View File

@@ -1,667 +0,0 @@
package com.massivecraft.factions.zcore.fupgrades;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.util.XMaterial;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.HumanEntity;
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.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.List;
public class FUpgradesGUI implements Listener {
/**
* @author Illyria Team
*/
public void openMainMenu(FPlayer fme) {
Inventory inventory = Bukkit.createInventory(null, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.DummyItem.rows") * 9, FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Title").replace("{faction}", fme.getFaction().getTag())));
ItemStack dummyItem = XMaterial.matchXMaterial(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.DummyItem.Type")).parseItem();
ItemMeta meta = dummyItem.getItemMeta();
meta.setLore(FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fupgrades.MainMenu.DummyItem.Lore")));
meta.setDisplayName(FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.DummyItem.Name")));
dummyItem.setItemMeta(meta);
for (int fill = 0; fill < FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.DummyItem.rows") * 9; ++fill) {
inventory.setItem(fill, dummyItem);
}
ItemStack[] items = buildItems(fme);
List<Integer> cropSlots = FactionsPlugin.getInstance().getConfig().getIntegerList("fupgrades.MainMenu.Crops.CropItem.slots");
List<Integer> spawnerSlots = FactionsPlugin.getInstance().getConfig().getIntegerList("fupgrades.MainMenu.Spawners.SpawnerItem.slots");
List<Integer> expSlots = FactionsPlugin.getInstance().getConfig().getIntegerList("fupgrades.MainMenu.EXP.EXPItem.slots");
List<Integer> chestSlots = FactionsPlugin.getInstance().getConfig().getIntegerList("fupgrades.MainMenu.Chest.ChestItem.slots");
List<Integer> powerSlots = FactionsPlugin.getInstance().getConfig().getIntegerList("fupgrades.MainMenu.Power.PowerItem.slots");
List<Integer> redSlots = FactionsPlugin.getInstance().getConfig().getIntegerList("fupgrades.MainMenu.Redstone.RedstoneItem.slots");
List<Integer> memberSlots = FactionsPlugin.getInstance().getConfig().getIntegerList("fupgrades.MainMenu.Members.MembersItem.slots");
List<Integer> reductSlots = FactionsPlugin.getInstance().getConfig().getIntegerList("fupgrades.MainMenu.DamageReduct.ReduceItem.slots");
List<Integer> increaseSlots = FactionsPlugin.getInstance().getConfig().getIntegerList("fupgrades.MainMenu.DamageIncrease.IncreaseItem.slots");
List<Integer> tntSlots = FactionsPlugin.getInstance().getConfig().getIntegerList("fupgrades.MainMenu.TNT.TntItem.slots");
List<Integer> warpSlots = FactionsPlugin.getInstance().getConfig().getIntegerList("fupgrades.MainMenu.Warps.WarpItem.slots");
List<Integer> armorSlots = FactionsPlugin.getInstance().getConfig().getIntegerList("fupgrades.MainMenu.Armor.ArmorItem.slots");
for (Integer cropSlot : cropSlots) if (cropSlot != -1) inventory.setItem(cropSlot, items[2]);
for (Integer spawnerSlot : spawnerSlots) if (spawnerSlot != -1) inventory.setItem(spawnerSlot, items[1]);
for (Integer expSlot : expSlots) if (expSlot != -1) inventory.setItem(expSlot, items[0]);
for (Integer chestSlot : chestSlots) if (chestSlot != -1) inventory.setItem(chestSlot, items[3]);
for (Integer powerSlot : powerSlots) if (powerSlot != -1) inventory.setItem(powerSlot, items[4]);
for (Integer redSlot : redSlots) if (redSlot != -1) inventory.setItem(redSlot, items[5]);
for (Integer memberSlot : memberSlots) if (memberSlot != -1) inventory.setItem(memberSlot, items[6]);
for (Integer reduceSlot : reductSlots) if (reduceSlot != -1) inventory.setItem(reduceSlot, items[7]);
for (Integer increaseSlot : increaseSlots) if (increaseSlot != -1) inventory.setItem(increaseSlot, items[8]);
for(Integer tntSlot : tntSlots) if(tntSlot != -1) inventory.setItem(tntSlot, items[9]);
for(Integer warpSlot : warpSlots) if(warpSlot != -1) inventory.setItem(warpSlot, items[10]);
for(Integer armorSlot : armorSlots) if(armorSlot != -1) inventory.setItem(armorSlot, items[11]);
fme.getPlayer().openInventory(inventory);
}
@EventHandler
public void onClick(InventoryClickEvent e) {
if (e.getClickedInventory() == null || e.getCurrentItem() == null || e.getCurrentItem().getItemMeta() == null || e.getCursor() == null)
return;
FPlayer fme = FPlayers.getInstance().getByPlayer((Player) e.getWhoClicked());
if (e.getView().getTitle().equalsIgnoreCase(FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Title").replace("{faction}", fme.getFaction().getTag())))) {
e.setCancelled(true);
ItemStack[] items = buildItems(fme);
ItemStack cropItem = items[2];
ItemStack expItem = items[0];
ItemStack chestitem = items[3];
ItemStack spawnerItem = items[1];
ItemStack powerItem = items[4];
ItemStack redItem = items[5];
ItemStack memberItem = items[6];
ItemStack reduceItem = items[7];
ItemStack increaseItem = items[8];
ItemStack tntItem = items[9];
ItemStack warpItem = items[10];
ItemStack armorItem = items[11];
if (e.getCurrentItem().equals(cropItem)) {
int cropLevel = fme.getFaction().getUpgrade(UpgradeType.CROP);
switch (cropLevel) {
case 3:
return;
case 2:
upgradeItem(fme, UpgradeType.CROP, 3, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Crops.Cost.level-3"));
break;
case 1:
upgradeItem(fme, UpgradeType.CROP, 2, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Crops.Cost.level-2"));
break;
case 0:
upgradeItem(fme, UpgradeType.CROP, 1, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Crops.Cost.level-1"));
break;
}
} else if (e.getCurrentItem().equals(powerItem)) {
int powerLevel = fme.getFaction().getUpgrade(UpgradeType.POWER);
switch (powerLevel) {
case 3:
return;
case 2:
upgradeItem(fme, UpgradeType.POWER, 3, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Power.Cost.level-3"));
updatePower(fme.getFaction());
break;
case 1:
upgradeItem(fme, UpgradeType.POWER, 2, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Power.Cost.level-2"));
updatePower(fme.getFaction());
break;
case 0:
upgradeItem(fme, UpgradeType.POWER, 1, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Power.Cost.level-1"));
updatePower(fme.getFaction());
break;
}
} else if (e.getCurrentItem().equals(spawnerItem)) {
int spawnerLevel = fme.getFaction().getUpgrade(UpgradeType.SPAWNER);
switch (spawnerLevel) {
case 3:
return;
case 2:
upgradeItem(fme, UpgradeType.SPAWNER, 3, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Spawners.Cost.level-3"));
break;
case 1:
upgradeItem(fme, UpgradeType.SPAWNER, 2, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Spawners.Cost.level-2"));
break;
case 0:
upgradeItem(fme, UpgradeType.SPAWNER, 1, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Spawners.Cost.level-1"));
break;
}
} else if (e.getCurrentItem().equals(expItem)) {
int expLevel = fme.getFaction().getUpgrade(UpgradeType.EXP);
switch (expLevel) {
case 3:
return;
case 2:
upgradeItem(fme, UpgradeType.EXP, 3, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.EXP.Cost.level-3"));
break;
case 1:
upgradeItem(fme, UpgradeType.EXP, 2, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.EXP.Cost.level-2"));
break;
case 0:
upgradeItem(fme, UpgradeType.EXP, 1, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.EXP.Cost.level-1"));
break;
}
} else if (e.getCurrentItem().equals(redItem)) {
int redLevel = fme.getFaction().getUpgrade(UpgradeType.REDSTONE);
switch (redLevel) {
case 1:
return;
case 0:
upgradeItem(fme, UpgradeType.REDSTONE, 1, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Redstone.Cost"));
break;
}
} else if (e.getCurrentItem().equals(chestitem)) {
int chestLevel = fme.getFaction().getUpgrade(UpgradeType.CHEST);
switch (chestLevel) {
case 3:
return;
case 2: {
if (upgradeItem(fme, UpgradeType.CHEST, 3, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Chest.Cost.level-3")))
updateChests(fme.getFaction());
break;
}
case 1: {
if (upgradeItem(fme, UpgradeType.CHEST, 2, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Chest.Cost.level-2")))
updateChests(fme.getFaction());
break;
}
case 0: {
if (upgradeItem(fme, UpgradeType.CHEST, 1, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Chest.Cost.level-1")))
updateChests(fme.getFaction());
break;
}
}
} else if (e.getCurrentItem().equals(armorItem)) {
int armorLevel = fme.getFaction().getUpgrade(UpgradeType.REINFORCEDARMOR);
switch (armorLevel) {
case 3:
return;
case 2: {
if (upgradeItem(fme, UpgradeType.REINFORCEDARMOR, 3, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Armor.Cost.level-3")))
break;
}
case 1: {
if (upgradeItem(fme, UpgradeType.REINFORCEDARMOR, 2, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Armor.Cost.level-2")))
break;
}
case 0: {
if (upgradeItem(fme, UpgradeType.REINFORCEDARMOR, 1, FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Armor.Cost.level-1")))
break;
}
}
} else if (e.getCurrentItem().equals(memberItem)) {
int memberLevel = fme.getFaction().getUpgrade(UpgradeType.MEMBERS) + 1;
if (!FactionsPlugin.getInstance().getConfig().isSet("fupgrades.MainMenu.Members.Cost.level-" + memberLevel)) {
return;
}
int cost = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Members.Cost.level-" + memberLevel);
if (hasMoney(fme, cost)) {
fme.getFaction().setUpgrade(UpgradeType.MEMBERS, memberLevel);
fme.getPlayer().closeInventory();
takeMoney(fme, cost);
}
} else if (e.getCurrentItem().equals(reduceItem)) {
int reduceLevel = fme.getFaction().getUpgrade(UpgradeType.DAMAGEDECREASE) + 1;
if (!FactionsPlugin.getInstance().getConfig().isSet("fupgrades.MainMenu.DamageReduct.Cost.level-" + reduceLevel)) {
return;
}
int cost = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.DamageReduct.Cost.level-" + reduceLevel);
if (hasMoney(fme, cost)) {
fme.getFaction().setUpgrade(UpgradeType.DAMAGEDECREASE, reduceLevel);
fme.getPlayer().closeInventory();
takeMoney(fme, cost);
}
} else if (e.getCurrentItem().equals(increaseItem)) {
int increaseLevel = fme.getFaction().getUpgrade(UpgradeType.DAMAGEINCREASE) + 1;
if (!FactionsPlugin.getInstance().getConfig().isSet("fupgrades.MainMenu.DamageIncrease.Cost.level-" + increaseLevel)) {
return;
}
int cost = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.DamageIncrease.Cost.level-" + increaseLevel);
if (hasMoney(fme, cost)) {
fme.getFaction().setUpgrade(UpgradeType.DAMAGEINCREASE, increaseLevel);
fme.getPlayer().closeInventory();
takeMoney(fme, cost);
}
} else if(e.getCurrentItem().equals(tntItem)){
int tntLevel = fme.getFaction().getUpgrade(UpgradeType.TNT) + 1;
if (!FactionsPlugin.getInstance().getConfig().isSet("fupgrades.MainMenu.TNT.Cost.level-" + tntLevel)) {
return;
}
int cost = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.TNT.Cost.level-" + tntLevel);
if (hasMoney(fme, cost)) {
fme.getFaction().setUpgrade(UpgradeType.TNT, tntLevel);
fme.getPlayer().closeInventory();
takeMoney(fme, cost);
updateTntBanks(fme.getFaction());
}
} else if(e.getCurrentItem().equals(warpItem)){
int warpLevel = fme.getFaction().getUpgrade(UpgradeType.WARP) + 1;
if (!FactionsPlugin.getInstance().getConfig().isSet("fupgrades.MainMenu.Warps.Cost.level-" + warpLevel)) {
return;
}
int cost = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Warps.Cost.level-" + warpLevel);
if (hasMoney(fme, cost)) {
fme.getFaction().setUpgrade(UpgradeType.WARP, warpLevel);
fme.getPlayer().closeInventory();
takeMoney(fme, cost);
setWarpLimit(fme.getFaction());
}
}
}
}
private void updateChests(Faction faction) {
String invName = FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fchest.Inventory-Title"));
for (HumanEntity player : faction.getChestInventory().getViewers()) {
if (player.getOpenInventory().getTitle() != null && player.getOpenInventory().getTitle().equalsIgnoreCase(invName))
player.closeInventory();
}
int level = faction.getUpgrade(UpgradeType.CHEST);
int size = FactionsPlugin.getInstance().getConfig().getInt("fchest.Default-Size");
switch (level) {
case 1:
size = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Chest.Chest-Size.level-1");
break;
case 2:
size = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Chest.Chest-Size.level-2");
break;
case 3:
size = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Chest.Chest-Size.level-3");
break;
}
faction.setChestSize(size * 9);
}
private void updatePower(Faction faction) {
int level = faction.getUpgrade(UpgradeType.POWER);
double power = 0.0;
switch (level) {
case 1:
power = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Power.Power-Boost.level-1");
break;
case 2:
power = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Power.Power-Boost.level-2");
break;
case 3:
power = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Power.Power-Boost.level-3");
break;
}
faction.setPowerBoost(power);
}
@SuppressWarnings("Duplicates")
private ItemStack[] buildItems(FPlayer fme) {
byte expData = (byte) (FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.EXP.EXPItem.Damage"));
Material expMaterial = XMaterial.parseMaterial(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.EXP.EXPItem.Type"), expData);
int expAmt = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.EXP.EXPItem.Amount");
String expName = FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.EXP.EXPItem.Name"));
List<String> expLore = FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fupgrades.MainMenu.EXP.EXPItem.Lore"));
int expLevel = fme.getFaction().getUpgrade(UpgradeType.EXP);
for (int i = 0; i <= expLore.size() - 1; i++)
expLore.set(i, expLore.get(i).replace("{level}", expLevel + ""));
ItemStack expItem = FactionsPlugin.getInstance().createItem(expMaterial, expAmt, expData, expName, expLore);
if (expLevel >= 1) {
ItemMeta itemMeta = expItem.getItemMeta();
if (!FactionsPlugin.getInstance().mc17) {
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
}
itemMeta.addEnchant(Enchantment.DURABILITY, 3, true);
expItem.setItemMeta(itemMeta);
expItem.setAmount(expLevel);
}
byte spawnerData = (byte) (FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Spawners.SpawnerItem.Damage"));
Material spawnerMaterial = XMaterial.parseMaterial(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Spawners.SpawnerItem.Type"), spawnerData);
int spawnerAmt = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Spawners.SpawnerItem.Amount");
String spawnerName = FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Spawners.SpawnerItem.Name"));
List<String> spawnerLore = FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fupgrades.MainMenu.Spawners.SpawnerItem.Lore"));
int spawnerLevel = fme.getFaction().getUpgrade(UpgradeType.SPAWNER);
for (int i = 0; i <= spawnerLore.size() - 1; i++) {
spawnerLore.set(i, spawnerLore.get(i).replace("{level}", spawnerLevel + ""));
}
byte cropData = (byte) (FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Crops.CropItem.Damage"));
Material cropMaterial = XMaterial.parseMaterial(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Crops.CropItem.Type"), cropData);
int cropAmt = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Crops.CropItem.Amount");
String cropName = FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Crops.CropItem.Name"));
List<String> cropLore = FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fupgrades.MainMenu.Crops.CropItem.Lore"));
int cropLevel = fme.getFaction().getUpgrade(UpgradeType.CROP);
for (int i = 0; i <= cropLore.size() - 1; i++) {
String line = cropLore.get(i);
line = line.replace("{level}", cropLevel + "");
cropLore.set(i, line);
}
ItemStack cropItem = FactionsPlugin.getInstance().createItem(cropMaterial, cropAmt, cropData, cropName, cropLore);
cropItem.getItemMeta().setLore(cropLore);
if (cropLevel >= 1) {
ItemMeta itemMeta = cropItem.getItemMeta();
if (!FactionsPlugin.getInstance().mc17) {
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
}
itemMeta.addEnchant(Enchantment.DURABILITY, 3, true);
cropItem.setItemMeta(itemMeta);
cropItem.setAmount(cropLevel);
}
ItemStack spawnerItem = FactionsPlugin.getInstance().createItem(spawnerMaterial, spawnerAmt, spawnerData, spawnerName, spawnerLore);
spawnerItem.getItemMeta().setLore(spawnerLore);
if (spawnerLevel >= 1) {
ItemMeta itemMeta = spawnerItem.getItemMeta();
if (!FactionsPlugin.getInstance().mc17) {
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
}
itemMeta.addEnchant(Enchantment.DURABILITY, 3, true);
spawnerItem.setItemMeta(itemMeta);
spawnerItem.setAmount(spawnerLevel);
}
byte chestData = (byte) (FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Chest.ChestItem.Damage"));
Material chestMaterial = XMaterial.parseMaterial(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Chest.ChestItem.Type"), chestData);
int chestAmt = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Chest.ChestItem.Amount");
String chestName = FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Chest.ChestItem.Name", "&e&lUpgrade Chest Size"));
List<String> chestLore = FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fupgrades.MainMenu.Chest.ChestItem.Lore"));
int chestlevel = fme.getFaction().getUpgrade(UpgradeType.CHEST);
for (int i = 0; i <= chestLore.size() - 1; i++) {
String line = chestLore.get(i);
line = line.replace("{level}", chestlevel + "");
chestLore.set(i, line);
}
ItemStack chestItem = FactionsPlugin.getInstance().createItem(chestMaterial, chestAmt, chestData, chestName, chestLore);
if (chestlevel >= 1) {
ItemMeta itemMeta = chestItem.getItemMeta();
if (!FactionsPlugin.getInstance().mc17) {
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
}
itemMeta.addEnchant(Enchantment.DURABILITY, 3, true);
chestItem.setItemMeta(itemMeta);
chestItem.setAmount(chestlevel);
}
byte memberData = (byte) (FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Members.MembersItem.Damage"));
Material memberMaterial = XMaterial.parseMaterial(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Members.MembersItem.Type"), memberData);
int memberAmt = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Members.MembersItem.Amount");
String memberName = FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Members.MembersItem.Name", "&e&lUpgrade Member Size"));
List<String> memberLore = FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fupgrades.MainMenu.Members.MembersItem.Lore"));
int memberlevel = fme.getFaction().getUpgrade(UpgradeType.MEMBERS);
for (int i = 0; i <= memberLore.size() - 1; i++) {
String line = memberLore.get(i);
line = line.replace("{level}", memberlevel + "");
memberLore.set(i, line);
}
ItemStack memberItem = FactionsPlugin.getInstance().createItem(memberMaterial, memberAmt, memberData, memberName, memberLore);
if (memberlevel >= 1) {
ItemMeta itemMeta = memberItem.getItemMeta();
if (!FactionsPlugin.getInstance().mc17) {
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
}
itemMeta.addEnchant(Enchantment.DURABILITY, 3, true);
memberItem.setItemMeta(itemMeta);
memberItem.setAmount(memberlevel);
}
byte powerData = (byte) (FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Power.PowerItem.Damage"));
Material powerMaterial = XMaterial.parseMaterial(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Power.PowerItem.Type"), powerData);
int powerAmt = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Power.PowerItem.Amount");
String powerName = FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Power.PowerItem.Name"));
List<String> powerLore = FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fupgrades.MainMenu.Power.PowerItem.Lore"));
int powerLevel = fme.getFaction().getUpgrade(UpgradeType.POWER);
for (int i = 0; i <= powerLore.size() - 1; i++) {
String line = powerLore.get(i);
line = line.replace("{level}", powerLevel + "");
powerLore.set(i, line);
}
ItemStack powerItem = FactionsPlugin.getInstance().createItem(powerMaterial, powerAmt, powerData, powerName, powerLore);
powerItem.getItemMeta().setLore(powerLore);
if (powerLevel >= 1) {
ItemMeta itemMeta = powerItem.getItemMeta();
if (!FactionsPlugin.getInstance().mc17) {
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
}
itemMeta.addEnchant(Enchantment.DURABILITY, 3, true);
powerItem.setItemMeta(itemMeta);
powerItem.setAmount(powerLevel);
}
byte redData = (byte) (FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Redstone.RedstoneItem.Damage"));
Material redMaterial = XMaterial.parseMaterial(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Redstone.RedstoneItem.Type"), redData);
int redAmt = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Redstone.RedstoneItem.Amount");
String redName = FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Redstone.RedstoneItem.Name"));
List<String> redLore = FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fupgrades.MainMenu.Redstone.RedstoneItem.Lore"));
int redLevel = fme.getFaction().getUpgrade(UpgradeType.REDSTONE);
for (int i = 0; i <= redLore.size() - 1; i++) {
String line = redLore.get(i);
line = line.replace("{level}", redLevel + "");
redLore.set(i, line);
}
ItemStack redItem = FactionsPlugin.getInstance().createItem(redMaterial, redAmt, redData, redName, redLore);
redItem.getItemMeta().setLore(redLore);
if (redLevel >= 1) {
ItemMeta itemMeta = redItem.getItemMeta();
if (!FactionsPlugin.getInstance().mc17) {
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
}
itemMeta.addEnchant(Enchantment.DURABILITY, 3, true);
redItem.setItemMeta(itemMeta);
redItem.setAmount(redLevel);
}
byte reduceData = (byte) (FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.DamageReduct.ReduceItem.Damage"));
Material reduceMaterial = XMaterial.parseMaterial(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.DamageReduct.ReduceItem.Type"), reduceData);
int reduceAmt = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.DamageReduct.ReduceItem.Amount");
String reduceName = FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.DamageReduct.ReduceItem.Name"));
List<String> reduceLore = FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fupgrades.MainMenu.DamageReduct.ReduceItem.Lore"));
int reduceLevel = fme.getFaction().getUpgrade(UpgradeType.DAMAGEDECREASE);
for (int i = 0; i <= reduceLore.size() - 1; i++) {
String line = reduceLore.get(i);
line = line.replace("{level}", reduceLevel + "");
reduceLore.set(i, line);
}
ItemStack reduceItem = FactionsPlugin.getInstance().createItem(reduceMaterial, reduceAmt, reduceData, reduceName, reduceLore);
reduceItem.getItemMeta().setLore(reduceLore);
if (reduceLevel >= 1) {
ItemMeta itemMeta = reduceItem.getItemMeta();
if (!FactionsPlugin.getInstance().mc17) {
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
}
itemMeta.addEnchant(Enchantment.DURABILITY, 3, true);
reduceItem.setItemMeta(itemMeta);
reduceItem.setAmount(reduceLevel);
}
byte increaseData = (byte) (FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.DamageIncrease.IncreaseItem.Damage"));
Material increaseMaterial = XMaterial.parseMaterial(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.DamageIncrease.IncreaseItem.Type"), increaseData);
int increaseAmt = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.DamageIncrease.IncreaseItem.Amount");
String increaseName = FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.DamageIncrease.IncreaseItem.Name"));
List<String> increaseLore = FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fupgrades.MainMenu.DamageIncrease.IncreaseItem.Lore"));
int increaseLevel = fme.getFaction().getUpgrade(UpgradeType.DAMAGEINCREASE);
for (int i = 0; i <= increaseLore.size() - 1; i++) {
String line = increaseLore.get(i);
line = line.replace("{level}", increaseLevel + "");
increaseLore.set(i, line);
}
ItemStack increaseItem = FactionsPlugin.getInstance().createItem(increaseMaterial, increaseAmt, increaseData, increaseName, increaseLore);
increaseItem.getItemMeta().setLore(increaseLore);
if (increaseLevel >= 1) {
ItemMeta itemMeta = increaseItem.getItemMeta();
if (!FactionsPlugin.getInstance().mc17) {
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
}
itemMeta.addEnchant(Enchantment.DURABILITY, 3, true);
increaseItem.setItemMeta(itemMeta);
increaseItem.setAmount(increaseLevel);
}
byte tntData = (byte) (FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.TNT.TntItem.Damage"));
Material tntMaterial = XMaterial.parseMaterial(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.TNT.TntItem.Type"), tntData);
int tntAmt = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.TNT.TntItem.Amount");
String tntName = FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.TNT.TntItem.Name"));
List<String> tntLore = FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fupgrades.MainMenu.TNT.TntItem.Lore"));
int tntLevel = fme.getFaction().getUpgrade(UpgradeType.TNT);
for (int i = 0; i <= tntLore.size() - 1; i++) {
String line = tntLore.get(i);
line = line.replace("{level}", tntLevel + "");
tntLore.set(i, line);
}
ItemStack tntItem = FactionsPlugin.getInstance().createItem(tntMaterial, tntAmt, tntData, tntName, tntLore);
tntItem.getItemMeta().setLore(tntLore);
if (tntLevel >= 1) {
ItemMeta itemMeta = tntItem.getItemMeta();
if (!FactionsPlugin.getInstance().mc17) {
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
}
itemMeta.addEnchant(Enchantment.DURABILITY, 3, true);
tntItem.setItemMeta(itemMeta);
tntItem.setAmount(tntLevel);
}
byte warpData = (byte) (FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Warps.WarpItem.Damage"));
Material warpMaterial = XMaterial.parseMaterial(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Warps.WarpItem.Type"), warpData);
int warpAmt = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Warps.WarpItem.Amount");
String warpName = FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Warps.WarpItem.Name"));
List<String> warpLore = FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fupgrades.MainMenu.Warps.WarpItem.Lore"));
int warpLevel = fme.getFaction().getUpgrade(UpgradeType.WARP);
for (int i = 0; i <= warpLore.size() - 1; i++) {
String line = warpLore.get(i);
line = line.replace("{level}", warpLevel + "");
warpLore.set(i, line);
}
ItemStack warpItem = FactionsPlugin.getInstance().createItem(warpMaterial, warpAmt, warpData, warpName, warpLore);
warpItem.getItemMeta().setLore(warpLore);
if (warpLevel >= 1) {
ItemMeta itemMeta = warpItem.getItemMeta();
if (!FactionsPlugin.getInstance().mc17) {
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
}
itemMeta.addEnchant(Enchantment.DURABILITY, 3, true);
warpItem.setItemMeta(itemMeta);
warpItem.setAmount(warpLevel);
}
byte armorData = (byte) (FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Armor.ArmorItem.Damage"));
Material armorMaterial = XMaterial.parseMaterial(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Armor.ArmorItem.Type"), warpData);
int armorAmt = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Armor.ArmorItem.Amount");
String armorName = FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fupgrades.MainMenu.Armor.ArmorItem.Name"));
List<String> armorLore = FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fupgrades.MainMenu.Armor.ArmorItem.Lore"));
int armorLevel = fme.getFaction().getUpgrade(UpgradeType.REINFORCEDARMOR);
for (int i = 0; i <= armorLore.size() - 1; i++) {
String line = armorLore.get(i);
line = line.replace("{level}", armorLevel + "");
armorLore.set(i, line);
}
ItemStack armorItem = FactionsPlugin.getInstance().createItem(armorMaterial, armorAmt, armorData, armorName, armorLore);
armorItem.getItemMeta().setLore(armorLore);
if (armorLevel >= 1) {
ItemMeta itemMeta = armorItem.getItemMeta();
if (!FactionsPlugin.getInstance().mc17) {
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
}
itemMeta.addEnchant(Enchantment.DURABILITY, 3, true);
armorItem.setItemMeta(itemMeta);
armorItem.setAmount(armorLevel);
}
return new ItemStack[]{expItem, spawnerItem, cropItem, chestItem, powerItem, redItem, memberItem, reduceItem, increaseItem, tntItem, warpItem, armorItem};
}
private void updateTntBanks(Faction faction) {
int level = faction.getUpgrade(UpgradeType.TNT);
int size = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.TNT.tnt-limit.level-" + (level));
faction.setTntBankLimit(size);
}
private void setWarpLimit(Faction faction) {
int level = faction.getUpgrade(UpgradeType.WARP);
int size = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Warps.warp-limit.level-" + (level));
faction.setWarpsLimit(size);
}
private boolean hasMoney(FPlayer fme, int amt) {
return fme.hasMoney(amt);
}
private boolean takeMoney(FPlayer fme, int amt) {
return fme.takeMoney(amt);
}
private boolean upgradeItem(FPlayer fme, UpgradeType upgrade, int level, int cost) {
if (hasMoney(fme, cost)) {
if (!takeMoney(fme, cost)) {return false;}
fme.getFaction().setUpgrade(upgrade, level);
fme.getPlayer().closeInventory();
return true;
}
return false;
}
}

View File

@@ -1,32 +1,103 @@
package com.massivecraft.factions.zcore.fupgrades;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.util.Placeholder;
import com.massivecraft.factions.util.XMaterial;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import java.lang.reflect.Field;
import java.util.UUID;
public enum UpgradeType {
/**
* @author Illyria Team
*/
CHEST("Chest"),
SPAWNER("Spawner"),
EXP("Exp"),
CROP("Crop"),
POWER("Power"),
REDSTONE("Redstone"),
MEMBERS("Members"),
TNT("TNT"),
WARP("Warps"),
DAMAGEINCREASE("DamageIncrease"),
DAMAGEDECREASE("DamageDecrease"),
REINFORCEDARMOR("ReinforcedArmor");
CHEST("Chest", 3),
SPAWNER("Spawners", 3),
EXP("EXP", 3),
CROP("Crops", 3),
POWER("Power", 3),
REDSTONE("Redstone", 1),
MEMBERS("Members", 3),
TNT("TNT", 3),
WARP("Warps", 3),
DAMAGEINCREASE("DamageIncrease", 3),
DAMAGEDECREASE("DamageReduct", 3),
REINFORCEDARMOR("Armor", 3);
private String id;
private int maxLevel;
UpgradeType(String id) {
UpgradeType(String id, int maxLevel) {
this.id = id;
this.maxLevel = maxLevel;
}
@Override
public String toString() {
return this.id;
}
public int getSlot() {
return FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu." + this.id + ".DisplayItem.Slot");
}
public int getMaxLevel() {
return this.maxLevel;
}
public ItemStack buildAsset(Faction f) {
ConfigurationSection config = FactionsPlugin.getInstance().getConfig().getConfigurationSection("fupgrades.MainMenu." + this.id + ".DisplayItem");
ItemStack item = XMaterial.matchXMaterial(config.getString("Type")).parseItem();
int level = f.getUpgrade(this);
ItemMeta meta = item.getItemMeta();
if (meta != null) {
meta.setLore(FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().replacePlaceholders(config.getStringList("Lore"), new Placeholder("{level}", level + ""))));
meta.setDisplayName(FactionsPlugin.getInstance().color(config.getString("Name")));
item.setItemMeta(meta);
if (XMaterial.matchXMaterial(item) == XMaterial.PLAYER_HEAD && config.isSet("Texture")) {
SkullMeta skullMeta = (SkullMeta) meta;
GameProfile profile = new GameProfile(UUID.randomUUID(), null);
profile.getProperties().put("textures", new Property("textures", config.getString("Texture")));
Field profileField;
try {
profileField = meta.getClass().getDeclaredField("profile");
profileField.setAccessible(true);
profileField.set(meta, profile);
} catch (IllegalAccessException | NoSuchFieldException | SecurityException | IllegalArgumentException e) {
e.printStackTrace();
}
item.setItemMeta(skullMeta);
}
}
return this.updateLevelStatus(item, level);
}
private ItemStack updateLevelStatus(ItemStack item, int level) {
if (level >= 1) {
item.setAmount(level);
enchant(item);
}
return item;
}
private ItemStack enchant(ItemStack item) {
ItemMeta itemMeta = item.getItemMeta();
if (itemMeta != null) {
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
itemMeta.addEnchant(Enchantment.DURABILITY, 1, true);
item.setItemMeta(itemMeta);
}
return item;
}
}

View File

@@ -47,6 +47,7 @@ import java.util.*;
*/
public abstract class MemoryFPlayer implements FPlayer {
public boolean enemiesNearby = false;
public boolean inChest = false;
public boolean discordSetup = false;
public String discordUserID = "";
@@ -221,6 +222,10 @@ public abstract class MemoryFPlayer implements FPlayer {
return this.notificationsEnabled;
}
public boolean hasEnemiesNearby() {return this.enemiesNearby;}
public void setEnemiesNearby(Boolean b) {this.enemiesNearby = b;}
public boolean discordSetup() {return this.discordSetup;}
public String discordUserID() {return this.discordUserID;}
@@ -972,7 +977,7 @@ public abstract class MemoryFPlayer implements FPlayer {
public boolean canFlyAtLocation(FLocation location) {
Faction faction = Board.getInstance().getFactionAt(location);
if ((faction == getFaction() && getRole() == Role.LEADER) || isAdminBypassing) return true;
if (faction.isSystemFaction()) return CmdFly.checkBypassPerms(this, getPlayer(), faction);
if (faction.isSystemFaction()) return CmdFly.checkFly(this, getPlayer(), faction);
Access access = faction.getAccess(this, PermissableAction.FLY);
return access == null || access == Access.UNDEFINED || access == Access.ALLOW;
}
@@ -1108,16 +1113,18 @@ public abstract class MemoryFPlayer implements FPlayer {
setFlying(false);
msg(TL.COMMAND_FLY_ENEMY_NEAR);
Bukkit.getServer().getPluginManager().callEvent(new FPlayerStoppedFlying(this));
this.enemiesNearby = true;
return true;
}
}
}
this.enemiesNearby = false;
return false;
}
@Override
public Boolean canflyinWilderness() {
return getPlayer().hasPermission(Permission.FLY_WILD.node);
return getPlayer().hasPermission(Permission.FLY_WILDERNESS.node);
}
@Override

View File

@@ -147,16 +147,16 @@ scoreboard:
# {maxPower} - player's max power.
# {powerBoost} - player's powerboost.
default-enabled: false # Default to false to keep original functionality.
######################################################
##################### SCOREBOARD #####################
######################################################
default-enabled: false # This is to enable or disable the scoreboard: false = Disabled
default-title: "&cSaberFactions" # Can use any of the values from above but this won't update once it's set (so don't set {balance}).
default-update-interval: 2 # in seconds.
# This will show faction prefixes colored based on relation on nametags and in the tab.
# The scoreboard needs to be enabled for this to work.
default-prefixes: true
# SUPPORTS PLACEHOLDERS
default:
- "&7&m--------------------------"
- "&4&lFaction Info &8»"
@@ -185,6 +185,7 @@ scoreboard:
- "&7&m---------------------------"
# Configration section for warmups.
# Warmup times are in seconds - if a value of 0 is set, there is no warmup.
warmups:
@@ -900,9 +901,9 @@ fchest:
fupgrades:
Enabled: true
MainMenu:
Rows: 5
Title: '&8&l{faction}''s Upgrade Menu'
DummyItem:
rows: 5
Name: '&f'
Type: BLACK_STAINED_GLASS_PANE
Lore:
@@ -916,11 +917,10 @@ fupgrades:
level-1: 250000
level-2: 500000
level-3: 750000
CropItem:
DisplayItem:
Name: '&c&lGrowth Speed'
Type: WHEAT
Amount: 1
Damage: 0
Type: WHEAT #MUST BE PLAYER_HEAD FOR TEXTURE TO WORK!
Texture: '' #Hash of skull here from minecraft-heads.com
Lore:
- '&7&oIncrease growth &c&ospeed&7&o of crops in &c&oclaims.'
- '&7&oChance to Grow Two Levels.'
@@ -937,8 +937,7 @@ fupgrades:
- '&4&l* &cLevel 3: &f$750,000'
- ''
- '&7&o(( Tip: &f&oleft-click&7&o to &c&oupgrade&7&o ))'
slots:
- 31
Slot: 31
EXP:
EXP-Boost:
level-1: 1.5
@@ -948,11 +947,10 @@ fupgrades:
level-1: 2000000
level-2: 4000000
level-3: 6000000
EXPItem:
DisplayItem:
Name: '&c&lEXP Drop Rate'
Type: EXP_BOTTLE
Amount: 1
Damage: 0
Type: EXP_BOTTLE #MUST BE PLAYER_HEAD FOR TEXTURE TO WORK!
Texture: '' #Hash of skull here from minecraft-heads.com
Lore:
- '&7&oIncreased Vanilla &e&oEXP&7&o gained from &c&omonsters&7&o.'
- '&7&oYour current level is &e&l&o{level}'
@@ -968,8 +966,7 @@ fupgrades:
- '&4&l* &cLevel 3: &f$6,000,000'
- ''
- '&7&o(( Tip: &f&oleft-click&7&o to &c&oupgrade&7&o ))'
slots:
- 32
Slot: 32
Power:
Power-Boost:
level-1: 100.0
@@ -979,11 +976,10 @@ fupgrades:
level-1: 1000000
level-2: 2000000
level-3: 3000000
PowerItem:
DisplayItem:
Name: '&c&lFaction Power'
Type: NETHER_STAR
Amount: 1
Damage: 0
Type: NETHER_STAR #MUST BE PLAYER_HEAD FOR TEXTURE TO WORK!
Texture: '' #Hash of skull here from minecraft-heads.com
Lore:
- '&a&oIncrease&7&o the amount of &c&opower'
- '&7&oyour &a&ofaction has&7&o.'
@@ -1000,15 +996,14 @@ fupgrades:
- '&4&l* &cLevel 3: &f$3,000,000'
- ''
- '&7&o(( Tip: &f&oleft-click&7&o to &c&oupgrade&7&o ))'
slots:
- 22
Slot: 22
Redstone:
Cost: 1000000
RedstoneItem:
Cost:
level-1: 1000000
DisplayItem:
Name: '&c&lUnbreakable Redstone'
Type: REDSTONE
Amount: 1
Damage: 0
Type: REDSTONE #MUST BE PLAYER_HEAD FOR TEXTURE TO WORK!
Texture: '' #Hash of skull here from minecraft-heads.com
Lore:
- '&7&oPrevents &e&owater&7&o from being'
- '&7&oable to break &c&oredstone'
@@ -1016,8 +1011,7 @@ fupgrades:
- '&4&l* &cCost: &f$1,000,000'
- ''
- '&7&o(( Tip: &f&oLeft-click&7&o to &c&oupgrade&7&o ))'
slots:
- 23
Slot: 23
Spawners:
Spawner-Boost:
# This is a Percentage so .10 means 10% lowered spawner delay!
@@ -1028,11 +1022,10 @@ fupgrades:
level-1: 1000000
level-2: 2000000
level-3: 3000000
SpawnerItem:
DisplayItem:
Name: '&c&lSpawn Rate'
Type: MOB_SPAWNER
Amount: 1
Damage: 0
Type: MOB_SPAWNER #MUST BE PLAYER_HEAD FOR TEXTURE TO WORK!
Texture: '' #Hash of skull here from minecraft-heads.com
Lore:
- '&c&oDecreased&7&o mob spawner delay in &a&oclaims&7&o.'
- '&7&oYour current level is &e&l&o{level}'
@@ -1048,8 +1041,7 @@ fupgrades:
- '&4&l* &cLevel 3: &f$3,000,000'
- ''
- '&7&o(( Tip: &f&oleft-click&7&o to &c&oupgrade&7&o ))'
slots:
- 30
Slot: 30
DamageReduct:
DamageReductPercent:
level-1: 3
@@ -1059,11 +1051,10 @@ fupgrades:
level-1: 2000000
level-2: 4000000
level-3: 6000000
ReduceItem:
DisplayItem:
Name: '&c&lDamage Reduction'
Type: GOLD_CHESTPLATE
Amount: 1
Damage: 0
Type: GOLD_CHESTPLATE #MUST BE PLAYER_HEAD FOR TEXTURE TO WORK!
Texture: '' #Hash of skull here from minecraft-heads.com
Lore:
- '&a&oReduce&7&o the amount of &a&odamage taken&7&o in faction claims.'
- '&7&oYour current level is &e&l&o{level}'
@@ -1079,8 +1070,7 @@ fupgrades:
- '&4&l* &cLevel 3: &f$6,000,000'
- ''
- '&7&o(( Tip: &f&oleft-click&7&o to &c&oupgrade&7&o ))'
slots:
- 7
Slot: 7
DamageIncrease:
DamageIncreasePercent:
level-1: 3
@@ -1090,11 +1080,10 @@ fupgrades:
level-1: 2000000
level-2: 4000000
level-3: 6000000
IncreaseItem:
DisplayItem:
Name: '&c&lDamage Increase'
Type: DIAMOND_SWORD
Amount: 1
Damage: 0
Type: DIAMOND_SWORD #MUST BE PLAYER_HEAD FOR TEXTURE TO WORK!
Texture: '' #Hash of skull here from minecraft-heads.com
Lore:
- '&a&oIncrease&7&o the amount of &a&odamage given&7&o.'
- '&7&oYour current level is &e&l&o{level}'
@@ -1110,8 +1099,7 @@ fupgrades:
- '&4&l* &cLevel 3: &f$6,000,000'
- ''
- '&7&o(( Tip: &f&oleft-click&7&o to &c&oupgrade&7&o ))'
slots:
- 1
Slot: 1
TNT:
tnt-limit:
level-1: 500000
@@ -1121,11 +1109,10 @@ fupgrades:
level-1: 2000000
level-2: 4000000
level-3: 6000000
TntItem:
DisplayItem:
Name: '&c&lTNT Bank'
Type: TNT
Amount: 1
Damage: 0
Type: TNT #MUST BE PLAYER_HEAD FOR TEXTURE TO WORK!
Texture: '' #Hash of skull here from minecraft-heads.com
Lore:
- '&a&oUpgrade&7&o your &a&ofactions tnt&7&o limit.'
- '&7&oYour current level is &e&l&o{level}'
@@ -1141,8 +1128,7 @@ fupgrades:
- '&4&l* &cLevel 3: &f$3,000,000'
- ''
- '&7&o(( Tip: &f&oleft-click&7&o to &c&oupgrade&7&o ))'
slots:
- 21
Slot: 21
Warps:
warp-limit:
level-1: 3
@@ -1152,11 +1138,10 @@ fupgrades:
level-1: 1000000
level-2: 2000000
level-3: 3000000
WarpItem:
DisplayItem:
Name: '&c&lWarps'
Type: EYE_OF_ENDER
Amount: 1
Damage: 0
Type: EYE_OF_ENDER #MUST BE PLAYER_HEAD FOR TEXTURE TO WORK!
Texture: '' #Hash of skull here from minecraft-heads.com
Lore:
- '&a&oIncrease&7&o the &a&ofaction warp&7&o limit.'
- '&7&oYour current level is &e&l&o{level}'
@@ -1172,8 +1157,7 @@ fupgrades:
- '&4&l* &cLevel 3: &f$3,000,000'
- ''
- '&7&o(( Tip: &f&oleft-click&7&o to &c&oupgrade&7&o ))'
slots:
- 24
Slot: 24
Chest:
Chest-Size:
# This is rows
@@ -1184,11 +1168,10 @@ fupgrades:
level-1: 1000000
level-2: 2000000
level-3: 3000000
ChestItem:
DisplayItem:
Name: '&c&lFaction Chest'
Type: CHEST
Amount: 1
Damage: 0
Type: CHEST #MUST BE PLAYER_HEAD FOR TEXTURE TO WORK!
Texture: '' #Hash of skull here from minecraft-heads.com
Lore:
- '&a&oIncreased&7&o Faction Chest Size.'
- '&7&oYour current level is &e&l&o{level}'
@@ -1204,8 +1187,7 @@ fupgrades:
- '&4&l* &cLevel 3: &f$3,000,000'
- ''
- '&7&o(( Tip: &f&oleft-click&7&o to &c&oupgrade&7&o ))'
slots:
- 20
Slot: 20
Members:
Members-Limit:
level-1: 30
@@ -1215,11 +1197,10 @@ fupgrades:
level-1: 1000000
level-2: 2000000
level-3: 3000000
MembersItem:
DisplayItem:
Name: '&c&lFaction Members'
Type: PAPER
Amount: 1
Damage: 0
Type: PAPER #MUST BE PLAYER_HEAD FOR TEXTURE TO WORK!
Texture: '' #Hash of skull here from minecraft-heads.com
Lore:
- '&a&oIncrease&7&o the &a&ofaction member&7&o limit.'
- '&7&oYour current level is &e&l&o{level}'
@@ -1235,8 +1216,7 @@ fupgrades:
- '&4&l* &cLevel 3: &f$3,000,000'
- ''
- '&7&o(( Tip: &f&oleft-click&7&o to &c&oupgrade&7&o ))'
slots:
- 40
Slot: 40
Armor:
Armor-HP-Drop:
# HP Drop is in percent so .10 would mean it would drop 10% of the damage to the armor
@@ -1247,11 +1227,10 @@ fupgrades:
level-1: 1000000
level-2: 2000000
level-3: 3000000
ArmorItem:
DisplayItem:
Name: '&c&lReinforced Armor'
Type: DIAMOND_CHESTPLATE
Amount: 1
Damage: 0
Type: DIAMOND_CHESTPLATE #MUST BE PLAYER_HEAD FOR TEXTURE TO WORK!
Texture: '' #Hash of skull here from minecraft-heads.com
Lore:
- '&a&oDecreases&7&o damage done &a&oto armor&7&o.'
- '&7&oYour current level is &e&l&o{level}'
@@ -1267,8 +1246,7 @@ fupgrades:
- '&4&l* &cLevel 3: &f$3,000,000'
- ''
- '&7&o(( Tip: &f&oleft-click&7&o to &c&oupgrade&7&o ))'
slots:
- 4
Slot: 4
############################################################
# +------------------------------------------------------+ #