Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Imported from mc-dev:

- WorldMapCollection
  • Loading branch information...
commit be105a7b2e8e46d4be32c58c730274d652dd3110 1 parent 5bee9cc
CelticMinstrel CelticMinstrel authored

Showing 1 changed file with 186 additions and 0 deletions. Show diff stats Hide diff stats

  1. +186 0 src/main/java/net/minecraft/server/WorldMapCollection.java
186 src/main/java/net/minecraft/server/WorldMapCollection.java
... ... @@ -0,0 +1,186 @@
  1 +package net.minecraft.server;
  2 +
  3 +import java.io.DataInput;
  4 +import java.io.DataInputStream;
  5 +import java.io.DataOutput;
  6 +import java.io.DataOutputStream;
  7 +import java.io.File;
  8 +import java.io.FileInputStream;
  9 +import java.io.FileOutputStream;
  10 +import java.io.InputStream;
  11 +import java.io.OutputStream;
  12 +import java.util.ArrayList;
  13 +import java.util.HashMap;
  14 +import java.util.Iterator;
  15 +import java.util.List;
  16 +import java.util.Map;
  17 +
  18 +public class WorldMapCollection {
  19 +
  20 + private IDataManager a;
  21 + private Map b = new HashMap();
  22 + private List c = new ArrayList();
  23 + private Map d = new HashMap();
  24 +
  25 + public WorldMapCollection(IDataManager idatamanager) {
  26 + this.a = idatamanager;
  27 + this.b();
  28 + }
  29 +
  30 + public WorldMapBase get(Class oclass, String s) {
  31 + WorldMapBase worldmapbase = (WorldMapBase) this.b.get(s);
  32 +
  33 + if (worldmapbase != null) {
  34 + return worldmapbase;
  35 + } else {
  36 + if (this.a != null) {
  37 + try {
  38 + File file1 = this.a.getDataFile(s);
  39 +
  40 + if (file1 != null && file1.exists()) {
  41 + try {
  42 + worldmapbase = (WorldMapBase) oclass.getConstructor(new Class[] { String.class}).newInstance(new Object[] { s});
  43 + } catch (Exception exception) {
  44 + throw new RuntimeException("Failed to instantiate " + oclass.toString(), exception);
  45 + }
  46 +
  47 + FileInputStream fileinputstream = new FileInputStream(file1);
  48 + NBTTagCompound nbttagcompound = NBTCompressedStreamTools.a((InputStream) fileinputstream);
  49 +
  50 + fileinputstream.close();
  51 + worldmapbase.a(nbttagcompound.getCompound("data"));
  52 + }
  53 + } catch (Exception exception1) {
  54 + exception1.printStackTrace();
  55 + }
  56 + }
  57 +
  58 + if (worldmapbase != null) {
  59 + this.b.put(s, worldmapbase);
  60 + this.c.add(worldmapbase);
  61 + }
  62 +
  63 + return worldmapbase;
  64 + }
  65 + }
  66 +
  67 + public void a(String s, WorldMapBase worldmapbase) {
  68 + if (worldmapbase == null) {
  69 + throw new RuntimeException("Can\'t set null data");
  70 + } else {
  71 + if (this.b.containsKey(s)) {
  72 + this.c.remove(this.b.remove(s));
  73 + }
  74 +
  75 + this.b.put(s, worldmapbase);
  76 + this.c.add(worldmapbase);
  77 + }
  78 + }
  79 +
  80 + public void a() {
  81 + for (int i = 0; i < this.c.size(); ++i) {
  82 + WorldMapBase worldmapbase = (WorldMapBase) this.c.get(i);
  83 +
  84 + if (worldmapbase.b()) {
  85 + this.a(worldmapbase);
  86 + worldmapbase.a(false);
  87 + }
  88 + }
  89 + }
  90 +
  91 + private void a(WorldMapBase worldmapbase) {
  92 + if (this.a != null) {
  93 + try {
  94 + File file1 = this.a.getDataFile(worldmapbase.id);
  95 +
  96 + if (file1 != null) {
  97 + NBTTagCompound nbttagcompound = new NBTTagCompound();
  98 +
  99 + worldmapbase.b(nbttagcompound);
  100 + NBTTagCompound nbttagcompound1 = new NBTTagCompound();
  101 +
  102 + nbttagcompound1.setCompound("data", nbttagcompound);
  103 + FileOutputStream fileoutputstream = new FileOutputStream(file1);
  104 +
  105 + NBTCompressedStreamTools.a(nbttagcompound1, (OutputStream) fileoutputstream);
  106 + fileoutputstream.close();
  107 + }
  108 + } catch (Exception exception) {
  109 + exception.printStackTrace();
  110 + }
  111 + }
  112 + }
  113 +
  114 + private void b() {
  115 + try {
  116 + this.d.clear();
  117 + if (this.a == null) {
  118 + return;
  119 + }
  120 +
  121 + File file1 = this.a.getDataFile("idcounts");
  122 +
  123 + if (file1 != null && file1.exists()) {
  124 + DataInputStream datainputstream = new DataInputStream(new FileInputStream(file1));
  125 + NBTTagCompound nbttagcompound = NBTCompressedStreamTools.a((DataInput) datainputstream);
  126 +
  127 + datainputstream.close();
  128 + Iterator iterator = nbttagcompound.d().iterator();
  129 +
  130 + while (iterator.hasNext()) {
  131 + NBTBase nbtbase = (NBTBase) iterator.next();
  132 +
  133 + if (nbtbase instanceof NBTTagShort) {
  134 + NBTTagShort nbttagshort = (NBTTagShort) nbtbase;
  135 + String s = nbttagshort.getName();
  136 + short short1 = nbttagshort.data;
  137 +
  138 + this.d.put(s, Short.valueOf(short1));
  139 + }
  140 + }
  141 + }
  142 + } catch (Exception exception) {
  143 + exception.printStackTrace();
  144 + }
  145 + }
  146 +
  147 + public int a(String s) {
  148 + Short oshort = (Short) this.d.get(s);
  149 +
  150 + if (oshort == null) {
  151 + oshort = Short.valueOf((short) 0);
  152 + } else {
  153 + oshort = Short.valueOf((short) (oshort.shortValue() + 1));
  154 + }
  155 +
  156 + this.d.put(s, oshort);
  157 + if (this.a == null) {
  158 + return oshort.shortValue();
  159 + } else {
  160 + try {
  161 + File file1 = this.a.getDataFile("idcounts");
  162 +
  163 + if (file1 != null) {
  164 + NBTTagCompound nbttagcompound = new NBTTagCompound();
  165 + Iterator iterator = this.d.keySet().iterator();
  166 +
  167 + while (iterator.hasNext()) {
  168 + String s1 = (String) iterator.next();
  169 + short short1 = ((Short) this.d.get(s1)).shortValue();
  170 +
  171 + nbttagcompound.setShort(s1, short1);
  172 + }
  173 +
  174 + DataOutputStream dataoutputstream = new DataOutputStream(new FileOutputStream(file1));
  175 +
  176 + NBTCompressedStreamTools.a(nbttagcompound, (DataOutput) dataoutputstream);
  177 + dataoutputstream.close();
  178 + }
  179 + } catch (Exception exception) {
  180 + exception.printStackTrace();
  181 + }
  182 +
  183 + return oshort.shortValue();
  184 + }
  185 + }
  186 +}

0 comments on commit be105a7

Please sign in to comment.
Something went wrong with that request. Please try again.