mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-11-02 17:09:58 +01:00
[Feature] Allow the placing of spawners with predefined network id's (/i spawner:50)
[Permission] essentials.spawnerconvert.<mobname> - Allow the placing of specific mobspawners with premade network id's.
This commit is contained in:
parent
88d025cd0f
commit
1cb9ddf9fe
@ -1,7 +1,12 @@
|
|||||||
package com.earth2me.essentials;
|
package com.earth2me.essentials;
|
||||||
|
|
||||||
import com.earth2me.essentials.utils.LocationUtil;
|
import com.earth2me.essentials.utils.LocationUtil;
|
||||||
|
import java.util.Locale;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
|
import org.bukkit.block.CreatureSpawner;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@ -28,19 +33,38 @@ public class EssentialsBlockListener implements Listener
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is.getType() == Material.MOB_SPAWNER && event.getItemInHand() != null && event.getPlayer() != null
|
||||||
|
&& event.getItemInHand().getType() == Material.MOB_SPAWNER)
|
||||||
|
{
|
||||||
|
final BlockState blockState = event.getBlockPlaced().getState();
|
||||||
|
if (blockState instanceof CreatureSpawner)
|
||||||
|
{
|
||||||
|
final CreatureSpawner spawner = (CreatureSpawner)blockState;
|
||||||
|
final EntityType type = EntityType.fromId(event.getItemInHand().getData().getData());
|
||||||
|
if (type != null && Mob.fromBukkitType(type) != null)
|
||||||
|
{
|
||||||
|
if (ess.getUser(event.getPlayer()).isAuthorized("essentials.spawnerconvert." + Mob.fromBukkitType(type).name().toLowerCase(Locale.ENGLISH)))
|
||||||
|
{
|
||||||
|
spawner.setSpawnedType(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final User user = ess.getUser(event.getPlayer());
|
final User user = ess.getUser(event.getPlayer());
|
||||||
if (user.hasUnlimited(is) && user.getGameMode() == GameMode.SURVIVAL)
|
if (user.hasUnlimited(is) && user.getGameMode() == GameMode.SURVIVAL)
|
||||||
{
|
{
|
||||||
ess.scheduleSyncDelayedTask(
|
ess.scheduleSyncDelayedTask(
|
||||||
new Runnable()
|
new Runnable()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
user.getInventory().addItem(is);
|
user.getInventory().addItem(is);
|
||||||
user.updateInventory();
|
user.updateInventory();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,7 @@ public enum Mob
|
|||||||
MINECART_FURNACE("FurnaceMinecart", Enemies.NEUTRAL, EntityType.MINECART_FURNACE),
|
MINECART_FURNACE("FurnaceMinecart", Enemies.NEUTRAL, EntityType.MINECART_FURNACE),
|
||||||
MINECART_TNT("TNTMinecart", Enemies.NEUTRAL, EntityType.MINECART_TNT),
|
MINECART_TNT("TNTMinecart", Enemies.NEUTRAL, EntityType.MINECART_TNT),
|
||||||
MINECART_HOPPER("HopperMinecart", Enemies.NEUTRAL, EntityType.MINECART_HOPPER),
|
MINECART_HOPPER("HopperMinecart", Enemies.NEUTRAL, EntityType.MINECART_HOPPER),
|
||||||
|
MINECART_MOB_SPAWNER("SpawnerMinecart", Enemies.NEUTRAL, EntityType.MINECART_MOB_SPAWNER),
|
||||||
ENDERCRYSTAL("EnderCrystal", Enemies.NEUTRAL, EntityType.ENDER_CRYSTAL),
|
ENDERCRYSTAL("EnderCrystal", Enemies.NEUTRAL, EntityType.ENDER_CRYSTAL),
|
||||||
EXPERIENCEORB("ExperienceOrb", Enemies.NEUTRAL, EntityType.EXPERIENCE_ORB);
|
EXPERIENCEORB("ExperienceOrb", Enemies.NEUTRAL, EntityType.EXPERIENCE_ORB);
|
||||||
public static final Logger logger = Logger.getLogger("Minecraft");
|
public static final Logger logger = Logger.getLogger("Minecraft");
|
||||||
@ -73,12 +74,14 @@ public enum Mob
|
|||||||
final public Enemies type;
|
final public Enemies type;
|
||||||
final private EntityType bukkitType;
|
final private EntityType bukkitType;
|
||||||
private static final Map<String, Mob> hashMap = new HashMap<String, Mob>();
|
private static final Map<String, Mob> hashMap = new HashMap<String, Mob>();
|
||||||
|
private static final Map<EntityType, Mob> bukkitMap = new HashMap<EntityType, Mob>();
|
||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
for (Mob mob : Mob.values())
|
for (Mob mob : Mob.values())
|
||||||
{
|
{
|
||||||
hashMap.put(mob.name.toLowerCase(Locale.ENGLISH), mob);
|
hashMap.put(mob.name.toLowerCase(Locale.ENGLISH), mob);
|
||||||
|
bukkitMap.put(mob.bukkitType, mob);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,6 +130,10 @@ public enum Mob
|
|||||||
return hashMap.get(name.toLowerCase(Locale.ENGLISH));
|
return hashMap.get(name.toLowerCase(Locale.ENGLISH));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Mob fromBukkitType(final EntityType type)
|
||||||
|
{
|
||||||
|
return bukkitMap.get(type);
|
||||||
|
}
|
||||||
|
|
||||||
public static class MobException extends Exception
|
public static class MobException extends Exception
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user