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-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;
|
2020-01-18 00:55:37 +01:00
|
|
|
import org.bukkit.ChatColor;
|
2018-03-26 23:43:15 +02:00
|
|
|
import org.bukkit.GameMode;
|
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.entity.Player;
|
2019-10-27 22:24:17 +01:00
|
|
|
import org.bukkit.scheduler.BukkitTask;
|
2018-03-26 23:43:15 +02:00
|
|
|
|
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 {
|
|
|
|
|
2019-12-02 19:55:38 +01:00
|
|
|
/**
|
|
|
|
* @author FactionsUUID Team
|
|
|
|
*/
|
|
|
|
|
2018-03-26 23:43:15 +02:00
|
|
|
|
2019-11-16 10:23:43 +01:00
|
|
|
public static ConcurrentHashMap<String, Boolean> flyMap = new ConcurrentHashMap<>();
|
|
|
|
public static BukkitTask particleTask = null;
|
2019-10-27 22:24:17 +01:00
|
|
|
public static BukkitTask flyTask = null;
|
|
|
|
|
2019-09-15 11:19:06 +02:00
|
|
|
|
|
|
|
public CmdFly() {
|
|
|
|
super();
|
2020-01-02 02:59:31 +01:00
|
|
|
this.aliases.addAll(Aliases.fly);
|
2019-09-15 11:19:06 +02:00
|
|
|
this.optionalArgs.put("on/off", "flip");
|
|
|
|
|
2020-01-18 00:55:37 +01:00
|
|
|
this.requirements = new CommandRequirements.Builder(Permission.FLY_FLY)
|
2019-09-15 11:19:06 +02:00
|
|
|
.playerOnly()
|
|
|
|
.memberOnly()
|
|
|
|
.build();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void startParticles() {
|
|
|
|
|
2019-11-16 10:23:43 +01:00
|
|
|
particleTask = Bukkit.getScheduler().runTaskTimerAsynchronously(FactionsPlugin.instance, () -> {
|
2019-09-15 11:19:06 +02:00
|
|
|
for (String name : flyMap.keySet()) {
|
|
|
|
Player player = Bukkit.getPlayer(name);
|
|
|
|
if (player == null) continue;
|
|
|
|
if (!player.isFlying()) continue;
|
|
|
|
if (!FactionsPlugin.getInstance().mc17) {
|
|
|
|
if (player.getGameMode() == GameMode.SPECTATOR) continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
FPlayer fplayer = FPlayers.getInstance().getByPlayer(player);
|
|
|
|
fplayer.isVanished();
|
|
|
|
}
|
2019-11-16 10:23:43 +01:00
|
|
|
if (flyMap.isEmpty()) {
|
|
|
|
particleTask.cancel();
|
|
|
|
particleTask = null;
|
2019-09-15 11:19:06 +02:00
|
|
|
}
|
|
|
|
}, 10L, 3L);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void startFlyCheck() {
|
2019-10-27 22:24:17 +01:00
|
|
|
flyTask = Bukkit.getScheduler().runTaskTimerAsynchronously(FactionsPlugin.instance, () -> {
|
2019-09-15 11:19:06 +02:00
|
|
|
checkTaskState();
|
|
|
|
if (flyMap.keySet().size() != 0) {
|
|
|
|
for (String name : flyMap.keySet()) {
|
|
|
|
if (name == null) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-08-24 19:18:50 +02:00
|
|
|
Player player = Bukkit.getPlayer(name);
|
2019-09-15 11:19:06 +02:00
|
|
|
if (player == null
|
|
|
|
|| !player.isFlying()
|
|
|
|
|| player.getGameMode() == GameMode.CREATIVE
|
|
|
|
|| !FactionsPlugin.getInstance().mc17 && player.getGameMode() == GameMode.SPECTATOR) {
|
|
|
|
continue;
|
2019-08-24 19:18:50 +02:00
|
|
|
}
|
2019-09-15 11:19:06 +02:00
|
|
|
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player);
|
|
|
|
Faction myFaction = fPlayer.getFaction();
|
2020-01-18 00:55:37 +01:00
|
|
|
if (!player.hasPermission("factions.fly.bypassnearbyenemycheck") && !fPlayer.isAdminBypassing()) {
|
|
|
|
if (fPlayer.hasEnemiesNearby()) disableFlightSync(fPlayer);
|
|
|
|
checkEnemiesSync(fPlayer);
|
2019-09-15 11:19:06 +02:00
|
|
|
continue;
|
2019-08-24 19:18:50 +02:00
|
|
|
}
|
2019-09-15 11:19:06 +02:00
|
|
|
FLocation myFloc = new FLocation(player.getLocation());
|
|
|
|
if (Board.getInstance().getFactionAt(myFloc) != myFaction) {
|
2020-01-18 00:55:37 +01:00
|
|
|
if (!checkFly(fPlayer, player, Board.getInstance().getFactionAt(myFloc))) {
|
|
|
|
disableFlightSync(fPlayer);
|
2019-09-15 11:19:06 +02:00
|
|
|
}
|
2019-08-24 19:18:50 +02:00
|
|
|
}
|
|
|
|
|
2019-09-15 11:19:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}, 20L, 20L);
|
|
|
|
}
|
|
|
|
|
2020-01-18 00:55:37 +01:00
|
|
|
public static boolean checkFly(FPlayer fme, Player me, Faction toFac) {
|
2019-11-28 08:09:21 +01:00
|
|
|
if (Conf.denyFlightIfInNoClaimingWorld && !Conf.worldsNoClaiming.isEmpty() && Conf.worldsNoClaiming.stream().anyMatch(me.getWorld().getName()::equalsIgnoreCase))
|
|
|
|
return false;
|
2020-01-18 00:55:37 +01:00
|
|
|
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;
|
2019-09-15 11:19:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void checkTaskState() {
|
2019-10-27 22:24:17 +01:00
|
|
|
if (flyMap.isEmpty()) {
|
|
|
|
flyTask.cancel();
|
|
|
|
flyTask = null;
|
2019-09-15 11:19:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void disableFlight(final FPlayer fme) {
|
|
|
|
fme.setFlying(false);
|
|
|
|
flyMap.remove(fme.getPlayer().getName());
|
|
|
|
}
|
|
|
|
|
2020-01-18 00:55:37 +01:00
|
|
|
private static void disableFlightSync(FPlayer fme) {
|
|
|
|
Bukkit.getScheduler().runTask(FactionsPlugin.instance, () -> fme.setFFlying(false, false));
|
|
|
|
flyMap.remove(fme.getName());
|
|
|
|
}
|
|
|
|
|
2019-09-15 11:19:06 +02:00
|
|
|
public boolean isInFlightChecker(Player player) {
|
|
|
|
return flyMap.containsKey(player.getName());
|
|
|
|
}
|
|
|
|
|
2020-01-18 00:55:37 +01:00
|
|
|
private static void checkEnemiesSync(FPlayer fp) {
|
|
|
|
Bukkit.getScheduler().runTask(FactionsPlugin.instance, fp::checkIfNearbyEnemies);
|
|
|
|
}
|
|
|
|
|
2019-09-15 11:19:06 +02:00
|
|
|
@Override
|
|
|
|
public void perform(CommandContext context) {
|
2020-01-18 00:55:37 +01:00
|
|
|
if (!context.fPlayer.isAdminBypassing()) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
context.fPlayer.setEnemiesNearby(false);
|
2019-09-15 11:19:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-18 00:55:37 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2019-09-15 11:19:06 +02:00
|
|
|
|
|
|
|
if (context.args.size() == 0) {
|
|
|
|
toggleFlight(context.fPlayer.isFlying(), context.fPlayer, context);
|
|
|
|
} else if (context.args.size() == 1) {
|
|
|
|
toggleFlight(context.argAsBool(0), context.fPlayer, context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void toggleFlight(final boolean toggle, final FPlayer fme, CommandContext context) {
|
|
|
|
if (toggle) {
|
|
|
|
fme.setFlying(false);
|
|
|
|
flyMap.remove(fme.getPlayer().getName());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
context.doWarmUp(WarmUpUtil.Warmup.FLIGHT, TL.WARMUPS_NOTIFY_FLIGHT, "Fly", () -> {
|
|
|
|
fme.setFlying(true);
|
|
|
|
flyMap.put(fme.getPlayer().getName(), true);
|
2019-11-16 10:23:43 +01:00
|
|
|
if (particleTask == null) {
|
|
|
|
startParticles();
|
|
|
|
}
|
|
|
|
|
2019-10-27 22:24:17 +01:00
|
|
|
if (flyTask == null) {
|
2019-09-15 11:19:06 +02:00
|
|
|
startFlyCheck();
|
|
|
|
}
|
|
|
|
}, FactionsPlugin.getInstance().getConfig().getLong("warmups.f-fly", 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TL getUsageTranslation() {
|
|
|
|
return TL.COMMAND_FLY_DESCRIPTION;
|
|
|
|
}
|
2018-03-04 23:13:32 +01:00
|
|
|
|
2019-09-14 21:13:01 +02:00
|
|
|
}
|