Implement a Bat-Anticamping system
This commit is contained in:
parent
361b6c57ec
commit
46b859ae8f
@ -39,6 +39,7 @@ import nautilus.game.arcade.game.GameTeam;
|
||||
import nautilus.game.arcade.game.TeamGame;
|
||||
import nautilus.game.arcade.game.games.AbsorptionFix;
|
||||
import nautilus.game.arcade.game.games.cakewars.capturepoint.CakePointModule;
|
||||
import nautilus.game.arcade.game.games.cakewars.general.CakeBatModule;
|
||||
import nautilus.game.arcade.game.games.cakewars.general.CakePlayerModule;
|
||||
import nautilus.game.arcade.game.games.cakewars.general.CakeSpawnerModule;
|
||||
import nautilus.game.arcade.game.games.cakewars.island.CakeIslandModule;
|
||||
@ -202,6 +203,9 @@ public class CakeWars extends TeamGame
|
||||
_cakePointModule = new CakePointModule(this);
|
||||
_cakePointModule.register();
|
||||
|
||||
new CakeBatModule(this)
|
||||
.register();
|
||||
|
||||
_capturePointModule = new CapturePointModule();
|
||||
_capturePointModule.register(this);
|
||||
|
||||
|
@ -0,0 +1,143 @@
|
||||
package nautilus.game.arcade.game.games.cakewars.general;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Bat;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilTextBottom;
|
||||
import mineplex.core.common.util.UtilTextMiddle;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
|
||||
import nautilus.game.arcade.events.GameStateChangeEvent;
|
||||
import nautilus.game.arcade.game.Game.GameState;
|
||||
import nautilus.game.arcade.game.games.cakewars.CakeModule;
|
||||
import nautilus.game.arcade.game.games.cakewars.CakeWars;
|
||||
|
||||
public class CakeBatModule extends CakeModule
|
||||
{
|
||||
|
||||
private static final long DAMAGE_TIME = TimeUnit.SECONDS.toMillis(30);
|
||||
|
||||
private final Map<Player, Long> _lastSafe;
|
||||
private final Set<Bat> _bats;
|
||||
private int _minY;
|
||||
|
||||
public CakeBatModule(CakeWars game)
|
||||
{
|
||||
super(game);
|
||||
|
||||
_lastSafe = new HashMap<>();
|
||||
_bats = new HashSet<>();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void prepare(GameStateChangeEvent event)
|
||||
{
|
||||
if (event.GetState() != GameState.Prepare)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
List<Location> locations = _game.WorldData.GetDataLocs("BROWN");
|
||||
|
||||
if (!locations.isEmpty())
|
||||
{
|
||||
_minY = locations.get(0).getBlockY();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void updateBats(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.SEC || _minY == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_bats.removeIf(bat ->
|
||||
{
|
||||
if (bat.getTicksLived() > 50)
|
||||
{
|
||||
bat.remove();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
for (Player player : _game.GetPlayers(true))
|
||||
{
|
||||
if (UtilPlayer.isSpectator(player))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Location location = player.getLocation();
|
||||
|
||||
if (location.getY() >= _minY)
|
||||
{
|
||||
_lastSafe.put(player, System.currentTimeMillis());
|
||||
continue;
|
||||
}
|
||||
|
||||
Long last = _lastSafe.get(player);
|
||||
|
||||
if (last == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!UtilTime.elapsed(last, DAMAGE_TIME))
|
||||
{
|
||||
if (Recharge.Instance.use(player, "Bat Warn", 8000, false, false))
|
||||
{
|
||||
player.sendMessage(F.main("Game", "Return to the surface. Staying under the map for too long and bats will start attacking you."));
|
||||
UtilTextBottom.display(C.cRedB + "Return to the surface!", player);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Recharge.Instance.use(player, "Bat Inform", 8000, false, false))
|
||||
{
|
||||
UtilTextMiddle.display(C.cRedB + "STOP CAMPING", "Bats are attacking you!", 0, 20, 10, player);
|
||||
player.sendMessage(F.main("Game", "Get back to the surface, bats are attacking you!"));
|
||||
player.playSound(location, Sound.NOTE_PLING, 1, 0.5F);
|
||||
}
|
||||
|
||||
_game.CreatureAllowOverride = true;
|
||||
|
||||
Bat bat = location.getWorld().spawn(location.add(0, 1.8, 0), Bat.class);
|
||||
bat.setAwake(true);
|
||||
_bats.add(bat);
|
||||
|
||||
_game.getArcadeManager().GetDamage().NewDamageEvent(player, bat, null, DamageCause.ENTITY_ATTACK, (System.currentTimeMillis() - last - DAMAGE_TIME) / 5000D, false, true, true, bat.getName(), "Camping");
|
||||
|
||||
_game.CreatureAllowOverride = false;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerQuit(PlayerQuitEvent event)
|
||||
{
|
||||
_lastSafe.remove(event.getPlayer());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user