package com.custombreads;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
public class Main extends JavaPlugin implements Listener {
private final Map breadPowers = new HashMap<>();
@Override
public void onEnable() {
getServer().getPluginManager().registerEvents(this, this);
setupBreads();
getLogger().info("25 Custom Breads Plugin successfully loaded!");
}
// Yahan 25 Breads aur unki powers define ki gayi hain (No modification needed)
private void setupBreads() {
int duration = 600; // 30 seconds (20 ticks = 1 second)
breadPowers.put("§bFlash Bread", new PotionEffect(PotionEffectType.SPEED, duration, 1));
breadPowers.put("§aHulk Bread", new PotionEffect(PotionEffectType.INCREASE_DAMAGE, duration, 1));
breadPowers.put("§7Ninja Bread", new PotionEffect(PotionEffectType.INVISIBILITY, duration, 0));
breadPowers.put("§dRabbit Bread", new PotionEffect(PotionEffectType.JUMP, duration, 1));
breadPowers.put("§8Iron Bread", new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, duration, 1));
breadPowers.put("§cFire Bread", new PotionEffect(PotionEffectType.FIRE_RESISTANCE, duration, 0));
breadPowers.put("§3Fish Bread", new PotionEffect(PotionEffectType.WATER_BREATHING, duration, 0));
breadPowers.put("§eOwl Bread", new PotionEffect(PotionEffectType.NIGHT_VISION, duration, 0));
breadPowers.put("§6Miner Bread", new PotionEffect(PotionEffectType.FAST_DIGGING, duration, 1));
breadPowers.put("§dHealer Bread", new PotionEffect(PotionEffectType.REGENERATION, duration, 1));
breadPowers.put("§cTank Bread", new PotionEffect(PotionEffectType.HEALTH_BOOST, duration, 1));
breadPowers.put("§fGhost Bread", new PotionEffect(PotionEffectType.SLOW_FALLING, duration, 0));
breadPowers.put("§bDolphin Bread", new PotionEffect(PotionEffectType.DOLPHINS_GRACE, duration, 0));
breadPowers.put("§eGlow Bread", new PotionEffect(PotionEffectType.GLOWING, duration, 0));
breadPowers.put("§aLucky Bread", new PotionEffect(PotionEffectType.LUCK, duration, 1));
breadPowers.put("§4Vampire Bread", new PotionEffect(PotionEffectType.ABSORPTION, duration, 1));
// Advanced/Extreme Breads
breadPowers.put("§bSonic Bread", new PotionEffect(PotionEffectType.SPEED, duration, 3));
breadPowers.put("§cTitan Bread", new PotionEffect(PotionEffectType.INCREASE_DAMAGE, duration, 3));
breadPowers.put("§aSpring Bread", new PotionEffect(PotionEffectType.JUMP, duration, 3));
breadPowers.put("§0Obsidian Bread", new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, duration, 3));
breadPowers.put("§6God Bread", new PotionEffect(PotionEffectType.REGENERATION, duration, 3));
breadPowers.put("§5Wizard Bread", new PotionEffect(PotionEffectType.SATURATION, duration, 1));
breadPowers.put("§5Dragon Bread", new PotionEffect(PotionEffectType.LEVITATION, 100, 1));
// Funny/Troll Breads
breadPowers.put("§2Troll Bread", new PotionEffect(PotionEffectType.CONFUSION, duration, 0));
breadPowers.put("§8Blind Bread", new PotionEffect(PotionEffectType.BLINDNESS, duration, 0));
}
// Command to get all breads in game
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (command.getName().equalsIgnoreCase("givebreads") && sender instanceof Player) {
Player player = (Player) sender;
for (String name : breadPowers.keySet()) {
player.getInventory().addItem(createBread(name));
}
player.sendMessage(ChatColor.GREEN + "Aapko sab 25 Magical Breads mil chuki hain!");
return true;
}
return false;
}
// Bread item create karne ka function
private ItemStack createBread(String name) {
ItemStack bread = new ItemStack(Material.BREAD);
ItemMeta meta = bread.getItemMeta();
meta.setDisplayName(name);
meta.setLore(Arrays.asList(ChatColor.GRAY + "Khao aur power pao!"));
bread.setItemMeta(meta);
return bread;
}
// Event Listener: Jab player bread khaye
@EventHandler
public void onConsume(PlayerItemConsumeEvent event) {
ItemStack item = event.getItem();
if (item.getType() == Material.BREAD && item.hasItemMeta() && item.getItemMeta().hasDisplayName()) {
String name = item.getItemMeta().getDisplayName();
if (breadPowers.containsKey(name)) {
event.getPlayer().addPotionEffect(breadPowers.get(name));
event.getPlayer().sendMessage(ChatColor.GOLD + "Aapne " + name + ChatColor.GOLD + " khayi!");
}
}
}
}