Auto Format code

This commit is contained in:
modmuss50 2016-10-08 20:46:16 +01:00
parent 112b1657cf
commit 796df6c055
No known key found for this signature in database
GPG key ID: 773D17BE8BF49C82
503 changed files with 12260 additions and 16291 deletions

View file

@ -14,38 +14,29 @@ import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.TreeMap;
public class IDSUManager
{
public class IDSUManager {
public static final String savename = "idsu.json";
public static IDSUManager INSTANCE;
public HashMap<World, IDSUWorldSaveData> worldData = new HashMap<>();
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void worldSave(WorldEvent.Save event)
{
public void worldSave(WorldEvent.Save event) {
if (event.getWorld() != null && event.getWorld().getSaveHandler() != null
&& event.getWorld().getSaveHandler().getWorldDirectory() != null)
{
if (worldData.containsKey(event.getWorld()))
{
&& event.getWorld().getSaveHandler().getWorldDirectory() != null) {
if (worldData.containsKey(event.getWorld())) {
worldData.get(event.getWorld()).save();
}
}
}
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void worldLoad(WorldEvent.Load event)
{
public void worldLoad(WorldEvent.Load event) {
if (event.getWorld() != null && event.getWorld().getSaveHandler() != null
&& event.getWorld().getSaveHandler().getWorldDirectory() != null)
{
if (worldData.containsKey(event.getWorld()))
{
&& event.getWorld().getSaveHandler().getWorldDirectory() != null) {
if (worldData.containsKey(event.getWorld())) {
worldData.get(event.getWorld()).load();
} else
{
} else {
IDSUWorldSaveData worldSaveData = new IDSUWorldSaveData(event.getWorld());
worldData.put(event.getWorld(), worldSaveData);
worldSaveData.load();
@ -54,13 +45,10 @@ public class IDSUManager
}
@SubscribeEvent(priority = EventPriority.LOWEST)
public void worldClosed(WorldEvent.Unload event)
{
public void worldClosed(WorldEvent.Unload event) {
if (event.getWorld() != null && event.getWorld().getSaveHandler() != null
&& event.getWorld().getSaveHandler().getWorldDirectory() != null)
{
if (worldData.containsKey(event.getWorld()))
{
&& event.getWorld().getSaveHandler().getWorldDirectory() != null) {
if (worldData.containsKey(event.getWorld())) {
worldData.get(event.getWorld()).save();
}
}
@ -68,13 +56,10 @@ public class IDSUManager
worldData.clear();
}
public IDSUValueSaveData getSaveDataForWorld(World world, String channel)
{
if (worldData.containsKey(world))
{
public IDSUValueSaveData getSaveDataForWorld(World world, String channel) {
if (worldData.containsKey(world)) {
return worldData.get(world).getSaves(channel);
} else
{
} else {
IDSUWorldSaveData worldSaveData = new IDSUWorldSaveData(world);
worldData.put(world, worldSaveData);
worldSaveData.load();
@ -82,13 +67,10 @@ public class IDSUManager
}
}
public IDSUWorldSaveData getWorldDataFormWorld(World world)
{
if (worldData.containsKey(world))
{
public IDSUWorldSaveData getWorldDataFormWorld(World world) {
if (worldData.containsKey(world)) {
return worldData.get(world);
} else
{
} else {
IDSUWorldSaveData worldSaveData = new IDSUWorldSaveData(world);
worldData.put(world, worldSaveData);
worldSaveData.load();
@ -96,31 +78,25 @@ public class IDSUManager
}
}
public void loadFromString(String json, World world)
{
if (json.equals("EMPTY"))
{
public void loadFromString(String json, World world) {
if (json.equals("EMPTY")) {
return;
}
IDSUWorldSaveData worldSaveData;
if (worldData.containsKey(world))
{
if (worldData.containsKey(world)) {
worldSaveData = worldData.get(world);
} else
{
} else {
worldSaveData = new IDSUWorldSaveData(world);
worldData.put(world, worldSaveData);
}
Gson gson = new Gson();
Type typeOfHashMap = new TypeToken<TreeMap<Integer, IDSUValueSaveData>>()
{
Type typeOfHashMap = new TypeToken<TreeMap<Integer, IDSUValueSaveData>>() {
}.getType();
worldSaveData.idsuValues.clear();
worldSaveData.idsuValues = gson.fromJson(json, typeOfHashMap);
}
public class IDSUWorldSaveData
{
public class IDSUWorldSaveData {
public TreeMap<String, IDSUValueSaveData> idsuValues = new TreeMap<>();
@ -132,114 +108,90 @@ public class IDSUManager
File file;
public IDSUWorldSaveData(World world)
{
public IDSUWorldSaveData(World world) {
this.world = world;
this.saveHandler = world.getSaveHandler();
folder = new File(saveHandler.getWorldDirectory(), "idsuData");
file = new File(folder, savename);
}
public IDSUValueSaveData getSaves(String udid)
{
if (udid == null)
{
public IDSUValueSaveData getSaves(String udid) {
if (udid == null) {
return null;
}
if (idsuValues.containsKey(udid))
{
if (idsuValues.containsKey(udid)) {
return idsuValues.get(udid);
} else
{
} else {
IDSUValueSaveData data = new IDSUValueSaveData();
idsuValues.put(udid, data);
return data;
}
}
public void load()
{
if (!file.exists())
{
public void load() {
if (!file.exists()) {
return;
}
try
{
try {
Gson gson = new Gson();
BufferedReader reader = new BufferedReader(new FileReader(file));
Type typeOfHashMap = new TypeToken<TreeMap<String, IDSUValueSaveData>>()
{
Type typeOfHashMap = new TypeToken<TreeMap<String, IDSUValueSaveData>>() {
}.getType();
idsuValues.clear();
idsuValues = gson.fromJson(reader, typeOfHashMap);
} catch (Exception e)
{
} catch (Exception e) {
e.printStackTrace();
}
}
public void save()
{
if (idsuValues.isEmpty())
{
public void save() {
if (idsuValues.isEmpty()) {
return;
}
if (!file.exists())
{
if (!folder.exists())
{
if (!file.exists()) {
if (!folder.exists()) {
folder.mkdirs();
}
try
{
try {
file.createNewFile();
} catch (IOException e)
{
} catch (IOException e) {
e.printStackTrace();
}
}
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String json = gson.toJson(idsuValues);
try
{
try {
FileWriter writer = new FileWriter(file);
writer.write(json);
writer.close();
} catch (IOException e)
{
} catch (IOException e) {
e.printStackTrace();
}
}
}
public class IDSUValueSaveData
{
public class IDSUValueSaveData {
public double storedPower = 0;
public IDSUValueSaveData(double storedPower)
{
public IDSUValueSaveData(double storedPower) {
this.storedPower = storedPower;
}
public IDSUValueSaveData()
{
public IDSUValueSaveData() {
}
public double getStoredPower()
{
public double getStoredPower() {
return storedPower;
}
public void setStoredPower(double storedPower)
{
public void setStoredPower(double storedPower) {
this.storedPower = storedPower;
}
public void addEnergy(double storedPower)
{
public void addEnergy(double storedPower) {
this.storedPower += storedPower;
}
}

View file

@ -1,18 +1,17 @@
package techreborn.tiles.idsu;
import reborncore.common.IWrenchable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import org.apache.commons.lang3.StringUtils;
import reborncore.api.power.EnumPowerTier;
import reborncore.common.IWrenchable;
import reborncore.common.powerSystem.TilePowerAcceptor;
import techreborn.config.ConfigTechReborn;
import techreborn.init.ModBlocks;
public class TileIDSU extends TilePowerAcceptor implements IWrenchable
{
public class TileIDSU extends TilePowerAcceptor implements IWrenchable {
public String ownerUdid;
public int tier;
@ -22,124 +21,102 @@ public class TileIDSU extends TilePowerAcceptor implements IWrenchable
private double euChange;
private int ticks;
public TileIDSU(int tier1, int output1, int maxStorage1)
{
public TileIDSU(int tier1, int output1, int maxStorage1) {
super(tier1);
this.tier = tier1;
this.output = output1;
this.maxStorage = maxStorage1;
}
public TileIDSU()
{
public TileIDSU() {
this(5, 2048, 100000000);
}
@Override
public double getEnergy()
{
if (ownerUdid == null && StringUtils.isBlank(ownerUdid) || StringUtils.isEmpty(ownerUdid))
{
public double getEnergy() {
if (ownerUdid == null && StringUtils.isBlank(ownerUdid) || StringUtils.isEmpty(ownerUdid)) {
return 0.0;
}
return IDSUManager.INSTANCE.getSaveDataForWorld(worldObj, ownerUdid).storedPower;
}
@Override
public void setEnergy(double energy)
{
if (ownerUdid == null && StringUtils.isBlank(ownerUdid) || StringUtils.isEmpty(ownerUdid))
{
public void setEnergy(double energy) {
if (ownerUdid == null && StringUtils.isBlank(ownerUdid) || StringUtils.isEmpty(ownerUdid)) {
return;
}
IDSUManager.INSTANCE.getSaveDataForWorld(worldObj, ownerUdid).storedPower = energy;
}
@Override
public void readFromNBTWithoutCoords(NBTTagCompound tag)
{
public void readFromNBTWithoutCoords(NBTTagCompound tag) {
}
@Override
public double getMaxPower()
{
public double getMaxPower() {
return 1000000000;
}
@Override
public boolean canAcceptEnergy(EnumFacing direction)
{
public boolean canAcceptEnergy(EnumFacing direction) {
return getFacingEnum() != direction;
}
@Override
public boolean canProvideEnergy(EnumFacing direction)
{
public boolean canProvideEnergy(EnumFacing direction) {
return getFacingEnum() == direction;
}
@Override
public double getMaxOutput()
{
public double getMaxOutput() {
return output;
}
@Override
public double getMaxInput()
{
public double getMaxInput() {
return maxStorage;
}
@Override
public EnumPowerTier getTier()
{
public EnumPowerTier getTier() {
return EnumPowerTier.EXTREME;
}
public float getChargeLevel()
{
public float getChargeLevel() {
float ret = (float) this.getEnergy() / (float) this.maxStorage;
if (ret > 1.0F)
{
if (ret > 1.0F) {
ret = 1.0F;
}
return ret;
}
public void readFromNBT(NBTTagCompound nbttagcompound)
{
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
this.ownerUdid = nbttagcompound.getString("ownerUdid");
}
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound)
{
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
if (ownerUdid == null && StringUtils.isBlank(ownerUdid) || StringUtils.isEmpty(ownerUdid))
{
if (ownerUdid == null && StringUtils.isBlank(ownerUdid) || StringUtils.isEmpty(ownerUdid)) {
return nbttagcompound;
}
nbttagcompound.setString("ownerUdid", this.ownerUdid);
return nbttagcompound;
}
public void updateEntity()
{
public void updateEntity() {
super.updateEntity();
if (ticks == ConfigTechReborn.AverageEuOutTickTime)
{
if (ticks == ConfigTechReborn.AverageEuOutTickTime) {
euChange = -1;
ticks = 0;
} else
{
} else {
ticks++;
euChange += getEnergy() - euLastTick;
if (euLastTick == getEnergy())
{
if (euLastTick == getEnergy()) {
euChange = 0;
}
}
@ -148,40 +125,37 @@ public class TileIDSU extends TilePowerAcceptor implements IWrenchable
boolean needsInvUpdate = false;
if (needsInvUpdate)
{
if (needsInvUpdate) {
this.markDirty();
}
}
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side)
{
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) {
return false;
}
@Override public boolean wrenchCanSetFacing(EntityPlayer p0, EnumFacing p1)
{
@Override
public boolean wrenchCanSetFacing(EntityPlayer p0, EnumFacing p1) {
return true;
}
@Override public EnumFacing getFacing()
{
@Override
public EnumFacing getFacing() {
return getFacingEnum();
}
@Override public boolean wrenchCanRemove(EntityPlayer p0)
{
@Override
public boolean wrenchCanRemove(EntityPlayer p0) {
return true;
}
@Override public float getWrenchDropRate()
{
@Override
public float getWrenchDropRate() {
return 1.0F;
}
public ItemStack getWrenchDrop(EntityPlayer entityPlayer)
{
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
NBTTagCompound tileEntity = new NBTTagCompound();
ItemStack dropStack = new ItemStack(ModBlocks.Idsu, 1);
writeToNBT(tileEntity);
@ -190,39 +164,30 @@ public class TileIDSU extends TilePowerAcceptor implements IWrenchable
return dropStack;
}
public double getEuChange()
{
if (euChange == -1)
{
public double getEuChange() {
if (euChange == -1) {
return -1;
}
return (euChange / ticks);
}
public void handleGuiInputFromClient(int id)
{
if (id == 0)
{
public void handleGuiInputFromClient(int id) {
if (id == 0) {
output += 256;
}
if (id == 1)
{
if (id == 1) {
output += 64;
}
if (id == 2)
{
if (id == 2) {
output -= 64;
}
if (id == 3)
{
if (id == 3) {
output -= 256;
}
if (output > 4096)
{
if (output > 4096) {
output = 4096;
}
if (output <= -1)
{
if (output <= -1) {
output = 0;
}
}