Facebook
From Saiyen, 3 Months ago, written in Java.
Embed
Download Paste or View Raw
Hits: 51
  1. package me.saiyen.saibomba;
  2.  
  3. import net.minecraft.server.v1_12_R1.BlockPortal;
  4. import org.bukkit.*;
  5. import org.bukkit.enchantments.Enchantment;
  6. import org.bukkit.entity.EntityType;
  7. import org.bukkit.entity.Player;
  8. import org.bukkit.entity.TNTPrimed;
  9. import org.bukkit.event.EventHandler;
  10. import org.bukkit.event.Listener;
  11. import org.bukkit.event.block.Action;
  12. import org.bukkit.event.block.BlockPlaceEvent;
  13. import org.bukkit.event.player.PlayerInteractEvent;
  14. import org.bukkit.inventory.ItemFlag;
  15. import org.bukkit.inventory.ItemStack;
  16. import org.bukkit.inventory.ShapedRecipe;
  17. import org.bukkit.inventory.meta.ItemMeta;
  18. import org.bukkit.plugin.java.JavaPlugin;
  19.  
  20. import java.util.Arrays;
  21.  
  22. public class Main extends JavaPlugin implements Listener {
  23.     private double silaRzutu = 1.2;
  24.     private int rzut = 25;
  25.     ItemStack sbItem = new ItemStack(Material.TNT);
  26.     ItemMeta sbItemMeta = sbItem.getItemMeta();
  27.     ShapedRecipe sbNewRecipe;
  28.  
  29.     @Override
  30.     public void onEnable() {
  31.         getLogger().info(ChatColor.translateAlternateColorCodes('&', "&aSG-SaiBomba WĹ‚Ä…czony"));
  32.         Bukkit.getServer().getPluginManager().registerEvents(this,this);
  33.         sbRecipe();
  34.  
  35.     }
  36.  
  37.     @Override
  38.     public void onDisable() {
  39.         getLogger().info(ChatColor.translateAlternateColorCodes('&', "&cSG-SaiBomba WyĹ‚Ä…czony"));
  40.     }
  41.  
  42.     @EventHandler
  43.     public void onClick(PlayerInteractEvent event){
  44.         Player player = event.getPlayer();
  45.         if((event.getAction().equals(Action.RIGHT_CLICK_AIR))&& (player.getInventory().getItemInMainHand().getItemMeta().equals(sbItemMeta))){
  46.             if(player.getLocation().getX()>600 || player.getLocation().getX()<-60 || player.getLocation().getZ()>316 || player.getLocation().getZ()<-343) {
  47.                 if (player.getGameMode().equals(GameMode.CREATIVE)) {
  48.                     shootSaiBomba(player, false, silaRzutu, rzut);
  49.                 } else {
  50.                     shootSaiBomba(player, true, silaRzutu, rzut);
  51.                 }
  52.             }
  53.         }
  54.     }
  55.  
  56.     @EventHandler
  57.     public void onPlace(BlockPlaceEvent event){
  58.         Player player = event.getPlayer();
  59.         if(event.getBlock().getType().equals(Material.TNT) && event.getItemInHand().getItemMeta().equals(sbItemMeta)){
  60.             event.getBlock().setType(Material.AIR);
  61.             TNTPrimed tnt = (TNTPrimed)player.getWorld().spawnEntity(new Location(player.getWorld(), player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ()), EntityType.PRIMED_TNT);
  62.             tnt.setVelocity(player.getLocation().getDirection().multiply(silaRzutu));
  63.             tnt.setFuseTicks(rzut);
  64.         }
  65.     }
  66.  
  67.     public static void shootSaiBomba(Player player, boolean takeItem, double silaRzutu, int rzut) {
  68.         if (takeItem) {
  69.             if (player.getInventory().getItemInMainHand().getAmount() == 1) {
  70.                 player.getInventory().setItemInMainHand((ItemStack)null);
  71.             } else {
  72.                 player.getInventory().getItemInMainHand().setAmount(player.getInventory().getItemInMainHand().getAmount() - 1);
  73.             }
  74.             }
  75.         TNTPrimed tnt = (TNTPrimed)player.getWorld().spawnEntity(new Location(player.getWorld(), player.getLocation().getX(), player.getLocation().getY() + 1.2D, player.getLocation().getZ()), EntityType.PRIMED_TNT);
  76.         tnt.setVelocity(player.getLocation().getDirection().multiply(silaRzutu));
  77.         tnt.setFuseTicks(rzut);
  78.         }
  79.  
  80.     public void sbRecipe(){
  81.         sbItemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&',"&6&lSaiBomba"));
  82.         sbItemMeta.setLore(Arrays.asList("",ChatColor.translateAlternateColorCodes('&', "&7- &9Masz jakiĹ› zapĹ‚on?"),
  83.                 ChatColor.translateAlternateColorCodes('&', "&7- &aJak po fasoli!"),
  84.                 ChatColor.translateAlternateColorCodes('&', "&7- &9BÄ™dzie bomba!"),"",
  85.                 ChatColor.translateAlternateColorCodes('&', "&c&oUWAGA, NIEBEZPIECZNE!")));
  86.         sbItemMeta.addEnchant(Enchantment.LUCK, 1, true);
  87.         sbItemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
  88.         sbItem.setItemMeta(sbItemMeta);
  89.         sbNewRecipe = new ShapedRecipe(sbItem);
  90.         sbNewRecipe.shape("sds","d#d","sds");
  91.         sbNewRecipe.setIngredient('#', Material.TNT);
  92.         sbNewRecipe.setIngredient('s', Material.EMERALD_BLOCK);
  93.         sbNewRecipe.setIngredient('d', Material.DIAMOND_BLOCK);
  94.         getServer().addRecipe(sbNewRecipe);
  95.     }
  96. }
  97.