Merge pull request #112 from SaberLLC/beta

Beta
This commit is contained in:
Driftay 2020-05-08 20:21:55 -04:00 committed by GitHub
commit 66f2fd22f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 287 additions and 591 deletions

View File

@ -279,8 +279,7 @@ public class Conf {
/// Useful for HCF features. /// Useful for HCF features.
/// </summary> /// </summary>
public static Set<Material> territoryBypassProtectedMaterials = EnumSet.noneOf(Material.class); public static Set<Material> territoryBypassProtectedMaterials = EnumSet.noneOf(Material.class);
// Dependency check
public static boolean dependencyCheck = true;
public static boolean enableClickToClaim = true; public static boolean enableClickToClaim = true;
public static Set<Material> territoryCancelAndAllowItemUseMaterial = new HashSet<>(); public static Set<Material> territoryCancelAndAllowItemUseMaterial = new HashSet<>();
@ -561,7 +560,6 @@ public class Conf {
territoryDenyUsageMaterials.add(Material.ARMOR_STAND); territoryDenyUsageMaterials.add(Material.ARMOR_STAND);
} }
territoryProtectedMaterialsWhenOffline.add(Material.BEACON); territoryProtectedMaterialsWhenOffline.add(Material.BEACON);
territoryDenyUsageMaterialsWhenOffline.add(XMaterial.FIRE_CHARGE.parseMaterial()); territoryDenyUsageMaterialsWhenOffline.add(XMaterial.FIRE_CHARGE.parseMaterial());

View File

@ -21,7 +21,6 @@ import com.massivecraft.factions.integration.Worldguard;
import com.massivecraft.factions.integration.dynmap.EngineDynmap; import com.massivecraft.factions.integration.dynmap.EngineDynmap;
import com.massivecraft.factions.listeners.*; import com.massivecraft.factions.listeners.*;
import com.massivecraft.factions.missions.MissionHandler; import com.massivecraft.factions.missions.MissionHandler;
import com.massivecraft.factions.struct.ChatMode;
import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.*; import com.massivecraft.factions.util.*;
@ -39,15 +38,15 @@ import me.lucko.commodore.CommodoreProvider;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission; import net.milkbowl.vault.permission.Permission;
import org.bstats.bukkit.Metrics; import org.bstats.bukkit.Metrics;
import org.bukkit.*; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.RegisteredServiceProvider;
@ -129,28 +128,20 @@ public class FactionsPlugin extends MPlugin {
this.setAutoSave(val); this.setAutoSave(val);
} }
public void playSoundForAll(String sound) {
for (Player pl : Bukkit.getOnlinePlayers()) playSound(pl, sound);
}
public void playSoundForAll(List<String> sounds) {
for (Player pl : Bukkit.getOnlinePlayers()) playSound(pl, sounds);
}
public void playSound(Player p, List<String> sounds) {
for (String sound : sounds) playSound(p, sound);
}
public void playSound(Player p, String sound) {
float pitch = Float.parseFloat(sound.split(":")[1]);
sound = sound.split(":")[0];
p.playSound(p.getLocation(), Sound.valueOf(sound), pitch, 5.0F);
}
@Override @Override
public void onEnable() { public void onEnable() {
log("==== Setup ===="); log("==== Setup ====");
if (getServer().getPluginManager().getPlugin("Vault") == null) {
divider();
System.out.println("You are missing dependencies!");
System.out.println("Please verify [Vault] is installed!");
Conf.save();
Bukkit.getPluginManager().disablePlugin(instance);
divider();
return;
}
int version = Integer.parseInt(ReflectionUtils.PackageType.getServerVersion().split("_")[1]); int version = Integer.parseInt(ReflectionUtils.PackageType.getServerVersion().split("_")[1]);
switch (version) { switch (version) {
case 7: case 7:
@ -183,37 +174,22 @@ public class FactionsPlugin extends MPlugin {
int pluginId = 7013; int pluginId = 7013;
Metrics metrics = new Metrics(this, pluginId); Metrics metrics = new Metrics(this, pluginId);
if (!preEnable()) { if (!preEnable()) {
this.loadSuccessful = false; this.loadSuccessful = false;
return; return;
} }
if (!new File(this.getDataFolder() + "/config.yml").exists()) { saveDefaultConfig();
this.saveResource("config.yml", false);
this.reloadConfig();
}
//Start wait task executor //Start wait task executor
WaitExecutor.startTask(); WaitExecutor.startTask();
// Load Conf from disk // Load Conf from disk
fileManager = new FileManager();
getFileManager().setupFiles();
Conf.load(); Conf.load();
fileManager = new FileManager();
fileManager.setupFiles();
fLogManager = new FLogManager(); fLogManager = new FLogManager();
//Dependency checks
if (Conf.dependencyCheck && (!Bukkit.getPluginManager().isPluginEnabled("Vault"))) {
divider();
System.out.println("You are missing dependencies!");
System.out.println("Please verify [Vault] is 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);
com.massivecraft.factions.integration.Essentials.setup(); com.massivecraft.factions.integration.Essentials.setup();
hookedPlayervaults = setupPlayervaults(); hookedPlayervaults = setupPlayervaults();
FPlayers.getInstance().load(); FPlayers.getInstance().load();
@ -230,6 +206,8 @@ public class FactionsPlugin extends MPlugin {
else faction.addFPlayer(fPlayer); else faction.addFPlayer(fPlayer);
} }
Factions.getInstance().getAllFactions().forEach(Faction::refreshFPlayers);
if (getConfig().getBoolean("enable-faction-flight", true)) { if (getConfig().getBoolean("enable-faction-flight", true)) {
UtilFly.run(); UtilFly.run();
} }
@ -261,7 +239,7 @@ public class FactionsPlugin extends MPlugin {
} }
if (getServer().getPluginManager().getPlugin("Skript") != null) { if (getServer().getPluginManager().getPlugin("Skript") != null) {
log("Skript was found! Registering FactionsPlugin Addon..."); log("Skript was found! Registering SaberFactions Addon...");
skriptAddon = Skript.registerAddon(this); skriptAddon = Skript.registerAddon(this);
try { try {
skriptAddon.loadClasses("com.massivecraft.factions.skript", "expressions"); skriptAddon.loadClasses("com.massivecraft.factions.skript", "expressions");
@ -270,6 +248,7 @@ public class FactionsPlugin extends MPlugin {
} }
log("Skript addon registered!"); log("Skript addon registered!");
} }
if (Conf.useCheckSystem) { if (Conf.useCheckSystem) {
int minute = 1200; int minute = 1200;
this.getServer().getScheduler().runTaskTimerAsynchronously(this, new CheckTask(this, 3), 0L, minute * 3); this.getServer().getScheduler().runTaskTimerAsynchronously(this, new CheckTask(this, 3), 0L, minute * 3);
@ -307,13 +286,14 @@ public class FactionsPlugin extends MPlugin {
for (Listener eventListener : eventsListener) for (Listener eventListener : eventsListener)
getServer().getPluginManager().registerEvents(eventListener, this); getServer().getPluginManager().registerEvents(eventListener, this);
if(Conf.useGraceSystem){ if (Conf.useGraceSystem) {
getServer().getPluginManager().registerEvents(timerManager.graceTimer, this); getServer().getPluginManager().registerEvents(timerManager.graceTimer, this);
} }
this.getCommand(refCommand).setExecutor(cmdBase); this.getCommand(refCommand).setExecutor(cmdBase);
if (!CommodoreProvider.isSupported()) this.getCommand(refCommand).setTabCompleter(this); if (!CommodoreProvider.isSupported()) this.getCommand(refCommand).setTabCompleter(this);
reserveObjects = new ArrayList<>(); reserveObjects = new ArrayList<>();
String path = Paths.get(this.getDataFolder().getAbsolutePath()).toAbsolutePath().toString() + File.separator + "reserves.json"; String path = Paths.get(this.getDataFolder().getAbsolutePath()).toAbsolutePath().toString() + File.separator + "reserves.json";
File file = new File(path); File file = new File(path);
@ -349,10 +329,6 @@ public class FactionsPlugin extends MPlugin {
FactionsPlugin.startupFinished = true; FactionsPlugin.startupFinished = true;
} }
public SkriptAddon getSkriptAddon() {
return skriptAddon;
}
private void setupPlaceholderAPI() { private void setupPlaceholderAPI() {
Plugin clip = getServer().getPluginManager().getPlugin("PlaceholderAPI"); Plugin clip = getServer().getPluginManager().getPlugin("PlaceholderAPI");
@ -459,30 +435,31 @@ public class FactionsPlugin extends MPlugin {
@Override @Override
public void onDisable() { public void onDisable() {
super.onDisable(); if (this.AutoLeaveTask != null) {
if (this.loadSuccessful) { getServer().getScheduler().cancelTask(this.AutoLeaveTask);
Conf.load(); this.AutoLeaveTask = null;
Conf.saveSync();
timerManager.saveTimerData();
DiscordListener.saveGuilds();
if (Discord.jda != null) Discord.jda.shutdownNow();
try {
fLogManager.saveLogs();
} catch (Exception e) {
e.printStackTrace();
}
try {
String path = Paths.get(getDataFolder().getAbsolutePath()).toAbsolutePath().toString() + File.separator + "reserves.json";
File file = new File(path);
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
Files.write(Paths.get(file.getPath()), getGsonBuilder().create().toJson(reserveObjects).getBytes());
} catch (IOException e) {
e.printStackTrace();
}
} }
Conf.saveSync();
timerManager.saveTimerData();
DiscordListener.saveGuilds();
if (Discord.jda != null) Discord.jda.shutdownNow();
fLogManager.saveLogs();
try {
String path = Paths.get(getDataFolder().getAbsolutePath()).toAbsolutePath().toString() + File.separator + "reserves.json";
File file = new File(path);
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
Files.write(Paths.get(file.getPath()), getGsonBuilder().create().toJson(reserveObjects).getBytes());
} catch (IOException e) {
e.printStackTrace();
}
super.onDisable(); super.onDisable();
} }
@ -504,26 +481,9 @@ public class FactionsPlugin extends MPlugin {
Conf.save(); Conf.save();
} }
public ItemStack createItem(Material material, int amount, short datavalue, String name, List<String> lore) {
ItemStack item = new ItemStack(XMaterial.matchXMaterial(material.toString()).get().parseMaterial(), amount, datavalue);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(color(name));
meta.setLore(colorList(lore));
item.setItemMeta(meta);
return item;
}
public ItemStack createLazyItem(Material material, int amount, short datavalue, String name, String lore) {
ItemStack item = new ItemStack(material, amount, datavalue);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(color(FactionsPlugin.instance.getConfig().getString(name)));
meta.setLore(colorList(FactionsPlugin.instance.getConfig().getStringList(lore)));
item.setItemMeta(meta);
return item;
}
public Economy getEcon() { public Economy getEcon() {
RegisteredServiceProvider<Economy> rsp = FactionsPlugin.instance.getServer().getServicesManager().getRegistration(Economy.class); RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
return rsp.getProvider(); return rsp.getProvider();
} }
@ -548,7 +508,6 @@ public class FactionsPlugin extends MPlugin {
List<FCommand> commandsList = cmdBase.subCommands; List<FCommand> commandsList = cmdBase.subCommands;
FCommand commandsEx = cmdBase; FCommand commandsEx = cmdBase;
List<String> completions = new ArrayList<>(); List<String> completions = new ArrayList<>();
// Check for "" first arg because spigot is mangled. // Check for "" first arg because spigot is mangled.
if (context.args.get(0).equals("")) { if (context.args.get(0).equals("")) {
for (FCommand subCommand : commandsEx.subCommands) { for (FCommand subCommand : commandsEx.subCommands) {
@ -596,70 +555,11 @@ public class FactionsPlugin extends MPlugin {
// Functions for other plugins to hook into // Functions for other plugins to hook into
// -------------------------------------------- // // -------------------------------------------- //
// This value will be updated whenever new hooks are added
public int hookSupportVersion() {
return 3;
}
// If another plugin is handling insertion of chat tags, this should be used to notify Factions // If another plugin is handling insertion of chat tags, this should be used to notify Factions
public void handleFactionTagExternally(boolean notByFactions) { public void handleFactionTagExternally(boolean notByFactions) {
Conf.chatTagHandledByAnotherPlugin = notByFactions; Conf.chatTagHandledByAnotherPlugin = notByFactions;
} }
// Simply put, should this chat event be left for Factions to handle? For now, that means players with Faction Chat
// enabled or use of the Factions f command without a slash; combination of isPlayerFactionChatting() and isFactionsCommand()
public boolean shouldLetFactionsHandleThisChat(AsyncPlayerChatEvent event) {
return event != null && (isPlayerFactionChatting(event.getPlayer()) || isFactionsCommand(event.getMessage()));
}
// 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;
FPlayer me = FPlayers.getInstance().getByPlayer(player);
return me != null && me.getChatMode().isAtLeast(ChatMode.ALLIANCE);
}
// Is this chat message actually a Factions command, and thus should be left alone by other plugins?
// TODO: GET THIS BACK AND WORKING
public boolean isFactionsCommand(String check) {
return !(check == null || check.isEmpty()) && this.handleCommand(null, check, true);
}
// Get a player's faction tag (faction name), mainly for usage by chat plugins for local/channel chat
public String getPlayerFactionTag(Player player) {
return getPlayerFactionTagRelation(player, null);
}
// Same as above, but with relation (enemy/neutral/ally) coloring potentially added to the tag
public String getPlayerFactionTagRelation(Player speaker, Player listener) {
String tag = "~";
if (speaker == null) return tag;
FPlayer me = FPlayers.getInstance().getByPlayer(speaker);
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();
} else {
FPlayer you = FPlayers.getInstance().getByPlayer(listener);
if (you == null) {
tag = me.getChatTag().trim();
} else { // everything checks out, give the colored tag
tag = me.getChatTag(you).trim();
}
}
if (tag.isEmpty()) tag = "~";
return tag;
}
public FLogManager getFlogManager() { public FLogManager getFlogManager() {
return fLogManager; return fLogManager;
} }
@ -668,14 +568,6 @@ public class FactionsPlugin extends MPlugin {
this.fLogManager.log(faction, type, arguments); this.fLogManager.log(faction, type, arguments);
} }
// 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 "";
FPlayer me = FPlayers.getInstance().getByPlayer(player);
if (me == null) return "";
return me.getTitle().trim();
}
public String color(String line) { public String color(String line) {
line = ChatColor.translateAlternateColorCodes('&', line); line = ChatColor.translateAlternateColorCodes('&', line);
return line; return line;
@ -687,38 +579,10 @@ public class FactionsPlugin extends MPlugin {
return lore; return lore;
} }
// Get a list of all faction tags (names)
public Set<String> getFactionTags() {
return Factions.getInstance().getFactionTags();
}
public List<ReserveObject> getFactionReserves() { public List<ReserveObject> getFactionReserves() {
return this.reserveObjects; return this.reserveObjects;
} }
// Get a list of all players in the specified faction
public Set<String> getPlayersInFaction(String factionTag) {
Set<String> players = new HashSet<>();
Faction faction = Factions.getInstance().getByTag(factionTag);
if (faction != null) {
for (FPlayer fplayer : faction.getFPlayers()) players.add(fplayer.getName());
}
return players;
}
// Get a list of all online players in the specified faction
public Set<String> getOnlinePlayersInFaction(String factionTag) {
Set<String> players = new HashSet<>();
Faction faction = Factions.getInstance().getByTag(factionTag);
if (faction != null) {
for (FPlayer fplayer : faction.getFPlayersWhereOnline(true)) players.add(fplayer.getName());
}
return players;
}
public boolean isHookedPlayervaults() {
return hookedPlayervaults;
}
public String getPrimaryGroup(OfflinePlayer player) { public String getPrimaryGroup(OfflinePlayer player) {
return perms == null || !perms.hasGroupSupport() ? " " : perms.getPrimaryGroup(Bukkit.getWorlds().get(0).toString(), player); return perms == null || !perms.hasGroupSupport() ? " " : perms.getPrimaryGroup(Bukkit.getWorlds().get(0).toString(), player);
@ -740,7 +604,4 @@ public class FactionsPlugin extends MPlugin {
debug(Level.INFO, s); debug(Level.INFO, s);
} }
public Worldguard getWg() {
return wg;
}
} }

View File

@ -26,8 +26,7 @@ public class CmdFly extends FCommand {
public static ConcurrentHashMap<String, Boolean> flyMap = new ConcurrentHashMap<>(); public static ConcurrentHashMap<String, Boolean> flyMap = new ConcurrentHashMap<>();
public static BukkitTask particleTask = null; public static BukkitTask particleTask = null;
public static BukkitTask flyTask = null;
public static boolean autoenable = FactionsPlugin.instance.getConfig().getBoolean("ffly.AutoEnable");
public static final boolean fly = FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight"); public static final boolean fly = FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight");
@ -48,9 +47,7 @@ public class CmdFly extends FCommand {
Player player = Bukkit.getPlayer(name); Player player = Bukkit.getPlayer(name);
if (player == null) continue; if (player == null) continue;
if (!player.isFlying()) continue; if (!player.isFlying()) continue;
if (!FactionsPlugin.getInstance().mc17) { if (!FactionsPlugin.getInstance().mc17 && player.getGameMode() == GameMode.SPECTATOR) continue;
if (player.getGameMode() == GameMode.SPECTATOR) continue;
}
FPlayer fplayer = FPlayers.getInstance().getByPlayer(player); FPlayer fplayer = FPlayers.getInstance().getByPlayer(player);
fplayer.isVanished(); fplayer.isVanished();
@ -62,71 +59,31 @@ public class CmdFly extends FCommand {
}, 10L, 3L); }, 10L, 3L);
} }
public static void startFlyCheck() { public static boolean checkBypassPerms(FPlayer fme, Player me, Faction toFac, boolean sendMessage) {
flyTask = Bukkit.getScheduler().runTaskTimerAsynchronously(FactionsPlugin.instance, () -> {
checkTaskState();
if (flyMap.keySet().size() != 0) {
for (String name : flyMap.keySet()) {
if (name == null) {
continue;
}
Player player = Bukkit.getPlayer(name);
if (player == null
|| !player.isFlying()
|| player.getGameMode() == GameMode.CREATIVE
|| !FactionsPlugin.getInstance().mc17 && player.getGameMode() == GameMode.SPECTATOR) {
continue;
}
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()) {
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);
}
}
}
}
}, 20L, 20L);
}
public static boolean checkBypassPerms(FPlayer fme, Player me, Faction toFac) {
if (Conf.denyFlightIfInNoClaimingWorld && !Conf.worldsNoClaiming.isEmpty() && Conf.worldsNoClaiming.stream().anyMatch(me.getWorld().getName()::equalsIgnoreCase)) if (Conf.denyFlightIfInNoClaimingWorld && !Conf.worldsNoClaiming.isEmpty() && Conf.worldsNoClaiming.stream().anyMatch(me.getWorld().getName()::equalsIgnoreCase))
return false; return false;
if (toFac != fme.getFaction()) { if (toFac != fme.getFaction()) {
if (!me.hasPermission(Permission.FLY_WILDERNESS.node) && toFac.isWilderness() || !me.hasPermission(Permission.FLY_SAFEZONE.node) && toFac.isSafeZone() || !me.hasPermission(Permission.FLY_WARZONE.node) && toFac.isWarZone()) { if (!me.hasPermission(Permission.FLY_WILDERNESS.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)); if(sendMessage) fme.msg(TL.COMMAND_FLY_NO_ACCESS, toFac.getTag(fme));
return false; return false;
} }
Access access = toFac.getAccess(fme, PermissableAction.FLY); Access access = toFac.getAccess(fme, PermissableAction.FLY);
if ((!(me.hasPermission(Permission.FLY_ENEMY.node) || access == Access.ALLOW)) && toFac.getRelationTo(fme.getFaction()) == Relation.ENEMY) { 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)); if(sendMessage) fme.msg(TL.COMMAND_FLY_NO_ACCESS, toFac.getTag(fme));
return false; return false;
} }
if (!(me.hasPermission(Permission.FLY_ALLY.node) || access == Access.ALLOW) && toFac.getRelationTo(fme.getFaction()) == Relation.ALLY) { 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)); if(sendMessage) fme.msg(TL.COMMAND_FLY_NO_ACCESS, toFac.getTag(fme));
return false; return false;
} }
if (!(me.hasPermission(Permission.FLY_TRUCE.node) || access == Access.ALLOW) && toFac.getRelationTo(fme.getFaction()) == Relation.TRUCE) { 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)); if(sendMessage) fme.msg(TL.COMMAND_FLY_NO_ACCESS, toFac.getTag(fme));
return false; return false;
} }
if (!(me.hasPermission(Permission.FLY_NEUTRAL.node) || access == Access.ALLOW) && toFac.getRelationTo(fme.getFaction()) == Relation.NEUTRAL && !toFac.isSystemFaction()) { 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)); if(sendMessage) fme.msg(TL.COMMAND_FLY_NO_ACCESS, toFac.getTag(fme));
return false; return false;
} }
return me.hasPermission(Permission.FLY_FLY.node) && (access != Access.DENY || toFac.isSystemFaction()); return me.hasPermission(Permission.FLY_FLY.node) && (access != Access.DENY || toFac.isSystemFaction());
@ -135,21 +92,14 @@ public class CmdFly extends FCommand {
} }
public static void checkTaskState() {
if (flyMap.isEmpty()) {
flyTask.cancel();
flyTask = null;
}
}
public static void disableFlight(final FPlayer fme) { public static void disableFlight(final FPlayer fme) {
fme.setFlying(false); fme.setFlying(false);
flyMap.remove(fme.getPlayer().getName()); flyMap.remove(fme.getPlayer().getName());
} }
public boolean isInFlightChecker(FPlayer fPlayer) { public boolean isInFlightChecker(Player player) {
return flyMap.containsKey(fPlayer); return flyMap.containsKey(player.getName());
} }
@Override @Override
@ -171,7 +121,7 @@ public class CmdFly extends FCommand {
FLocation myfloc = new FLocation(context.player.getLocation()); FLocation myfloc = new FLocation(context.player.getLocation());
Faction toFac = Board.getInstance().getFactionAt(myfloc); Faction toFac = Board.getInstance().getFactionAt(myfloc);
if (!checkBypassPerms(context.fPlayer, context.player, toFac)) { if (!checkBypassPerms(context.fPlayer, context.player, toFac, false)) {
context.fPlayer.sendMessage(TL.COMMAND_FLY_NO_ACCESS.format(toFac.getTag())); context.fPlayer.sendMessage(TL.COMMAND_FLY_NO_ACCESS.format(toFac.getTag()));
return; return;
} }
@ -195,13 +145,7 @@ public class CmdFly extends FCommand {
context.doWarmUp(WarmUpUtil.Warmup.FLIGHT, TL.WARMUPS_NOTIFY_FLIGHT, "Fly", () -> { context.doWarmUp(WarmUpUtil.Warmup.FLIGHT, TL.WARMUPS_NOTIFY_FLIGHT, "Fly", () -> {
fme.setFlying(true); fme.setFlying(true);
flyMap.put(fme.getPlayer().getName(), true); flyMap.put(fme.getPlayer().getName(), true);
if (particleTask == null) { if (particleTask == null) startParticles();
startParticles();
}
if (flyTask == null) {
startFlyCheck();
}
}, FactionsPlugin.getInstance().getConfig().getLong("warmups.f-fly", 0)); }, FactionsPlugin.getInstance().getConfig().getLong("warmups.f-fly", 0));
} else { } else {
fme.msg(TL.COMMAND_FLY_NO_ACCESS, Board.getInstance().getFactionAt(fme.getLastStoodAt()).getTag()); fme.msg(TL.COMMAND_FLY_NO_ACCESS, Board.getInstance().getFactionAt(fme.getLastStoodAt()).getTag());

View File

@ -8,9 +8,11 @@ import com.massivecraft.factions.zcore.util.TL;
import com.massivecraft.factions.zcore.util.TagReplacer; import com.massivecraft.factions.zcore.util.TagReplacer;
import com.massivecraft.factions.zcore.util.TagUtil; import com.massivecraft.factions.zcore.util.TagUtil;
import mkremins.fanciful.FancyMessage; import mkremins.fanciful.FancyMessage;
import org.bukkit.scheduler.BukkitScheduler;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
public class CmdShow extends FCommand { public class CmdShow extends FCommand {
@ -24,17 +26,21 @@ public class CmdShow extends FCommand {
this.aliases.addAll(Aliases.show_show); this.aliases.addAll(Aliases.show_show);
// add defaults to /f show in case config doesnt have it // add defaults to /f show in case config doesnt have it
defaults.add("{header}"); defaults.add("&8&m--------------&7 &8<&e{faction}&8> &8&m--------------");
defaults.add("<a>Description: <i>{description}"); defaults.add("&4* &cOwner: &f{leader}");
defaults.add("<a>Joining: <i>{joining} {peaceful}"); defaults.add("&4* &cDescription: &f{description}");
defaults.add("<a>Land / Power / Maxpower: <i> {chunks} / {power} / {maxPower}"); defaults.add("&4* &cLand / Power / Max Power: &f{chunks} &8/ &f{power} &8/ &f{maxPower}");
defaults.add("<a>Founded: <i>{create-date}"); defaults.add("&4* &cFaction Strikes: &f{strikes}");
defaults.add("<a>This faction is permanent, remaining even with no members."); defaults.add("&4* &cFaction Points: &f{faction-points}");
defaults.add("<a>Land value: <i>{land-value} {land-refund}"); defaults.add("&4* &cFounded: &f{create-date}");
defaults.add("<a>Balance: <i>{faction-balance}"); defaults.add("&4* &cBalance: &f{faction-balance}");
defaults.add("<a>Allies(<i>{allies}<a>/<i>{max-allies}<a>): {allies-list}"); defaults.add("&4* &cAllies: &a{allies-list}");
defaults.add("<a>Online: (<i>{online}<a>/<i>{members}<a>): {online-list}"); defaults.add("&4* &cEnemies: &4{enemies-list}");
defaults.add("<a>Offline: (<i>{offline}<a>/<i>{members}<a>): {offline-list}"); defaults.add("&4* &cOnline Members: &8[&f{online}/{members}&8] &a{online-list}");
defaults.add("&4* &cOffline Members: &8[&f{offline}/{members}&8] &a{offline-list}");
defaults.add("&4* &cAlts: &f{alts}");
defaults.add("&4* &cBans: &f{faction-bancount}");
defaults.add("&8&m----------------------------------------");
// this.requiredArgs.add(""); // this.requiredArgs.add("");
this.optionalArgs.put("faction tag", "yours"); this.optionalArgs.put("faction tag", "yours");
@ -45,6 +51,7 @@ public class CmdShow extends FCommand {
@Override @Override
public void perform(CommandContext context) { public void perform(CommandContext context) {
Faction faction = context.faction; Faction faction = context.faction;
FactionsPlugin instance = FactionsPlugin.getInstance();
if (context.argIsSet(0)) if (context.argIsSet(0))
faction = context.argAsFaction(0); faction = context.argAsFaction(0);
@ -52,7 +59,7 @@ public class CmdShow extends FCommand {
return; return;
if (context.fPlayer != null && !context.player.getPlayer().hasPermission("factions.show.bypassexempt") if (context.fPlayer != null && !context.player.getPlayer().hasPermission("factions.show.bypassexempt")
&& FactionsPlugin.getInstance().getConfig().getStringList("show-exempt").contains(faction.getTag())) { && instance.getConfig().getStringList("show-exempt").contains(faction.getTag())) {
context.msg(TL.COMMAND_SHOW_EXEMPT); context.msg(TL.COMMAND_SHOW_EXEMPT);
return; return;
} }
@ -62,7 +69,7 @@ public class CmdShow extends FCommand {
return; return;
} }
List<String> show = FactionsPlugin.getInstance().getConfig().getStringList("show"); List<String> show = instance.getConfig().getStringList("show");
if (show == null || show.isEmpty()) if (show == null || show.isEmpty())
show = defaults; show = defaults;
@ -71,41 +78,49 @@ public class CmdShow extends FCommand {
// send header and that's all // send header and that's all
String header = show.get(0); String header = show.get(0);
if (TagReplacer.HEADER.contains(header)) { if (TagReplacer.HEADER.contains(header)) {
context.msg(FactionsPlugin.getInstance().txt.titleize(tag)); context.msg(instance.txt.titleize(tag));
} else { } else {
context.msg(FactionsPlugin.getInstance().txt.parse(TagReplacer.FACTION.replace(header, tag))); context.msg(instance.txt.parse(TagReplacer.FACTION.replace(header, tag)));
} }
return; // we only show header for non-normal factions return; // we only show header for non-normal factions
} }
for (String raw : show) { List<String> finalShow = show;
String parsed = TagUtil.parsePlain(faction, context.fPlayer, raw); // use relations Faction finalFaction = faction;
if (parsed == null) { List<FancyMessage> fancy = new ArrayList<>();
continue; // Due to minimal f show. instance.getServer().getScheduler().runTaskAsynchronously(instance, () -> {
} for (String raw : finalShow) {
String parsed = TagUtil.parsePlain(finalFaction, context.fPlayer, raw); // use relations
if (context.fPlayer != null) { if (parsed == null) {
parsed = TagUtil.parsePlaceholders(context.fPlayer.getPlayer(), parsed); continue; // Due to minimal f show.
}
if (TagUtil.hasFancy(parsed)) {
List<FancyMessage> fancy = TagUtil.parseFancy(faction, context.fPlayer, parsed);
if (fancy != null)
context.sendFancyMessage(fancy);
continue;
}
if (!parsed.contains("{notFrozen}") && !parsed.contains("{notPermanent}")) {
if (parsed.contains("{ig}")) {
// replaces all variables with no home TL
parsed = parsed.substring(0, parsed.indexOf("{ig}")) + TL.COMMAND_SHOW_NOHOME.toString();
} }
if (parsed.contains("%")) {
parsed = parsed.replaceAll("%", ""); // Just in case it got in there before we disallowed it. if (context.fPlayer != null) {
parsed = TagUtil.parsePlaceholders(context.fPlayer.getPlayer(), parsed);
}
if (TagUtil.hasFancy(parsed)) {
List<FancyMessage> localFancy = TagUtil.parseFancy(finalFaction, context.fPlayer, parsed);
if (localFancy != null)
fancy.addAll(localFancy);
continue;
}
if (!parsed.contains("{notFrozen}") && !parsed.contains("{notPermanent}")) {
if (parsed.contains("{ig}")) {
// replaces all variables with no home TL
parsed = parsed.substring(0, parsed.indexOf("{ig}")) + TL.COMMAND_SHOW_NOHOME.toString();
}
if (parsed.contains("%")) {
parsed = parsed.replaceAll("%", ""); // Just in case it got in there before we disallowed it.
}
parsed = FactionsPlugin.getInstance().txt.parse(parsed);
FancyMessage localFancy = instance.txt.parseFancy(parsed);
fancy.add(localFancy);
} }
context.msg(FactionsPlugin.getInstance().txt.parse(parsed));
} }
} instance.getServer().getScheduler().runTask(instance, () -> context.sendFancyMessage(fancy));
});
} }
@Override @Override

View File

@ -399,11 +399,9 @@ public class FCmdRoot extends FCommand implements CommandExecutor {
addSubCommand(this.cmdFocus); addSubCommand(this.cmdFocus);
fFocusEnabled = true; fFocusEnabled = true;
} }
if (FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight", false) && !fFlyEnabled) { if (FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight", true) && !fFlyEnabled) {
this.addSubCommand(this.cmdFly); this.addSubCommand(this.cmdFly);
fFlyEnabled = true; fFlyEnabled = true;
CmdFly.startFlyCheck();
CmdFly.startParticles();
} }
} }

