Teleport players back to center of arcade lobby

This commit is contained in:
samczsun 2016-09-16 23:25:04 -04:00 committed by Shaun Bennett
parent bf61296948
commit ec4add259d
6 changed files with 104 additions and 59 deletions

View File

@ -0,0 +1,55 @@
package mineplex.core.common.util;
import java.util.function.Predicate;
public class UtilLambda
{
/**
* This will return a {@link Predicate} which will return true <b>if and only if</b> all of the supplied Predicates
* return true
* @param predicates The Predicates to test against
* @return The resulting criterion
*/
@SafeVarargs
public static <T> Predicate<T> and(Predicate<T>... predicates)
{
return t ->
{
for (Predicate<T> predicate : predicates)
{
if (!predicate.test(t))
{
return false;
}
}
return true;
};
}
/**
* This will return a {@link Predicate} which will return true <b>if and only if</b> one of the the supplied Predicates
* return true
* @param predicates The Predicates to test against
* @return The resulting criterion
*/
@SafeVarargs
public static <T> Predicate<T> or(Predicate<T>... predicates)
{
return t ->
{
for (Predicate<T> predicate : predicates)
{
if (predicate.test(t))
{
return true;
}
}
return false;
};
}
public static <T> Predicate<T> not(Predicate<T> predicate)
{
return t -> !predicate.test(t);
}
}

View File

@ -3,9 +3,11 @@ package mineplex.core;
import mineplex.core.account.CoreClient;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Rank;
import mineplex.core.common.util.UtilMath;
import mineplex.core.incognito.IncognitoManager;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
@ -113,47 +115,8 @@ public class PlayerSelector
return entity -> world == null || entity.getWorld().equals(world);
}
/**
* This will return a {@link Predicate} which will return true <b>if and only if</b> all of the supplied Predicates
* return true
* @param predicates The Predicates to test against
* @return The resulting criterion
*/
@SafeVarargs
public static <T> Predicate<T> and(Predicate<T>... predicates)
public static Predicate<Player> within(Location center, double radius)
{
return t ->
{
for (Predicate<T> predicate : predicates)
{
if (!predicate.test(t))
{
return false;
}
}
return true;
};
}
/**
* This will return a {@link Predicate} which will return true <b>if and only if</b> one of the the supplied Predicates
* return true
* @param predicates The Predicates to test against
* @return The resulting criterion
*/
@SafeVarargs
public static <T> Predicate<T> or(Predicate<T>... predicates)
{
return t ->
{
for (Predicate<T> predicate : predicates)
{
if (predicate.test(t))
{
return true;
}
}
return false;
};
return player -> UtilMath.offset(player.getLocation(), center) <= radius;
}
}

View File

@ -251,22 +251,23 @@ public class AntiHack extends MiniPlugin
return;
}
List<Player> targets = PlayerSelector.selectPlayers(PlayerSelector.and(
PlayerSelector.NOT_VANISHED,
PlayerSelector.hasAnyRank(false,
Rank.ALL,
Rank.ULTRA,
Rank.HERO,
Rank.LEGEND,
Rank.TITAN,
Rank.TWITCH,
Rank.YOUTUBE_SMALL,
Rank.YOUTUBE,
Rank.MEDIA,
Rank.ADMIN,
Rank.DEVELOPER,
Rank.OWNER,
Rank.LT
List<Player> targets = PlayerSelector.selectPlayers(
UtilLambda.and(
PlayerSelector.NOT_VANISHED,
PlayerSelector.hasAnyRank(false,
Rank.ALL,
Rank.ULTRA,
Rank.HERO,
Rank.LEGEND,
Rank.TITAN,
Rank.TWITCH,
Rank.YOUTUBE_SMALL,
Rank.YOUTUBE,
Rank.MEDIA,
Rank.ADMIN,
Rank.DEVELOPER,
Rank.OWNER,
Rank.LT
),
player -> !_stalking.contains(player.getUniqueId()),
player -> _stalkingCooldown.getIfPresent(player.getUniqueId()) == null,

View File

@ -4,6 +4,7 @@ import com.mineplex.spigot.ChunkAddEntityEvent;
import mineplex.core.MiniPlugin;
import mineplex.core.PlayerSelector;
import mineplex.core.ReflectivelyCreateMiniPlugin;
import mineplex.core.common.util.UtilLambda;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTasks;
@ -665,7 +666,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
if (entity.isValid())
{
for (Player player : PlayerSelector.selectPlayers(
PlayerSelector.and(
UtilLambda.and(
PlayerSelector.inWorld(entity.getWorld()),
OfflinePlayer::isOnline,
tester

View File

@ -2,6 +2,7 @@ package nautilus.game.arcade;
import mineplex.core.Managers;
import mineplex.core.MiniPlugin;
import mineplex.core.PlayerSelector;
import mineplex.core.account.CoreClient;
import mineplex.core.account.CoreClientManager;
import mineplex.core.achievement.AchievementManager;
@ -17,6 +18,8 @@ import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilGear;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilLambda;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.cosmetic.CosmeticManager;
@ -66,6 +69,8 @@ import mineplex.core.teleport.Teleport;
import mineplex.core.thank.ThankManager;
import mineplex.core.timing.TimingManager;
import mineplex.core.titangiveaway.TitanGiveawayManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.valentines.ValentinesGiftManager;
import mineplex.core.youtube.YoutubeManager;
import mineplex.minecraft.game.classcombat.Class.ClassManager;
@ -1962,6 +1967,22 @@ public class ArcadeManager extends MiniPlugin implements IRelation
}
}
@EventHandler
public void teleportPlayersToSpawn(UpdateEvent event)
{
if (event.getType() != UpdateType.FASTEST)
return;
PlayerSelector
.selectPlayers(
UtilLambda.and(
PlayerSelector.inWorld(Bukkit.getWorld("world")),
UtilLambda.not(PlayerSelector.within(GetLobby().GetSpawn(), 70))
)
)
.forEach(player -> player.teleport(GetLobby().GetSpawn()));
}
@EventHandler
public void clearGameTeams(GameStateChangeEvent event)
{

View File

@ -5,6 +5,7 @@ import java.util.Iterator;
import java.util.List;
import mineplex.core.PlayerSelector;
import mineplex.core.common.util.UtilLambda;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.FireworkEffect.Type;
@ -415,7 +416,10 @@ public class GameManager implements Listener
public List<Player> getValidPlayersForGameStart()
{
return PlayerSelector.selectPlayers(
PlayerSelector.and(PlayerSelector.NOT_VANISHED, player -> !Manager.IsObserver(player))
UtilLambda.and(
PlayerSelector.NOT_VANISHED,
player -> !Manager.IsObserver(player)
)
);
}