mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-01-09 09:57:33 +01:00
Add color to /npc shulker
This commit is contained in:
parent
dd53b5eefa
commit
73ff01c774
@ -48,6 +48,7 @@ import net.citizensnpcs.api.command.CommandContext;
|
||||
import net.citizensnpcs.api.command.CommandMessages;
|
||||
import net.citizensnpcs.api.command.Requirements;
|
||||
import net.citizensnpcs.api.command.exception.CommandException;
|
||||
import net.citizensnpcs.api.command.exception.CommandUsageException;
|
||||
import net.citizensnpcs.api.command.exception.NoPermissionsException;
|
||||
import net.citizensnpcs.api.command.exception.ServerCommandException;
|
||||
import net.citizensnpcs.api.event.CommandSenderCreateNPCEvent;
|
||||
@ -120,7 +121,6 @@ public class NPCCommands {
|
||||
if (!npc.isSpawned() || (!(npc.getEntity() instanceof Ageable) && !(npc.getEntity() instanceof Zombie)))
|
||||
throw new CommandException(Messages.MOBTYPE_CANNOT_BE_AGED, npc.getName());
|
||||
Age trait = npc.getTrait(Age.class);
|
||||
|
||||
boolean toggleLock = args.hasFlag('l');
|
||||
if (toggleLock) {
|
||||
Messaging.sendTr(sender, trait.toggle() ? Messages.AGE_LOCKED : Messages.AGE_UNLOCKED);
|
||||
@ -298,8 +298,9 @@ public class NPCCommands {
|
||||
public void collidable(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
npc.data().setPersistent(NPC.COLLIDABLE_METADATA, !npc.data().get(NPC.COLLIDABLE_METADATA, true));
|
||||
Messaging.sendTr(sender,
|
||||
npc.data().get(NPC.COLLIDABLE_METADATA) ? Messages.COLLIDABLE_SET : Messages.COLLIDABLE_UNSET,
|
||||
npc.data().<Boolean> get(NPC.COLLIDABLE_METADATA) ? Messages.COLLIDABLE_SET : Messages.COLLIDABLE_UNSET,
|
||||
npc.getName());
|
||||
|
||||
}
|
||||
|
||||
@Command(
|
||||
@ -1492,7 +1493,7 @@ public class NPCCommands {
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "shulker (--peek [peek])",
|
||||
usage = "shulker (--peek [peek] --color [color])",
|
||||
desc = "Sets shulker modifiers.",
|
||||
modifiers = { "shulker" },
|
||||
min = 1,
|
||||
@ -1508,8 +1509,14 @@ public class NPCCommands {
|
||||
Messaging.sendTr(sender, Messages.SHULKER_PEEK_SET, npc.getName(), peek);
|
||||
hasArg = true;
|
||||
}
|
||||
if (args.hasValueFlag("color")) {
|
||||
DyeColor color = Util.matchEnum(DyeColor.values(), args.getFlag("color"));
|
||||
trait.setColor(color);
|
||||
Messaging.sendTr(sender, Messages.SHULKER_COLOR_SET, npc.getName(), Util.prettyEnum(color));
|
||||
hasArg = true;
|
||||
}
|
||||
if (!hasArg) {
|
||||
throw new CommandException();
|
||||
throw new CommandUsageException();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.citizensnpcs.trait;
|
||||
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.entity.Shulker;
|
||||
|
||||
import net.citizensnpcs.api.persistence.Persist;
|
||||
@ -9,6 +10,8 @@ import net.citizensnpcs.util.NMS;
|
||||
|
||||
@TraitName("shulkertrait")
|
||||
public class ShulkerTrait extends Trait {
|
||||
@Persist("color")
|
||||
private DyeColor color = DyeColor.PURPLE;
|
||||
@Persist("peek")
|
||||
private int peek = 0;
|
||||
|
||||
@ -21,10 +24,19 @@ public class ShulkerTrait extends Trait {
|
||||
setPeek(peek);
|
||||
}
|
||||
|
||||
public void setPeek(int peek) {
|
||||
this.peek = peek;
|
||||
@Override
|
||||
public void run() {
|
||||
if (npc.getEntity() instanceof Shulker) {
|
||||
NMS.setShulkerPeek((Shulker) npc.getEntity(), peek);
|
||||
NMS.setShulkerColor((Shulker) npc.getEntity(), color);
|
||||
}
|
||||
}
|
||||
|
||||
public void setColor(DyeColor color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public void setPeek(int peek) {
|
||||
this.peek = peek;
|
||||
}
|
||||
}
|
||||
|
@ -207,6 +207,7 @@ public class Messages {
|
||||
public static final String SHEARED_SET = "citizens.editors.equipment.sheared-set";
|
||||
public static final String SHEARED_STOPPED = "citizens.editors.equipment.sheared-stopped";
|
||||
public static final String SHEEP_COLOR_SET = "citizens.commands.npc.sheep.color-set";
|
||||
public static final String SHULKER_COLOR_SET = "citizens.commands.npc.shulker.color-set";
|
||||
public static final String SHULKER_PEEK_SET = "citizens.commands.npc.shulker.peek-set";
|
||||
public static final String SIZE_DESCRIPTION = "citizens.commands.npc.size.description";
|
||||
public static final String SIZE_SET = "citizens.commands.npc.size.set";
|
||||
|
@ -5,6 +5,7 @@ import java.lang.reflect.Modifier;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.boss.BossBar;
|
||||
@ -261,6 +262,10 @@ public class NMS {
|
||||
BRIDGE.setShouldJump(entity);
|
||||
}
|
||||
|
||||
public static void setShulkerColor(Shulker entity, DyeColor color) {
|
||||
BRIDGE.setShulkerColor(entity, color);
|
||||
}
|
||||
|
||||
public static void setShulkerPeek(Shulker shulker, int peek) {
|
||||
BRIDGE.setShulkerPeek(shulker, peek);
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package net.citizensnpcs.util;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
@ -125,6 +126,8 @@ public interface NMSBridge {
|
||||
|
||||
public void setShouldJump(Entity entity);
|
||||
|
||||
public void setShulkerColor(Shulker entity, DyeColor color);
|
||||
|
||||
public void setShulkerPeek(Shulker shulker, int peek);
|
||||
|
||||
public void setSitting(Tameable tameable, boolean sitting);
|
||||
|
@ -114,6 +114,7 @@ citizens.commands.npc.select.already-selected=You already have that NPC selected
|
||||
citizens.commands.npc.script.invalid-file=Unknown or unavailable script ''[[{0}]]''.
|
||||
citizens.commands.npc.script.current-scripts=[[{0}]]''s current scripts are [[{1}]].
|
||||
citizens.commands.npc.shulker.peek-set=[[{0}]]''s peek amount set to [[{1}]].
|
||||
citizens.commands.npc.shulker.color-set=[[{0}]]''s color set to [[{1}]].
|
||||
citizens.commands.npc.skin.set=[[{0}]]''s skin name set to [[{1}]].
|
||||
citizens.commands.npc.skin.missing-skin=A skin name is required.
|
||||
citizens.commands.npc.skin.cleared=[[{0}]]''s skin name was cleared.
|
||||
|
@ -15,6 +15,7 @@ import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
@ -883,6 +884,10 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShulkerColor(Shulker shulker, DyeColor color) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShulkerPeek(Shulker shulker, int peek) {
|
||||
((EntityShulker) getHandle(shulker)).a((byte) peek);
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.citizensnpcs.nms.v1_11_R1.entity;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.craftbukkit.v1_11_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftShulker;
|
||||
@ -194,6 +195,10 @@ public class ShulkerController extends MobEntityController {
|
||||
return new EntityAIBodyControl(this);
|
||||
}
|
||||
|
||||
public void setColor(DyeColor color) {
|
||||
this.datawatcher.set(bw, color.getDyeData());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSize(float f, float f1) {
|
||||
if (npc == null) {
|
||||
|
@ -15,6 +15,7 @@ import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
@ -99,6 +100,7 @@ import net.citizensnpcs.nms.v1_11_R1.entity.PolarBearController;
|
||||
import net.citizensnpcs.nms.v1_11_R1.entity.RabbitController;
|
||||
import net.citizensnpcs.nms.v1_11_R1.entity.SheepController;
|
||||
import net.citizensnpcs.nms.v1_11_R1.entity.ShulkerController;
|
||||
import net.citizensnpcs.nms.v1_11_R1.entity.ShulkerController.EntityShulkerNPC;
|
||||
import net.citizensnpcs.nms.v1_11_R1.entity.SilverfishController;
|
||||
import net.citizensnpcs.nms.v1_11_R1.entity.SkeletonController;
|
||||
import net.citizensnpcs.nms.v1_11_R1.entity.SkeletonStrayController;
|
||||
@ -945,6 +947,11 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShulkerColor(Shulker shulker, DyeColor color) {
|
||||
((EntityShulkerNPC) getHandle(shulker)).setColor(color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShulkerPeek(Shulker shulker, int peek) {
|
||||
((EntityShulker) getHandle(shulker)).a((byte) peek);
|
||||
|
@ -15,6 +15,7 @@ import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
@ -730,6 +731,7 @@ public class NMSImpl implements NMSBridge {
|
||||
@Override
|
||||
public void look(org.bukkit.entity.Entity from, org.bukkit.entity.Entity to) {
|
||||
Entity handle = NMSImpl.getHandle(from), target = NMSImpl.getHandle(to);
|
||||
BAD_CONTROLLER_LOOK.add(EntityType.SHULKER);
|
||||
if (BAD_CONTROLLER_LOOK.contains(handle.getBukkitEntity().getType())) {
|
||||
if (to instanceof LivingEntity) {
|
||||
look(from, ((LivingEntity) to).getEyeLocation(), false, true);
|
||||
@ -959,6 +961,11 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShulkerColor(Shulker shulker, DyeColor color) {
|
||||
((EntityShulker) getHandle(shulker)).getDataWatcher().set(EntityShulker.COLOR, color.getDyeData());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShulkerPeek(Shulker shulker, int peek) {
|
||||
((EntityShulker) getHandle(shulker)).a((byte) peek);
|
||||
@ -1494,12 +1501,12 @@ public class NMSImpl implements NMSBridge {
|
||||
|
||||
public static void updateNavigation(NavigationAbstract navigation) {
|
||||
navigation.d();
|
||||
}
|
||||
};
|
||||
|
||||
private static Field ADVANCEMENT_PLAYER_FIELD = NMS.getFinalField(EntityPlayer.class, "bY");;
|
||||
private static Field ADVANCEMENT_PLAYER_FIELD = NMS.getFinalField(EntityPlayer.class, "bY");
|
||||
private static final Set<EntityType> BAD_CONTROLLER_LOOK = EnumSet.of(EntityType.POLAR_BEAR, EntityType.SILVERFISH,
|
||||
EntityType.ENDERMITE, EntityType.ENDER_DRAGON, EntityType.BAT, EntityType.SLIME, EntityType.MAGMA_CUBE,
|
||||
EntityType.HORSE, EntityType.GHAST);
|
||||
EntityType.SHULKER, EntityType.ENDERMITE, EntityType.ENDER_DRAGON, EntityType.BAT, EntityType.SLIME,
|
||||
EntityType.MAGMA_CUBE, EntityType.HORSE, EntityType.GHAST);
|
||||
private static final Field CRAFT_BOSSBAR_HANDLE_FIELD = NMS.getField(CraftBossBar.class, "handle");
|
||||
private static final float DEFAULT_SPEED = 1F;
|
||||
private static final Field ENDERDRAGON_BATTLE_BAR_FIELD = NMS.getField(EnderDragonBattle.class, "c");
|
||||
@ -1516,6 +1523,7 @@ public class NMSImpl implements NMSBridge {
|
||||
private static final Field RABBIT_FIELD = NMS.getField(EntityRabbit.class, "bx");
|
||||
private static final Random RANDOM = Util.getFastRandom();
|
||||
private static Field SKULL_PROFILE_FIELD;
|
||||
|
||||
private static Field TRACKED_ENTITY_SET = NMS.getField(EntityTracker.class, "c");
|
||||
|
||||
private static final Field WITHER_BOSS_BAR_FIELD = NMS.getField(EntityWither.class, "bG");
|
||||
|
Loading…
Reference in New Issue
Block a user