Skip to content
Open
2 changes: 1 addition & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="RealisticBiomes.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="C:/Users/jacob/Desktop/Bukkit/Bukkit/craftbukkit.jar"/>
<classpathentry kind="lib" path="D:/workspace/bukkit-1.7.2-R0.1-20131201.031854-2.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/bin
*.class

# Package Files #
*.jar
*.war
*.ear
Binary file modified bin/com/untamedears/realisticbiomes/GrowthConfig.class
Binary file not shown.
Binary file modified bin/com/untamedears/realisticbiomes/RealisticBiomes.class
Binary file not shown.
Binary file modified bin/com/untamedears/realisticbiomes/listener/GrowListener.class
Binary file not shown.
Binary file modified bin/com/untamedears/realisticbiomes/listener/PlayerListener.class
Binary file not shown.
Binary file modified bin/com/untamedears/realisticbiomes/persist/PlantChunk.class
Binary file not shown.
3 changes: 2 additions & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
name: RealisticBiomes
main: com.untamedears.realisticbiomes.RealisticBiomes
version: 0.6
version: 0.06.02
authors: [ttk2, Wehttam664, nrfs] # Not sure who the authors are here. Assuming ttk2, myself, and latest contributor.
8 changes: 8 additions & 0 deletions src/com/untamedears/realisticbiomes/RealisticBiomes.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Object, GrowthConfig> materialGrowth;
public BlockGrower blockGrower;
public PersistConfig persistConfig;
public ChatBufferThread chatBuffer;
private PlantManager plantManager;

public void onEnable() {
isEnabled=true;

WorldID.init(this);

Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
53 changes: 53 additions & 0 deletions src/com/untamedears/realisticbiomes/async/ChatBufferThread.java
Original file line number Diff line number Diff line change
@@ -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<Player, HashMap<String, Integer>> buffer = new HashMap<Player, HashMap<String, Integer>>();
public static final int delay = 20; // Delay before chat refresh.

@Override
public void run() {
while(RealisticBiomes.isEnabled){
for (Player p : buffer.keySet()){
HashMap<String, Integer> 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<String, Integer> msgBuffer = new HashMap<String, Integer>();
msgBuffer.put(msg, delay);
buffer.put(p, msgBuffer);
p.sendMessage(msg);
} else {
HashMap<String, Integer> msgBuffer = buffer.get(p);
if (msgBuffer.containsKey(msg)){
msgBuffer.put(msg, delay);
} else {
msgBuffer.put(msg, delay);
p.sendMessage(msg);
}
}
}

}
44 changes: 42 additions & 2 deletions src/com/untamedears/realisticbiomes/listener/GrowListener.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<Location> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
}
}
Expand All @@ -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);
}
}
}