本文整理汇总了Java中org.spongepowered.api.text.chat.ChatTypes类的典型用法代码示例。如果您正苦于以下问题:Java ChatTypes类的具体用法?Java ChatTypes怎么用?Java ChatTypes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ChatTypes类属于org.spongepowered.api.text.chat包,在下文中一共展示了ChatTypes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeTransaction
import org.spongepowered.api.text.chat.ChatTypes; //导入依赖的package包/类
public CommandResult executeTransaction(CommandSource src, CommandContext args, ShopTransactionCommandProcessor processor, String consoleReject) throws CommandException {
if (src instanceof Player) {
Player player = (Player) src;
Optional<String> shopUUIDOptional = args.getOne(Text.of(CommandArgs.SHOP_UUID));
Optional<ShopContainer> shopContainerOptional = shopUUIDOptional.isPresent() ? shopManager.getShopByUUID(UUID.fromString(shopUUIDOptional.get()), player) : shopManager.getShop(player);
if (shopContainerOptional.isPresent()) {
ShopContainer shopContainer = shopContainerOptional.get();
Shop shop = shopContainer.getShop();
ShopTransactionResult transactionResult = processor.processCommand(player, args, shop);
if (transactionResult != ShopTransactionResult.SUCCESS && !transactionResult.getMessage().isEmpty()) {
player.sendMessage(ChatTypes.CHAT, Text.of(TextColors.RED, transactionResult.getMessage()));
}
} else {
player.sendMessage(ChatTypes.CHAT, Text.of(TextColors.RED, Messages.YOU_ARE_NOT_IN_A_SHOP));
}
return CommandResult.success();
}
src.sendMessage(Text.of(consoleReject));
return CommandResult.success();
}
示例2: execute
import org.spongepowered.api.text.chat.ChatTypes; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
return super.executeTransaction(src, args, (player, arg, shop) -> {
Optional<String> itemIndexArgumentOptional = arg.getOne(CommandArgs.ITEM_INDEX);
if (itemIndexArgumentOptional.isPresent()) {
Optional<ShopItem> shopItem = shop.getShopItem(UUID.fromString(itemIndexArgumentOptional.get()));
if (shopItem.isPresent()) {
ShopTransactionResult transactionResult = shop.destroyItem(player, shopItem.get().getShopItemUUID());
if (transactionResult == ShopTransactionResult.SUCCESS) {
shopItem.ifPresent(item -> SQLDataUtil.deleteShopItem(item.getShopItemUUID(), plugin.getLogger()));
player.sendMessage(ChatTypes.CHAT, Text.of(TextColors.BLUE, Messages.processDropins(Messages.DESTROY_ITEM_SUCCESS,
ImmutableMap.of(Messages.DROPIN_SHOP_NAME, shop.getName(), Messages.DROPIN_ITEM_INDEX,
String.valueOf(itemIndexArgumentOptional.get())))));
}
return transactionResult;
}
}
return ShopTransactionResult.EMPTY;
}, Messages.DESTROY_ITEM_CONSOLE_REJECT);
}
示例3: execute
import org.spongepowered.api.text.chat.ChatTypes; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (src instanceof Player) {
Player player = (Player) src;
Optional<ShopContainer> shopContainerOptional = shopManager.getShop(player);
if (shopContainerOptional.isPresent()) {
ShopContainer shopContainer = shopContainerOptional.get();
if (shopContainer.getShop().hasOwnerPermissions(player)) {
shopManager.removeShop(player);
player.sendMessage(ChatTypes.CHAT, Text.of(TextColors.BLUE, Messages.processDropins(Messages.DESTROY_SUCCESS,
ImmutableMap.of(Messages.DROPIN_SHOP_NAME, shopContainer.getShop().getName()))));
} else {
player.sendMessage(ChatTypes.CHAT, Text.of(TextColors.RED, Messages.DESTROY_NO_PERMISSION));
}
} else {
player.sendMessage(ChatTypes.CHAT, Text.of(TextColors.RED, Messages.YOU_ARE_NOT_IN_A_SHOP));
}
return CommandResult.success();
}
src.sendMessage(Text.of(Messages.DESTROY_CONSOLE_REJECT));
return CommandResult.success();
}
示例4: execute
import org.spongepowered.api.text.chat.ChatTypes; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
return super.executeTransaction(src, args, (player, arg, shop) -> {
Optional<Double> doubleArgOptional = arg.getOne(CommandArgs.DOUBLE_ARGUMENT);
if (doubleArgOptional.isPresent()) {
ShopTransactionResult transactionResult = shop.rentShop(player, BigDecimal.valueOf(doubleArgOptional.get()));
if (transactionResult == ShopTransactionResult.SUCCESS) {
player.sendMessage(ChatTypes.CHAT, Text.of(TextColors.BLUE, Messages.processDropins(Messages.RENT_SHOP_SUCCESS,
ImmutableMap.of(Messages.DROPIN_SHOP_NAME, shop.getName()))));
}
return transactionResult;
}
return ShopTransactionResult.EMPTY;
}, Messages.RENT_CONSOLE_REJECT);
}
示例5: transformMessage
import org.spongepowered.api.text.chat.ChatTypes; //导入依赖的package包/类
@Override
public Optional<Text> transformMessage(@Nullable Object sender, MessageReceiver recipient, Text original, ChatType type) {
Optional<Text> optMessage = super.transformMessage(sender, recipient, original, type);
if (!optMessage.isPresent()) {
return optMessage;
}
// This could be useful as a method on ChatType.
boolean isChatArea = type == ChatTypes.CHAT || type == ChatTypes.SYSTEM;
if (recipient instanceof Player && isChatArea) {
PlayerChatView view = ChatUILib.getView((Player) recipient);
CommandSource source = this.causeSource;
if (sender instanceof CommandSource) {
source = (CommandSource) sender;
}
if (view != null) {
return view.transformOutgoing(source, optMessage.get(), type);
}
}
return optMessage;
}
示例6: reload
import org.spongepowered.api.text.chat.ChatTypes; //导入依赖的package包/类
public void reload() {
if (this.task != null) {
this.task.cancel();
}
HashMap<UUID, ActionBarMessage> actionBars = new HashMap<UUID, ActionBarMessage>(this.players);
this.players.clear();
for (Entry<UUID, ActionBarMessage> actionBar : actionBars.entrySet()) {
Optional<EPlayer> player = this.plugin.getEServer().getEPlayer(actionBar.getKey());
if (player.isPresent()) {
player.get().sendMessage(ChatTypes.ACTION_BAR, Text.EMPTY);
// Event
this.postRemove(player.get(), actionBar.getValue());
}
}
}
示例7: updateSync
import org.spongepowered.api.text.chat.ChatTypes; //导入依赖的package包/类
public void updateSync(List<UUID> players) {
for (UUID uuid : players) {
ActionBarMessage actionBar = this.players.get(uuid);
if (actionBar != null && System.currentTimeMillis() + LAST_UPDATE > actionBar.getTime()) {
this.players.remove(uuid);
Optional<EPlayer> player = this.plugin.getEServer().getEPlayer(uuid);
if (player.isPresent()) {
player.get().sendMessage(ChatTypes.ACTION_BAR, Text.EMPTY);
//Event
this.postRemove(player.get(), actionBar);
}
}
}
if (this.players.isEmpty()) {
stop();
} else {
start();
}
}
示例8: onEntityDamage
import org.spongepowered.api.text.chat.ChatTypes; //导入依赖的package包/类
@Listener
public void onEntityDamage(DamageEntityEvent event, @Root EntityDamageSource dmgSource) {
if(dmgSource.getSource() instanceof Player) {
Player player = (Player)dmgSource.getSource();
EntityType entityType = event.getTargetEntity().getType();
String entityId = entityType.getId();
PermHandler ph = PermHandler.getInstance();
if (!ph.checkPerm(player, "protectionperms.entity.damage." + entityId + ".deal")) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR,
Text.of(TextColors.RED, "You don't have permission to damage " + entityType.getName() + "s!"));
}
}
}
示例9: onItemDrop
import org.spongepowered.api.text.chat.ChatTypes; //导入依赖的package包/类
@Listener
public void onItemDrop(DropItemEvent.Dispense event, @Root Player player) {
PermHandler ph = PermHandler.getInstance();
event.filterEntities(entity -> {
if (entity.getType().equals(EntityTypes.ITEM)) {
Item item = (Item) entity;
ItemType itemType = item.getItemType();
String itemId = itemType.getId();
if (!ph.checkPerm(player, "protectionperms.item.drop." + itemId + ".dispense")) {
player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to drop " + itemType.getName() + '!'));
return false;
}
}
return true;
});
}
示例10: onInteractBlockPrimaryMain
import org.spongepowered.api.text.chat.ChatTypes; //导入依赖的package包/类
@Listener
public void onInteractBlockPrimaryMain(InteractBlockEvent.Primary event, @Root Player player) {
Optional<ItemStack> itemStackOptional = player.getItemInHand(event.getHandType());
if(itemStackOptional.isPresent()) {
BlockState blockState = event.getTargetBlock().getState();
String blockTypeId = blockState.getType().getId();
String blockStateId = blockState.getId();
ItemType itemType = itemStackOptional.get().getType();
String itemId = itemType.getId();
PermHandler ph = PermHandler.getInstance();
if (!ph.checkPerm(player, "protectionperms.item.use." + itemId + ".on." + blockTypeId + ".primary",
"protectionperms.item.use." + itemId + ".on." + blockStateId + ".primary")) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR,
Text.of(TextColors.RED, "You don't have permission to primary use " + itemType.getName() + " on " + blockState.getName() + '!'));
}
}
}
示例11: onInteractBlockSecondaryMain
import org.spongepowered.api.text.chat.ChatTypes; //导入依赖的package包/类
@Listener
public void onInteractBlockSecondaryMain(InteractBlockEvent.Secondary event, @Root Player player) {
Optional<ItemStack> itemStackOptional = player.getItemInHand(event.getHandType());
if(itemStackOptional.isPresent()) {
BlockState blockState = event.getTargetBlock().getState();
String blockTypeId = blockState.getType().getId();
String blockStateId = blockState.getId();
ItemType itemType = itemStackOptional.get().getType();
String itemId = itemType.getId();
PermHandler ph = PermHandler.getInstance();
if (!ph.checkPerm(player, "protectionperms.item.use." + itemId + ".on." + blockTypeId + ".secondary",
"protectionperms.item.use." + itemId + ".on." + blockStateId + ".secondary")) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR,
Text.of(TextColors.RED, "You don't have permission to secondary use " + itemType.getName() + " on " + blockState.getName() + '!'));
}
}
}
示例12: onInteractEntitySecondaryMain
import org.spongepowered.api.text.chat.ChatTypes; //导入依赖的package包/类
@Listener
public void onInteractEntitySecondaryMain(InteractEntityEvent.Secondary event, @Root Player player) {
Optional<ItemStack> itemStackOptional = player.getItemInHand(event.getHandType());
if(itemStackOptional.isPresent()) {
EntityType entityType = event.getTargetEntity().getType();
String entityId = entityType.getId();
ItemType itemType = itemStackOptional.get().getType();
String itemId = itemType.getId();
PermHandler ph = PermHandler.getInstance();
if (!ph.checkPerm(player, "protectionperms.item.use." + itemId + ".on." + entityId + ".primary")) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR,
Text.of(TextColors.RED, "You don't have permission to secondary use " + itemType.getName() + " on " + entityType.getName() + "s!"));
}
}
}
示例13: onInteractEntityPrimaryMain
import org.spongepowered.api.text.chat.ChatTypes; //导入依赖的package包/类
@Listener
public void onInteractEntityPrimaryMain(InteractEntityEvent.Primary event, @Root Player player) {
Optional<ItemStack> itemStackOptional = player.getItemInHand(event.getHandType());
if(itemStackOptional.isPresent()) {
EntityType entityType = event.getTargetEntity().getType();
String entityId = entityType.getId();
ItemType itemType = itemStackOptional.get().getType();
String itemId = itemType.getId();
PermHandler ph = PermHandler.getInstance();
if (!ph.checkPerm(player, "protectionperms.item.use." + itemId + ".on." + entityId + ".primary")) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR,
Text.of(TextColors.RED, "You don't have permission to primary use " + itemType.getName() + " on " + entityType.getName() + "s!"));
}
}
}
示例14: onItemEquip
import org.spongepowered.api.text.chat.ChatTypes; //导入依赖的package包/类
@Listener
public void onItemEquip(ClickInventoryEvent event, @First Player player, @Getter("getTargetInventory") Inventory inventory) {
if (inventory.getArchetype() == InventoryArchetypes.PLAYER) {
Inventory equipmentSlots = inventory.query(QueryOperationTypes.INVENTORY_TYPE.of(EquipmentSlot.class));
equipmentSlots.slots().forEach(slot -> slot.peek().ifPresent(itemStack -> {
ItemType itemType = itemStack.getType();
String itemId = itemType.getId();
PermHandler ph = PermHandler.getInstance();
if (!ph.checkPerm(player, "protectionperms.item.equip." + itemId + ".on.self")) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to equip " + itemType.getName() + '!'));
}
}));
}
}
示例15: onItemCraft
import org.spongepowered.api.text.chat.ChatTypes; //导入依赖的package包/类
@Listener
public void onItemCraft(ClickInventoryEvent event, @First Player player, @Getter("getTargetInventory") Inventory inventory) {
if (inventory.getArchetype() == InventoryArchetypes.PLAYER || inventory.getArchetype() == InventoryArchetypes.WORKBENCH) {
Inventory craftingOutputs = inventory.query(QueryOperationTypes.INVENTORY_TYPE.of(CraftingOutput.class));
craftingOutputs.slots().forEach(slot -> slot.peek().ifPresent(itemStack -> {
ItemType itemType = itemStack.getType();
String itemId = itemType.getId();
PermHandler ph = PermHandler.getInstance();
if (!ph.checkPerm(player, "protectionperms.item.craft." + itemId)) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to craft " + itemType.getName() + '!'));
}
}));
}
}