]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/commitdiff
General tidy up
authorirtimaled <irtimaled@gmail.com>
Thu, 28 Dec 2017 08:00:53 +0000 (00:00 -0800)
committerirtimaled <irtimaled@gmail.com>
Sat, 30 Dec 2017 03:48:26 +0000 (19:48 -0800)
21 files changed:
java/com/irtimaled/bbor/ReflectionHelper.java
java/com/irtimaled/bbor/common/BoundingBoxCache.java
java/com/irtimaled/bbor/common/CommonProxy.java
java/com/irtimaled/bbor/common/DimensionProcessor.java
java/com/irtimaled/bbor/common/IEventHandler.java [deleted file]
java/com/irtimaled/bbor/common/IVillageEventHandler.java [new file with mode: 0644]
java/com/irtimaled/bbor/common/models/BoundingBox.java
java/com/irtimaled/bbor/common/models/BoundingBoxSlimeChunk.java
java/com/irtimaled/bbor/common/models/BoundingBoxWorldSpawn.java
java/com/irtimaled/bbor/config/ConfigManager.java
java/com/irtimaled/bbor/config/Configuration.java
java/com/irtimaled/bbor/config/Setting.java
java/com/irtimaled/bbor/forge/ForgeClientProxy.java
java/com/irtimaled/bbor/forge/ForgeCommonProxy.java
java/com/irtimaled/bbor/forge/ForgeMod.java
java/com/irtimaled/bbor/forge/messages/AddBoundingBoxMessage.java
java/com/irtimaled/bbor/forge/messages/BoundingBoxDeserializer.java
java/com/irtimaled/bbor/forge/messages/BoundingBoxSerializer.java
java/com/irtimaled/bbor/forge/messages/InitializeClientMessage.java
java/com/irtimaled/bbor/forge/messages/InitializeClientMessageHandler.java
java/com/irtimaled/bbor/forge/messages/RemoveBoundingBoxMessage.java

index afc8f27bf62fdd67ad2bff49a56bd6f2979cfab9..2bd0a4168840618a5b71d2cc694227c27dbb372e 100644 (file)
@@ -11,19 +11,15 @@ public class ReflectionHelper {
             if (f != null) {
                 return (R) f.get(instance);
             }
-        } catch (Exception e) {
+        } catch (Exception ignored) {
         }
         return null;
     }
 
     private static Map<Class, Map<Class, Field>> fieldMap = new HashMap<>();
 
