Search in sources :

Example 1 with Residence

use of mc.dragons.res.ResLoader.Residence in project DragonsOnline by UniverseCraft.

the class ResCommands method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!requirePlayer(sender))
        return true;
    Player player = player(sender);
    User user = user(sender);
    if (label.equalsIgnoreCase("res")) {
        if (args.length == 0) {
            sender.sendMessage(ChatColor.GRAY + "To create a residence, open the door");
            sender.sendMessage(ChatColor.GRAY + "of the residence you would like to claim.");
            sender.sendMessage(ChatColor.GRAY + "You have claimed " + ChatColor.RESET + resLoader.getAllResidencesOf(user).size() + "/" + DragonsResidences.MAX_RES_PER_USER + " allowed residences.");
            sender.sendMessage(ChatColor.YELLOW + "/res mine");
            sender.sendMessage(ChatColor.YELLOW + "/res exit");
            sender.sendMessage(ChatColor.YELLOW + "/res delete <ID>");
        } else if (args[0].equalsIgnoreCase("mine")) {
            sender.sendMessage(ChatColor.GREEN + "Listing your residences:");
            for (Residence res : resLoader.getAllResidencesOf(user)) {
                Location door = res.getResPoint().getDoorLocation();
                sender.sendMessage(ChatColor.DARK_GREEN + "#" + res.getId() + ChatColor.GRAY + " (" + res.getAccessLevel() + ")" + " (" + FloorLoader.fromWorld(door.getWorld()).getDisplayName() + " " + door.getBlockX() + ", " + door.getBlockZ() + ")");
            }
        } else if (args[0].equalsIgnoreCase("exit")) {
            Document saved = user.getData().get("resExitTo", Document.class);
            if (saved == null) {
                sender.sendMessage(ChatColor.RED + "You're not in a residence right now!");
                return true;
            }
            Location to = StorageUtil.docToLoc(saved);
            player.teleport(to);
            sender.sendMessage(ChatColor.GREEN + "Exited residence successfully.");
            user.getStorageAccess().set("resExitTo", null);
        } else if (args[0].equalsIgnoreCase("delete")) {
            if (args.length == 1) {
                sender.sendMessage(ChatColor.RED + "/res delete <ID>");
                return true;
            }
            Integer id = parseInt(sender, args[1]);
            if (id == null)
                return true;
            Residence res = resLoader.getResidenceById(id);
            if (res == null) {
                sender.sendMessage(ChatColor.RED + "Invalid residence ID! You can see your residences with /res mine");
                return true;
            }
            if (res.isLocked()) {
                sender.sendMessage(ChatColor.RED + "This residence has been locked by an administrator.");
                return true;
            }
            if (!res.getOwner().getIdentifier().equals(user.getIdentifier())) {
                sender.sendMessage(ChatColor.RED + "You do not own this residence! You can see your residences with /res mine");
                return true;
            }
            resLoader.deleteResidence(id);
            resPointLoader.updateResHologramOn(user, res.getResPoint());
            if (player.getWorld().getName().equals("res_temp") && user.getData().getInteger("lastResId") == id) {
                Document saved = user.getData().get("resExitTo", Document.class);
                Location to = StorageUtil.docToLoc(saved);
                player.teleport(to);
                user.getStorageAccess().set("resExitTo", null);
            }
            sender.sendMessage(ChatColor.GREEN + "Deleted residence #" + id + " successfully.");
        }
        return true;
    }
    if (!requirePermission(sender, PermissionLevel.DEVELOPER))
        return true;
    if (label.equalsIgnoreCase("resadmin")) {
        if (!requirePermission(sender, PermissionLevel.ADMIN))
            return true;
        // Res commands for admins
        if (args.length == 0) {
            sender.sendMessage(ChatColor.YELLOW + "/resadmin linkpoint <Name> <Price> <Display Name...>");
            sender.sendMessage(ChatColor.YELLOW + "/resadmin setprice <Name> <NewPrice>");
            sender.sendMessage(ChatColor.YELLOW + "/resadmin displayname <Name> <New Display Name...>");
            sender.sendMessage(ChatColor.YELLOW + "/resadmin delpoint <Name>");
            sender.sendMessage(ChatColor.YELLOW + "/resadmin listpoints");
            sender.sendMessage(ChatColor.YELLOW + "/resadmin listowned <Player>");
            sender.sendMessage(ChatColor.YELLOW + "/resadmin [un]lock <ID>");
            sender.sendMessage(ChatColor.YELLOW + "/resadmin delete <ID>");
            sender.sendMessage(ChatColor.YELLOW + "/resadmin flag <ID> <Flag> <Value>");
            sender.sendMessage(ChatColor.YELLOW + "/resadmin goto <ID>");
            sender.sendMessage(ChatColor.YELLOW + "/resadmin rebuild <ID>");
        } else if (args[0].equalsIgnoreCase("linkpoint")) {
            if (args.length < 3) {
                sender.sendMessage(ChatColor.RED + "/resadmin linkpoint <Name> <Price> <Display Name...>");
                return true;
            }
            Block target = player.getTargetBlock(null, 5);
            if (target == null) {
                sender.sendMessage(ChatColor.RED + "Please look at the door you want to link!");
                return true;
            }
            if (!(target.getBlockData() instanceof Door)) {
                sender.sendMessage(ChatColor.RED + "Please look at the " + ChatColor.ITALIC + "door " + ChatColor.RED + "you want to link!");
                return true;
            }
            Door door = (Door) target.getBlockData();
            if (door.getHalf() == Half.TOP) {
                target = target.getRelative(BlockFace.DOWN);
            }
            resPointLoader.addResPoint(args[1], StringUtil.concatArgs(args, 3), Double.valueOf(args[2]), target.getLocation());
            sender.sendMessage(ChatColor.GREEN + "Added res point successfully.");
        } else if (args[0].equalsIgnoreCase("setprice")) {
            if (args.length < 2) {
                sender.sendMessage(ChatColor.RED + "/resadmin setprice <Name> <NewPrice>");
                return true;
            }
            ResPoint resPoint = resPointLoader.getResPointByName(args[1]);
            if (resPoint == null) {
                sender.sendMessage(ChatColor.RED + "Invalid res point! /respoint listpoints");
                return true;
            }
            resPoint.setPrice(Double.valueOf(args[2]));
            sender.sendMessage(ChatColor.GREEN + "Updated res point price successfully.");
        } else if (args[0].equalsIgnoreCase("displayname")) {
            if (args.length < 2) {
                sender.sendMessage(ChatColor.RED + "/resadmin displayname <Name> <New Display Name...>");
                return true;
            }
            ResPoint resPoint = resPointLoader.getResPointByName(args[1]);
            if (resPoint == null) {
                sender.sendMessage(ChatColor.RED + "Invalid res point! /respoint listpoints");
                return true;
            }
            resPoint.setDisplayName(StringUtil.concatArgs(args, 2));
            sender.sendMessage(ChatColor.GREEN + "Updated res point display name successfully.");
        } else if (args[0].equalsIgnoreCase("delpoint")) {
            if (args.length == 1) {
                sender.sendMessage(ChatColor.RED + "/reasdmin delpoint <Name>");
                return true;
            }
            resPointLoader.deleteResPoint(args[1]);
            sender.sendMessage(ChatColor.GREEN + "If a res point by this name existed, it has been deleted successfully.");
            return true;
        } else if (args[0].equalsIgnoreCase("listpoints")) {
            sender.sendMessage(ChatColor.GREEN + "Listing all res points:");
            for (ResPoint resPoint : resPointLoader.getAllResPoints()) {
                sender.sendMessage(ChatColor.GRAY + "- " + resPoint.getName() + " - " + resPoint.getPrice() + " gold" + " (" + StringUtil.locToString(resPoint.getDoorLocation()) + ")");
                if (!(resPoint.getDoorLocation().getBlock().getBlockData() instanceof Door)) {
                    sender.sendMessage(ChatColor.RED + "   (Invalid: No door at that location!)");
                }
            }
        } else if (args[0].equalsIgnoreCase("listowned")) {
            if (args.length == 1) {
                sender.sendMessage(ChatColor.RED + "/resadmin listowned <Player>");
                return true;
            }
            sender.sendMessage(ChatColor.GREEN + "Listing residences owned by " + args[1] + ":");
            for (Residence res : resLoader.getAllResidencesOf(GameObjectType.USER.<User, UserLoader>getLoader().loadObject(args[1]))) {
                sender.sendMessage(ChatColor.DARK_GREEN + "#" + res.getId() + ChatColor.GRAY + ": " + res.getAccessLevel() + (res.isLocked() ? " (Locked)" : ""));
            }
        } else if (args[0].equalsIgnoreCase("lock") || args[0].equalsIgnoreCase("unlock")) {
            if (args.length == 1) {
                sender.sendMessage(ChatColor.RED + "/resadmin " + args[0].toLowerCase() + " <ID>");
                return true;
            }
            Residence res = resLoader.getResidenceById(Integer.valueOf(args[1]));
            if (res == null) {
                sender.sendMessage(ChatColor.RED + "Invalid residence ID!");
                return true;
            }
            res.setLocked(args[0].equalsIgnoreCase("lock"));
            sender.sendMessage(ChatColor.GREEN + (args[0].equalsIgnoreCase("lock") ? "Locked" : "Unlocked") + " residence #" + args[1]);
        } else if (args[0].equalsIgnoreCase("delete")) {
            if (args.length == 1) {
                sender.sendMessage(ChatColor.RED + "/resadmin delete <ID>");
                return true;
            }
            Residence res = resLoader.getResidenceById(Integer.valueOf(args[1]));
            if (res == null) {
                sender.sendMessage(ChatColor.RED + "Invalid residence ID!");
                return true;
            }
            resLoader.deleteResidence(res.getId());
            sender.sendMessage(ChatColor.GREEN + "Deleted residence #" + args[1]);
        } else if (args[0].equalsIgnoreCase("flag")) {
            if (args.length < 3) {
                sender.sendMessage(ChatColor.RED + "/resadmin flag <ID> <Flag> <Value>");
                return true;
            }
            Residence res = resLoader.getResidenceById(Integer.valueOf(args[1]));
            if (res == null) {
                sender.sendMessage(ChatColor.RED + "Invalid residence ID!");
                return true;
            }
            res.getProperties().append(args[2], args[3]);
            res.save();
            sender.sendMessage(ChatColor.GREEN + "Set flag " + args[2] + " to " + args[3] + " for residence #" + args[1]);
        } else if (args[0].equalsIgnoreCase("goto")) {
            if (args.length == 1) {
                sender.sendMessage(ChatColor.RED + "/resadmin goto <ID>");
                return true;
            }
            Residence res = resLoader.getResidenceById(Integer.valueOf(args[1]));
            if (res == null) {
                sender.sendMessage(ChatColor.RED + "Invalid residence ID!");
                return true;
            }
            resLoader.goToResidence(user, res.getId(), true);
        } else if (args[0].equalsIgnoreCase("rebuild")) {
            if (args.length == 1) {
                sender.sendMessage(ChatColor.RED + "/resadmin rebuild <ID>");
                return true;
            }
            int id = Integer.valueOf(args[1]);
            Residence res = resLoader.getResidenceById(id);
            if (res == null) {
                sender.sendMessage(ChatColor.RED + "Invalid residence ID!");
                return true;
            }
            resLoader.removeResidenceLocally(id);
            resLoader.generateResidence(id);
            sender.sendMessage(ChatColor.GREEN + "Rebuilt residence #" + id + " successfully.");
        } else {
            sender.sendMessage(ChatColor.RED + "/resadmin");
        }
    } else if (label.equalsIgnoreCase("testcontextualholograms")) {
        for (ResPoint resPoint : resPointLoader.getAllResPoints()) {
            resPointLoader.updateResHologramOn(user, resPoint);
        }
    } else if (label.equalsIgnoreCase("testschematic")) {
        if (args[1].equalsIgnoreCase("good")) {
            DragonsResidences.pasteSchematic(DragonsResidences.loadSchematic(args[0]), DragonsResidences.getEditSession(new BukkitWorld(player.getWorld())), player.getLocation());
        } else if (args[1].equalsIgnoreCase("bad")) {
            // DragonsResPlugin.pasteSchematic(args[0], DragonsResPlugin.getEditSession(new BukkitWorld(player.getWorld())), player.getLocation());
            sender.sendMessage(ChatColor.RED + "No! Don't be bad");
            sender.sendMessage(ChatColor.GREEN + "Be good instead ;)");
        }
    } else if (label.equalsIgnoreCase("restest")) {
        // Test commands for devs
        if (args.length == 0) {
            sender.sendMessage("/restest new <ResPoint>");
            sender.sendMessage("/restest go <ID>");
            sender.sendMessage("/restest my");
            sender.sendMessage("/restest whatsthatrespoint");
        } else if (args[0].equalsIgnoreCase("new")) {
            Residence res = resLoader.addResidence(user, resPointLoader.getResPointByName(args[1]), ResAccess.PRIVATE);
            sender.sendMessage("Created new residence #" + res.getId());
        } else if (args[0].equalsIgnoreCase("go")) {
            Residence res = resLoader.getResidenceById(Integer.valueOf(args[1]));
            if (res == null) {
                sender.sendMessage("No residence by that ID exists! (highest ID=" + resPointLoader.getCurrentMaxId() + ")");
                return true;
            }
            resLoader.goToResidence(user, res.getId(), true);
        } else if (args[0].equalsIgnoreCase("my")) {
            for (Residence res : resLoader.getAllResidencesOf(user)) {
                sender.sendMessage("#" + res.getId() + " (owner=" + res.getOwner().getName() + ", access=" + res.getAccessLevel() + ")");
            }
        } else if (args[0].equalsIgnoreCase("whatsthatrespoint")) {
            // bottom half only
            Block target = player.getTargetBlock(null, 5);
            if (target == null) {
                sender.sendMessage("No target block");
                return true;
            }
            sender.sendMessage("Target block is " + target.getType());
            sender.sendMessage("Target block location is " + StringUtil.locToString(target.getLocation()));
            ResPoint resPoint = resPointLoader.getResPointByDoorLocation(target.getLocation());
            if (resPoint == null) {
                sender.sendMessage("No res point here");
                return true;
            }
            sender.sendMessage("Res point is " + resPoint.getName());
        }
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) User(mc.dragons.core.gameobject.user.User) Block(org.bukkit.block.Block) UserLoader(mc.dragons.core.gameobject.user.UserLoader) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) Residence(mc.dragons.res.ResLoader.Residence) Document(org.bson.Document) Door(org.bukkit.block.data.type.Door) ResPoint(mc.dragons.res.ResPointLoader.ResPoint) Location(org.bukkit.Location)

