removed the iterator in fly checks.

...
This commit is contained in:
Naman 2018-04-01 09:13:23 -05:00
parent 21587db74d
commit 12b9f94fe4
11 changed files with 1850 additions and 1827 deletions

@ -47,6 +47,10 @@
<pattern>com.google.gson</pattern> <pattern>com.google.gson</pattern>
<shadedPattern>com.massivecraft.factions.shade.com.google.gson</shadedPattern> <shadedPattern>com.massivecraft.factions.shade.com.google.gson</shadedPattern>
</relocation> </relocation>
<relocation>
<pattern>com.darkblade12</pattern>
<shadedPattern>com.massivecraft.factions.shade.com.darkblade12</shadedPattern>
</relocation>
</relocations> </relocations>
</configuration> </configuration>
<executions> <executions>
@ -321,10 +325,6 @@
<id>vault-repo</id> <id>vault-repo</id>
<url>http://nexus.hc.to/content/repositories/pub_releases</url> <url>http://nexus.hc.to/content/repositories/pub_releases</url>
</repository> </repository>
<repository>
<id>inventive-repo</id>
<url>https://repo.inventivetalent.org/content/groups/public/</url>
</repository>
<repository> <repository>
<id>ess-repo</id> <id>ess-repo</id>
<url>http://ci.ender.zone/plugin/repository/everything/</url> <url>http://ci.ender.zone/plugin/repository/everything/</url>

@ -3,10 +3,10 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.P; import com.massivecraft.factions.P;
import com.massivecraft.factions.event.FPlayerLeaveEvent; import com.massivecraft.factions.event.FPlayerLeaveEvent;
import com.massivecraft.factions.struct.BanInfo;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.Permissable;
import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -67,6 +67,15 @@ public class CmdBan extends FCommand {
return; return;
} }
for (BanInfo banInfo : myFaction.getBannedPlayers()) {
if (banInfo.getBanned().equals(target.getId())) {
msg(TL.COMMAND_BAN_ALREADYBANNED);
return;
}
}
// Ban the user. // Ban the user.
myFaction.ban(target, fme); myFaction.ban(target, fme);
myFaction.deinvite(target); // can't hurt myFaction.deinvite(target); // can't hurt