View File

@ -69,9 +69,9 @@ public class CmdAutoClaim extends FCommand {
context.msg(TL.COMMAND_AUTOCLAIM_ENABLED, forFaction.describeTo(context.fPlayer)); context.msg(TL.COMMAND_AUTOCLAIM_ENABLED, forFaction.describeTo(context.fPlayer));
if (FactionsPlugin.cachedRadiusClaim && context.fPlayer.attemptClaim(forFaction, context.player.getLocation(), true)) { if (FactionsPlugin.cachedRadiusClaim && context.fPlayer.attemptClaim(forFaction, context.player.getLocation(), true)) {
context.fPlayer.getFaction().getFPlayersWhereOnline(true).forEach(f -> f.msg(TL.CLAIM_CLAIMED, context.fPlayer.describeTo(f, true), context.fPlayer.getFaction().describeTo(f), at.describeTo(f))); context.fPlayer.getFaction().getFPlayersWhereOnline(true).forEach(f -> f.msg(TL.CLAIM_CLAIMED, context.fPlayer.describeTo(f, true), context.fPlayer.getFaction().describeTo(f), at.describeTo(f)));
return; } else {
context.fPlayer.attemptClaim(forFaction, context.fPlayer.getPlayer().getLocation(), true);
} }
context.fPlayer.attemptClaim(forFaction, context.fPlayer.getPlayer().getLocation(), true);
} }
@Override @Override

