use of com.elmakers.mine.bukkit.wand.Wand in project MagicPlugin by elBukkit.
the class Mage method tick.
@Override
public void tick() {
if (isNPC)
return;
long now = System.currentTimeMillis();
if (entityData != null) {
if (lastTick != 0) {
long tickInterval = entityData.getTickInterval();
if (tickInterval > 0 && now - lastTick > tickInterval) {
updateVelocity();
entityData.tick(this);
lastTick = now;
}
} else {
lastTick = now;
}
} else {
updateVelocity();
lastTick = now;
}
// We don't tick non-player or offline Mages, except
// above where entityData is ticked if present.
Player player = getPlayer();
if (player != null && player.isOnline()) {
checkWand();
if (activeWand != null) {
activeWand.tick();
} else if (virtualExperience) {
resetSentExperience();
}
if (offhandWand != null) {
offhandWand.tick();
}
if (activeClass != null) {
activeClass.tick();
}
properties.tick();
if (Wand.LiveHotbarSkills && (activeWand == null || !activeWand.isInventoryOpen())) {
updateHotbarStatus();
}
// it turns out that is not easy to check efficiently.
if (JUMP_EFFECT_FLIGHT_EXEMPTION_DURATION > 0 && player.hasPotionEffect(PotionEffectType.JUMP)) {
controller.addFlightExemption(player, JUMP_EFFECT_FLIGHT_EXEMPTION_DURATION);
}
for (Wand armorWand : activeArmor.values()) {
armorWand.updateEffects(this);
}
// Copy this set since spells may get removed while iterating!
List<MageSpell> active = new ArrayList<>(activeSpells);
for (MageSpell spell : active) {
spell.tick();
if (!spell.isActive()) {
deactivateSpell(spell);
}
}
}
}
use of com.elmakers.mine.bukkit.wand.Wand in project MagicPlugin by elBukkit.
the class Mage method restoreWand.
@Override
public boolean restoreWand() {
if (boundWands.size() == 0)
return false;
Player player = getPlayer();
if (player == null)
return false;
Set<String> foundTemplates = new HashSet<>();
ItemStack[] inventory = getInventory().getContents();
for (ItemStack item : inventory) {
if (Wand.isWand(item)) {
Wand tempWand = controller.getWand(item);
String template = tempWand.getTemplateKey();
if (template != null) {
foundTemplates.add(template);
}
}
}
inventory = player.getEnderChest().getContents();
for (ItemStack item : inventory) {
if (Wand.isWand(item)) {
Wand tempWand = controller.getWand(item);
String template = tempWand.getTemplateKey();
if (template != null) {
foundTemplates.add(template);
}
}
}
int givenWands = 0;
for (Map.Entry<String, Wand> wandEntry : boundWands.entrySet()) {
if (foundTemplates.contains(wandEntry.getKey()))
continue;
givenWands++;
ItemStack wandItem = wandEntry.getValue().duplicate().getItem();
wandItem.setAmount(1);
giveItem(wandItem);
}
return givenWands > 0;
}
use of com.elmakers.mine.bukkit.wand.Wand in project MagicPlugin by elBukkit.
the class Mage method checkWand.
@Nullable
private Wand checkWand(ItemStack itemInHand) {
Player player = getPlayer();
if (isLoading() || player == null)
return null;
ItemStack activeWandItem = activeWand != null ? activeWand.getItem() : null;
if (InventoryUtils.isSameInstance(activeWandItem, itemInHand))
return activeWand;
if (!Wand.isWand(itemInHand))
itemInHand = null;
if ((itemInHand != null && activeWandItem == null) || (activeWandItem != null && itemInHand == null) || (activeWandItem != null && itemInHand != null && !itemInHand.equals(activeWandItem))) {
if (activeWand != null) {
activeWand.deactivate();
}
if (itemInHand != null && controller.hasWandPermission(player)) {
Wand newActiveWand = controller.getWand(itemInHand);
if (!newActiveWand.activate(this)) {
setActiveWand(null);
}
}
}
return activeWand;
}
use of com.elmakers.mine.bukkit.wand.Wand in project MagicPlugin by elBukkit.
the class MagicController method checkForItem.
public boolean checkForItem(Player player, ItemStack requireItem, boolean take) {
boolean foundItem = false;
ItemStack[] contents = player.getInventory().getContents();
for (int i = 0; i < contents.length; i++) {
ItemStack item = contents[i];
if (itemsAreEqual(item, requireItem)) {
Wand wand = null;
if (Wand.isWand(item) && Wand.isBound(item)) {
wand = getWand(item);
if (!wand.canUse(player))
continue;
}
if (take) {
player.getInventory().setItem(i, null);
if (wand != null) {
wand.unbind();
}
}
foundItem = true;
break;
}
}
return foundItem;
}
use of com.elmakers.mine.bukkit.wand.Wand in project MagicPlugin by elBukkit.
the class CasterProperties method updateMaxMana.
public boolean updateMaxMana(Mage mage) {
if (!usesMana()) {
return false;
}
int currentMana = effectiveManaMax;
int currentManaRegen = effectiveManaRegeneration;
float effectiveBoost = getManaMaxBoost();
float effectiveRegenBoost = getManaRegenerationBoost();
if (mage != null) {
Collection<Wand> activeArmor = mage.getActiveArmor();
for (Wand armorWand : activeArmor) {
effectiveBoost += armorWand.getManaMaxBoost();
effectiveRegenBoost += armorWand.getManaRegenerationBoost();
}
Wand activeWand = mage.getActiveWand();
if (activeWand != null && !activeWand.isPassive()) {
effectiveBoost += activeWand.getManaMaxBoost();
effectiveRegenBoost += activeWand.getManaRegenerationBoost();
}
Wand offhandWand = mage.getOffhandWand();
if (offhandWand != null && !offhandWand.isPassive()) {
effectiveBoost += offhandWand.getManaMaxBoost();
effectiveRegenBoost += offhandWand.getManaRegenerationBoost();
}
}
boolean boostable = getBoolean("boostable", true);
effectiveManaMax = getManaMax();
if (boostable && effectiveBoost != 0) {
effectiveManaMax = (int) Math.ceil(effectiveManaMax + effectiveBoost * effectiveManaMax);
}
effectiveManaRegeneration = getManaRegeneration();
if (boostable && effectiveRegenBoost != 0) {
effectiveManaRegeneration = (int) Math.ceil(effectiveManaRegeneration + effectiveRegenBoost * effectiveManaRegeneration);
}
return (currentMana != effectiveManaMax || effectiveManaRegeneration != currentManaRegen);
}
Aggregations