-    protected static <T, R> Field getField(Class<T> sourceClass, Class<R> resultClass) {
-        Map<Class, Field> map = fieldMap.get(sourceClass);
-        if (map == null) {
-            map = new HashMap<>();
-            fieldMap.put(sourceClass, map);
-        }
+    private static <T, R> Field getField(Class<T> sourceClass, Class<R> resultClass) {
+        Map<Class, Field> map = fieldMap.computeIfAbsent(sourceClass, k -> new HashMap<>());
         Field field = map.get(resultClass);
         if (field == null) {
             field = getFieldUsingReflection(sourceClass, resultClass);
index f2bd78e6bd1fff9315dc4d57c33b81badf6ab8d8..03026f1689acc682a2568c7b2304b0084315ba3d 100644 (file)
@@ -21,7 +21,7 @@ public class BoundingBoxCache {
         cache.clear();
     }
 
-    public boolean isCached(BoundingBox key) {
+    boolean isCached(BoundingBox key) {
         return cache.containsKey(key);
     }
 
index 02f74f046829e389d473fff6d01491388fdef670..db749d6061044692f708ab55c4002427e5b26e92 100644 (file)
@@ -12,7 +12,7 @@ import net.minecraft.world.gen.IChunkGenerator;
 public class CommonProxy {
     protected DimensionCache dimensionCache = new DimensionCache();
 
-    private IEventHandler eventHandler = null;
+    private IVillageEventHandler eventHandler = null;
 
     public void worldLoaded(World world) {
         IChunkProvider chunkProvider = world.getChunkProvider();
@@ -34,7 +34,7 @@ public class CommonProxy {
     public void init() {
     }
 
-    public void setEventHandler(IEventHandler eventHandler) {
+    public void setEventHandler(IVillageEventHandler eventHandler) {
         this.eventHandler = eventHandler;
     }
 
index 16c8a230cfdd96dccb3f815609e374a61c603152..108586e5e5dd25d08e21bd5329590de7e963c81c 100644 (file)
@@ -24,9 +24,9 @@ import java.util.List;
 
 public class DimensionProcessor extends BoundingBoxCache {
     private World world;
-    private IEventHandler eventHandler;
+    private IVillageEventHandler eventHandler;
 
-    public DimensionProcessor(IEventHandler eventHandler, World world, DimensionType dimensionType, IChunkGenerator chunkGenerator) {
+    DimensionProcessor(IVillageEventHandler eventHandler, World world, DimensionType dimensionType, IChunkGenerator chunkGenerator) {
         this.eventHandler = eventHandler;
         this.world = world;
         this.dimensionType = dimensionType;
@@ -180,7 +180,7 @@ public class DimensionProcessor extends BoundingBoxCache {
         for (BoundingBox village : oldVillages.values()) {
             removeBoundingBox(village);
             if (eventHandler != null) {
-                eventHandler.boundingBoxRemoved(this.dimensionType, village);
+                eventHandler.villageRemoved(this.dimensionType, village);
             }
         }
         for (BoundingBox village : newVillages.values()) {
diff --git a/java/com/irtimaled/bbor/common/IEventHandler.java b/java/com/irtimaled/bbor/common/IEventHandler.java
deleted file mode 100644 (file)
index e427ab5..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.irtimaled.bbor.common;
-
-import com.irtimaled.bbor.common.models.BoundingBox;
-import net.minecraft.world.DimensionType;
-
-public interface IEventHandler {
-    void boundingBoxRemoved(DimensionType dimensionType, BoundingBox bb);
-}
diff --git a/java/com/irtimaled/bbor/common/IVillageEventHandler.java b/java/com/irtimaled/bbor/common/IVillageEventHandler.java
new file mode 100644 (file)
index 0000000..b8df1c8
--- /dev/null
@@ -0,0 +1,8 @@
+package com.irtimaled.bbor.common;
+
+import com.irtimaled.bbor.common.models.BoundingBox;
+import net.minecraft.world.DimensionType;
+
+public interface IVillageEventHandler {
+    void villageRemoved(DimensionType dimensionType, BoundingBox bb);
+}
index 6d322cd0980850fa0b834bb6fb261c703dd45fa3..c337dc7c03bbce4621155174de32ee784e057bd4 100644 (file)
@@ -34,11 +34,7 @@ public abstract class BoundingBox {
         if (getClass() != obj.getClass())
             return false;
         BoundingBox other = (BoundingBox) obj;
-        if (!minBlockPos.equals(other.minBlockPos))
-            return false;
-        if (!maxBlockPos.equals(other.maxBlockPos))
-            return false;
-        return true;
+        return minBlockPos.equals(other.minBlockPos) && maxBlockPos.equals(other.maxBlockPos);
     }
 
     @Override
index 9966b1b8c20bad81a1146df207753f68b78cdf19..93aa8f3658d69c1f0a66c1da49b319d900039bad 100644 (file)
@@ -1,7 +1,6 @@
 package com.irtimaled.bbor.common.models;
 
 import net.minecraft.util.math.BlockPos;
-import net.minecraft.util.math.ChunkPos;
 
 import java.awt.*;
 
@@ -10,12 +9,6 @@ public class BoundingBoxSlimeChunk extends BoundingBox {
         super(minBlockPos, maxBlockPos, color);
     }
 
-    public static BoundingBoxSlimeChunk from(ChunkPos chunkCoordIntPair, Color color) {
-        BlockPos minBlockPos = new BlockPos(chunkCoordIntPair.getXStart(), 1, chunkCoordIntPair.getZStart());
-        BlockPos maxBlockPos = new BlockPos(chunkCoordIntPair.getXEnd(), 38, chunkCoordIntPair.getZEnd());
-        return new BoundingBoxSlimeChunk(minBlockPos, maxBlockPos, color);
-    }
-
     public static BoundingBoxSlimeChunk from(BlockPos minBlockPos, BlockPos maxBlockPos, Color color) {
         return new BoundingBoxSlimeChunk(minBlockPos, maxBlockPos, color);
     }
index 4ea13b55d00e7fa5eee4e935238abe8995aa98bf..ad3a127a4e1245d29aa4f4b0f31618f995875833 100644 (file)
@@ -5,7 +5,7 @@ import net.minecraft.util.math.BlockPos;
 import java.awt.*;
 
 public class BoundingBoxWorldSpawn extends BoundingBox {
-    protected BoundingBoxWorldSpawn(BlockPos minBlockPos, BlockPos maxBlockPos, Color color) {
+    private BoundingBoxWorldSpawn(BlockPos minBlockPos, BlockPos maxBlockPos, Color color) {
         super(minBlockPos, maxBlockPos, color);
     }
 
index 1551461a58cfa41a61ccb7497130a95598ed63cc..37227f9bfbd6017b0f96efd46e2f888cf06374b8 100644 (file)
@@ -27,11 +27,9 @@ public class ConfigManager {
     public static Setting drawEndCities;
     public static Setting drawMansions;
 
-    private static Configuration config;
-
     public static void loadConfig(File mcConfigDir) {
         configDir = mcConfigDir;
-        config = new Configuration(new File(configDir, "BBOutlineReloaded.cfg"));
+        Configuration config = new Configuration(new File(configDir, "BBOutlineReloaded.cfg"));
         config.load();
 
         fill = SetupBooleanProperty(config, "general", "fill", true, "If set to true the bounding boxes are filled. (default: true)");
index 2a7d217ef084765d5ea5c2aa67483ccc66eb2ae5..20485262fde6a6a1b3dbd9f323df222b82d95e44 100644 (file)
@@ -11,11 +11,11 @@ import java.util.Map;
 public class Configuration {
     private final File file;
 
-    public Configuration(File file) {
+    Configuration(File file) {
         this.file = file;
     }
 
-    public void save() {
+    void save() {
         Writer writer = null;
         try {
             writer = new BufferedWriter(new OutputStreamWriter(
@@ -36,18 +36,20 @@ public class Configuration {
                 }
                 writer.write("}\n");
             }
-        } catch (IOException ex) {
+        } catch (IOException ignored) {
         } finally {
             try {
-                writer.close();
-            } catch (Exception ex) {
+                if (writer != null) {
+                    writer.close();
+                }
+            } catch (Exception ignored) {
             }
         }
     }
 
-    Map<String, Map<String, Setting>> settingsGroup = new HashMap<>();
+    private Map<String, Map<String, Setting>> settingsGroup = new HashMap<>();
 
-    public void load() {
+    void load() {
         try {
             List<String> lines = Files.readLines(file, Charset.forName("utf-8"));
             String category = null;
@@ -79,10 +81,9 @@ public class Configuration {
                     Setting setting = new Setting(value);
                     setting.comment = lastCommentLine;
                     settingsGroup.get(category).put(name, setting);
-                    continue;
                 }
             }
-        } catch (IOException e) {
+        } catch (IOException ignored) {
         }
     }
 
index f6a7bfc4b8c8352c54fc4e93c48c9bef6e6e1ab3..ec7bbefe92998e5efca2a083e96add20d0508568 100644 (file)
@@ -2,9 +2,9 @@ package com.irtimaled.bbor.config;
 
 public class Setting {
     private Object value;
-    public String comment;
+    String comment;
 
-    public Setting(Object value) {
+    Setting(Object value) {
         this.value = value;
     }
 
@@ -15,7 +15,7 @@ public class Setting {
         return defaultValue;
     }
 
-    public int getInt(int defaultValue) {
+    int getInt(int defaultValue) {
         if (value instanceof Integer)
             return (Integer) value;
 
@@ -34,7 +34,7 @@ public class Setting {
         return getInt(0);
     }
 
-    public String getType() {
+    String getType() {
         if (value instanceof Integer)
             return "I";
         if (value instanceof Boolean)
@@ -42,7 +42,7 @@ public class Setting {
         return "S";
     }
 
-    public Object getValue() {
+    Object getValue() {
         return value;
     }
 }
index d248b4a189d539a6da9463caab0d41fcaf1f91ff..2f60e74297b4693e5aeea829f3d9df6479a2b03d 100644 (file)
@@ -28,9 +28,7 @@ public class ForgeClientProxy extends ForgeCommonProxy {
     protected boolean isRemotePlayer(EntityPlayer player) {
         if (Minecraft.getMinecraft().isSingleplayer()) {
             EntityPlayer singlePlayer = Minecraft.getMinecraft().player;
-            if (singlePlayer == null)
-                return false;
-            return player.getGameProfile() != singlePlayer.getGameProfile();
+            return singlePlayer != null && player.getGameProfile() != singlePlayer.getGameProfile();
         }
         return true;
     }
index b1f7a3bfb4337121495c75c0773604d9a5036d03..234a61335ee9d6fba66c1c08a15afbdf86b4852d 100644 (file)
@@ -4,16 +4,15 @@ import com.irtimaled.bbor.Logger;
 import com.irtimaled.bbor.common.BoundingBoxCache;
 import com.irtimaled.bbor.common.CommonProxy;
 import com.irtimaled.bbor.common.DimensionCache;
-import com.irtimaled.bbor.common.IEventHandler;
+import com.irtimaled.bbor.common.IVillageEventHandler;
 import com.irtimaled.bbor.common.models.BoundingBox;
-import com.irtimaled.bbor.common.models.WorldData;
-import com.irtimaled.bbor.config.ConfigManager;
 import com.irtimaled.bbor.forge.messages.*;
 import net.minecraft.entity.player.EntityPlayer;
 import net.minecraft.entity.player.EntityPlayerMP;
 import net.minecraft.network.NetHandlerPlayServer;
 import net.minecraft.server.MinecraftServer;
 import net.minecraft.world.DimensionType;
+import net.minecraft.world.World;
 import net.minecraftforge.event.world.ChunkEvent;
 import net.minecraftforge.event.world.WorldEvent;
 import net.minecraftforge.fml.common.FMLCommonHandler;
@@ -31,10 +30,10 @@ import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 
-public class ForgeCommonProxy implements IEventHandler {
-    public Map<EntityPlayerMP, DimensionType> playerDimensions = new ConcurrentHashMap<>();
+public class ForgeCommonProxy implements IVillageEventHandler {
+    private Map<EntityPlayerMP, DimensionType> playerDimensions = new ConcurrentHashMap<>();
     private Map<EntityPlayerMP, Set<BoundingBox>> playerBoundingBoxesCache = new HashMap<>();
-    public HashSet<EntityPlayerMP> registeredPlayers = new HashSet<>();
+    private HashSet<EntityPlayerMP> registeredPlayers = new HashSet<>();
 
     protected CommonProxy getProxy() {
         if (commonProxy == null)
@@ -54,7 +53,7 @@ public class ForgeCommonProxy implements IEventHandler {
     protected SimpleNetworkWrapper network;
     private CommonProxy commonProxy;
 
-    public void init() {
+    void init() {
         CommonProxy proxy = getProxy();
         proxy.setEventHandler(this);
         proxy.init();
@@ -66,7 +65,8 @@ public class ForgeCommonProxy implements IEventHandler {
 
     @SubscribeEvent
     public void worldEvent(WorldEvent.Load event) {
-        getProxy().worldLoaded(event.getWorld());
+        World world = event.getWorld();
+        getProxy().worldLoaded(world);
     }
 
     @SubscribeEvent
@@ -78,29 +78,34 @@ public class ForgeCommonProxy implements IEventHandler {
     public void playerChangedDimensionEvent(PlayerEvent.PlayerChangedDimensionEvent evt) {
         if (playerDimensions.containsKey(evt.player)) {
             EntityPlayerMP player = (EntityPlayerMP) evt.player;
-            DimensionType dimensionType = DimensionType.getById(player.dimension);
-            playerDimensions.put(player, dimensionType);
-
-            sendToPlayer(player, getDimensionCache().getBoundingBoxes(dimensionType));
+            sendBoundingBoxes(player);
         }
     }
 
-    protected boolean isRemotePlayer(EntityPlayer player) {
-        return registeredPlayers.contains(player);
-    }
-
     @SubscribeEvent
     public void playerLoggedInEvent(PlayerEvent.PlayerLoggedInEvent evt) {
         if (evt.player instanceof EntityPlayerMP &&
                 isRemotePlayer(evt.player)) {
             EntityPlayerMP player = (EntityPlayerMP) evt.player;
             initializeClient(player);
-            DimensionType dimensionType = DimensionType.getById(player.dimension);
-            playerDimensions.put(player, dimensionType);
-            sendToPlayer(player, getDimensionCache().getBoundingBoxes(dimensionType));
+            sendBoundingBoxes(player);
         }
     }
 
+    private void sendBoundingBoxes(EntityPlayerMP player) {
+        DimensionType dimensionType = DimensionType.getById(player.dimension);
+        playerDimensions.put(player, dimensionType);
+        sendToPlayer(player, getDimensionCache().getBoundingBoxes(dimensionType));
+    }
+
+    protected boolean isRemotePlayer(EntityPlayer player) {
+        return registeredPlayers.contains(player);
+    }
+
+    private void initializeClient(EntityPlayerMP player) {
+        network.sendTo(InitializeClientMessage.from(getDimensionCache().getWorldData()), player);
+    }
+
     @SubscribeEvent
     public void playerLoggedOutEvent(PlayerEvent.PlayerLoggedOutEvent evt) {
         if (playerDimensions.containsKey(evt.player)) {
@@ -123,10 +128,6 @@ public class ForgeCommonProxy implements IEventHandler {
         }
     }
 
-    private void initializeClient(EntityPlayerMP player) {
-        network.sendTo(InitializeClientMessage.from(getDimensionCache().getWorldData()), player);
-    }
-
     private void sendToPlayer(EntityPlayerMP player, BoundingBoxCache boundingBoxCache) {
         if (boundingBoxCache == null)
             return;
@@ -158,11 +159,11 @@ public class ForgeCommonProxy implements IEventHandler {
         return cacheSubset;
     }
 
-    public void boundingBoxRemoved(DimensionType dimensionType, BoundingBox bb) {
+    public void villageRemoved(DimensionType dimensionType, BoundingBox bb) {
         RemoveBoundingBoxMessage message = RemoveBoundingBoxMessage.from(dimensionType, bb);
         for (EntityPlayerMP player : playerDimensions.keySet()) {
             if (DimensionType.getById(player.dimension) == dimensionType) {
-                Logger.info("remove 1 entry from %s (0)", player.getDisplayNameString());
+                Logger.info("remove 1 entry from %s (%s)", player.getDisplayNameString(), dimensionType);
                 network.sendTo(message, player);
 
                 if (playerBoundingBoxesCache.containsKey(player) &&
@@ -173,8 +174,8 @@ public class ForgeCommonProxy implements IEventHandler {
         }
     }
 
-    public void setWorldData(WorldData worldData) {
-        getDimensionCache().setWorldData(worldData.getSeed(), worldData.getSpawnX(), worldData.getSpawnZ());
+    public void setWorldData(long seed, int spawnX, int spawnZ) {
+        getDimensionCache().setWorldData(seed, spawnX, spawnZ);
     }
 
     public void addBoundingBox(DimensionType dimensionType, BoundingBox key, Set<BoundingBox> boundingBoxes) {
index b702e52ac39cde5c63194d3ce750e2f4c570f794..4ad5b59137faa4cd48b5b49ceb1fd1dc81552385 100644 (file)
@@ -10,10 +10,10 @@ import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
 
 @Mod(modid = ForgeMod.MODID, name = ForgeMod.NAME, version = ForgeMod.VERSION, acceptedMinecraftVersions = ForgeMod.MCVERSION, acceptableRemoteVersions = "*")
 public class ForgeMod {
-    public static final String MODID = "bbor";
-    public static final String NAME = "Bounding Box Outline Reloaded";
-    public static final String VERSION = "1.0.0-beta18";
-    public static final String MCVERSION = "1.12";
+    static final String MODID = "bbor";
+    static final String NAME = "Bounding Box Outline Reloaded";
+    static final String VERSION = "1.0.0-beta18";
+    static final String MCVERSION = "1.12";
 
     public SimpleNetworkWrapper network;
 
index b76826e6c47a9dfc5bcbfec16568ea1ba3abb05f..26f5cb4d7a3dc411d91442a153be1758114644d1 100644 (file)
@@ -51,11 +51,11 @@ public class AddBoundingBoxMessage implements IMessage {
         return dimensionType;
     }
 
-    public BoundingBox getKey() {
+    BoundingBox getKey() {
         return key;
     }
 
-    public Set<BoundingBox> getBoundingBoxes() {
+    Set<BoundingBox> getBoundingBoxes() {
         return boundingBoxes;
     }
 }
index 44c4296284f63ef9109ef9efc5b2b802b7ec3d11..d0441520388143f990fa7d5f2385f6d7842d1442 100644 (file)
@@ -11,8 +11,8 @@ import java.awt.*;
 import java.util.HashSet;
 import java.util.Set;
 
-public class BoundingBoxDeserializer {
-    public static BoundingBox deserialize(ByteBuf buf) {
+class BoundingBoxDeserializer {
+    static BoundingBox deserialize(ByteBuf buf) {
         char type = (char) ByteBufUtils.readVarShort(buf);
         switch (type) {
             case 'V':
index 7b0965006b5576e76989e8b18e61b9de773a73ba..f0392f6ec1544fb9b7e036d2a36584337d1d74e8 100644 (file)
@@ -9,8 +9,8 @@ import net.minecraftforge.fml.common.network.ByteBufUtils;
 
 import java.awt.*;
 
-public class BoundingBoxSerializer {
-    public static void serialize(BoundingBox boundingBox, ByteBuf buf) {
+class BoundingBoxSerializer {
+    static void serialize(BoundingBox boundingBox, ByteBuf buf) {
         if (boundingBox instanceof BoundingBoxVillage) {
             serializeVillage((BoundingBoxVillage) boundingBox, buf);
         }
index cd32a00e9aff2665cac16bf8164d67f49e5b622c..684736ac5cd83a0183efc0bf0950038369cddcf6 100644 (file)
@@ -28,7 +28,7 @@ public class InitializeClientMessage implements IMessage {
         buf.writeInt(worldData.getSpawnZ());
     }
 
-    public WorldData getWorldData() {
+    WorldData getWorldData() {
         return worldData;
     }
 }
index 59976a3503965e1b42b6f0d1b803b52eea61d8c0..176231a3e84e4373b65428cfa3c831fa3bef1df8 100644 (file)
@@ -1,5 +1,6 @@
 package com.irtimaled.bbor.forge.messages;
 
+import com.irtimaled.bbor.common.models.WorldData;
 import com.irtimaled.bbor.forge.ForgeMod;
 import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
 import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
@@ -8,7 +9,8 @@ import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
 public class InitializeClientMessageHandler implements IMessageHandler<InitializeClientMessage, IMessage> {
     @Override
     public IMessage onMessage(InitializeClientMessage message, MessageContext ctx) {
-        ForgeMod.proxy.setWorldData(message.getWorldData());
+        WorldData worldData = message.getWorldData();
+        ForgeMod.proxy.setWorldData(worldData.getSeed(), worldData.getSpawnX(), worldData.getSpawnZ());
         return null;
     }
 }
index a80fc09686a7dc933847bbf2a013afc22eb6cef9..283dbe1a58a5a2be704c247bdbc67d102861237a 100644 (file)
@@ -33,7 +33,7 @@ public class RemoveBoundingBoxMessage implements IMessage {
         return dimensionType;
     }
 
-    public BoundingBox getKey() {
+    BoundingBox getKey() {
         return key;
     }
 }