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

Don't use tomes when right clicking on containers, #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.projectiles.ProjectileSource;

import us.deathmarine.diablodrops.DiabloDrops;
import us.deathmarine.diablodrops.effects.EffectsAPI;
Expand All @@ -34,7 +35,10 @@ public void onDiabloMonsterDamageByEntityEvent(
if (event.getDamager() instanceof LivingEntity) {
damager = (LivingEntity) event.getDamager();
} else if (event.getDamager() instanceof Projectile) {
damager = ((Projectile) event.getDamager()).getShooter();
ProjectileSource shooter = ((Projectile) event.getDamager()).getShooter();
if (shooter instanceof LivingEntity) {
damager = (LivingEntity) shooter;
}
}
if ((entity == null) || (damager == null))
return;
Expand Down
44 changes: 41 additions & 3 deletions src/us/deathmarine/diablodrops/listeners/TomeListener.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package us.deathmarine.diablodrops.listeners;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import org.bukkit.ChatColor;
import org.bukkit.Material;
Expand All @@ -11,6 +13,7 @@
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.BookMeta;
Expand All @@ -21,10 +24,39 @@

public class TomeListener implements Listener {

private Set<Material> interactable = new HashSet<Material>();

private final DiabloDrops plugin;

public TomeListener(final DiabloDrops plugin) {
this.plugin = plugin;
interactable.add(Material.NOTE_BLOCK);
interactable.add(Material.DISPENSER);
interactable.add(Material.BED_BLOCK);
interactable.add(Material.CHEST);
interactable.add(Material.WORKBENCH);
interactable.add(Material.FURNACE);
interactable.add(Material.BURNING_FURNACE);
interactable.add(Material.WOODEN_DOOR);
interactable.add(Material.LEVER);
interactable.add(Material.STONE_BUTTON);
interactable.add(Material.CAKE_BLOCK);
interactable.add(Material.DIODE_BLOCK_OFF);
interactable.add(Material.DIODE_BLOCK_ON);
interactable.add(Material.TRAP_DOOR);
interactable.add(Material.FENCE_GATE);
interactable.add(Material.ENCHANTMENT_TABLE);
interactable.add(Material.BREWING_STAND);
interactable.add(Material.ENDER_CHEST);
interactable.add(Material.COMMAND);
interactable.add(Material.BEACON);
interactable.add(Material.WOOD_BUTTON);
interactable.add(Material.ANVIL);
interactable.add(Material.TRAPPED_CHEST);
interactable.add(Material.REDSTONE_COMPARATOR_OFF);
interactable.add(Material.REDSTONE_COMPARATOR_ON);
interactable.add(Material.HOPPER);
interactable.add(Material.DROPPER);
}

public ChatColor findColor(final String s) {
Expand All @@ -38,8 +70,9 @@ public ChatColor findColor(final String s) {
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOWEST)
public void onRightClick(final PlayerInteractEvent e) {
if ((e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction()
.equals(Action.RIGHT_CLICK_BLOCK))
if ((e.getAction().equals(Action.RIGHT_CLICK_AIR) || (e.getAction()
.equals(Action.RIGHT_CLICK_BLOCK) &&
!interactable.contains(e.getClickedBlock().getType())))
&& e.getPlayer().getItemInHand().getType()
.equals(Material.WRITTEN_BOOK)) {
ItemStack inh = e.getPlayer().getItemInHand();
Expand Down Expand Up @@ -90,7 +123,12 @@ && findColor(b.getAuthor()).equals(ChatColor.MAGIC)) {
e.setCancelled(true);
return;
}
pi.setItemInHand(null);
if (inh.getAmount() > 1) {
inh.setAmount(inh.getAmount()-1);
pi.setItemInHand(inh);
} else {
pi.setItemInHand(null);
}
ItemStack item = plugin.getDropAPI().getItem(tool);
while ((item == null)
|| !item.hasItemMeta()
Expand Down