Example 2 with Residence

use of mc.dragons.res.ResLoader.Residence in project DragonsOnline by UniverseCraft.

the class ResEvents method onInteract.

@EventHandler
public void onInteract(PlayerInteractEvent event) {
    if (event.getClickedBlock() == null)
        return;
    if (!(event.getClickedBlock().getBlockData() instanceof Door)) {
        return;
    }
    Player player = event.getPlayer();
    User user = UserLoader.fromPlayer(player);
    Door door = (Door) event.getClickedBlock().getBlockData();
    if (player.getWorld().getName().equals("res_temp")) {
        player.performCommand("res exit");
        event.setCancelled(true);
        return;
    }
    if (!door.isOpen()) {
        user.debug("R.Click on door (opening it)");
        Location realLocation = door.getHalf() == Half.TOP ? event.getClickedBlock().getRelative(BlockFace.DOWN).getLocation() : event.getClickedBlock().getLocation();
        user.debug("-Door base=" + StringUtil.locToString(realLocation));
        ResPoint resPoint = resPointLoader.getResPointByDoorLocation(realLocation);
        if (resPoint == null)
            return;
        user.debug("-Res point: " + resPoint.getName());
        // ((Door) realLocation.getBlock().getState().getData()).setOpen(false);
        event.setCancelled(true);
        List<Residence> ownedHere = resLoader.getAllResidencesOf(user, resPoint);
        if (ownedHere.size() == 0) {
            user.debug("-Doesn't have any residences here");
            if (resPoint.getPrice() > user.getGold()) {
                player.sendMessage(ChatColor.RED + "You cannot afford this residence! (Costs " + resPoint.getPrice() + " gold)");
                return;
            }
            if (resLoader.getAllResidencesOf(user).size() >= DragonsResidences.MAX_RES_PER_USER) {
                player.sendMessage(ChatColor.RED + "You have reached the maximum number of residences per user! (" + DragonsResidences.MAX_RES_PER_USER + ")");
                return;
            }
            GUI gui = new GUI(1, "Purchase a residence here?");
            gui.add(new GUIElement(1, Material.EMERALD_BLOCK, ChatColor.GREEN + "✓ " + ChatColor.DARK_GREEN + "" + ChatColor.BOLD + "YES", u -> {
                player.playSound(player.getLocation(), Sound.BLOCK_WOODEN_DOOR_OPEN, 1f, 1f);
                u.takeGold(resPoint.getPrice());
                Residence purchased = resLoader.addResidence(user, resPoint, ResAccess.PRIVATE);
                resLoader.goToResidence(user, purchased.getId(), false);
                resPointLoader.updateResHologramOn(user, resPoint);
                u.closeGUI(true);
            }));
            gui.add(new GUIElement(4, Material.PAPER, ChatColor.YELLOW + "Price: " + ChatColor.GOLD + resPoint.getPrice() + " Gold"));
            gui.add(new GUIElement(7, Material.REDSTONE_BLOCK, ChatColor.RED + "✘ " + ChatColor.DARK_RED + "" + ChatColor.BOLD + "NO", u -> u.closeGUI(true)));
            gui.open(user);
        } else {
            user.debug("-Has a residence here, going there now");
            player.playSound(player.getLocation(), Sound.BLOCK_WOODEN_DOOR_OPEN, 1f, 1f);
            resLoader.goToResidence(user, ownedHere.get(0).getId(), false);
        }
    }
}
Also used : StringUtil(mc.dragons.core.util.StringUtil) UserLoader(mc.dragons.core.gameobject.user.UserLoader) Door(org.bukkit.block.data.type.Door) GUIElement(mc.dragons.core.gui.GUIElement) User(mc.dragons.core.gameobject.user.User) Residence(mc.dragons.res.ResLoader.Residence) Sound(org.bukkit.Sound) BlockFace(org.bukkit.block.BlockFace) Player(org.bukkit.entity.Player) Dragons(mc.dragons.core.Dragons) ResPoint(mc.dragons.res.ResPointLoader.ResPoint) EventHandler(org.bukkit.event.EventHandler) List(java.util.List) Location(org.bukkit.Location) GUI(mc.dragons.core.gui.GUI) ResAccess(mc.dragons.res.ResLoader.Residence.ResAccess) ChatColor(org.bukkit.ChatColor) Half(org.bukkit.block.data.Bisected.Half) PlayerInteractEvent(org.bukkit.event.player.PlayerInteractEvent) Material(org.bukkit.Material) Listener(org.bukkit.event.Listener) Player(org.bukkit.entity.Player) User(mc.dragons.core.gameobject.user.User) GUIElement(mc.dragons.core.gui.GUIElement) Residence(mc.dragons.res.ResLoader.Residence) GUI(mc.dragons.core.gui.GUI) Door(org.bukkit.block.data.type.Door) ResPoint(mc.dragons.res.ResPointLoader.ResPoint) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 3 with Residence

