Search in sources :

Example 21 with UPlayer

use of xyz.derkades.ublisk.utils.UPlayer in project Ublisk by Derkades.

the class HelpMenu method onOptionClick.

@Override
public boolean onOptionClick(OptionClickEvent event) {
    String name = event.getName().toLowerCase();
    final UPlayer player = new UPlayer(event);
    if (name.contains("commands")) {
        new CommandsHelp(player).open();
    } else if (name.contains("faq")) {
    // TODO Open faq menu
    } else if (name.equals("back")) {
        new MainMenu(player).open();
    } else {
        player.sendMessage(Message.ERROR_MENU);
    }
    return false;
}
Also used : UPlayer(xyz.derkades.ublisk.utils.UPlayer) MainMenu(xyz.derkades.ublisk.iconmenus.MainMenu)

Example 22 with UPlayer

use of xyz.derkades.ublisk.utils.UPlayer in project Ublisk by Derkades.

the class NPCClickListener method onClick.

@EventHandler(priority = EventPriority.LOW)
public void onClick(PlayerInteractEntityEvent event) {
    Entity entity = event.getRightClicked();
    if (!(entity instanceof Villager)) {
        return;
    }
    event.setCancelled(true);
    UPlayer player = new UPlayer(event);
    NPC npc = NPC.fromName(entity.getCustomName());
    if (npc == null) {
        player.sendPrefixedMessage("NPC", RED + "No dialogue could be found for an npc with name " + entity.getCustomName() + RED + ", please report this error.");
        return;
    }
    npc.talk(player);
}
Also used : Entity(org.bukkit.entity.Entity) UPlayer(xyz.derkades.ublisk.utils.UPlayer) Villager(org.bukkit.entity.Villager) EventHandler(org.bukkit.event.EventHandler)

Example 23 with UPlayer

use of xyz.derkades.ublisk.utils.UPlayer in project Ublisk by Derkades.

the class Menu method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (sender instanceof Player) {
        UPlayer player = new UPlayer(sender);
        new MainMenu(player).open();
        return true;
    } else {
        sender.sendMessage(Message.NOT_A_PLAYER.toString());
        return true;
    }
}
Also used : UPlayer(xyz.derkades.ublisk.utils.UPlayer) Player(org.bukkit.entity.Player) UPlayer(xyz.derkades.ublisk.utils.UPlayer) MainMenu(xyz.derkades.ublisk.iconmenus.MainMenu)

Example 24 with UPlayer

use of xyz.derkades.ublisk.utils.UPlayer in project Ublisk by Derkades.

the class MsgCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player)) {
        sender.sendMessage(Message.NOT_A_PLAYER.toString());
        return true;
    }
    UPlayer player = new UPlayer(sender);
    // If player is muted don't send private message
    if (Chat.IS_MUTED.get(player.getUniqueId())) {
        player.sendMessage(Message.CANT_PM_MUTED);
        return true;
    }
    if (args.length >= 2) {
        UPlayer target;
        try {
            target = new UPlayer(args[0]);
        } catch (PlayerNotFoundException e1) {
            player.sendMessage(Message.PLAYER_NOT_FOUND);
            return true;
        }
        List<String> list = new ArrayList<String>();
        for (int x = 1; x < args.length; x++) {
            list.add(args[x]);
        }
        String msg = String.join(" ", list);
        // Play a sound if the target player has enabled sounds.
        if (target.getSetting(Setting.PM_SOUND)) {
            target.playSound(Sound.ENTITY_ITEM_PICKUP);
        }
        target.setLastSender(player);
        target.sendPrivateMessage(player, msg);
        return true;
    } else {
        player.sendMessage(Message.WRONG_USAGE);
        return true;
    }
}
Also used : UPlayer(xyz.derkades.ublisk.utils.UPlayer) Player(org.bukkit.entity.Player) UPlayer(xyz.derkades.ublisk.utils.UPlayer) ArrayList(java.util.ArrayList) PlayerNotFoundException(xyz.derkades.ublisk.utils.exception.PlayerNotFoundException)

