use of org.spongepowered.api.world.World in project Skree by Skelril.
the class WorldServiceImpl method onPlayerJoin.
@Listener
public void onPlayerJoin(ClientConnectionEvent.Join event) {
try (Connection con = SQLHandle.getConnection()) {
DSLContext create = DSL.using(con);
Player player = event.getTargetEntity();
UUID uuid = player.getUniqueId();
World world = player.getWorld();
Record1<Timestamp> result = create.select(WORLDS.CREATED_AT).from(WORLDS).where(WORLDS.NAME.equal(world.getName())).fetchOne();
Timestamp worldCreationTimestamp = result.getValue(WORLDS.CREATED_AT);
long worldCreationTime = 0;
if (worldCreationTimestamp != null) {
worldCreationTime = worldCreationTimestamp.getTime();
}
if (worldCreationTime > lastPlayerLogin.remove(uuid)) {
Location<World> spawn = getEffectWrapper(MainWorldWrapper.class).get().getPrimaryWorld().getSpawnLocation();
player.setLocation(spawn);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
use of org.spongepowered.api.world.World in project Skree by Skelril.
the class SkyWarsInstance method spawnChickens.
private void spawnChickens() {
Vector3i bvMax = getRegion().getMaximumPoint();
Vector3i bvMin = getRegion().getMinimumPoint();
for (int i = 0; i < getPlayers(PARTICIPANT).size(); ++i) {
Location<World> testLoc = new Location<>(getRegion().getExtent(), Probability.getRangedRandom(bvMin.getX(), bvMax.getX()), bvMax.getY() - 10, Probability.getRangedRandom(bvMin.getZ(), bvMax.getZ()));
Vector2d testPos = new Vector2d(testLoc.getX(), testLoc.getZ());
Vector2d originPos = new Vector2d(startingLocation.getX(), startingLocation.getZ());
if (testPos.distanceSquared(originPos) >= 70 * 70) {
--i;
continue;
}
Chicken chicken = (Chicken) testLoc.getExtent().createEntity(EntityTypes.CHICKEN, testLoc.getPosition());
chicken.offer(Keys.PERSISTS, false);
testLoc.getExtent().spawnEntity(chicken, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build());
}
}
use of org.spongepowered.api.world.World in project Skree by Skelril.
the class VelocityEntitySpawner method sendRadial.
public static List<Entity> sendRadial(EntityType type, Living living, int amt, float speed, Cause cause) {
Location<World> livingLocation = living.getLocation();
Optional<EyeLocationProperty> optEyeLoc = living.getProperty(EyeLocationProperty.class);
if (optEyeLoc.isPresent()) {
Vector3d eyePosition = optEyeLoc.get().getValue();
livingLocation = livingLocation.setPosition(eyePosition);
}
return sendRadial(type, livingLocation, amt, speed, cause);
}
use of org.spongepowered.api.world.World in project HuskyCrates-Sponge by codeHusky.
the class CrateUtilities method particleRunner.
private void particleRunner() {
if (flag)
return;
try {
ArrayList<Location<World>> invalidLocations = new ArrayList<>();
HashSet<World> invalidLocationWorlds = new HashSet<>();
for (Location<World> b : physicalCrates.keySet()) {
PhysicalCrate c = physicalCrates.get(b);
if (c.vc.crateBlockType != c.location.getBlock().getType() && c.location.getExtent().isLoaded() && c.location.getExtent().getChunk(c.location.getChunkPosition()).isPresent()) {
if (c.location.getExtent().getChunk(c.location.getChunkPosition()).get().isLoaded()) {
invalidLocations.add(c.location);
invalidLocationWorlds.add(c.location.getExtent());
continue;
}
}
c.runParticles();
}
for (World w : invalidLocationWorlds) {
for (Entity e : w.getEntities()) {
if (invalidLocations.contains(e.getLocation()) && e.getType() != EntityTypes.ARMOR_STAND) {
//System.out.println("woah");
invalidLocations.remove(e.getLocation());
physicalCrates.get(e.getLocation()).runParticles();
}
}
}
for (Location<World> l : invalidLocations) {
PhysicalCrate c = physicalCrates.get(l);
HuskyCrates.instance.logger.warn("Removing crate that no longer exists! " + c.location.getPosition().toString());
c.as.remove();
physicalCrates.remove(l);
flag = true;
}
} catch (Exception e) {
}
if (flag)
HuskyCrates.instance.updatePhysicalCrates();
}
use of org.spongepowered.api.world.World in project HuskyCrates-Sponge by codeHusky.
the class HuskyCrates method crateInteract.
@Listener
public void crateInteract(InteractBlockEvent.Secondary.MainHand event) {
//pp.getInventory().offer(ItemStack.builder().fromContainer(ss.toContainer().set(DataQuery.of("UnsafeDamage"),3)).build());*/
if (!event.getTargetBlock().getLocation().isPresent())
return;
Location<World> blk = event.getTargetBlock().getLocation().get();
//System.out.println(blk.getBlock().getType());
if (validCrateBlocks.contains(blk.getBlockType())) {
Player plr = (Player) event.getCause().root();
if (crateUtilities.physicalCrates.containsKey(blk)) {
String crateType = crateUtilities.physicalCrates.get(blk).vc.id;
VirtualCrate vc = crateUtilities.getVirtualCrate(crateType);
crateUtilities.physicalCrates.get(blk).createHologram();
if (vc.crateBlockType == blk.getBlockType()) {
event.setCancelled(true);
} else {
return;
}
//crateUtilities.recognizeChest(te.getLocation());
if (plr.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
ItemStack inhand = plr.getItemInHand(HandTypes.MAIN_HAND).get();
if (inhand.getItem() == vc.getKeyType()) {
if (inhand.toContainer().get(DataQuery.of("UnsafeData", "crateID")).isPresent()) {
String id = inhand.toContainer().get(DataQuery.of("UnsafeData", "crateID")).get().toString();
if (id.equals(crateType)) {
if (!plr.hasPermission("huskycrates.tester")) {
if (inhand.getQuantity() == 1)
plr.setItemInHand(HandTypes.MAIN_HAND, null);
else {
ItemStack tobe = inhand.copy();
tobe.setQuantity(tobe.getQuantity() - 1);
plr.setItemInHand(HandTypes.MAIN_HAND, tobe);
}
}
Task.Builder upcoming = scheduler.createTaskBuilder();
upcoming.execute(() -> {
crateUtilities.launchCrateForPlayer(crateType, plr, this);
}).delayTicks(1).submit(this);
return;
}
}
}
}
plr.playSound(SoundTypes.BLOCK_ANVIL_LAND, blk.getPosition(), 0.3);
try {
plr.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(vc.langData.formatter(vc.langData.prefix + vc.langData.noKeyMessage, null, plr, vc, null)));
} catch (Exception e) {
plr.sendMessage(Text.of(TextColors.RED, "Critical crate failure, contact the administrator. (Admins, check console!)"));
e.printStackTrace();
}
}
}
}
Aggregations