use of micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats in project Galacticraft by micdoodle8.
the class CommandSpaceStationChangeOwner method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
String oldOwner = null;
String newOwner = "ERROR";
int stationID = -1;
EntityPlayerMP playerAdmin = PlayerUtil.getPlayerBaseServerFromPlayerUsername(sender.getName(), true);
if (args.length > 1) {
newOwner = args[1];
try {
stationID = Integer.parseInt(args[0]);
} catch (final Exception var6) {
throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.ssnewowner.wrong_usage", this.getUsage(sender)), new Object[0]);
}
if (stationID < 2) {
throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.ssnewowner.wrong_usage", this.getUsage(sender)), new Object[0]);
}
try {
SpaceStationWorldData stationData = SpaceStationWorldData.getMPSpaceStationData(null, stationID, null);
if (stationData == null) {
throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.ssnewowner.wrong_usage", this.getUsage(sender)), new Object[0]);
}
oldOwner = stationData.getOwner();
stationData.getAllowedPlayers().remove(oldOwner);
if (stationData.getSpaceStationName().equals("Station: " + oldOwner)) {
stationData.setSpaceStationName("Station: " + newOwner);
}
stationData.getAllowedPlayers().add(newOwner);
stationData.setOwner(newOwner);
final EntityPlayerMP oldPlayer = PlayerUtil.getPlayerBaseServerFromPlayerUsername(oldOwner, true);
final EntityPlayerMP newPlayer = PlayerUtil.getPlayerBaseServerFromPlayerUsername(newOwner, true);
if (oldPlayer != null) {
GCPlayerStats stats = GCPlayerStats.get(oldPlayer);
SpaceStationWorldData.updateSSOwnership(oldPlayer, oldOwner, stats, stationID, stationData);
GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_UPDATE_SPACESTATION_CLIENT_ID, GCCoreUtil.getDimensionID(oldPlayer.world), new Object[] { WorldUtil.spaceStationDataToString(stats.getSpaceStationDimensionData()) }), oldPlayer);
}
if (newPlayer != null) {
GCPlayerStats stats = GCPlayerStats.get(newPlayer);
SpaceStationWorldData.updateSSOwnership(newPlayer, newOwner.replace(".", ""), stats, stationID, stationData);
GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_UPDATE_SPACESTATION_CLIENT_ID, GCCoreUtil.getDimensionID(oldPlayer.world), new Object[] { WorldUtil.spaceStationDataToString(stats.getSpaceStationDimensionData()) }), newPlayer);
}
} catch (final Exception var6) {
throw new CommandException(var6.getMessage(), new Object[0]);
}
} else {
throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.ssinvite.wrong_usage", this.getUsage(sender)), new Object[0]);
}
if (playerAdmin != null) {
playerAdmin.sendMessage(new TextComponentString(GCCoreUtil.translateWithFormat("gui.spacestation.changesuccess", oldOwner, newOwner)));
} else // Console
{
System.out.println(GCCoreUtil.translateWithFormat("gui.spacestation.changesuccess", oldOwner, newOwner));
}
}
use of micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats in project Galacticraft by micdoodle8.
the class CommandSpaceStationRemoveOwner method getPlayers.
protected String[] getPlayers(MinecraftServer server, ICommandSender sender) {
EntityPlayerMP playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(sender.getName(), false);
if (playerBase != null) {
GCPlayerStats stats = GCPlayerStats.get(playerBase);
if (!stats.getSpaceStationDimensionData().isEmpty()) {
String[] allNames = server.getOnlinePlayerNames();
// data.getAllowedPlayers may include some in lowercase
// Convert to correct case at least for those players who are online
HashSet<String> allowedNames = Sets.newHashSet();
for (Map.Entry<Integer, Integer> e : stats.getSpaceStationDimensionData().entrySet()) {
final SpaceStationWorldData data = SpaceStationWorldData.getStationData(playerBase.world, e.getValue(), playerBase);
allowedNames.addAll(data.getAllowedPlayers());
}
Iterator<String> itName = allowedNames.iterator();
ArrayList<String> replaceNames = new ArrayList<String>();
while (itName.hasNext()) {
String name = itName.next();
for (String allEntry : allNames) {
if (name.equalsIgnoreCase(allEntry)) {
itName.remove();
replaceNames.add(allEntry);
}
}
}
// This does the conversion to correct case
allowedNames.addAll(replaceNames);
String[] rvsize = new String[allowedNames.size()];
return allowedNames.toArray(rvsize);
}
}
String[] returnvalue = { "" };
return returnvalue;
}
use of micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats in project Galacticraft by micdoodle8.
the class CommandSpaceStationRemoveOwner method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
String var3 = null;
EntityPlayerMP playerBase = null;
if (args.length > 0) {
var3 = args[0];
try {
playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(sender.getName(), false);
if (playerBase != null) {
GCPlayerStats stats = GCPlayerStats.get(playerBase);
if (stats.getSpaceStationDimensionData().isEmpty()) {
throw new WrongUsageException(GCCoreUtil.translate("commands.ssinvite.not_found"), new Object[0]);
} else {
for (Map.Entry<Integer, Integer> e : stats.getSpaceStationDimensionData().entrySet()) {
final SpaceStationWorldData data = SpaceStationWorldData.getStationData(playerBase.world, e.getValue(), playerBase);
String str = null;
for (String name : data.getAllowedPlayers()) {
if (name.equalsIgnoreCase(var3)) {
str = name;
break;
}
}
if (str != null) {
data.getAllowedPlayers().remove(str);
data.markDirty();
} else {
throw new CommandException(GCCoreUtil.translateWithFormat("commands.ssuninvite.no_player", "\"" + var3 + "\""), new Object[0]);
}
}
}
}
} catch (final Exception var6) {
throw new CommandException(var6.getMessage(), new Object[0]);
}
} else {
throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.ssinvite.wrong_usage", this.getUsage(sender)), new Object[0]);
}
if (playerBase != null) {
playerBase.sendMessage(new TextComponentString(GCCoreUtil.translateWithFormat("gui.spacestation.removesuccess", var3)));
}
}
use of micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats in project Galacticraft by micdoodle8.
the class CommandGCAstroMiner method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (args.length > 2) {
throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.dimensiontp.too_many", this.getUsage(sender)), new Object[0]);
}
if (args.length < 1) {
throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.ssinvite.wrong_usage", this.getUsage(sender)), new Object[0]);
}
int type = 0;
int newvalue = 0;
if (args[0].equalsIgnoreCase("show")) {
type = 1;
} else if (args[0].equalsIgnoreCase("reset")) {
type = 2;
} else if (args[0].length() > 3 && args[0].substring(0, 3).equalsIgnoreCase("set")) {
String number = args[0].substring(3);
try {
newvalue = Integer.parseInt(number);
if (newvalue > 0) {
type = 3;
}
} catch (NumberFormatException ex) {
}
}
// Proceed if syntax of show|reset|set<number> was correct
if (type > 0) {
EntityPlayerMP playerBase = null;
try {
if (args.length == 2) {
playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(args[1], true);
} else {
playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(sender.getName(), true);
}
if (playerBase != null) {
GCPlayerStats stats = GCPlayerStats.get(playerBase);
switch(type) {
case 1:
sender.sendMessage(new TextComponentString(GCCoreUtil.translateWithFormat("command.gcastrominer.count", PlayerUtil.getName(playerBase), "" + stats.getAstroMinerCount())));
break;
case 2:
stats.setAstroMinerCount(0);
sender.sendMessage(new TextComponentString(GCCoreUtil.translateWithFormat("command.gcastrominer.count", PlayerUtil.getName(playerBase), "" + 0)));
break;
case 3:
stats.setAstroMinerCount(newvalue);
sender.sendMessage(new TextComponentString(GCCoreUtil.translateWithFormat("command.gcastrominer.count", PlayerUtil.getName(playerBase), "" + newvalue)));
break;
}
} else {
throw new Exception("Could not find player with name: " + args[1]);
}
} catch (final Exception e) {
throw new CommandException(e.getMessage(), new Object[0]);
}
return;
}
}
use of micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats in project Galacticraft by micdoodle8.
the class OxygenUtil method hasValidOxygenSetup.
public static boolean hasValidOxygenSetup(EntityPlayerMP player) {
boolean missingComponent = false;
GCPlayerStats stats = GCPlayerStats.get(player);
if (!OxygenUtil.isItemValidForPlayerTankInv(0, stats.getExtendedInventory().getStackInSlot(0))) {
boolean handled = false;
for (final ItemStack armorStack : player.inventory.armorInventory) {
if (!armorStack.isEmpty() && armorStack.getItem() instanceof IBreathableArmor) {
final IBreathableArmor breathableArmor = (IBreathableArmor) armorStack.getItem();
if (breathableArmor.handleGearType(EnumGearType.HELMET)) {
if (breathableArmor.canBreathe(armorStack, player, EnumGearType.HELMET)) {
handled = true;
}
}
}
}
if (!handled) {
missingComponent = true;
}
}
if (!OxygenUtil.isItemValidForPlayerTankInv(1, stats.getExtendedInventory().getStackInSlot(1))) {
boolean handled = false;
for (final ItemStack armorStack : player.inventory.armorInventory) {
if (!armorStack.isEmpty() && armorStack.getItem() instanceof IBreathableArmor) {
final IBreathableArmor breathableArmor = (IBreathableArmor) armorStack.getItem();
if (breathableArmor.handleGearType(EnumGearType.GEAR)) {
if (breathableArmor.canBreathe(armorStack, player, EnumGearType.GEAR)) {
handled = true;
}
}
}
}
if (!handled) {
missingComponent = true;
}
}
if (!OxygenUtil.isItemValidForPlayerTankInv(2, stats.getExtendedInventory().getStackInSlot(2)) && !OxygenUtil.isItemValidForPlayerTankInv(3, stats.getExtendedInventory().getStackInSlot(3))) {
boolean handled = false;
for (final ItemStack armorStack : player.inventory.armorInventory) {
if (!armorStack.isEmpty() && armorStack.getItem() instanceof IBreathableArmor) {
final IBreathableArmor breathableArmor = (IBreathableArmor) armorStack.getItem();
if (breathableArmor.handleGearType(EnumGearType.TANK1)) {
if (breathableArmor.canBreathe(armorStack, player, EnumGearType.TANK1)) {
handled = true;
}
}
if (breathableArmor.handleGearType(EnumGearType.TANK2)) {
if (breathableArmor.canBreathe(armorStack, player, EnumGearType.TANK2)) {
handled = true;
}
}
}
}
if (!handled) {
missingComponent = true;
}
}
return !missingComponent;
}
Aggregations