mirror of
https://github.com/essentials/Essentials.git
synced 2025-08-13 18:14:38 +02:00
Port spawnmob changes to 3.x
This commit is contained in:
@@ -48,74 +48,75 @@ public class SpawnMob
|
||||
return Util.joinList(availableList);
|
||||
}
|
||||
|
||||
public static String[] mobData(final String mobString)
|
||||
{
|
||||
String[] returnString = new String[4];
|
||||
public static List<String> mobParts(final String mobString)
|
||||
{
|
||||
String[] mobParts = comma.split(mobString);
|
||||
|
||||
final String[] parts = comma.split(mobString);
|
||||
String[] mobParts = colon.split(parts[0]);
|
||||
List<String> mobs = new ArrayList<String>();
|
||||
|
||||
returnString[0] = mobParts[0];
|
||||
if (mobParts.length == 2)
|
||||
{
|
||||
returnString[1] = mobParts[1];
|
||||
}
|
||||
for (String mobPart : mobParts)
|
||||
{
|
||||
String[] mobDatas = colon.split(mobPart);
|
||||
mobs.add(mobDatas[0]);
|
||||
}
|
||||
|
||||
if (parts.length > 1)
|
||||
{
|
||||
String[] mountParts = colon.split(parts[1]);
|
||||
returnString[2] = mountParts[0];
|
||||
if (mountParts.length == 2)
|
||||
{
|
||||
returnString[3] = mountParts[1];
|
||||
}
|
||||
}
|
||||
return mobs;
|
||||
}
|
||||
|
||||
return returnString;
|
||||
}
|
||||
public static List<String> mobData(final String mobString)
|
||||
{
|
||||
String[] mobParts = comma.split(mobString);
|
||||
|
||||
List<String> mobData = new ArrayList<String>();
|
||||
|
||||
for (String mobPart : mobParts)
|
||||
{
|
||||
String[] mobDatas = colon.split(mobPart);
|
||||
if(mobDatas.length == 1)
|
||||
{
|
||||
mobData.add(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
mobData.add(mobDatas[1]);
|
||||
}
|
||||
}
|
||||
return mobData;
|
||||
}
|
||||
|
||||
// This method spawns a mob where the user is looking, owned by user
|
||||
public static void spawnmob(final IEssentials ess, final Server server, final IUser user, final String[] Data, int mobCount) throws Exception
|
||||
public static void spawnmob(final IEssentials ess, final Server server, final IUser user, final List<String> parts, final List<String> data, int mobCount) throws Exception
|
||||
{
|
||||
final Block block = LocationUtil.getTarget(user.getPlayer()).getBlock();
|
||||
if (block == null)
|
||||
{
|
||||
throw new Exception(_("unableToSpawnMob"));
|
||||
}
|
||||
spawnmob(ess, server, user, user, block.getLocation(), Data, mobCount);
|
||||
spawnmob(ess, server, user, user, block.getLocation(), parts, data, mobCount);
|
||||
}
|
||||
|
||||
// This method spawns a mob at loc, owned by noone
|
||||
public static void spawnmob(final IEssentials ess, final Server server, final CommandSender sender, final Location loc, final String[] Data, int mobCount) throws Exception
|
||||
public static void spawnmob(final IEssentials ess, final Server server, final CommandSender sender, final Location loc, final List<String> parts, final List<String> data, int mobCount) throws Exception
|
||||
{
|
||||
spawnmob(ess, server, sender, null, loc, Data, mobCount);
|
||||
spawnmob(ess, server, sender, null, loc, parts, data, mobCount);
|
||||
}
|
||||
|
||||
// This method spawns a mob at target, owned by target
|
||||
public static void spawnmob(final IEssentials ess, final Server server, final CommandSender sender, final IUser target, final String[] Data, int mobCount) throws Exception
|
||||
public static void spawnmob(final IEssentials ess, final Server server, final CommandSender sender, final IUser target, final List<String> parts, final List<String> data, int mobCount) throws Exception
|
||||
{
|
||||
spawnmob(ess, server, sender, target, target.getPlayer().getLocation(), Data, mobCount);
|
||||
spawnmob(ess, server, sender, target, target.getPlayer().getLocation(), parts, data, mobCount);
|
||||
}
|
||||
|
||||
// This method spawns a mob at loc, owned by target
|
||||
public static void spawnmob(final IEssentials ess, final Server server, final CommandSender sender, final IUser target, final Location loc, final String[] Data, int mobCount) throws Exception
|
||||
public static void spawnmob(final IEssentials ess, final Server server, final CommandSender sender, final IUser target, final Location loc, final List<String> parts, final List<String> data, int mobCount) throws Exception
|
||||
{
|
||||
final Location sloc = LocationUtil.getSafeDestination(loc);
|
||||
final String mobType = Data[0];
|
||||
final String mobData = Data[1];
|
||||
final String mountType = Data[2];
|
||||
final String mountData = Data[3];
|
||||
|
||||
EntityType mob = LivingEntities.fromName(mobType);
|
||||
EntityType mobMount = null;
|
||||
|
||||
checkSpawnable(ess, sender, mob);
|
||||
|
||||
if (mountType != null)
|
||||
{
|
||||
mobMount = LivingEntities.fromName(mountType);
|
||||
checkSpawnable(ess, sender, mobMount);
|
||||
}
|
||||
for (int i = 0; i < parts.size(); i++)
|
||||
{
|
||||
EntityType mob = LivingEntities.fromName(parts.get(i));
|
||||
checkSpawnable(ess, sender, mob);
|
||||
}
|
||||
|
||||
ISettings settings = ess.getSettings();
|
||||
int serverLimit = settings.getData().getCommands().getSpawnmob().getLimit();
|
||||
@@ -126,11 +127,12 @@ public class SpawnMob
|
||||
sender.sendMessage(_("mobSpawnLimit"));
|
||||
}
|
||||
|
||||
EntityType mob = LivingEntities.fromName(parts.get(0));
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < mobCount; i++)
|
||||
{
|
||||
spawnMob(ess, server, sender, target, sloc, mob, mobData, mobMount, mountData);
|
||||
spawnMob(ess, server, sender, target, sloc, parts, data);
|
||||
}
|
||||
sender.sendMessage(mobCount + " " + mob.getName().toLowerCase(Locale.ENGLISH) + " " + _("spawned"));
|
||||
}
|
||||
@@ -148,26 +150,42 @@ public class SpawnMob
|
||||
}
|
||||
}
|
||||
|
||||
private static void spawnMob(final IEssentials ess, final Server server, final CommandSender sender, final IUser target, final Location sloc, EntityType mob, String mobData, EntityType mobMount, String mountData) throws Exception
|
||||
private static void spawnMob(final IEssentials ess, final Server server, final CommandSender sender, final IUser target, final Location sloc, final List<String> parts, final List<String> data) throws Exception
|
||||
{
|
||||
EntityType mob;
|
||||
Entity spawnedMob = null;
|
||||
Entity spawnedMount;
|
||||
final World spawningWorld = sloc.getWorld();
|
||||
|
||||
final World spawningWorld = sloc.getWorld();
|
||||
final Entity spawnedMob = spawningWorld.spawn(sloc, (Class<? extends LivingEntity>)mob.getEntityClass());
|
||||
Entity spawnedMount = null;
|
||||
for (int i = 0; i < parts.size(); i++)
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
mob = EntityType.fromName(parts.get(i));
|
||||
spawnedMob = spawningWorld.spawn(sloc, (Class<? extends LivingEntity>)mob.getEntityClass());
|
||||
|
||||
if (mobMount != null)
|
||||
{
|
||||
spawnedMount = spawningWorld.spawn(sloc, (Class<? extends LivingEntity>)mobMount.getEntityClass());
|
||||
spawnedMob.setPassenger(spawnedMount);
|
||||
}
|
||||
if (mobData != null)
|
||||
{
|
||||
changeMobData(mob, spawnedMob, mobData, target);
|
||||
}
|
||||
if (spawnedMount != null && mountData != null)
|
||||
{
|
||||
changeMobData(mobMount, spawnedMount, mountData, target);
|
||||
}
|
||||
if (data.get(i) != null)
|
||||
{
|
||||
changeMobData(mob, spawnedMob, data.get(i), target);
|
||||
}
|
||||
}
|
||||
|
||||
int next = (i + 1);
|
||||
if (next < parts.size())
|
||||
{
|
||||
EntityType mMob = EntityType.fromName(parts.get(next));
|
||||
spawnedMount = spawningWorld.spawn(sloc, (Class<? extends LivingEntity>)mMob.getEntityClass());
|
||||
|
||||
if(data.get(next) != null)
|
||||
{
|
||||
changeMobData(mMob, spawnedMount, data.get(next), target);
|
||||
}
|
||||
|
||||
spawnedMob.setPassenger(spawnedMount);
|
||||
|
||||
spawnedMob = spawnedMount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkSpawnable(IEssentials ess, CommandSender sender, EntityType mob) throws Exception
|
||||
@@ -201,7 +219,7 @@ public class SpawnMob
|
||||
if (spawned instanceof Ageable && data.contains("baby"))
|
||||
{
|
||||
((Ageable)spawned).setBaby();
|
||||
return;
|
||||
data = data.replace("baby", "");
|
||||
}
|
||||
if (spawned instanceof Colorable)
|
||||
{
|
||||
@@ -228,6 +246,7 @@ public class SpawnMob
|
||||
final Tameable tameable = ((Tameable)spawned);
|
||||
tameable.setTamed(true);
|
||||
tameable.setOwner(target.getPlayer());
|
||||
data = data.replace("tamed", "");
|
||||
}
|
||||
if (type == EntityType.WOLF && data.contains("angry"))
|
||||
{
|
||||
@@ -239,15 +258,15 @@ public class SpawnMob
|
||||
}
|
||||
if (type == EntityType.OCELOT)
|
||||
{
|
||||
if (data.contains("siamese"))
|
||||
if (data.contains("siamese") || data.contains("white"))
|
||||
{
|
||||
((Ocelot)spawned).setCatType(Ocelot.Type.SIAMESE_CAT);
|
||||
}
|
||||
else if (data.contains("red"))
|
||||
else if (data.contains("red") || data.contains("orange") || data.contains("tabby"))
|
||||
{
|
||||
((Ocelot)spawned).setCatType(Ocelot.Type.RED_CAT);
|
||||
}
|
||||
else if (data.contains("black"))
|
||||
else if (data.contains("black") || data.contains("tuxedo"))
|
||||
{
|
||||
((Ocelot)spawned).setCatType(Ocelot.Type.BLACK_CAT);
|
||||
}
|
||||
@@ -262,5 +281,27 @@ public class SpawnMob
|
||||
}
|
||||
}
|
||||
}
|
||||
if (spawned instanceof Zombie)
|
||||
{
|
||||
if (data.contains("villager"))
|
||||
{
|
||||
((Zombie)spawned).setVillager(true);
|
||||
}
|
||||
if (data.contains("baby"))
|
||||
{
|
||||
((Zombie)spawned).setBaby(true);
|
||||
}
|
||||
}
|
||||
if (type == EntityType.SKELETON)
|
||||
{
|
||||
if (data.contains("wither"))
|
||||
{
|
||||
((Skeleton)spawned).setSkeletonType(Skeleton.SkeletonType.WITHER);
|
||||
}
|
||||
}
|
||||
if (type == EntityType.EXPERIENCE_ORB)
|
||||
{
|
||||
((ExperienceOrb)spawned).setExperience(Integer.parseInt(data));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -4,6 +4,8 @@ import static net.ess3.I18n._;
|
||||
import net.ess3.SpawnMob;
|
||||
import net.ess3.api.IUser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class Commandspawnmob extends EssentialsCommand
|
||||
{
|
||||
@@ -17,7 +19,8 @@ public class Commandspawnmob extends EssentialsCommand
|
||||
throw new NotEnoughArgumentsException(_("mobsAvailable", mobList));
|
||||
}
|
||||
|
||||
String[] mobData = SpawnMob.mobData(args[0]);
|
||||
List<String> mobParts = SpawnMob.mobParts(args[0]);
|
||||
List<String> mobData = SpawnMob.mobData(args[0]);
|
||||
|
||||
int mobCount = 1;
|
||||
if (args.length >= 2)
|
||||
@@ -28,9 +31,9 @@ public class Commandspawnmob extends EssentialsCommand
|
||||
if (args.length >= 3)
|
||||
{
|
||||
IUser target = ess.getUserMap().getUser(args[2]);
|
||||
SpawnMob.spawnmob(ess, server, user, target, mobData, mobCount);
|
||||
SpawnMob.spawnmob(ess, server, user, target, mobParts, mobData, mobCount);
|
||||
}
|
||||
|
||||
SpawnMob.spawnmob(ess, server, user, mobData, mobCount);
|
||||
SpawnMob.spawnmob(ess, server, user, mobParts, mobData, mobCount);
|
||||
}
|
||||
}
|
||||
|
@@ -7,6 +7,8 @@ import net.ess3.api.IUser;
|
||||
import net.ess3.economy.Trade;
|
||||
import net.ess3.signs.EssentialsSign;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class SignSpawnmob extends EssentialsSign
|
||||
{
|
||||
@@ -30,8 +32,9 @@ public class SignSpawnmob extends EssentialsSign
|
||||
charge.isAffordableFor(player);
|
||||
try
|
||||
{
|
||||
String[] mobData = SpawnMob.mobData(sign.getLine(2));
|
||||
SpawnMob.spawnmob(ess, ess.getServer(), player, player, mobData, Integer.parseInt(sign.getLine(1)));
|
||||
List<String> mobParts = SpawnMob.mobParts(sign.getLine(2));
|
||||
List<String> mobData = SpawnMob.mobData(sign.getLine(2));
|
||||
SpawnMob.spawnmob(ess, ess.getServer(), player, player, mobParts, mobData, Integer.parseInt(sign.getLine(1)));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
Reference in New Issue
Block a user