use of org.bukkit.event.EventHandler in project Core by iConomy.
the class players method onPlayerJoin.
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Accounts accounts = new Accounts();
Player player = event.getPlayer();
if (player != null)
if (!accounts.exists(player.getName()))
accounts.create(player.getName());
}
use of org.bukkit.event.EventHandler in project HawkEye by oliverwoodings.
the class ToolListener method onBlockPlace.
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockPlace(BlockPlaceEvent event) {
Player player = event.getPlayer();
Block block = event.getBlock();
if (BlockUtil.getBlockString(block).equals(Config.ToolBlock) && SessionManager.getSession(player).isUsingTool()) {
ToolManager.toolSearch(player, block.getLocation());
event.setCancelled(true);
}
}
use of org.bukkit.event.EventHandler in project Prism-Bukkit by prism.
the class PrismEntityEvents method onPotionSplashEvent.
/**
*
* @param event
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPotionSplashEvent(final PotionSplashEvent event) {
final ProjectileSource source = event.getPotion().getShooter();
// Ignore from non-players for the time being
if (!(source instanceof Player))
return;
final Player player = (Player) source;
if (!Prism.getIgnore().event("potion-splash", player))
return;
// What type?
// Right now this won't support anything with multiple effects
final Collection<PotionEffect> potion = event.getPotion().getEffects();
String name = "";
for (final PotionEffect eff : potion) {
name = eff.getType().getName().toLowerCase();
}
RecordingQueue.addToQueue(ActionFactory.createPlayer("potion-splash", player, name));
}
use of org.bukkit.event.EventHandler in project Prism-Bukkit by prism.
the class PrismEntityEvents method onEntityChangeBlock.
/**
*
* @param event
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityChangeBlock(final EntityChangeBlockEvent event) {
final String entity = MiscUtils.getEntityName(event.getEntity());
// Technically I think that I really should name it "entity-eat" for
// better consistency and
// in case other mobs ever are made to eat. But that's not as fun
Material to = event.getTo();
Material from = event.getBlock().getType();
if (from == Material.GRASS && to == Material.DIRT) {
if (event.getEntityType() != EntityType.SHEEP)
return;
if (!Prism.getIgnore().event("sheep-eat", event.getBlock()))
return;
RecordingQueue.addToQueue(ActionFactory.createBlock("sheep-eat", event.getBlock(), entity));
} else if (to == Material.AIR ^ from == Material.AIR && event.getEntity() instanceof Enderman) {
if (from == Material.AIR) {
if (!Prism.getIgnore().event("enderman-place", event.getBlock()))
return;
BlockState state = event.getBlock().getState();
state.setType(to);
RecordingQueue.addToQueue(ActionFactory.createBlock("enderman-place", state, entity));
} else {
if (!Prism.getIgnore().event("enderman-pickup", event.getBlock()))
return;
final Enderman enderman = (Enderman) event.getEntity();
if (enderman.getCarriedMaterial() != null) {
BlockState state = event.getBlock().getState();
state.setData(enderman.getCarriedMaterial());
RecordingQueue.addToQueue(ActionFactory.createBlock("enderman-pickup", state, entity));
}
}
} else if (to == Material.AIR && event.getEntity() instanceof Wither) {
if (!Prism.getIgnore().event("entity-break", event.getBlock()))
return;
RecordingQueue.addToQueue(ActionFactory.createBlock("block-break", event.getBlock(), event.getEntityType().getName()));
}
}
use of org.bukkit.event.EventHandler in project Prism-Bukkit by prism.
the class PrismInventoryEvents method onInventoryClick.
/**
* Handle inventory transfers
*
* @param event
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryClick(final InventoryClickEvent event) {
if (!plugin.getConfig().getBoolean("prism.tracking.item-insert") && !plugin.getConfig().getBoolean("prism.tracking.item-remove"))
return;
Location containerLoc = null;
// Store some info
final Player player = (Player) event.getWhoClicked();
final ItemStack currentitem = event.getCurrentItem();
final ItemStack cursoritem = event.getCursor();
// Get location
if (event.getInventory().getHolder() instanceof BlockState) {
final BlockState b = (BlockState) event.getInventory().getHolder();
containerLoc = b.getLocation();
} else if (event.getInventory().getHolder() instanceof Entity) {
final Entity e = (Entity) event.getInventory().getHolder();
containerLoc = e.getLocation();
} else if (event.getInventory().getHolder() instanceof DoubleChest) {
final DoubleChest chest = (DoubleChest) event.getInventory().getHolder();
containerLoc = chest.getLocation();
}
// Double chests report 27 default size, though they actually
// have 6 rows of 9 for 54 slots
int defaultSize = event.getView().getType().getDefaultSize();
if (event.getInventory().getHolder() instanceof DoubleChest) {
defaultSize = event.getView().getType().getDefaultSize() * 2;
}
// slot count of the inventory. At that point, they represent the player inv.
if (event.getSlot() == event.getRawSlot() && event.getRawSlot() <= defaultSize) {
ItemStack addStack = null;
ItemStack removeStack = null;
if (currentitem != null && !currentitem.getType().equals(Material.AIR) && cursoritem != null && !cursoritem.getType().equals(Material.AIR)) {
if (currentitem.isSimilar(cursoritem)) {
// Items are similar enough to stack
int amount = cursoritem.getAmount();
if (event.isRightClick()) {
amount = 1;
}
int remaining = (currentitem.getMaxStackSize() - currentitem.getAmount());
int inserted = (amount <= remaining) ? amount : remaining;
if (inserted > 0) {
addStack = cursoritem.clone();
addStack.setAmount(inserted);
}
} else {
// Items are not similar
addStack = cursoritem.clone();
removeStack = currentitem.clone();
}
} else if (currentitem != null && !currentitem.getType().equals(Material.AIR)) {
removeStack = currentitem.clone();
} else if (cursoritem != null && !cursoritem.getType().equals(Material.AIR)) {
addStack = cursoritem.clone();
}
// Record events
if (addStack != null) {
recordInvAction(player, containerLoc, addStack, event.getRawSlot(), "item-insert", event);
}
if (removeStack != null) {
recordInvAction(player, containerLoc, removeStack, event.getRawSlot(), "item-remove", event);
}
return;
}
if (event.isShiftClick() && cursoritem != null && cursoritem.getType().equals(Material.AIR)) {
recordInvAction(player, containerLoc, currentitem, -1, "item-insert", event);
}
}
Aggregations