mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-12 20:29:20 +00:00
Another fix to /spawnmob
Merged for release
This commit is contained in:
parent
e652ed2981
commit
3dc0659f66
2 changed files with 56 additions and 98 deletions
|
@ -1,75 +1,55 @@
|
||||||
package com.earth2me.essentials;
|
package com.earth2me.essentials;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import net.minecraft.server.Entity;
|
import org.bukkit.Location;
|
||||||
import net.minecraft.server.WorldServer;
|
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.craftbukkit.entity.CraftEntity;
|
import org.bukkit.entity.CreatureType;
|
||||||
import org.bukkit.craftbukkit.CraftServer;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
||||||
public enum Mob
|
public enum Mob
|
||||||
{
|
{
|
||||||
CHICKEN("Chicken", Enemies.FRIENDLY),
|
CHICKEN("Chicken", Enemies.FRIENDLY, CreatureType.CHICKEN),
|
||||||
COW("Cow", Enemies.FRIENDLY),
|
COW("Cow", Enemies.FRIENDLY, CreatureType.COW),
|
||||||
CREEPER("Creeper", Enemies.ENEMY),
|
CREEPER("Creeper", Enemies.ENEMY, CreatureType.CREEPER),
|
||||||
GHAST("Ghast", Enemies.ENEMY),
|
GHAST("Ghast", Enemies.ENEMY, CreatureType.GHAST),
|
||||||
GIANT("Giant", "GiantZombie", Enemies.ENEMY),
|
GIANT("Giant", Enemies.ENEMY, CreatureType.GIANT),
|
||||||
PIG("Pig", Enemies.FRIENDLY),
|
PIG("Pig", Enemies.FRIENDLY, CreatureType.PIG),
|
||||||
PIGZOMB("PigZombie", Enemies.NEUTRAL),
|
PIGZOMB("PigZombie", Enemies.NEUTRAL, CreatureType.PIG_ZOMBIE),
|
||||||
SHEEP("Sheep", Enemies.FRIENDLY, ""),
|
SHEEP("Sheep", Enemies.FRIENDLY, "", CreatureType.SHEEP),
|
||||||
SKELETON("Skeleton", Enemies.ENEMY),
|
SKELETON("Skeleton", Enemies.ENEMY, CreatureType.SKELETON),
|
||||||
SLIME("Slime", Enemies.ENEMY),
|
SLIME("Slime", Enemies.ENEMY, CreatureType.SLIME),
|
||||||
SPIDER("Spider", Enemies.ENEMY),
|
SPIDER("Spider", Enemies.ENEMY, CreatureType.SPIDER),
|
||||||
SQUID("Squid", Enemies.FRIENDLY),
|
SQUID("Squid", Enemies.FRIENDLY, CreatureType.SQUID),
|
||||||
ZOMBIE("Zombie", Enemies.ENEMY),
|
ZOMBIE("Zombie", Enemies.ENEMY, CreatureType.ZOMBIE),
|
||||||
MONSTER("Monster", Enemies.ENEMY),
|
MONSTER("Monster", Enemies.ENEMY, CreatureType.MONSTER),
|
||||||
WOLF("Wolf", Enemies.NEUTRAL);
|
WOLF("Wolf", Enemies.NEUTRAL, CreatureType.WOLF);
|
||||||
|
|
||||||
public static final Logger logger = Logger.getLogger("Minecraft");
|
public static final Logger logger = Logger.getLogger("Minecraft");
|
||||||
|
|
||||||
private Mob(String n, Enemies en, String s)
|
private Mob(String n, Enemies en, String s, CreatureType type)
|
||||||
{
|
{
|
||||||
this.s = s;
|
this.suffix = s;
|
||||||
this.name = n;
|
this.name = n;
|
||||||
this.craftClass = n;
|
|
||||||
this.entityClass = n;
|
|
||||||
this.type = en;
|
this.type = en;
|
||||||
|
this.bukkitType = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Mob(String n, Enemies en)
|
private Mob(String n, Enemies en, CreatureType type)
|
||||||
{
|
{
|
||||||
this.name = n;
|
this.name = n;
|
||||||
this.craftClass = n;
|
|
||||||
this.entityClass = n;
|
|
||||||
this.type = en;
|
this.type = en;
|
||||||
|
this.bukkitType = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Mob(String n, String ec, Enemies en)
|
public String suffix = "s";
|
||||||
{
|
final public String name;
|
||||||
this.name = n;
|
final public Enemies type;
|
||||||
this.craftClass = n;
|
final private CreatureType bukkitType;
|
||||||
this.entityClass = ec;
|
|
||||||
this.type = en;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Mob(String n, String ec, String cc, Enemies en)
|
|
||||||
{
|
|
||||||
this.name = n;
|
|
||||||
this.entityClass = ec;
|
|
||||||
this.craftClass = cc;
|
|
||||||
this.type = en;
|
|
||||||
}
|
|
||||||
public String s = "s";
|
|
||||||
public String name;
|
|
||||||
public Enemies type;
|
|
||||||
private String entityClass;
|
|
||||||
private String craftClass;
|
|
||||||
private static final Map<String, Mob> hashMap = new HashMap<String, Mob>();
|
private static final Map<String, Mob> hashMap = new HashMap<String, Mob>();
|
||||||
|
|
||||||
static
|
static
|
||||||
|
@ -80,24 +60,16 @@ public enum Mob
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings(
|
public LivingEntity spawn(final Player player, final Server server, final Location loc) throws MobException
|
||||||
{
|
{
|
||||||
"unchecked", "CallToThreadDumpStack"
|
|
||||||
})
|
final LivingEntity entity = player.getWorld().spawnCreature(loc, this.bukkitType);
|
||||||
public CraftEntity spawn(Player player, Server server) throws MobException
|
if (entity == null)
|
||||||
{
|
{
|
||||||
try
|
logger.log(Level.WARNING, Util.i18n("unableToSpawnMob"));
|
||||||
{
|
throw new MobException();
|
||||||
WorldServer world = ((org.bukkit.craftbukkit.CraftWorld)player.getWorld()).getHandle();
|
|
||||||
Constructor<CraftEntity> craft = (Constructor<CraftEntity>)ClassLoader.getSystemClassLoader().loadClass("org.bukkit.craftbukkit.entity.Craft" + craftClass).getConstructors()[0];
|
|
||||||
Constructor<Entity> entity = (Constructor<Entity>)ClassLoader.getSystemClassLoader().loadClass("net.minecraft.server.Entity" + entityClass).getConstructors()[0];
|
|
||||||
return craft.newInstance((CraftServer)server, entity.newInstance(world));
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
logger.log(Level.WARNING, Util.i18n("unableToSpawnMob"), ex);
|
|
||||||
throw new MobException(ex);
|
|
||||||
}
|
}
|
||||||
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -107,22 +79,17 @@ public enum Mob
|
||||||
NEUTRAL("neutral"),
|
NEUTRAL("neutral"),
|
||||||
ENEMY("enemy");
|
ENEMY("enemy");
|
||||||
|
|
||||||
private Enemies(String t)
|
private Enemies(final String t)
|
||||||
{
|
{
|
||||||
this.type = t;
|
this.type = t;
|
||||||
}
|
}
|
||||||
protected String type;
|
final protected String type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class MobException extends Exception
|
public static class MobException extends Exception
|
||||||
{
|
{
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private MobException(Exception ex)
|
|
||||||
{
|
|
||||||
super(ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Mob fromName(String n)
|
public static Mob fromName(String n)
|
||||||
|
|
|
@ -3,8 +3,6 @@ package com.earth2me.essentials.commands;
|
||||||
import net.minecraft.server.WorldServer;
|
import net.minecraft.server.WorldServer;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.craftbukkit.entity.CraftEntity;
|
|
||||||
import com.earth2me.essentials.Essentials;
|
|
||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.User;
|
||||||
import com.earth2me.essentials.Mob;
|
import com.earth2me.essentials.Mob;
|
||||||
import com.earth2me.essentials.Mob.MobException;
|
import com.earth2me.essentials.Mob.MobException;
|
||||||
|
@ -20,6 +18,7 @@ import org.bukkit.craftbukkit.entity.CraftCreeper;
|
||||||
import org.bukkit.craftbukkit.entity.CraftSheep;
|
import org.bukkit.craftbukkit.entity.CraftSheep;
|
||||||
import org.bukkit.craftbukkit.entity.CraftSlime;
|
import org.bukkit.craftbukkit.entity.CraftSlime;
|
||||||
import org.bukkit.craftbukkit.entity.CraftWolf;
|
import org.bukkit.craftbukkit.entity.CraftWolf;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
|
||||||
|
|
||||||
public class Commandspawnmob extends EssentialsCommand
|
public class Commandspawnmob extends EssentialsCommand
|
||||||
|
@ -62,9 +61,9 @@ public class Commandspawnmob extends EssentialsCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CraftEntity spawnedMob = null;
|
Entity spawnedMob = null;
|
||||||
Mob mob = null;
|
Mob mob = null;
|
||||||
CraftEntity spawnedMount = null;
|
Entity spawnedMount = null;
|
||||||
Mob mobMount = null;
|
Mob mobMount = null;
|
||||||
|
|
||||||
mob = Mob.fromName(mobType);
|
mob = Mob.fromName(mobType);
|
||||||
|
@ -74,16 +73,6 @@ public class Commandspawnmob extends EssentialsCommand
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
charge(user);
|
charge(user);
|
||||||
WorldServer world = ((CraftWorld)user.getWorld()).getHandle();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
spawnedMob = mob.spawn(user, server);
|
|
||||||
}
|
|
||||||
catch (MobException e)
|
|
||||||
{
|
|
||||||
user.sendMessage(Util.i18n("unableToSpawnMob"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int[] ignore =
|
int[] ignore =
|
||||||
{
|
{
|
||||||
8, 9
|
8, 9
|
||||||
|
@ -96,8 +85,16 @@ public class Commandspawnmob extends EssentialsCommand
|
||||||
loc.setY(loc.getY() + 1);
|
loc.setY(loc.getY() + 1);
|
||||||
block = user.getWorld().getBlockAt(loc);
|
block = user.getWorld().getBlockAt(loc);
|
||||||
}
|
}
|
||||||
spawnedMob.teleportTo(loc);
|
|
||||||
world.addEntity(spawnedMob.getHandle());
|
try
|
||||||
|
{
|
||||||
|
spawnedMob = mob.spawn(user, server, loc);
|
||||||
|
}
|
||||||
|
catch (MobException e)
|
||||||
|
{
|
||||||
|
user.sendMessage(Util.i18n("unableToSpawnMob"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (mountType != null)
|
if (mountType != null)
|
||||||
{
|
{
|
||||||
|
@ -109,16 +106,14 @@ public class Commandspawnmob extends EssentialsCommand
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
spawnedMount = mobMount.spawn(user, server);
|
spawnedMount = mobMount.spawn(user, server, loc);
|
||||||
}
|
}
|
||||||
catch (MobException e)
|
catch (MobException e)
|
||||||
{
|
{
|
||||||
user.sendMessage(Util.i18n("unableToSpawnMob"));
|
user.sendMessage(Util.i18n("unableToSpawnMob"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
spawnedMount.teleportTo(spawnedMob);
|
spawnedMob.setPassenger(spawnedMount);
|
||||||
spawnedMount.getHandle().setPassengerOf(spawnedMob.getHandle());
|
|
||||||
world.addEntity(spawnedMount.getHandle());
|
|
||||||
}
|
}
|
||||||
if (mobData != null)
|
if (mobData != null)
|
||||||
{
|
{
|
||||||
|
@ -142,23 +137,19 @@ public class Commandspawnmob extends EssentialsCommand
|
||||||
{
|
{
|
||||||
for (int i = 1; i < mobCount; i++)
|
for (int i = 1; i < mobCount; i++)
|
||||||
{
|
{
|
||||||
spawnedMob = mob.spawn(user, server);
|
spawnedMob = mob.spawn(user, server, loc);
|
||||||
spawnedMob.teleportTo(loc);
|
|
||||||
world.addEntity(spawnedMob.getHandle());
|
|
||||||
if (mobMount != null)
|
if (mobMount != null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
spawnedMount = mobMount.spawn(user, server);
|
spawnedMount = mobMount.spawn(user, server, loc);
|
||||||
}
|
}
|
||||||
catch (MobException e)
|
catch (MobException e)
|
||||||
{
|
{
|
||||||
user.sendMessage(Util.i18n("unableToSpawnMob"));
|
user.sendMessage(Util.i18n("unableToSpawnMob"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
spawnedMount.teleportTo(spawnedMob);
|
spawnedMob.setPassenger(spawnedMount);
|
||||||
spawnedMount.getHandle().setPassengerOf(spawnedMob.getHandle());
|
|
||||||
world.addEntity(spawnedMount.getHandle());
|
|
||||||
}
|
}
|
||||||
if (mobData != null)
|
if (mobData != null)
|
||||||
{
|
{
|
||||||
|
@ -169,7 +160,7 @@ public class Commandspawnmob extends EssentialsCommand
|
||||||
changeMobData(mobMount.name, spawnedMount, mountData, user);
|
changeMobData(mobMount.name, spawnedMount, mountData, user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
user.sendMessage(args[1] + " " + mob.name.toLowerCase() + mob.s + Util.i18n("spawned"));
|
user.sendMessage(args[1] + " " + mob.name.toLowerCase() + mob.suffix + Util.i18n("spawned"));
|
||||||
}
|
}
|
||||||
catch (MobException e1)
|
catch (MobException e1)
|
||||||
{
|
{
|
||||||
|
@ -195,7 +186,7 @@ public class Commandspawnmob extends EssentialsCommand
|
||||||
return s.toUpperCase().charAt(0) + s.toLowerCase().substring(1);
|
return s.toUpperCase().charAt(0) + s.toLowerCase().substring(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeMobData(String type, CraftEntity spawned, String data, User user) throws Exception
|
private void changeMobData(String type, Entity spawned, String data, User user) throws Exception
|
||||||
{
|
{
|
||||||
if ("Slime".equalsIgnoreCase(type))
|
if ("Slime".equalsIgnoreCase(type))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue