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);
cache.clear();
}
- public boolean isCached(BoundingBox key) {
+ boolean isCached(BoundingBox key) {
return cache.containsKey(key);
}
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();
public void init() {
}
- public void setEventHandler(IEventHandler eventHandler) {
+ public void setEventHandler(IVillageEventHandler eventHandler) {
this.eventHandler = eventHandler;
}
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;
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()) {
+++ /dev/null
-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);
-}
--- /dev/null
+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);
+}
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
package com.irtimaled.bbor.common.models;
import net.minecraft.util.math.BlockPos;
-import net.minecraft.util.math.ChunkPos;
import java.awt.*;
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);
}
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);
}
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)");
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(
}
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;
Setting setting = new Setting(value);
setting.comment = lastCommentLine;
settingsGroup.get(category).put(name, setting);
- continue;
}
}
- } catch (IOException e) {
+ } catch (IOException ignored) {
}
}
public class Setting {
private Object value;
- public String comment;
+ String comment;
- public Setting(Object value) {
+ Setting(Object value) {
this.value = value;
}
return defaultValue;
}
- public int getInt(int defaultValue) {
+ int getInt(int defaultValue) {
if (value instanceof Integer)
return (Integer) value;
return getInt(0);
}
- public String getType() {
+ String getType() {
if (value instanceof Integer)
return "I";
if (value instanceof Boolean)
return "S";
}
- public Object getValue() {
+ Object getValue() {
return value;
}
}
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;
}
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;
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)
protected SimpleNetworkWrapper network;
private CommonProxy commonProxy;
- public void init() {
+ void init() {
CommonProxy proxy = getProxy();
proxy.setEventHandler(this);
proxy.init();
@SubscribeEvent
public void worldEvent(WorldEvent.Load event) {
- getProxy().worldLoaded(event.getWorld());
+ World world = event.getWorld();
+ getProxy().worldLoaded(world);
}
@SubscribeEvent
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)) {
}
}
- private void initializeClient(EntityPlayerMP player) {
- network.sendTo(InitializeClientMessage.from(getDimensionCache().getWorldData()), player);
- }
-
private void sendToPlayer(EntityPlayerMP player, BoundingBoxCache boundingBoxCache) {
if (boundingBoxCache == null)
return;
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) &&
}
}
- 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) {
@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;
return dimensionType;
}
- public BoundingBox getKey() {
+ BoundingBox getKey() {
return key;
}
- public Set<BoundingBox> getBoundingBoxes() {
+ Set<BoundingBox> getBoundingBoxes() {
return boundingBoxes;
}
}
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':
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);
}
buf.writeInt(worldData.getSpawnZ());
}
- public WorldData getWorldData() {
+ WorldData getWorldData() {
return worldData;
}
}
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;
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;
}
}
return dimensionType;
}
- public BoundingBox getKey() {
+ BoundingBox getKey() {
return key;
}
}