diff --git a/.classpath b/.classpath index 0f49c3ee..11dd3c2f 100644 --- a/.classpath +++ b/.classpath @@ -3,6 +3,6 @@ - + diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..9783897c --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +/bin +*.class + +# Package Files # +*.jar +*.war +*.ear diff --git a/bin/com/untamedears/realisticbiomes/GrowthConfig.class b/bin/com/untamedears/realisticbiomes/GrowthConfig.class index 5ee3b74b..bc73aba1 100644 Binary files a/bin/com/untamedears/realisticbiomes/GrowthConfig.class and b/bin/com/untamedears/realisticbiomes/GrowthConfig.class differ diff --git a/bin/com/untamedears/realisticbiomes/RealisticBiomes.class b/bin/com/untamedears/realisticbiomes/RealisticBiomes.class index 631efbc2..31b500e6 100644 Binary files a/bin/com/untamedears/realisticbiomes/RealisticBiomes.class and b/bin/com/untamedears/realisticbiomes/RealisticBiomes.class differ diff --git a/bin/com/untamedears/realisticbiomes/listener/GrowListener.class b/bin/com/untamedears/realisticbiomes/listener/GrowListener.class index e543f045..7e6ad791 100644 Binary files a/bin/com/untamedears/realisticbiomes/listener/GrowListener.class and b/bin/com/untamedears/realisticbiomes/listener/GrowListener.class differ diff --git a/bin/com/untamedears/realisticbiomes/listener/PlayerListener.class b/bin/com/untamedears/realisticbiomes/listener/PlayerListener.class index ad411e27..aa4f4351 100644 Binary files a/bin/com/untamedears/realisticbiomes/listener/PlayerListener.class and b/bin/com/untamedears/realisticbiomes/listener/PlayerListener.class differ diff --git a/bin/com/untamedears/realisticbiomes/persist/PlantChunk.class b/bin/com/untamedears/realisticbiomes/persist/PlantChunk.class index a4869426..2d6d7ca1 100644 Binary files a/bin/com/untamedears/realisticbiomes/persist/PlantChunk.class and b/bin/com/untamedears/realisticbiomes/persist/PlantChunk.class differ diff --git a/plugin.yml b/plugin.yml index dd0981b6..5fd0cc5c 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,3 +1,4 @@ name: RealisticBiomes main: com.untamedears.realisticbiomes.RealisticBiomes -version: 0.6 \ No newline at end of file +version: 0.06.02 +authors: [ttk2, Wehttam664, nrfs] # Not sure who the authors are here. Assuming ttk2, myself, and latest contributor. diff --git a/src/com/untamedears/realisticbiomes/RealisticBiomes.java b/src/com/untamedears/realisticbiomes/RealisticBiomes.java index 3ddf4917..88045f5c 100644 --- a/src/com/untamedears/realisticbiomes/RealisticBiomes.java +++ b/src/com/untamedears/realisticbiomes/RealisticBiomes.java @@ -15,6 +15,7 @@ import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; +import com.untamedears.realisticbiomes.async.ChatBufferThread; import com.untamedears.realisticbiomes.listener.GrowListener; import com.untamedears.realisticbiomes.listener.PlayerListener; import com.untamedears.realisticbiomes.listener.SpawnListener; @@ -27,13 +28,16 @@ public class RealisticBiomes extends JavaPlugin implements Listener { private static final Logger LOG = Logger.getLogger("RealisticBiomes"); + public static boolean isEnabled = false; public HashMap materialGrowth; public BlockGrower blockGrower; public PersistConfig persistConfig; + public ChatBufferThread chatBuffer; private PlantManager plantManager; public void onEnable() { + isEnabled=true; WorldID.init(this); @@ -51,6 +55,9 @@ public void onEnable() { registerEvents(); + chatBuffer = new ChatBufferThread(); + new Thread(chatBuffer).start(); + if (persistConfig.enabled) { plantManager = new PlantManager(this, persistConfig); blockGrower = new BlockGrower(plantManager); @@ -206,6 +213,7 @@ else if (materialName.startsWith("entity_")) { } public void onDisable() { + isEnabled=false; if (persistConfig.enabled) { LOG.info("[RealisticBiomes] saving plant growth data."); plantManager.saveAllAndStop(); diff --git a/src/com/untamedears/realisticbiomes/async/ChatBufferThread.java b/src/com/untamedears/realisticbiomes/async/ChatBufferThread.java new file mode 100644 index 00000000..2ed93f82 --- /dev/null +++ b/src/com/untamedears/realisticbiomes/async/ChatBufferThread.java @@ -0,0 +1,53 @@ +package com.untamedears.realisticbiomes.async; + +import java.util.HashMap; + +import org.bukkit.entity.Player; + +import com.untamedears.realisticbiomes.RealisticBiomes; + +public class ChatBufferThread implements Runnable{ + + public static HashMap> buffer = new HashMap>(); + public static final int delay = 20; // Delay before chat refresh. + + @Override + public void run() { + while(RealisticBiomes.isEnabled){ + for (Player p : buffer.keySet()){ + HashMap msgBuffer = buffer.get(p); + for (String msg : msgBuffer.keySet()){ + if (msgBuffer.get(msg)<=1){ + msgBuffer.remove(msg); + } else { + msgBuffer.put(msg, buffer.get(p).get(msg)-1); + } + } + buffer.put(p, msgBuffer); + } + } + } + + /** + * Send a message with a check to prevent message multiplying. + * @param p The player to send the message to. + * @param msg The message. + */ + public static void sendMsg(Player p, String msg){ + if (!buffer.containsKey(p)){ + HashMap msgBuffer = new HashMap(); + msgBuffer.put(msg, delay); + buffer.put(p, msgBuffer); + p.sendMessage(msg); + } else { + HashMap msgBuffer = buffer.get(p); + if (msgBuffer.containsKey(msg)){ + msgBuffer.put(msg, delay); + } else { + msgBuffer.put(msg, delay); + p.sendMessage(msg); + } + } + } + +} diff --git a/src/com/untamedears/realisticbiomes/listener/GrowListener.java b/src/com/untamedears/realisticbiomes/listener/GrowListener.java index d8685a1e..8398ea82 100644 --- a/src/com/untamedears/realisticbiomes/listener/GrowListener.java +++ b/src/com/untamedears/realisticbiomes/listener/GrowListener.java @@ -1,9 +1,12 @@ package com.untamedears.realisticbiomes.listener; +import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.logging.Logger; import org.bukkit.Chunk; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.TreeType; import org.bukkit.block.Block; @@ -132,12 +135,49 @@ public void onPlayerInteract(PlayerInteractEvent event) { */ private boolean willGrow(Object m, Block b) { if(growthMap.containsKey(m)) { - boolean willGrow = Math.random() < growthMap.get(m).getRate(b); - return willGrow; + if (isUnderGreenhouse(b)){ + return Math.random() < 0.08; // If it's in a greenhouse, hamper to 8% under any conditions. + } else { + boolean willGrow = Math.random() < growthMap.get(m).getRate(b); + return willGrow; + } } return true; } + /** + * Determines if a plant of any {@link Material} is under greenhouse conditions. + * @param b The block the crop is growing on. + * @return Whether the crop is in greenhouse conditions or not. + */ + private boolean isUnderGreenhouse(Block b){ + boolean is = false; + Location loc = b.getLocation(); + loc.add(0,3,0); + b=loc.getBlock(); + /* + * Check if the crop is two blocks below a valid light. In this case GLOWSTONE or REDSTONE_LAMP_ON. + * If not, check its adjacents. + */ + if (b.getType().equals(Material.GLOWSTONE) || b.getType().equals(Material.REDSTONE_LAMP_ON)){ + is=true; // Returned if directly under a light. + } else { + List adjacents = Arrays.asList( + b.getLocation().add(0,0,1), + b.getLocation().add(0,0,-1), + b.getLocation().add(1,0,0), + b.getLocation().add(-1,0,0)); + for (Location l : adjacents){ + Block bl = l.getBlock(); + if (bl.getType().equals(Material.GLOWSTONE) || bl.getType().equals(Material.REDSTONE_LAMP_ON)){ + is=true; // Returned if next to a crop directly under a light. + } + } + } + + return is; + } + @EventHandler public void onChunkUnload(ChunkUnloadEvent e) { if (!plugin.persistConfig.enabled) diff --git a/src/com/untamedears/realisticbiomes/listener/PlayerListener.java b/src/com/untamedears/realisticbiomes/listener/PlayerListener.java index 22577d7d..6531dac3 100644 --- a/src/com/untamedears/realisticbiomes/listener/PlayerListener.java +++ b/src/com/untamedears/realisticbiomes/listener/PlayerListener.java @@ -19,6 +19,7 @@ import com.untamedears.realisticbiomes.GrowthConfig; import com.untamedears.realisticbiomes.RealisticBiomes; +import com.untamedears.realisticbiomes.async.ChatBufferThread; public class PlayerListener implements Listener { @@ -151,12 +152,12 @@ else if (material == Material.PUMPKIN || material == Material.MELON_BLOCK || mat if (plantGrowth == 1.0) { String amount = new DecimalFormat("#0.00").format(growthAmount); - event.getPlayer().sendMessage("§7[Realistic Biomes] \""+material.toString()+"\": "+amount+" hours to maturity"); + ChatBufferThread.sendMsg(event.getPlayer(), "§7[Realistic Biomes] \""+material.toString()+"\": "+amount+" hours to maturity"); } else { String amount = new DecimalFormat("#0.00").format(growthAmount); String pAmount = new DecimalFormat("#0.00").format(growthAmount*(1.0-plantGrowth)); - event.getPlayer().sendMessage("§7[Realistic Biomes] \""+material.toString()+"\": "+pAmount+" of "+amount+" hours to maturity"); + ChatBufferThread.sendMsg(event.getPlayer(), "§7[Realistic Biomes] \""+material.toString()+"\": "+pAmount+" of "+amount+" hours to maturity"); } return; @@ -171,7 +172,7 @@ else if (growthAmount < 0.0) growthAmount = 0.0; String amount = new DecimalFormat("#0.00").format(growthAmount*100.0)+"%"; // send the message out to the user! - event.getPlayer().sendMessage("§7[Realistic Biomes] Growth rate \""+material.toString()+"\" = "+amount); + ChatBufferThread.sendMsg(event.getPlayer(), "§7[Realistic Biomes] Growth rate \""+material.toString()+"\" = "+amount); } } } @@ -195,7 +196,7 @@ else if (growthAmount < 0.0) growthAmount = 0.0; String amount = new DecimalFormat("#0.00").format(growthAmount*100.0)+"%"; // send the message out to the user! - event.getPlayer().sendMessage("§7[Realistic Biomes] Spawn rate \""+entity.getType().toString()+"\" = "+amount); + ChatBufferThread.sendMsg(event.getPlayer(), "§7[Realistic Biomes] Spawn rate \""+entity.getType().toString()+"\" = "+amount); } } }