Spam fix for older versions

This commit is contained in:
Om Choksi 2023-04-23 19:38:23 +05:30
parent dff4d59fc0
commit c33ac8a1b1
No known key found for this signature in database
GPG Key ID: 5B5E07C43970B43B
5 changed files with 48 additions and 8 deletions

@ -84,6 +84,10 @@ public class DefaultCommand extends Command {
return;
}
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);
Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.SUCCESS);
}
@ -116,7 +120,13 @@ public class DefaultCommand extends Command {
sender.sendMessage(ChatColor.DARK_GREEN + "NPC list:");
for (NPCModel npcModel : ConfigurationConstants.NPC_LIST) {
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.setColor(ChatColor.GREEN);
parts.add(textComponent);

@ -7,6 +7,7 @@ import java.util.List;
public final class ConfigurationConstants {
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 SAVE_DELAY = Configuration.CONFIGURATION.<Integer>getValue(ConfigurationValue.SAVE_NPCS_DELAY_SECONDS);
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),
CANT_GET_SKIN("messages", "&cCould not fetch skin for name: %s.", 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);
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 io.github.retrooper.packetevents.util.SpigotConversionUtil;
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.nms.PacketCache;
import io.github.znetworkw.znpcservers.npc.conversation.ConversationModel;
@ -81,6 +83,13 @@ public class NPC {
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.getProperties().put("textures", new Property("textures", this.npcPojo.getSkin(), this.npcPojo.getSignature()));
if (this.npcPojo.getNpcType().getConstructor() == null && !this.npcPojo.getNpcType().equals(NPCType.PLAYER)) {
this.npcPojo.setShouldSpawn(false);
if (ConfigurationConstants.DEBUG_ENABLED) {
ZNPCsPlus.LOGGER.warning("The NPC Type " + npcPojo.getNpcType().name() + " does not exist or is not supported in this version.");
}
} else {
this.npcPojo.setShouldSpawn(true);
changeType(this.npcPojo.getNpcType());
updateProfile(this.gameProfile.getProperties());
setLocation(getNpcPojo().getLocation().toBukkitLocation(), false);
@ -88,6 +97,7 @@ public class NPC {
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);
}
@ -212,6 +222,9 @@ public class NPC {
if (this.viewers.contains(user)) {
return;
}
if (!getNpcPojo().getShouldSpawn()) {
return;
}
try {
this.viewers.add(user);
boolean npcIsPlayer = (this.npcPojo.getNpcType() == NPCType.PLAYER);

@ -19,6 +19,7 @@ public class NPCModel {
private ConversationModel conversation;
private ZLocation location;
private NPCType npcType;
private boolean shouldSpawn;
private List<String> hologramLines;
private List<NPCAction> clickActions;
private Map<EquipmentSlot, ItemStack> npcEquip;
@ -31,6 +32,7 @@ public class NPCModel {
this.skin = "";
this.signature = "";
this.npcType = NPCType.PLAYER;
this.shouldSpawn = true;
this.hologramLines = Collections.singletonList("/znpcs lines");
this.clickActions = new ArrayList<>();
this.npcEquip = new HashMap<>();
@ -178,6 +180,19 @@ public class NPCModel {
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() {
return this.clickActions;
}