HELP! Someone banned me with a kick potion D:
Archives → Problems & bugs → HELP! Someone banned me with a kick potion D:
SOLVED
I am terribly sorry for the inconvenience. I’m currently in the process of writing a plugin which removes the potion from any inventory when being opened - this includes, but is not limited to chests, enderchests and player inventories.
The event which I’m using is Inventory.InventoryOpenEvent
, but I can’t figure out how to set the itemstack correctly. Would you be able to help me out on this? if you know how to do that, that would be great. I’m not really that pro with python.
In java I’d use:
That is written from the top of my head, so I can’t assure it working…
public void onInventoryOpen (InventoryOpenEvent e) {
Potion p = new Potion(PotionType type, int lvl); //PotionType.? - I think lvl = amplifier, so should be negative
if (e.getInventory().contains(p.toItemStack()) {
e.removeItem(p.toItemStack());
}
}
Ah, what just came to my mind: InventoryOpenEvent
won’t help. If someone /i’s a potion like this, it won’t be triggered and they won’t have to open their inventory to throw it at someone. I’ve tried some PotionSplashEvent
, but that doesn’t work either, because it is triggered when the potion hits something.
And, as a fancy addon feature, you could add that staff will be notified if any of those potions are deleted out of an inventory or thrown.
You could even automatically kill the player hit.
Hmm thats quite nice, but its e.remove(ItemStack item)
I wasn’t quite sure how to make it happen. I can tell you whats returned by the potion if you look for it in your first hotbar slot:
CraftItemStack: ItemStack{POTION x 1, POTION_META:{meta-type=POTION, display-name=CP, custom-effects=[HEALTH_BOOST:3000t-x-120]}}
I was personally going to use InventoryOpenEvent in the first place, but asecta told me to use ProjectileLaunchEvent, which works too. The part that doesnt work is getting to the eventhandler it seems… It just doesnt work.
What you’d have to do with projectile launch event would be: (I’m not 100% sure if this will work)
public void onEvent(ProjectileLaunchEvent event) {
Projectile projectile = event.getEntity();
try {
Player player = (Player) projectile.getShooter();
ThrownPotion potion = (ThrownPotion) projectile;
} catch (Exception e) {
return;
}
for (PotionEffect effect : potion.getEffects()) {
if (effect.getAmplifier() > 4 || effect.getAmplifier() < 0)
event.setCancelled(true);
}
if (event.isCancelled()) {
Inventory inventory = player.getInventory();
# Here you have to remove the item which I don't know how to do from the top of my head.
player.kickPlayer("OP Potions are not tolerated on this server.");
}
}
public void onEvent(ProjectileLaunchEvent event)
{
Projectile projectile = event.getEntity();
try
{
Player player = (Player) projectile.getShooter();
ThrownPotion potion = (ThrownPotion) projectile;
}
catch (Exception e)
{
return;
}
for (PotionEffect effect : potion.getEffects())
{
if (effect.getAmplifier() > 4 || effect.getAmplifier() < 0)
{
event.setCancelled(true);
}
}
if (event.isCancelled())
{
Inventory inventory = player.getInventory();
# Here you have to remove the item which I don't know how to do from the top of my head.
player.kickPlayer("OP Potions are not tolerated on this server.");
}
}
Sorry i really had to, othwise i can't read it and get it
Sorry for any typos, mostly Typing of my phone atm.
I have tried to put that into python - but Python is not my strongest language. Don’t be mad :3
import org.bukkit as noreply+1100@redstoner.com("ProjectileLaunchEvent","monitor")
def onPotion(event):
projectile = event.getEntity()
try:
player = projectile.getShooter()
potion = #Parsing in python? No idea again sorry
for effect in potion.getEffects():
if effect.getAmplifier() > 4 or effect.getAmplifier() < 0:
event.setCancelled(true)
if event.isCancelled():
inventory = player.getInventory()
inventory.removeItem(potion.toItemStack()) #Like this?
player.kickPlayer("OP Potions are not tolerated on this server.")
#Notifying staff? Does staff have op? Otherwise with a perm.
for p in bukkit.getServer().getOnlinePlayers():
if p.isOp():
p.sendMessage(player.getName() + "threw a potion.")
That staff notifying part can of course also be: (I don’t know how you handle these)
for p in bukkit.getServer().getOnlinePlayers():
if p.hasPermission("some.permission"):
p.sendMessage(player.getName() + "threw a potion.")
You’ve written that if cancelled initially, I just copied it ;)
And yes, would make removing it easier.