mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-26 08:03:06 +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
@@ -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