use of org.spongepowered.api.entity.Entity in project TotalEconomy by Erigitic.
the class TEJobManager method onPlayerKillEntity.
/**
* 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 DestructEntityEvent.Death
*/
@Listener
public void onPlayerKillEntity(DestructEntityEvent.Death event) {
Optional<EntityDamageSource> optDamageSource = event.getCause().first(EntityDamageSource.class);
if (optDamageSource.isPresent()) {
EntityDamageSource damageSource = optDamageSource.get();
Entity killer = damageSource.getSource();
Entity victim = event.getTargetEntity();
if (!(killer instanceof Player)) {
// If a projectile was shot to kill an entity, this will grab the player who shot it
Optional<UUID> damageCreator = damageSource.getSource().getCreator();
if (damageCreator.isPresent())
killer = Sponge.getServer().getPlayer(damageCreator.get()).get();
}
if (killer instanceof Player) {
Player player = (Player) killer;
UUID playerUUID = player.getUniqueId();
String victimName = victim.getType().getName();
String playerJob = getPlayerJob(player);
Optional<TEJob> optPlayerJob = getJob(playerJob, true);
if (optPlayerJob.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 nonexistent set \"" + s + "\"");
continue;
}
reward = optSet.get().getRewardFor("kill", victimName);
}
if (reward.isPresent()) {
int expAmount = reward.get().getExpReward();
BigDecimal payAmount = reward.get().getMoneyReward();
boolean notify = accountConfig.getNode(playerUUID.toString(), "jobnotifications").getBoolean();
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);
}
}
}
}
}
use of org.spongepowered.api.entity.Entity in project HuskyCrates-Sponge by codeHusky.
the class HuskyCrates method gameReloaded.
@Listener
public void gameReloaded(GameReloadEvent event) {
for (World bit : Sponge.getServer().getWorlds()) {
for (Entity ent : bit.getEntities()) {
if (ent instanceof ArmorStand) {
ArmorStand arm = (ArmorStand) ent;
if (arm.getCreator().isPresent()) {
if (arm.getCreator().get().equals(UUID.fromString(armorStandIdentifier))) {
arm.remove();
}
}
}
}
}
langData = new SharedLangData("", "You won %a %R&rfrom a %C&r!", "&e%p just won %a %R&r&e from a %C&r!", "You need a %K&r to open this crate.");
CommentedConfigurationNode conf = null;
try {
conf = crateConfig.load();
if (!conf.getNode("lang").isVirtual())
langData = new SharedLangData(conf.getNode("lang"));
else
logger.info("Using default lang settings.");
} catch (IOException e) {
e.printStackTrace();
logger.warn("Lang load failed, using defaults.");
}
crateUtilities.generateVirtualCrates(crateConfig);
CommentedConfigurationNode root = null;
try {
root = crateConfig.load();
for (CommentedConfigurationNode node : root.getNode("positions").getChildrenList()) {
Location<World> ee;
try {
ee = node.getNode("location").getValue(TypeToken.of(Location.class));
} catch (InvalidDataException err2) {
logger.warn("Bug sponge developers about world UUIDs!");
ee = new Location<World>(Sponge.getServer().getWorld(node.getNode("location", "WorldName").getString()).get(), node.getNode("location", "X").getDouble(), node.getNode("location", "Y").getDouble(), node.getNode("location", "Z").getDouble());
}
if (!crateUtilities.physicalCrates.containsKey(ee))
crateUtilities.physicalCrates.put(ee, new PhysicalCrate(ee, node.getNode("crateID").getString(), HuskyCrates.instance));
}
} catch (IOException e) {
e.printStackTrace();
} catch (ObjectMappingException e) {
e.printStackTrace();
}
crateUtilities.startParticleEffects();
}
use of org.spongepowered.api.entity.Entity in project ClearMob by axle2005.
the class CommandDump method entityAllDump.
private void entityAllDump() {
List<String> listentitydump = new ArrayList<String>();
List<String> listtiledump = new ArrayList<String>();
List<Integer> listentitycount = new ArrayList<Integer>();
List<Integer> listtilecount = new ArrayList<Integer>();
for (World world : Sponge.getServer().getWorlds()) {
for (Entity entity : world.getEntities()) {
if (!listentitydump.contains("Entity: " + entity.getType().getId())) {
listentitydump.add("Entity: " + entity.getType().getId());
listentitycount.add(1);
} else if (listentitydump.contains("Entity: " + entity.getType().getId())) {
listentitycount.set(listentitydump.indexOf("Entity: " + entity.getType().getId()), listentitycount.get(listentitydump.indexOf("Entity: " + entity.getType().getId())) + 1);
}
}
for (TileEntity entity : world.getTileEntities()) {
if (!listtiledump.contains("Tile Entity: " + entity.getType().getId())) {
listtiledump.add("Tile Entity: " + entity.getType().getId());
listtilecount.add(1);
} else if (listtiledump.contains("Tile Entity: " + entity.getType().getId())) {
listtilecount.set(listtiledump.indexOf("Tile Entity: " + entity.getType().getId()), listtilecount.get(listtiledump.indexOf("Tile Entity: " + entity.getType().getId())) + 1);
}
}
}
if (listentitydump.isEmpty()) {
plugin.getLogger().info("No Entities to Add");
} else {
for (int i = 0; i <= listentitydump.size() - 1; i++) {
plugin.getLogger().info(listentitydump.get(i) + ": (" + listentitycount.get(i) + ")");
}
}
if (listtiledump.isEmpty()) {
plugin.getLogger().info("No Tile Entities to Add");
} else {
for (int i = 0; i <= listtiledump.size() - 1; i++) {
plugin.getLogger().info(listtiledump.get(i) + ": (" + listtilecount.get(i) + ")");
}
}
}
use of org.spongepowered.api.entity.Entity in project ClearMob by axle2005.
the class CommandInfo method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext arguments) throws CommandException {
String type = arguments.<String>getOne("range/hand").get();
if (!Util.playerPermCheck(src, "clearmob.admin")) {
return CommandResult.empty();
} else if (src instanceof Player) {
Player player = (Player) src;
if (type.equalsIgnoreCase("hand")) {
player.sendMessage(Text.of(player.getItemInHand(HandTypes.MAIN_HAND).get().getItem().getId()));
return CommandResult.success();
} else if (type.equalsIgnoreCase("range")) {
Integer range = arguments.<Integer>getOne("range").get();
Collection<Entity> e = player.getNearbyEntities(range);
for (Entity en : e) {
plugin.getLogger().info("Entity: " + en.getType().getId());
plugin.getLogger().info("Name " + en.getType().getName());
plugin.getLogger().info("DisplayName " + en.getContainers());
plugin.getLogger().info("Display " + en.getValues());
if (en.getKeys().contains(Keys.DISPLAY_NAME)) {
plugin.getLogger().info("D " + en.get(Keys.DISPLAY_NAME));
}
}
return CommandResult.success();
} else {
src.sendMessage(Text.of("clearmob <info><range|hand>"));
return CommandResult.empty();
}
} else {
src.sendMessage(Text.of("You can not run this command"));
return CommandResult.empty();
}
}
use of org.spongepowered.api.entity.Entity in project ClearMob by axle2005.
the class CrashChunkClear method handle.
@Override
public void handle(LoadChunkEvent event) throws Exception {
int removedentities = 0;
for (Entity entity : event.getTargetChunk().getEntities()) {
if ((!entity.getType().getId().equalsIgnoreCase("minecraft:player"))) {
entity.remove();
removedentities++;
}
}
Sponge.getServer().getBroadcastChannel().send(Text.of("Removed: " + removedentities + " Entities at chunk: " + event.getTargetChunk().getPosition()));
}
Aggregations