org.spongepowered.api.event.cause.EventContext Java Examples
The following examples show how to use
org.spongepowered.api.event.cause.EventContext.
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: SignListener.java From UltimateCore with MIT License | 6 votes |
@Listener public void onSignDestroy(ChangeBlockEvent.Break event, @Root Player p) { for (Transaction<BlockSnapshot> transaction : event.getTransactions()) { BlockSnapshot snapshot = transaction.getOriginal(); if (snapshot.supports(Keys.SIGN_LINES) && snapshot.getLocation().isPresent()) { List<Text> texts = snapshot.get(Keys.SIGN_LINES).get(); //Checking for sign contents for (UCSign usign : UltimateCore.get().getSignService().get().getRegisteredSigns()) { if (texts.get(0).toPlain().equalsIgnoreCase("[" + usign.getIdentifier() + "]")) { if (!p.hasPermission(usign.getDestroyPermission().get())) { Messages.send(p, "core.nopermissions"); } SignDestroyEvent cevent = new SignDestroyEvent(usign, snapshot.getLocation().get(), Cause.builder().append(UltimateCore.getContainer()).append(p).build(EventContext.builder().build())); Sponge.getEventManager().post(cevent); if (!cevent.isCancelled() && usign.onDestroy(p, event, texts)) { Messages.send(p, "sign.destroy", "%sign%", usign.getIdentifier()); } } } } } }
Example #2
Source File: RemoveCommand.java From EconomyLite with MIT License | 6 votes |
@Override public void run(CommandSource src, CommandContext args) { if (args.getOne("player").isPresent() && args.getOne("amount").isPresent()) { User target = args.<User>getOne("player").get(); String targetName = target.getName(); BigDecimal toRemove = BigDecimal.valueOf(args.<Double>getOne("amount").get()); Optional<UniqueAccount> uOpt = EconomyLite.getEconomyService().getOrCreateAccount(target.getUniqueId()); if (uOpt.isPresent()) { UniqueAccount targetAccount = uOpt.get(); if (targetAccount.withdraw(EconomyLite.getCurrencyService().getCurrentCurrency(), toRemove, Cause.of(EventContext.empty(),(EconomyLite.getInstance()))).getResult().equals(ResultType.SUCCESS)) { src.sendMessage(messageStorage.getMessage("command.econ.removesuccess", "name", targetName)); attemptNotify(target); } else { src.sendMessage(messageStorage.getMessage("command.econ.removefail", "name", targetName)); } } else { src.sendMessage(messageStorage.getMessage("command.error")); } } else { src.sendMessage(messageStorage.getMessage("command.error")); } }
Example #3
Source File: SetCommand.java From EconomyLite with MIT License | 6 votes |
@Override public void run(CommandSource src, CommandContext args) { if (args.getOne("player").isPresent() && args.getOne("balance").isPresent()) { User target = args.<User>getOne("player").get(); String targetName = target.getName(); BigDecimal newBal = BigDecimal.valueOf(args.<Double>getOne("balance").get()); Optional<UniqueAccount> uOpt = EconomyLite.getEconomyService().getOrCreateAccount(target.getUniqueId()); if (uOpt.isPresent()) { UniqueAccount targetAccount = uOpt.get(); if (targetAccount.setBalance(EconomyLite.getCurrencyService().getCurrentCurrency(), newBal, Cause.of(EventContext.empty(),(EconomyLite.getInstance()))).getResult().equals(ResultType.SUCCESS)) { src.sendMessage(messageStorage.getMessage("command.econ.setsuccess", "name", targetName)); attemptNotify(target); } else { src.sendMessage(messageStorage.getMessage("command.econ.setfail", "name", targetName)); } } else { src.sendMessage(messageStorage.getMessage("command.error")); } } else { src.sendMessage(messageStorage.getMessage("command.error")); } }
Example #4
Source File: AddCommand.java From EconomyLite with MIT License | 6 votes |
@Override public void run(CommandSource src, CommandContext args) { if (args.getOne("player").isPresent() && args.getOne("amount").isPresent()) { User target = args.<User>getOne("player").get(); String targetName = target.getName(); BigDecimal toAdd = BigDecimal.valueOf(args.<Double>getOne("amount").get()); Optional<UniqueAccount> uOpt = EconomyLite.getEconomyService().getOrCreateAccount(target.getUniqueId()); if (uOpt.isPresent()) { UniqueAccount targetAccount = uOpt.get(); if (targetAccount.deposit(EconomyLite.getCurrencyService().getCurrentCurrency(), toAdd, Cause.of(EventContext.empty(),(EconomyLite.getInstance()))).getResult().equals(ResultType.SUCCESS)) { src.sendMessage(messageStorage.getMessage("command.econ.addsuccess", "name", targetName)); attemptNotify(target); } else { src.sendMessage(messageStorage.getMessage("command.econ.addfail", "name", targetName)); } } else { src.sendMessage(messageStorage.getMessage("command.error")); } } else { src.sendMessage(messageStorage.getMessage("command.error")); } }
Example #5
Source File: PayVirtualCommand.java From EconomyLite with MIT License | 6 votes |
@Override public void run(Player src, CommandContext args) { if (args.getOne("target").isPresent() && args.getOne("amount").isPresent()) { String target = args.<String>getOne("target").get(); BigDecimal amount = BigDecimal.valueOf(args.<Double>getOne("amount").get()); Optional<Account> aOpt = EconomyLite.getEconomyService().getOrCreateAccount(target); Optional<UniqueAccount> uOpt = EconomyLite.getEconomyService().getOrCreateAccount(src.getUniqueId()); // Check for negative payments if (amount.doubleValue() <= 0) { src.sendMessage(messageStorage.getMessage("command.pay.invalid")); } else { if (aOpt.isPresent() && uOpt.isPresent()) { Account receiver = aOpt.get(); UniqueAccount payer = uOpt.get(); if (payer.transfer(receiver, ecoService.getDefaultCurrency(), amount, Cause.of(EventContext.empty(), (EconomyLite.getInstance()))) .getResult().equals(ResultType.SUCCESS)) { src.sendMessage(messageStorage.getMessage("command.pay.success", "target", receiver.getDisplayName().toPlain())); } else { src.sendMessage(messageStorage.getMessage("command.pay.failed", "target", receiver.getDisplayName().toPlain())); } } } } else { src.sendMessage(messageStorage.getMessage("command.error")); } }
Example #6
Source File: VirtualSetCommand.java From EconomyLite with MIT License | 6 votes |
@Override public void run(CommandSource src, CommandContext args) { if (args.getOne("account").isPresent() && args.getOne("amount").isPresent()) { String target = args.<String>getOne("account").get(); BigDecimal newBal = BigDecimal.valueOf(args.<Double>getOne("amount").get()); Optional<Account> aOpt = EconomyLite.getEconomyService().getOrCreateAccount(target); if (aOpt.isPresent()) { Account targetAccount = aOpt.get(); if (targetAccount.setBalance(EconomyLite.getCurrencyService().getCurrentCurrency(), newBal, Cause.of(EventContext.empty(), (EconomyLite.getInstance()))).getResult().equals(ResultType.SUCCESS)) { src.sendMessage(messageStorage.getMessage("command.econ.setsuccess", "name", targetAccount.getDisplayName().toPlain())); } else { src.sendMessage(messageStorage.getMessage("command.econ.setfail", "name", targetAccount.getDisplayName().toPlain())); } } else { src.sendMessage(messageStorage.getMessage("command.error")); } } else { src.sendMessage(messageStorage.getMessage("command.error")); } }
Example #7
Source File: VirtualRemoveCommand.java From EconomyLite with MIT License | 6 votes |
@Override public void run(CommandSource src, CommandContext args) { if (args.getOne("account").isPresent() && args.getOne("amount").isPresent()) { String target = args.<String>getOne("account").get(); BigDecimal toRemove = BigDecimal.valueOf(args.<Double>getOne("amount").get()); Optional<Account> aOpt = EconomyLite.getEconomyService().getOrCreateAccount(target); if (aOpt.isPresent()) { Account targetAccount = aOpt.get(); if (targetAccount.withdraw(EconomyLite.getCurrencyService().getCurrentCurrency(), toRemove, Cause.of(EventContext.empty(),(EconomyLite.getInstance()))).getResult().equals(ResultType.SUCCESS)) { src.sendMessage(messageStorage.getMessage("command.econ.removesuccess", "name", target)); } else { src.sendMessage(messageStorage.getMessage("command.econ.removefail", "name", target)); } } else { src.sendMessage(messageStorage.getMessage("command.error")); } } else { src.sendMessage(messageStorage.getMessage("command.error")); } }
Example #8
Source File: VirtualAddCommand.java From EconomyLite with MIT License | 6 votes |
@Override public void run(CommandSource src, CommandContext args) { if (args.getOne("account").isPresent() && args.getOne("amount").isPresent()) { String target = args.<String>getOne("account").get(); BigDecimal toAdd = BigDecimal.valueOf(args.<Double>getOne("amount").get()); Optional<Account> aOpt = EconomyLite.getEconomyService().getOrCreateAccount(target); if (aOpt.isPresent()) { Account targetAccount = aOpt.get(); if (targetAccount.deposit(EconomyLite.getCurrencyService().getCurrentCurrency(), toAdd, Cause.of(EventContext.empty(),(EconomyLite.getInstance()))).getResult().equals(ResultType.SUCCESS)) { src.sendMessage(messageStorage.getMessage("command.econ.addsuccess", "name", target)); } else { src.sendMessage(messageStorage.getMessage("command.econ.addfail", "name", target)); } } else { src.sendMessage(messageStorage.getMessage("command.error")); } } else { src.sendMessage(messageStorage.getMessage("command.error")); } }
Example #9
Source File: SignListener.java From UltimateCore with MIT License | 6 votes |
@Listener(order = Order.EARLY) public void onSignCreate(ChangeSignEvent event, @Root Player p) { //Sign colors List<Text> lines = event.getText().lines().get(); lines.set(0, TextUtil.replaceColors(lines.get(0), p, "uc.sign")); lines.set(1, TextUtil.replaceColors(lines.get(1), p, "uc.sign")); lines.set(2, TextUtil.replaceColors(lines.get(2), p, "uc.sign")); lines.set(3, TextUtil.replaceColors(lines.get(3), p, "uc.sign")); event.getText().setElements(lines); //Registered signs for (UCSign sign : UltimateCore.get().getSignService().get().getRegisteredSigns()) { if (event.getText().get(0).orElse(Text.of()).toPlain().equalsIgnoreCase("[" + sign.getIdentifier() + "]")) { if (!p.hasPermission(sign.getCreatePermission().get())) { Messages.send(p, "core.nopermissions"); } SignCreateEvent cevent = new SignCreateEvent(sign, event.getTargetTile().getLocation(), Cause.builder().append(UltimateCore.getContainer()).append(p).build(EventContext.builder().build())); Sponge.getEventManager().post(cevent); if (!cevent.isCancelled() && sign.onCreate(p, event)) { //Color sign event.getTargetTile().offer(Keys.SIGN_LINES, event.getText().setElement(0, Text.of(TextColors.AQUA, "[" + StringUtil.firstUpperCase(sign.getIdentifier()) + "]")).asList()); Messages.send(p, "sign.create", "%sign%", sign.getIdentifier()); } } } }
Example #10
Source File: SignListener.java From UltimateCore with MIT License | 6 votes |
@Listener public void onSignClick(InteractBlockEvent.Secondary event, @Root Player p) { if (!event.getTargetBlock().getLocation().isPresent() || !event.getTargetBlock().getLocation().get().getTileEntity().isPresent()) { return; } if (!(event.getTargetBlock().getLocation().get().getTileEntity().get() instanceof Sign)) { return; } Sign sign = (Sign) event.getTargetBlock().getLocation().get().getTileEntity().get(); for (UCSign usign : UltimateCore.get().getSignService().get().getRegisteredSigns()) { if (sign.getSignData().get(0).orElse(Text.of()).toPlain().equalsIgnoreCase("[" + usign.getIdentifier() + "]")) { if (!p.hasPermission(usign.getUsePermission().get())) { Messages.send(p, "core.nopermissions"); } SignUseEvent cevent = new SignUseEvent(usign, sign.getLocation(), Cause.builder().append(UltimateCore.getContainer()).append(p).build(EventContext.builder().build())); Sponge.getEventManager().post(cevent); if (!cevent.isCancelled()) { usign.onExecute(p, sign); } } } }
Example #11
Source File: GlobalData.java From UltimateCore with MIT License | 6 votes |
/** * Get the value for the provided key, or the default value of the key when no value for the key was found in the map. * {@link Optional#empty()} is returned when the {@link Key} is not compatible or has no default value. * * @param key The key to search for * @param <C> The expected type of value to be returned * @return The value found, or {@link Optional#empty()} when no value was found. */ public static <C> Optional<C> get(Key.Global<C> key) { Optional<C> rtrn; if (!datas.containsKey(key.getIdentifier())) { if (key.getProvider().isPresent()) { //Run the provider rtrn = Optional.ofNullable(key.getProvider().get().load(Sponge.getGame())); } else { rtrn = key.getDefaultValue(); } } else { //Provider not available, get the default value rtrn = Optional.ofNullable((C) datas.get(key.getIdentifier())); } DataRetrieveEvent<C> event = new DataRetrieveEvent<>(key, rtrn.orElse(null), Cause.builder().append(UltimateCore.getContainer()).build(EventContext.builder().build())); Sponge.getEventManager().post(event); return event.getValue(); }
Example #12
Source File: GlobalData.java From UltimateCore with MIT License | 6 votes |
/** * Set the value of a key to the specified value. * * @param key The key to set the value of * @param value The value to set the value to * @param <C> The type of value the key holds * @return Whether the value was accepted */ public static <C> boolean offer(Key.Global<C> key, C value) { Cause cause = Cause.builder().append(UltimateCore.getContainer()).build(EventContext.builder().build()); DataOfferEvent<C> event = new DataOfferEvent<>(key, (C) datas.get(key.getIdentifier()), value, cause); Sponge.getEventManager().post(event); if (event.isCancelled()) { return false; } value = event.getValue().orElse(null); //Save to config if needed if (key.getProvider().isPresent()) { key.getProvider().get().save(Sponge.getGame(), value); } //Save to map if (value == null) { datas.remove(key.getIdentifier()); } else { datas.put(key.getIdentifier(), value); } return true; }
Example #13
Source File: UltimateUser.java From UltimateCore with MIT License | 6 votes |
/** * Get the value for the provided key, or the default value of the key when no value for the key was found in the map. * {@link Optional#empty()} is returned when the {@link Key} is not compatible or has no default value. * * @param key The key to search for * @param <C> The expected type of value to be returned * @return The value found, or {@link Optional#empty()} when no value was found. */ public <C> Optional<C> get(Key.User<C> key) { if (!isCompatible(key)) { return Optional.empty(); } Optional<C> rtrn; if (this.datas.containsKey(key.getIdentifier())) { rtrn = Optional.ofNullable((C) this.datas.get(key.getIdentifier())); } else { if (key.getProvider().isPresent()) { //Run the provider rtrn = Optional.ofNullable(key.getProvider().get().load(this)); } else { //Provider not available, get the default value rtrn = key.getDefaultValue(); } } DataRetrieveEvent<C> event = new DataRetrieveEvent<>(key, rtrn.orElse(null), Cause.builder().append(UltimateCore.getContainer()).build(EventContext.builder().build())); Sponge.getEventManager().post(event); return event.getValue(); }
Example #14
Source File: UltimateUser.java From UltimateCore with MIT License | 6 votes |
/** * Set the value of a key to the specified value. * * @param key The key to set the value of * @param value The value to set the value to * @param <C> The type of value the key holds * @return Whether the value was accepted */ public <C> boolean offer(Key.User<C> key, C value) { if (!isCompatible(key)) { return false; } Cause cause = getPlayer().isPresent() ? Cause.builder().append(UltimateCore.getContainer()).append(getPlayer().get()).build(EventContext.builder().build()) : Cause.builder().append (UltimateCore.get()).append(getUser()).build(EventContext.builder().build()); DataOfferEvent<C> event = new DataOfferEvent<>(key, (C) this.datas.get(key.getIdentifier()), value, cause); Sponge.getEventManager().post(event); if (event.isCancelled()) { return false; } value = event.getValue().orElse(null); //Save to config if needed if (key.getProvider().isPresent()) { key.getProvider().get().save(this, value); } //Save to map if (value == null) { this.datas.remove(key.getIdentifier()); } else { this.datas.put(key.getIdentifier(), value); } return UltimateCore.get().getUserService().addToCache(this); }
Example #15
Source File: UltimateUser.java From UltimateCore with MIT License | 5 votes |
/** * Get the value for the provided key, or {@link Optional#empty()} when no value was found in the map. * * @param key The key to search for * @param <C> The expected type of value to be returned * @return The value found, or {@link Optional#empty()} when no value was found. */ public <C> Optional<C> getRaw(Key.User<C> key) { if (!isCompatible(key)) { return Optional.empty(); } Optional<C> rtrn; if (!this.datas.containsKey(key.getIdentifier())) { rtrn = Optional.empty(); } else { rtrn = Optional.ofNullable((C) this.datas.get(key.getIdentifier())); } DataRetrieveEvent<C> event = new DataRetrieveEvent<>(key, rtrn.orElse(null), Cause.builder().append(UltimateCore.getContainer()).build(EventContext.builder().build())); Sponge.getEventManager().post(event); return event.getValue(); }
Example #16
Source File: PlayerEventHandler.java From GriefDefender with MIT License | 5 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onPlayerInteractInventoryOpen(InteractInventoryEvent.Open event, @First Player player) { if (!GDFlags.INTERACT_INVENTORY || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUniqueId())) { return; } final Cause cause = event.getCause(); final EventContext context = cause.getContext(); final BlockSnapshot blockSnapshot = context.get(EventContextKeys.BLOCK_HIT).orElse(BlockSnapshot.NONE); if (blockSnapshot == BlockSnapshot.NONE) { return; } if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.INTERACT_INVENTORY.getName(), blockSnapshot, player.getWorld().getProperties())) { return; } GDTimings.PLAYER_INTERACT_INVENTORY_OPEN_EVENT.startTimingIfSync(); final Location<World> location = blockSnapshot.getLocation().get(); final GDClaim claim = this.dataStore.getClaimAt(location); final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.INTERACT_INVENTORY, player, blockSnapshot, player, TrustTypes.CONTAINER, true); if (result == Tristate.FALSE) { final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.PERMISSION_INVENTORY_OPEN, ImmutableMap.of( "player", claim.getOwnerName(), "block", blockSnapshot.getState().getType().getId())); GriefDefenderPlugin.sendClaimDenyMessage(claim, player, message); NMSUtil.getInstance().closePlayerScreen(player); event.setCancelled(true); } GDTimings.PLAYER_INTERACT_INVENTORY_OPEN_EVENT.stopTimingIfSync(); }
Example #17
Source File: UCCommandService.java From UltimateCore with MIT License | 5 votes |
/** * Unregisters the given {@link Command}. * This also unregisters it from the sponge command manager. * * @param command The {@link Command} to unregister * @return Whether the command was found */ @Override public boolean unregister(Command command) { if (Sponge.getEventManager().post(new CommandUnregisterEvent(command, Cause.builder().append(UltimateCore.getContainer()).build(EventContext.builder().build())))) { return false; } return this.commands.remove(command); }
Example #18
Source File: UCCommandService.java From UltimateCore with MIT License | 5 votes |
/** * Register a new {@link Command}. * This also registers it to the sponge command manager. * * @param command The command to register * @return Whether the command was successfully registered */ @Override public boolean register(Command command) { if (!UltimateCore.get().getCommandsConfig().get().getNode("commands", command.getIdentifier(), "enabled").getBoolean(true)) { return false; } if (Sponge.getEventManager().post(new CommandRegisterEvent(command, Cause.builder().append(UltimateCore.getContainer()).build(EventContext.builder().build())))) { return false; } this.commands.add(command); Sponge.getCommandManager().register(UltimateCore.get(), command.getCallable(), command.getAliases()); return true; }
Example #19
Source File: SetAllCommand.java From EconomyLite with MIT License | 5 votes |
@Override public void run(CommandSource src, CommandContext args) { if (args.getOne("balance").isPresent()) { String targetName = "all players"; BigDecimal newBal = BigDecimal.valueOf(args.<Double>getOne("balance").get()); if (EconomyLite.getPlayerService().setBalanceAll(newBal, EconomyLite.getCurrencyService().getCurrentCurrency(), Cause.of(EventContext.empty(),(EconomyLite.getInstance())))) { src.sendMessage(messageStorage.getMessage("command.econ.setsuccess", "name", targetName)); } else { src.sendMessage(messageStorage.getMessage("command.econ.setfail", "name", targetName)); } } else { src.sendMessage(messageStorage.getMessage("command.error")); } }
Example #20
Source File: PayCommand.java From EconomyLite with MIT License | 5 votes |
private void pay(User target, BigDecimal amount, Player src) { String targetName = target.getName(); if (!target.getUniqueId().equals(src.getUniqueId())) { Optional<UniqueAccount> uOpt = ecoService.getOrCreateAccount(src.getUniqueId()); Optional<UniqueAccount> tOpt = ecoService.getOrCreateAccount(target.getUniqueId()); if (uOpt.isPresent() && tOpt.isPresent()) { if (uOpt.get() .transfer(tOpt.get(), ecoService.getDefaultCurrency(), amount, Cause.of(EventContext.empty(), (EconomyLite.getInstance()))) .getResult().equals(ResultType.SUCCESS)) { Text label = ecoService.getDefaultCurrency().getPluralDisplayName(); if (amount.equals(BigDecimal.ONE)) { label = ecoService.getDefaultCurrency().getDisplayName(); } src.sendMessage(messageStorage.getMessage("command.pay.success", "target", targetName, "amountandlabel", String.format(Locale.ENGLISH, "%,.2f", amount) + " " + label.toPlain())); final Text curLabel = label; Sponge.getServer().getPlayer(target.getUniqueId()).ifPresent(p -> { p.sendMessage(messageStorage.getMessage("command.pay.target", "amountandlabel", String.format(Locale.ENGLISH, "%,.2f", amount) + " " + curLabel.toPlain(), "sender", uOpt.get().getDisplayName().toPlain())); }); } else { src.sendMessage(messageStorage.getMessage("command.pay.failed", "target", targetName)); } } else { src.sendMessage(messageStorage.getMessage("command.error")); } } else { src.sendMessage(messageStorage.getMessage("command.pay.notyou")); } }
Example #21
Source File: ExecutorListenerWrapper.java From UltimateCore with MIT License | 5 votes |
@Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { if (Sponge.getEventManager().post(new CommandExecuteEvent(this.command, args, Cause.builder().append(UltimateCore.getContainer()).append(src).build(EventContext.builder().build())))) { //Event canceller is expected to send message return CommandResult.empty(); } CommandResult result = this.executor.execute(src, args); CommandPostExecuteEvent pEvent = new CommandPostExecuteEvent(this.command, args, result, Cause.builder().append(UltimateCore.getContainer()).append(src).build(EventContext.builder().build())); Sponge.getEventManager().post(pEvent); return pEvent.getResult(); }
Example #22
Source File: VirtualPayCommand.java From EconomyLite with MIT License | 5 votes |
@Override public void run(CommandSource src, CommandContext args) { if (args.getOne("account").isPresent() && args.getOne("target").isPresent() && args.getOne("amount").isPresent()) { String account = args.<String>getOne("account").get(); User target = args.<User>getOne("target").get(); BigDecimal amount = BigDecimal.valueOf(args.<Double>getOne("amount").get()); Optional<Account> aOpt = EconomyLite.getEconomyService().getOrCreateAccount(account); Optional<UniqueAccount> uOpt = EconomyLite.getEconomyService().getOrCreateAccount(target.getUniqueId()); // Check for negative payments if (amount.compareTo(BigDecimal.ONE) == -1) { src.sendMessage(messageStorage.getMessage("command.pay.invalid")); } else { if (aOpt.isPresent() && uOpt.isPresent()) { Account payer = aOpt.get(); UniqueAccount receiver = uOpt.get(); if (payer.transfer(receiver, ecoService.getDefaultCurrency(), amount, Cause.of(EventContext.empty(), EconomyLite.getInstance ())) .getResult().equals(ResultType.SUCCESS)) { src.sendMessage(messageStorage.getMessage("command.pay.success", "target", target.getName())); if (target instanceof Player) { Text label = ecoService.getDefaultCurrency().getPluralDisplayName(); if (amount.equals(BigDecimal.ONE)) { label = ecoService.getDefaultCurrency().getDisplayName(); } ((Player) target).sendMessage(messageStorage.getMessage("command.pay.target", "amountandlabel", String.format(Locale.ENGLISH, "%,.2f", amount) + " " + label.toPlain(), "sender", payer.getDisplayName().toPlain())); } } else { src.sendMessage(messageStorage.getMessage("command.pay.failed", "target", target.getName())); } } } } else { src.sendMessage(messageStorage.getMessage("command.error")); } }
Example #23
Source File: GlobalData.java From UltimateCore with MIT License | 5 votes |
/** * Get the value for the provided key, or {@link Optional#empty()} when no value was found in the map. * * @param key The key to search for * @param <C> The expected type of value to be returned * @return The value found, or {@link Optional#empty()} when no value was found. */ public static <C> Optional<C> getRaw(Key.Global<C> key) { Optional<C> rtrn; if (!datas.containsKey(key.getIdentifier())) { rtrn = Optional.empty(); } else { rtrn = Optional.ofNullable((C) datas.get(key.getIdentifier())); } DataRetrieveEvent<C> event = new DataRetrieveEvent<>(key, rtrn.orElse(null), Cause.builder().append(UltimateCore.getContainer()).build(EventContext.builder().build())); Sponge.getEventManager().post(event); return event.getValue(); }
Example #24
Source File: LiteEconomyTransactionEvent.java From EconomyLite with MIT License | 5 votes |
@Override public Cause getCause() { if (cause != null) { return cause; } else { return Cause.of(EventContext.empty(), EconomyLite.getInstance().getPluginContainer()); } }
Example #25
Source File: UCSignService.java From UltimateCore with MIT License | 5 votes |
/** * Unregisters a sign * * @param sign The instance of the sign * @return Whether the sign was found */ @Override public boolean unregisterSign(UCSign sign) { SignUnregisterEvent cevent = new SignUnregisterEvent(sign, Cause.builder().append(UltimateCore.getContainer()).build(EventContext.builder().build())); Sponge.getEventManager().post(cevent); if (cevent.isCancelled()) { return false; } this.perms.remove(sign.getIdentifier()); return this.signs.remove(sign); }
Example #26
Source File: UCModuleService.java From UltimateCore with MIT License | 5 votes |
/** * Registers a new module * * @param module The module to register * @return Whether it was successfully registered */ @Override public boolean registerModule(Module module) { try { if (module.getClass().getAnnotation(ModuleIgnore.class) != null) return false; ModuleRegisterEvent event = new ModuleRegisterEvent(module, Cause.builder().append(UltimateCore.getContainer()).build(EventContext.builder().build())); Sponge.getEventManager().post(event); String def = module.getClass().getAnnotation(ModuleDisableByDefault.class) == null ? "enabled" : "disabled"; String state = UltimateCore.get().getModulesConfig().get().getNode("modules", module.getIdentifier(), "state").getString(def); //state != null because state is null when module is first loaded if (event.isCancelled() && !module.getIdentifier().equalsIgnoreCase("default") && state != null && !state.equalsIgnoreCase("force")) { Messages.log(Messages.getFormatted("core.load.module.blocked", "%module%", module.getIdentifier())); this.unregisteredModules.add(module); return false; } if (!module.getIdentifier().equalsIgnoreCase("default") && state != null && state.equalsIgnoreCase("disabled")) { Messages.log(Messages.getFormatted("core.load.module.disabled", "%module%", module.getIdentifier())); this.unregisteredModules.add(module); return false; } this.modules.add(module); module.onRegister(); return true; } catch (Exception ex) { ErrorLogger.log(ex, "An error occured while registering the module '" + module.getIdentifier() + "'"); this.unregisteredModules.add(module); return false; } }
Example #27
Source File: RecordingQueueManager.java From Prism with MIT License | 5 votes |
@Override public synchronized void run() { List<DataContainer> eventsSaveBatch = new ArrayList<>(); // Assume we're iterating everything in the queue while (!RecordingQueue.getQueue().isEmpty()) { // Poll the next event, append to list PrismRecord record = RecordingQueue.getQueue().poll(); if (record != null) { // Prepare PrismRecord for sending to a PrismRecordEvent PluginContainer plugin = Prism.getInstance().getPluginContainer(); EventContext eventContext = EventContext.builder().add(EventContextKeys.PLUGIN, plugin).build(); PrismRecordPreSaveEvent preSaveEvent = new PrismRecordPreSaveEvent(record, Cause.of(eventContext, plugin)); // Tell Sponge that this PrismRecordEvent has occurred Sponge.getEventManager().post(preSaveEvent); if (!preSaveEvent.isCancelled()) { eventsSaveBatch.add(record.getDataContainer()); } } } if (eventsSaveBatch.size() > 0) { try { Prism.getInstance().getStorageAdapter().records().write(eventsSaveBatch); } catch (Exception e) { // @todo handle failures e.printStackTrace(); } } }
Example #28
Source File: SudoCommand.java From UltimateCore with MIT License | 5 votes |
@Override public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException { checkPermission(sender, SudoPermissions.UC_SUDO_SUDO_BASE); Player t = args.<Player>getOne("player").get(); String message = args.<String>getOne("command").get(); boolean cmd = message.startsWith("/"); if (cmd) { //COMMAND checkPermission(sender, SudoPermissions.UC_SUDO_SUDO_COMMAND); try { if (Sponge.getCommandManager().process(t, message.replaceFirst("/", "")).getSuccessCount().orElse(0) >= 1) { //Success Messages.send(sender, "sudo.command.sudo.command.success", "%target%", t, "%command%", message); } else { //Failed throw new ErrorMessageException(Messages.getFormatted(sender, "sudo.command.sudo.command.failed")); } } catch (Exception ex) { //Error Messages.send(sender, "sudo.command.sudo.command.error"); } } else { //CHAT checkPermission(sender, SudoPermissions.UC_SUDO_SUDO_CHAT); if (!t.simulateChat(Text.of(message), Cause.builder().append(t).append(sender).build(EventContext.builder().build())).isMessageCancelled()) { //Success Messages.send(sender, "sudo.command.sudo.chat.success", "%target%", t, "%message%", message); } else { //Failed throw new ErrorMessageException(Messages.getFormatted("sudo.command.sudo.chat.failed")); } } return CommandResult.success(); }
Example #29
Source File: PersonalmessageCommand.java From UltimateCore with MIT License | 5 votes |
@Override public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException { checkPermission(sender, PersonalmessagePermissions.UC_PERSONALMESSAGE_PERSONALMESSAGE_BASE); CommandSource t = args.<CommandSource>getOne("player").get(); String message = args.<String>getOne("message").get(); Text fmessage = Messages.getFormatted("personalmessage.command.personalmessage.format.receive", "%player%", sender, "%message%", message); //Event Cause cause = Cause.builder().append(UltimateCore.getContainer()).append(sender).append(t).build(EventContext.builder().build()); MessageEvent.MessageFormatter formatter = new MessageEvent.MessageFormatter(fmessage); final CommandSource tf = t; MessageChannel channel = () -> Arrays.asList(tf); PersonalmessageEvent event = new PersonalmessageEvent(cause, sender, t, formatter, channel, message, fmessage); Sponge.getEventManager().post(event); if (!event.isMessageCancelled()) { Text received = event.getFormatter().toText(); t.sendMessage(received); //Reply UUID uuid_s = sender instanceof Player ? ((Player) sender).getUniqueId() : UUID.fromString("00000000-0000-0000-0000-000000000000"); UUID uuid_t = t instanceof Player ? ((Player) t).getUniqueId() : UUID.fromString("00000000-0000-0000-0000-000000000000"); if (t instanceof Player) { UltimateUser user = UltimateCore.get().getUserService().getUser((Player) t); user.offer(PersonalmessageKeys.REPLY, uuid_s); } if (sender instanceof Player) { UltimateUser user2 = UltimateCore.get().getUserService().getUser((Player) sender); user2.offer(PersonalmessageKeys.REPLY, uuid_t); } //TODO better system for this message? Text send = Messages.getFormatted("personalmessage.command.personalmessage.format.send", "%player%", t, "%message%", message); sender.sendMessage(send); return CommandResult.success(); } else { throw new ErrorMessageException(Messages.getFormatted(t, "personalmessage.command.personalmessage.cancelled")); } }
Example #30
Source File: EventRunner.java From EagleFactions with MIT License | 5 votes |
/** * @return True if cancelled, false if not */ public static boolean runFactionLeaveEvent(final Player player, final Faction faction) { final EventContext eventContext = EventContext.builder() .add(EventContextKeys.OWNER, player) .add(EventContextKeys.PLAYER, player) .add(EventContextKeys.CREATOR, player) .build(); final Cause eventCause = Cause.of(eventContext, player, faction); final FactionLeaveEvent event = new FactionLeaveEventImpl(player, faction, eventCause); return Sponge.getEventManager().post(event); }