use of org.spongepowered.api.entity.living.player.Player in project Almura by AlmuraDev.
the class FarmersAlmanacItem method onItemUse.
@SuppressWarnings("ConstantConditions")
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (!world.isRemote) {
final Player spongePlayer = (Player) player;
if (!spongePlayer.hasPermission("almura.item.farmers_almanac")) {
spongePlayer.sendMessage(Text.of("Access denied, missing permission: ", TextColors.AQUA, "almura.item.farmers_" + "almanac", TextColors.WHITE, "."));
return EnumActionResult.FAIL;
}
final Block block = world.getBlockState(pos).getBlock();
if (block instanceof BlockFarmland | block instanceof BlockCrops) {
final Biome biome = world.getBiome(pos);
final float biomeTemperature = biome.getTemperature(pos);
final float biomeRainfall = biome.getRainfall();
final int blockLight = world.getLightFor(EnumSkyBlock.BLOCK, pos);
final int skyLight = world.getLightFor(EnumSkyBlock.SKY, pos) - world.getSkylightSubtracted();
player.swingArm(hand);
network.sendTo(spongePlayer, new ClientboundWorldPositionInformationPacket(pos.getX(), pos.getY(), pos.getZ(), hitX, hitY, hitZ, biome.getRegistryName().toString(), biomeTemperature, biomeRainfall, blockLight, skyLight));
} else {
spongePlayer.sendMessage(Text.of("The ", TextColors.AQUA, "Farmer's Almanac", TextColors.WHITE, " can only be " + "used on crops or farmland."));
}
}
return EnumActionResult.PASS;
}
use of org.spongepowered.api.entity.living.player.Player in project Almura by AlmuraDev.
the class LightRepairWand method onItemRightClick.
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer player, EnumHand handIn) {
if (!worldIn.isRemote) {
final Player spongePlayer = (org.spongepowered.api.entity.living.player.Player) player;
if (!spongePlayer.hasPermission("almura.item.light_repair_wand")) {
spongePlayer.sendMessage(Text.of(TextColors.WHITE + "Access denied, missing permission: ", TextColors.AQUA, "almura.item.light_repair_wand", TextColors.WHITE, "."));
return new ActionResult<>(EnumActionResult.FAIL, player.getHeldItem(handIn));
} else {
final BlockPos pos = player.getPosition();
for (BlockPos.MutableBlockPos blockpos$mutableblockpos : BlockPos.getAllInBoxMutable(pos.add(-100, -20, -100), pos.add(100, 20, 100))) {
worldIn.setLightFor(EnumSkyBlock.BLOCK, blockpos$mutableblockpos, 0);
if (worldIn.getBlockState(blockpos$mutableblockpos).getBlock() == Blocks.TORCH) {
worldIn.setBlockToAir(blockpos$mutableblockpos);
}
if (worldIn.getBlockState(blockpos$mutableblockpos).getBlock() == Blocks.GLOWSTONE) {
worldIn.setBlockToAir(blockpos$mutableblockpos);
}
}
spongePlayer.sendMessage(Text.of("Light values within a -100/[40]+100 range have been fixed. Unload and reload chunks to get client ot update."));
}
}
// Both Server & Client expect a returned value.
return new ActionResult<>(EnumActionResult.PASS, player.getHeldItem(handIn));
}
use of org.spongepowered.api.entity.living.player.Player in project TotalEconomy by Erigitic.
the class BalanceCommand method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (src instanceof Player) {
Player sender = (Player) src;
TEAccount playerAccount = (TEAccount) accountManager.getOrCreateAccount(sender.getUniqueId()).get();
Currency defaultCurrency = totalEconomy.getDefaultCurrency();
Text playerBalance = defaultCurrency.format(playerAccount.getBalance(defaultCurrency));
sender.sendMessage(Text.of(TextColors.GRAY, "Balance: ", TextColors.GOLD, playerBalance));
return CommandResult.success();
}
return CommandResult.empty();
}
use of org.spongepowered.api.entity.living.player.Player in project TotalEconomy by Erigitic.
the class JobCommand method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (src instanceof Player) {
Player player = ((Player) src).getPlayer().get();
String jobName = totalEconomy.getTEJobManager().getPlayerJob(player);
player.sendMessage(Text.of(TextColors.GRAY, "Current Job: ", TextColors.GOLD, totalEconomy.getTEJobManager().titleize(jobName)));
player.sendMessage(Text.of(TextColors.GRAY, totalEconomy.getTEJobManager().titleize(jobName), " Level: ", TextColors.GOLD, totalEconomy.getTEJobManager().getJobLevel(jobName, player)));
player.sendMessage(Text.of(TextColors.GRAY, totalEconomy.getTEJobManager().titleize(jobName), " Exp: ", TextColors.GOLD, totalEconomy.getTEJobManager().getJobExp(jobName, player), "/", totalEconomy.getTEJobManager().getExpToLevel(player), " exp\n"));
player.sendMessage(Text.of(TextColors.GRAY, "Available Jobs: ", TextColors.GOLD, totalEconomy.getTEJobManager().getJobList()));
return CommandResult.success();
} else {
throw new CommandException(Text.of("You can't have a job!"));
}
}
use of org.spongepowered.api.entity.living.player.Player in project TotalEconomy by Erigitic.
the class TEJobManager method onPlayerBlockBreak.
/**
* Used for the break option in jobs. Will check if the job has the break node and if it does it will check if the
* block that was broken is present in the config of the player's job. If it is, it will grab the job exp reward as
* well as the pay.
*
* @param event ChangeBlockEvent.Break
*/
@Listener
public void onPlayerBlockBreak(ChangeBlockEvent.Break event) {
if (event.getCause().first(Player.class).isPresent()) {
Player player = event.getCause().first(Player.class).get();
UUID playerUUID = player.getUniqueId();
String playerJob = getPlayerJob(player);
Optional<TEJob> optPlayerJob = getJob(playerJob, true);
String blockName = event.getTransactions().get(0).getOriginal().getState().getType().getName();
Optional<UUID> blockCreator = event.getTransactions().get(0).getOriginal().getCreator();
if (optPlayerJob.isPresent()) {
// Prevent blocks placed by other players from counting towards a job
if (!blockCreator.isPresent()) {
Optional<TEActionReward> reward = Optional.empty();
List<String> sets = optPlayerJob.get().getSets();
for (String s : sets) {
Optional<TEJobSet> optSet = getJobSet(s);
if (!optSet.isPresent()) {
logger.warn("[TE] Job " + getPlayerJob(player) + " has the nonexistent set \"" + s + "\"");
continue;
}
reward = optSet.get().getRewardFor("break", blockName);
}
if (reward.isPresent()) {
int expAmount = reward.get().getExpReward();
BigDecimal payAmount = reward.get().getMoneyReward();
boolean notify = accountManager.getJobNotificationState(player);
TEAccount playerAccount = (TEAccount) accountManager.getOrCreateAccount(player.getUniqueId()).get();
if (notify) {
notifyPlayer(player, payAmount);
}
addExp(player, expAmount);
playerAccount.deposit(totalEconomy.getDefaultCurrency(), payAmount, Cause.of(NamedCause.of("TotalEconomy", totalEconomy.getPluginContainer())));
checkForLevel(player);
}
}
}
}
}
Aggregations