use of micdoodle8.mods.galacticraft.core.dimension.SpaceStationWorldData in project Galacticraft by micdoodle8.
the class CommandSpaceStationAddOwner method processCommand.
@Override
public void processCommand(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(), true);
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> ownedStations : stats.getSpaceStationDimensionData().entrySet()) {
final SpaceStationWorldData data = SpaceStationWorldData.getStationData(playerBase.worldObj, ownedStations.getValue(), playerBase);
if (var3.equalsIgnoreCase("+all")) {
data.setAllowedAll(true);
playerBase.addChatMessage(new ChatComponentText(GCCoreUtil.translateWithFormat("gui.spacestation.allow_all_true")));
return;
}
if (var3.equalsIgnoreCase("-all")) {
data.setAllowedAll(false);
playerBase.addChatMessage(new ChatComponentText(GCCoreUtil.translateWithFormat("gui.spacestation.allow_all_false", var3)));
return;
}
if (!data.getAllowedPlayers().contains(var3)) {
data.getAllowedPlayers().add(var3);
data.markDirty();
}
}
}
final EntityPlayerMP playerToAdd = PlayerUtil.getPlayerBaseServerFromPlayerUsername(var3, true);
if (playerToAdd != null) {
playerToAdd.addChatMessage(new ChatComponentText(GCCoreUtil.translateWithFormat("gui.spacestation.added", PlayerUtil.getName(playerBase))));
}
}
} catch (final Exception var6) {
throw new CommandException(var6.getMessage(), new Object[0]);
}
} else {
throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.ssinvite.wrong_usage", this.getCommandUsage(sender)), new Object[0]);
}
if (playerBase != null) {
playerBase.addChatMessage(new ChatComponentText(GCCoreUtil.translateWithFormat("gui.spacestation.addsuccess", var3)));
}
}
use of micdoodle8.mods.galacticraft.core.dimension.SpaceStationWorldData in project Galacticraft by micdoodle8.
the class CommandSpaceStationRemoveOwner method processCommand.
@Override
public void processCommand(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.worldObj, 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.getCommandUsage(sender)), new Object[0]);
}
if (playerBase != null) {
playerBase.addChatMessage(new ChatComponentText(GCCoreUtil.translateWithFormat("gui.spacestation.removesuccess", var3)));
}
}
use of micdoodle8.mods.galacticraft.core.dimension.SpaceStationWorldData in project Galacticraft by micdoodle8.
the class WorldUtil method bindSpaceStationToNewDimension.
public static SpaceStationWorldData bindSpaceStationToNewDimension(World world, EntityPlayerMP player, int homePlanetID) {
int dynamicProviderID = -1;
int staticProviderID = -1;
for (Satellite satellite : GalaxyRegistry.getRegisteredSatellites().values()) {
if (satellite.getParentPlanet().getDimensionID() == homePlanetID) {
dynamicProviderID = satellite.getDimensionID();
staticProviderID = satellite.getDimensionIdStatic();
}
}
if (dynamicProviderID == -1 || staticProviderID == -1) {
throw new RuntimeException("Space station being bound on bad provider IDs!");
}
int newID = DimensionManager.getNextFreeDimId();
SpaceStationWorldData data = WorldUtil.createSpaceStation(world, newID, homePlanetID, dynamicProviderID, staticProviderID, player);
dimNames.put(newID, "Space Station " + newID);
GCPlayerStats stats = GCPlayerStats.get(player);
stats.getSpaceStationDimensionData().put(homePlanetID, newID);
GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_UPDATE_SPACESTATION_CLIENT_ID, GCCoreUtil.getDimensionID(player.worldObj), new Object[] { WorldUtil.spaceStationDataToString(stats.getSpaceStationDimensionData()) }), player);
return data;
}
use of micdoodle8.mods.galacticraft.core.dimension.SpaceStationWorldData in project Galacticraft by micdoodle8.
the class SpaceStationWorldData method getStationData.
/**
* Retrieve a space station data entry, creating if necessary (with provided data)
*/
public static SpaceStationWorldData getStationData(World world, int stationID, int homeID, int providerIdDynamic, int providerIdStatic, EntityPlayer owner) {
int providerType = DimensionManager.getProviderType(stationID);
boolean foundMatch = false;
// being called on an incorrect
for (Satellite satellite : GalaxyRegistry.getRegisteredSatellites().values()) {
if (satellite.getDimensionIdStatic() == providerType || satellite.getDimensionID() == providerType) {
foundMatch = true;
break;
}
}
if (!foundMatch) {
return null;
} else {
final String stationIdentifier = SpaceStationWorldData.getSpaceStationID(stationID);
SpaceStationWorldData stationData = (SpaceStationWorldData) world.loadItemData(SpaceStationWorldData.class, Constants.GCDATAFOLDER + stationIdentifier);
if (stationData == null) {
stationData = new SpaceStationWorldData(stationIdentifier);
world.setItemData(Constants.GCDATAFOLDER + stationIdentifier, stationData);
stationData.dataCompound = new NBTTagCompound();
if (owner != null) {
stationData.owner = PlayerUtil.getName(owner).replace(".", "");
}
stationData.spaceStationName = "Station: " + stationData.owner;
if (owner != null) {
stationData.allowedPlayers.add(PlayerUtil.getName(owner));
}
if (homeID == -1) {
throw new RuntimeException("Space station being created on bad home planet ID!");
} else {
stationData.homePlanet = homeID;
}
if (providerIdDynamic == -1 || providerIdStatic == -1) {
throw new RuntimeException("Space station being created on bad provider IDs!");
} else {
stationData.dimensionIdDynamic = providerIdDynamic;
stationData.dimensionIdStatic = providerIdStatic;
}
stationData.markDirty();
}
if (stationData.getSpaceStationName().replace(" ", "").isEmpty()) {
stationData.setSpaceStationName("Station: " + stationData.owner);
stationData.markDirty();
}
return stationData;
}
}
use of micdoodle8.mods.galacticraft.core.dimension.SpaceStationWorldData in project Galacticraft by micdoodle8.
the class CommandSpaceStationChangeOwner method processCommand.
@Override
public void processCommand(ICommandSender icommandsender, String[] astring) throws CommandException {
String oldOwner = null;
String newOwner = "ERROR";
int stationID = -1;
EntityPlayerMP playerAdmin = PlayerUtil.getPlayerBaseServerFromPlayerUsername(icommandsender.getName(), true);
if (astring.length > 1) {
newOwner = astring[1];
try {
stationID = Integer.parseInt(astring[0]);
} catch (final Exception var6) {
throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.ssnewowner.wrong_usage", this.getCommandUsage(icommandsender)), new Object[0]);
}
if (stationID < 2) {
throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.ssnewowner.wrong_usage", this.getCommandUsage(icommandsender)), new Object[0]);
}
try {
SpaceStationWorldData stationData = SpaceStationWorldData.getMPSpaceStationData(null, stationID, null);
if (stationData == null) {
throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.ssnewowner.wrong_usage", this.getCommandUsage(icommandsender)), 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.worldObj), 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.worldObj), 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.getCommandUsage(icommandsender)), new Object[0]);
}
if (playerAdmin != null) {
playerAdmin.addChatMessage(new ChatComponentText(GCCoreUtil.translateWithFormat("gui.spacestation.changesuccess", oldOwner, newOwner)));
} else // Console
{
System.out.println(GCCoreUtil.translateWithFormat("gui.spacestation.changesuccess", oldOwner, newOwner));
}
}
Aggregations