Last active
August 16, 2017 22:58
-
-
Save chunte/eeeb37e1db63c5c7a4a3f04ec121a5b9 to your computer and use it in GitHub Desktop.
SpawningBow - spigot 1.11.2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tutorial.spigot.plugins; | |
import org.bukkit.plugin.java.JavaPlugin; | |
public class Main extends JavaPlugin{ | |
@Override | |
public void onEnable() { | |
getLogger().info("Dr Ewe's plugin is enabled"); | |
getServer().getPluginManager().registerEvents(new SpawningBow(), this); | |
} | |
@Override | |
public void onDisable() { | |
getLogger().info("Dr Ewe's plugin is disabled"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tutorial.spigot.plugins; | |
import org.bukkit.Material; | |
import org.bukkit.enchantments.Enchantment; | |
import org.bukkit.entity.Arrow; | |
import org.bukkit.entity.Entity; | |
import org.bukkit.entity.Player; | |
import org.bukkit.entity.Projectile; | |
import org.bukkit.event.EventHandler; | |
import org.bukkit.event.Listener; | |
import org.bukkit.event.entity.ProjectileLaunchEvent; | |
import org.bukkit.inventory.ItemStack; | |
import org.bukkit.inventory.meta.SpawnEggMeta; | |
public class SpawningBow implements Listener { | |
@EventHandler | |
public void spawningArrows(ProjectileLaunchEvent event){ | |
Projectile projectile = event.getEntity(); | |
Player player = (Player) projectile.getShooter(); | |
if(!(projectile instanceof Arrow | |
&& projectile.getShooter() instanceof Player | |
&& player.getInventory().getItemInMainHand().getType() == Material.BOW | |
&& player.getInventory().getItemInOffHand().getType() == Material.MONSTER_EGG )) { | |
return; | |
} | |
ItemStack bow = player.getInventory().getItemInMainHand(); | |
ItemStack offHand = player.getInventory().getItemInOffHand(); | |
SpawnEggMeta sem = (SpawnEggMeta) offHand.getItemMeta(); | |
Entity ent = player.getWorld().spawn(player.getLocation(), sem.getSpawnedType().getEntityClass() ); | |
ent.setVelocity(projectile.getVelocity()); | |
event.setCancelled(true); | |
if (bow.getEnchantments().containsKey(Enchantment.ARROW_DAMAGE)) { | |
ent.setVelocity(ent.getVelocity().multiply(bow.getEnchantmentLevel(Enchantment.ARROW_DAMAGE) + 1)); | |
} | |
if (bow.getEnchantments().containsKey(Enchantment.ARROW_FIRE)) { | |
ent.setFireTicks(bow.getEnchantmentLevel(Enchantment.ARROW_FIRE) * 100); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment