org.bukkit.entity.Player Java Examples
The following examples show how to use
org.bukkit.entity.Player.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Checks.java From WildernessTp with MIT License | 6 votes |
public double getSolidBlock(int x, int z, Player target) { if(target.getWorld().getBiome(target.getLocation().getBlockX(),target.getLocation().getBlockZ()).equals(Biome.valueOf(nether))) return getSolidBlockNether(x,z,target); if (wild.getConfig().getBoolean("Worlds."+target.getWorld().getName()+".InvertY",false)) return invertSearch(x,z,target); else { if(target.getWorld().getBiome(x,z).equals(Biome.valueOf(nether))) return getSolidBlockNether(x,z,target); else { /*for (int i = target.getWorld().getMaxHeight(); i >=0; i--) { if (!target.getWorld().getBlockAt(x, i, z).isEmpty() && target.getWorld().getBlockAt(x, i + 1, z).isEmpty() && target.getWorld().getBlockAt(x, i + 2, z).isEmpty() && target.getWorld().getBlockAt(x, i + 3, z).isEmpty() && !checkBlocks(target, x, i, z)) { target.sendMessage(ChatColor.LIGHT_PURPLE+ ""+i); return i ; } }*/ return target.getWorld().getHighestBlockYAt(x,z); //return (target.getWorld().getHighestBlockAt(x,z).getY()-1)+5; } } //return 10; }
Example #2
Source File: ListenerEssentials.java From CombatLogX with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true) public void onToggleFlight(FlyStatusChangeEvent e) { if(!e.getValue()) return; FileConfiguration config = this.expansion.getConfig("cheat-prevention.yml"); if (!config.getBoolean("flight.prevent-flying")) return; IUser affectedUser = e.getAffected(); Player player = affectedUser.getBase(); ICombatManager manager = this.plugin.getCombatManager(); if (!manager.isInCombat(player)) return; e.setCancelled(true); String message = this.plugin.getLanguageMessageColoredWithPrefix("cheat-prevention.flight.no-flying"); this.plugin.sendMessage(player, message); }
Example #3
Source File: MagicSugar.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
@Override public ItemUseHandler getItemHandler() { return e -> { // Check if it is being placed into an ancient altar. if (e.getClickedBlock().isPresent()) { Material block = e.getClickedBlock().get().getType(); if (block == Material.DISPENSER || block == Material.ENCHANTING_TABLE) { return; } } Player p = e.getPlayer(); if (p.getGameMode() != GameMode.CREATIVE) { ItemUtils.consumeItem(e.getItem(), false); } p.playSound(p.getLocation(), Sound.ENTITY_GENERIC_EAT, 1, 1); p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 600, 3)); }; }
Example #4
Source File: TestProfileResearches.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
@Test public void testHasUnlocked() throws InterruptedException { SlimefunPlugin.getRegistry().setResearchingEnabled(true); Player player = server.addPlayer(); PlayerProfile profile = TestUtilities.awaitProfile(player); NamespacedKey key = new NamespacedKey(plugin, "player_profile_test"); Research research = new Research(key, 280, "Test", 100); research.register(); profile.setResearched(research, true); Assertions.assertTrue(profile.hasUnlocked(research)); Assertions.assertTrue(profile.hasUnlocked(null)); profile.setResearched(research, false); Assertions.assertFalse(profile.hasUnlocked(research)); // Researches are disabled now, so this method should pass // Whether Research#isEnabled() works correctly is covered elsewhere SlimefunPlugin.getRegistry().setResearchingEnabled(false); Assertions.assertTrue(profile.hasUnlocked(research)); }
Example #5
Source File: Injector.java From BungeePerms with GNU General Public License v3.0 | 6 votes |
private static Field getPermField(CommandSender sender) { Field perm = null; try { if (sender instanceof Player) { perm = Class.forName(getVersionedClassName("entity.CraftHumanEntity")).getDeclaredField("perm"); } else if (sender instanceof ConsoleCommandSender) { perm = Class.forName(getVersionedClassName("command.ServerCommandSender")).getDeclaredField("perm"); } } catch (Exception e) { BungeePerms.getInstance().getDebug().log(e); } return perm; }
Example #6
Source File: InventoryClearCommand.java From Minepacks with GNU General Public License v3.0 | 6 votes |
private void clearInventory(Player player, CommandSender sender) { InventoryClearEvent clearEvent = new InventoryClearEvent(player, sender); Bukkit.getPluginManager().callEvent(clearEvent); if(clearEvent.isCancelled()) return; player.getInventory().clear(); if(sender.equals(player)) { messageOwnInventoryCleared.send(player); Bukkit.getPluginManager().callEvent(new InventoryClearedEvent(player, sender)); } else { messageInventoryWasCleared.send(player, sender.getName(), (sender instanceof Player) ? ((Player) sender).getDisplayName() : ChatColor.GRAY + sender.getName()); messageOtherInventoryCleared.send(sender, player.getName(), player.getDisplayName()); Bukkit.getPluginManager().callEvent(new InventoryClearedEvent(player, sender)); } }
Example #7
Source File: Titles.java From XSeries with MIT License | 6 votes |
/** * Clears the title and subtitle message from the player's screen. * * @param player the player to clear the title from. * @since 1.0.0 */ public static void clearTitle(@Nonnull Player player) { Objects.requireNonNull(player, "Cannot clear title from null player"); if (supported) { player.resetTitle(); return; } Object clearPacket = null; try { clearPacket = PACKET.invoke(CLEAR, null, -1, -1, -1); } catch (Throwable throwable) { throwable.printStackTrace(); } ReflectionUtils.sendPacket(player, clearPacket); }
Example #8
Source File: InventoryChangeProcessTest.java From PerWorldInventory with GNU General Public License v3.0 | 6 votes |
@Test public void shouldNotBypassBecauseBypassDisabled() { // given Player player = mock(Player.class); given(player.getName()).willReturn("Bob"); given(player.getGameMode()).willReturn(GameMode.SURVIVAL); Group from = mockGroup("test_group", GameMode.SURVIVAL, true); Group to = mockGroup("other_group", GameMode.SURVIVAL, true); given(settings.getProperty(PwiProperties.SEPARATE_GAMEMODE_INVENTORIES)).willReturn(true); given(settings.getProperty(PwiProperties.DISABLE_BYPASS)).willReturn(true); // when process.processWorldChange(player, from, to); // then verify(bukkitService).callEvent(any(InventoryLoadEvent.class)); }
Example #9
Source File: Attack.java From civcraft with GNU General Public License v2.0 | 6 votes |
@Override public void onAttack(EntityDamageByEntityEvent event, ItemStack inHand) { AttributeUtil attrs = new AttributeUtil(inHand); double dmg = this.getDouble("value"); double extraAtt = 0.0; for (LoreEnhancement enh : attrs.getEnhancements()) { if (enh instanceof LoreEnhancementAttack) { extraAtt += ((LoreEnhancementAttack)enh).getExtraAttack(attrs); } } dmg += extraAtt; if (event.getDamager() instanceof Player) { Resident resident = CivGlobal.getResident(((Player)event.getDamager())); if (!resident.hasTechForItem(inHand)) { dmg = dmg / 2; } } if (dmg < 0.5) { dmg = 0.5; } event.setDamage(dmg); }
Example #10
Source File: CivilianManager.java From Civs with GNU General Public License v3.0 | 6 votes |
Civilian createDefaultCivilian(UUID uuid) { ConfigManager configManager = ConfigManager.getInstance(); CivClass defaultClass = ClassManager.getInstance().createDefaultClass(uuid); Set<CivClass> classes = new HashSet<>(); classes.add(defaultClass); int expOrbs = -1; if (Civs.getInstance() != null) { Player player = Bukkit.getPlayer(uuid); if (player != null) { expOrbs = player.getTotalExperience(); } } Civilian civilian = new Civilian(uuid, configManager.getDefaultLanguage(), new HashMap<>(), classes, new HashMap<>(), 0, 0, 0, 0, 0, 0, expOrbs); civilian.getStashItems().putAll(ItemManager.getInstance().getNewItems(civilian)); civilian.setTutorialPath("default"); civilian.setTutorialIndex(0); civilian.setUseAnnouncements(true); civilian.setTutorialProgress(0); return civilian; }
Example #11
Source File: CommandGuildCompass.java From NovaGuilds with GNU General Public License v3.0 | 6 votes |
@Override public void execute(CommandSender sender, String[] args) throws Exception { Player player = (Player) sender; NovaPlayer nPlayer = PlayerManager.getPlayer(sender); if(!nPlayer.hasGuild()) { Message.CHAT_GUILD_NOTINGUILD.send(sender); return; } if(nPlayer.getPreferences().isCompassPointingGuild()) { //disable nPlayer.getPreferences().setCompassPointingGuild(false); player.setCompassTarget(player.getWorld().getSpawnLocation()); Message.CHAT_GUILD_COMPASSTARGET_OFF.send(sender); } else { //enable nPlayer.getPreferences().setCompassPointingGuild(true); player.setCompassTarget(nPlayer.getGuild().getHome()); Message.CHAT_GUILD_COMPASSTARGET_ON.send(sender); } }
Example #12
Source File: EntityShootCustomBow.java From AdditionsAPI with MIT License | 6 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onEntityShootCustomBowLowest(EntityShootCustomBowEvent customEvent) { if (customEvent.isCancelled()) return; CustomBow cBow = customEvent.getCustomBow(); if (!(cBow.getPermissions() instanceof BowPermissions)) return; BowPermissions perm = (BowPermissions) cBow.getPermissions(); EntityShootBowEvent event = customEvent.getEntityShootBowEvent(); if (event.getEntity().getType().equals(EntityType.PLAYER) && !PermissionUtils.allowedAction((Player) event.getEntity(), perm.getType(), perm.getShoot())) event.setCancelled(true); }
Example #13
Source File: Main.java From TAB with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public Player[] getOnlinePlayers(){ try { Object players = Bukkit.class.getMethod("getOnlinePlayers").invoke(null); if (players instanceof Player[]) { //1.5.x - 1.6.x return (Player[]) players; } else { //1.7+ return ((Collection<Player>)players).toArray(new Player[0]); } } catch (Exception e) { return Shared.errorManager.printError(new Player[0], "Failed to get online players"); } }
Example #14
Source File: EditCommand.java From DungeonsXL with GNU General Public License v3.0 | 5 votes |
@Override public void onExecute(String[] args, CommandSender sender) { Player player = (Player) sender; ResourceWorld resource = plugin.getMapRegistry().getFirstIf(d -> d.getName().equalsIgnoreCase(args[1])); if (resource == null) { MessageUtil.sendMessage(sender, DMessage.ERROR_NO_SUCH_MAP.getMessage(args[1])); return; } if (!resource.isInvitedPlayer(player) && !DPermission.hasPermission(player, DPermission.EDIT)) { MessageUtil.sendMessage(player, CommonMessage.CMD_NO_PERMISSION.getMessage()); return; } EditWorld editWorld = resource.getOrInstantiateEditWorld(false); if (editWorld == null) { MessageUtil.sendMessage(player, DMessage.ERROR_TOO_MANY_INSTANCES.getMessage()); return; } PlayerGroup dGroup = plugin.getPlayerGroup(player); GlobalPlayer dPlayer = dPlayers.get(player); if (dPlayer instanceof InstancePlayer) { MessageUtil.sendMessage(player, DMessage.ERROR_LEAVE_DUNGEON.getMessage()); return; } if (dGroup != null) { MessageUtil.sendMessage(player, DMessage.ERROR_LEAVE_GROUP.getMessage()); return; } new DEditPlayer(plugin, player, editWorld); }
Example #15
Source File: AdminCmd.java From askyblock with GNU General Public License v2.0 | 5 votes |
private boolean checkModPerms(Player player2, String[] split) { // Check perms quickly for this command if (player2.isOp()) { return true; } String check = split[0]; // Check special cases if (check.contains("challenge".toLowerCase())) { check = "challenges"; } if (VaultHelper.checkPerm(player2, Settings.PERMPREFIX + "mod." + check.toLowerCase())) { return true; } return false; }
Example #16
Source File: ListCommand.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@Override public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) { if (args.length == 1 && RedProtect.get().ph.hasPerm(sender, "redprotect.command.admin.list")) { if (args[0].isEmpty()) return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList()); else return Bukkit.getOnlinePlayers().stream().map(Player::getName).filter(p -> p.toLowerCase().startsWith(args[0].toLowerCase())).collect(Collectors.toList()); } return new ArrayList<>(); }
Example #17
Source File: CombatTag.java From EliteMobs with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onDamage(EntityDamageByEntityEvent event) { Player player = playerFinder(event); if (player == null) return; if (player.getGameMode().equals(GameMode.CREATIVE)) return; if (player.isInvulnerable()) player.setInvulnerable(false); if (player.isFlying()) { player.setFlying(false); player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(ChatColorConverter.convert(ConfigValues.combatTagConfig.getString(CombatTagConfig.COMBAT_TAG_MESSAGE)))); new BukkitRunnable() { @Override public void run() { //TODO: introduce the featherfall potion effect for versions above 1.12.2 // if (NameHandler.currentVersionIsUnder(13, 0)) { if (!player.isOnline() || player.isDead()) cancel(); if (player.isOnGround()) { player.setFallDistance(0F); cancel(); } // } else { ////TODO: introduce the featherfall potion effect for versions above 1.12.2 // if (!player.isOnline() || player.isDead()) // player.removePotionEffect(PotionEffectType.SLOW); // cancel(); // if (player.isOnGround()) { // player.setFallDistance(0F); // cancel(); // } // // } } }.runTaskTimer(MetadataHandler.PLUGIN, 0, 1); } }
Example #18
Source File: InfoCommand.java From AACAdditionPro with GNU General Public License v3.0 | 5 votes |
@Override protected void execute(CommandSender sender, Queue<String> arguments) { // Peek for better performance final Player player = AACAdditionPro.getInstance().getServer().getPlayer(arguments.peek()); if (player == null) { ChatMessage.sendPlayerNotFoundMessage(sender); return; } final List<ModuleVl> messages = new ArrayList<>(); int vl; for (ModuleType moduleType : ModuleType.VL_MODULETYPES) { vl = AACAdditionPro.getInstance().getModuleManager().getViolationLevelManagement(moduleType).getVL(player.getUniqueId()); if (vl != 0) { messages.add(new ModuleVl(moduleType, vl)); } } ChatMessage.sendInfoMessage(sender, ChatColor.GOLD, player.getName()); if (messages.isEmpty()) { ChatMessage.sendInfoMessage(sender, ChatColor.GOLD, "The player has no violations."); } else { messages.sort(ModuleVl::compareTo); messages.forEach(moduleVl -> ChatMessage.sendInfoMessage(sender, ChatColor.GOLD, moduleVl.getDisplayMessage())); } }
Example #19
Source File: Player112Listener.java From BedWars with GNU Lesser General Public License v3.0 | 5 votes |
@EventHandler public void onPickup(EntityPickupItemEvent event) { if (!(event.getEntity() instanceof Player)) { return; } PlayerListener.onItemPickup((Player) event.getEntity(), event.getItem(), event); }
Example #20
Source File: ViewConversation.java From ServerTutorial with MIT License | 5 votes |
@Override public Prompt getNextPrompt(ConversationContext context) { Player player = (Player) context.getForWhom(); String location = ServerTutorial.getInstance().getServer().getPlayer(player.getName()).getLocation() .getWorld().getName() + "," + ServerTutorial.getInstance().getServer().getPlayer(player.getName() ).getLocation().getX() + "," + ServerTutorial.getInstance().getServer().getPlayer(player.getName()) .getLocation().getY() + "," + ServerTutorial.getInstance().getServer().getPlayer(player.getName() ).getLocation().getZ() + "," + ServerTutorial.getInstance().getServer().getPlayer(player.getName()) .getLocation().getYaw() + "," + ServerTutorial.getInstance().getServer().getPlayer(player.getName ()).getLocation().getPitch(); String message = context.getSessionData("message").toString(); String messageType = context.getSessionData("messagetype").toString(); String name = context.getSessionData("name").toString(); String viewTime = context.getSessionData("viewtime").toString(); int viewID = 1; while (DataLoading.getDataLoading().getData().get("tutorials." + context.getSessionData("name") + ".views" + "." + viewID) != null) { viewID++; } try { DataLoading.getDataLoading().getData().set("tutorials." + name + ".views." + viewID + ".message", message); DataLoading.getDataLoading().getData().set("tutorials." + name + ".views." + viewID + ".messagetype", messageType); DataLoading.getDataLoading().getData().set("tutorials." + name + ".views." + viewID + ".location", location); DataLoading.getDataLoading().getData().set("tutorials." + name + ".views." + viewID + ".viewtime", viewTime); DataLoading.getDataLoading().saveData(); Caching.getCaching().reCasheTutorials(); } catch (Exception e) { e.printStackTrace(); } AddViewEvent event = new AddViewEvent(player, TutorialManager.getManager().getTutorial(name), TutorialManager.getManager().getTutorialView(name, viewID)); ServerTutorial.getInstance().getServer().getPluginManager().callEvent(event); return END_OF_CONVERSATION; }
Example #21
Source File: ExecutorCaller.java From FunnyGuilds with Apache License 2.0 | 5 votes |
@Override public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args) { if (!(sender instanceof Player)) { return Collections.emptyList(); } if (this.secondary != null) { return Arrays.asList(this.secondary); } else { return null; } }
Example #22
Source File: ProcessSyncPlayerLogout.java From AuthMeReloaded with GNU General Public License v3.0 | 5 votes |
private void applyLogoutEffect(Player player) { // dismount player player.leaveVehicle(); teleportationService.teleportOnJoin(player); // Apply Blindness effect if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) { int timeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND; player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, timeout, 2)); } // Set player's data to unauthenticated limboService.createLimboPlayer(player, true); }
Example #23
Source File: UHPluginListener.java From KTP with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onEntityRegainHealth(final EntityRegainHealthEvent ev) { if (ev.getRegainReason() == RegainReason.SATIATED) ev.setCancelled(true); if (ev.getEntity() instanceof Player) { Bukkit.getScheduler().runTaskLater(this.p, new BukkitRunnable() { @Override public void run() { p.updatePlayerListName((Player)ev.getEntity()); } }, 1L); } }
Example #24
Source File: uSkyBlock.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
public boolean playerIsInSpawn(Player player) { Location pLoc = player.getLocation(); if (!getWorldManager().isSkyWorld(pLoc.getWorld())) { return false; } Location spawnCenter = new Location(WorldManager.skyBlockWorld, 0, pLoc.getBlockY(), 0); return spawnCenter.distance(pLoc) <= Settings.general_spawnSize; }
Example #25
Source File: Pet.java From SonarPet with GNU General Public License v3.0 | 5 votes |
@SneakyThrows(CancelledSpawnException.class) public Pet(Player owner) { Objects.requireNonNull(owner, "Null owner"); this.ownerId = Objects.requireNonNull(owner.getUniqueId()); this.petType = this.determinePetType(); this.setPetName(petType.getDefaultName(owner.getName())); spawnPet(getOwner(), getPetType().getPrimaryHookType(), false); }
Example #26
Source File: HarborCommand.java From Harbor with MIT License | 5 votes |
@Override public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { final String prefix = Config.getString("messages.miscellaneous.chat-prefix"); if (args.length < 1 || !sender.hasPermission("harbor.admin")) { sender.sendMessage(ChatColor.translateAlternateColorCodes('&', String.format( "%sHarbor version %s by TechToolbox (@nkomarn).", prefix, Harbor.version))); } else if (args[0].equalsIgnoreCase("reload")) { Harbor.getHarbor().reloadConfig(); sender.sendMessage(ChatColor.translateAlternateColorCodes('&', prefix + "Reloaded configuration.")); } else if (args[0].equalsIgnoreCase("forceskip")) { if (!(sender instanceof Player)) { sender.sendMessage(ChatColor.translateAlternateColorCodes('&', prefix + "This command requires you to be a player.")); } else { Player player = (Player) sender; World world = player.getWorld(); if (Checker.SKIPPING_WORLDS.contains(world)) { sender.sendMessage(ChatColor.translateAlternateColorCodes('&', prefix + "This world's time is already being accelerated.")); } else { Checker.SKIPPING_WORLDS.add(world); new AccelerateNightTask(world).runTaskTimer(Harbor.getHarbor(), 0L, 1); sender.sendMessage(ChatColor.translateAlternateColorCodes('&', prefix + "Forcing night skip in your world.")); } } } else { sender.sendMessage(ChatColor.translateAlternateColorCodes('&', prefix + Config.getString("messages.miscellaneous.unrecognized-command"))); } return true; }
Example #27
Source File: IndividualPrefixManager.java From FunnyGuilds with Apache License 2.0 | 5 votes |
public static void addPlayer(String player) { for (Player p : Bukkit.getOnlinePlayers()) { IndividualPrefix prefix = User.get(p).getCache().getIndividualPrefix(); if (prefix == null) { continue; } prefix.addPlayer(player); } updatePlayers(); }
Example #28
Source File: EffNameOfScore.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public boolean init(Expression<?>[] exp, int arg1, Kleenean arg2, ParseResult arg3) { players = (Expression<Player>) exp[0]; name = (Expression<String>) exp[1]; return true; }
Example #29
Source File: RequestDenyCommand.java From MarriageMaster with GNU General Public License v3.0 | 5 votes |
@Override public void execute(@NotNull final CommandSender sender, @NotNull String mainCommandAlias, @NotNull String alias, @NotNull String[] args) { MarriagePlayer player = getMarriagePlugin().getPlayerData((Player) sender); if(player.getOpenRequest() != null) { player.getOpenRequest().deny(player); } else { messageNothingToDeny.send(sender); } }
Example #30
Source File: PlaysoundEvent.java From BetonQuest with GNU General Public License v3.0 | 5 votes |
@Override protected Void execute(String playerID) throws QuestRuntimeException { Player player = PlayerConverter.getPlayer(playerID); if (location != null) { player.playSound(location.getLocation(playerID), sound, soundCategoty, volume, pitch); } else { player.playSound(player.getLocation(), sound, soundCategoty, volume, pitch); } return null; }