本文整理汇总了Java中org.spongepowered.api.entity.living.player.Player类的典型用法代码示例。如果您正苦于以下问题:Java Player类的具体用法?Java Player怎么用?Java Player使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Player类属于org.spongepowered.api.entity.living.player包,在下文中一共展示了Player类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.spongepowered.api.entity.living.player.Player; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource source, CommandContext context) throws CommandException {
//https://docs.spongepowered.org/stable/zh-CN/plugin/commands/arguments.html?highlight=commandcontext
if (context.hasAny("arg")) {
String[] args = context.<String>getOne("arg").get().split(" ");
for (CommandHandler handler : this.handlerList) {
if (args[0].equalsIgnoreCase(handler.getName()) && handler.hasPermission(source)) {
if (!handler.hasPermission(source)) {//如果命令已禁用后台执行并且执行者是后台
if (source instanceof Player) {
source.sendMessage(TextUtil.of("§c你没有执行该命令的权限."));
} else {
source.sendMessage(TextUtil.of("§c后台无法执行该命令."));
}
} else {//否则
handler.execute(source, args.length == 1 ? new String[0] : Util.subArray(args, 1, args.length - 1));
return CommandResult.success();
}
}
}
}
source.sendMessage(TextUtil.of("§2输入/" + McrmbPluginInfo.config.command + " help §2来查看帮助"));
return CommandResult.success();
}
示例2: joined
import org.spongepowered.api.entity.living.player.Player; //导入依赖的package包/类
@Listener(order=Order.FIRST)
public void joined(ClientConnectionEvent.Join event) {
Player player = event.getTargetEntity();
Collection<ProfileProperty> props = player.getProfile().getPropertyMap().get("language");
Locale checkload = null;
for (ProfileProperty prop : props)
if (prop.getName().equalsIgnoreCase("language")) {
playerLang.put(player.getProfile().getUniqueId(), checkload=Locale.forLanguageTag(prop.getValue().replace('_', '-')));
break;
}
//use geo location in the future? player.getLocale seems to stick to en_US
if (checkload==null)
playerLang.put(player.getProfile().getUniqueId(), checkload=player.getLocale());
loadLang(checkload);
}
示例3: inspectContainer
import org.spongepowered.api.entity.living.player.Player; //导入依赖的package包/类
public synchronized void inspectContainer(Player p, UUID world, Vector3i pos) {
Connection c = db.getConnection();
ContainerLookupResult lookup = null;
try {
PreparedStatement ps = c.prepareStatement(QueryHelper.INSPECT_CONTAINER_QUERY);
ps.setInt(1, pos.getX());
ps.setInt(2, pos.getY());
ps.setInt(3, pos.getZ());
ps.setString(4, world.toString());
ResultSet result = ps.executeQuery();
lookup = new ContainerLookupResult(result);
LookupResultManager.instance().setLookupResult(p, lookup);
result.close();
c.close();
} catch (SQLException e) {
e.printStackTrace();
p.sendMessage(Text.of(TextColors.DARK_AQUA, "[AC] ", TextColors.RED, "A database error has occurred! Contact your server administrator!"));
return;
}
lookup.showPage(p, 1);
}
示例4: getBackpackSize
import org.spongepowered.api.entity.living.player.Player; //导入依赖的package包/类
public int getBackpackSize(Player player, Integer size) {
if (size == 0) {
if (player.hasPermission(VTPermissions.COMMAND_BACKPACK_SIZE_SIX))
return 6;
if (player.hasPermission(VTPermissions.COMMAND_BACKPACK_SIZE_FIVE))
return 5;
if (player.hasPermission(VTPermissions.COMMAND_BACKPACK_SIZE_FOUR))
return 4;
if (player.hasPermission(VTPermissions.COMMAND_BACKPACK_SIZE_THREE))
return 3;
if (player.hasPermission(VTPermissions.COMMAND_BACKPACK_SIZE_TWO))
return 2;
if (player.hasPermission(VTPermissions.COMMAND_BACKPACK_SIZE_ONE))
return 1;
return 1;
} else {
if (size < 6) {
return 6;
} else {
return size;
}
}
}
示例5: allyChatCommand
import org.spongepowered.api.entity.living.player.Player; //导入依赖的package包/类
@Command(name = "ally", description = "Писать в чат альянса", isPlayerOnly = true, isClanOnly = true, clanPermission = "allychat", spongePermission = "mcclans.user.chat.ally")
public void allyChatCommand(Player player, ClanPlayerImpl clanPlayer, @Multiline @Parameter(name = "message") Optional<String> optionalMessage) {
if (optionalMessage.isPresent()) {
String message = optionalMessage.get();
if (clanPlayer.getTempChatState() == null) {
if (clanPlayer.getIgnoreAllyChat()) {
Messages.sendYouNeedToUnignoreAllyChatBeforeTalking(player);
} else {
clanPlayer.setTempChatState(PlayerChatState.ALLY);
AllyMessageChannelImpl.getFor(clanPlayer).send(player, Text.of(message));
clanPlayer.setTempChatState(null);
}
}
} else {
PlayerChatState chatState = clanPlayer.getChatState();
if (chatState.equals(PlayerChatState.ALLY)) {
clanPlayer.setChatState(PlayerChatState.GLOBAL);
Messages.sendNowTalkingInGlobal(player);
} else {
clanPlayer.setChatState(PlayerChatState.ALLY);
Messages.sendNowTalkingInAllyChat(player);
}
}
}
示例6: resetPlayerEVs
import org.spongepowered.api.entity.living.player.Player; //导入依赖的package包/类
private void resetPlayerEVs(NBTTagCompound nbt, Player player)
{
int EVHP = nbt.getInteger(NbtKeys.EV_HP);
int EVATT = nbt.getInteger(NbtKeys.EV_ATTACK);
int EVDEF = nbt.getInteger(NbtKeys.EV_DEFENCE);
int EVSPATT = nbt.getInteger(NbtKeys.EV_SPECIAL_ATTACK);
int EVSPDEF = nbt.getInteger(NbtKeys.EV_SPECIAL_DEFENCE);
int EVSPD = nbt.getInteger(NbtKeys.EV_SPEED);
printToLog(1, "Command has been confirmed, printing old EVs...");
printToLog(1, "HP: §6" + EVHP + "§e | ATK: §6" + EVATT + "§e | DEF: §6" + EVDEF +
"§e | SPATK: §6" + EVSPATT + "§e | SPDEF: §6" + EVSPDEF + "§e | SPD: §6" + EVSPD);
nbt.setInteger(NbtKeys.EV_HP, 0);
nbt.setInteger(NbtKeys.EV_ATTACK, 0);
nbt.setInteger(NbtKeys.EV_DEFENCE, 0);
nbt.setInteger(NbtKeys.EV_SPECIAL_ATTACK, 0);
nbt.setInteger(NbtKeys.EV_SPECIAL_DEFENCE, 0);
nbt.setInteger(NbtKeys.EV_SPEED, 0);
if (nbt.getString("Nickname").equals(""))
player.sendMessage(Text.of("§2" + nbt.getString("Name") + "§a had its EVs wiped!"));
else
player.sendMessage(Text.of("§aYour §2" + nbt.getString("Nickname") + "§a had its EVs wiped!"));
}
示例7: listRewards
import org.spongepowered.api.entity.living.player.Player; //导入依赖的package包/类
public void listRewards(Player player, VirtualCrate vc){
if(!vc.showRewardsOnLeft) return;
/* Home */
StateContainer test = new StateContainer();
Page.PageBuilder rewards = Page.builder();
rewards.setAutoPaging(true);
rewards.setTitle(TextSerializers.FORMATTING_CODE.deserialize(vc.displayName + " Rewards"));
rewards.setEmptyStack(ItemStack.builder()
.itemType(ItemTypes.STAINED_GLASS_PANE)
.add(Keys.DYE_COLOR, DyeColors.BLACK)
.add(Keys.DISPLAY_NAME, Text.of(TextColors.DARK_GRAY, "HuskyCrates")).build());
for(Object[] e : vc.getItemSet()){
CrateReward rew = (CrateReward)e[1];
ItemStack item = rew.getDisplayItem().copy();
if(vc.showProbability) {
ArrayList<Text> lore = (ArrayList<Text>) item.getOrElse(Keys.ITEM_LORE, new ArrayList<>());
lore.add(Text.of());
lore.add(Text.of(TextColors.GRAY, TextStyles.ITALIC, "Win Probability: " + BigDecimal.valueOf((rew.getChance() / vc.getMaxProb()) * 100d).setScale(1, RoundingMode.HALF_UP).toString() + "%"));
item.offer(Keys.ITEM_LORE, lore);
}
rewards.addElement(new Element(item));
}
test.setInitialState(rewards.build("rewards"));
test.launchFor(player);
}
示例8: execute
import org.spongepowered.api.entity.living.player.Player; //导入依赖的package包/类
@Override public CommandResult execute(CommandSource commandSource, CommandContext commandContext) throws CommandException {
if (!(commandSource instanceof Player)) {
commandSource.sendMessage(Text.of("You need to be in game or specify a player for this command to work."));
return CommandResult.empty();
}
Player plr = (Player)commandSource;
if(!plr.getItemInHand(HandTypes.MAIN_HAND).isPresent()){
commandSource.sendMessage(Text.of("You must be holding an item to deposit a key."));
return CommandResult.empty();
}
ItemStack key = plr.getItemInHand(HandTypes.MAIN_HAND).get();
if(HuskyCrates.instance.crateUtilities.vcFromKey(key) == null){
commandSource.sendMessage(Text.of(TextColors.RED,"Not a valid key."));
return CommandResult.empty();
}
VirtualCrate virtualCrate = HuskyCrates.instance.crateUtilities.vcFromKey(plr.getItemInHand(HandTypes.MAIN_HAND).get());
int keyCount = key.getQuantity();
plr.setItemInHand(HandTypes.MAIN_HAND,null);
virtualCrate.giveVirtualKeys(plr,keyCount);
//commandSource.sendMessage(Text.of(TextColors.GREEN,"Successfully deposited " + keyCount + " ", TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName),TextColors.GREEN," Key(s)."));
commandSource.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(
virtualCrate.getLangData().formatter(virtualCrate.getLangData().depositSuccess,null,plr,virtualCrate,null,null,keyCount)
));
return CommandResult.success();
}
示例9: accept
import org.spongepowered.api.entity.living.player.Player; //导入依赖的package包/类
@Override
public void accept(CommandResult commandResult)
{
Player player = playerReference.get();
if (!Objects.isNull(player))
{
Tuple<String, String> t = commandList.poll();
if (Objects.isNull(t))
{
permissionMap.removeAll(this);
permissionManager.setIgnored(player, permissionMap.values());
}
else
{
activatedPlayers.add(player.getUniqueId());
String prefix = t.getFirst(), suffix = t.getSecond();
String command = prefix.isEmpty() ? suffix : prefix + ": " + suffix;
String escapedCommand = '\'' + SpongeUnimplemented.escapeString(command) + '\'';
logger.debug("Player {} is now executing {}", player.getName(), escapedCommand);
executors.get(prefix).doAction(player, suffix, this);
}
}
}
示例10: execute
import org.spongepowered.api.entity.living.player.Player; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (!(src instanceof Player)) {
src.sendMessage(Text.of(TextColors.RED, "Lookups can only be performed by players"));
return CommandResult.empty();
}
Player p = (Player) src;
Collection<String> filters = args.getAll("filter");
LookupResult lookup = LookupResultManager.instance().getLookupResult(p);
if (lookup == null) {
src.sendMessage(Text.of(TextColors.DARK_AQUA, "[AS] ", TextColors.YELLOW, "You have no lookup history!"));
return CommandResult.empty();
}
FilterSet filterSet = new FilterSet(plugin, p, false);
filterSet.forceLookupType(lookup.getLookupType());
FilterParser.parse(filters, filterSet, p);
lookup.filterResult(filterSet);
lookup.showPage(p, 1);
return CommandResult.success();
}
示例11: open
import org.spongepowered.api.entity.living.player.Player; //导入依赖的package包/类
@Override
public void open(Player player, Manager manager) {
PlayerOpenCrateEvent open_event = new PlayerOpenCrateEvent(player, manager);
Sponge.getEventManager().post(open_event);
if (open_event.isCancelled()) return;
Inventory inventory = display_name.map(text -> Inventory.builder().of(InventoryArchetypes.CHEST).
property(InventoryDimension.PROPERTY_NAME, new InventoryDimension(9, rows)).
property(InventoryTitle.PROPERTY_NAME, new InventoryTitle(text)).
build(GWMCrates.getInstance())).orElseGet(() -> Inventory.builder().of(InventoryArchetypes.CHEST).
property(InventoryDimension.PROPERTY_NAME, new InventoryDimension(9, rows)).
build(GWMCrates.getInstance()));
OrderedInventory ordered = Utils.castToOrdered(inventory);
int hidden_item_quantity = hidden_item.getQuantity();
for (int i = 0; i < 9 * rows; i++) {
int quantity = increase_hidden_item_quantity ? i + 1 : hidden_item_quantity;
ItemStack copy = hidden_item.copy();
copy.setQuantity(quantity);
ordered.getSlot(new SlotIndex(i)).get().set(copy);
}
Container container = player.openInventory(inventory).get();
getOpenSound().ifPresent(open_sound -> player.playSound(open_sound, player.getLocation().getPosition(), 1.));
SECOND_GUI_INVENTORIES.put(container, new Pair<SecondOpenManager, Manager>(this, manager));
}
示例12: onChangeSignEvent
import org.spongepowered.api.entity.living.player.Player; //导入依赖的package包/类
@Listener
public void onChangeSignEvent(ChangeSignEvent e, @First Player player) {
if (plugin.getMainConfig().isUseSigns()) {
if (player.hasPermission("minecraftmarket.signs")) {
Optional<Text> optionalLine1 = e.getText().get(0);
Optional<Text> optionalLine2 = e.getText().get(1);
if (optionalLine1.isPresent() && optionalLine2.isPresent()) {
String line1 = optionalLine1.get().toPlain();
String line2 = optionalLine2.get().toPlain();
if (line1.equals("[RecentDonor]") && Utils.isInt(line2)) {
int order = Utils.getInt(line2);
if (order > 0) {
if (plugin.getSignsConfig().addDonorSign(order, e.getTargetTile().getLocation())) {
player.sendMessage(Colors.color(I18n.tl("prefix") + " " + I18n.tl("sign_added")));
plugin.getSignsTask().updateSigns();
}
}
}
}
}
}
}
示例13: printCorrectPerm
import org.spongepowered.api.entity.living.player.Player; //导入依赖的package包/类
private void printCorrectPerm(int cost, Player player)
{
if (cost != 0)
{
if (player.hasPermission("pixelupgrade.command.other.checkegg"))
player.sendMessage(Text.of("§4Usage: §c/" + commandAlias + " [optional target] <slot, 1-6> {-c to confirm}"));
else
player.sendMessage(Text.of("§4Usage: §c/" + commandAlias + " <slot> {-c to confirm} §7(no perms for target)"));
}
else
{
if (player.hasPermission("pixelupgrade.command.other.checkegg"))
player.sendMessage(Text.of("§4Usage: §c/" + commandAlias + " [optional target] <slot, 1-6>"));
else
player.sendMessage(Text.of("§4Usage: §c/" + commandAlias + " <slot> §7(no perms for target)"));
}
}
示例14: submitCommands
import org.spongepowered.api.entity.living.player.Player; //导入依赖的package包/类
public void submitCommands(Player player, List<String> commands, List<String> ignoredPermissions)
{
plugin.getLogger().debug("Player {} tries to run {} command(s)", player.getName(), commands.size());
VirtualChestPlaceholderManager placeholderManager = this.plugin.getPlaceholderManager();
LinkedList<Tuple<String, String>> commandList = new LinkedList<>();
for (String command : commands)
{
int colonPos = command.indexOf(PREFIX_SPLITTER);
String prefix = colonPos > 0 ? command.substring(0, colonPos) : "";
if (this.executors.containsKey(prefix))
{
int length = command.length(), suffixPosition = colonPos + 1;
while (suffixPosition < length && Character.isWhitespace(command.charAt(suffixPosition)))
{
++suffixPosition;
}
String suffix = command.substring(suffixPosition);
commandList.add(Tuple.of(prefix, placeholderManager.parseText(player, suffix)));
}
else if (!command.isEmpty())
{
commandList.add(Tuple.of("", placeholderManager.parseText(player, command)));
}
}
new Callback(player, commandList, ignoredPermissions).start();
}
示例15: onPlayerJoin
import org.spongepowered.api.entity.living.player.Player; //导入依赖的package包/类
@Listener
public void onPlayerJoin(ClientConnectionEvent event)
{
if(event.getCause().root() instanceof Player)
{
Player player = (Player) event.getCause().root();
if(PowerService.checkIfPlayerExists(player.getUniqueId()))
{
PowerService.increasePower(player.getUniqueId());
return;
}
else
{
//Create player file and set power.
PowerService.addPlayer(player.getUniqueId());
PlayerService.setPlayerChunkPosition(player.getUniqueId(), player.getLocation().getChunkPosition());
return;
}
}
}