Spam fix for older versions
This commit is contained in:
parent
dff4d59fc0
commit
c33ac8a1b1
5 changed files with 48 additions and 8 deletions
|
@ -84,6 +84,10 @@ public class DefaultCommand extends Command {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
NPCType npcType = NPCType.valueOf(args.get("type").toUpperCase());
|
NPCType npcType = NPCType.valueOf(args.get("type").toUpperCase());
|
||||||
|
if (npcType.getConstructor() == null && !npcType.equals(NPCType.PLAYER)) {
|
||||||
|
Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.NOT_SUPPORTED_NPC_TYPE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
ZNPCsPlus.createNPC(id, npcType, sender.getPlayer().getLocation(), name);
|
ZNPCsPlus.createNPC(id, npcType, sender.getPlayer().getLocation(), name);
|
||||||
Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.SUCCESS);
|
Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.SUCCESS);
|
||||||
}
|
}
|
||||||
|
@ -116,7 +120,13 @@ public class DefaultCommand extends Command {
|
||||||
sender.sendMessage(ChatColor.DARK_GREEN + "NPC list:");
|
sender.sendMessage(ChatColor.DARK_GREEN + "NPC list:");
|
||||||
for (NPCModel npcModel : ConfigurationConstants.NPC_LIST) {
|
for (NPCModel npcModel : ConfigurationConstants.NPC_LIST) {
|
||||||
List<BaseComponent> parts = new ArrayList<>();
|
List<BaseComponent> parts = new ArrayList<>();
|
||||||
String message = "- " + npcModel.getId() + " " + npcModel.getHologramLines().toString() + " (" + npcModel.getLocation().getWorldName() + " " + (int) npcModel.getLocation().getX() + " " + (int) npcModel.getLocation().getY() + " " + (int) npcModel.getLocation().getZ() + ") ";
|
TextComponent component1 = new TextComponent("-");
|
||||||
|
component1.setColor(ChatColor.GREEN);
|
||||||
|
parts.add(component1);
|
||||||
|
TextComponent idComponent = new TextComponent(" " + npcModel.getId());
|
||||||
|
idComponent.setColor(npcModel.getShouldSpawn() ? ChatColor.GREEN : ChatColor.RED);
|
||||||
|
parts.add(idComponent);
|
||||||
|
String message = " " + npcModel.getHologramLines().toString() + " (" + npcModel.getLocation().getWorldName() + " " + (int) npcModel.getLocation().getX() + " " + (int) npcModel.getLocation().getY() + " " + (int) npcModel.getLocation().getZ() + ") ";
|
||||||
TextComponent textComponent = new TextComponent(message);
|
TextComponent textComponent = new TextComponent(message);
|
||||||
textComponent.setColor(ChatColor.GREEN);
|
textComponent.setColor(ChatColor.GREEN);
|
||||||
parts.add(textComponent);
|
parts.add(textComponent);
|
||||||
|
|
|
@ -7,6 +7,7 @@ import java.util.List;
|
||||||
|
|
||||||
public final class ConfigurationConstants {
|
public final class ConfigurationConstants {
|
||||||
public static final String SPACE_SYMBOL = Configuration.CONFIGURATION.getValue(ConfigurationValue.REPLACE_SYMBOL);
|
public static final String SPACE_SYMBOL = Configuration.CONFIGURATION.getValue(ConfigurationValue.REPLACE_SYMBOL);
|
||||||
|
public static final boolean DEBUG_ENABLED = Configuration.CONFIGURATION.getValue(ConfigurationValue.DEBUG_ENABLED);
|
||||||
public static final int VIEW_DISTANCE = Configuration.CONFIGURATION.<Integer>getValue(ConfigurationValue.VIEW_DISTANCE);
|
public static final int VIEW_DISTANCE = Configuration.CONFIGURATION.<Integer>getValue(ConfigurationValue.VIEW_DISTANCE);
|
||||||
public static final int SAVE_DELAY = Configuration.CONFIGURATION.<Integer>getValue(ConfigurationValue.SAVE_NPCS_DELAY_SECONDS);
|
public static final int SAVE_DELAY = Configuration.CONFIGURATION.<Integer>getValue(ConfigurationValue.SAVE_NPCS_DELAY_SECONDS);
|
||||||
public static final boolean RGB_ANIMATION = Configuration.CONFIGURATION.<Boolean>getValue(ConfigurationValue.ANIMATION_RGB);
|
public static final boolean RGB_ANIMATION = Configuration.CONFIGURATION.<Boolean>getValue(ConfigurationValue.ANIMATION_RGB);
|
||||||
|
|
|
@ -51,6 +51,7 @@ public enum ConfigurationValue {
|
||||||
FETCHING_SKIN("messages", "&aFetching skin for name: &f%s&a. Please wait...", String.class),
|
FETCHING_SKIN("messages", "&aFetching skin for name: &f%s&a. Please wait...", String.class),
|
||||||
CANT_GET_SKIN("messages", "&cCould not fetch skin for name: %s.", String.class),
|
CANT_GET_SKIN("messages", "&cCould not fetch skin for name: %s.", String.class),
|
||||||
GET_SKIN("messages", "&aSkin successfully fetched!", String.class),
|
GET_SKIN("messages", "&aSkin successfully fetched!", String.class),
|
||||||
|
NOT_SUPPORTED_NPC_TYPE("messages", "&cThis NPC type doesn't exists or is not supported in your current server version.", String.class),
|
||||||
CONVERSATION_LIST("conversations" /* Leave this lowercase or it will break */, new ArrayList<>(), Conversation.class);
|
CONVERSATION_LIST("conversations" /* Leave this lowercase or it will break */, new ArrayList<>(), Conversation.class);
|
||||||
|
|
||||||
public static final Map<String, ImmutableSet<ConfigurationValue>> VALUES_BY_NAME;
|
public static final Map<String, ImmutableSet<ConfigurationValue>> VALUES_BY_NAME;
|
||||||
|
|
|
@ -12,6 +12,8 @@ import com.mojang.authlib.properties.Property;
|
||||||
import com.mojang.authlib.properties.PropertyMap;
|
import com.mojang.authlib.properties.PropertyMap;
|
||||||
import io.github.retrooper.packetevents.util.SpigotConversionUtil;
|
import io.github.retrooper.packetevents.util.SpigotConversionUtil;
|
||||||
import io.github.znetworkw.znpcservers.UnexpectedCallException;
|
import io.github.znetworkw.znpcservers.UnexpectedCallException;
|
||||||
|
import io.github.znetworkw.znpcservers.configuration.ConfigurationConstants;
|
||||||
|
import io.github.znetworkw.znpcservers.configuration.ConfigurationValue;
|
||||||
import io.github.znetworkw.znpcservers.hologram.Hologram;
|
import io.github.znetworkw.znpcservers.hologram.Hologram;
|
||||||
import io.github.znetworkw.znpcservers.nms.PacketCache;
|
import io.github.znetworkw.znpcservers.nms.PacketCache;
|
||||||
import io.github.znetworkw.znpcservers.npc.conversation.ConversationModel;
|
import io.github.znetworkw.znpcservers.npc.conversation.ConversationModel;
|
||||||
|
@ -81,13 +83,21 @@ public class NPC {
|
||||||
if (NPC_MAP.containsKey(getNpcPojo().getId())) throw new IllegalStateException("npc with id " + getNpcPojo().getId() + " already exists.");
|
if (NPC_MAP.containsKey(getNpcPojo().getId())) throw new IllegalStateException("npc with id " + getNpcPojo().getId() + " already exists.");
|
||||||
this.gameProfile = new GameProfile(this.uuid, "[ZNPC] " + this.npcName);
|
this.gameProfile = new GameProfile(this.uuid, "[ZNPC] " + this.npcName);
|
||||||
this.gameProfile.getProperties().put("textures", new Property("textures", this.npcPojo.getSkin(), this.npcPojo.getSignature()));
|
this.gameProfile.getProperties().put("textures", new Property("textures", this.npcPojo.getSkin(), this.npcPojo.getSignature()));
|
||||||
changeType(this.npcPojo.getNpcType());
|
if (this.npcPojo.getNpcType().getConstructor() == null && !this.npcPojo.getNpcType().equals(NPCType.PLAYER)) {
|
||||||
updateProfile(this.gameProfile.getProperties());
|
this.npcPojo.setShouldSpawn(false);
|
||||||
setLocation(getNpcPojo().getLocation().toBukkitLocation(), false);
|
if (ConfigurationConstants.DEBUG_ENABLED) {
|
||||||
this.hologram.createHologram();
|
ZNPCsPlus.LOGGER.warning("The NPC Type " + npcPojo.getNpcType().name() + " does not exist or is not supported in this version.");
|
||||||
if (this.npcPojo.getPathName() != null)
|
}
|
||||||
setPath(NPCPath.AbstractTypeWriter.find(this.npcPojo.getPathName()));
|
} else {
|
||||||
this.npcPojo.getCustomizationMap().forEach((key, value) -> this.npcPojo.getNpcType().updateCustomization(this, key, value));
|
this.npcPojo.setShouldSpawn(true);
|
||||||
|
changeType(this.npcPojo.getNpcType());
|
||||||
|
updateProfile(this.gameProfile.getProperties());
|
||||||
|
setLocation(getNpcPojo().getLocation().toBukkitLocation(), false);
|
||||||
|
this.hologram.createHologram();
|
||||||
|
if (this.npcPojo.getPathName() != null)
|
||||||
|
setPath(NPCPath.AbstractTypeWriter.find(this.npcPojo.getPathName()));
|
||||||
|
this.npcPojo.getCustomizationMap().forEach((key, value) -> this.npcPojo.getNpcType().updateCustomization(this, key, value));
|
||||||
|
}
|
||||||
NPC_MAP.put(getNpcPojo().getId(), this);
|
NPC_MAP.put(getNpcPojo().getId(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,6 +222,9 @@ public class NPC {
|
||||||
if (this.viewers.contains(user)) {
|
if (this.viewers.contains(user)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!getNpcPojo().getShouldSpawn()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
this.viewers.add(user);
|
this.viewers.add(user);
|
||||||
boolean npcIsPlayer = (this.npcPojo.getNpcType() == NPCType.PLAYER);
|
boolean npcIsPlayer = (this.npcPojo.getNpcType() == NPCType.PLAYER);
|
||||||
|
|
|
@ -19,6 +19,7 @@ public class NPCModel {
|
||||||
private ConversationModel conversation;
|
private ConversationModel conversation;
|
||||||
private ZLocation location;
|
private ZLocation location;
|
||||||
private NPCType npcType;
|
private NPCType npcType;
|
||||||
|
private boolean shouldSpawn;
|
||||||
private List<String> hologramLines;
|
private List<String> hologramLines;
|
||||||
private List<NPCAction> clickActions;
|
private List<NPCAction> clickActions;
|
||||||
private Map<EquipmentSlot, ItemStack> npcEquip;
|
private Map<EquipmentSlot, ItemStack> npcEquip;
|
||||||
|
@ -31,6 +32,7 @@ public class NPCModel {
|
||||||
this.skin = "";
|
this.skin = "";
|
||||||
this.signature = "";
|
this.signature = "";
|
||||||
this.npcType = NPCType.PLAYER;
|
this.npcType = NPCType.PLAYER;
|
||||||
|
this.shouldSpawn = true;
|
||||||
this.hologramLines = Collections.singletonList("/znpcs lines");
|
this.hologramLines = Collections.singletonList("/znpcs lines");
|
||||||
this.clickActions = new ArrayList<>();
|
this.clickActions = new ArrayList<>();
|
||||||
this.npcEquip = new HashMap<>();
|
this.npcEquip = new HashMap<>();
|
||||||
|
@ -178,6 +180,19 @@ public class NPCModel {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getShouldSpawn() {
|
||||||
|
return this.shouldSpawn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShouldSpawn(boolean shouldSpawn) {
|
||||||
|
this.shouldSpawn = shouldSpawn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NPCModel withShouldSpawn(boolean shouldSpawn) {
|
||||||
|
setShouldSpawn(shouldSpawn);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public List<NPCAction> getClickActions() {
|
public List<NPCAction> getClickActions() {
|
||||||
return this.clickActions;
|
return this.clickActions;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue