use of com.elmakers.mine.bukkit.wand.Wand in project MagicPlugin by elBukkit.
the class EnchantingController method onInventoryClick.
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
if (event.isCancelled())
return;
InventoryType inventoryType = event.getInventory().getType();
SlotType slotType = event.getSlotType();
if (enchantingEnabled && inventoryType == InventoryType.ENCHANTING) {
if (slotType == SlotType.CRAFTING) {
HumanEntity clicker = event.getWhoClicked();
Player player = clicker instanceof Player ? (Player) clicker : null;
if (player == null || !controller.hasPermission(player, "Magic.wand.enchant")) {
return;
}
ItemStack cursor = event.getCursor();
ItemStack current = event.getCurrentItem();
// Make wands into an enchantable item when placing
if (Wand.isWand(cursor)) {
Wand wand = controller.getWand(cursor);
if (wand.isModifiable()) {
wand.makeEnchantable(true);
}
}
// And turn them back when taking out
if (Wand.isWand(current)) {
Wand wand = controller.getWand(current);
if (wand.isModifiable()) {
wand.makeEnchantable(false);
}
}
}
}
}
use of com.elmakers.mine.bukkit.wand.Wand in project MagicPlugin by elBukkit.
the class EntityController method onItemSpawn.
@EventHandler(priority = EventPriority.LOWEST)
public void onItemSpawn(ItemSpawnEvent event) {
if (disableItemSpawn || com.elmakers.mine.bukkit.block.BlockData.undoing) {
event.setCancelled(true);
return;
}
Item itemEntity = event.getEntity();
ItemStack spawnedItem = itemEntity.getItemStack();
Block block = itemEntity.getLocation().getBlock();
BlockData undoData = com.elmakers.mine.bukkit.block.UndoList.getBlockData(block.getLocation());
boolean isBreaking = block.getType() != Material.AIR;
if (!isBreaking) {
MaterialSet doubleAttachables = controller.getMaterialSetManager().getMaterialSetEmpty("attachable_double");
isBreaking = doubleAttachables.testItem(spawnedItem);
}
if (undoData != null && isBreaking) {
// So we can catch this as a one-time event, for blocks we have recorded.
if (undoData.getMaterial() != Material.AIR) {
UndoList undoList = undoData.getUndoList();
if (undoList != null) {
undoList.add(block);
} else {
controller.getLogger().warning("Block broken into item under undo at " + block + ", but no undo list was assigned");
}
event.setCancelled(true);
return;
}
// If this was a block we built magically, don't drop items if the item being dropped
// matches the block type. This is messy, but avoid players losing all their items
// when suffocating inside a Blob
Collection<ItemStack> drops = block.getDrops();
if (drops != null) {
for (ItemStack drop : drops) {
if (drop.getType() == spawnedItem.getType()) {
com.elmakers.mine.bukkit.block.UndoList.commit(undoData);
event.setCancelled(true);
return;
}
}
}
}
if (Wand.isSkill(spawnedItem)) {
event.setCancelled(true);
return;
}
if (Wand.isWand(spawnedItem)) {
boolean invulnerable = controller.getWandProperty(spawnedItem, "invulnerable", false);
if (invulnerable) {
CompatibilityUtils.setInvulnerable(event.getEntity());
}
boolean trackWand = controller.getWandProperty(spawnedItem, "track", false);
if (trackWand) {
Wand wand = controller.getWand(spawnedItem);
controller.addLostWand(wand, event.getEntity().getLocation());
}
} else {
// registerEntityForUndo(event.getEntity());
if (ageDroppedItems > 0) {
int ticks = ageDroppedItems * 20 / 1000;
Item item = event.getEntity();
CompatibilityUtils.ageItem(item, ticks);
}
}
}
use of com.elmakers.mine.bukkit.wand.Wand in project MagicPlugin by elBukkit.
the class InventoryController method onInventoryOpen.
@EventHandler
public void onInventoryOpen(InventoryOpenEvent event) {
Player player = (Player) event.getPlayer();
Mage mage = controller.getRegisteredMage(player);
if (mage == null)
return;
mage.setOpenCooldown(openCooldown);
Wand wand = mage.getActiveWand();
GUIAction gui = mage.getActiveGUI();
if (wand != null && gui == null) {
// Anyway, check for opening another inventory and close the wand.
if (event.getView().getType() != InventoryType.CRAFTING) {
if (wand.getMode() == WandMode.INVENTORY || !wand.isInventoryOpen()) {
wand.deactivate();
}
}
}
}
use of com.elmakers.mine.bukkit.wand.Wand in project MagicPlugin by elBukkit.
the class PlayerController method onPlayerAnimate.
@EventHandler(ignoreCancelled = true)
public void onPlayerAnimate(PlayerAnimationEvent event) {
Player player = event.getPlayer();
if (event.getAnimationType() != PlayerAnimationType.ARM_SWING) {
return;
}
Mage mage = controller.getMage(player);
Wand wand = mage.checkWand();
if (wand == null)
return;
Messages messages = controller.getMessages();
if (!controller.hasWandPermission(player)) {
return;
}
// Check for region or wand-specific permissions
if (!controller.hasWandPermission(player, wand)) {
wand.deactivate();
mage.sendMessage(messages.get("wand.no_permission").replace("$wand", wand.getName()));
return;
}
if (!mage.checkLastClick(clickCooldown)) {
return;
}
if (wand.isUpgrade())
return;
wand.playEffects("swing");
wand.performAction(wand.getLeftClickAction());
}
use of com.elmakers.mine.bukkit.wand.Wand in project MagicPlugin by elBukkit.
the class PlayerController method onPlayerInteract.
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerInteract(PlayerInteractEvent event) {
if (!controller.isLoaded())
return;
Action action = event.getAction();
boolean isLeftClick = action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK;
boolean isRightClick = (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK);
// We only care about left click and right click.
if (!isLeftClick && !isRightClick)
return;
// Note that an interact on air event will arrive pre-cancelled
// So this is kind of useless. :\
// if (event.isCancelled()) return;
// Block block = event.getClickedBlock();
// controller.getLogger().info("INTERACT: " + event.getAction() + " on " + (block == null ? "NOTHING" : block.getType()) + " cancelled: " + event.isCancelled());
Player player = event.getPlayer();
// Don't allow interacting while holding spells, brushes or upgrades
ItemStack itemInHand = player.getInventory().getItemInMainHand();
boolean isSkill = Wand.isSkill(itemInHand);
boolean isSpell = !isSkill && Wand.isSpell(itemInHand);
if (isSpell || Wand.isBrush(itemInHand) || Wand.isUpgrade(itemInHand)) {
event.setCancelled(true);
return;
}
boolean isOffhandSkill = false;
ItemStack itemInOffhand = player.getInventory().getItemInOffHand();
if (isRightClick) {
isOffhandSkill = Wand.isSkill(itemInOffhand);
boolean isOffhandSpell = !isOffhandSkill && Wand.isSpell(itemInOffhand);
if (isOffhandSpell || Wand.isBrush(itemInOffhand) || Wand.isUpgrade(itemInOffhand)) {
event.setCancelled(true);
return;
}
}
Mage mage = controller.getMage(player);
Wand wand = mage.checkWand();
if (action == Action.RIGHT_CLICK_BLOCK) {
Material material = event.getClickedBlock().getType();
isRightClick = !controller.isInteractable(event.getClickedBlock());
// This is to prevent Essentials signs from giving you an item in your wand inventory.
if (wand != null && (material == Material.SIGN_POST || material == Material.WALL_SIGN)) {
wand.closeInventory();
}
}
if (!isLeftClick && !mage.checkLastClick(clickCooldown)) {
return;
}
// Prefer wand right-click if wand is active
if (isOffhandSkill && wand != null) {
if (wand.getRightClickAction() != WandAction.NONE) {
isOffhandSkill = false;
}
}
if (isRightClick && (isOffhandSkill || isSkill)) {
if (isSkill) {
mage.useSkill(itemInHand);
} else {
mage.useSkill(itemInOffhand);
}
event.setCancelled(true);
return;
}
// Check for offhand casting
if (isRightClick) {
if (allowOffhandCasting && mage.offhandCast()) {
// which in the offhand case are right-click actions.
if (cancelInteractOnLeftClick) {
event.setCancelled(true);
}
return;
}
}
// Special-case here for skulls, which actually are not wearable via right-click.
if (itemInHand != null && isRightClick && controller.isWearable(itemInHand) && itemInHand.getType() != Material.SKULL_ITEM) {
if (wand != null) {
wand.deactivate();
}
controller.onArmorUpdated(mage);
return;
}
if (wand == null)
return;
Messages messages = controller.getMessages();
if (!controller.hasWandPermission(player)) {
return;
}
// Check for region or wand-specific permissions
if (!controller.hasWandPermission(player, wand)) {
wand.deactivate();
mage.sendMessage(messages.get("wand.no_permission").replace("$wand", wand.getName()));
return;
}
// Check for enchantment table click
Block clickedBlock = event.getClickedBlock();
if (clickedBlock != null && clickedBlock.getType() != Material.AIR && enchantBlockMaterial != null && enchantBlockMaterial.is(clickedBlock)) {
Spell spell = null;
if (player.isSneaking()) {
spell = enchantSneakClickSpell != null ? mage.getSpell(enchantSneakClickSpell) : null;
} else {
spell = enchantClickSpell != null ? mage.getSpell(enchantClickSpell) : null;
}
if (spell != null) {
spell.cast();
event.setCancelled(true);
return;
}
}
if (isLeftClick && !wand.isUpgrade() && wand.getLeftClickAction() != WandAction.NONE && cancelInteractOnLeftClick) {
event.setCancelled(true);
}
if (isRightClick && wand.performAction(wand.getRightClickAction()) && cancelInteractOnRightClick) {
event.setCancelled(true);
}
}
Aggregations