use of org.spongepowered.api.event.Listener in project HuskyCrates-Sponge by codeHusky.
the class HuskyCrates method placeBlock.
@Listener
public void placeBlock(ChangeBlockEvent event) {
if (event.getCause().root() instanceof Player) {
Player plr = (Player) event.getCause().root();
if (event instanceof ChangeBlockEvent.Place || event instanceof ChangeBlockEvent.Break) {
BlockType t = event.getTransactions().get(0).getOriginal().getLocation().get().getBlock().getType();
Location<World> location = event.getTransactions().get(0).getOriginal().getLocation().get();
location.getBlock().toContainer().set(DataQuery.of("rock"), 1);
//location.getBlock().with()
if (validCrateBlocks.contains(t)) {
//crateUtilities.recognizeChest(event.getTransactions().get(0).getOriginal().getLocation().get());
if (event instanceof ChangeBlockEvent.Place) {
if (plr.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
Optional<Object> tt = plr.getItemInHand(HandTypes.MAIN_HAND).get().toContainer().get(DataQuery.of("UnsafeData", "crateID"));
if (tt.isPresent()) {
String crateID = tt.get().toString();
if (!plr.hasPermission("huskycrates.tester")) {
event.setCancelled(true);
return;
}
if (!crateUtilities.physicalCrates.containsKey(location))
crateUtilities.physicalCrates.put(location, new PhysicalCrate(location, crateID, this));
crateUtilities.physicalCrates.get(location).createHologram();
updatePhysicalCrates();
}
}
}
} else {
if (crateUtilities.physicalCrates.containsKey(location)) {
if (!plr.hasPermission("huskycrates.tester")) {
event.setCancelled(true);
return;
}
crateUtilities.flag = true;
crateUtilities.physicalCrates.get(location).as.remove();
crateUtilities.physicalCrates.remove(location);
updatePhysicalCrates();
}
}
}
}
}
use of org.spongepowered.api.event.Listener 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.event.Listener in project HuskyCrates-Sponge by codeHusky.
the class HuskyCrates method gameInit.
@Listener
public void gameInit(GamePreInitializationEvent event) {
logger = LoggerFactory.getLogger(pC.getName());
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.");
}
logger.info("Let's not init VCrates here anymore. ://)");
instance = this;
}
use of org.spongepowered.api.event.Listener in project ClearMob by axle2005.
the class EntityLimiter method handle.
@Listener(beforeModifications = true)
public void handle(SpawnEntityEvent event) throws Exception {
List<Entity> entity = event.getEntities();
Integer count = 0;
Integer xpcount = 0;
for (World w : plugin.getWorlds()) {
for (Entity e : w.getEntities()) {
if (e instanceof Monster && !(e instanceof Boss)) {
count++;
}
if (e instanceof ExperienceOrb) {
xpcount++;
}
}
}
for (int i = 0; i < entity.size(); i++) {
if (entity.get(i) instanceof Monster && (count > plugin.getMobLimit()) && !(entity.get(i) instanceof Boss)) {
event.setCancelled(true);
}
if ((entity.get(i) instanceof ExperienceOrb && entity.get(i).getNearbyEntities(10).size() > 20)) {
event.setCancelled(true);
}
}
}
use of org.spongepowered.api.event.Listener in project ClearMob by axle2005.
the class ClearMob method preInitialization.
@Listener
public void preInitialization(GamePreInitializationEvent event) {
config = new Config(this, defaultConfig, configManager);
events = new ListenersRegister(this);
w = new Warning();
listEntityType = Util.getEntityType(config.getList("ClearingLists,EntityList"));
listTileEntityType = Util.getTileEntityType(config.getList("Clearing,Lists,TileEntityList"));
listItemType = Util.getItemType(config.getList("Clearing,Lists,ItemList"));
itemWB = config.getNodeString("Clearing,KillDrops,ListType");
configoptions[0] = config.getNodeBoolean("Clearing,PassiveMode");
configoptions[1] = config.getNodeBoolean("Clearing,KillAllMonsters");
configoptions[2] = config.getNodeBoolean("Clearing,KillDrops,Enabled");
configoptions[3] = config.getNodeBoolean("Clearing,KillAnimalGroups");
configoptions[4] = config.getNodeBoolean("Warning,Enabled");
configoptions[5] = config.getNodeBoolean("Clearing,CrashMode");
configoptions[6] = config.getNodeBoolean("Clearing,MobLimiter,Enabled");
interval = config.getNodeInt("Clearing,Interval");
moblimit = config.getNodeInt("Clearing,MobLimiter,Limit");
warningmessage = config.getNodeString("Warning,Messages,Warning");
clearedmessage = config.getNodeString("Warning,Messages,Cleared");
}
Aggregations