Various Updates #138

Merged
SenseiKiwi merged 20 commits from master into master 2014-03-06 06:23:16 +00:00
3 changed files with 112 additions and 46 deletions
Showing only changes of commit cd7cf4e7ca - Show all commits

View File

@@ -0,0 +1,102 @@
package StevenDimDoors.mod_pocketDim;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Random;
public class DeathTracker
{
private ArrayList<String> usernameList;
private HashSet<String> usernameSet;
private String filePath;
private boolean modified;
public DeathTracker(String filePath)
{
this.usernameList = new ArrayList<String>();
this.usernameSet = new HashSet<String>();
this.filePath = filePath;
this.modified = false;
readFromFile();
}
private void readFromFile()
{
try
{
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(filePath)));
for (String line = reader.readLine(); line != null; line = reader.readLine())
{
line = line.trim();
if (!line.isEmpty())
{
usernameSet.add(line);
}
}
reader.close();
}
catch (FileNotFoundException e) { }
catch (IOException e)
{
System.err.println("An unexpected exception occurred while trying to read DeathTracker data:");
System.err.println(e.toString());
}
usernameList.addAll(usernameSet);
}
public void writeToFile()
{
try
{
PrintWriter writer = new PrintWriter(filePath);
for (String username : usernameList)
{
writer.println(username);
}
writer.close();
modified = false;
}
catch (FileNotFoundException e)
{
System.err.println("An unexpected exception occurred while trying to read DeathTracker data:");
System.err.println(e.toString());
}
}
public boolean isModified()
{
return modified;
}
public boolean isEmpty()
{
return usernameList.isEmpty();
}
public String getRandomUsername(Random random)
{
if (usernameList.isEmpty())
{
throw new IllegalStateException("Cannot retrieve a random username from an empty list.");
}
return usernameList.get(random.nextInt(usernameList.size()));
}
public boolean addUsername(String username)
{
if (usernameSet.add(username))
{
usernameList.add(username);
modified = true;
return true;
}
return false;
}
}

View File

@@ -1,39 +0,0 @@
package StevenDimDoors.mod_pocketDim;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.common.network.ForgePacket;
import net.minecraftforge.common.network.packet.DimensionRegisterPacket;
import cpw.mods.fml.common.IPlayerTracker;
public class PlayerTracker implements IPlayerTracker
{
@Override
public void onPlayerLogin(EntityPlayer player)
{
}
@Override
public void onPlayerLogout(EntityPlayer player) {
// TODO Auto-generated method stub
}
@Override
public void onPlayerChangedDimension(EntityPlayer player) {
// TODO Auto-generated method stub
}
@Override
public void onPlayerRespawn(EntityPlayer player)
{
}
}

View File

@@ -134,9 +134,9 @@ public class mod_pocketDim
public static DDProperties properties;
public static CustomLimboPopulator spawner; //Added this field temporarily. Will be refactored out later.
public FastRiftRegenerator fastRiftRegenerator;
public static FastRiftRegenerator fastRiftRegenerator;
public static GatewayGenerator gatewayGenerator;
public static PlayerTracker tracker;
public static DeathTracker deathTracker;
public static CreativeTabs dimDoorsCreativeTab = new CreativeTabs("dimDoorsCreativeTab")
{
@@ -207,13 +207,10 @@ public class mod_pocketDim
itemStabilizedLinkSignature = (new ItemStabilizedRiftSignature(properties.StabilizedRiftSignatureItemID)).setUnlocalizedName("itemStabilizedRiftSig");
itemWorldThread = (new ItemWorldThread(properties.WorldThreadItemID)).setUnlocalizedName("itemWorldThread");
mod_pocketDim.limboBiome = (new BiomeGenLimbo(properties.LimboBiomeID));
mod_pocketDim.pocketBiome = (new BiomeGenPocket(properties.PocketBiomeID));
GameRegistry.registerWorldGenerator(mod_pocketDim.gatewayGenerator);
tracker = new PlayerTracker();
GameRegistry.registerPlayerTracker(tracker);
GameRegistry.registerBlock(goldenDoor, "Golden Door");
GameRegistry.registerBlock(goldenDimensionalDoor, "Golden Dimensional Door");
@@ -298,6 +295,8 @@ public class mod_pocketDim
try
{
PocketManager.unload();
deathTracker.writeToFile();
deathTracker = null;
}
catch (Exception e)
{
@@ -308,9 +307,9 @@ public class mod_pocketDim
@EventHandler
public void onServerStarting(FMLServerStartingEvent event)
{
//TODO- load dims with forced chunks on server startup here
// Register commands with the server
CommandResetDungeons.instance().register(event);
CommandCreateDungeonRift.instance().register(event);
CommandDeleteAllLinks.instance().register(event);
@@ -322,6 +321,10 @@ public class mod_pocketDim
CommandCreatePocket.instance().register(event);
CommandTeleportPlayer.instance().register(event);
// Initialize a new DeathTracker
String deathTrackerFile = DimensionManager.getCurrentSaveRootDirectory() + "/DimensionalDoors/data/deaths.txt";
deathTracker = new DeathTracker(deathTrackerFile);
try
{
ChunkLoaderHelper.loadChunkForcedWorlds(event);