2018-03-04 23:13:32 +01:00
|
|
|
package com.massivecraft.factions.cmd;
|
|
|
|
|
2018-03-31 18:46:37 +02:00
|
|
|
|
2018-03-26 23:43:15 +02:00
|
|
|
import com.massivecraft.factions.*;
|
2018-03-04 23:13:32 +01:00
|
|
|
import com.massivecraft.factions.struct.Permission;
|
2018-03-26 23:43:15 +02:00
|
|
|
import com.massivecraft.factions.struct.Relation;
|
2018-04-01 16:13:23 +02:00
|
|
|
import com.massivecraft.factions.util.Particles.ParticleEffect;
|
2018-04-04 05:20:30 +02:00
|
|
|
import com.massivecraft.factions.util.WarmUpUtil;
|
2018-04-07 23:29:24 +02:00
|
|
|
import com.massivecraft.factions.zcore.fperms.Access;
|
|
|
|
import com.massivecraft.factions.zcore.fperms.PermissableAction;
|
2018-03-04 23:13:32 +01:00
|
|
|
import com.massivecraft.factions.zcore.util.TL;
|
2018-03-26 23:43:15 +02:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.GameMode;
|
2018-07-29 21:34:40 +02:00
|
|
|
import org.bukkit.Particle;
|
2018-03-26 23:43:15 +02:00
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2018-04-09 05:13:41 +02:00
|
|
|
import java.util.ConcurrentModificationException;
|
2018-03-27 15:17:55 +02:00
|
|
|
import java.util.List;
|
2018-05-03 16:03:16 +02:00
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
2018-03-04 23:13:32 +01:00
|
|
|
|
|
|
|
public class CmdFly extends FCommand {
|
|
|
|
|
2018-03-26 23:43:15 +02:00
|
|
|
|
2018-05-03 16:03:16 +02:00
|
|
|
public static ConcurrentHashMap<String, Boolean> flyMap = new ConcurrentHashMap<String, Boolean>();
|
2018-11-07 06:38:43 +01:00
|
|
|
public static int id = - 1;
|
|
|
|
public static int flyid = - 1;
|
2018-07-12 18:11:07 +02:00
|
|
|
|
2018-03-04 23:13:32 +01:00
|
|
|
public CmdFly() {
|
|
|
|
super();
|
|
|
|
this.aliases.add("fly");
|
|
|
|
|
|
|
|
this.optionalArgs.put("on/off", "flip");
|
|
|
|
|
2018-03-04 23:16:17 +01:00
|
|
|
this.permission = Permission.FLY.node;
|
2018-03-04 23:13:32 +01:00
|
|
|
this.senderMustBeMember = true;
|
|
|
|
this.senderMustBeModerator = false;
|
|
|
|
}
|
|
|
|
|
2018-04-01 16:13:23 +02:00
|
|
|
public static void startParticles() {
|
2018-09-10 17:05:16 +02:00
|
|
|
// Just a secondary check.
|
2018-11-07 17:14:42 +01:00
|
|
|
if (!SavageFactions.plugin.getConfig().getBoolean("ffly.Particles.Enabled")) {
|
2018-09-10 17:05:16 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-07 06:38:43 +01:00
|
|
|
id = Bukkit.getScheduler().scheduleSyncRepeatingTask(SavageFactions.plugin, new Runnable() {
|
2018-04-01 16:13:23 +02:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
for (String name : flyMap.keySet()) {
|
|
|
|
Player player = Bukkit.getPlayer(name);
|
|
|
|
if (player == null) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-11-07 17:14:42 +01:00
|
|
|
if (!player.isFlying()) {
|
2018-04-01 16:13:23 +02:00
|
|
|
continue;
|
|
|
|
}
|
2018-11-07 17:14:42 +01:00
|
|
|
if (!SavageFactions.plugin.mc17) {
|
2018-07-12 18:11:07 +02:00
|
|
|
if (player.getGameMode() == GameMode.SPECTATOR) {
|
2018-06-21 21:16:55 +02:00
|
|
|
continue;
|
|
|
|
}
|
2018-04-14 04:05:43 +02:00
|
|
|
}
|
2018-08-05 03:32:36 +02:00
|
|
|
|
2018-08-02 16:29:41 +02:00
|
|
|
if (FPlayers.getInstance().getByPlayer(player).isVanished()) {
|
|
|
|
// Actually, vanished players (such as admins) should not display particles to prevent others from knowing their vanished assistance for moderation.
|
|
|
|
// But we can keep it as a config.
|
2018-11-07 06:38:43 +01:00
|
|
|
if (SavageFactions.plugin.getConfig().getBoolean("ffly.Particles.Enable-While-Vanished")) {
|
2018-08-02 16:29:41 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2018-11-07 06:38:43 +01:00
|
|
|
if (SavageFactions.plugin.useNonPacketParticles) {
|
2018-07-29 21:34:40 +02:00
|
|
|
// 1.9+ based servers will use the built in particleAPI instead of packet based.
|
|
|
|
// any particle amount higher than 0 made them go everywhere, and the offset at 0 was not working.
|
|
|
|
// So setting the amount to 0 spawns 1 in the precise location
|
2018-11-07 06:38:43 +01:00
|
|
|
player.getWorld().spawnParticle(Particle.CLOUD, player.getLocation().add(0, - 0.35, 0), 0);
|
2018-07-29 21:34:40 +02:00
|
|
|
} else {
|
2018-11-07 06:38:43 +01:00
|
|
|
ParticleEffect.CLOUD.display((float) 0, (float) 0, (float) 0, (float) 0, 3, player.getLocation().add(0, - 0.35, 0), 16);
|
2018-07-29 21:34:40 +02:00
|
|
|
}
|
|
|
|
|
2018-04-01 16:13:23 +02:00
|
|
|
}
|
|
|
|
if (flyMap.keySet().size() == 0) {
|
|
|
|
Bukkit.getScheduler().cancelTask(id);
|
2018-11-07 06:38:43 +01:00
|
|
|
id = - 1;
|
2018-04-01 16:13:23 +02:00
|
|
|
}
|
|
|
|
}
|
2018-04-14 04:05:43 +02:00
|
|
|
}, 10L, 3L);
|
2018-04-01 16:13:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void startFlyCheck() {
|
2018-11-07 06:38:43 +01:00
|
|
|
flyid = Bukkit.getScheduler().scheduleSyncRepeatingTask(SavageFactions.plugin, new Runnable() {
|
2018-04-01 16:13:23 +02:00
|
|
|
@Override
|
2018-04-09 05:13:41 +02:00
|
|
|
public void run() throws ConcurrentModificationException { //threw the exception for now, until I recode fly :( Cringe.
|
2018-04-07 23:29:24 +02:00
|
|
|
checkTaskState();
|
|
|
|
if (flyMap.keySet().size() != 0) {
|
2018-07-12 18:11:07 +02:00
|
|
|
for (String name : flyMap.keySet()) {
|
|
|
|
if (name == null) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Player player = Bukkit.getPlayer(name);
|
|
|
|
if (player == null) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-11-07 17:14:42 +01:00
|
|
|
if (!player.isFlying()) {
|
2018-07-12 18:11:07 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player);
|
|
|
|
if (fPlayer == null) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-10-26 22:10:50 +02:00
|
|
|
if (player.getGameMode() == GameMode.CREATIVE) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-11-07 17:14:42 +01:00
|
|
|
if (!SavageFactions.plugin.mc17 && player.getGameMode() == GameMode.SPECTATOR) {
|
2018-07-12 18:11:07 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Faction myFaction = fPlayer.getFaction();
|
|
|
|
if (myFaction.isWilderness()) {
|
|
|
|
fPlayer.setFlying(false);
|
|
|
|
flyMap.remove(name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (fPlayer.checkIfNearbyEnemies()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
FLocation myFloc = new FLocation(player.getLocation());
|
|
|
|
Faction toFac = Board.getInstance().getFactionAt(myFloc);
|
|
|
|
if (Board.getInstance().getFactionAt(myFloc) != myFaction) {
|
2018-11-07 17:14:42 +01:00
|
|
|
if (!checkBypassPerms(fPlayer, player, toFac)) {
|
2018-04-07 23:29:24 +02:00
|
|
|
fPlayer.setFlying(false);
|
|
|
|
flyMap.remove(name);
|
|
|
|
continue;
|
|
|
|
}
|
2018-04-09 05:13:41 +02:00
|
|
|
}
|
2018-07-12 18:11:07 +02:00
|
|
|
|
|
|
|
}
|
2018-04-01 16:13:23 +02:00
|
|
|
}
|
2018-04-07 23:29:24 +02:00
|
|
|
|
2018-04-01 16:13:23 +02:00
|
|
|
}
|
|
|
|
}, 20L, 20L);
|
|
|
|
}
|
|
|
|
|
2018-09-03 17:11:57 +02:00
|
|
|
private static boolean checkBypassPerms(FPlayer fme, Player me, Faction toFac) {
|
|
|
|
if (toFac != fme.getFaction()) {
|
2018-11-07 17:14:42 +01:00
|
|
|
if (!me.hasPermission("factions.fly.wilderness") && toFac.isWilderness() || !me.hasPermission("factions.fly.safezone") && toFac.isSafeZone() || !me.hasPermission("factions.fly.warzone") && toFac.isWarZone()) {
|
2018-09-03 17:11:57 +02:00
|
|
|
fme.msg(TL.COMMAND_FLY_NO_ACCESS, toFac.getTag(fme));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Access access = toFac.getAccess(fme, PermissableAction.FLY);
|
2018-11-07 17:14:42 +01:00
|
|
|
if ((!(me.hasPermission("factions.fly.enemy") || access == Access.ALLOW)) && toFac.getRelationTo(fme.getFaction()) == Relation.ENEMY) {
|
2018-09-03 17:11:57 +02:00
|
|
|
fme.msg(TL.COMMAND_FLY_NO_ACCESS, toFac.getTag(fme));
|
|
|
|
return false;
|
|
|
|
}
|
2018-11-07 17:14:42 +01:00
|
|
|
if (!(me.hasPermission("factions.fly.ally") || access == Access.ALLOW) && toFac.getRelationTo(fme.getFaction()) == Relation.ALLY) {
|
2018-09-03 17:11:57 +02:00
|
|
|
fme.msg(TL.COMMAND_FLY_NO_ACCESS, toFac.getTag(fme));
|
|
|
|
return false;
|
|
|
|
}
|
2018-11-07 17:14:42 +01:00
|
|
|
if (!(me.hasPermission("factions.fly.truce") || access == Access.ALLOW) && toFac.getRelationTo(fme.getFaction()) == Relation.TRUCE) {
|
2018-09-03 17:11:57 +02:00
|
|
|
fme.msg(TL.COMMAND_FLY_NO_ACCESS, toFac.getTag(fme));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-11-07 17:14:42 +01:00
|
|
|
if (!(me.hasPermission("factions.fly.neutral") || access == Access.ALLOW) && toFac.getRelationTo(fme.getFaction()) == Relation.NEUTRAL && !isSystemFaction(toFac)) {
|
2018-09-03 17:11:57 +02:00
|
|
|
fme.msg(TL.COMMAND_FLY_NO_ACCESS, toFac.getTag(fme));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return me.hasPermission("factions.fly") && access != Access.DENY;
|
2018-04-04 05:20:30 +02:00
|
|
|
}
|
2018-09-03 17:11:57 +02:00
|
|
|
return true;
|
2018-04-04 05:20:30 +02:00
|
|
|
}
|
|
|
|
|
2018-04-07 23:29:24 +02:00
|
|
|
public static Boolean isSystemFaction(Faction faction) {
|
|
|
|
return faction.isSafeZone() ||
|
|
|
|
faction.isWarZone() ||
|
|
|
|
faction.isWilderness();
|
|
|
|
}
|
|
|
|
|
2018-07-12 18:11:07 +02:00
|
|
|
public static void checkTaskState() {
|
|
|
|
if (flyMap.keySet().size() == 0) {
|
|
|
|
Bukkit.getScheduler().cancelTask(flyid);
|
2018-11-07 06:38:43 +01:00
|
|
|
flyid = - 1;
|
2018-07-12 18:11:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isInFlightChecker(Player player) {
|
|
|
|
return flyMap.containsKey(player.getName());
|
|
|
|
}
|
|
|
|
|
2018-03-04 23:13:32 +01:00
|
|
|
@Override
|
|
|
|
public void perform() {
|
2018-03-26 23:43:15 +02:00
|
|
|
// Disabled by default.
|
2018-11-07 17:14:42 +01:00
|
|
|
if (!SavageFactions.plugin.getConfig().getBoolean("enable-faction-flight", false)) {
|
2018-03-26 23:43:15 +02:00
|
|
|
fme.msg(TL.COMMAND_FLY_DISABLED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FLocation myfloc = new FLocation(me.getLocation());
|
|
|
|
Faction toFac = Board.getInstance().getFactionAt(myfloc);
|
2018-11-07 17:14:42 +01:00
|
|
|
if (!checkBypassPerms(fme, me, toFac)) return;
|
2018-09-20 22:55:19 +02:00
|
|
|
List<Entity> entities = this.me.getNearbyEntities(16.0D, 256.0D, 16.0D);
|
|
|
|
|
2018-11-07 06:38:43 +01:00
|
|
|
for (int i = 0; i <= entities.size() - 1; ++ i) {
|
2018-07-12 18:11:07 +02:00
|
|
|
if (entities.get(i) instanceof Player) {
|
2018-11-07 06:38:43 +01:00
|
|
|
Player eplayer = (Player) entities.get(i);
|
2018-03-26 23:43:15 +02:00
|
|
|
FPlayer efplayer = FPlayers.getInstance().getByPlayer(eplayer);
|
2018-11-07 17:14:42 +01:00
|
|
|
if (efplayer.getRelationTo(this.fme) == Relation.ENEMY && !efplayer.isStealthEnabled()) {
|
2018-09-20 22:55:19 +02:00
|
|
|
this.fme.msg(TL.COMMAND_FLY_CHECK_ENEMY);
|
2018-03-26 23:43:15 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-04 23:13:32 +01:00
|
|
|
if (args.size() == 0) {
|
2018-11-07 17:14:42 +01:00
|
|
|
toggleFlight(!fme.isFlying(), me);
|
2018-03-04 23:13:32 +01:00
|
|
|
} else if (args.size() == 1) {
|
2018-07-12 18:11:07 +02:00
|
|
|
toggleFlight(argAsBool(0), me);
|
2018-03-26 23:43:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void toggleFlight(final boolean toggle, final Player player) {
|
2018-11-07 17:14:42 +01:00
|
|
|
if (!toggle) {
|
2018-03-04 23:13:32 +01:00
|
|
|
fme.setFlying(false);
|
2018-03-26 23:43:15 +02:00
|
|
|
flyMap.remove(player.getName());
|
2018-03-04 23:13:32 +01:00
|
|
|
return;
|
|
|
|
}
|
2018-04-07 23:29:24 +02:00
|
|
|
|
|
|
|
if (fme.canFlyAtLocation())
|
|
|
|
|
|
|
|
this.doWarmUp(WarmUpUtil.Warmup.FLIGHT, TL.WARMUPS_NOTIFY_FLIGHT, "Fly", new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
fme.setFlying(true);
|
2018-07-12 18:11:07 +02:00
|
|
|
flyMap.put(player.getName(), true);
|
2018-11-07 06:38:43 +01:00
|
|
|
if (id == - 1) {
|
|
|
|
if (SavageFactions.plugin.getConfig().getBoolean("ffly.Particles.Enabled")) {
|
2018-04-07 23:29:24 +02:00
|
|
|
startParticles();
|
|
|
|
}
|
|
|
|
}
|
2018-11-07 06:38:43 +01:00
|
|
|
if (flyid == - 1) {
|
2018-04-07 23:29:24 +02:00
|
|
|
startFlyCheck();
|
2018-03-26 23:43:15 +02:00
|
|
|
}
|
|
|
|
}
|
2018-04-07 23:29:24 +02:00
|
|
|
}, this.p.getConfig().getLong("warmups.f-fly", 0));
|
2018-03-04 23:13:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TL getUsageTranslation() {
|
|
|
|
return TL.COMMAND_FLY_DESCRIPTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|