Search in sources :

Example 21 with ISoliniaPlayer

use of com.solinia.solinia.Interfaces.ISoliniaPlayer in project solinia3-core by mixxit.

the class CommandCharacter method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player))
        return false;
    Player player = (Player) sender;
    try {
        ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(player);
        if (args.length == 0) {
            player.sendMessage("Your Characters: ");
            String main = "ALT";
            if (solplayer.isMain()) {
                main = "MAIN";
            }
            player.sendMessage("- " + ChatColor.LIGHT_PURPLE + solplayer.getFullNameWithTitle() + ChatColor.RESET + " " + main + " - " + ChatColor.GREEN + "ACTIVE" + ChatColor.RESET);
            for (ISoliniaPlayer character : StateManager.getInstance().getPlayerManager().getCharactersByPlayerUUID(player.getUniqueId())) {
                if (character.getCharacterId().equals(solplayer.getCharacterId()))
                    continue;
                if (character.isMain()) {
                    main = "MAIN";
                } else {
                    main = "ALT";
                }
                TextComponent tc = new TextComponent();
                tc.setText("- " + ChatColor.LIGHT_PURPLE + character.getFullNameWithTitle() + ChatColor.RESET + " " + main + " - ");
                String details = ChatColor.GOLD + character.getFullNameWithTitle() + " Level: " + character.getLevel() + ChatColor.RESET;
                TextComponent tc2 = new TextComponent();
                String changetext = "/character load " + character.getCharacterId().toString();
                if (StateManager.getInstance().getPlayerManager().getPlayerLastChangeChar(player.getUniqueId()) != null) {
                    tc2.setText(ChatColor.RED + "Already changed this session" + ChatColor.RESET);
                } else {
                    tc2.setText(ChatColor.AQUA + "[Click to Switch]" + ChatColor.RESET);
                    tc2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, changetext));
                }
                tc.addExtra(tc2);
                tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(details).create()));
                sender.spigot().sendMessage(tc);
            }
            player.sendMessage("Note, new characters may not be visible for up to 15 minutes");
            player.sendMessage("Use '/character new' to create a new character");
        } else {
            switch(args[0].toUpperCase()) {
                case "NEW":
                    if (StateManager.getInstance().getPlayerManager().getPlayerLastChangeChar(player.getUniqueId()) != null) {
                        player.sendMessage("You can only change your character once per server session. Please wait for the next 4 hourly restart");
                        return true;
                    }
                    ISoliniaPlayer newPlayer = StateManager.getInstance().getPlayerManager().createNewPlayerAlt(plugin, player);
                    if (newPlayer != null) {
                        player.sendMessage("Your character has been stored and a new character created");
                        player.sendMessage("Please check you have not dropped any items due to your character change");
                    } else {
                        player.sendMessage("Problem creating your new character");
                    }
                    break;
                case "LOAD":
                    if (args.length < 2) {
                        player.sendMessage("You must provide the character UUID");
                        return true;
                    }
                    if (StateManager.getInstance().getPlayerManager().getPlayerLastChangeChar(player.getUniqueId()) != null) {
                        player.sendMessage("You can only change your character once per server session. Please wait for the next 4 hourly restart");
                        return true;
                    }
                    UUID characterUUID = UUID.fromString(args[1]);
                    ISoliniaPlayer loadedPlayer = StateManager.getInstance().getPlayerManager().loadPlayerAlt(plugin, player, characterUUID);
                    if (loadedPlayer != null) {
                        player.sendMessage("Your character has been stored and your new character loaded");
                        player.sendMessage("Please check you have not dropped any items due to your character change");
                    } else {
                        player.sendMessage("Problem loading requested character");
                    }
                    break;
                default:
                    player.sendMessage("Unknown character subcommand");
                    break;
            }
        }
    } catch (CoreStateInitException e) {
    }
    return true;
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) HoverEvent(net.md_5.bungee.api.chat.HoverEvent) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) UUID(java.util.UUID) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Example 22 with ISoliniaPlayer

use of com.solinia.solinia.Interfaces.ISoliniaPlayer in project solinia3-core by mixxit.

the class ChannelManager method sendToGlobalChannel.

@Override
public void sendToGlobalChannel(ISoliniaPlayer source, String message) {
    for (Player player : Bukkit.getOnlinePlayers()) {
        player.sendMessage(message);
    }
    System.out.println(message);
    sendToDiscordMC(source, getDefaultDiscordChannel(), source.getFullNameWithTitle() + ": " + message);
}
Also used : Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer)

Example 23 with ISoliniaPlayer

use of com.solinia.solinia.Interfaces.ISoliniaPlayer in project solinia3-core by mixxit.

the class Solinia3CorePlayerListener method onPlayerSwapHandItems.

