Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue #52 #53

Merged
merged 2 commits into from
Aug 13, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/com/untamedears/realisticbiomes/listener/PlayerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import java.text.DecimalFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.UUID;

import org.bukkit.Material;
import org.bukkit.block.Block;
Expand All @@ -12,6 +15,8 @@
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;

import com.untamedears.realisticbiomes.GrowthConfig;
import com.untamedears.realisticbiomes.GrowthMap;
import com.untamedears.realisticbiomes.RealisticBiomes;
Expand All @@ -25,8 +30,7 @@ public class PlayerListener implements Listener {

private RealisticBiomes plugin;



private static ConcurrentHashMap<UUID, Long> suppression = new ConcurrentHashMap<UUID, Long>();

private GrowthMap growthConfigs;

Expand All @@ -45,10 +49,19 @@ public void onPlayerInteractEvent(PlayerInteractEvent event) {
return;
}

Plant plant = null;

Block block = event.getClickedBlock();

if (((List<ItemStack>)block.getDrops()).get(0).getType() == event.getMaterial()) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surely this cast is unsafe and could be changed to something like block.getDrops().iterator().next()?
Edit: plus it probably needs a null-check anyhow. This should be throwing NPEs right now when breaking blocks that don't give drops.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the bukkit docs, it is a safe cast. And don't call me Shirley.

suppression.put(event.getPlayer().getUniqueId(), System.currentTimeMillis());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ProgrammerDan do you think it's okay that this lis never gets cleared? It should be filling up with players over the course of the day.

return;
}

if(System.currentTimeMillis() - suppression.get(event.getPlayer().getUniqueId()) < 1000) {
return;
}

Plant plant = null;

GrowthConfig growthConfig;

if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
Expand Down