tv_game.dev

צור פלאגין לדוגמה

Kodari AI
KodariMay 20 at 8:04 pm 10,278 (v2)

I’ll create a simple home teleportation plugin that demonstrates common Minecraft plugin patterns.

PlayerHomes
A lightweight home teleportation system allowing players to set and manage personal home locations. Features include multiple home support, configurable cooldowns, customizable messages, and safe teleportation checks. Players can set homes in any world they have access to, delete unwanted homes, and instantly teleport back. Includes permission nodes for limiting home slots and bypassing cooldowns. Perfect example of command handling, data persistence, and player interaction.

Now I’ll create the complete plugin structure:

Perfect! I’ve created a complete example plugin with the following features:

Structure:

  • ✅ Main plugin class with manager initialization

  • ✅ Four commands: /sethome, /home, /delhome, /homes

  • ✅ Three managers: Config, Home storage, Teleport handling

  • ✅ Event listener for teleport cancellation

  • ✅ Data persistence in YAML format

Features demonstrated:

  • Command registration and execution

  • Configuration management with customizable messages

  • Data persistence (homes saved to homes.yml)

  • Permission-based limits (max homes per player)

  • Cooldown and delay system

  • Event listening (movement, damage, quit)

  • Safe location checking

  • HashMap-based data caching

Key learning points:

  • Manager pattern for organized code

  • Lombok usage for reduced boilerplate

  • Proper Bukkit task scheduling

  • Message formatting with placeholders

  • Permission-based feature access

The plugin is production-ready and follows Minecraft plugin best practices!

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
15 831
src/main/java/com/example/playerhomes/PlayerHomes.java
package com.example.playerhomes;

import com.example.playerhomes.commands.DelHomeCommand;
import com.example.playerhomes.commands.HomeCommand;
import com.example.playerhomes.commands.HomesCommand;
import com.example.playerhomes.commands.SetHomeCommand;
import com.example.playerhomes.listeners.PlayerListener;
import com.example.playerhomes.managers.ConfigManager;
import com.example.playerhomes.managers.HomeManager;
import com.example.playerhomes.managers.TeleportManager;
import lombok.Getter;
import org.bukkit.plugin.java.JavaPlugin;

@Getter
public class PlayerHomes extends JavaPlugin {
    
    private ConfigManager configManager;
    private HomeManager homeManager;
    private TeleportManager teleportManager;
    
    @Override
    public void onEnable() {
        // Save default config
        saveDefaultConfig();
        
        // Initialize managers
        this.configManager = new ConfigManager(this);
        this.homeManager = new HomeManager(this);
        this.teleportManager = new TeleportManager(this);
        
        // Register commands
        getCommand("sethome").setExecutor(new SetHomeCommand(this));
        getCommand("home").setExecutor(new HomeCommand(this));
        getCommand("delhome").setExecutor(new DelHomeCommand(this));
        getCommand("homes").setExecutor(new HomesCommand(this));
        
        // Register listeners
        getServer().getPluginManager().registerEvents(new PlayerListener(this), this);
        
        getLogger().info("PlayerHomes has been enabled!");
    }
    
    @Override
    public void onDisable() {
        // Save all homes
        if (homeManager != null) {
            homeManager.saveAllHomes();
        }
        
        // Cancel all pending teleports
        if (teleportManager != null) {
            teleportManager.cancelAllTeleports();
        }
        
        getLogger().info("PlayerHomes has been disabled!");
    }
}