Remove entity bots
This commit is contained in:
parent
ee8f970673
commit
0f5fcc7670
@ -11,8 +11,7 @@ import nautilus.game.arcade.GameType;
|
|||||||
import nautilus.game.arcade.events.GameStateChangeEvent;
|
import nautilus.game.arcade.events.GameStateChangeEvent;
|
||||||
import nautilus.game.arcade.game.GameTeam;
|
import nautilus.game.arcade.game.GameTeam;
|
||||||
import nautilus.game.arcade.game.games.smash.events.SmashActivateEvent;
|
import nautilus.game.arcade.game.games.smash.events.SmashActivateEvent;
|
||||||
import nautilus.game.arcade.game.modules.training.TrainingBot;
|
import nautilus.game.arcade.game.modules.TrainingGameModule;
|
||||||
import nautilus.game.arcade.game.modules.training.TrainingGameModule;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -62,7 +61,6 @@ public class SuperSmashTraining extends SuperSmash
|
|||||||
new TrainingGameModule()
|
new TrainingGameModule()
|
||||||
.setSkillFunction(_safeFunction)
|
.setSkillFunction(_safeFunction)
|
||||||
.setDamageFunction(_safeFunction)
|
.setDamageFunction(_safeFunction)
|
||||||
.addBot(TrainingBot.class)
|
|
||||||
.register(this);
|
.register(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package nautilus.game.arcade.game.modules.training;
|
package nautilus.game.arcade.game.modules;
|
||||||
|
|
||||||
import mineplex.core.command.CommandCenter;
|
|
||||||
import mineplex.core.common.events.EntityVelocityChangeEvent;
|
import mineplex.core.common.events.EntityVelocityChangeEvent;
|
||||||
import mineplex.core.common.util.*;
|
import mineplex.core.common.util.*;
|
||||||
import mineplex.core.itemstack.ItemBuilder;
|
import mineplex.core.itemstack.ItemBuilder;
|
||||||
@ -11,7 +10,6 @@ import mineplex.minecraft.game.core.damage.CustomDamageEvent;
|
|||||||
import nautilus.game.arcade.events.GameStateChangeEvent;
|
import nautilus.game.arcade.events.GameStateChangeEvent;
|
||||||
import nautilus.game.arcade.game.Game;
|
import nautilus.game.arcade.game.Game;
|
||||||
import nautilus.game.arcade.game.GameTeam;
|
import nautilus.game.arcade.game.GameTeam;
|
||||||
import nautilus.game.arcade.game.modules.Module;
|
|
||||||
import nautilus.game.arcade.kit.Kit;
|
import nautilus.game.arcade.kit.Kit;
|
||||||
import nautilus.game.arcade.kit.ProgressingKit;
|
import nautilus.game.arcade.kit.ProgressingKit;
|
||||||
import nautilus.game.arcade.managers.LobbyEnt;
|
import nautilus.game.arcade.managers.LobbyEnt;
|
||||||
@ -47,14 +45,10 @@ public class TrainingGameModule extends Module
|
|||||||
private Function<Player, GameTeam> _teamFunction;
|
private Function<Player, GameTeam> _teamFunction;
|
||||||
private Function<Player, Boolean> _skillFunction;
|
private Function<Player, Boolean> _skillFunction;
|
||||||
private Function<Player, Boolean> _damageFunction;
|
private Function<Player, Boolean> _damageFunction;
|
||||||
private final Set<Class<? extends TrainingBot>> _botClasses;
|
|
||||||
private final Set<TrainingBot> _bots;
|
|
||||||
|
|
||||||
public TrainingGameModule()
|
public TrainingGameModule()
|
||||||
{
|
{
|
||||||
_kits = new HashSet<>();
|
_kits = new HashSet<>();
|
||||||
_botClasses = new HashSet<>();
|
|
||||||
_bots = new HashSet<>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -84,37 +78,6 @@ public class TrainingGameModule extends Module
|
|||||||
UtilEnt.CreatureLook(entity.GetEnt(), average);
|
UtilEnt.CreatureLook(entity.GetEnt(), average);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, ArrayList<Location>> map = getGame().WorldData.GetAllCustomLocs();
|
|
||||||
int j = 0;
|
|
||||||
|
|
||||||
for (Map.Entry<String, ArrayList<Location>> entry : map.entrySet())
|
|
||||||
{
|
|
||||||
String s = entry.getKey();
|
|
||||||
|
|
||||||
if (s.startsWith("BOT"))
|
|
||||||
{
|
|
||||||
String[] split = s.split(" ");
|
|
||||||
|
|
||||||
if (split.length < 2)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
String clazzName = split[1];
|
|
||||||
|
|
||||||
for (Class<? extends TrainingBot> clazz : _botClasses)
|
|
||||||
{
|
|
||||||
if (clazzName.equals(clazz.getSimpleName()))
|
|
||||||
{
|
|
||||||
for (Location location : entry.getValue())
|
|
||||||
{
|
|
||||||
spawnBot(clazz, location, ++j);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getGame().CreatureAllowOverride = false;
|
getGame().CreatureAllowOverride = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,11 +89,6 @@ public class TrainingGameModule extends Module
|
|||||||
lobbyEnt.GetEnt().remove();
|
lobbyEnt.GetEnt().remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (TrainingBot bot : _bots)
|
|
||||||
{
|
|
||||||
bot.cleanup();
|
|
||||||
}
|
|
||||||
|
|
||||||
_kits.clear();
|
_kits.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -367,22 +325,6 @@ public class TrainingGameModule extends Module
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T extends TrainingBot> T spawnBot(Class<T> clazz, Location location, int number)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
T bot = clazz.getConstructor(TrainingGameModule.class, Location.class, int.class).newInstance(this, location, number);
|
|
||||||
_bots.add(bot);
|
|
||||||
return bot;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TrainingGameModule setTeamFunction(Function<Player, GameTeam> function)
|
public TrainingGameModule setTeamFunction(Function<Player, GameTeam> function)
|
||||||
{
|
{
|
||||||
_teamFunction = function;
|
_teamFunction = function;
|
||||||
@ -401,12 +343,6 @@ public class TrainingGameModule extends Module
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TrainingGameModule addBot(Class<? extends TrainingBot> clazz)
|
|
||||||
{
|
|
||||||
_botClasses.add(clazz);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
private LobbyEnt getFromEntity(Entity entity)
|
private LobbyEnt getFromEntity(Entity entity)
|
||||||
{
|
{
|
||||||
for (LobbyEnt lobbyEnt : _kits)
|
for (LobbyEnt lobbyEnt : _kits)
|
@ -1,138 +0,0 @@
|
|||||||
package nautilus.game.arcade.game.modules.training;
|
|
||||||
|
|
||||||
import mineplex.core.common.skin.SkinData;
|
|
||||||
import mineplex.core.common.util.*;
|
|
||||||
import mineplex.core.disguise.disguises.DisguisePlayer;
|
|
||||||
import mineplex.core.updater.UpdateType;
|
|
||||||
import mineplex.core.updater.event.UpdateEvent;
|
|
||||||
import mineplex.minecraft.game.core.combat.DeathMessageType;
|
|
||||||
import mineplex.minecraft.game.core.combat.event.CombatDeathEvent;
|
|
||||||
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.entity.ArmorStand;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
public class TrainingBot implements Listener
|
|
||||||
{
|
|
||||||
|
|
||||||
private static final SkinData[] SKIN_DATAS =
|
|
||||||
{
|
|
||||||
SkinData.SNOWMAN,
|
|
||||||
SkinData.MOOSHROOM,
|
|
||||||
SkinData.WITCH
|
|
||||||
};
|
|
||||||
private static final int DAMAGE_HOLOGRAMS_LIFE = 40;
|
|
||||||
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("0.0");
|
|
||||||
private static final long RESPAWN_TIME = TimeUnit.SECONDS.toMillis(5);
|
|
||||||
|
|
||||||
private TrainingGameModule _module;
|
|
||||||
private Location _location;
|
|
||||||
private int _number;
|
|
||||||
|
|
||||||
protected ArmorStand _stand;
|
|
||||||
private long _lastDeath;
|
|
||||||
|
|
||||||
private final Set<ArmorStand> _damageHolograms;
|
|
||||||
|
|
||||||
public TrainingBot(TrainingGameModule module, Location location, int number)
|
|
||||||
{
|
|
||||||
_module = module;
|
|
||||||
_location = location;
|
|
||||||
_number = number;
|
|
||||||
_lastDeath = System.currentTimeMillis();
|
|
||||||
_damageHolograms = new HashSet<>();
|
|
||||||
|
|
||||||
UtilServer.RegisterEvents(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void cleanup()
|
|
||||||
{
|
|
||||||
UtilServer.Unregister(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
|
||||||
public void botDamage(CustomDamageEvent event)
|
|
||||||
{
|
|
||||||
if (_stand == null || !_stand.equals(event.GetDamageeEntity()))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
spawnDamageHologram(event.GetDamage());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void botDeath(CombatDeathEvent event)
|
|
||||||
{
|
|
||||||
if (_stand == null || !_stand.equals(event.GetEvent().getEntity()))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
event.SetBroadcastType(DeathMessageType.Detailed);
|
|
||||||
_stand.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void spawnDamageHologram(double damage)
|
|
||||||
{
|
|
||||||
String damageSting = DECIMAL_FORMAT.format(damage);
|
|
||||||
Location location = UtilAlg.getRandomLocation(_stand.getLocation().add(0, 1, 0), 1, 0, 1);
|
|
||||||
ArmorStand stand = location.getWorld().spawn(location, ArmorStand.class);
|
|
||||||
|
|
||||||
stand.setVisible(false);
|
|
||||||
stand.setGravity(false);
|
|
||||||
stand.setCustomName(C.cRedB + "-" + damageSting);
|
|
||||||
stand.setCustomNameVisible(true);
|
|
||||||
|
|
||||||
_damageHolograms.add(stand);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void cleanupDamageHolograms(UpdateEvent event)
|
|
||||||
{
|
|
||||||
if (event.getType() != UpdateType.FASTEST)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Iterator<ArmorStand> iterator = _damageHolograms.iterator();
|
|
||||||
|
|
||||||
while (iterator.hasNext())
|
|
||||||
{
|
|
||||||
ArmorStand stand = iterator.next();
|
|
||||||
|
|
||||||
if (stand.getTicksLived() > DAMAGE_HOLOGRAMS_LIFE)
|
|
||||||
{
|
|
||||||
stand.remove();
|
|
||||||
iterator.remove();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
stand.teleport(stand.getLocation().add(0, 0.25, 0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void respawn(UpdateEvent event)
|
|
||||||
{
|
|
||||||
if (event.getType() != UpdateType.SEC || !UtilTime.elapsed(_lastDeath, RESPAWN_TIME))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_lastDeath = System.currentTimeMillis();
|
|
||||||
_stand = _location.getWorld().spawn(_location, ArmorStand.class);
|
|
||||||
|
|
||||||
DisguisePlayer disguise = new DisguisePlayer(_stand, C.cYellowB + "Bot #" + _number, SKIN_DATAS[UtilMath.r(SKIN_DATAS.length)]);
|
|
||||||
disguise.setSendSkinDataToSelf(false);
|
|
||||||
_module.getGame().getArcadeManager().GetDisguise().disguise(disguise);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user