2018-03-04 23:13:32 +01:00
|
|
|
package com.massivecraft.factions.cmd;
|
|
|
|
|
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-03-04 23:13:32 +01:00
|
|
|
import com.massivecraft.factions.util.WarmUpUtil;
|
|
|
|
import com.massivecraft.factions.zcore.util.TL;
|
2018-03-26 23:43:15 +02:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.GameMode;
|
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.entity.Player;
|
2018-03-29 02:33:10 +02:00
|
|
|
import org.inventivetalent.particle.ParticleEffect;
|
2018-03-26 23:43:15 +02:00
|
|
|
|
2018-03-27 15:17:55 +02:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
2018-03-04 23:13:32 +01:00
|
|
|
|
|
|
|
public class CmdFly extends FCommand {
|
|
|
|
|
2018-03-26 23:43:15 +02:00
|
|
|
|
|
|
|
public static HashMap<String,Boolean> flyMap = new HashMap<String,Boolean>();
|
|
|
|
public int id = -1;
|
|
|
|
public int flyid = -1;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void perform() {
|
2018-03-26 23:43:15 +02:00
|
|
|
// Disabled by default.
|
|
|
|
if (!P.p.getConfig().getBoolean("enable-faction-flight", false)) {
|
|
|
|
fme.msg(TL.COMMAND_FLY_DISABLED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FLocation myfloc = new FLocation(me.getLocation());
|
|
|
|
Faction toFac = Board.getInstance().getFactionAt(myfloc);
|
|
|
|
if (Board.getInstance().getFactionAt(myfloc) != fme.getFaction()){
|
|
|
|
if (!me.hasPermission("factions.fly.wilderness") && toFac.isWilderness()) {
|
|
|
|
fme.msg(TL.COMMAND_FLY_NO_ACCESS, Board.getInstance().getFactionAt(myfloc).getTag(fme));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!me.hasPermission("factions.fly.safezone") && toFac.isSafeZone()) {
|
|
|
|
fme.msg(TL.COMMAND_FLY_NO_ACCESS, Board.getInstance().getFactionAt(myfloc).getTag(fme));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!me.hasPermission("factions.fly.warzone") && toFac.isWarZone()) {
|
|
|
|
fme.msg(TL.COMMAND_FLY_NO_ACCESS, Board.getInstance().getFactionAt(myfloc).getTag(fme));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!me.hasPermission("factions.fly.enemy") && toFac.getRelationTo(myFaction)== Relation.ENEMY){
|
|
|
|
fme.msg(TL.COMMAND_FLY_NO_ACCESS, Board.getInstance().getFactionAt(myfloc).getTag(fme));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!me.hasPermission("factions.fly.ally") && toFac.getRelationTo(myFaction)== Relation.ALLY){
|
|
|
|
fme.msg(TL.COMMAND_FLY_NO_ACCESS, Board.getInstance().getFactionAt(myfloc).getTag(fme));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!me.hasPermission("factions.fly.truce") && toFac.getRelationTo(myFaction)== Relation.TRUCE){
|
|
|
|
fme.msg(TL.COMMAND_FLY_NO_ACCESS, Board.getInstance().getFactionAt(myfloc).getTag(fme));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!me.hasPermission("factions.fly.neutral") && toFac.getRelationTo(myFaction) == Relation.NEUTRAL) {
|
|
|
|
fme.msg(TL.COMMAND_FLY_NO_ACCESS, Board.getInstance().getFactionAt(myfloc).getTag(fme));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<Entity> entities = me.getNearbyEntities(16,256,16);
|
|
|
|
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(fme) == Relation.ENEMY)
|
|
|
|
{
|
|
|
|
fme.msg(TL.COMMAND_FLY_CHECK_ENEMY);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-04 23:13:32 +01:00
|
|
|
if (args.size() == 0) {
|
|
|
|
if (!fme.canFlyAtLocation() && !fme.isFlying()) {
|
2018-03-26 23:43:15 +02:00
|
|
|
if (!me.hasPermission("factions.fly.wilderness") && toFac.isWilderness()) {
|
|
|
|
fme.msg(TL.COMMAND_FLY_NO_ACCESS, Board.getInstance().getFactionAt(myfloc).getTag(fme));
|
|
|
|
return;
|
|
|
|
} else if (!me.hasPermission("factions.fly.safezone") && toFac.isSafeZone()) {
|
|
|
|
fme.msg(TL.COMMAND_FLY_NO_ACCESS, Board.getInstance().getFactionAt(myfloc).getTag(fme));
|
|
|
|
return;
|
|
|
|
} else if (!me.hasPermission("factions.fly.warzone") && toFac.isWarZone()) {
|
|
|
|
fme.msg(TL.COMMAND_FLY_NO_ACCESS, Board.getInstance().getFactionAt(myfloc).getTag(fme));
|
|
|
|
return;
|
|
|
|
} else if (!me.hasPermission("factions.fly.enemy") && toFac.getRelationTo(myFaction) == Relation.ENEMY) {
|
|
|
|
fme.msg(TL.COMMAND_FLY_NO_ACCESS, Board.getInstance().getFactionAt(myfloc).getTag(fme));
|
|
|
|
return;
|
|
|
|
} else if (!me.hasPermission("factions.fly.ally") && toFac.getRelationTo(myFaction) == Relation.ALLY) {
|
|
|
|
fme.msg(TL.COMMAND_FLY_NO_ACCESS, Board.getInstance().getFactionAt(myfloc).getTag(fme));
|
|
|
|
return;
|
|
|
|
} else if (!me.hasPermission("factions.fly.truce") && toFac.getRelationTo(myFaction) == Relation.TRUCE) {
|
|
|
|
fme.msg(TL.COMMAND_FLY_NO_ACCESS, Board.getInstance().getFactionAt(myfloc).getTag(fme));
|
|
|
|
} else if (!me.hasPermission("factions.fly.neutral") && toFac.getRelationTo(myFaction) == Relation.NEUTRAL) {
|
|
|
|
fme.msg(TL.COMMAND_FLY_NO_ACCESS, Board.getInstance().getFactionAt(myfloc).getTag(fme));
|
|
|
|
}
|
|
|
|
|
2018-03-04 23:13:32 +01:00
|
|
|
}
|
|
|
|
|
2018-03-26 23:43:15 +02:00
|
|
|
toggleFlight(!fme.isFlying(),me);
|
2018-03-04 23:13:32 +01:00
|
|
|
} else if (args.size() == 1) {
|
|
|
|
if (!fme.canFlyAtLocation() && argAsBool(0)) {
|
2018-03-26 23:43:15 +02:00
|
|
|
if (!me.hasPermission("factions.fly.wilderness") && toFac.isWilderness()) {
|
|
|
|
fme.msg(TL.COMMAND_FLY_NO_ACCESS, Board.getInstance().getFactionAt(myfloc).getTag(fme));
|
|
|
|
return;
|
|
|
|
} else if (!me.hasPermission("factions.fly.safezone") && toFac.isSafeZone()) {
|
|
|
|
fme.msg(TL.COMMAND_FLY_NO_ACCESS, Board.getInstance().getFactionAt(myfloc).getTag(fme));
|
|
|
|
return;
|
|
|
|
} else if (!me.hasPermission("factions.fly.warzone") && toFac.isWarZone()) {
|
|
|
|
fme.msg(TL.COMMAND_FLY_NO_ACCESS, Board.getInstance().getFactionAt(myfloc).getTag(fme));
|
|
|
|
return;
|
|
|
|
} else if (!me.hasPermission("factions.fly.enemy") && toFac.getRelationTo(myFaction) == Relation.ENEMY) {
|
|
|
|
fme.msg(TL.COMMAND_FLY_NO_ACCESS, Board.getInstance().getFactionAt(myfloc).getTag(fme));
|
|
|
|
return;
|
|
|
|
} else if (!me.hasPermission("factions.fly.ally") && toFac.getRelationTo(myFaction) == Relation.ALLY) {
|
|
|
|
fme.msg(TL.COMMAND_FLY_NO_ACCESS, Board.getInstance().getFactionAt(myfloc).getTag(fme));
|
|
|
|
return;
|
|
|
|
} else if (!me.hasPermission("factions.fly.truce") && toFac.getRelationTo(myFaction) == Relation.TRUCE) {
|
|
|
|
fme.msg(TL.COMMAND_FLY_NO_ACCESS, Board.getInstance().getFactionAt(myfloc).getTag(fme));
|
|
|
|
} else if (!me.hasPermission("factions.fly.neutral") && toFac.getRelationTo(myFaction) == Relation.NEUTRAL) {
|
|
|
|
fme.msg(TL.COMMAND_FLY_NO_ACCESS, Board.getInstance().getFactionAt(myfloc).getTag(fme));
|
|
|
|
}
|
|
|
|
|
2018-03-04 23:13:32 +01:00
|
|
|
}
|
|
|
|
|
2018-03-26 23:43:15 +02:00
|
|
|
|
|
|
|
toggleFlight(argAsBool(0),me);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isInFlightChecker(Player player){
|
|
|
|
if (flyMap.containsKey(player.getName())){
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
2018-03-04 23:13:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-26 23:43:15 +02:00
|
|
|
|
|
|
|
public void startParticles(){
|
|
|
|
id = Bukkit.getScheduler().scheduleSyncRepeatingTask(P.p, new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
for(String name : flyMap.keySet()){
|
|
|
|
Player player = Bukkit.getPlayer(name);
|
|
|
|
if (player == null){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!player.isFlying()){
|
|
|
|
continue;
|
|
|
|
}
|
2018-03-29 02:33:10 +02:00
|
|
|
|
|
|
|
ParticleEffect.CLOUD.send(Bukkit.getOnlinePlayers(), player.getLocation().add(0, -0.35, 0), 0, 0, 0, 0, 3, 16);
|
2018-03-26 23:43:15 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
if (flyMap.keySet().size() == 0){
|
|
|
|
Bukkit.getScheduler().cancelTask(id);
|
|
|
|
id = -1;
|
|
|
|
}
|
|
|
|
}
|
2018-03-29 02:33:10 +02:00
|
|
|
}, 10L, 10L);
|
2018-03-26 23:43:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void startFlyCheck(){
|
|
|
|
flyid = Bukkit.getScheduler().scheduleSyncRepeatingTask(P.p, new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2018-03-27 15:17:55 +02:00
|
|
|
Iterator itr = flyMap.keySet().iterator();
|
|
|
|
while (itr.hasNext()) {
|
|
|
|
Object nameObj = itr.next();
|
|
|
|
String name = nameObj + "";
|
2018-03-26 23:43:15 +02:00
|
|
|
Player player = Bukkit.getPlayer(name);
|
|
|
|
if (player == null) { continue;}
|
|
|
|
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player);
|
|
|
|
|
|
|
|
if (fPlayer == null) { continue; }
|
|
|
|
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR){
|
|
|
|
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) {
|
|
|
|
if (!checkBypassPerms(fPlayer,player,toFac)){
|
|
|
|
fPlayer.setFlying(false);
|
|
|
|
flyMap.remove(name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-27 15:17:55 +02:00
|
|
|
checkTaskState();
|
2018-03-26 23:43:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},20L,20L);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean checkBypassPerms(FPlayer fplayer, Player player,Faction toFac){
|
|
|
|
if (player.hasPermission("factions.fly.wilderness") && toFac.isWilderness()){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (player.hasPermission("factions.fly.warzone") && toFac.isWarZone()){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (player.hasPermission("factions.fly.safezone") && toFac.isSafeZone()){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (player.hasPermission("factions.fly.enemy") && toFac.getRelationTo(fplayer.getFaction()) == Relation.ENEMY) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (player.hasPermission("factions.fly.ally") && toFac.getRelationTo(fplayer.getFaction()) == Relation.ALLY) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (player.hasPermission("factions.fly.truce") && toFac.getRelationTo(fplayer.getFaction()) == Relation.TRUCE) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (player.hasPermission("factions.fly.neutral") && toFac.getRelationTo(fplayer.getFaction()) == Relation.NEUTRAL) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void checkTaskState(){
|
|
|
|
if (flyMap.keySet().size() == 0) {
|
|
|
|
Bukkit.getScheduler().cancelTask(flyid);
|
|
|
|
flyid = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void toggleFlight(final boolean toggle, final Player player) {
|
2018-03-04 23:13:32 +01:00
|
|
|
if (!toggle) {
|
|
|
|
fme.setFlying(false);
|
2018-03-26 23:43:15 +02:00
|
|
|
flyMap.remove(player.getName());
|
2018-03-04 23:13:32 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.doWarmUp(WarmUpUtil.Warmup.FLIGHT, TL.WARMUPS_NOTIFY_FLIGHT, "Fly", new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
fme.setFlying(true);
|
2018-03-26 23:43:15 +02:00
|
|
|
flyMap.put(player.getName(),true);
|
|
|
|
if (id == -1){
|
|
|
|
if (P.p.getConfig().getBoolean("ffly.Particles.Enabled")){
|
|
|
|
startParticles();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (flyid == -1){
|
|
|
|
startFlyCheck();
|
|
|
|
}
|
2018-03-04 23:13:32 +01:00
|
|
|
}
|
|
|
|
}, this.p.getConfig().getLong("warmups.f-fly", 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TL getUsageTranslation() {
|
|
|
|
return TL.COMMAND_FLY_DESCRIPTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|