name: CustomBreads version: 3.0 main: com.custombreads.Main api-version: 1.13 commands: givebreads: description: Gives you all 15 ability breads! usage: /givebreads
📎
1 file
9,903 chars
📄
pasted-code-1782973672114.txt
txt
223 lines
▶
pasted-code-1782973672114.txt
txt
223 lines
package com.custombreads;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.inventory.ItemFlag;
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.*;
public class Main extends JavaPlugin implements Listener {
private final Map> breadAbilities = new HashMap<>();
private final Map> deathStorage = new HashMap<>();
private final String LORE_TEXT = ChatColor.GRAY + "EAT TO GAIN POWER";
@Override
public void onEnable() {
getServer().getPluginManager().registerEvents(this, this);
setup15Breads();
getLogger().info("15 Custom Ability Breads Plugin Loaded Successfully!");
}
private void setup15Breads() {
// 5 Minutes = 300 seconds = 6000 ticks
int duration = 6000;
// PotionEffect constructor: (Type, Duration, Amplifier, Ambient, Particles, Icon)
// Setting the last three to 'false' hides the effect completely from the UI and player body.
breadAbilities.put("§6Zeus Bread", Arrays.asList(
new PotionEffect(PotionEffectType.SPEED, duration, 1, false, false, false),
new PotionEffect(PotionEffectType.INCREASE_DAMAGE, duration, 1, false, false, false)
));
breadAbilities.put("§bPoseidon Bread", Arrays.asList(
new PotionEffect(PotionEffectType.WATER_BREATHING, duration, 0, false, false, false),
new PotionEffect(PotionEffectType.DOLPHINS_GRACE, duration, 0, false, false, false)
));
breadAbilities.put("§cHephaestus Bread", Collections.singletonList(
new PotionEffect(PotionEffectType.FIRE_RESISTANCE, duration, 0, false, false, false)
));
breadAbilities.put("§dHermes Bread", Arrays.asList(
new PotionEffect(PotionEffectType.JUMP, duration, 2, false, false, false),
new PotionEffect(PotionEffectType.SPEED, duration, 2, false, false, false)
));
breadAbilities.put("§aChronos Bread", Collections.singletonList(
new PotionEffect(PotionEffectType.FAST_DIGGING, duration, 2, false, false, false)
));
breadAbilities.put("§eApollo Bread", Arrays.asList(
new PotionEffect(PotionEffectType.NIGHT_VISION, duration, 0, false, false, false),
new PotionEffect(PotionEffectType.REGENERATION, duration, 1, false, false, false)
));
breadAbilities.put("§5Merlin Bread", Collections.singletonList(
new PotionEffect(PotionEffectType.SATURATION, duration, 0, false, false, false)
));
breadAbilities.put("§8Titanium Bread", Arrays.asList(
new PotionEffect(PotionEffectType.HEALTH_BOOST, duration, 3, false, false, false),
new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, duration, 1, false, false, false)
));
breadAbilities.put("§fGhost Bread", Arrays.asList(
new PotionEffect(PotionEffectType.INVISIBILITY, duration, 0, false, false, false),
new PotionEffect(PotionEffectType.SLOW_FALLING, duration, 0, false, false, false)
));
breadAbilities.put("§4Vampire Bread", Collections.singletonList(
new PotionEffect(PotionEffectType.ABSORPTION, duration, 2, false, false, false)
));
breadAbilities.put("§2Ninja Bread", Arrays.asList(
new PotionEffect(PotionEffectType.SPEED, duration, 2, false, false, false),
new PotionEffect(PotionEffectType.INVISIBILITY, duration, 0, false, false, false)
));
breadAbilities.put("§cPhoenix Bread", Collections.singletonList(
new PotionEffect(PotionEffectType.REGENERATION, duration, 2, false, false, false)
));
breadAbilities.put("§eFortune Bread", Arrays.asList(
new PotionEffect(PotionEffectType.LUCK, duration, 2, false, false, false),
new PotionEffect(PotionEffectType.HERO_OF_THE_VILLAGE, duration, 1, false, false, false)
));
// Icarus handles custom flight logic, no potion effects needed here
breadAbilities.put("§bIcarus Bread", new ArrayList<>());
breadAbilities.put("§5Demigod Bread", Arrays.asList(
new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, duration, 2, false, false, false),
new PotionEffect(PotionEffectType.FIRE_RESISTANCE, duration, 0, false, false, false)
));
}
@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 : breadAbilities.keySet()) {
player.getInventory().addItem(createCustomBread(name));
}
player.sendMessage(ChatColor.GREEN + "You have received all 15 Magical Ability Breads!");
return true;
}
return false;
}
private ItemStack createCustomBread(String name) {
ItemStack bread = new ItemStack(Material.BREAD);
ItemMeta meta = bread.getItemMeta();
meta.setDisplayName(name);
meta.setLore(Collections.singletonList(LORE_TEXT));
// Adds the magical glowing glint effect without showing any enchantment text
meta.addEnchant(Enchantment.LURE, 1, true);
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
bread.setItemMeta(meta);
return bread;
}
@EventHandler
public void onInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
ItemStack item = event.getItem();
if (item != null && item.getType() == Material.BREAD && item.hasItemMeta() && item.getItemMeta().hasLore()) {
if (item.getItemMeta().getLore().contains(LORE_TEXT)) {
if (player.getFoodLevel() >= 20) {
player.setFoodLevel(19);
}
}
}
}
@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 (breadAbilities.containsKey(name)) {
event.setCancelled(true); // Keeps the bread in inventory
Player player = event.getPlayer();
if (name.contains("Icarus Bread")) {
player.setAllowFlight(true);
player.sendMessage(ChatColor.GOLD + "✨ You have unlocked the Icarus Ability (Flight) for 5 minutes!");
// Schedules a task to remove flight after 5 minutes (6000 ticks)
Bukkit.getScheduler().runTaskLater(this, () -> {
if (player.isOnline()) {
player.setAllowFlight(false);
player.sendMessage(ChatColor.RED + "Your Icarus flight ability has worn off!");
}
}, 6000L);
} else {
for (PotionEffect effect : breadAbilities.get(name)) {
player.addPotionEffect(effect);
}
player.sendMessage(ChatColor.GOLD + "✨ You have gained the " + name + ChatColor.GOLD + " ability for 5 minutes!");
}
}
}
}
@EventHandler
public void onDeath(PlayerDeathEvent event) {
Player player = event.getEntity();
List drops = event.getDrops();
List savedBreads = new ArrayList<>();
Iterator iterator = drops.iterator();
while (iterator.hasNext()) {
ItemStack item = iterator.next();
if (item != null && item.getType() == Material.BREAD && item.hasItemMeta() && item.getItemMeta().hasLore()) {
if (item.getItemMeta().getLore().contains(LORE_TEXT)) {
savedBreads.add(item.clone());
iterator.remove();
}
}
}
if (!savedBreads.isEmpty()) {
deathStorage.put(player.getUniqueId(), savedBreads);
}
}
@EventHandler
public void onRespawn(PlayerRespawnEvent event) {
Player player = event.getPlayer();
UUID uuid = player.getUniqueId();
if (deathStorage.containsKey(uuid)) {
List breadsToReturn = deathStorage.remove(uuid);
Bukkit.getScheduler().runTaskLater(this, () -> {
for (ItemStack bread : breadsToReturn) {
player.getInventory().addItem(bread);
}
player.sendMessage(ChatColor.AQUA + "🛡️ Your Magical Breads are safe and have been returned to your inventory!");
}, 5L);
}
}
}
KodariJul 2 at 6:29 am 1
I’ll create a structured, refactored plugin with proper class separation.
CustomBreads
A magical ability breads plugin featuring 15 unique bread types each granting special potion effects or flight abilities. Players gain powers by consuming breads from Greek mythology-themed types. Breads are preserved on death and returned on respawn. Includes a /givebreads command for administration.
Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
7 324
src/main/java/com/custombreads/Main.java
package com.custombreads;
import com.custombreads.listener.BreadListener;
import com.custombreads.manager.BreadManager;
import com.custombreads.model.BreadType;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin {
private BreadManager breadManager;
@Override
public void onEnable() {
breadManager = new BreadManager();
breadManager.initialize();
BreadListener listener = new BreadListener(this, breadManager);
Bukkit.getPluginManager().registerEvents(listener, this);
getLogger().info("15 Custom Ability Breads Plugin Loaded Successfully!");
}
@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 (BreadType type : breadManager.getAllBreads()) {
player.getInventory().addItem(breadManager.createBread(type));
}
player.sendMessage(ChatColor.GREEN + "You have received all 15 Magical Ability Breads!");
return true;
}
return false;
}
}