Example 25 with UPlayer

use of xyz.derkades.ublisk.utils.UPlayer in project Ublisk by Derkades.

the class MuteCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player)) {
        sender.sendMessage(Message.NOT_A_PLAYER.toString());
        return true;
    }
    UPlayer player = new UPlayer(sender);
    if (player.hasPermission(Permission.COMMAND_MUTE)) {
        player.sendMessage(Message.NO_PERMISSION);
        return true;
    }
    if (args.length == 1) {
        UPlayer target;
        try {
            target = new UPlayer(args[0]);
        } catch (PlayerNotFoundException e) {
            player.sendMessage(Message.PLAYER_NOT_FOUND);
            return true;
        }
        UUID uuid = target.getUniqueId();
        String targetName = target.getName();
        String playerName = player.getName();
        if (Chat.IS_MUTED.get(uuid)) {
            player.sendPrefixedMessage("Chat", targetName + " has been unmuted.");
            target.sendPrefixedMessage("Chat", "You have been unmuted by " + playerName);
            Chat.IS_MUTED.put(uuid, false);
            return true;
        } else {
            player.sendPrefixedMessage("Chat", targetName + " has been muted.");
            target.sendPrefixedMessage("Chat", "You have been muted by " + playerName);
            Chat.IS_MUTED.put(uuid, true);
            return true;
        }
    } else if (args.length == 2 && args[0].equalsIgnoreCase("soft")) {
        UPlayer target;
        try {
            target = new UPlayer(args[1]);
        } catch (PlayerNotFoundException e) {
            player.sendMessage(Message.PLAYER_NOT_FOUND);
            return true;
        }
        UUID uuid = target.getUniqueId();
        String targetName = target.getName();
        String playerName = player.getName();
        if (Chat.IS_SOFT_MUTED.get(uuid)) {
            player.sendPrefixedMessage("Chat", targetName + " has been un-soft-muted.");
            target.sendPrefixedMessage("Chat", "You have been un-soft-muted by " + playerName);
            Chat.IS_MUTED.put(uuid, false);
            return true;
        } else {
            player.sendPrefixedMessage("Chat", targetName + " has been soft-muted.");
            target.sendPrefixedMessage("Chat", "You have been soft-muted by " + playerName);
            Chat.IS_MUTED.put(uuid, true);
            return true;
        }
    } else {
        player.sendMessage(Message.WRONG_USAGE);
        return true;
    }
}
Also used : UPlayer(xyz.derkades.ublisk.utils.UPlayer) Player(org.bukkit.entity.Player) UPlayer(xyz.derkades.ublisk.utils.UPlayer) PlayerNotFoundException(xyz.derkades.ublisk.utils.exception.PlayerNotFoundException) UUID(java.util.UUID)

Aggregations

UPlayer (xyz.derkades.ublisk.utils.UPlayer)47 EventHandler (org.bukkit.event.EventHandler)26 Player (org.bukkit.entity.Player)9 PlayerNotFoundException (xyz.derkades.ublisk.utils.exception.PlayerNotFoundException)7 ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)5 Item (xyz.derkades.ublisk.utils.inventory.Item)5 BaseComponent (net.md_5.bungee.api.chat.BaseComponent)4 ArrayList (java.util.ArrayList)3 ClickEvent (net.md_5.bungee.api.chat.ClickEvent)3 Material (org.bukkit.Material)3 OfflinePlayer (org.bukkit.OfflinePlayer)3 Chest (org.bukkit.block.Chest)3 Action (org.bukkit.event.block.Action)3 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)3 Town (xyz.derkades.ublisk.Town)3 MainMenu (xyz.derkades.ublisk.iconmenus.MainMenu)3 UUID (java.util.UUID)2 HoverEvent (net.md_5.bungee.api.chat.HoverEvent)2 Location (org.bukkit.Location)2 Block (org.bukkit.block.Block)2