org.spongepowered.api.event.cause.Cause Java Examples
The following examples show how to use
org.spongepowered.api.event.cause.Cause.
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: 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 #2
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 #3
Source File: LiteUniqueAccount.java From EconomyLite with MIT License | 6 votes |
@Override public TransferResult transfer(Account to, Currency currency, BigDecimal amount, Cause cause, Set<Context> contexts) { BigDecimal newBal = to.getBalance(currency).add(amount); // Check if the new balance is in bounds if (newBal.compareTo(BigDecimal.ZERO) == -1 || newBal.compareTo(BigDecimal.valueOf(999999999)) == 1) { return resultAndEvent(this, amount, currency, ResultType.ACCOUNT_NO_SPACE, to, cause); } // Check if the account has enough funds if (amount.compareTo(getBalance(currency)) == 1) { return resultAndEvent(this, amount, currency, ResultType.ACCOUNT_NO_FUNDS, to, cause); } if (withdraw(currency, amount, cause).getResult().equals(ResultType.SUCCESS) && to.deposit(currency, amount, cause).getResult().equals(ResultType.SUCCESS)) { return resultAndEvent(this, amount, currency, ResultType.SUCCESS, to, cause); } else { return resultAndEvent(this, amount, currency, ResultType.FAILED, to, cause); } }
Example #4
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 #5
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 #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: LiteVirtualAccount.java From EconomyLite with MIT License | 6 votes |
@Override public TransferResult transfer(Account to, Currency currency, BigDecimal amount, Cause cause, Set<Context> contexts) { BigDecimal newBal = to.getBalance(currency).add(amount); // Check if the new balance is in bounds if (newBal.compareTo(BigDecimal.ZERO) == -1 || newBal.compareTo(BigDecimal.valueOf(999999999)) == 1) { return resultAndEvent(this, amount, currency, ResultType.ACCOUNT_NO_SPACE, to, cause); } // Check if the account has enough funds if (amount.compareTo(getBalance(currency)) == 1) { return resultAndEvent(this, amount, currency, ResultType.ACCOUNT_NO_FUNDS, to, cause); } if (withdraw(currency, amount, cause).getResult().equals(ResultType.SUCCESS) && to.deposit(currency, amount, cause).getResult().equals(ResultType.SUCCESS)) { return resultAndEvent(this, amount, currency, ResultType.SUCCESS, to, cause); } else { return resultAndEvent(this, amount, currency, ResultType.FAILED, to, cause); } }
Example #8
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 #9
Source File: VirtualServiceCommon.java From EconomyLite with MIT License | 6 votes |
public boolean setBalance(String id, BigDecimal balance, Currency currency, Cause cause) { boolean result; if (accountExists(id, currency, cause)) { result = manager.executeUpdate("UPDATE economylitevirts SET balance = ? WHERE id = ? AND currency = ?", balance.toString(), id, currency.getId()); debug("virtcommon: +Account Exists+ Setting balance of '" + id + "' to '" + balance.toPlainString() + "' with '" + currency.getId() + "' - " + cause.toString() + " = " + result); } else { result = manager.executeUpdate("INSERT INTO economylitevirts (`id`, `balance`, `currency`) VALUES (?, ?, ?)", id, balance.toString(), currency.getId()); debug("virtcommon: +Account Does Not Exist+ Setting balance of '" + id + "' to '" + balance.toPlainString() + "' with '" + currency.getId() + "' - " + cause.toString() + " = " + result); } if (result) { balCache.update(formId(id, currency), balance); exCache.update(formId(id, currency), true); } return result; }
Example #10
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 #11
Source File: PlayerServiceCommon.java From EconomyLite with MIT License | 6 votes |
public boolean setBalance(UUID uuid, BigDecimal balance, Currency currency, Cause cause) { boolean result; if (accountExists(uuid, currency, cause)) { result = manager.executeUpdate("UPDATE economyliteplayers SET balance = ? WHERE uuid = ? AND currency = ?", balance.toString(), uuid.toString(), currency.getId()); debug("playercommon: +Account Exists+ Setting balance of '" + uuid.toString() + "' to '" + balance.toPlainString() + "' with '" + currency.getId() + "' - " + cause.toString() + " = " + result); } else { result = manager.executeUpdate("INSERT INTO economyliteplayers (`uuid`, `balance`, `currency`) VALUES (?, ?, ?)", uuid.toString(), balance.toString(), currency.getId()); debug("playercommon: +Account Does Not Exist+ Setting balance of '" + uuid.toString() + "' to '" + balance.toPlainString() + "' with '" + currency.getId() + "' - " + cause.toString() + " = " + result); } if (result) { balCache.update(formId(uuid, currency), balance); exCache.update(formId(uuid, currency), true); } return result; }
Example #12
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 #13
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 #14
Source File: PrismRecord.java From Prism with MIT License | 6 votes |
/** * Set a cause based on a Cause chain. * * @param cause Cause of event. * @return The created EventBuilder instance */ public PrismRecord.EventBuilder source(Cause cause) { Player player = cause.first(Player.class).orElse(null); if (player != null) { return new PrismRecord.EventBuilder(player); } EntityDamageSource attacker = cause.first(EntityDamageSource.class).orElse(null); if (attacker != null) { return new PrismRecord.EventBuilder(attacker); } IndirectEntityDamageSource indirectAttacker = cause.first(IndirectEntityDamageSource.class).orElse(null); if (indirectAttacker != null) { return new PrismRecord.EventBuilder(indirectAttacker); } if (!cause.all().isEmpty()) { return new PrismRecord.EventBuilder(cause.all().get(0)); } return new PrismRecord.EventBuilder(null); }
Example #15
Source File: LiteVirtualAccount.java From EconomyLite with MIT License | 5 votes |
@Override public Map<Currency, TransactionResult> resetBalances(Cause cause, Set<Context> contexts) { HashMap<Currency, TransactionResult> results = new HashMap<>(); for (Currency currency : currencyService.getCurrencies()) { if (virtualService.accountExists(name, currency, cause)) { if (virtualService.setBalance(name, getDefaultBalance(currency), currency, cause)) { results.put(currency, resultAndEvent(this, getBalance(currency), currency, ResultType.SUCCESS, TransactionTypes.WITHDRAW, cause)); } else { results.put(currency, resultAndEvent(this, getBalance(currency), currency, ResultType.FAILED, TransactionTypes.WITHDRAW, cause)); } } } return results; }
Example #16
Source File: Region.java From RedProtect with GNU General Public License v3.0 | 5 votes |
public boolean setFlag(Cause cause, String fname, Object value) { ChangeRegionFlagEvent event = new ChangeRegionFlagEvent(cause, this, fname, value); if (Sponge.getEventManager().post(event)) return false; setToSave(true); this.flags.put(event.getFlag(), event.getFlagValue()); RedProtect.get().rm.updateLiveFlags(this, event.getFlag(), event.getFlagValue().toString()); updateSigns(event.getFlag()); checkParticle(); return true; }
Example #17
Source File: EventRunner.java From EagleFactions with MIT License | 5 votes |
public static boolean runFactionDisbandEvent(final Player player, final Faction playerFaction) { final EventContext eventContext = EventContext.builder() .add(EventContextKeys.OWNER, player) .add(EventContextKeys.PLAYER, player) .add(EventContextKeys.CREATOR, player) .build(); final Cause cause = Cause.of(eventContext, player, playerFaction); final FactionDisbandEvent event = new FactionAreaEnterEventImp(player, playerFaction, cause); return Sponge.getEventManager().post(event); }
Example #18
Source File: FactionAreaEnterEventImpl.java From EagleFactions with MIT License | 5 votes |
public FactionAreaEnterEventImpl(final MoveEntityEvent moveEntityEvent, final Player creator, final Optional<Faction> enteredFaction, final Optional<Faction> leftFaction, final Cause cause) { this.moveEntityEvent = moveEntityEvent; this.creator = creator; this.cause = cause; this.enteredFaction = enteredFaction; this.leftFaction = leftFaction; }
Example #19
Source File: LiteUniqueAccount.java From EconomyLite with MIT License | 5 votes |
@Override public Map<Currency, TransactionResult> resetBalances(Cause cause, Set<Context> contexts) { HashMap<Currency, TransactionResult> results = new HashMap<>(); for (Currency currency : currencyService.getCurrencies()) { if (playerService.accountExists(uuid, currency, cause)) { if (playerService.setBalance(uuid, getDefaultBalance(currency), currency, cause)) { results.put(currency, resultAndEvent(this, getBalance(currency), currency, ResultType.SUCCESS, TransactionTypes.WITHDRAW, cause)); } else { results.put(currency, resultAndEvent(this, getBalance(currency), currency, ResultType.FAILED, TransactionTypes.WITHDRAW, cause)); } } } return results; }
Example #20
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 #21
Source File: PrismRecord.java From Prism with MIT License | 5 votes |
/** * Save the current record. */ public void save() { DataUtil.writeToDataView(getDataContainer(), DataQueries.Created, new Date()); DataUtil.writeToDataView(getDataContainer(), DataQueries.EventName, getEvent()); DataQuery causeKey = DataQueries.Cause; String causeValue = "environment"; if (getSource() instanceof Player) { causeKey = DataQueries.Player; causeValue = ((Player) getSource()).getUniqueId().toString(); } else if (getSource() instanceof Entity) { causeValue = ((Entity) getSource()).getType().getName(); } DataUtil.writeToDataView(getDataContainer(), causeKey, causeValue); // Source filtered? if (!Prism.getInstance().getFilterList().allowsSource(getSource())) { return; } // Original block filtered? Optional<BlockType> originalBlockType = getDataContainer().getObject(DataQueries.OriginalBlock.then(DataQueries.BlockState).then(DataQueries.BlockType), BlockType.class); if (originalBlockType.map(Prism.getInstance().getFilterList()::allows).orElse(false)) { return; } // Replacement block filtered? Optional<BlockType> replacementBlockType = getDataContainer().getObject(DataQueries.ReplacementBlock.then(DataQueries.BlockState).then(DataQueries.BlockType), BlockType.class); if (replacementBlockType.map(Prism.getInstance().getFilterList()::allows).orElse(false)) { return; } // Queue the finished record for saving RecordingQueue.add(this); }
Example #22
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 #23
Source File: FactionUnclaimEventImpl.java From EagleFactions with MIT License | 5 votes |
FactionUnclaimEventImpl(final Player creator, final Faction faction, final World world, final Vector3i chunkPosition, final Cause cause) { super(); this.creator = creator; this.faction = faction; this.cause = cause; this.world = world; this.chunkPosition = chunkPosition; }
Example #24
Source File: LiteUniqueAccount.java From EconomyLite with MIT License | 5 votes |
@Override public TransactionResult deposit(Currency currency, BigDecimal amount, Cause cause, Set<Context> contexts) { BigDecimal newBal = getBalance(currency).add(amount); // Check if the new balance is in bounds if (newBal.compareTo(BigDecimal.ZERO) == -1 || newBal.compareTo(BigDecimal.valueOf(999999999)) == 1) { return resultAndEvent(this, amount, currency, ResultType.ACCOUNT_NO_SPACE, TransactionTypes.DEPOSIT, cause); } if (playerService.deposit(uuid, amount, currency, cause)) { return resultAndEvent(this, amount, currency, ResultType.SUCCESS, TransactionTypes.DEPOSIT, cause); } else { return resultAndEvent(this, amount, currency, ResultType.FAILED, TransactionTypes.DEPOSIT, cause); } }
Example #25
Source File: BlockListener.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onBlockStartBurn(IgniteEntityEvent e) { Entity b = e.getTargetEntity(); Cause ignit = e.getCause(); RedProtect.get().logger.debug(LogLevel.BLOCKS, "Is BlockIgniteEvent event."); Region r = RedProtect.get().rm.getTopRegion(b.getLocation(), this.getClass().getName()); if (r != null && !r.canFire()) { if (ignit.first(Player.class).isPresent()) { Player p = ignit.first(Player.class).get(); if (!r.canBuild(p)) { RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantplace"); e.setCancelled(true); return; } } else { e.setCancelled(true); return; } if (ignit.first(BlockSnapshot.class).isPresent() && (ignit.first(BlockSnapshot.class).get().getState().getType().equals(BlockTypes.FIRE) || ignit.first(BlockSnapshot.class).get().getState().getType().getName().contains("lava"))) { e.setCancelled(true); return; } if (ignit.first(Lightning.class).isPresent() || ignit.first(Explosion.class).isPresent() || ignit.first(Fireball.class).isPresent()) { e.setCancelled(true); } } }
Example #26
Source File: EventUtil.java From Prism with MIT License | 5 votes |
/** * Reject certain events which can only be identified * by the change + cause signature. * * @param a BlockType original * @param b BlockType replacement * @param cause Cause chain from event * @return boolean If should be rejected */ public static boolean rejectPlaceEventIdentity(BlockType a, BlockType b, Cause cause) { // Things that eat grass... if (a.equals(BlockTypes.GRASS) && b.equals(BlockTypes.DIRT)) { return cause.first(Living.class).isPresent(); } // Grass-like "Grow" events if (a.equals(BlockTypes.DIRT) && b.equals(BlockTypes.GRASS)) { return cause.first(BlockSnapshot.class).isPresent(); } // If no entity at fault, we don't care about placement that didn't affect anything if (!cause.first(Entity.class).isPresent()) { return (a.equals(BlockTypes.AIR)); } // Natural flow/fire. // Note: This only allows tracking on the source block set by a player using // buckets, or items to set fires. Blocks broken by water, lava or fire are still logged as usual. // Full flow/fire tracking would be hard on the database and is generally unnecessary. if (!cause.first(Player.class).isPresent()) { return (a.equals(BlockTypes.AIR) && (b.equals(BlockTypes.FLOWING_LAVA) || b.equals(BlockTypes.FLOWING_WATER)) || b.equals(BlockTypes.FIRE)); } return false; }
Example #27
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 #28
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 #29
Source File: LiteVirtualAccount.java From EconomyLite with MIT License | 5 votes |
@Override public TransactionResult resetBalance(Currency currency, Cause cause, Set<Context> contexts) { if (virtualService.setBalance(name, getDefaultBalance(currency), currency, cause)) { return resultAndEvent(this, BigDecimal.ZERO, currency, ResultType.SUCCESS, TransactionTypes.WITHDRAW, cause); } else { return resultAndEvent(this, BigDecimal.ZERO, currency, ResultType.FAILED, TransactionTypes.WITHDRAW, cause); } }
Example #30
Source File: MobSpawnExecutor.java From EssentialCmds with MIT License | 5 votes |
public void spawnEntity(Location<World> location, Player player, EntityType type, int amount) { for (int i = 1; i <= amount; i++) { Entity entity = location.getExtent().createEntity(type, location.getPosition()); location.getExtent().spawnEntity(entity, Cause.of(NamedCause.source(SpawnCause.builder().type(SpawnTypes.CUSTOM).build()))); } }