From 1ce9b3f4b07a5f79990d3aa67c6126842aa053ca Mon Sep 17 00:00:00 2001 From: jameslfc19 Date: Tue, 28 Jul 2020 12:39:09 +0100 Subject: [PATCH] Bug Fixes --- .../tileentities/CustomTileEntityChest.java | 9 ++++++++ .../tileentities/CustomTileEntityChest.java | 9 ++++++++ .../tileentities/CustomTileEntityChest.java | 8 ++++++- .../minecraft/chests/ChestsPlusPlus.java | 21 ++++++++++++------- .../chests/listeners/WorldListener.java | 8 +------ .../minecraft/chests/misc/Utils.java | 8 +++++++ .../storage/abstracts/AbstractStorage.java | 4 +--- 7 files changed, 49 insertions(+), 18 deletions(-) diff --git a/ChestsPlusPlus_1_14/src/main/java/com/jamesdpeters/minecraft/chests/v1_14_R1/tileentities/CustomTileEntityChest.java b/ChestsPlusPlus_1_14/src/main/java/com/jamesdpeters/minecraft/chests/v1_14_R1/tileentities/CustomTileEntityChest.java index ee01ab7..b2529bf 100644 --- a/ChestsPlusPlus_1_14/src/main/java/com/jamesdpeters/minecraft/chests/v1_14_R1/tileentities/CustomTileEntityChest.java +++ b/ChestsPlusPlus_1_14/src/main/java/com/jamesdpeters/minecraft/chests/v1_14_R1/tileentities/CustomTileEntityChest.java @@ -4,6 +4,7 @@ import com.jamesdpeters.minecraft.chests.TileEntityOpener; import net.minecraft.server.v1_14_R1.Block; import net.minecraft.server.v1_14_R1.BlockChest; import net.minecraft.server.v1_14_R1.BlockPropertyChestType; +import net.minecraft.server.v1_14_R1.EntityHuman; import net.minecraft.server.v1_14_R1.EnumDirection; import net.minecraft.server.v1_14_R1.SoundCategory; import net.minecraft.server.v1_14_R1.SoundEffect; @@ -71,4 +72,12 @@ public class CustomTileEntityChest extends TileEntityChest implements TileEntity } } + + public void startOpen(EntityHuman entityhuman) { + + } + + public void closeContainer(EntityHuman entityhuman) { + + } } diff --git a/ChestsPlusPlus_1_15/src/main/java/com/jamesdpeters/minecraft/chests/v1_15_R1/tileentities/CustomTileEntityChest.java b/ChestsPlusPlus_1_15/src/main/java/com/jamesdpeters/minecraft/chests/v1_15_R1/tileentities/CustomTileEntityChest.java index aa2e4bc..8aa0f4a 100644 --- a/ChestsPlusPlus_1_15/src/main/java/com/jamesdpeters/minecraft/chests/v1_15_R1/tileentities/CustomTileEntityChest.java +++ b/ChestsPlusPlus_1_15/src/main/java/com/jamesdpeters/minecraft/chests/v1_15_R1/tileentities/CustomTileEntityChest.java @@ -71,4 +71,13 @@ public class CustomTileEntityChest extends TileEntityChest implements TileEntity } } + + public void startOpen(EntityHuman entityhuman) { + + } + + public void closeContainer(EntityHuman entityhuman) { + + } + } diff --git a/ChestsPlusPlus_1_16/src/main/java/com/jamesdpeters/minecraft/chests/v1_16_R1/tileentities/CustomTileEntityChest.java b/ChestsPlusPlus_1_16/src/main/java/com/jamesdpeters/minecraft/chests/v1_16_R1/tileentities/CustomTileEntityChest.java index 31b9b8a..3aa8e39 100644 --- a/ChestsPlusPlus_1_16/src/main/java/com/jamesdpeters/minecraft/chests/v1_16_R1/tileentities/CustomTileEntityChest.java +++ b/ChestsPlusPlus_1_16/src/main/java/com/jamesdpeters/minecraft/chests/v1_16_R1/tileentities/CustomTileEntityChest.java @@ -10,7 +10,6 @@ import net.minecraft.server.v1_16_R1.SoundCategory; import net.minecraft.server.v1_16_R1.SoundEffect; import net.minecraft.server.v1_16_R1.SoundEffects; import net.minecraft.server.v1_16_R1.TileEntityChest; -import net.minecraft.server.v1_16_R1.TileEntityChestTrapped; import net.minecraft.server.v1_16_R1.TileEntityTypes; import org.bukkit.entity.HumanEntity; @@ -74,5 +73,12 @@ public class CustomTileEntityChest extends TileEntityChest implements TileEntity } + public void startOpen(EntityHuman entityhuman) { + + } + + public void closeContainer(EntityHuman entityhuman) { + + } } diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/ChestsPlusPlus.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/ChestsPlusPlus.java index ec9353b..fa85402 100644 --- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/ChestsPlusPlus.java +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/ChestsPlusPlus.java @@ -5,6 +5,8 @@ import com.jamesdpeters.minecraft.chests.commands.AutoCraftCommand; import com.jamesdpeters.minecraft.chests.commands.ChestLinkCommand; import com.jamesdpeters.minecraft.chests.commands.ChestsPlusPlusCommand; import com.jamesdpeters.minecraft.chests.crafting.Crafting; +import com.jamesdpeters.minecraft.chests.lang.LangFile; +import com.jamesdpeters.minecraft.chests.lang.Message; import com.jamesdpeters.minecraft.chests.listeners.StorageListener; import com.jamesdpeters.minecraft.chests.listeners.HopperListener; import com.jamesdpeters.minecraft.chests.listeners.InventoryListener; @@ -38,6 +40,9 @@ import org.bukkit.plugin.java.annotation.plugin.Description; import org.bukkit.plugin.java.annotation.plugin.Plugin; import org.bukkit.plugin.java.annotation.plugin.author.Author; +import java.io.IOException; +import java.util.Set; + @Plugin(name = "ChestsPlusPlus", version = BuildConstants.VERSION) @ApiVersion(ApiVersion.Target.v1_14) @Description(value = "Minecraft Spigot mod that enhances chests and hoppers, with ChestLinks and Hopper filters!") @@ -81,8 +86,10 @@ public class ChestsPlusPlus extends JavaPlugin { Metrics metrics = new Metrics(this, pluginId); Stats.addCharts(metrics); - Settings.initConfig(this); PLUGIN = this; +// LangFile.createTemplateLangFile(); + Settings.initConfig(this); +// LangFile.loadLangFile(Settings.getLangFileName()); //API initialisation API.register(this); @@ -93,12 +100,6 @@ public class ChestsPlusPlus extends JavaPlugin { new AutoCraftCommand().register(this); new ChestsPlusPlusCommand().register(this); - //Register event listeners - getServer().getPluginManager().registerEvents(new StorageListener(),this); - getServer().getPluginManager().registerEvents(new InventoryListener(),this); - getServer().getPluginManager().registerEvents(new HopperListener(),this); - getServer().getPluginManager().registerEvents(new WorldListener(),this); - //Load storage SpigotConfig.load(this); @@ -142,6 +143,12 @@ public class ChestsPlusPlus extends JavaPlugin { Bukkit.getScheduler().scheduleSyncDelayedTask(this, () ->{ Crafting.load(); new Config(); + + //Register event listeners + getServer().getPluginManager().registerEvents(new StorageListener(),this); + getServer().getPluginManager().registerEvents(new InventoryListener(),this); + getServer().getPluginManager().registerEvents(new HopperListener(),this); + getServer().getPluginManager().registerEvents(new WorldListener(),this); getLogger().info("Chests++ Successfully Loaded Config and Recipes"); },1); } diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/listeners/WorldListener.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/listeners/WorldListener.java index 418ba49..b11725d 100644 --- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/listeners/WorldListener.java +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/listeners/WorldListener.java @@ -3,10 +3,6 @@ package com.jamesdpeters.minecraft.chests.listeners; import com.jamesdpeters.minecraft.chests.ChestsPlusPlus; import com.jamesdpeters.minecraft.chests.misc.Utils; import com.jamesdpeters.minecraft.chests.serialize.Config; -import com.jamesdpeters.minecraft.chests.serialize.ConfigStorage; -import com.jamesdpeters.minecraft.chests.serialize.LocationInfo; -import com.jamesdpeters.minecraft.chests.storage.abstracts.AbstractStorage; -import com.jamesdpeters.minecraft.chests.storage.abstracts.StorageType; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.world.ChunkLoadEvent; @@ -14,8 +10,6 @@ import org.bukkit.event.world.WorldLoadEvent; import org.bukkit.event.world.WorldSaveEvent; import org.bukkit.scheduler.BukkitRunnable; -import java.util.List; - public class WorldListener implements Listener { private static boolean justSaved = false; @@ -47,7 +41,7 @@ public class WorldListener implements Listener { storageType.getStorageMap().values().forEach(stringHashMap -> { stringHashMap.values().forEach(o -> { o.getLocations().forEach(locationInfo -> { - if(locationInfo != null && locationInfo.getSignLocation() != null && locationInfo.getSignLocation().getChunk().equals(event.getChunk())){ + if(locationInfo != null && locationInfo.getSignLocation() != null && Utils.isLocationInChunk(locationInfo.getSignLocation(),event.getChunk())) { o.updateClient(locationInfo); } }); diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/misc/Utils.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/misc/Utils.java index d1f6f1f..2c30d15 100644 --- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/misc/Utils.java +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/misc/Utils.java @@ -262,12 +262,20 @@ public class Utils { return location.getWorld() != null && location.getWorld().isChunkLoaded(chunkX, chunkZ); } + public static boolean isLocationInChunk(Location location, Chunk chunk){ + int chunkX = location.getBlockX() >> 4; + int chunkZ = location.getBlockZ() >> 4; + return (chunkX == chunk.getX()) && (chunkZ == chunk.getZ()); + } + public static Collection getPlayersInViewDistance(Location location){ if(location.getWorld() == null) return null; return location.getWorld().getNearbyEntities(location, Bukkit.getViewDistance()*16, 256, Bukkit.getViewDistance()*16, entity -> entity instanceof Player); } public static boolean isLocationInViewDistance(Player player, Location location){ + if(location == null) return false; + if(!player.getWorld().equals(location.getWorld())) return false; Location delta = player.getLocation().subtract(location); return (delta.getX() <= Bukkit.getViewDistance()*16) && (delta.getZ() <= Bukkit.getViewDistance()*16); } diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/abstracts/AbstractStorage.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/abstracts/AbstractStorage.java index 6579a3c..94e298b 100644 --- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/abstracts/AbstractStorage.java +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/abstracts/AbstractStorage.java @@ -140,7 +140,7 @@ public abstract class AbstractStorage implements ConfigurationSerializable { Bukkit.getOnlinePlayers().forEach(player -> { List locationInfos = locationInfoList.stream().filter(locationInfo -> locationInfo.isInWorld(player)).collect(Collectors.toList()); // Create a utility method for this locationInfos.forEach(locationInfo -> { - if (Utils.isLocationInViewDistance(player, locationInfo.getSignLocation())) { + if (Utils.isLocationInViewDistance(player, locationInfo.getSignLocation()) && Utils.isLocationChunkLoaded(locationInfo.getSignLocation())) { if(displayItem != null) player.sendBlockChange(locationInfo.getSignLocation(), air); } }); @@ -513,8 +513,6 @@ public abstract class AbstractStorage implements ConfigurationSerializable { EulerAngle angle = isTool ? TOOL_ITEM_POSE : (isBlock ? BLOCK_POSE : STANDARD_ITEM_POSE); stand.setRightArmPose(angle); -// stand.setArms(true); - //Store value of 1 in armour stand to indicate it belongs to this plugin. stand.getPersistentDataContainer().set(Values.PluginKey, PersistentDataType.INTEGER, 1); return stand;