Magic

Magic

190k Downloads

Problem with MagicAPI

Blamo27 opened this issue · 50 comments

commented

Hello, I have a problem with the MagicAPI.

Can you contact me on Skype ?
My Skype: dr.blamo

Thanks.

commented

Ow.. because it's working when I execute the command IG.

/wand configure xp_max_boost 100

But it's not working using the MagicAPI

commented

That will show up in lore as a boost on the wand, but I don't think it actually has any effect.

That command also does the equivalent of what I wrote above- mage.getActiveWand().configure()

commented

No, the effect is ok.
For instance when I run this command :
/wand configure xp_max_boost 1
I have 400 mana, I can cast a spell of 200 mana twice

commented
commented

I'm not really sure where you're at right now, sorry. Are you using mage.getActiveWand() ?

Calling configure() on a Wand instance is exactly what the "/wand configure" command does, so if you're not getting the same results that is very odd.

commented

I'm using getWand, with the WandActivatedEvent

commented

it could be something weird with that event- have you tried calling setName() or some other method that would create a really obvious effect?

commented

Even though the wand description (lore) changes, so that we can SEE the boost written in the description, that boost is in fact not active. It's just written, and that's it.
Without setName().

commented

What I was trying to tell you before is boosts don't work on wands, that's only for armor. Shouldn't make a difference how you set it.

At least, it's not intentional for it to work on wands. If you want to increase max mana of a wand, just increase the max mana.

Boost is meant for armor- so for instance you can wear the full set of Wizard's Robes and your wand will get a boost to max mana and regeneration.

commented

Yes but the effect work when I execute the command in-game :

/wand configure xp_max_boost 1

Not working with :

Configure(p, "xp_max_boost", 1.f);

commented

I have no idea why that would be, just that I know it's not intended to work on wands. The behavior may be unpredictable.

If you think it's working the way you want when using the configure command, maybe try calling Wand.deactivate() before configure, and activate() after. Looking at the code for the "configure" command, that's all it does differently (all of the commands use the API):

https://github.com/elBukkit/MagicPlugin/blob/master/Magic/src/main/java/com/elmakers/mine/bukkit/magic/command/WandCommandExecutor.java#L887

I do want to stress yet again that it's not intentional if it does work that way. I really didn't think the code even looked at the boost attributes on wands at all.

commented

It's working when I deactivate / activate, but it's flooding the event :/

//Mage mage = instance.getMagicAPI().getMage(p);

//instance.getMagicAPI().getWand(p.getItemInHand()).deactivate();
instance.mage.Configure(p, "xp_max_boost", 1.f);
//instance.getMagicAPI().getWand(p.getItemInHand()).activate(mage);
commented

Oh yeah.. since an activate would fire the event :\

Um- maybe can you tell me what exactly you're trying to accomplish? Maybe there's a simpler way.

commented

Well, I want to create a plugin that allows players to customize their armors with gems. For short, you can put "intelligence gems" on your armor to boost your maximum mana and your spell damage. You can put up to six gems on a single piece of armor. In such a case, each gem must increase the maximum mana of the player by five (3 gems = +15 max mana).

commented

Might be interesting to do that with crafting- I'm not sure if you could simply config it in Magic (maybe), but making a custom crafting plugin that adds mana boosts to armor would be pretty easy.

If you're applying the bonuses to armor, I don't think you have to worry about the activate event, or activating/deactivating a wand. Especially if the armor is in a workbench when it gets upgraded.

If you want to update a piece of armor while a player is wearing it, there is no API method for updating but I could add one. Mage.armorUpdated is the method you'd want to call, but it's not currently exposed in the API.

commented

The thing is, you don't actually craft the armor (in a workbench), you go see a NPC that pops up a menu where you put the armor and the gem, the plugin takes them and give you the updated armor. However, the armor may be updated while the player is wearing it by many ways : the armor breaks, the player goes in a world with different inventory, the player joins a mobarena, etc. In thoses cases, the armor of the player is removed without any actual action from him.

commented

That sounds cool!

And .. I may be missing something, but this sounds a lot easier than you're making it out to be.. maybe!

So when the NPC is giving the player their armor, you could do this like:

MageController controller = magicAPI.getController();
Wand enchantedArmor = controller.getWand(theArmorItemStack);

// It occurs to me that I could add some accessor methods here to make this easier..
Map<String, Object> properties = new HashMap<String, Object>();
properties.set("mana_max_boost", 2.0);
enchantedArmor.configure(properties);
// The itemstack *may* be changed here, though probably not.
theArmorItemStack = enchantedArmor.getItem();
// Then give this ItemStack to the player

They will then have a piece of armor that, when worn, will increase their mana. If they lose the armor, they lose the mana boost.

Does that sound like what you want?

commented

I'll try that a bit later, I have to go now, but that sounds like something that could work with what I want ! I will keep you updated as soon as I'll try it.

Thank you !

commented

I tried your solution, but your plugin removes lores.
And my plugin uses lores to add some abilities.

