use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class CraftingController method onCraftItem.
@EventHandler
public void onCraftItem(CraftItemEvent event) {
HumanEntity human = event.getWhoClicked();
if (!(human instanceof Player))
return;
Player player = (Player) human;
Mage mage = controller.getMage(player);
// Don't allow crafting in the wand inventory.
if (mage.hasStoredInventory()) {
event.setCancelled(true);
return;
}
ItemStack currentItem = event.getCurrentItem();
if (Wand.isWand(currentItem)) {
CraftWandEvent castEvent = new CraftWandEvent(mage, controller.getWand(currentItem));
Bukkit.getPluginManager().callEvent(castEvent);
}
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class EntityController method onEntityPreDamageByEntity.
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onEntityPreDamageByEntity(EntityDamageByEntityEvent event) {
Entity entity = event.getEntity();
if (entity instanceof Projectile || entity instanceof TNTPrimed)
return;
Mage entityMage = controller.getRegisteredMage(entity);
if (entityMage != null) {
entityMage.damagedBy(event.getDamager(), event.getDamage());
if (entity instanceof Player) {
Player damaged = (Player) entity;
if (damaged.isBlocking()) {
com.elmakers.mine.bukkit.api.wand.Wand damagedWand = entityMage.getActiveWand();
if (damagedWand != null) {
damagedWand.playEffects("hit_blocked");
}
}
}
if (entityMage.isSuperProtected()) {
event.setCancelled(true);
return;
}
}
Entity damager = event.getDamager();
if (entityDamageReduction != null) {
Double reduction = entityDamageReduction.get(damager.getType());
if (reduction != null) {
if (reduction >= 1) {
event.setCancelled(true);
return;
}
event.setDamage(event.getDamage() * (1 - reduction));
}
}
if (damager instanceof Player) {
Mage damagerMage = controller.getRegisteredMage(damager);
com.elmakers.mine.bukkit.api.wand.Wand activeWand = null;
boolean isMelee = event.getCause() == EntityDamageEvent.DamageCause.ENTITY_ATTACK && !CompatibilityUtils.isDamaging;
if (isMelee && meleeDamageReduction > 0) {
if (meleeDamageReduction >= 1) {
event.setCancelled(true);
return;
}
event.setDamage(event.getDamage() * (1 - meleeDamageReduction));
}
if (isMelee && damagerMage != null) {
activeWand = damagerMage.getActiveWand();
if (activeWand != null) {
activeWand.playEffects("hit_entity");
activeWand.damageDealt(event.getDamage(), entity);
}
}
if (preventWandMeleeDamage) {
boolean hasWand = activeWand != null;
Player player = (Player) damager;
ItemStack itemInHand = player.getInventory().getItemInMainHand();
boolean isMeleeWeapon = controller.isMeleeWeapon(itemInHand);
if (isMelee && hasWand && !isMeleeWeapon) {
event.setCancelled(true);
CompatibilityUtils.isDamaging = true;
activeWand.performAction(activeWand.getLeftClickAction());
CompatibilityUtils.isDamaging = false;
} else if (!hasWand && preventMeleeDamage && isMelee && !isMeleeWeapon) {
event.setCancelled(true);
}
}
} else {
Targeting.checkTracking(controller.getPlugin(), damager, entity, null);
}
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class MagicRequirement method checkRequirement.
public boolean checkRequirement(@Nonnull CastContext context) {
Mage mage = context.getMage();
Player player = mage.getPlayer();
if (permissionNode != null && (player == null || !player.hasPermission(permissionNode))) {
return false;
}
Wand wand = context.getWand();
if (wand == null && requireWand) {
return false;
}
if (requiredTemplate != null) {
String template = wand.getTemplateKey();
if (template == null || !template.equals(requiredTemplate)) {
return false;
}
}
if (requiredTemplates != null) {
String template = wand.getTemplateKey();
if (template == null || !requiredTemplates.contains(template)) {
return false;
}
}
CasterProperties checkProperties = context.getActiveProperties();
ProgressionPath path = checkProperties.getPath();
if (mageClass != null && !mageClass.isEmpty()) {
if (!mage.hasClassUnlocked(mageClass)) {
return false;
}
}
if (requiredPath != null || exactPath != null) {
if (path == null) {
return false;
}
if (requiredPath != null && !path.hasPath(requiredPath)) {
return false;
}
if (exactPath != null && !exactPath.equals(path.getKey())) {
return false;
}
if (requiresCompletedPath != null) {
boolean hasPathCompleted = false;
if (path.hasPath(requiresCompletedPath)) {
if (path.getKey().equals(requiresCompletedPath)) {
hasPathCompleted = !path.canProgress(checkProperties);
} else {
hasPathCompleted = true;
}
}
if (!hasPathCompleted) {
return false;
}
}
}
if (wandProperties != null) {
if (!checkProperties(wand, wandProperties)) {
return false;
}
}
if (classProperties != null) {
MageClass activeClass = mageClass == null ? mage.getActiveClass() : mage.getClass(mageClass);
if (activeClass == null) {
return false;
}
if (!checkProperties(activeClass, classProperties)) {
return false;
}
}
if (attributes != null) {
for (PropertyRequirement requirement : attributes) {
String key = requirement.key;
Double value = mage.getAttribute(key);
if (!checkProperty(requirement, value)) {
return false;
}
}
}
return true;
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class MagicCommandExecutor method onGiveUpgrade.
protected boolean onGiveUpgrade(CommandSender sender, Player player, String wandKey, boolean quiet, boolean giveItem, boolean giveValue, boolean showWorth) {
Mage mage = controller.getMage(player);
Wand currentWand = mage.getActiveWand();
if (currentWand != null) {
currentWand.closeInventory();
}
Wand wand = api.createWand(wandKey);
if (wand != null) {
wand.makeUpgrade();
if (giveItem) {
api.giveItemToPlayer(player, wand.getItem());
if (sender != player && !quiet) {
sender.sendMessage("Gave upgrade " + wand.getName() + " to " + player.getName());
}
}
if (showWorth) {
showWorth(sender, wand.getItem());
}
} else {
if (!quiet)
sender.sendMessage(api.getMessages().getParameterized("wand.unknown_template", "$name", wandKey));
return false;
}
return true;
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class MagicCommandExecutor method onTabComplete.
@Override
public Collection<String> onTabComplete(CommandSender sender, String commandName, String[] args) {
List<String> options = new ArrayList<>();
if (args.length == 1) {
addIfPermissible(sender, options, "Magic.commands.magic.", "clean");
addIfPermissible(sender, options, "Magic.commands.magic.", "clearcache");
addIfPermissible(sender, options, "Magic.commands.magic.", "cancel");
addIfPermissible(sender, options, "Magic.commands.magic.", "load");
addIfPermissible(sender, options, "Magic.commands.magic.", "save");
addIfPermissible(sender, options, "Magic.commands.magic.", "commit");
addIfPermissible(sender, options, "Magic.commands.magic.", "give");
addIfPermissible(sender, options, "Magic.commands.magic.", "worth");
addIfPermissible(sender, options, "Magic.commands.magic.", "sell");
addIfPermissible(sender, options, "Magic.commands.magic.", "list");
addIfPermissible(sender, options, "Magic.commands.magic.", "rpcheck");
addIfPermissible(sender, options, "Magic.commands.magic.", "rpsend");
} else if (args.length == 2) {
if (args[0].equalsIgnoreCase("list")) {
addIfPermissible(sender, options, "Magic.commands.magic.list", "maps");
addIfPermissible(sender, options, "Magic.commands.magic.list", "wands");
addIfPermissible(sender, options, "Magic.commands.magic.list", "automata");
addIfPermissible(sender, options, "Magic.commands.magic.list", "schematics");
addIfPermissible(sender, options, "Magic.commands.magic.list", "entities");
addIfPermissible(sender, options, "Magic.commands.magic.list", "tasks");
addIfPermissible(sender, options, "Magic.commands.magic.list", "blocks");
addIfPermissible(sender, options, "Magic.commands.magic.list", "mages");
} else if (args[0].equalsIgnoreCase("give") || args[0].equalsIgnoreCase("worth") || args[0].equalsIgnoreCase("sell")) {
options.add("wand");
options.add("material");
options.add("upgrade");
Collection<SpellTemplate> spellList = api.getSpellTemplates(sender.hasPermission("Magic.bypass_hidden"));
for (SpellTemplate spell : spellList) {
options.add(spell.getKey());
}
Collection<String> allWands = api.getWandKeys();
for (String wandKey : allWands) {
options.add(wandKey);
}
options.addAll(api.getBrushes());
}
} else if (args.length == 3) {
if (args[0].equalsIgnoreCase("give") || args[0].equalsIgnoreCase("sell")) {
if (args[1].equalsIgnoreCase("upgrade") || args[1].equalsIgnoreCase("wand")) {
Collection<String> allWands = api.getWandKeys();
for (String wandKey : allWands) {
options.add(wandKey);
}
} else if (args[1].equalsIgnoreCase("material")) {
options.addAll(api.getBrushes());
}
} else if (args[0].equalsIgnoreCase("configure") || args[0].equalsIgnoreCase("describe")) {
Player player = DeprecatedUtils.getPlayer(args[1]);
if (player != null) {
Mage mage = controller.getMage(player);
ConfigurationSection data = mage.getData();
options.addAll(data.getKeys(false));
}
}
}
return options;
}
Aggregations