Search in sources :

Example 6 with ItemClass

use of mc.dragons.core.gameobject.item.ItemClass in project DragonsOnline by UniverseCraft.

the class ItemCommand method giveItemOfClass.

private void giveItemOfClass(CommandSender sender, String[] args) {
    if (args.length == 1) {
        sender.sendMessage(ChatColor.RED + "Insufficient arguments! /item give <ClassName> [Player] [Quantity]");
        return;
    }
    ItemClass itemClass = lookupItemClass(sender, args[1]);
    if (itemClass == null)
        return;
    Item item = itemLoader.registerNew(itemClass);
    if (args.length > 3) {
        Integer quantityOpt = parseInt(sender, args[3]);
        if (quantityOpt == null)
            return;
        item.setQuantity(quantityOpt);
    }
    if (args.length > 2) {
        Player target = Bukkit.getPlayerExact(args[2]);
        if (target == null) {
            sender.sendMessage(ChatColor.RED + "That player is not online!");
            return;
        }
        User targetUser = UserLoader.fromPlayer(target);
        targetUser.giveItem(item);
    } else if (!isPlayer(sender)) {
        sender.sendMessage(ChatColor.RED + "Console must specify a player to give the item to!");
    } else {
        user(sender).giveItem(item);
    }
}
Also used : ItemClass(mc.dragons.core.gameobject.item.ItemClass) Item(mc.dragons.core.gameobject.item.Item) Player(org.bukkit.entity.Player) User(mc.dragons.core.gameobject.user.User)

Example 7 with ItemClass

use of mc.dragons.core.gameobject.item.ItemClass in project DragonsOnline by UniverseCraft.

the class ItemCommand method push.

private void push(CommandSender sender, String[] args) {
    ItemClass itemClass = lookupItemClass(sender, args[0]);
    if (itemClass == null)
        return;
    Document update = new Document(itemClass.getData());
    update.remove("_id");
    update.remove("type");
    storageManager.push(GameObjectType.ITEM, new Document("className", itemClass.getClassName()), update);
    sender.sendMessage(ChatColor.GREEN + "Updated all items matching class " + itemClass.getClassName() + " in database.");
    sender.sendMessage(ChatColor.GREEN + "Players must rejoin to receive the updated items.");
    AUDIT_LOG.savePush(itemClass, user(sender));
}
Also used : ItemClass(mc.dragons.core.gameobject.item.ItemClass) Document(org.bson.Document)

Example 8 with ItemClass

use of mc.dragons.core.gameobject.item.ItemClass in project DragonsOnline by UniverseCraft.

the class ItemCommand method listClasses.

private void listClasses(CommandSender sender, String[] args) {
    String startingWith = "";
    if (args.length > 1) {
        startingWith = args[1];
    }
    sender.sendMessage(ChatColor.GREEN + "Listing all item classes" + (startingWith.length() > 0 ? (" starting with \"" + startingWith + "\"") : "") + ":");
    for (GameObject gameObject : registry.getRegisteredObjects(GameObjectType.ITEM_CLASS)) {
        ItemClass itemClass = (ItemClass) gameObject;
        if (!itemClass.getClassName().startsWith(startingWith))
            continue;
        sender.spigot().sendMessage(StringUtil.clickableHoverableText(ChatColor.GRAY + "- " + itemClass.getClassName() + " [Lv Min " + itemClass.getLevelMin() + "]", "/item give " + itemClass.getClassName(), true, "Click to receive this item"));
    }
}
Also used : ItemClass(mc.dragons.core.gameobject.item.ItemClass) GameObject(mc.dragons.core.gameobject.GameObject)

Example 9 with ItemClass

use of mc.dragons.core.gameobject.item.ItemClass in project DragonsOnline by UniverseCraft.

the class ItemCommand method manageLore.

private void manageLore(CommandSender sender, String[] args) {
    ItemClass itemClass = lookupItemClass(sender, args[0]);
    if (itemClass == null)
        return;
    User user = user(sender);
    if (args.length == 2) {
        if (itemClass.getLore().size() == 0) {
            sender.sendMessage(ChatColor.RED + "This item has no lore!");
        } else {
            sender.sendMessage(ChatColor.GREEN + "Item lore:");
            for (String line : itemClass.getLore()) {
                sender.sendMessage(ChatColor.GRAY + "- " + ChatColor.GREEN + line);
            }
        }
    } else if (args[2].equalsIgnoreCase("add")) {
        Document base = Document.parse(itemClass.getData().toJson());
        String loreLine = StringUtil.concatArgs(args, 3);
        List<String> lore = itemClass.getLore();
        lore.add(loreLine);
        itemClass.setLore(lore);
        sender.sendMessage(ChatColor.GREEN + "Updated item lore successfully.");
        AUDIT_LOG.saveEntry(itemClass, user, base, "Added lore line " + loreLine);
    } else if (args[2].equalsIgnoreCase("remove")) {
        Document base = Document.parse(itemClass.getData().toJson());
        List<String> lore = itemClass.getLore();
        lore.remove(Integer.valueOf(args[3]) - 1);
        itemClass.setLore(lore);
        sender.sendMessage(ChatColor.GREEN + "Updated item lore successfully.");
        AUDIT_LOG.saveEntry(itemClass, user, base, "Removed lore line #" + args[3]);
    } else {
        sender.sendMessage(ChatColor.RED + "Invalid arguments! /item <ClassName> lore [add <Lore>|remove <LineNo>]");
    }
}
Also used : ItemClass(mc.dragons.core.gameobject.item.ItemClass) User(mc.dragons.core.gameobject.user.User) ArrayList(java.util.ArrayList) List(java.util.List) Document(org.bson.Document)