Is there a way to keep lores ?

commented

Not really, no. I don't think you're going to be able to make wands useable by a plugin that needs specific lore.

You can mess with the description, but that's just one line.

commented

Yes but my server is still on 1.8.9 version :/

The WandPreActivateEvent is working but there is a bug, the method that is configuring the wand need to be fired twice to refresh correctly the wand.

commented

So does that mean you found a workaround and got it working? Or no?

The 1.8 builds of Magic aren't going to be getting any major updates.

commented

Yes it's working but I have to trigger event at two times.

instance.mage.Configure(p, "xp_max", mana);
instance.mage.Configure(p, "xp_max", mana);
commented

Looking at the code, one ugly work-around for this might be to call Wand.armorUpdated after you call Configure.

You'd need to cast the API Wand to com.elmakers.mine.bukkit.wand.Wand since this method is not exposed to the API.

commented

Could you add the possibility to add a lore with your plugin, that stays ? That would be very useful, with something like : magicAPI.lore.add(String text);

commented

No, not easily. The lore is all dynamically added based on Wand NBT data. It'd be extremely non-trivial to add arbitrary lore. Sorry!

commented

Or a possibility to add xp_max_boost on a wand ? :/

commented

I still don't get why you need that? It makes very little sense- a boost is meant to boost a wand via an accessory item. Wands themselves have max mana that you can just increase if you want more mana on it.

commented

The boost will apply a bonus of mana, so I don't have to get the mana of a wand, and players could compare the base mana with the armor mana.

commented

Hm, alright. Well looking at the code I may be mistaken, it looks like boosts on wands ought to work, so long as it's their active wand.

Mana boost calculation starts with the wand's boost and adds in any boosts from the armor.

It looks like you were seeing this working, so maybe the only problem is that you have to deactivate+reactivate the wand while configuring, and you can't really do that during the wand activate event? It should work fine if you're doing some sort of "give your wand to an NPC to get a boost" thing though.

commented

Not with an NPC, if they unequip their armor, they can save the mana and try glitch.
The only problem, it will deactivate / reactivate when the player call the WandActivatedEvent.

commented

I'm extremely confused about what you're trying to do.

If you want a mana boost when the player is wearing certain armor, the mana boost goes on the armor, not on the wand.

Magic will handle applying the boost when the player wears and removes armor. There is no need to mess with the wand data yourself.

commented

I want to apply a mana boost on the wand, to prevent glitches that would happen if it was applied to the armor. Furthermore, with xp_max, it wouldn't be possible to add directly mana on the wand, otherwise I would need to find a solution to save the base mana of the wand. I must use xp_max_boost to achieve what I want to do.

The boosts will be updated each time the player calls the event WandActivatedEvent, because it's not Magic which will define the % boost, it will be the lores on the armor, via my plugin, wich will apply certain Magic effects.

commented

Ah so the part I was missing is that you're trying to use your own lore-based plugin so you can't use the feature that is, sadly, made specifically for what you're trying to do.

Oh well...

Offhand it looks like if you switch to the PreActivateEvent it should work. Try this with just configure(), no need to deactivate and reactivate.

commented

But I can't find the PreActivateEvent

commented

Make sure you're building against the latest Magic, that event is relatively new (like a few months old)- 6.2.2 is the latest version, Maven should be able to find it.

commented

Okey, I'll try thanks :)

I wanted to know to if I can make a MagicItem unstackable.
The item name must be bold & green colored.

commented
commented

Um.. I don't think I have anything in the configuration to allow that directly. As far as I know the only way to do that is to put some random NBT data on the item.

commented

Okey, thanks :)

commented

And can't we add a green colored, bold, name on a magic item ?

commented
commented

I'll try thanks

commented

Hey sorry I never responded to this - but yes you can use & escape codes to do color and formatting in magic item and wands names. Hope you figured it out!

commented

I don't get on Skype or do live chat (sorry!) but I'd be happy to help here if you can elaborate.

commented

When I configure the wand to add a property It doesn't work.
The property appear in the Wand description only, but has no actual effect.

(With the MagicAPI ==> configure)

commented

If it shows in the lore it should be active- lore is dynamically generated from the wand properties.

Could you please paste the code you're using and let me know the effects and what you expect to see?

commented
public void mana(Player p) throws SQLException {

    int volontecount = instance.getArmorLores(p, "Volonté");

    if (volontecount == 0) return;

    float mana = (float)volontecount * (1.f/24.f); p.sendMessage("0");
    instance.mage.Configure(p, "xp_max_boost", mana);

}
commented

Hm- I don't think there is a "configure" method on Mage, does that code compile?

If you want to configure the wand the player is holding, it'd be like mage.getActiveWand().configure().

Also "xp_max_boost" doesn't work on wands, that's only for armor- and there isn't an API to get armor, I don't think. You'd have to get the ItemStack from the Player inventory, then wrap it in a Wand and use configure on that.

If you just want to raise the max mana on a wand it'd be "mana_max"