Add /npc glowing <color>, fix waypoint editor right clicks

This commit is contained in:
fullwall 2016-03-20 19:32:24 +08:00
parent 94dd5c4dba
commit b13fbeddd5
8 changed files with 54 additions and 35 deletions

View File

@ -478,8 +478,10 @@ public class EventListen implements Listener {
}
return;
}
storeForRespawn(npc);
Messaging.debug("Despawned", npc.getId() + "due to world unload at", event.getWorld().getName());
if (npc.isSpawned()) {
storeForRespawn(npc);
Messaging.debug("Despawned", npc.getId() + "due to world unload at", event.getWorld().getName());
}
}
}

View File

@ -8,6 +8,7 @@ import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.DyeColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
@ -548,7 +549,7 @@ public class NPCCommands {
@Command(
aliases = { "npc" },
usage = "glowing",
usage = "glowing --color [minecraft chat color]",
desc = "Toggles an NPC's glowing status",
modifiers = { "glowing" },
min = 1,
@ -556,6 +557,12 @@ public class NPCCommands {
permission = "citizens.npc.glowing")
@Requirements(selected = true, ownership = true)
public void glowing(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
if (args.hasValueFlag("color")) {
ChatColor chatColor = Util.matchEnum(ChatColor.values(), args.getFlag("color"));
if (chatColor == null || !(npc.getEntity() instanceof Player))
throw new CommandException();
npc.data().setPersistent(NPC.GLOWING_COLOR_METADATA, chatColor.name());
}
npc.data().setPersistent(NPC.GLOWING_METADATA, !npc.data().get(NPC.GLOWING_METADATA, false));
boolean glowing = npc.data().get(NPC.GLOWING_METADATA);
Messaging.sendTr(sender, glowing ? Messages.GLOWING_SET : Messages.GLOWING_UNSET, npc.getName());

View File

@ -5,6 +5,7 @@ import java.util.Collection;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftEntity;
@ -15,7 +16,9 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.scoreboard.NameTagVisibility;
import org.bukkit.scoreboard.Team;
import org.bukkit.scoreboard.Team.Option;
import org.bukkit.scoreboard.Team.OptionStatus;
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
@ -277,21 +280,22 @@ public class CitizensNPC extends AbstractNPC {
if (!getNavigator().isNavigating() && updateCounter++ > Setting.PACKET_UPDATE_DELAY.asInt()) {
updateCounter = 0;
if (getEntity() instanceof LivingEntity) {
OptionStatus nameVisibility = OptionStatus.NEVER;
if (!getEntity().isCustomNameVisible()) {
if (getEntity() instanceof Player && data().has(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA)) {
String teamName = data().get(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA);
Bukkit.getScoreboardManager().getMainScoreboard().getTeam(teamName)
.setNameTagVisibility(NameTagVisibility.NEVER);
}
getEntity().setCustomName("");
} else {
if (getEntity() instanceof Player && data().has(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA)) {
String teamName = data().get(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA);
Bukkit.getScoreboardManager().getMainScoreboard().getTeam(teamName)
.setNameTagVisibility(NameTagVisibility.ALWAYS);
}
nameVisibility = OptionStatus.ALWAYS;
getEntity().setCustomName(getFullName());
}
if (getEntity() instanceof Player && data().has(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA)) {
String teamName = data().get(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA);
Team team = Bukkit.getScoreboardManager().getMainScoreboard().getTeam(teamName);
team.setOption(Option.NAME_TAG_VISIBILITY, nameVisibility);
if (data().has(NPC.GLOWING_COLOR_METADATA) && team.getPrefix() == null) {
team.setPrefix(
ChatColor.valueOf(data().<String> get(NPC.GLOWING_COLOR_METADATA)).toString());
}
}
}
Player player = getEntity() instanceof Player ? (Player) getEntity() : null;
NMS.sendPacketNearby(player, getStoredLocation(),

View File

@ -98,22 +98,22 @@ public class HumanController extends AbstractEntityController {
Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());
NMS.addOrRemoveFromPlayerList(getBukkitEntity(),
npc.data().get("removefromplayerlist", removeFromPlayerList));
if (prefixCapture != null) {
Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
String teamName = UUID.randomUUID().toString().substring(0, 16);
Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
String teamName = UUID.randomUUID().toString().substring(0, 16);
Team team = scoreboard.getTeam(teamName);
if (team == null) {
team = scoreboard.registerNewTeam(teamName);
Team team = scoreboard.getTeam(teamName);
if (team == null) {
team = scoreboard.registerNewTeam(teamName);
if (prefixCapture != null) {
team.setPrefix(prefixCapture);
if (suffixCapture != null) {
team.setSuffix(suffixCapture);
}
}
team.addPlayer(handle.getBukkitEntity());
handle.getNPC().data().set(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA, teamName);
if (suffixCapture != null) {
team.setSuffix(suffixCapture);
}
}
team.addPlayer(handle.getBukkitEntity());
handle.getNPC().data().set(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA, teamName);
}
}, 20);

View File

@ -13,6 +13,7 @@ import org.bukkit.event.block.Action;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.util.Vector;
@ -113,7 +114,7 @@ public class GuidedWaypointProvider implements WaypointProvider {
public void onPlayerInteract(PlayerInteractEvent event) {
if (!event.getPlayer().equals(player) || event.getAction() == Action.PHYSICAL
|| event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK
|| event.getClickedBlock() == null)
|| event.getClickedBlock() == null || event.getHand() == EquipmentSlot.OFF_HAND)
return;
if (event.getPlayer().getWorld() != npc.getEntity().getWorld())
return;
@ -133,7 +134,8 @@ public class GuidedWaypointProvider implements WaypointProvider {
@EventHandler(ignoreCancelled = true)
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
if (!event.getRightClicked().hasMetadata("citizens.waypointhashcode"))
if (!event.getRightClicked().hasMetadata("citizens.waypointhashcode")
|| event.getHand() == EquipmentSlot.OFF_HAND)
return;
int hashcode = event.getRightClicked().getMetadata("citizens.waypointhashcode").get(0).asInt();
Iterator<Waypoint> itr = Iterables.concat(available, helpers).iterator();

View File

@ -17,6 +17,7 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.inventory.EquipmentSlot;
import com.google.common.collect.Lists;
@ -247,7 +248,8 @@ public class LinearWaypointProvider implements WaypointProvider {
@EventHandler(ignoreCancelled = true)
public void onPlayerInteract(PlayerInteractEvent event) {
if (!event.getPlayer().equals(player) || event.getAction() == Action.PHYSICAL || !npc.isSpawned()
|| event.getPlayer().getWorld() != npc.getEntity().getWorld())
|| event.getPlayer().getWorld() != npc.getEntity().getWorld()
|| event.getHand() == EquipmentSlot.OFF_HAND)
return;
if (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_AIR) {
if (event.getClickedBlock() == null)
@ -291,7 +293,7 @@ public class LinearWaypointProvider implements WaypointProvider {
@EventHandler(ignoreCancelled = true)
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
if (!player.equals(event.getPlayer()) || !showPath)
if (!player.equals(event.getPlayer()) || !showPath || event.getHand() == EquipmentSlot.OFF_HAND)
return;
if (!event.getRightClicked().hasMetadata("waypointindex"))
return;

View File

@ -18,6 +18,7 @@ import javax.annotation.Nullable;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
@ -35,6 +36,7 @@ import org.bukkit.entity.Tameable;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.plugin.PluginLoadOrder;
import org.bukkit.scoreboard.Team;
import com.google.common.base.Preconditions;
import com.mojang.authlib.GameProfile;
@ -76,6 +78,7 @@ import net.minecraft.server.v1_9_R1.EntityTameableAnimal;
import net.minecraft.server.v1_9_R1.EntityTracker;
import net.minecraft.server.v1_9_R1.EntityTrackerEntry;
import net.minecraft.server.v1_9_R1.EntityTypes;
import net.minecraft.server.v1_9_R1.EnumChatFormat;
import net.minecraft.server.v1_9_R1.GenericAttributes;
import net.minecraft.server.v1_9_R1.MathHelper;
import net.minecraft.server.v1_9_R1.MobEffects;
@ -84,6 +87,7 @@ import net.minecraft.server.v1_9_R1.NetworkManager;
import net.minecraft.server.v1_9_R1.Packet;
import net.minecraft.server.v1_9_R1.PacketPlayOutPlayerInfo;
import net.minecraft.server.v1_9_R1.PathfinderGoalSelector;
import net.minecraft.server.v1_9_R1.ScoreboardTeam;
import net.minecraft.server.v1_9_R1.Vec3D;
import net.minecraft.server.v1_9_R1.World;
import net.minecraft.server.v1_9_R1.WorldServer;
@ -720,8 +724,7 @@ public class NMS {
} else if (handle instanceof EntityHumanNPC) {
((EntityHumanNPC) handle).setMoveDestination(x, y, z, speed);
}
}
}
public static void setHeadYaw(Entity en, float yaw) {
if (!(en instanceof EntityLiving))
return;
@ -890,6 +893,7 @@ public class NMS {
}
}
private static Field CRAFT_TEAM_FIELD;
private static final float DEFAULT_SPEED = 1F;
private static Map<Class<?>, Integer> ENTITY_CLASS_TO_INT;
private static Map<Class<?>, String> ENTITY_CLASS_TO_NAME;
@ -902,11 +906,8 @@ public class NMS {
private static final Location PACKET_CACHE_LOCATION = new Location(null, 0, 0, 0);
private static Field PATHFINDING_RANGE = getField(NavigationAbstract.class, "g");
private static final Field RABBIT_FIELD = getField(EntityRabbit.class, "bv");
private static final Random RANDOM = Util.getFastRandom();
private static Field SKULL_PROFILE_FIELD;
private static Field TRACKED_ENTITY_SET = NMS.getField(EntityTracker.class, "c");
static {

View File

@ -48,6 +48,7 @@ public class PlayerNavigation extends NavigationAbstract {
this.e = new PlayerPathfinderNormal();
this.e.a(true);
this.s = new PlayerPathfinder(this.e);
// this.b.C().a(this);
}
@Override