Skip to content

Commit

Permalink
Add color to /npc shulker
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Mar 9, 2018
1 parent dd53b5e commit 73ff01c
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 10 deletions.
15 changes: 11 additions & 4 deletions main/src/main/java/net/citizensnpcs/commands/NPCCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
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;
Expand Down Expand Up @@ -120,7 +121,6 @@ public void age(CommandContext args, CommandSender sender, NPC npc) throws Comma
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);
Expand Down Expand Up @@ -298,8 +298,9 @@ public void bossbar(CommandContext args, CommandSender sender, NPC npc) throws C
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(
Expand Down Expand Up @@ -1492,7 +1493,7 @@ public void sheep(CommandContext args, CommandSender sender, NPC npc) throws Com

@Command(
aliases = { "npc" },
usage = "shulker (--peek [peek])",
usage = "shulker (--peek [peek] --color [color])",
desc = "Sets shulker modifiers.",
modifiers = { "shulker" },
min = 1,
Expand All @@ -1508,8 +1509,14 @@ public void shulker(CommandContext args, CommandSender sender, NPC npc) throws C
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();
}
}

Expand Down
16 changes: 14 additions & 2 deletions main/src/main/java/net/citizensnpcs/trait/ShulkerTrait.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.citizensnpcs.trait;

import org.bukkit.DyeColor;
import org.bukkit.entity.Shulker;

import net.citizensnpcs.api.persistence.Persist;
Expand All @@ -9,6 +10,8 @@

@TraitName("shulkertrait")
public class ShulkerTrait extends Trait {
@Persist("color")
private DyeColor color = DyeColor.PURPLE;
@Persist("peek")
private int peek = 0;

Expand All @@ -21,10 +24,19 @@ public void onSpawn() {
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;
}
}
1 change: 1 addition & 0 deletions main/src/main/java/net/citizensnpcs/util/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
5 changes: 5 additions & 0 deletions main/src/main/java/net/citizensnpcs/util/NMS.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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;
Expand Down Expand Up @@ -261,6 +262,10 @@ public static void setShouldJump(org.bukkit.entity.Entity entity) {
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);
}
Expand Down
3 changes: 3 additions & 0 deletions main/src/main/java/net/citizensnpcs/util/NMSBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions main/src/main/resources/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Set;

import org.bukkit.Bukkit;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
Expand Down Expand Up @@ -883,6 +884,10 @@ public void setShouldJump(org.bukkit.entity.Entity entity) {
}
}

@Override
public void setShulkerColor(Shulker shulker, DyeColor color) {
}

@Override
public void setShulkerPeek(Shulker shulker, int peek) {
((EntityShulker) getHandle(shulker)).a((byte) peek);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -194,6 +195,10 @@ protected EntityAIBodyControl s() {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Set;

import org.bukkit.Bukkit;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
Expand Down Expand Up @@ -99,6 +100,7 @@
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;
Expand Down Expand Up @@ -945,6 +947,11 @@ public void setShouldJump(org.bukkit.entity.Entity entity) {
}
}

@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Set;

import org.bukkit.Bukkit;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
Expand Down Expand Up @@ -730,6 +731,7 @@ public void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly,
@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);
Expand Down Expand Up @@ -959,6 +961,11 @@ public void setShouldJump(org.bukkit.entity.Entity entity) {
}
}

@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);
Expand Down Expand Up @@ -1494,12 +1501,12 @@ public static void updateAI(EntityLiving entity) {

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");
Expand All @@ -1516,6 +1523,7 @@ public static void updateNavigation(NavigationAbstract navigation) {
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");
Expand Down

0 comments on commit 73ff01c

Please sign in to comment.