mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-19 00:19:05 +00:00
NpcAPI:
-Added getPlayer() function -Added getChunkLoadingNPCs function -Added getCurrentPlayerCount, getMaxPlayers, and kickAllPlayers, isHardcore, getFile(path), and getServerOwner functions
This commit is contained in:
1 parent
e9a8f8cebc
commit
3fd962289c
6 files changed
+78
-18
No files matched your search
@@ -147,11 +147,11 @@ public class CmdConfig extends ChMcLogger {
|
||||
)
|
||||
public boolean chunkloaders(String[] args){
|
||||
if(args.length == 0){
|
||||
sendmessage("ChunkLoaders: " + ChunkController.instance.size() + "/" + CustomNpcs.ChuckLoaders);
|
||||
sendmessage("ChunkLoaders: " + ChunkController.instance.size() + "/" + CustomNpcs.ChunkLoaders);
|
||||
}
|
||||
else{
|
||||
try{
|
||||
CustomNpcs.ChuckLoaders = Integer.parseInt(args[0]);
|
||||
CustomNpcs.ChunkLoaders = Integer.parseInt(args[0]);
|
||||
}
|
||||
catch(NumberFormatException ex){
|
||||
sendmessage("Didnt get a number");
|
||||
@@ -160,11 +160,11 @@ public class CmdConfig extends ChMcLogger {
|
||||
CustomNpcs.Config.updateConfig();
|
||||
|
||||
int size = ChunkController.instance.size();
|
||||
if(size > CustomNpcs.ChuckLoaders){
|
||||
ChunkController.instance.unload(size - CustomNpcs.ChuckLoaders);
|
||||
sendmessage(size - CustomNpcs.ChuckLoaders + " chunksloaders unloaded");
|
||||
if(size > CustomNpcs.ChunkLoaders){
|
||||
ChunkController.instance.unload(size - CustomNpcs.ChunkLoaders);
|
||||
sendmessage(size - CustomNpcs.ChunkLoaders + " chunksloaders unloaded");
|
||||
}
|
||||
sendmessage("ChunkLoaders: " + ChunkController.instance.size() + "/" + CustomNpcs.ChuckLoaders);
|
||||
sendmessage("ChunkLoaders: " + ChunkController.instance.size() + "/" + CustomNpcs.ChunkLoaders);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ public class CustomNpcs {
|
||||
public static int EnchantStartId = 100;
|
||||
|
||||
@ConfigProp(info = "Number of chunk loading npcs that can be active at the same time")
|
||||
public static int ChuckLoaders = 20;
|
||||
public static int ChunkLoaders = 20;
|
||||
|
||||
@ConfigProp(info = "The maximum number of images any dialog can hold.")
|
||||
public static int DialogImageLimit = 10;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -16,16 +15,16 @@ import net.minecraftforge.common.ForgeChunkManager.Type;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.constants.EnumJobType;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.roles.JobChunkLoader;
|
||||
|
||||
public class ChunkController implements LoadingCallback{
|
||||
public static ChunkController instance;
|
||||
|
||||
private HashMap<Entity,Ticket> tickets = new HashMap<Entity,Ticket>();
|
||||
public HashMap<Entity,Ticket> tickets = new HashMap<Entity,Ticket>();
|
||||
|
||||
public ChunkController(){
|
||||
instance = this;
|
||||
}
|
||||
|
||||
public void clear(){
|
||||
tickets = new HashMap<Entity,Ticket>();
|
||||
}
|
||||
@@ -34,7 +33,7 @@ public class ChunkController implements LoadingCallback{
|
||||
Ticket ticket = tickets.get(npc);
|
||||
if(ticket != null)
|
||||
return ticket;
|
||||
if(size() >= CustomNpcs.ChuckLoaders)
|
||||
if(size() >= CustomNpcs.ChunkLoaders)
|
||||
return null;
|
||||
ticket = ForgeChunkManager.requestTicket(CustomNpcs.instance, npc.worldObj, Type.ENTITY);
|
||||
if(ticket == null)
|
||||
|
||||
@@ -11,6 +11,7 @@ import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.INpc;
|
||||
import net.minecraft.entity.monster.EntityMob;
|
||||
import net.minecraft.entity.passive.EntityAnimal;
|
||||
import net.minecraft.entity.passive.EntityTameable;
|
||||
@@ -56,6 +57,7 @@ import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class NpcAPI extends AbstractNpcAPI {
|
||||
private static final Map<Integer, ScriptWorld> worldCache = new LRUHashMap<>(10);
|
||||
@@ -74,7 +76,31 @@ public class NpcAPI extends AbstractNpcAPI {
|
||||
}
|
||||
|
||||
public void stopServer() {
|
||||
CustomNpcs.getServer().initiateShutdown();
|
||||
MinecraftServer.getServer().initiateShutdown();
|
||||
}
|
||||
|
||||
public int getCurrentPlayerCount() {
|
||||
return MinecraftServer.getServer().getConfigurationManager().getCurrentPlayerCount();
|
||||
}
|
||||
|
||||
public int getMaxPlayers() {
|
||||
return MinecraftServer.getServer().getConfigurationManager().getMaxPlayers();
|
||||
}
|
||||
|
||||
public void kickAllPlayers() {
|
||||
MinecraftServer.getServer().getConfigurationManager().removeAllPlayers();
|
||||
}
|
||||
|
||||
public boolean isHardcore() {
|
||||
return MinecraftServer.getServer().isHardcore();
|
||||
}
|
||||
|
||||
public File getFile(String path) {
|
||||
return MinecraftServer.getServer().getFile(path);
|
||||
}
|
||||
|
||||
public String getServerOwner() {
|
||||
return MinecraftServer.getServer().getServerOwner();
|
||||
}
|
||||
|
||||
public IFactionHandler getFactions() {
|
||||
@@ -146,6 +172,18 @@ public class NpcAPI extends AbstractNpcAPI {
|
||||
}
|
||||
}
|
||||
|
||||
public INpc[] getChunkLoadingNPCs() {
|
||||
ArrayList<INpc> list = new ArrayList<>();
|
||||
Set<Entity> npcSet = ChunkController.instance.tickets.keySet();
|
||||
for (Entity entity : npcSet) {
|
||||
if (entity instanceof EntityNPCInterface) {
|
||||
list.add((INpc) NpcAPI.Instance().getIEntity(entity));
|
||||
}
|
||||
}
|
||||
|
||||
return list.toArray(new INpc[0]);
|
||||
}
|
||||
|
||||
public IEntity<?>[] getLoadedEntities() {
|
||||
ArrayList<IEntity<?>> list = new ArrayList<>();
|
||||
|
||||
@@ -351,6 +389,15 @@ public class NpcAPI extends AbstractNpcAPI {
|
||||
return CustomNpcs.MARKOV_GENERATOR[dictionary].fetch(gender);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param username The username of the player to be returned
|
||||
* @return The Player with name. Null is returned when the player isn't found
|
||||
*/
|
||||
public IPlayer<?> getPlayer(String username) {
|
||||
EntityPlayerMP player = MinecraftServer.getServer().getConfigurationManager().func_152612_a(username);
|
||||
return player == null ? null : (IPlayer<?>) NpcAPI.Instance().getIEntity(player);
|
||||
}
|
||||
|
||||
public IPlayer<?>[] getAllServerPlayers(){
|
||||
List<?> list = MinecraftServer.getServer().getConfigurationManager().playerEntityList;
|
||||
IPlayer<?>[] arr = new IPlayer[list.size()];
|
||||
@@ -362,10 +409,7 @@ public class NpcAPI extends AbstractNpcAPI {
|
||||
}
|
||||
|
||||
public String[] getPlayerNames() {
|
||||
IPlayer<?>[] players = getAllServerPlayers();
|
||||
String[] names = new String[players.length];
|
||||
for (int i = 0; i < names.length; ++i) names[i] = players[i].getDisplayName();
|
||||
return names;
|
||||
return MinecraftServer.getServer().getConfigurationManager().getAllUsernames();
|
||||
}
|
||||
|
||||
public void playSoundAtEntity(IEntity<?> entity, String sound, float volume, float pitch){
|
||||
|
||||
@@ -608,9 +608,9 @@ public class ScriptWorld implements IWorld {
|
||||
return rayCastEntities(new double[] {startPos.getX(), startPos.getY(), startPos.getZ()}, lookVector.normalize(), maxDistance, offset, range, true, false, true);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
/**
|
||||
* @param name The name of the player to be returned
|
||||
* @return The Player with name. Null is returned when the player isnt found
|
||||
* Deprecated. Use NpcAPI.Instance().getPlayer(name) instead.
|
||||
*/
|
||||
public IPlayer getPlayer(String name){
|
||||
EntityPlayer player = world.getPlayerEntityByName(name);
|
||||
|
||||
@@ -11,6 +11,7 @@ import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.eventhandler.EventBus;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.INpc;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
@@ -51,6 +52,18 @@ public abstract class AbstractNpcAPI {
|
||||
|
||||
public abstract void stopServer();
|
||||
|
||||
public abstract int getCurrentPlayerCount();
|
||||
|
||||
public abstract int getMaxPlayers();
|
||||
|
||||
public abstract void kickAllPlayers();
|
||||
|
||||
public abstract boolean isHardcore();
|
||||
|
||||
public abstract File getFile(String path);
|
||||
|
||||
public abstract String getServerOwner();
|
||||
|
||||
public abstract IFactionHandler getFactions();
|
||||
|
||||
public abstract IRecipeHandler getRecipes();
|
||||
@@ -79,6 +92,10 @@ public abstract class AbstractNpcAPI {
|
||||
|
||||
public abstract IEntity<?> getIEntity(Entity var1);
|
||||
|
||||
public abstract IPlayer<?> getPlayer(String username);
|
||||
|
||||
public abstract INpc[] getChunkLoadingNPCs();
|
||||
|
||||
public abstract IEntity<?>[] getLoadedEntities();
|
||||
|
||||
public abstract IBlock getIBlock(IWorld world, int x, int y, int z);
|
||||
|
||||
Reference in new issue
Block a user