Improve api a lot
This commit is contained in:
parent
9e920ecab1
commit
0052584507
9 changed files with 44 additions and 6 deletions
|
@ -1,6 +1,9 @@
|
|||
package lol.pyr.znpcsplus.api.entity;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface EntityPropertyRegistry {
|
||||
Collection<EntityProperty<?>> getAll();
|
||||
EntityProperty<?> getByName(String name);
|
||||
<T> EntityProperty<T> getByName(String name, Class<T> type);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,9 @@ import java.util.Collection;
|
|||
|
||||
public interface NpcRegistry {
|
||||
Collection<? extends NpcEntry> getAll();
|
||||
Collection<String> getIds();
|
||||
Collection<String> getAllIds();
|
||||
Collection<? extends NpcEntry> getAllPlayerMade();
|
||||
Collection<String> getAllPlayerMadeIds();
|
||||
NpcEntry create(String id, World world, NpcType type, NpcLocation location);
|
||||
NpcEntry get(String id);
|
||||
void delete(String id);
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package lol.pyr.znpcsplus.api.npc;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface NpcTypeRegistry {
|
||||
NpcType getByName(String name);
|
||||
Collection<NpcType> getAll();
|
||||
}
|
||||
|
|
|
@ -158,7 +158,7 @@ public class ZNpcsPlus extends JavaPlugin {
|
|||
World world = Bukkit.getWorld("world");
|
||||
if (world == null) world = Bukkit.getWorlds().get(0);
|
||||
int i = 0;
|
||||
for (NpcTypeImpl type : typeRegistry.getAll()) {
|
||||
for (NpcTypeImpl type : typeRegistry.getAllImpl()) {
|
||||
NpcEntryImpl entry = npcRegistry.create("debug_npc_" + i, world, type, new NpcLocation(i * 3, 200, 0, 0, 0));
|
||||
entry.setProcessed(true);
|
||||
NpcImpl npc = entry.getNpc();
|
||||
|
|
|
@ -42,7 +42,7 @@ public class CreateCommand implements CommandHandler {
|
|||
@Override
|
||||
public List<String> suggest(CommandContext context) throws CommandExecutionException {
|
||||
if (context.argSize() == 1) return context.suggestCollection(npcRegistry.getModifiableIds());
|
||||
if (context.argSize() == 2) return context.suggestStream(typeRegistry.getAll().stream().map(NpcTypeImpl::getName));
|
||||
if (context.argSize() == 2) return context.suggestStream(typeRegistry.getAllImpl().stream().map(NpcTypeImpl::getName));
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ public class TypeCommand implements CommandHandler {
|
|||
@Override
|
||||
public List<String> suggest(CommandContext context) throws CommandExecutionException {
|
||||
if (context.argSize() == 1) return context.suggestCollection(registry.getModifiableIds());
|
||||
if (context.argSize() == 2) return context.suggestStream(typeRegistry.getAll().stream().map(NpcTypeImpl::getName));
|
||||
if (context.argSize() == 2) return context.suggestStream(typeRegistry.getAllImpl().stream().map(NpcTypeImpl::getName));
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package lol.pyr.znpcsplus.entity;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.item.ItemStack;
|
||||
import lol.pyr.znpcsplus.api.entity.EntityProperty;
|
||||
import lol.pyr.znpcsplus.api.entity.EntityPropertyRegistry;
|
||||
import lol.pyr.znpcsplus.api.skin.SkinDescriptor;
|
||||
import lol.pyr.znpcsplus.entity.serializers.*;
|
||||
|
@ -8,8 +9,11 @@ import lol.pyr.znpcsplus.skin.cache.SkinCache;
|
|||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class EntityPropertyRegistryImpl implements EntityPropertyRegistry {
|
||||
|
@ -213,6 +217,14 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry {
|
|||
byName.put(name.toLowerCase(), property);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<EntityProperty<?>> getAll() {
|
||||
return Collections.unmodifiableCollection(
|
||||
byName.values().stream()
|
||||
.map(property -> (EntityProperty<?>) property)
|
||||
.collect(Collectors.toSet()));
|
||||
}
|
||||
|
||||
public <T> EntityPropertyImpl<T> getByName(String name, Class<T> type) {
|
||||
return (EntityPropertyImpl<T>) getByName(name);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package lol.pyr.znpcsplus.npc;
|
||||
|
||||
import lol.pyr.znpcsplus.ZNpcsPlus;
|
||||
import lol.pyr.znpcsplus.api.npc.NpcEntry;
|
||||
import lol.pyr.znpcsplus.api.npc.NpcRegistry;
|
||||
import lol.pyr.znpcsplus.api.npc.NpcType;
|
||||
import lol.pyr.znpcsplus.config.ConfigManager;
|
||||
|
@ -80,10 +81,22 @@ public class NpcRegistryImpl implements NpcRegistry {
|
|||
return getAll().stream().filter(entry -> entry.getNpc().getEntity().getEntityId() == id).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public Collection<String> getIds() {
|
||||
public Collection<String> getAllIds() {
|
||||
return Collections.unmodifiableSet(npcMap.keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends NpcEntry> getAllPlayerMade() {
|
||||
return getAllModifiable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getAllPlayerMadeIds() {
|
||||
return getAllModifiable().stream()
|
||||
.map(NpcEntryImpl::getId)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
public Collection<String> getModifiableIds() {
|
||||
return Collections.unmodifiableSet(npcMap.entrySet().stream()
|
||||
.filter(entry -> entry.getValue().isAllowCommandModification())
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.github.retrooper.packetevents.PacketEventsAPI;
|
|||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.protocol.entity.type.EntityType;
|
||||
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
|
||||
import lol.pyr.znpcsplus.api.npc.NpcType;
|
||||
import lol.pyr.znpcsplus.api.npc.NpcTypeRegistry;
|
||||
import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
@ -319,7 +320,11 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry {
|
|||
.setHologramOffset(0.25));
|
||||
}
|
||||
|
||||
public Collection<NpcTypeImpl> getAll() {
|
||||
public Collection<NpcType> getAll() {
|
||||
return Collections.unmodifiableList(types);
|
||||
}
|
||||
|
||||
public Collection<NpcTypeImpl> getAllImpl() {
|
||||
return Collections.unmodifiableList(types);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue