Files
src
economy.sk
home.sk
menu.sk
pom.xml
shop.sk
tpa.sk
Code
9 1,740
src/main/java/com/kodari/KodariPlugin.java
package com.kodari;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockExplodeEvent;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;
import org.bukkit.NamespacedKey;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.event.inventory.ClickType;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
public final class KodariPlugin extends org.bukkit.plugin.java.JavaPlugin implements Listener, CommandExecutor {
private static final String ECONOMY = "&d[경제]&r ";
private static final String HOME = "&d[집]&r ";
private static final String TPA = "&d[TPA]&r ";
private static final String SHOP = "&d[상점]&r ";
private final Map<UUID, Long> balances = new HashMap<>();
private final Map<UUID, Location> homes = new HashMap<>();
private final Map<String, UUID> homeOwners = new HashMap<>();
private final Map<UUID, UUID> tpaRequests = new HashMap<>();
private final Map<UUID, BukkitTask> requestExpiry = new HashMap<>();
private final Map<UUID, PendingTeleport> pendingTeleports = new HashMap<>();
private final Map<String, List<ShopItem>> shopItems = new LinkedHashMap<>();
private NamespacedKey homeItemKey;
private File dataFile;
private FileConfiguration data;
@Override
public void onEnable() {
saveDefaultConfig();
homeItemKey = new NamespacedKey(this, "home_magnet");
dataFile = new File(getDataFolder(), "data.yml");
data = YamlConfiguration.loadConfiguration(dataFile);
loadData();
createShopItems();
getServer().getPluginManager().registerEvents(this, this);
for (String commandName : Arrays.asList("balance", "pay", "give-money", "home", "home-reset", "home-give", "tpa", "tpaccept", "tpdeny", "anvil")) {
if (getCommand(commandName) != null) {
getCommand(commandName).setExecutor(this);
}
}
getLogger().info("KodariServer가 활성화되었습니다.");
}
@Override
public void onDisable() {
for (BukkitTask task : requestExpiry.values()) {
task.cancel();
}
for (PendingTeleport pending : pendingTeleports.values()) {
pending.task().cancel();
}
saveData();
}
private void loadData() {
if (data.isConfigurationSection("balances")) {
for (String key : data.getConfigurationSection("balances").getKeys(false)) {
try {
balances.put(UUID.fromString(key), data.getLong("balances." + key));
} catch (IllegalArgumentException ignored) {
}
}
}
if (!data.isConfigurationSection("homes")) {
return;
}
for (String key : data.getConfigurationSection("homes").getKeys(false)) {
try {
UUID owner = UUID.fromString(key);
String worldName = data.getString("homes." + key + ".world");
World world = worldName == null ? null : Bukkit.getWorld(worldName);
if (world == null) {
continue;
}
Location location = new Location(world,
data.getInt("homes." + key + ".x"),
data.getInt("homes." + key + ".y"),
data.getInt("homes." + key + ".z"));
homes.put(owner, location);
homeOwners.put(locationKey(location), owner);
} catch (IllegalArgumentException ignored) {
}
}
}
private void saveData() {
if (data == null) {
return;
}
data.set("balances", null);
for (Map.Entry<UUID, Long> entry : balances.entrySet()) {
data.set("balances." + entry.getKey(), entry.getValue());
}
data.set("homes", null);
for (Map.Entry<UUID, Location> entry : homes.entrySet()) {
Location location = entry.getValue();
String path = "homes." + entry.getKey();
data.set(path + ".world", location.getWorld().getName());
data.set(path + ".x", location.getBlockX());
data.set(path + ".y", location.getBlockY());
data.set(path + ".z", location.getBlockZ());
}
try {
data.save(dataFile);
} catch (IOException exception) {
getLogger().warning("데이터 저장에 실패했습니다: " + exception.getMessage());
}
}
private void createShopItems() {
shopItems.put("natural", List.of(
item("grass", Material.GRASS_BLOCK, "&a잔디 블록", 5),
item("dirt", Material.DIRT, "&6흙", 3),
item("stone", Material.STONE, "&7돌", 4),
item("cobblestone", Material.COBBLESTONE, "&8조약돌", 2),
item("sand", Material.SAND, "&e모래", 4),
item("gravel", Material.GRAVEL, "&7자갈", 4),
item("clay", Material.CLAY, "&f점토", 6)));
shopItems.put("wood", List.of(
item("oak_log", Material.OAK_LOG, "&6참나무 원목", 12),
item("spruce_log", Material.SPRUCE_LOG, "&6가문비나무 원목", 12),
item("birch_log", Material.BIRCH_LOG, "&e자작나무 원목", 12),
item("jungle_log", Material.JUNGLE_LOG, "&2정글나무 원목", 14),
item("acacia_log", Material.ACACIA_LOG, "&c아카시아 원목", 14),
item("dark_oak_log", Material.DARK_OAK_LOG, "&8짙은 참나무 원목", 16),
item("mangrove_log", Material.MANGROVE_LOG, "&4맹그로브 원목", 16)));
shopItems.put("redstone", List.of(
item("redstone", Material.REDSTONE, "&c레드스톤", 8),
item("repeater", Material.REPEATER, "&c레드스톤 중계기", 24),
item("comparator", Material.COMPARATOR, "&c레드스톤 비교기", 30),
item("piston", Material.PISTON, "&7피스톤", 45),
item("observer", Material.OBSERVER, "&7관측기", 60),
item("hopper", Material.HOPPER, "&8호퍼", 80),
item("dispenser", Material.DISPENSER, "&7발사기", 35)));
shopItems.put("food", List.of(
item("wheat", Material.WHEAT, "&e밀", 5),
item("carrot", Material.CARROT, "&6당근", 5),
item("potato", Material.POTATO, "&e감자", 5),
item("bread", Material.BREAD, "&e빵", 15),
item("apple", Material.APPLE, "&c사과", 18),
item("cooked_beef", Material.COOKED_BEEF, "&6익힌 소고기", 25),
item("cooked_chicken", Material.COOKED_CHICKEN, "&e익힌 닭고기", 20)));
shopItems.put("mineral", List.of(
item("coal", Material.COAL, "&8석탄", 18),
item("iron_ingot", Material.IRON_INGOT, "&f철 주괴", 35),
item("gold_ingot", Material.GOLD_INGOT, "&e금 주괴", 55),
item("diamond", Material.DIAMOND, "&b다이아몬드", 250),
item("emerald", Material.EMERALD, "&a에메랄드", 180),
item("lapis", Material.LAPIS_LAZULI, "&9청금석", 20),
item("redstone", Material.REDSTONE, "&c레드스톤", 8)));
}