use of com.jacob_vejvoda.infernal_mobs.ability.EnumAbilities in project InfernalMobs by NyaaCat.
the class CommandHandler method onCommand.
@Override
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
if (!sender.hasPermission("infernal_mobs.commands")) {
sender.sendMessage("§cYou don't have permission to use this command!");
return true;
}
Arguments arg = Arguments.parse(args);
if (arg == null)
return false;
String subcommand = arg.next();
if (subcommand == null)
subcommand = "help";
try {
if ("help".equalsIgnoreCase(subcommand)) {
printHelp(sender);
} else if ("reload".equalsIgnoreCase(subcommand)) {
plugin.reloadConfig();
plugin.reloadLoot();
sender.sendMessage("§eConfig reloaded!");
} else if ("mobList".equalsIgnoreCase(subcommand)) {
sender.sendMessage("§6Mob List:");
for (EntityType t : EntityType.values()) {
sender.sendMessage("§e" + t.name());
}
} else if ("error".equalsIgnoreCase(subcommand)) {
plugin.errorList.add(asPlayer(sender));
sender.sendMessage("§eClick on a mob to send an error report about it.");
} else if ("info".equalsIgnoreCase(subcommand)) {
sender.sendMessage("§eMounts: " + plugin.mobManager.mounteeMobs.size());
sender.sendMessage("§eInfernals: " + plugin.mobManager.mobMap.size());
} else if ("worldInfo".equalsIgnoreCase(subcommand)) {
final World world = asPlayer(sender).getWorld();
String enabled = ConfigReader.isEnabledWorld(world) ? "is" : "is not";
sender.sendMessage("The world you are currently in, " + world + " " + enabled + " enabled.");
sender.sendMessage("All the world that are enabled are: ");
for (World w : Bukkit.getWorlds()) {
if (ConfigReader.isEnabledWorld(w)) {
sender.sendMessage("- " + w.getName());
}
}
} else if ("abilities".equalsIgnoreCase(subcommand)) {
printAbilities(sender);
} else if ("addloot".equalsIgnoreCase(subcommand)) {
if (arg.top() == null) {
sender.sendMessage("usage: /im addloot <name>");
return true;
}
ItemStack item = asPlayer(sender).getInventory().getItemInMainHand();
if (item == null || item.getType() == Material.AIR) {
sender.sendMessage("Add fail. Please check if you are holding the item");
return true;
}
String name = arg.nextString();
LootItem li = new LootItem();
li.item = item.clone();
if (plugin.lootManager.cfg.lootItems.containsKey(name)) {
sender.sendMessage("Fail. Duplicated name");
return true;
}
plugin.lootManager.cfg.lootItems.put(name, li);
plugin.lootManager.save();
sender.sendMessage("Item Added.");
} else if ("checkchance".equalsIgnoreCase(subcommand)) {
if ("level".equalsIgnoreCase(arg.nextString())) {
int level = arg.nextInt();
Map<String, Double> m = plugin.lootManager.cfg.dropMap.get(level);
Double sum = m.values().stream().mapToDouble(Double::doubleValue).sum();
sender.sendMessage(String.format("Listing drop chance for level %d", level));
m.entrySet().stream().sorted((a, b) -> a.getValue().compareTo(b.getValue())).forEach(e -> sender.sendMessage(String.format(" %3.03f%% %s", e.getValue() / sum * 100D, getLootDisplayName(e.getKey()))));
} else {
String itemName = arg.nextString();
Map2D<Integer, String, Double> map = new Map2D<>();
for (Map.Entry<Integer, Map<String, Double>> e : plugin.lootManager.cfg.dropMap.entrySet()) {
map.setRow(e.getKey(), normalize(e.getValue()));
}
sender.sendMessage(String.format("Listing drop chance for item \"%s\"", itemName));
Map<Integer, Double> m = map.getColumn(itemName);
if (m.size() == 0) {
sender.sendMessage("Item never dropped");
} else {
normalize(m).entrySet().stream().sorted((a, b) -> a.getKey().compareTo(b.getKey())).forEach(e -> sender.sendMessage(String.format(" Level%2d: %.03f%%", e.getKey(), e.getValue() * 100D)));
}
}
} else if ("setdrop".equalsIgnoreCase(subcommand)) {
int level = arg.nextInt();
String name = arg.nextString();
double w = arg.nextDouble();
plugin.lootManager.cfg.setDropChance(level, name, w);
plugin.lootManager.save();
sender.sendMessage("Chance set.");
} else if ("killall".equalsIgnoreCase(subcommand)) {
String worldName = arg.nextString();
World w = plugin.getServer().getWorld(worldName);
if (w == null) {
sender.sendMessage("§cWorld not found!");
return true;
}
for (Entity e : w.getEntities()) {
if (plugin.mobManager.mobMap.containsKey(e.getUniqueId())) {
plugin.mobManager.mobMap.remove(e.getUniqueId());
e.remove();
}
}
sender.sendMessage("§eKilled all loaded infernal mobs in that world!");
} else if ("kill".equalsIgnoreCase(subcommand)) {
int radius = arg.nextInt();
for (Entity e : asPlayer(sender).getNearbyEntities(radius, radius, radius)) {
if (plugin.mobManager.mobMap.containsKey(e.getUniqueId())) {
plugin.mobManager.mobMap.remove(e.getUniqueId());
e.remove();
}
}
sender.sendMessage("§eKilled all infernal mobs near you!");
} else if ("getloot".equalsIgnoreCase(subcommand)) {
if (arg.top() == null) {
Player player = asPlayer(sender);
final int powers = Helper.rand(ConfigReader.getMinimalLevel(), ConfigReader.getMaximumLevel());
final ItemStack gottenLoot = plugin.lootManager.getRandomLoot(player, powers);
if (gottenLoot != null && gottenLoot.getType() != Material.AIR) {
player.getInventory().addItem(gottenLoot);
sender.sendMessage("§eGave you some random loot!");
}
} else {
String name = arg.nextString();
ItemStack i = plugin.lootManager.getLootByName(asPlayer(sender), name);
if (i != null && i.getType() != Material.AIR) {
asPlayer(sender).getInventory().addItem(i);
sender.sendMessage("§eGave you the loot: " + name);
}
}
} else if ("spawn".equalsIgnoreCase(subcommand)) {
EntityType type = arg.nextEnum(EntityType.class);
Location farSpawnLoc = asPlayer(sender).getTargetBlock((Set<Material>) null, 200).getLocation();
farSpawnLoc.setY(farSpawnLoc.getY() + 1.0);
List<EnumAbilities> abilities = new ArrayList<>();
if (arg.top() == null) {
// random ability
abilities = Helper.randomNItems(ConfigReader.getEnabledAbilities(), MobManager.getInfernalLevelForLocation(farSpawnLoc));
} else {
// ability list
while (arg.top() != null) abilities.add(arg.nextEnum(EnumAbilities.class));
}
if (abilities.size() <= 0) {
sender.sendMessage("No ability selected");
} else {
if (plugin.mobManager.spawnMob(type, farSpawnLoc, abilities, InfernalSpawnReason.COMMAND) != null) {
sender.sendMessage("Mob spawned");
} else {
sender.sendMessage("Cannot spawn mob");
}
}
} else if ("cspawn".equalsIgnoreCase(subcommand)) {
EntityType type = arg.nextEnum(EntityType.class);
String worldName = arg.nextString();
World w = plugin.getServer().getWorld(worldName);
if (w == null) {
sender.sendMessage("§cWorld not found!");
return true;
}
double x = arg.nextDouble();
double y = arg.nextDouble();
double z = arg.nextDouble();
Location loc = new Location(w, x, y, z);
List<EnumAbilities> abilities = new ArrayList<>();
if (arg.top() == null) {
// random ability
abilities = Helper.randomNItems(ConfigReader.getEnabledAbilities(), MobManager.getInfernalLevelForLocation(loc));
} else {
// ability list
while (arg.top() != null) abilities.add(arg.nextEnum(EnumAbilities.class));
}
if (abilities.size() <= 0) {
sender.sendMessage("No ability selected");
} else {
if (plugin.mobManager.spawnMob(type, loc, abilities, InfernalSpawnReason.COMMAND) != null) {
sender.sendMessage("Mob spawned");
} else {
sender.sendMessage("Cannot spawn mob");
}
}
} else if ("pspawn".equalsIgnoreCase(subcommand)) {
EntityType type = arg.nextEnum(EntityType.class);
String playerName = arg.nextString();
Player p = Bukkit.getPlayer(playerName);
if (p == null) {
sender.sendMessage("§cPlayer not found: " + playerName);
return true;
}
Location loc = p.getLocation();
List<EnumAbilities> abilities = new ArrayList<>();
if (arg.top() == null) {
// random ability
abilities = Helper.randomNItems(ConfigReader.getEnabledAbilities(), MobManager.getInfernalLevelForLocation(loc));
} else {
// ability list
while (arg.top() != null) abilities.add(arg.nextEnum(EnumAbilities.class));
}
if (abilities.size() <= 0) {
sender.sendMessage("No ability selected");
} else {
if (plugin.mobManager.spawnMob(type, loc, abilities, InfernalSpawnReason.COMMAND) != null) {
sender.sendMessage("Mob spawned");
} else {
sender.sendMessage("Cannot spawn mob");
}
}
}
} catch (NotPlayerException ex) {
sender.sendMessage("This command can only be run by a player!");
return true;
} catch (RuntimeException ex) {
sender.sendMessage("Command fail: " + ex.getMessage());
ex.printStackTrace();
return true;
}
return true;
// TODO set infernal spawner
// if (args[0].equals("setInfernal") && args.length == 2) {
// if (player.getTargetBlock((Set<Material>) null, 25).getType().equals((Object) Material.MOB_SPAWNER)) {
// final int delay = Integer.parseInt(args[1]);
// Location loc = player.getTargetBlock((Set<Material>) null, 25).getLocation();
// plugin.persist.validInfernalSpawners.put(loc, delay);
// sender.sendMessage("§cSpawner set to infernal with a " + delay + " second delay!");
// } else {
// sender.sendMessage("§cYou must be looking a spawner to make it infernal!");
// }
// }
}
use of com.jacob_vejvoda.infernal_mobs.ability.EnumAbilities in project InfernalMobs by NyaaCat.
the class EventListener method onEntityDeath.
@EventHandler(priority = EventPriority.HIGH)
public void onEntityDeath(final EntityDeathEvent event) {
UUID id = event.getEntity().getUniqueId();
Mob mob = plugin.mobManager.mobMap.get(id);
if (mob == null)
return;
LivingEntity mobEntity = event.getEntity();
for (EnumAbilities ab : mob.abilityList) {
ab.onDeath(mobEntity, mob, mobEntity.getKiller(), event);
}
// item drop decision
ItemStack selectedDropItem = null;
Player killer = mobEntity.getKiller();
if (determineShouldDrop(killer != null, (killer != null) && (killer.getGameMode() == GameMode.CREATIVE))) {
ItemStack drop = this.plugin.lootManager.getRandomLoot(killer, mob.getMobLevel());
if (drop != null && drop.getType() != Material.AIR) {
final int min = 1;
final int max = ConfigReader.getDropChance();
final int randomNum = new Random().nextInt(max - min + 1) + min;
if (randomNum == 1) {
event.getDrops().add(drop);
selectedDropItem = drop;
}
}
}
// set xp drop
final int xpm = ConfigReader.getXpMultiplier();
final int xp = event.getDroppedExp() * xpm;
event.setDroppedExp(xp);
// broadcast death message TODO use ConfigReader
if (ConfigReader.isMobDeathMessageEnabled() && event.getEntity().getKiller() != null) {
Player player = event.getEntity().getKiller();
String playerName = player.getName();
String mobName;
if (event.getEntity().getCustomName() != null) {
mobName = event.getEntity().getCustomName();
} else {
mobName = event.getEntity().getType().name();
}
boolean broadcastToAllWorld = ConfigReader.isDeathMessageBroadcastAllWorld();
if (this.plugin.getConfig().getList("deathMessages") != null) {
String deathMessage = Helper.randomItem(plugin.getConfig().getStringList("deathMessages"));
deathMessage = ChatColor.translateAlternateColorCodes('&', deathMessage);
deathMessage = deathMessage.replace("{player}", playerName);
deathMessage = deathMessage.replace("{mob}", mobName);
ItemStack item = player.getInventory().getItemInMainHand();
if (item != null && !item.getType().equals(Material.AIR)) {
if (broadcastToAllWorld) {
new Message("").append(deathMessage, item).broadcast();
} else {
new Message("").append(deathMessage, item).broadcast(player.getLocation().getWorld());
}
} else {
if (broadcastToAllWorld) {
new Message(deathMessage.replace("{itemName}", "fist").replace("{itemName:0}", "fist")).broadcast();
} else {
new Message(deathMessage.replace("{itemName}", "fist").replace("{itemName:0}", "fist")).broadcast(player.getLocation().getWorld());
}
}
} else {
System.out.println("No valid death messages found!");
}
if (plugin.getConfig().isList("dropMessages") && selectedDropItem != null) {
String msg = Helper.randomItem(plugin.getConfig().getStringList("dropMessages"));
msg = ChatColor.translateAlternateColorCodes('&', msg);
msg = msg.replace("{player}", playerName);
msg = msg.replace("{mob}", mobName);
if (broadcastToAllWorld) {
new Message("").append(msg, selectedDropItem).broadcast();
} else {
new Message("").append(msg, selectedDropItem).broadcast(player.getLocation().getWorld());
}
}
if (plugin.getConfig().isList("nodropMessages") && selectedDropItem == null) {
String msg = Helper.randomItem(plugin.getConfig().getStringList("nodropMessages"));
msg = ChatColor.translateAlternateColorCodes('&', msg);
msg = msg.replace("{player}", playerName);
msg = msg.replace("{mob}", mobName);
if (broadcastToAllWorld) {
new Message(msg).broadcast();
} else {
new Message(msg).broadcast(player.getLocation().getWorld());
}
}
}
plugin.mobManager.mobMap.remove(id);
// TODO event
}
use of com.jacob_vejvoda.infernal_mobs.ability.EnumAbilities in project InfernalMobs by NyaaCat.
the class InfernalMobs method mainLoop.
/**
* The main loop to display all effects
* Called every second
*/
public void mainLoop() {
// update scoreboard
for (Player p : Bukkit.getOnlinePlayers()) {
GUI.refreshPlayerScoreboard(p);
}
// clear mountee mobs
for (Iterator<UUID> iter = mobManager.mounteeMobs.iterator(); iter.hasNext(); ) {
UUID entityId = iter.next();
Entity e = Bukkit.getEntity(entityId);
if (e == null) {
iter.remove();
continue;
}
if (e.getPassengers().size() <= 0) {
if (ConfigReader.isKillMountee() && e instanceof LivingEntity) {
((LivingEntity) e).damage(9.99999999E8);
iter.remove();
} else if (ConfigReader.isRemovalMountee()) {
e.remove();
iter.remove();
}
}
}
for (Mob mob : mobManager.mobMap.values()) {
Entity e = Bukkit.getEntity(mob.entityId);
if (!(e instanceof LivingEntity))
continue;
if (!e.isValid() || e.isDead() || e.getLocation() == null || !e.getLocation().getChunk().isLoaded())
continue;
LivingEntity mobEntity = (LivingEntity) e;
// send particle effects
Location feet = mobEntity.getLocation();
Location eye = mobEntity.getEyeLocation();
if (ConfigReader.particlesEnabled()) {
mob.particleEffect.spawnAt(feet);
if (feet.distanceSquared(eye) > 1)
mob.particleEffect.spawnAt(eye);
}
// Per-cycle abilities
for (EnumAbilities ab : mob.abilityList) {
ab.perCycleEffect(mobEntity, mob);
}
}
}
use of com.jacob_vejvoda.infernal_mobs.ability.EnumAbilities in project InfernalMobs by NyaaCat.
the class MobManager method morphInfernalMob.
// preserve health and lives
public LivingEntity morphInfernalMob(LivingEntity mobEntity, Mob mob) {
EntityType type = Helper.randomItem(ConfigReader.getEnabledEntityTypes());
Location loc = mobEntity.getLocation();
Entity spawnedEntity = loc.getWorld().spawnEntity(loc, type);
UUID id = spawnedEntity.getUniqueId();
mob.entityId = id;
unnaturallySpawned.put(id, true);
InfernalMobSpawnEvent spwanEvent = new InfernalMobSpawnEvent((LivingEntity) spawnedEntity, mob, mobEntity.getUniqueId(), InfernalSpawnReason.MORPH);
for (EnumAbilities ability : mob.abilityList) ability.onMobSpawn(spwanEvent);
((LivingEntity) spawnedEntity).getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(mobEntity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue());
((LivingEntity) spawnedEntity).setHealth(mobEntity.getHealth());
setInfernalMobName(spwanEvent);
mobMap.put(id, mob);
mobMap.remove(mobEntity.getUniqueId());
mobEntity.remove();
Bukkit.getPluginManager().callEvent(spwanEvent);
return (LivingEntity) spawnedEntity;
}
use of com.jacob_vejvoda.infernal_mobs.ability.EnumAbilities in project InfernalMobs by NyaaCat.
the class MobManager method getHumanReadableAbilityString.
/**
* "mama thief ..."
*/
public static String getHumanReadableAbilityString(List<EnumAbilities> abilities, int maxAbility, int maxLength) {
if (abilities.size() <= 0)
return "";
maxLength -= 3;
int count = 0;
int len = 0;
for (EnumAbilities ab : abilities) {
len += ab.name().length() + 1;
count += 1;
if (len > maxLength)
break;
}
if (len > maxLength)
count--;
String ret = abilities.get(0).name().toLowerCase();
for (int i = 1; i < count; i++) {
ret += " " + abilities.get(i).name().toLowerCase();
}
if (count < abilities.size())
ret += " ...";
return ret;
}
Aggregations