View File

@ -59,7 +59,7 @@ public class CmdClaim extends FCommand {
Faction at = Board.getInstance().getFactionAt(new FLocation(context.fPlayer.getPlayer().getLocation())); Faction at = Board.getInstance().getFactionAt(new FLocation(context.fPlayer.getPlayer().getLocation()));
if (radius < 2) { if (radius < 2) {
if (FactionsPlugin.cachedRadiusClaim && context.fPlayer.attemptClaim(forFaction, context.player.getLocation(), true)) { if (FactionsPlugin.cachedRadiusClaim && context.fPlayer.attemptClaim(forFaction, context.player.getLocation(), false)) {
context.fPlayer.getFaction().getFPlayersWhereOnline(true).forEach(f -> f.msg(TL.CLAIM_CLAIMED, context.fPlayer.describeTo(f, true), context.fPlayer.getFaction().describeTo(f), at.describeTo(f))); context.fPlayer.getFaction().getFPlayersWhereOnline(true).forEach(f -> f.msg(TL.CLAIM_CLAIMED, context.fPlayer.describeTo(f, true), context.fPlayer.getFaction().describeTo(f), at.describeTo(f)));
FactionsPlugin.instance.logFactionEvent(forFaction, FLogType.CHUNK_CLAIMS, context.fPlayer.getName(), CC.GreenB + "CLAIMED", "1", (new FLocation(context.fPlayer.getPlayer().getLocation())).formatXAndZ(",")); FactionsPlugin.instance.logFactionEvent(forFaction, FLogType.CHUNK_CLAIMS, context.fPlayer.getName(), CC.GreenB + "CLAIMED", "1", (new FLocation(context.fPlayer.getPlayer().getLocation())).formatXAndZ(","));
return; return;

View File

@ -83,11 +83,13 @@ public class CmdClaimLine extends FCommand {
// TODO: make this a task like claiming a radius? // TODO: make this a task like claiming a radius?
int claims = 0; int claims = 0;
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
if (FactionsPlugin.cachedRadiusClaim && context.fPlayer.attemptClaim(forFaction, context.player.getLocation(), true)) { if (FactionsPlugin.cachedRadiusClaim && context.fPlayer.attemptClaim(forFaction, context.player.getLocation(), false)) {
claims++; claims++;
} else { } else {
context.fPlayer.attemptClaim(forFaction, location, true); context.fPlayer.attemptClaim(forFaction, location, true);
claims++;
} }
location = location.add(blockFace.getModX() * 16, 0, blockFace.getModZ() * 16); location = location.add(blockFace.getModX() * 16, 0, blockFace.getModZ() * 16);
FactionsPlugin.instance.logFactionEvent(forFaction, FLogType.CHUNK_CLAIMS, context.fPlayer.getName(), CC.GreenB + "CLAIMED", String.valueOf(i), new FLocation(context.player.getLocation()).formatXAndZ(",")); FactionsPlugin.instance.logFactionEvent(forFaction, FLogType.CHUNK_CLAIMS, context.fPlayer.getName(), CC.GreenB + "CLAIMED", String.valueOf(i), new FLocation(context.player.getLocation()).formatXAndZ(","));

View File

@ -32,9 +32,8 @@ public class Econ {
private static Economy econ = null; private static Economy econ = null;
public static void setup() { public static void setup() {
if (isSetup()) { if (isSetup()) return;
return;
}
String integrationFail = "Economy integration is " + (Conf.econEnabled ? "enabled, but" : "disabled, and") + " the plugin \"Vault\" "; String integrationFail = "Economy integration is " + (Conf.econEnabled ? "enabled, but" : "disabled, and") + " the plugin \"Vault\" ";
@ -42,20 +41,14 @@ public class Econ {
FactionsPlugin.getInstance().log(integrationFail + "is not installed."); FactionsPlugin.getInstance().log(integrationFail + "is not installed.");
return; return;
} }
RegisteredServiceProvider<Economy> rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class); RegisteredServiceProvider<Economy> rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
if (rsp == null) { if (rsp == null) {
FactionsPlugin.getInstance().log(integrationFail + "is not hooked into an economy plugin."); FactionsPlugin.getInstance().log(integrationFail + "is not hooked into an economy plugin.");
return; return;
} }
econ = rsp.getProvider(); econ = rsp.getProvider();
FactionsPlugin.getInstance().log("Economy integration through Vault plugin successful."); FactionsPlugin.getInstance().log("Economy integration through Vault plugin successful.");
if (!Conf.econEnabled) FactionsPlugin.getInstance().log("NOTE: Economy is disabled. You can enable it with the command: f config econEnabled true");
if (!Conf.econEnabled) {
FactionsPlugin.getInstance().log("NOTE: Economy is disabled. You can enable it with the command: f config econEnabled true");
}
//FactionsPlugin.getInstance().cmdBase.cmdHelp.updateHelp(); //FactionsPlugin.getInstance().cmdBase.cmdHelp.updateHelp();
} }
@ -68,26 +61,24 @@ public class Econ {
} }
public static void modifyUniverseMoney(double delta) { public static void modifyUniverseMoney(double delta) {
if (!shouldBeUsed()) { if (!shouldBeUsed()) return;
return; if (Conf.econUniverseAccount == null) return;
} if (Conf.econUniverseAccount.length() == 0) return;
if (!econ.hasAccount(Conf.econUniverseAccount)) return;
if (Conf.econUniverseAccount == null) {
return;
}
if (Conf.econUniverseAccount.length() == 0) {
return;
}
if (!econ.hasAccount(Conf.econUniverseAccount)) {
return;
}
modifyBalance(Conf.econUniverseAccount, delta); modifyBalance(Conf.econUniverseAccount, delta);
} }
public static void sendBalanceInfo(FPlayer to, EconomyParticipator about) {
if (!shouldBeUsed()) {
FactionsPlugin.instance.log(Level.WARNING, "Vault does not appear to be hooked into an economy plugin.");
return;
}
to.msg(TL.ECON_PLAYERBALANCE, about.describeTo(to, true), Econ.moneyString(econ.getBalance(about.getAccountId())));
}
public static void sendBalanceInfo(CommandSender to, Faction about) { public static void sendBalanceInfo(CommandSender to, Faction about) {
if (!shouldBeUsed()) { if (!shouldBeUsed()) {
FactionsPlugin.getInstance().log(Level.WARNING, "Vault does not appear to be hooked into an economy plugin."); FactionsPlugin.instance.log(Level.WARNING, "Vault does not appear to be hooked into an economy plugin.");
return; return;
} }
to.sendMessage(String.format(TL.ECON_PLAYERBALANCE.toString(), about.getTag(), Econ.moneyString(econ.getBalance(about.getAccountId())))); to.sendMessage(String.format(TL.ECON_PLAYERBALANCE.toString(), about.getTag(), Econ.moneyString(econ.getBalance(about.getAccountId()))));
@ -98,37 +89,20 @@ public class Econ {
Faction fYou = RelationUtil.getFaction(you); Faction fYou = RelationUtil.getFaction(you);
// This is a system invoker. Accept it. // This is a system invoker. Accept it.
if (fI == null) { if (fI == null) return true;
return true;
}
// Bypassing players can do any kind of transaction // Bypassing players can do any kind of transaction
if (i instanceof FPlayer && ((FPlayer) i).isAdminBypassing()) { if (i instanceof FPlayer && ((FPlayer) i).isAdminBypassing()) return true;
return true;
}
// Players with the any withdraw can do. // Players with the any withdraw can do.
if (i instanceof FPlayer && Permission.MONEY_WITHDRAW_ANY.has(((FPlayer) i).getPlayer())) { if (i instanceof FPlayer && Permission.MONEY_WITHDRAW_ANY.has(((FPlayer) i).getPlayer())) return true;
return true;
}
// You can deposit to anywhere you feel like. It's your loss if you can't withdraw it again. // You can deposit to anywhere you feel like. It's your loss if you can't withdraw it again.
if (i == you) { if (i == you) return true;
return true;
}
// A faction can always transfer away the money of it's members and its own money... // A faction can always transfer away the money of it's members and its own money...
// This will however probably never happen as a faction does not have free will. // This will however probably never happen as a faction does not have free will.
// Ohh by the way... Yes it could. For daily rent to the faction. // Ohh by the way... Yes it could. For daily rent to the faction.
if (i == fI && fI == fYou) { if (i == fI && fI == fYou) return true;
return true;
}
// Factions can be controlled by members that are moderators... or any member if any member can withdraw. // Factions can be controlled by members that are moderators... or any member if any member can withdraw.
if (i instanceof FPlayer && you instanceof Faction && fI == fYou && (Conf.bankMembersCanWithdraw || ((FPlayer) i).getRole().value >= Role.MODERATOR.value)) { if (you instanceof Faction && fI == fYou && (Conf.bankMembersCanWithdraw || (i instanceof FPlayer && ((FPlayer) i).getRole().value >= Role.MODERATOR.value)))
return true; return true;
}
// Otherwise you may not!;,,; // Otherwise you may not!;,,;
i.msg(TL.ECON_CANTCONTROLMONEY, i.describeTo(i, true), you.describeTo(i)); i.msg(TL.ECON_CANTCONTROLMONEY, i.describeTo(i, true), you.describeTo(i));
return false; return false;
@ -140,6 +114,7 @@ public class Econ {
public static boolean transferMoney(EconomyParticipator invoker, EconomyParticipator from, EconomyParticipator to, double amount, boolean notify) { public static boolean transferMoney(EconomyParticipator invoker, EconomyParticipator from, EconomyParticipator to, double amount, boolean notify) {
if (!shouldBeUsed()) { if (!shouldBeUsed()) {
invoker.msg(TL.ECON_DISABLED);
return false; return false;
} }
@ -153,30 +128,21 @@ public class Econ {
} }
// Check the rights // Check the rights
if (!canIControllYou(invoker, from)) { if (!canIControllYou(invoker, from)) return false;
return false;
}
OfflinePlayer fromAcc; OfflinePlayer fromAcc;
OfflinePlayer toAcc; OfflinePlayer toAcc;
if (isUUID(from.getAccountId())) { if (isUUID(from.getAccountId())) {
fromAcc = Bukkit.getOfflinePlayer(UUID.fromString(from.getAccountId())); fromAcc = Bukkit.getOfflinePlayer(UUID.fromString(from.getAccountId()));
if (fromAcc.getName() == null) { if (fromAcc.getName() == null) return false;
return false; } else fromAcc = Bukkit.getOfflinePlayer(from.getAccountId());
}
} else {
fromAcc = Bukkit.getOfflinePlayer(from.getAccountId());
}
if (isUUID(to.getAccountId())) { if (isUUID(to.getAccountId())) {
toAcc = Bukkit.getOfflinePlayer(UUID.fromString(to.getAccountId())); toAcc = Bukkit.getOfflinePlayer(UUID.fromString(to.getAccountId()));
if (toAcc.getName() == null) { if (toAcc.getName() == null) return false;
return false; } else toAcc = Bukkit.getOfflinePlayer(to.getAccountId());
}
} else {
toAcc = Bukkit.getOfflinePlayer(to.getAccountId());
}
// Is there enough money for the transaction to happen? // Is there enough money for the transaction to happen?
if (!econ.has(fromAcc, amount)) { if (!econ.has(fromAcc, amount)) {
@ -184,13 +150,6 @@ public class Econ {
if (invoker != null && notify) { if (invoker != null && notify) {
invoker.msg(TL.COMMAND_MONEYTRANSFERFF_TRANSFERCANTAFFORD, from.describeTo(invoker, true), moneyString(amount), to.describeTo(invoker)); invoker.msg(TL.COMMAND_MONEYTRANSFERFF_TRANSFERCANTAFFORD, from.describeTo(invoker, true), moneyString(amount), to.describeTo(invoker));
} }
return false;
}
// Check if the new balance is over Essential's money cap.
if (Essentials.isOverBalCap(to, econ.getBalance(toAcc) + amount)) {
invoker.msg(TL.ECON_OVER_BAL_CAP, amount);
return false; return false;
} }
@ -200,21 +159,15 @@ public class Econ {
if (erw.transactionSuccess()) { if (erw.transactionSuccess()) {
EconomyResponse erd = econ.depositPlayer(toAcc, amount); EconomyResponse erd = econ.depositPlayer(toAcc, amount);
if (erd.transactionSuccess()) { if (erd.transactionSuccess()) {
if (notify) { if (notify) sendTransferInfo(invoker, from, to, amount);
sendTransferInfo(invoker, from, to, amount);
}
return true; return true;
} else { } else econ.depositPlayer(fromAcc, amount);
// transaction failed, refund account
econ.depositPlayer(fromAcc, amount);
}
} }
// if we get here something with the transaction failed // if we get here something with the transaction failed
if (notify) { if (notify)
invoker.msg(TL.ECON_UNABLETOTRANSFER, moneyString(amount), to.describeTo(invoker), from.describeTo(invoker, true)); invoker.msg(TL.ECON_UNABLETOTRANSFER, moneyString(amount), to.describeTo(invoker), from.describeTo(invoker, true));
}
return false; return false;
} }
@ -239,28 +192,22 @@ public class Econ {
recipients.addAll(getFplayers(to)); recipients.addAll(getFplayers(to));
if (invoker == null) { if (invoker == null) {
for (FPlayer recipient : recipients) { for (FPlayer recipient : recipients)
recipient.msg(TL.ECON_MONEYTRASFERREDFROM, moneyString(amount), from.describeTo(recipient), to.describeTo(recipient)); recipient.msg(TL.ECON_MONEYTRASFERREDFROM, moneyString(amount), from.describeTo(recipient), to.describeTo(recipient));
}
} else if (invoker == from) { } else if (invoker == from) {
for (FPlayer recipient : recipients) { for (FPlayer recipient : recipients)
recipient.msg(TL.ECON_PERSONGAVEMONEYTO, from.describeTo(recipient, true), moneyString(amount), to.describeTo(recipient)); recipient.msg(TL.ECON_PERSONGAVEMONEYTO, from.describeTo(recipient, true), moneyString(amount), to.describeTo(recipient));
}
} else if (invoker == to) { } else if (invoker == to) {
for (FPlayer recipient : recipients) { for (FPlayer recipient : recipients)
recipient.msg(TL.ECON_PERSONTOOKMONEYFROM, to.describeTo(recipient, true), moneyString(amount), from.describeTo(recipient)); recipient.msg(TL.ECON_PERSONTOOKMONEYFROM, to.describeTo(recipient, true), moneyString(amount), from.describeTo(recipient));
}
} else { } else {
for (FPlayer recipient : recipients) { for (FPlayer recipient : recipients)
recipient.msg(TL.ECON_MONEYTRASFERREDFROMPERSONTOPERSON, invoker.describeTo(recipient, true), moneyString(amount), from.describeTo(recipient), to.describeTo(recipient)); recipient.msg(TL.ECON_MONEYTRASFERREDFROMPERSONTOPERSON, invoker.describeTo(recipient, true), moneyString(amount), from.describeTo(recipient), to.describeTo(recipient));
}
} }
} }
public static boolean hasAtLeast(EconomyParticipator ep, double delta, String toDoThis) { public static boolean hasAtLeast(EconomyParticipator ep, double delta, String toDoThis) {
if (!shouldBeUsed()) { if (!shouldBeUsed()) return true;
return true;
}
// going the hard way round as econ.has refuses to work. // going the hard way round as econ.has refuses to work.
boolean affordable = false; boolean affordable = false;
@ -268,85 +215,59 @@ public class Econ {
if (isUUID(ep.getAccountId())) { if (isUUID(ep.getAccountId())) {
OfflinePlayer offline = Bukkit.getOfflinePlayer(UUID.fromString(ep.getAccountId())); OfflinePlayer offline = Bukkit.getOfflinePlayer(UUID.fromString(ep.getAccountId()));
if (offline.getName() != null) { if (offline.getName() != null)
currentBalance = econ.getBalance(Bukkit.getOfflinePlayer(UUID.fromString(ep.getAccountId()))); currentBalance = econ.getBalance(Bukkit.getOfflinePlayer(UUID.fromString(ep.getAccountId())));
} else { else currentBalance = 0;
currentBalance = 0; } else currentBalance = econ.getBalance(ep.getAccountId());
} if (currentBalance >= delta) affordable = true;
} else {
currentBalance = econ.getBalance(ep.getAccountId());
}
if (currentBalance >= delta) {
affordable = true;
}
if (!affordable) { if (!affordable) {
if (toDoThis != null && !toDoThis.isEmpty()) { if (toDoThis != null && !toDoThis.isEmpty())
ep.msg(TL.COMMAND_MONEY_CANTAFFORD, ep.describeTo(ep, true), moneyString(delta), toDoThis); ep.msg(TL.COMMAND_MONEY_CANTAFFORD, ep.describeTo(ep, true), moneyString(delta), toDoThis);
}
return false; return false;
} }
return true; return true;
} }
public static boolean modifyMoney(EconomyParticipator ep, double delta, String toDoThis, String forDoingThis) { public static boolean modifyMoney(EconomyParticipator ep, double delta, String toDoThis, String forDoingThis) {
if (!shouldBeUsed()) { if (!shouldBeUsed()) return false;
return false;
}
OfflinePlayer acc; OfflinePlayer acc;
if (isUUID(ep.getAccountId())) { if (isUUID(ep.getAccountId())) {
acc = Bukkit.getOfflinePlayer(UUID.fromString(ep.getAccountId())); acc = Bukkit.getOfflinePlayer(UUID.fromString(ep.getAccountId()));
if (acc.getName() == null) { if (acc.getName() == null) return false;
return false; } else acc = Bukkit.getOfflinePlayer(ep.getAccountId());
}
} else {
acc = Bukkit.getOfflinePlayer(ep.getAccountId());
}
String You = ep.describeTo(ep, true); String You = ep.describeTo(ep, true);
if (delta == 0) { if (delta == 0) return true;
// no money actually transferred? else if (delta > 0) {
// ep.msg("<h>%s<i> didn't have to pay anything %s.", You, forDoingThis); // might be for gains, might be for losses
return true;
}
if (delta > 0) {
// The player should gain money // The player should gain money
// The account might not have enough space // The account might not have enough space
EconomyResponse er = econ.depositPlayer(acc, delta); EconomyResponse er = econ.depositPlayer(acc, delta);
if (er.transactionSuccess()) { if (er.transactionSuccess()) {
modifyUniverseMoney(-delta); modifyUniverseMoney(-delta);
if (forDoingThis != null && !forDoingThis.isEmpty()) { if (forDoingThis != null && !forDoingThis.isEmpty())
ep.msg(TL.COMMAND_MONEY_GAINED, You, moneyString(delta), forDoingThis); ep.msg(TL.COMMAND_MONEY_GAINED, You, moneyString(delta), forDoingThis);
}
return true; return true;
} else { } else {
// transfer to account failed // transfer to account failed
if (forDoingThis != null && !forDoingThis.isEmpty()) { if (forDoingThis != null && !forDoingThis.isEmpty())
ep.msg(TL.ECON_DEPOSITFAILED, You, moneyString(delta), forDoingThis); ep.msg(TL.ECON_DEPOSITFAILED, You, moneyString(delta), forDoingThis);
}
return false; return false;
} }
} else { } else {
// The player should loose money // The player should loose money
// The player might not have enough. // The player might not have enough.
if (econ.has(acc, -delta) && econ.withdrawPlayer(acc, -delta).transactionSuccess()) { if (econ.has(acc, -delta) && econ.withdrawPlayer(acc, -delta).transactionSuccess()) {
// There is enough money to pay // There is enough money to pay
modifyUniverseMoney(-delta); modifyUniverseMoney(-delta);
if (forDoingThis != null && !forDoingThis.isEmpty()) { if (forDoingThis != null && !forDoingThis.isEmpty())
ep.msg(TL.ECON_MONEYLOST, You, moneyString(-delta), forDoingThis); ep.msg(TL.ECON_MONEYLOST, You, moneyString(-delta), forDoingThis);
}
return true; return true;
} else { } else {
// There was not enough money to pay // There was not enough money to pay
if (toDoThis != null && !toDoThis.isEmpty()) { if (toDoThis != null && !toDoThis.isEmpty())
ep.msg(TL.ECON_CANTAFFORD, You, moneyString(-delta), toDoThis); ep.msg(TL.ECON_CANTAFFORD, You, moneyString(-delta), toDoThis);
}
return false; return false;
} }
} }
@ -358,10 +279,7 @@ public class Econ {
// calculate the cost for claiming land // calculate the cost for claiming land
public static double calculateClaimCost(int ownedLand, boolean takingFromAnotherFaction) { public static double calculateClaimCost(int ownedLand, boolean takingFromAnotherFaction) {
if (!shouldBeUsed()) { if (!shouldBeUsed()) return 0d;
return 0d;
}
// basic claim cost, plus land inflation cost, minus the potential bonus given for claiming from another faction // basic claim cost, plus land inflation cost, minus the potential bonus given for claiming from another faction
return Conf.econCostClaimWilderness + (Conf.econCostClaimWilderness * Conf.econClaimAdditionalMultiplier * ownedLand) - (takingFromAnotherFaction ? Conf.econCostClaimFromFactionBonus : 0); return Conf.econCostClaimWilderness + (Conf.econCostClaimWilderness * Conf.econClaimAdditionalMultiplier * ownedLand) - (takingFromAnotherFaction ? Conf.econCostClaimFromFactionBonus : 0);
} }
@ -374,9 +292,7 @@ public class Econ {
// calculate value of all owned land // calculate value of all owned land
public static double calculateTotalLandValue(int ownedLand) { public static double calculateTotalLandValue(int ownedLand) {
double amount = 0; double amount = 0;
for (int x = 0; x < ownedLand; x++) { for (int x = 0; x < ownedLand; x++) amount += calculateClaimCost(x, false);
amount += calculateClaimCost(x, false);
}
return amount; return amount;
} }
@ -400,9 +316,7 @@ public class Econ {
public static String getFriendlyBalance(UUID uuid) { public static String getFriendlyBalance(UUID uuid) {
OfflinePlayer offline = Bukkit.getOfflinePlayer(uuid); OfflinePlayer offline = Bukkit.getOfflinePlayer(uuid);
if (offline.getName() == null) { if (offline.getName() == null) return "0";
return "0";
}
return format.format(econ.getBalance(offline)); return format.format(econ.getBalance(offline));
} }
@ -412,19 +326,13 @@ public class Econ {
public static boolean setBalance(String account, double amount) { public static boolean setBalance(String account, double amount) {
double current = econ.getBalance(account); double current = econ.getBalance(account);
if (current > amount) { if (current > amount) return econ.withdrawPlayer(account, current - amount).transactionSuccess();
return econ.withdrawPlayer(account, current - amount).transactionSuccess(); else return econ.depositPlayer(account, amount - current).transactionSuccess();
} else {
return econ.depositPlayer(account, amount - current).transactionSuccess();
}
} }
public static boolean modifyBalance(String account, double amount) { public static boolean modifyBalance(String account, double amount) {
if (amount < 0) { if (amount < 0) return econ.withdrawPlayer(account, -amount).transactionSuccess();
return econ.withdrawPlayer(account, -amount).transactionSuccess(); else return econ.depositPlayer(account, amount).transactionSuccess();
} else {
return econ.depositPlayer(account, amount).transactionSuccess();
}
} }
public static boolean deposit(String account, double amount) { public static boolean deposit(String account, double amount) {

View File

@ -4,47 +4,30 @@ import com.earth2me.essentials.Teleport;
import com.earth2me.essentials.Trade; import com.earth2me.essentials.Trade;
import com.earth2me.essentials.User; import com.earth2me.essentials.User;
import com.massivecraft.factions.Conf; import com.massivecraft.factions.Conf;
import com.massivecraft.factions.iface.EconomyParticipator;
import net.ess3.api.IEssentials; import net.ess3.api.IEssentials;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.plugin.Plugin; import org.bukkit.metadata.MetadataValue;
import java.math.BigDecimal; import java.math.BigDecimal;
public class Essentials { public class Essentials {
/**
* @author FactionsUUID Team
*/
private static IEssentials essentials; private static IEssentials essentials;
public static void setup() { public static void setup() {
Plugin ess = Bukkit.getPluginManager().getPlugin("Essentials"); essentials = (IEssentials) Bukkit.getPluginManager().getPlugin("Essentials");
if (ess != null) {
essentials = (IEssentials) ess;
}
}
public static boolean isOverBalCap(EconomyParticipator participator, double amount) {
if (essentials == null) {
return false;
}
return amount > essentials.getSettings().getMaxMoney().doubleValue();
} }
// return false if feature is disabled or Essentials isn't available // return false if feature is disabled or Essentials isn't available
public static boolean handleTeleport(Player player, Location loc) { public static boolean handleTeleport(Player player, Location loc) {
if (!Conf.homesTeleportCommandEssentialsIntegration || essentials == null) { if (!Conf.homesTeleportCommandEssentialsIntegration || essentials == null) return false;
return false;
}
Teleport teleport = essentials.getUser(player).getTeleport(); Teleport teleport = essentials.getUser(player).getTeleport();
Trade trade = new Trade(new BigDecimal(Conf.econCostHome), essentials); Trade trade = new Trade(BigDecimal.valueOf(Conf.econCostHome), essentials);
try { try {
teleport.teleport(loc, trade, TeleportCause.PLUGIN); teleport.teleport(loc, trade, TeleportCause.PLUGIN);
} catch (Exception e) { } catch (Exception e) {
@ -54,8 +37,21 @@ public class Essentials {
} }
public static boolean isVanished(Player player) { public static boolean isVanished(Player player) {
if (essentials == null) return false; // Edge case handling.
User user = essentials.getUser(player); if (player == null) return false;
return user != null && user.isVanished(); boolean vanish = false;
if (essentials != null) {
User user = essentials.getUser(player);
if (user != null && user.isVanished()) return true;
}
if (player.hasMetadata("vanished"))
for (MetadataValue meta : player.getMetadata("vanished")) {
if (meta == null) continue;
if (meta.asBoolean()) {
vanish = true;
break;
}
}
return vanish;
} }
} }

View File

@ -4,6 +4,7 @@ import com.massivecraft.factions.*;
import com.massivecraft.factions.event.PowerLossEvent; import com.massivecraft.factions.event.PowerLossEvent;
import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.util.MiscUtil; import com.massivecraft.factions.util.MiscUtil;
import com.massivecraft.factions.util.timer.type.GraceTimer;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
@ -258,6 +259,8 @@ public class FactionsEntityListener implements Listener {
private boolean checkExplosionForBlock(Entity boomer, Block block) { private boolean checkExplosionForBlock(Entity boomer, Block block) {
Faction faction = Board.getInstance().getFactionAt(new FLocation(block.getLocation())); Faction faction = Board.getInstance().getFactionAt(new FLocation(block.getLocation()));
if(FactionsPlugin.getInstance().getTimerManager().graceTimer.getRemaining() > 0) return false;
if (faction.noExplosionsInTerritory() || (faction.isPeaceful() && Conf.peacefulTerritoryDisableBoom)) if (faction.noExplosionsInTerritory() || (faction.isPeaceful() && Conf.peacefulTerritoryDisableBoom))
return false; return false;
// faction is peaceful and has explosions set to disabled // faction is peaceful and has explosions set to disabled

View File

@ -58,8 +58,6 @@ import java.util.logging.Level;
public class FactionsPlayerListener implements Listener { public class FactionsPlayerListener implements Listener {
public static Set<FLocation> corners; public static Set<FLocation> corners;
public static BukkitTask positionTask = null;
public static Map<UUID, Location> lastLocations = new HashMap<>();
/** /**
* @author FactionsUUID Team * @author FactionsUUID Team
*/ */
@ -311,7 +309,7 @@ public class FactionsPlayerListener implements Listener {
if ((landOwned && factionToCheck.getOwnerListString(loc).contains(player.getName())) || (me.getRole() == Role.LEADER && me.getFactionId().equals(factionToCheck.getId()))) { if ((landOwned && factionToCheck.getOwnerListString(loc).contains(player.getName())) || (me.getRole() == Role.LEADER && me.getFactionId().equals(factionToCheck.getId()))) {
return true; return true;
} else if (landOwned && !factionToCheck.getOwnerListString(loc).contains(player.getName())) { } else if (landOwned && !factionToCheck.getOwnerListString(loc).contains(player.getName())) {
me.msg(TL.ACTIONS_OWNEDTERRITORYDENY, factionToCheck.getOwnerListString(loc)); me.msg(TL.ACTIONS_OWNEDTERRITORYDENY.toString().replace("{owners}", factionToCheck.getOwnerListString(loc)));
if (doPain) player.damage(Conf.actionDeniedPainAmount); if (doPain) player.damage(Conf.actionDeniedPainAmount);
return false; return false;
} else if (!landOwned && access == Access.ALLOW) { } else if (!landOwned && access == Access.ALLOW) {
@ -479,6 +477,8 @@ public class FactionsPlayerListener implements Listener {
// Update the lastLoginTime for this fplayer // Update the lastLoginTime for this fplayer
me.setLastLoginTime(System.currentTimeMillis()); me.setLastLoginTime(System.currentTimeMillis());
lastLocations.put(player.getUniqueId(), player.getLocation());
// Store player's current FLocation and notify them where they are // Store player's current FLocation and notify them where they are
me.setLastStoodAt(new FLocation(player.getLocation())); me.setLastStoodAt(new FLocation(player.getLocation()));
@ -535,6 +535,7 @@ public class FactionsPlayerListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onPlayerQuit(PlayerQuitEvent event) { public void onPlayerQuit(PlayerQuitEvent event) {
Player this_ = event.getPlayer();
FPlayer me = FPlayers.getInstance().getByPlayer(event.getPlayer()); FPlayer me = FPlayers.getInstance().getByPlayer(event.getPlayer());
// Make sure player's power is up to date when they log off. // Make sure player's power is up to date when they log off.
@ -551,6 +552,8 @@ public class FactionsPlayerListener implements Listener {
FactionsPlugin.instance.getTimers().remove(me.getPlayer().getUniqueId()); FactionsPlugin.instance.getTimers().remove(me.getPlayer().getUniqueId());
} }
lastLocations.remove(this_.getUniqueId());
Faction myFaction = me.getFaction(); Faction myFaction = me.getFaction();
if (!myFaction.isWilderness()) myFaction.memberLoggedOff(); if (!myFaction.isWilderness()) myFaction.memberLoggedOff();
@ -651,43 +654,16 @@ public class FactionsPlayerListener implements Listener {
return (result.length() == 3 ? result + "0" : result) + "/hrs ago"; return (result.length() == 3 ? result + "0" : result) + "/hrs ago";
} }
public static BukkitTask positionTask = null;
public final static Map<UUID, Location> lastLocations = new HashMap<>();
public void startPositionCheck() { public void startPositionCheck() {
positionTask = Bukkit.getScheduler().runTaskTimer(FactionsPlugin.instance, () -> { positionTask = Bukkit.getScheduler().runTaskTimer(FactionsPlugin.getInstance(), () -> {
if (Bukkit.getOnlinePlayers().size() > 0) { if (lastLocations.isEmpty()) return;
for (Player player : Bukkit.getOnlinePlayers()) { for (Map.Entry<UUID, Location> check : lastLocations.entrySet()) {
if (!lastLocations.containsKey(player.getUniqueId())) { Player player = Bukkit.getPlayer(check.getKey());
lastLocations.put(player.getUniqueId(), player.getLocation()); refreshPosition(player, check.getValue(), player.getLocation());
continue; lastLocations.put(player.getUniqueId(), player.getLocation());
}
refreshPosition(player, lastLocations.get(player.getUniqueId()), player.getLocation());
lastLocations.put(player.getUniqueId(), player.getLocation());
if (CmdFly.flyMap.containsKey(player.getName())) {
String name = player.getName();
if (!player.isFlying()
|| player.getGameMode() == GameMode.CREATIVE
|| !FactionsPlugin.instance.mc17 && player.getGameMode() == GameMode.SPECTATOR) {
continue;
}
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player);
Faction myFaction = fPlayer.getFaction();
if (myFaction.isWilderness()) {
Bukkit.getScheduler().runTask(FactionsPlugin.instance, () -> fPlayer.setFlying(false));
CmdFly.flyMap.remove(player.getName());
continue;
}
Bukkit.getScheduler().runTask(FactionsPlugin.instance, () -> {
if (!fPlayer.checkIfNearbyEnemies()) {
FLocation myFloc = new FLocation(player.getLocation());
if (Board.getInstance().getFactionAt(myFloc) != myFaction) {
if (!CmdFly.checkBypassPerms(fPlayer, player, Board.getInstance().getFactionAt(myFloc))) {
fPlayer.setFFlying(false, false);
CmdFly.flyMap.remove(name);
}
}
}
});
}
}
} }
}, 5L, 10L); }, 5L, 10L);
} }

View File

@ -172,11 +172,13 @@ public abstract class MPlugin extends JavaPlugin {
} }
public void onDisable() { public void onDisable() {
getServer().getScheduler().cancelTasks(this);
if (saveTask != null) { if (saveTask != null) {
this.getServer().getScheduler().cancelTask(saveTask); this.getServer().getScheduler().cancelTask(saveTask);
saveTask = null; saveTask = null;
} }
this.getServer().getScheduler().cancelTasks(this);
// only save data if plugin actually loaded successfully // only save data if plugin actually loaded successfully
if (loadSuccessful) { if (loadSuccessful) {
Factions.getInstance().forceSave(); Factions.getInstance().forceSave();

View File

@ -25,22 +25,22 @@ public class UpgradesListener implements Listener {
@EventHandler @EventHandler
public static void onDamageReduction(EntityDamageByEntityEvent e) { public static void onDamageReduction(EntityDamageByEntityEvent e) {
if (e.isCancelled()) { if (e.isCancelled()) return;
return;
} if (!(e.getDamager() instanceof Player) || !(e.getEntity() instanceof Player)) return;
if (!(e.getDamager() instanceof Player) || !(e.getEntity() instanceof Player)) { if(e.getEntity() == null) return;
return;
}
FPlayer fme = FPlayers.getInstance().getByPlayer((Player) e.getEntity()); FPlayer fme = FPlayers.getInstance().getByPlayer((Player) e.getEntity());
FPlayer dame = FPlayers.getInstance().getByPlayer((Player) e.getDamager()); FPlayer dame = FPlayers.getInstance().getByPlayer((Player) e.getDamager());
if (fme == null || dame == null) {
return; if (fme == null || dame == null) return;
}
FLocation floc = new FLocation(fme.getPlayer().getLocation()); FLocation floc = new FLocation(fme.getPlayer().getLocation());
if(floc == null) return;
if (Board.getInstance().getFactionAt(floc) == fme.getFaction()) { if (Board.getInstance().getFactionAt(floc) == fme.getFaction()) {
if (dame.getFaction() == fme.getFaction()) { if (dame.getFaction() == fme.getFaction()) return;
return;
}
double damage = e.getDamage(); double damage = e.getDamage();
int level = fme.getFaction().getUpgrade(UpgradeType.DAMAGEDECREASE); int level = fme.getFaction().getUpgrade(UpgradeType.DAMAGEDECREASE);
double increase = FactionsPlugin.getInstance().getConfig().getDouble("fupgrades.MainMenu.DamageReduction.DamageReductionPercent.level-" + level); double increase = FactionsPlugin.getInstance().getConfig().getDouble("fupgrades.MainMenu.DamageReduction.DamageReductionPercent.level-" + level);
@ -50,20 +50,17 @@ public class UpgradesListener implements Listener {
@EventHandler @EventHandler
public static void onDamageIncrease(EntityDamageByEntityEvent e) { public static void onDamageIncrease(EntityDamageByEntityEvent e) {
if (e == null) { if (e == null) return;
return;
} if (!(e.getDamager() instanceof Player) || !(e.getEntity() instanceof Player)) return;
if (!(e.getDamager() instanceof Player) || !(e.getEntity() instanceof Player)) {
return;
}
if (e.getDamager().hasMetadata("NPC") || e.getEntity().hasMetadata("NPC")) return; if (e.getDamager().hasMetadata("NPC") || e.getEntity().hasMetadata("NPC")) return;
FPlayer fme = FPlayers.getInstance().getByPlayer((Player) e.getEntity()); FPlayer fme = FPlayers.getInstance().getByPlayer((Player) e.getEntity());
FPlayer dame = FPlayers.getInstance().getByPlayer((Player) e.getDamager()); FPlayer dame = FPlayers.getInstance().getByPlayer((Player) e.getDamager());
if (fme == null || dame == null) { if (fme == null || dame == null) return;
return;
}
FLocation floc = new FLocation(fme.getPlayer().getLocation()); FLocation floc = new FLocation(fme.getPlayer().getLocation());
@ -87,9 +84,8 @@ public class UpgradesListener implements Listener {
@EventHandler @EventHandler
public void onDeath(EntityDeathEvent e) { public void onDeath(EntityDeathEvent e) {
Entity killer = e.getEntity().getKiller(); Entity killer = e.getEntity().getKiller();
if (killer == null || !(killer instanceof Player)) { if (killer == null || !(killer instanceof Player)) return;
return;
}
FLocation floc = new FLocation(e.getEntity().getLocation()); FLocation floc = new FLocation(e.getEntity().getLocation());
Faction faction = Board.getInstance().getFactionAt(floc); Faction faction = Board.getInstance().getFactionAt(floc);
if (!faction.isWilderness()) { if (!faction.isWilderness()) {
@ -112,9 +108,7 @@ public class UpgradesListener implements Listener {
Faction factionAtLoc = Board.getInstance().getFactionAt(floc); Faction factionAtLoc = Board.getInstance().getFactionAt(floc);
if (!factionAtLoc.isWilderness()) { if (!factionAtLoc.isWilderness()) {
int level = factionAtLoc.getUpgrade(UpgradeType.SPAWNER); int level = factionAtLoc.getUpgrade(UpgradeType.SPAWNER);
if (level == 0) { if (level == 0) return;
return;
}
this.lowerSpawnerDelay(e, FactionsPlugin.getInstance().getConfig().getDouble("fupgrades.MainMenu.Spawners.Spawner-Boost.level-" + level)); this.lowerSpawnerDelay(e, FactionsPlugin.getInstance().getConfig().getDouble("fupgrades.MainMenu.Spawners.Spawner-Boost.level-" + level));
} }
} }
@ -131,13 +125,10 @@ public class UpgradesListener implements Listener {
if (!factionAtLoc.isWilderness()) { if (!factionAtLoc.isWilderness()) {
int level = factionAtLoc.getUpgrade(UpgradeType.CROP); int level = factionAtLoc.getUpgrade(UpgradeType.CROP);
int chance = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Crops.Crop-Boost.level-" + level); int chance = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Crops.Crop-Boost.level-" + level);
if (level == 0 || chance == 0) { if (level == 0 || chance == 0) return;
return;
}
int randomNum = ThreadLocalRandom.current().nextInt(1, 101); int randomNum = ThreadLocalRandom.current().nextInt(1, 101);
if (randomNum <= chance) { if (randomNum <= chance) this.growCrop(e);
this.growCrop(e);
}
} }
} }
@ -173,21 +164,16 @@ public class UpgradesListener implements Listener {
if (!factionAtLoc.isWilderness()) { if (!factionAtLoc.isWilderness()) {
int level = factionAtLoc.getUpgrade(UpgradeType.REDSTONE); int level = factionAtLoc.getUpgrade(UpgradeType.REDSTONE);
if (level != 0) { if (level != 0) {
if (level == 1) { if (level == 1) FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Redstone.Cost");
FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Redstone.Cost"); if (unbreakable.contains(block)) e.setCancelled(true);
}
if (unbreakable.contains(block)) {
e.setCancelled(true);
}
} }
} }
} }
@EventHandler @EventHandler
public void onArmorDamage(PlayerItemDamageEvent e) { public void onArmorDamage(PlayerItemDamageEvent e) {
if (FPlayers.getInstance().getByPlayer(e.getPlayer()) == null) { if (FPlayers.getInstance().getByPlayer(e.getPlayer()) == null) return;
return;
}
if (e.getItem().getType().toString().contains("LEGGINGS") || e.getItem().getType().toString().contains("CHESTPLATE") || e.getItem().getType().toString().contains("HELMET") || e.getItem().getType().toString().contains("BOOTS")) { if (e.getItem().getType().toString().contains("LEGGINGS") || e.getItem().getType().toString().contains("CHESTPLATE") || e.getItem().getType().toString().contains("HELMET") || e.getItem().getType().toString().contains("BOOTS")) {
int lvl = FPlayers.getInstance().getByPlayer(e.getPlayer()).getFaction().getUpgrade(UpgradeType.REINFORCEDARMOR); int lvl = FPlayers.getInstance().getByPlayer(e.getPlayer()).getFaction().getUpgrade(UpgradeType.REINFORCEDARMOR);
double drop = FactionsPlugin.getInstance().getConfig().getDouble("fupgrades.MainMenu.Armor.Armor-HP-Drop.level-" + lvl); double drop = FactionsPlugin.getInstance().getConfig().getDouble("fupgrades.MainMenu.Armor.Armor-HP-Drop.level-" + lvl);

View File

@ -974,7 +974,6 @@ public abstract class MemoryFPlayer implements FPlayer {
if (!fly) { if (!fly) {
sendMessage(TL.COMMAND_FLY_COOLDOWN.toString().replace("{amount}", FactionsPlugin.getInstance().getConfig().getInt("fly-falldamage-cooldown", 3) + "")); sendMessage(TL.COMMAND_FLY_COOLDOWN.toString().replace("{amount}", FactionsPlugin.getInstance().getConfig().getInt("fly-falldamage-cooldown", 3) + ""));
} }
} else { } else {
msg(TL.COMMAND_FLY_DAMAGE); msg(TL.COMMAND_FLY_DAMAGE);
} }
@ -1023,7 +1022,7 @@ public abstract class MemoryFPlayer implements FPlayer {
} }
if (faction.isSystemFaction()) { if (faction.isSystemFaction()) {
return CmdFly.checkBypassPerms(this, getPlayer(), faction); return CmdFly.checkBypassPerms(this, getPlayer(), faction, false);
} }
Access access = faction.getAccess(this, PermissableAction.FLY); Access access = faction.getAccess(this, PermissableAction.FLY);

View File

@ -1277,9 +1277,10 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
if (Conf.logFactionDisband) if (Conf.logFactionDisband)
FactionsPlugin.getInstance().log("The faction " + this.getTag() + " (" + this.getId() + ") has been disbanded since it has no members left" + (autoLeave ? " and by inactivity" : "") + "."); FactionsPlugin.getInstance().log("The faction " + this.getTag() + " (" + this.getId() + ") has been disbanded since it has no members left" + (autoLeave ? " and by inactivity" : "") + ".");
if(FactionsPlugin.getInstance().getConfig().getBoolean("faction-disband-broadcast")) {
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers())
fplayer.msg(TL.COMMAND_DISBAND_BROADCAST_GENERIC, this.getTag(fplayer)); fplayer.msg(TL.COMMAND_DISBAND_BROADCAST_GENERIC, this.getTag(fplayer));
}
FactionDisbandEvent disbandEvent = new FactionDisbandEvent(null, getId(), autoLeave ? PlayerDisbandReason.INACTIVITY : PlayerDisbandReason.LEAVE); FactionDisbandEvent disbandEvent = new FactionDisbandEvent(null, getId(), autoLeave ? PlayerDisbandReason.INACTIVITY : PlayerDisbandReason.LEAVE);

View File

@ -148,7 +148,7 @@ public enum TL {
COMMAND_AHOME_DESCRIPTION("Send a player to their f home no matter what."), COMMAND_AHOME_DESCRIPTION("Send a player to their f home no matter what."),
COMMAND_AHOME_NOHOME("%1$s doesn't have an f home."), COMMAND_AHOME_NOHOME("%1$s doesn't have an f home."),
COMMAND_AHOME_SUCCESS("$1%s was sent to their f home."), COMMAND_AHOME_SUCCESS("%1%s was sent to their f home."),
COMMAND_AHOME_OFFLINE("%1$s is offline."), COMMAND_AHOME_OFFLINE("%1$s is offline."),
COMMAND_AHOME_TARGET("You were sent to your f home."), COMMAND_AHOME_TARGET("You were sent to your f home."),

View File

@ -105,7 +105,6 @@ public class TagUtil {
if (FactionsPlugin.getInstance().isMVdWPlaceholderAPIHooked() && player.isOnline()) { if (FactionsPlugin.getInstance().isMVdWPlaceholderAPIHooked() && player.isOnline()) {
line = be.maximvdw.placeholderapi.PlaceholderAPI.replacePlaceholders(player, line); line = be.maximvdw.placeholderapi.PlaceholderAPI.replacePlaceholders(player, line);
} }
return line; return line;
} }

View File

@ -47,33 +47,41 @@ public class TextUtil {
String text = ""; String text = "";
FancyMessage message = new FancyMessage(text); FancyMessage message = new FancyMessage(text);
ChatColor color = null; ChatColor color = null;
ChatColor style = null;
char[] chars = first.toCharArray(); char[] chars = first.toCharArray();
for (int i = 0; i < chars.length; i++) { for (int i = 0; i < chars.length; i++) {
// changed this so javadocs wont throw an error // changed this so javadocs wont throw an error
String compareChar = chars[i] + ""; String compareChar = chars[i] + "";
if (compareChar.equals("§")) { if (compareChar.equals("§")) {
if (color != null) { if (color != null || style != null) {
if (color.isColor()) { message.then(text);
message.then(text).color(color); if (color != null)
} else { message.color(color);
message.then(text).style(color); if (style != null) {
message.style(style);
style = null;
} }
text = ""; text = "";
} }
color = ChatColor.getByChar(chars[i + 1]); ChatColor tempColor = ChatColor.getByChar(chars[i + 1]);
if (tempColor.isColor()) {
color = tempColor;
} else {
style = tempColor;
}
i++; // skip color char i++; // skip color char
} else { } else {
text += chars[i]; text += chars[i];
} }
} }
if (text.length() > 0) { if (text.length() > 0) {
if (color != null) { if (color != null || style != null) {
if (color.isColor()) { message.then(text);
message.then(text).color(color); if (color != null)
} else { message.color(color);
message.then(text).style(color); if (style != null)
} message.style(style);
} else { } else {
message.text(text); message.text(text);
} }

View File

@ -832,7 +832,7 @@ Missions:
- "&b&lMine &f&n10,000&r &2Sugar Cane" - "&b&lMine &f&n10,000&r &2Sugar Cane"
Mission: Mission:
Type: "MINE" Type: "MINE"
Material: "SUGAR_CANE_BLOCK" Material: "SUGAR_CANE"
Amount: 10000 Amount: 10000
Reward: Reward:
Commands: ["f points add %faction% 100"] Commands: ["f points add %faction% 100"]
@ -1250,9 +1250,9 @@ fupgrades:
Members: Members:
Max-Level: 3 Max-Level: 3
Members-Limit: Members-Limit:
level-1: 30 level-1: 5 #The Number Of Members It Will Increase By
level-2: 35 level-2: 10
level-3: 40 level-3: 15
Cost: Cost:
level-1: 1000000 level-1: 1000000
level-2: 2000000 level-2: 2000000
@ -1266,9 +1266,9 @@ fupgrades:
- '&7&oYour current level is &e&l&o{level}' - '&7&oYour current level is &e&l&o{level}'
- '' - ''
- '&c&lFaction Member Limit' - '&c&lFaction Member Limit'
- '&4&l* &cLevel 1: &f30' - '&4&l* &cLevel 1: &f35'
- '&4&l* &cLevel 2: &f35' - '&4&l* &cLevel 2: &f40'
- '&4&l* &cLevel 3: &f40' - '&4&l* &cLevel 3: &f45'
- '&f' - '&f'
- '&c&lCosts' - '&c&lCosts'
- '&4&l* &cLevel 1: &f$1,000,000' - '&4&l* &cLevel 1: &f$1,000,000'