Veikka Vattulainen

Can you make a plugin when you pull a fishing rod it does a minecraft command /weather rain and you can give it to your self with a command like /giveRainrod

Kodari AI
KodariOct 1 at 11:06 am 1
RainRod
A Minecraft plugin that transforms a fishing rod into a weather-control tool. When a player pulls the fishing rod (right-click or casts it), the plugin automatically executes the /weather rain command, changing the in-game weather to rain. Players can obtain this special rod using the /giveRainrod command, which grants them the enchanted fishing rod item. The plugin listens for fishing rod interactions and triggers the weather change effect, providing a fun and interactive way to control weather conditions in the game world.
  • Create a Paper plugin with a marked Rain Rod and /giveRainrod.

  • Detect rod casts and dispatch /weather rain from the console.

Created the RainRod plugin. Players with permission rainrod.give can use /giveRainrod; casting that rod runs /weather rain through the console.

Kodari can make mistakes. Review important code before using.
Files
src
Code
2 86
src/main/java/com/kodari/rainrod/RainRodPlugin.java
package com.kodari.rainrod;

import com.cryptomorin.xseries.XMaterial;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.NamespacedKey;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
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.PlayerFishEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;

public final class RainRodPlugin extends JavaPlugin implements Listener, CommandExecutor {
    private NamespacedKey rainRodKey;

    @Override
    public void onEnable() {
        rainRodKey = new NamespacedKey(this, "rain_rod");
        getServer().getPluginManager().registerEvents(this, this);
        getCommand("giverainrod").setExecutor(this);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!(sender instanceof Player player)) {
            sender.sendMessage("Only players can receive a Rain Rod.");
            return true;
        }

        ItemStack rod = XMaterial.matchXMaterial("FISHING_ROD")
                .map(XMaterial::parseItem)
                .orElse(null);
        if (rod == null) {
            player.sendMessage(ChatColor.RED + "Could not create a fishing rod.");
            return true;
        }

        ItemMeta meta = rod.getItemMeta();
        meta.setDisplayName(ChatColor.AQUA + "Rain Rod");
        meta.getPersistentDataContainer().set(rainRodKey, PersistentDataType.BYTE, (byte) 1);
        rod.setItemMeta(meta);
        player.getInventory().addItem(rod);
        player.sendMessage(ChatColor.GREEN + "You received a Rain Rod!");
        return true;
    }

    @EventHandler
    public void onFish(PlayerFishEvent event) {
        if (event.getState() != PlayerFishEvent.State.FISHING) {
            return;
        }

        Player player = event.getPlayer();
        if (isRainRod(player.getInventory().getItemInMainHand())
                || isRainRod(player.getInventory().getItemInOffHand())) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "weather rain");
        }
    }

    private boolean isRainRod(ItemStack item) {
        if (item == null || item.getType().isAir() || !item.hasItemMeta()) {
            return false;
        }
        return item.getItemMeta().getPersistentDataContainer()
                .has(rainRodKey, PersistentDataType.BYTE);
    }
}