use of org.spongepowered.api.event.game.state.GameInitializationEvent in project SpongeCommon by SpongePowered.
the class CooldownTrackerTest method onInit.
@Listener
public void onInit(GameInitializationEvent event) {
final CommandSpec test = CommandSpec.builder().executor((src, args) -> {
if (!(src instanceof Player)) {
throw new CommandException(Text.of(TextColors.RED, "You must be a player to execute this command!"));
}
final Player player = (Player) src;
final CooldownTracker cooldownTracker = player.getCooldownTracker();
final ItemType itemType = player.getItemInHand(HandTypes.MAIN_HAND).orElse(ItemStack.empty()).getType();
if (!cooldownTracker.hasCooldown(itemType)) {
player.sendMessage(Text.of(TextColors.GRAY, "The item type in your hand is not on cooldown!"));
} else {
player.sendMessage(Text.of(TextColors.GRAY, "The cooldown remaining for the item type in your hand is ", TextColors.GOLD, cooldownTracker.getCooldown(itemType).orElse(0), TextColors.GRAY, " tick(s)."));
player.sendMessage(Text.of(TextColors.GRAY, "This item type has ", TextColors.GOLD, new DecimalFormat("#.00").format(cooldownTracker.getFractionRemaining(itemType).orElse(0.0) * 100) + "%", TextColors.GRAY, " of its cooldown remaining."));
}
return CommandResult.success();
}).build();
final CommandSpec set = CommandSpec.builder().executor((src, args) -> {
if (!(src instanceof Player)) {
throw new CommandException(Text.of(TextColors.RED, "You must be a player to execute this command!"));
}
final Player player = (Player) src;
final int cooldown = args.<Integer>getOne("cooldown").orElse(10);
player.getCooldownTracker().setCooldown(player.getItemInHand(HandTypes.MAIN_HAND).orElse(ItemStack.empty()).getType(), cooldown);
player.sendMessage(Text.of(TextColors.GRAY, "You have given the item type in your hand a cooldown of ", TextColors.GOLD, cooldown, TextColors.GRAY, " tick(s)."));
return CommandResult.success();
}).arguments(GenericArguments.integer(Text.of("cooldown"))).build();
final CommandSpec enable = CommandSpec.builder().executor(((src, args) -> {
if (!(src instanceof Player)) {
throw new CommandException(Text.of(TextColors.RED, "You must be a player to execute this command!"));
}
final Player player = (Player) src;
if (!this.enabled.remove(player.getUniqueId())) {
this.enabled.add(player.getUniqueId());
src.sendMessage(Text.of(TextColors.GOLD, "You have enabled the cooldown listeners!"));
} else {
src.sendMessage(Text.of(TextColors.GOLD, "You have disabled the cooldown listeners!"));
}
return CommandResult.success();
})).build();
Sponge.getCommandManager().register(this, CommandSpec.builder().executor(((src, args) -> {
src.sendMessage(Text.of(TextColors.GOLD, "Use cooldown set|test|enable"));
return CommandResult.success();
})).child(test, "test").child(set, "set").child(enable, "enable", "disable").build(), "cooldowns");
}
use of org.spongepowered.api.event.game.state.GameInitializationEvent in project SpongeCommon by SpongePowered.
the class InventoryQueryTest method onInitialization.
@Listener
public void onInitialization(GameInitializationEvent e) {
CommandSpec inventoryType = CommandSpec.builder().executor((src, args) -> {
Inventory inventory = getPlayerInventory(src);
Inventory hotbar = inventory.query(QueryOperationTypes.INVENTORY_TYPE.of(Hotbar.class));
src.sendMessage(Text.of("You have ", hotbar.totalItems(), " items in your hotbar."));
return CommandResult.success();
}).build();
CommandSpec itemType = CommandSpec.builder().executor((src, args) -> {
Inventory inventory = getPlayerInventory(src);
Inventory sticks = inventory.query(QueryOperationTypes.ITEM_TYPE.of(ItemTypes.STICK));
src.sendMessage(Text.of("You have ", sticks.totalItems(), " sticks in your inventory."));
return CommandResult.success();
}).build();
CommandSpec itemStackGeneral = CommandSpec.builder().executor((src, args) -> {
Inventory inventory = getPlayerInventory(src);
ItemStack lapis = ItemStack.of(ItemTypes.DYE, 4);
lapis.offer(Keys.DYE_COLOR, DyeColors.BLUE);
Inventory lapisItems = inventory.query(QueryOperationTypes.ITEM_STACK_IGNORE_QUANTITY.of(lapis));
src.sendMessage(Text.of("You have ", lapisItems.totalItems(), " lapis lazuli in your inventory."));
return CommandResult.success();
}).build();
CommandSpec itemStackSpecific = CommandSpec.builder().executor((src, args) -> {
Inventory inventory = getPlayerInventory(src);
ItemStack lapis = ItemStack.of(ItemTypes.DYE, 4);
lapis.offer(Keys.DYE_COLOR, DyeColors.BLUE);
Inventory lapisItems = inventory.query(QueryOperationTypes.ITEM_STACK_EXACT.of(lapis));
src.sendMessage(Text.of("You have ", lapisItems.size(), " stacks of 4 lapis lazuli in your inventory."));
return CommandResult.success();
}).build();
CommandSpec itemStackCustom = CommandSpec.builder().executor((src, args) -> {
Inventory inventory = getPlayerInventory(src);
Inventory evenCountStacks = inventory.query(QueryOperationTypes.ITEM_STACK_CUSTOM.of(x -> x.getQuantity() > 0 && x.getQuantity() % 2 == 0));
src.sendMessage(Text.of("You have ", evenCountStacks.size(), " stacks with an even number of items in your inventory."));
return CommandResult.success();
}).build();
CommandSpec inventoryProperty = CommandSpec.builder().executor((src, args) -> {
Inventory inventory = getPlayerInventory(src);
Inventory slots = ((PlayerInventory) inventory).getHotbar().query(QueryOperationTypes.INVENTORY_PROPERTY.of(new SlotIndex(3, Property.Operator.LESS)));
src.sendMessage(Text.of("You have ", slots.totalItems(), " items in the first 3 slots of your hotbar."));
return CommandResult.success();
}).build();
CommandSpec inventoryTranslation = CommandSpec.builder().executor((src, args) -> {
Inventory inventory = getPlayerInventory(src);
Inventory slots = ((PlayerInventory) inventory).getHotbar().query(QueryOperationTypes.INVENTORY_TRANSLATION.of(Sponge.getRegistry().getTranslationById("slot.name").get()));
src.sendMessage(Text.of("You have ", slots.totalItems(), " items in your hotbar."));
return CommandResult.success();
}).build();
Sponge.getCommandManager().register(this, CommandSpec.builder().child(inventoryType, "inventorytype").child(itemType, "itemtype").child(itemStackGeneral, "itemstackgeneral").child(itemStackSpecific, "itemstackspecific").child(itemStackCustom, "itemstackcustom").child(inventoryProperty, "inventoryproperty").child(inventoryTranslation, "inventorytranslation").build(), "invquery");
}
use of org.spongepowered.api.event.game.state.GameInitializationEvent in project SpongeCommon by SpongePowered.
the class DamageSourceTest method onInit.
@Listener
public void onInit(GameInitializationEvent event) {
Sponge.getCommandManager().register(this, CommandSpec.builder().executor((src, args) -> {
if (src instanceof Player) {
final UUID uuid = ((Player) src).getUniqueId();
if (this.activated.contains(uuid)) {
this.activated.remove(uuid);
src.sendMessage(Text.of("You have deactivated damage source analysis."));
} else {
this.activated.add(uuid);
src.sendMessage(Text.of("You have activated damage source analysis."));
}
return CommandResult.success();
}
throw new CommandException(Text.of(TextColors.RED, "You must be a player to execute this command!"));
}).build(), "dstest");
final DamageSource damageSource = DamageSource.builder().type(DamageTypes.CUSTOM).exhaustion(5).scalesWithDifficulty().build();
Sponge.getCommandManager().register(this, CommandSpec.builder().executor((src, args) -> {
if (src instanceof Player) {
final Player player = (Player) src;
player.damage(args.<Double>getOne("damage").orElse(2.0), damageSource);
player.sendMessage(Text.of("You have damaged yourself with the custom damage source."));
return CommandResult.success();
}
throw new CommandException(Text.of(TextColors.RED, "You must be a player to execute this command!"));
}).arguments(GenericArguments.doubleNum(Text.of("damage"))).build(), "dsdamage");
}
use of org.spongepowered.api.event.game.state.GameInitializationEvent in project PokexpMultiplier by happyzleaf.
the class PokexpMultiplier method init.
@Listener
public void init(GameInitializationEvent event) {
PlaceholderUtility.init();
PokexpConfig.getInstance().setup(configFile, configLoader);
Pixelmon.EVENT_BUS.register(this);
CommandSpec reload = CommandSpec.builder().executor((src, args) -> {
PokexpConfig.getInstance().loadConfig();
src.sendMessage(Text.of(TextColors.DARK_GREEN, "[" + PLUGIN_NAME + "]", TextColors.GREEN, " Config(s) reloaded!"));
return CommandResult.success();
}).description(Text.of("Reload configs.")).permission(PLUGIN_ID + ".admin.reload").build();
CommandSpec info = CommandSpec.builder().arguments(GenericArguments.optional(GenericArguments.requiringPermission(GenericArguments.onlyOne(GenericArguments.player(Text.of("player"))), PLUGIN_ID + ".info.others"))).executor((src, args) -> {
if (args.hasAny("player")) {
Player player = (Player) args.getOne("player").get();
src.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(AlgorithmUtilities.parseInfoWithValues(player, AlgorithmUtilities.algorithmPerUser(player))));
return CommandResult.success();
} else {
if (src instanceof Player) {
src.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(AlgorithmUtilities.parseInfoWithValues((Player) src, AlgorithmUtilities.algorithmPerUser((Player) src))));
return CommandResult.success();
} else {
src.sendMessage(Text.of(TextColors.DARK_RED, "[" + PLUGIN_NAME + "]", TextColors.RED, " Your MUST be in-game in order to execute this command."));
return CommandResult.successCount(0);
}
}
}).permission(PLUGIN_ID + ".info.me").description(Text.of("Get the player's experience algorithm info.")).build();
CommandSpec pokexp = CommandSpec.builder().child(reload, "reload").child(info, "info").build();
Sponge.getGame().getCommandManager().register(this, pokexp, "pokexp", "pkexp");
// Just to check if the method works well
/*Sponge.getGame().getCommandManager().register(this, CommandSpec.builder()
.arguments(GenericArguments.onlyOne(GenericArguments.remainingJoinedStrings(Text.of("operation"))))
.executor(((src, args) -> {
src.sendMessage(Text.of(TextColors.GREEN, "result: " + AlgorithmUtilities.eval((String) args.getOne("operation").get())));
return CommandResult.success();
}))
.build(), "math");*/
LOGGER.info("Loaded!");
}
Aggregations