@EventHandler
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
    if (event.isCancelled())
        return;
    try {
        ItemStack itemstack = event.getOffHandItem();
        if (itemstack == null)
            return;
        if (Utils.IsSoliniaItem(itemstack) && !itemstack.getType().equals(Material.ENCHANTED_BOOK)) {
            ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt((Player) event.getPlayer());
            ISoliniaItem soliniaitem = StateManager.getInstance().getConfigurationManager().getItem(itemstack);
            if (soliniaitem.getAllowedClassNames().size() == 0)
                return;
            if (solplayer.getClassObj() == null) {
                Utils.CancelEvent(event);
                ;
                event.getPlayer().sendMessage(ChatColor.GRAY + "Your class cannot wear this armour");
                return;
            }
            if (!soliniaitem.getAllowedClassNames().contains(solplayer.getClassObj().getName().toUpperCase())) {
                Utils.CancelEvent(event);
                ;
                event.getPlayer().getPlayer().sendMessage(ChatColor.GRAY + "Your class cannot wear this armour");
                return;
            }
            if (soliniaitem.getMinLevel() > solplayer.getLevel()) {
                Utils.CancelEvent(event);
                ;
                event.getPlayer().getPlayer().sendMessage(ChatColor.GRAY + "Your are not sufficient level wear this armour");
                return;
            }
            solplayer.updateMaxHp();
        }
    } catch (CoreStateInitException e) {
    }
}
Also used : ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 24 with ISoliniaPlayer

use of com.solinia.solinia.Interfaces.ISoliniaPlayer in project solinia3-core by mixxit.

the class Solinia3CorePlayerListener method onChat.

@EventHandler
public void onChat(AsyncPlayerChatEvent event) {
    if (event.isCancelled())
        return;
    SoliniaAsyncPlayerChatEvent soliniaevent;
    try {
        ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(event.getPlayer());
        if (solplayer.getLanguage() == null || solplayer.getLanguage().equals("UNKNOWN")) {
            if (solplayer.getRace() == null) {
                event.getPlayer().sendMessage("You cannot speak until you set a race /setrace");
                Utils.CancelEvent(event);
                ;
                return;
            } else {
                solplayer.setLanguage(solplayer.getRace().getName().toUpperCase());
            }
        }
        soliniaevent = new SoliniaAsyncPlayerChatEvent(event, solplayer, event.getMessage());
        Bukkit.getPluginManager().callEvent(soliniaevent);
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : SoliniaAsyncPlayerChatEvent(com.solinia.solinia.Events.SoliniaAsyncPlayerChatEvent) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) EventHandler(org.bukkit.event.EventHandler)

Example 25 with ISoliniaPlayer

use of com.solinia.solinia.Interfaces.ISoliniaPlayer in project solinia3-core by mixxit.

the class Solinia3CorePlayerListener method onPlayerJoin.

@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
    SoliniaPlayerJoinEvent soliniaevent;
    try {
        ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(event.getPlayer());
        soliniaevent = new SoliniaPlayerJoinEvent(event, solplayer);
        solplayer.updateDisplayName();
        solplayer.updateMaxHp();
        Bukkit.getPluginManager().callEvent(soliniaevent);
        // patch
        if (solplayer.getClassObj() != null)
            solplayer.setChosenClass(true);
        else
            solplayer.setChosenClass(false);
        // patch
        if (solplayer.getRace() != null)
            solplayer.setChosenRace(true);
        else
            solplayer.setChosenRace(false);
        StateManager.getInstance().getChannelManager().sendToDiscordMC(solplayer, StateManager.getInstance().getChannelManager().getDefaultDiscordChannel(), event.getPlayer().getName() + "(" + solplayer.getFullName() + ") has joined the game");
    } catch (CoreStateInitException e) {
        event.getPlayer().kickPlayer("Server initialising");
    }
}
Also used : CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) SoliniaPlayerJoinEvent(com.solinia.solinia.Events.SoliniaPlayerJoinEvent) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) EventHandler(org.bukkit.event.EventHandler)

Aggregations

ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)89 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)85 Player (org.bukkit.entity.Player)57 ISoliniaNPC (com.solinia.solinia.Interfaces.ISoliniaNPC)16 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)13 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)12 EventHandler (org.bukkit.event.EventHandler)11 LivingEntity (org.bukkit.entity.LivingEntity)10 ArrayList (java.util.ArrayList)9 UUID (java.util.UUID)9 SoliniaItemException (com.solinia.solinia.Exceptions.SoliniaItemException)8 TextComponent (net.md_5.bungee.api.chat.TextComponent)8 ItemStack (org.bukkit.inventory.ItemStack)8 CommandSender (org.bukkit.command.CommandSender)5 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)5 Entity (org.bukkit.entity.Entity)5 Timestamp (java.sql.Timestamp)4 LocalDateTime (java.time.LocalDateTime)4 ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)4 HoverEvent (net.md_5.bungee.api.chat.HoverEvent)4