Files
CodeChickenCore/src/codechicken/core/ServerUtils.java
T

65 lines
2.2 KiB
Java
Raw Normal View History

2014-04-29 00:35:55 +10:00
package codechicken.core;
import java.util.ArrayList;
import java.util.List;
2014-08-02 22:26:49 +10:00
import com.mojang.authlib.GameProfile;
2014-04-29 00:35:55 +10:00
import net.minecraft.server.MinecraftServer;
import net.minecraft.command.CommandHandler;
import net.minecraft.inventory.Container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.command.ICommand;
import net.minecraft.util.IChatComponent;
public class ServerUtils extends CommonUtils
{
public static MinecraftServer mc() {
return MinecraftServer.getServer();
}
public static EntityPlayerMP getPlayer(String playername) {
2014-06-29 20:38:07 +10:00
return mc().getConfigurationManager().func_152612_a(playername);
2014-04-29 00:35:55 +10:00
}
public static List<EntityPlayerMP> getPlayers() {
return mc().getConfigurationManager().playerEntityList;
}
public static ArrayList<EntityPlayer> getPlayersInDimension(int dimension) {
ArrayList<EntityPlayer> players = new ArrayList<EntityPlayer>();
for (EntityPlayer p : getPlayers())
if(p.dimension == dimension)
players.add(p);
return players;
}
public static void openSMPContainer(EntityPlayerMP player, Container container, IGuiPacketSender packetSender) {
player.getNextWindowId();
player.closeContainer();
packetSender.sendPacket(player, player.currentWindowId);
player.openContainer = container;
player.openContainer.windowId = player.currentWindowId;
player.openContainer.addCraftingToCrafters(player);
}
2014-08-02 22:26:49 +10:00
public static GameProfile getGameProfile(String username) {
return mc().func_152358_ax().func_152655_a(username);
}
2014-04-29 00:35:55 +10:00
public static boolean isPlayerOP(String username) {
2014-08-02 22:26:49 +10:00
GameProfile prof = getGameProfile(username);
if(prof == null) return false;
return mc().getConfigurationManager().func_152596_g(getGameProfile(username));
2014-04-29 00:35:55 +10:00
}
public static boolean isPlayerOwner(String username) {
return mc().isSinglePlayer() && mc().getServerOwner().equalsIgnoreCase(username);
}
public static void sendChatToAll(IChatComponent msg) {
for(EntityPlayer p : getPlayers())
p.addChatComponentMessage(msg);
}
}