use of mc.dragons.res.ResLoader.Residence in project DragonsOnline by UniverseCraft.

the class ResLoader method addResidence.

public Residence addResidence(User owner, ResPoint resPoint, ResAccess access) {
    int id = reserveNextId();
    Residence task = new Residence(id, resPoint, false, owner, new Document(), access);
    collection.insertOne(task.toDocument());
    return task;
}
Also used : Residence(mc.dragons.res.ResLoader.Residence) Document(org.bson.Document) ResPoint(mc.dragons.res.ResPointLoader.ResPoint)

Example 4 with Residence

use of mc.dragons.res.ResLoader.Residence in project DragonsOnline by UniverseCraft.

the class ResLoader method goToResidence.

public void goToResidence(User user, int id, boolean bypass) {
    Residence res = getResidenceById(id);
    if (res.isLocked() && !bypass) {
        user.getPlayer().sendMessage(ChatColor.RED + "This residence has been locked by an administrator.");
        return;
    }
    boolean canAccess = bypass;
    ResAccess access = res.getAccessLevel();
    if (access == ResAccess.ALL) {
        canAccess = true;
    }
    if (access == ResAccess.PRIVATE && res.getOwner().getIdentifier().equals(user.getIdentifier())) {
        canAccess = true;
    }
    if (!canAccess) {
        user.getPlayer().sendMessage(ChatColor.RED + "You do not have access to this residence! (Guild-only and friend-only status doesn't work yet)");
        return;
    }
    Location spawn = generateResidence(id);
    // send user to residence
    if (!user.getPlayer().getWorld().getName().equals("res_temp")) {
        user.getStorageAccess().set("resExitTo", StorageUtil.locToDoc(user.getPlayer().getLocation()));
    }
    user.getStorageAccess().set("lastResId", id);
    user.getPlayer().teleport(spawn);
    user.getPlayer().sendMessage(ChatColor.GREEN + "Welcome to your residence (ID #" + id + ")");
}
Also used : Residence(mc.dragons.res.ResLoader.Residence) ResAccess(mc.dragons.res.ResLoader.Residence.ResAccess) Location(org.bukkit.Location)

Aggregations

Residence (mc.dragons.res.ResLoader.Residence)4 ResPoint (mc.dragons.res.ResPointLoader.ResPoint)3 Location (org.bukkit.Location)3 User (mc.dragons.core.gameobject.user.User)2 UserLoader (mc.dragons.core.gameobject.user.UserLoader)2 ResAccess (mc.dragons.res.ResLoader.Residence.ResAccess)2 Document (org.bson.Document)2 Door (org.bukkit.block.data.type.Door)2 Player (org.bukkit.entity.Player)2 BukkitWorld (com.sk89q.worldedit.bukkit.BukkitWorld)1 List (java.util.List)1 Dragons (mc.dragons.core.Dragons)1 GUI (mc.dragons.core.gui.GUI)1 GUIElement (mc.dragons.core.gui.GUIElement)1 StringUtil (mc.dragons.core.util.StringUtil)1 ChatColor (org.bukkit.ChatColor)1 Material (org.bukkit.Material)1 Sound (org.bukkit.Sound)1 Block (org.bukkit.block.Block)1 BlockFace (org.bukkit.block.BlockFace)1