use of org.spongepowered.api.entity.living.ArmorStand 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.living.ArmorStand in project RedProtect by FabioZumbi12.
the class RPGlobalListener method onPlayerInteract.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerInteract(InteractEntityEvent e, @Root Player p) {
Entity ent = e.getTargetEntity();
Location<World> l = ent.getLocation();
Region r = RedProtect.get().rm.getTopRegion(l);
if (!canInteract(p, r)) {
e.setCancelled(true);
}
if (r != null) {
return;
}
if (ent instanceof Minecart || ent instanceof Boat) {
if (!RedProtect.get().cfgs.getGlobalFlag(ent.getWorld().getName(), "use-minecart") && !p.hasPermission("redprotect.world.bypass")) {
e.setCancelled(true);
return;
}
}
if (ent instanceof Hanging || ent instanceof ArmorStand) {
if (!RedProtect.get().cfgs.getGlobalFlag(ent.getWorld().getName(), "build") && !p.hasPermission("redprotect.world.bypass")) {
e.setCancelled(true);
return;
}
}
if (!RedProtect.get().cfgs.getGlobalFlag(ent.getWorld().getName(), "interact") && !p.hasPermission("redprotect.world.bypass") && (!(ent instanceof Player))) {
e.setCancelled(true);
}
}
use of org.spongepowered.api.entity.living.ArmorStand in project RedProtect by FabioZumbi12.
the class RPMine18 method onEntityDamage.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onEntityDamage(DamageEntityEvent e, @First Entity e2) {
Entity e1 = e.getTargetEntity();
Location<World> loc = e1.getLocation();
Player damager = null;
if (e2 instanceof Projectile) {
Projectile proj = (Projectile) e2;
if (proj.getShooter() instanceof Player) {
damager = (Player) proj.getShooter();
}
} else if (e2 instanceof Player) {
damager = (Player) e2;
}
Region r1 = RedProtect.get().rm.getTopRegion(loc);
if (r1 == null) {
// global flags
if (e1 instanceof ArmorStand) {
if (e2 instanceof Player) {
if (!RedProtect.get().cfgs.getGlobalFlag(loc.getExtent().getName(), "build")) {
e.setCancelled(true);
return;
}
}
}
return;
}
if (e1 instanceof ArmorStand) {
if (r1 != null && !r1.canBuild(damager)) {
e.setCancelled(true);
RPLang.sendMessage(damager, "blocklistener.region.cantbreak");
}
}
}
use of org.spongepowered.api.entity.living.ArmorStand in project HuskyCrates-Sponge by codeHusky.
the class HuskyCrates method postGameStart.
@Listener(order = Order.POST)
public void postGameStart(GameStartedServerEvent event) {
Sponge.getScheduler().createTaskBuilder().async().execute(new Consumer<Task>() {
@Override
public void accept(Task task) {
try {
JSONObject obj = JsonReader.readJsonFromUrl("https://api.github.com/repos/codehusky/HuskyCrates-Sponge/releases");
String[] thisVersion = pC.getVersion().get().split("\\.");
String[] remoteVersion = obj.getJSONArray("releases").getJSONObject(0).getString("tag_name").replace("v", "").split("\\.");
for (int i = 0; i < Math.min(remoteVersion.length, thisVersion.length); i++) {
if (!thisVersion[i].equals(remoteVersion[i])) {
if (Integer.parseInt(thisVersion[i]) > Integer.parseInt(remoteVersion[i])) {
//we're ahead
logger.warn("----------------------------------------------------");
logger.warn("Running unreleased version. (Developer build?)");
logger.warn("----------------------------------------------------");
} else {
//we're behind
logger.warn("----------------------------------------------------");
logger.warn("Your version of HuskyCrates is out of date!");
logger.warn("Your version: v" + pC.getVersion().get());
logger.warn("Latest version: " + obj.getJSONArray("releases").getJSONObject(0).getString("tag_name"));
logger.warn("Update here: https://goo.gl/hgtPMR");
logger.warn("----------------------------------------------------");
}
return;
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}).submit(this);
Sponge.getScheduler().createTaskBuilder().execute(new Consumer<Task>() {
@Override
public void accept(Task task) {
logger.info("Deleting existing armor stands...");
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();
}
}
}
}
}
logger.info("Initalizing config...");
if (!crateUtilities.hasInitalizedVirtualCrates) {
crateUtilities.generateVirtualCrates(crateConfig);
}
// doublecheck
crateUtilities.hasInitalizedVirtualCrates = true;
logger.info("Done initalizing config.");
logger.info("Populating physical crates...");
CommentedConfigurationNode root = null;
try {
root = crateConfig.load();
double max = root.getNode("positions").getChildrenList().size();
double count = 0;
for (CommentedConfigurationNode node : root.getNode("positions").getChildrenList()) {
count++;
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));
logger.info("PROGRESS: " + Math.round((count / max) * 100) + "%");
}
} catch (IOException e) {
e.printStackTrace();
} catch (ObjectMappingException e) {
e.printStackTrace();
}
crateUtilities.startParticleEffects();
logger.info("Done populating physical crates.");
logger.info("Initalization complete.");
}
}).delayTicks(1).submit(this);
}
use of org.spongepowered.api.entity.living.ArmorStand in project RedProtect by FabioZumbi12.
the class RPGlobalListener method onProjectileHit.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onProjectileHit(CollideEntityEvent event, @Root Projectile proj) {
RedProtect.get().logger.debug("entity", "Is CollideEntityEvent(onProjectileHit) event.");
RedProtect.get().logger.debug("entity", "Projectile: " + proj.getType().getName());
if (RedProtect.get().rm.getTopRegion(proj.getLocation()) != null)
return;
for (Entity ent : event.getEntities()) {
RedProtect.get().logger.debug("entity", "Entity: " + ent.getType().getName());
if (proj.getShooter() instanceof Player) {
Player p = (Player) proj.getShooter();
if (ent instanceof Player) {
if (!p.equals(ent) && !RedProtect.get().cfgs.getGlobalFlag(ent.getWorld().getName(), "pvp") && !p.hasPermission("redprotect.world.bypass")) {
event.setCancelled(true);
return;
}
}
if (ent instanceof Animal || ent instanceof Villager || ent instanceof Golem || ent instanceof Ambient) {
if (!RedProtect.get().cfgs.getGlobalFlag(ent.getWorld().getName(), "player-hurt-passives") && !p.hasPermission("redprotect.world.bypass")) {
event.setCancelled(true);
return;
}
}
if (ent instanceof Monster) {
if (!RedProtect.get().cfgs.getGlobalFlag(ent.getWorld().getName(), "player-hurt-monsters") && !p.hasPermission("redprotect.world.bypass")) {
event.setCancelled(true);
return;
}
}
if (ent instanceof Hanging || ent instanceof ArmorStand) {
if (!RedProtect.get().cfgs.getGlobalFlag(ent.getWorld().getName(), "build") && !p.hasPermission("redprotect.world.bypass")) {
event.setCancelled(true);
}
}
} else {
if (ent instanceof Hanging || ent instanceof ArmorStand) {
if (!RedProtect.get().cfgs.getGlobalFlag(ent.getWorld().getName(), "entity-block-damage")) {
event.setCancelled(true);
return;
}
}
}
}
}
Aggregations