@ -5,15 +5,14 @@ import com.massivecraft.factions.*;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.util.WarmUpUtil; import com.massivecraft.factions.util.WarmUpUtil;
import com.massivecraft.factions.util.Particles.ParticleEffect;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
import com.massivecraft.factions.zcore.util.particles.ParticleEffect;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
public class CmdFly extends FCommand { public class CmdFly extends FCommand {
@ -33,6 +32,81 @@ public class CmdFly extends FCommand {
this.senderMustBeModerator = false; this.senderMustBeModerator = false;
} }
public static 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;
}
ParticleEffect.CLOUD.display(0, 0, 0, 0, 1, player.getLocation().add(0, -0.35, 0), 16);
}
if (flyMap.keySet().size() == 0) {
Bukkit.getScheduler().cancelTask(id);
id = -1;
}
}
}, 10L, 10L);
}
public static void startFlyCheck() {
flyid = 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;
}
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;
}
}
checkTaskState();
}
}
}, 20L, 20L);
}
public boolean isInFlightChecker(Player player) {
if (flyMap.containsKey(player.getName())) {
return true;
} else {
return false;
}
}
@Override @Override
public void perform() { public void perform() {
// Disabled by default. // Disabled by default.
@ -148,82 +222,6 @@ public class CmdFly extends FCommand {
} }
} }
public boolean isInFlightChecker(Player player){
if (flyMap.containsKey(player.getName())){
return true;
} else {
return false;
}
}
public static void startParticles() {
id = Bukkit.getScheduler().scheduleSyncRepeatingTask(P.p, new Runnable() {
@Override
public void run() {
Iterator<String> itr = flyMap.keySet().iterator();
while (itr.hasNext()) {
Player player = Bukkit.getPlayer(itr.next());
if (player == null){
continue;
}
if (!player.isFlying()){
continue;
}
ParticleEffect.CLOUD.display(0, 0, 0, 0, 1, player.getLocation().add(0, -0.35, 0), 16);
}
if (flyMap.keySet().size() == 0){
Bukkit.getScheduler().cancelTask(id);
id = -1;
}
}
}, 10L, 10L);
}
public static void startFlyCheck() {
flyid = Bukkit.getScheduler().scheduleSyncRepeatingTask(P.p, new Runnable() {
@Override
public void run() {
Iterator itr = flyMap.keySet().iterator();
while (itr.hasNext()) {
Object nameObj = itr.next();
String name = nameObj + "";
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);
itr.remove();
continue;
}
}
checkTaskState();
}
}
},20L,20L);
}
private static boolean checkBypassPerms(FPlayer fplayer, Player player, Faction toFac) { private static boolean checkBypassPerms(FPlayer fplayer, Player player, Faction toFac) {
if (player.hasPermission("factions.fly.wilderness") && toFac.isWilderness()){ if (player.hasPermission("factions.fly.wilderness") && toFac.isWilderness()){
@ -257,10 +255,10 @@ public class CmdFly extends FCommand {
} }
} }
private void toggleFlight(final boolean toggle, final Player player) { private void toggleFlight(final boolean toggle, final Player player) {
if (!toggle) { if (!toggle) {
fme.setFlying(false); fme.setFlying(false);
flyMap.remove(player.getName()); flyMap.remove(player.getName());
return; return;
} }

@ -1,13 +1,12 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FLocation; import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.P; import com.massivecraft.factions.P;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.VisualizeUtil; import com.massivecraft.factions.util.VisualizeUtil;
import com.massivecraft.factions.util.Particles.ParticleEffect;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
import com.massivecraft.factions.zcore.util.particles.ParticleEffect;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -23,6 +22,7 @@ public class CmdSeeChunk extends FCommand {
private boolean useParticles; private boolean useParticles;
private int length; private int length;
private ParticleEffect effect; private ParticleEffect effect;
//Used a hashmap cuz imma make a particle selection gui later, will store it where the boolean is rn. //Used a hashmap cuz imma make a particle selection gui later, will store it where the boolean is rn.
public static HashMap<String, Boolean> seeChunkMap = new HashMap<>(); public static HashMap<String, Boolean> seeChunkMap = new HashMap<>();
@ -125,12 +125,8 @@ public class CmdSeeChunk extends FCommand {
if (loc.getBlock().getType() != Material.AIR) { if (loc.getBlock().getType() != Material.AIR) {
continue; continue;
} }
if (useParticles) { if (useParticles) {
this.effect.display(0, 0, 0, 0, 1, loc, player);
this.effect.display(0, 0, 0, 0, 3, loc, player);
} else { } else {
int typeId = blockY % 5 == 0 ? Material.REDSTONE_LAMP_ON.getId() : Material.STAINED_GLASS.getId(); int typeId = blockY % 5 == 0 ? Material.REDSTONE_LAMP_ON.getId() : Material.STAINED_GLASS.getId();
VisualizeUtil.addLocation(player, loc, typeId); VisualizeUtil.addLocation(player, loc, typeId);

@ -30,6 +30,7 @@ public class CmdTitle extends FCommand {
return; return;
} }
args.remove(0); args.remove(0);
String title = TextUtil.implode(args, " "); String title = TextUtil.implode(args, " ");

@ -18,9 +18,9 @@ import com.massivecraft.factions.util.VisualizeUtil;
import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.persist.MemoryFPlayer; import com.massivecraft.factions.zcore.persist.MemoryFPlayer;
import com.massivecraft.factions.util.Particles.ParticleEffect;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
import com.massivecraft.factions.zcore.util.TextUtil; import com.massivecraft.factions.zcore.util.TextUtil;
import com.massivecraft.factions.zcore.util.particles.ParticleEffect;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -311,13 +311,14 @@ public class FactionsPlayerListener implements Listener {
enableFly(me); enableFly(me);
} }
// bypass checks // bypass checks
Relation relationTo = factionTo.getRelationTo(me);
if ((factionTo.isWilderness() && me.canflyinWilderness()) || if ((factionTo.isWilderness() && me.canflyinWilderness()) ||
(factionTo.isWarZone() && me.canflyinWarzone()) || (factionTo.isWarZone() && me.canflyinWarzone()) ||
(factionTo.isSafeZone() && me.canflyinSafezone()) || (factionTo.isSafeZone() && me.canflyinSafezone()) ||
(factionTo.getRelationTo(me) == Relation.ENEMY && me.canflyinEnemy()) || (relationTo == Relation.ENEMY && me.canflyinEnemy()) ||
(factionTo.getRelationTo(me) == Relation.ALLY && me.canflyinAlly()) || (relationTo == Relation.ALLY && me.canflyinAlly()) ||
(factionTo.getRelationTo(me) == Relation.TRUCE && me.canflyinTruce()) || (relationTo == Relation.TRUCE && me.canflyinTruce()) ||
(factionTo.getRelationTo(me) == Relation.NEUTRAL && me.canflyinNeutral())) { (relationTo == Relation.NEUTRAL && me.canflyinNeutral())) {
enableFly(me); enableFly(me);
} }

File diff suppressed because it is too large Load Diff

@ -1,5 +1,4 @@
package com.massivecraft.factions.zcore.util.particles; package com.massivecraft.factions.util.Particles;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -11,7 +10,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
* <b>com.prosavage.savagecore.particle.ReflectionUtils</b> * <b>ReflectionUtils</b>
* <p> * <p>
* This class provides useful methods which makes dealing with reflection much easier, especially when working with Bukkit * This class provides useful methods which makes dealing with reflection much easier, especially when working with Bukkit
* <p> * <p>
@ -23,7 +22,7 @@ import java.util.Map;
* <p> * <p>
* <i>It would be nice if you provide credit to me if you use this class in a published project</i> * <i>It would be nice if you provide credit to me if you use this class in a published project</i>
* *
* @author Araos * @author DarkBlade12
* @version 1.1 * @version 1.1
*/ */
public final class ReflectionUtils { public final class ReflectionUtils {
@ -62,6 +61,7 @@ public final class ReflectionUtils {
* @return The constructor of the desired target class with the specified parameter types * @return The constructor of the desired target class with the specified parameter types
* @throws NoSuchMethodException If the desired constructor with the specified parameter types cannot be found * @throws NoSuchMethodException If the desired constructor with the specified parameter types cannot be found
* @throws ClassNotFoundException ClassNotFoundException If the desired target class with the specified name and package cannot be found * @throws ClassNotFoundException ClassNotFoundException If the desired target class with the specified name and package cannot be found
* @see #getClass(String, PackageType)
* @see #getConstructor(Class, Class...) * @see #getConstructor(Class, Class...)
*/ */
public static Constructor<?> getConstructor(String className, PackageType packageType, Class<?>... parameterTypes) throws NoSuchMethodException, ClassNotFoundException { public static Constructor<?> getConstructor(String className, PackageType packageType, Class<?>... parameterTypes) throws NoSuchMethodException, ClassNotFoundException {
@ -97,6 +97,7 @@ public final class ReflectionUtils {
* @throws InvocationTargetException If the desired constructor cannot be invoked * @throws InvocationTargetException If the desired constructor cannot be invoked
* @throws NoSuchMethodException If the desired constructor with the specified arguments cannot be found * @throws NoSuchMethodException If the desired constructor with the specified arguments cannot be found
* @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found * @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found
* @see #getClass(String, PackageType)
* @see #instantiateObject(Class, Object...) * @see #instantiateObject(Class, Object...)
*/ */
public static Object instantiateObject(String className, PackageType packageType, Object... arguments) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException { public static Object instantiateObject(String className, PackageType packageType, Object... arguments) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException {
@ -135,6 +136,7 @@ public final class ReflectionUtils {
* @return The method of the desired target class with the specified name and parameter types * @return The method of the desired target class with the specified name and parameter types
* @throws NoSuchMethodException If the desired method of the desired target class with the specified name and parameter types cannot be found * @throws NoSuchMethodException If the desired method of the desired target class with the specified name and parameter types cannot be found
* @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found * @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found
* @see #getClass(String, PackageType)
* @see #getMethod(Class, String, Class...) * @see #getMethod(Class, String, Class...)
*/ */
public static Method getMethod(String className, PackageType packageType, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException, ClassNotFoundException { public static Method getMethod(String className, PackageType packageType, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException, ClassNotFoundException {
@ -192,6 +194,7 @@ public final class ReflectionUtils {
* @throws InvocationTargetException If the desired method cannot be invoked on the target object * @throws InvocationTargetException If the desired method cannot be invoked on the target object
* @throws NoSuchMethodException If the desired method of the desired target class with the specified name and arguments cannot be found * @throws NoSuchMethodException If the desired method of the desired target class with the specified name and arguments cannot be found
* @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found * @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found
* @see #getClass(String, PackageType)
* @see #invokeMethod(Object, Class, String, Object...) * @see #invokeMethod(Object, Class, String, Object...)
*/ */
public static Object invokeMethod(Object instance, String className, PackageType packageType, String methodName, Object... arguments) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException { public static Object invokeMethod(Object instance, String className, PackageType packageType, String methodName, Object... arguments) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException {
@ -344,7 +347,7 @@ public final class ReflectionUtils {
/** /**
* Represents an enumeration of dynamic packages of NMS and CraftBukkit * Represents an enumeration of dynamic packages of NMS and CraftBukkit
* <p> * <p>
* This class is part of the <b>com.prosavage.savagecore.particle.ReflectionUtils</b> and follows the same usage conditions * This class is part of the <b>ReflectionUtils</b> and follows the same usage conditions
* *
* @author DarkBlade12 * @author DarkBlade12
* @since 1.0 * @since 1.0
@ -398,7 +401,7 @@ public final class ReflectionUtils {
* @return The server version * @return The server version
*/ */
public static String getServerVersion() { public static String getServerVersion() {
return Bukkit.getServer().getClass().getPackage().getName().substring(23); return Bukkit.getServer().getClass().getName().split("\\.")[3];
} }
/** /**
@ -431,7 +434,7 @@ public final class ReflectionUtils {
/** /**
* Represents an enumeration of Java data types with corresponding classes * Represents an enumeration of Java data types with corresponding classes
* <p> * <p>
* This class is part of the <b>com.prosavage.savagecore.particle.ReflectionUtils</b> and follows the same usage conditions * This class is part of the <b>ReflectionUtils</b> and follows the same usage conditions
* *
* @author DarkBlade12 * @author DarkBlade12
* @since 1.0 * @since 1.0
@ -535,7 +538,7 @@ public final class ReflectionUtils {
/** /**
* Returns the primitive class array of the given object array * Returns the primitive class array of the given object array
* *
* @param objects Given object array * @param object Given object array
* @return The primitive class array * @return The primitive class array
*/ */
public static Class<?>[] getPrimitive(Object[] objects) { public static Class<?>[] getPrimitive(Object[] objects) {
@ -550,7 +553,7 @@ public final class ReflectionUtils {
/** /**
* Returns the reference class array of the given object array * Returns the reference class array of the given object array
* *
* @param objects Given object array * @param object Given object array
* @return The reference class array * @return The reference class array
*/ */
public static Class<?>[] getReference(Object[] objects) { public static Class<?>[] getReference(Object[] objects) {

@ -147,6 +147,7 @@ public enum TL {
COMMAND_BAN_BANNED("&e%1$s &cbanned &7%2$s"), COMMAND_BAN_BANNED("&e%1$s &cbanned &7%2$s"),
COMMAND_BAN_SELF("&cYou may not ban yourself"), COMMAND_BAN_SELF("&cYou may not ban yourself"),
COMMAND_BAN_INSUFFICIENTRANK("&cYour rank is too low to ban &7%1$s"), COMMAND_BAN_INSUFFICIENTRANK("&cYour rank is too low to ban &7%1$s"),
COMMAND_BAN_ALREADYBANNED("&cThis player is already banned!"),
COMMAND_BANLIST_DESCRIPTION("View a Faction's ban list"), COMMAND_BANLIST_DESCRIPTION("View a Faction's ban list"),
COMMAND_BANLIST_HEADER("&6There are &c%d&6 bans for %s"), COMMAND_BANLIST_HEADER("&6There are &c%d&6 bans for %s"),

@ -61,7 +61,6 @@ warp-cost:
# Faction Fly # Faction Fly
# Enable Faction Fly: # Enable Faction Fly:
enable-faction-flight: true enable-faction-flight: true
fly-falldamage-cooldown: 10
ffly: ffly:
Particles: Particles:
Enabled: true Enabled: true
@ -72,7 +71,7 @@ ffly:
# If a player leaves fly (out of territory or took damage) # If a player leaves fly (out of territory or took damage)
# how long should they not take fall damage for? # how long should they not take fall damage for?
# Set to 0 to have them always take fall damage. # Set to 0 to have them always take fall damage.
fly-falldamage-cooldown: 3 fly-falldamage-cooldown: 10
# Pistons # Pistons
# Should we disable pistons in Faction territory? This will prevent people from doing something like: # Should we disable pistons in Faction territory? This will prevent people from doing something like: