Search in sources :

Example 36 with UPlayer

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

the class PlayerCommandPreprocess method onCommand.

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onCommand(PlayerCommandPreprocessEvent event) {
    String cmd = event.getMessage();
    UPlayer sender = new UPlayer(event);
    if (cmd.startsWith("/time set")) {
        sender.sendMessage("Please do not use /time set. The command has been cancelled");
        event.setCancelled(true);
        return;
    }
    if (cmd.length() >= 4) {
        if (cmd.substring(0, 4).equalsIgnoreCase("/op ")) {
            sender.sendMessage(ChatColor.AQUA + "oygnuonaiysgdcoauisgcdoauighscdoauismh");
            event.setCancelled(true);
            return;
        }
    }
    if (cmd.contains("gamemode")) {
        sender.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "Use /builder for building or /u spec to go into spectator mode.");
        event.setCancelled(true);
        return;
    }
    if (cmd.contains("gamerule")) {
        sender.sendMessage("no no no.");
        event.setCancelled(true);
        return;
    }
    if ((cmd.startsWith("/kill") || cmd.startsWith("/kick")) && !sender.getName().equals("Derkades")) {
        sender.teleport(0, 1000, 0);
        sender.clearInventory();
        event.setCancelled(true);
    }
    if ((cmd.equalsIgnoreCase("/rl") || cmd.equalsIgnoreCase("/reload")) && !Var.DEBUG) {
        sender.sendMessage("You can't reload when the server is in debug mode");
        event.setCancelled(true);
    }
}
Also used : UPlayer(xyz.derkades.ublisk.utils.UPlayer) EventHandler(org.bukkit.event.EventHandler)

Example 37 with UPlayer

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

the class PlayerDropItem method onItemDrop.

@EventHandler(priority = EventPriority.LOW)
public void onItemDrop(PlayerDropItemEvent event) {
    UPlayer player = new UPlayer(event);
    if (player.isInBuilderMode()) {
        return;
    }
    Item item = new Item(event.getItemDrop());
    event.setCancelled(!item.isDroppable());
}
Also used : Item(xyz.derkades.ublisk.utils.inventory.Item) UPlayer(xyz.derkades.ublisk.utils.UPlayer) EventHandler(org.bukkit.event.EventHandler)

Example 38 with UPlayer

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

the class PlayerInteract method onInteract.

@EventHandler(ignoreCancelled = false)
public void onInteract(PlayerInteractEvent event) {
    UPlayer player = new UPlayer(event);
    Action action = event.getAction();
    if (action == Action.RIGHT_CLICK_BLOCK || action == Action.RIGHT_CLICK_AIR) {
        UInventory inv = player.getInventory();
        Material item = inv.getItemInMainHand().getType();
        if (item == Material.CHEST && !player.isInBuilderMode()) {
            new MainMenu(player).open();
            event.setCancelled(true);
        } else if (item == Material.END_CRYSTAL) {
            player.openEnderchest();
            event.setCancelled(true);
        }
    }
}
Also used : Action(org.bukkit.event.block.Action) UPlayer(xyz.derkades.ublisk.utils.UPlayer) UInventory(xyz.derkades.ublisk.utils.inventory.UInventory) Material(org.bukkit.Material) MainMenu(xyz.derkades.ublisk.iconmenus.MainMenu) EventHandler(org.bukkit.event.EventHandler)

Example 39 with UPlayer

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

the class PlayerItemConsume method eat.

@EventHandler
public void eat(PlayerItemConsumeEvent event) {
    if (event.isCancelled()) {
        return;
    }
    UPlayer player = new UPlayer(event);
    player.sendMessage(Message.CANT_EAT);
    event.setCancelled(true);
}
Also used : UPlayer(xyz.derkades.ublisk.utils.UPlayer) EventHandler(org.bukkit.event.EventHandler)

Example 40 with UPlayer

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

the class PlayerJoin method onJoin.

@EventHandler
public void onJoin(PlayerJoinEvent event) {
    final UPlayer player = new UPlayer(event);
    String pn = player.getName();
    UUID uuid = player.getUniqueId();
    PlayerInfo.resetHashMaps(player);
    player.setCollidable(false);
    event.setJoinMessage(DARK_AQUA + "" + BOLD + pn + RESET + AQUA + " has joined");
    player.givePotionEffect(PotionEffectType.BLINDNESS, 1 * 20, 0);
    player.givePotionEffect(PotionEffectType.NIGHT_VISION, 1 * 20, 0);
    player.sendTitle(ChatColor.DARK_AQUA + "" + ChatColor.BOLD + "Ublisk", ChatColor.YELLOW + "Welcome back, " + pn + "!");
    if (player.getSetting(Setting.PLAY_MUSIC)) {
        Town town = player.getTown();
        if (town != null)
            town.playThemeToPlayer(player);
    }
    player.tracker(PlayerInfo.JOIN_COUNT);
    // String ip = player.getPlayer().getAddress().toString();
    // ip = ip.replace("/", "");
    String ip = player.getIP();
    DataFile.IP.getConfig().set("ip." + uuid, ip);
    player.updateXPBar();
    // Disable builder mode if the player no longer has permission
    if (!player.hasPermission(Permission.BUILDER_MODE)) {
        player.setBuilderModeEnabled(false);
    }
    if (player.isInBuilderMode()) {
        player.setGameMode(GameMode.CREATIVE);
    } else {
        player.setGameMode(GameMode.ADVENTURE);
    }
    player.setFlying(false);
    player.setAttribute(Attribute.GENERIC_ATTACK_SPEED, 0.7);
    new URunnable() {

        public void run() {
            player.sendSpacers(10);
            final String[] fancyStrings = new String[] { "                       ", " # # ##  #   # ### # # ", " # # # # #   # #   # # ", " # # ##  #   # ### ##  ", " # # # # #   #   # ##  ", " ### ##  ### # ### # # ", "                       " };
            for (String string : fancyStrings) {
                player.sendMessage(string.replace("#", ChatColor.AQUA + "" + ChatColor.BOLD + ImageChar.DARK_SHADE.getChar()).replace(" ", ChatColor.DARK_AQUA + "" + ChatColor.BOLD + ImageChar.DARK_SHADE.getChar()));
            }
            player.sendMessage(ChatColor.GRAY + "Welcome to Ublisk! If you find any bugs, please report them using /bug [description].");
        }
    }.runLater(4);
/*Ublisk.runAsync(() -> {
			Connection connection = null;
			
			PreparedStatement check = null;
			ResultSet checkResult = null;
			
			PreparedStatement insert = null;
			try {				
				connection = Ublisk.getDatabaseConnection("Player join insert");
				
				check = connection.prepareStatement("SELECT EXISTS(SELECT * FROM player_info_2 WHERE uuid=?) AS `exists`");
				check.setString(1, uuid.toString());
				checkResult = check.executeQuery();
				checkResult.next();
			
				boolean exists = checkResult.getBoolean("exists");
				
				Logger.log(LogLevel.DEBUG, "Exists: " + exists);
				
				if (!exists) {
					insert = connection.prepareStatement("INSERT INTO `player_info_2) (uuid, name, xp) VALUES (?, ?, ?)");
					insert.setString(1, uuid.toString());
					insert.setString(2, pn);
					insert.setInt(3, 0);
					insert.execute();
				}
			} catch (SQLException e) {
				Ublisk.exception(e, PlayerJoin.class);
			} finally {
				try {
					if (check != null) check.close();
					if (checkResult != null) checkResult.close();
					if (insert != null) insert.close();
				} catch (SQLException e) {
					Ublisk.exception(e, PlayerJoin.class);
				}
			}
		});*/
}
Also used : URunnable(xyz.derkades.ublisk.utils.URunnable) UPlayer(xyz.derkades.ublisk.utils.UPlayer) Town(xyz.derkades.ublisk.Town) UUID(java.util.UUID) EventHandler(org.bukkit.event.EventHandler)

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