Example 10 with ItemClass

use of mc.dragons.core.gameobject.item.ItemClass in project DragonsOnline by UniverseCraft.

the class PlayerEventListeners method onJoin.

@EventHandler
public void onJoin(PlayerJoinEvent event) {
    LOGGER.debug("Join event on " + event.getPlayer().getName());
    event.setJoinMessage(null);
    Player player = event.getPlayer();
    if (!plugin.isJoinable()) {
        event.getPlayer().kickPlayer(ChatColor.YELLOW + "This server (" + plugin.getServerName() + ") is still loading and is not joinable yet.\n" + "Please try again in a few minutes.\n\n" + "This is not a punishment-related kick.");
        return;
    }
    rollingAsync(() -> {
        UUID uuid = player.getUniqueId();
        User user = userLoader.loadObject(uuid);
        boolean firstJoin = false;
        if (user == null) {
            firstJoin = true;
            plugin.getLogger().info("Player " + player.getName() + " joined for the first time");
            user = userLoader.registerNew(player);
            user.sendToFloor("BeginnerTown");
            int i = 1;
            final User fUser = user;
            for (ItemClass itemClass : DEFAULT_INVENTORY) {
                sync(() -> fUser.giveItem(itemLoader.registerNew(itemClass), true, false, true), i);
                i++;
            }
        }
        Floor floor = FloorLoader.fromLocation(player.getLocation());
        if (floor.isPlayerLocked() && !PermissionUtil.verifyActivePermissionLevel(user, PermissionLevel.GM, false)) {
            sync(() -> player.kickPlayer(ChatColor.RED + "This floor (#" + floor.getLevelMin() + " " + floor.getDisplayName() + ") is currently locked for maintenance.\n" + "You will be allowed to re-join once the maintenance completes.\n\n" + "This is not a punishment-related kick.\n\n" + StringUtil.dateFormatNow()));
            return;
        }
        if (user.getRank().isStaff()) {
            GameMode restoreTo = user.getSavedGameMode();
            final User fUser = user;
            sync(() -> {
                fUser.setGameMode(GameMode.ADVENTURE, true);
                fUser.setGameMode(restoreTo, false);
                fUser.sendToFloor("Staff");
                player.setPlayerListName(ChatColor.DARK_GRAY + "" + ChatColor.MAGIC + "[Staff Joining]");
                fUser.updatePrimaryNameTag();
            });
            player.sendMessage(ChatColor.AQUA + "Please login to your system profile or select \"Join as player\".");
        } else {
            user.handleJoin(firstJoin);
        }
    });
}
Also used : ItemClass(mc.dragons.core.gameobject.item.ItemClass) Floor(mc.dragons.core.gameobject.floor.Floor) GameMode(org.bukkit.GameMode) Player(org.bukkit.entity.Player) User(mc.dragons.core.gameobject.user.User) UUID(java.util.UUID) EventHandler(org.bukkit.event.EventHandler)

Aggregations

ItemClass (mc.dragons.core.gameobject.item.ItemClass)16 Document (org.bson.Document)8 User (mc.dragons.core.gameobject.user.User)7 Material (org.bukkit.Material)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Item (mc.dragons.core.gameobject.item.Item)2 ItemClassLoader (mc.dragons.core.gameobject.item.ItemClassLoader)2 Quest (mc.dragons.core.gameobject.quest.Quest)2 GUI (mc.dragons.core.gui.GUI)2 GUIElement (mc.dragons.core.gui.GUIElement)2 ChatColor (org.bukkit.ChatColor)2 Player (org.bukkit.entity.Player)2 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1 Dragons (mc.dragons.core.Dragons)1 Addon (mc.dragons.core.addon.Addon)1 ItemAddon (mc.dragons.core.addon.ItemAddon)1 GameObject (mc.dragons.core.gameobject.GameObject)1