use of org.spongepowered.api.event.Listener in project Skree by Skelril.
the class CursedMineListener method onBlockBreak.
@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @Named(NamedCause.SOURCE) Player player) {
Optional<CursedMineInstance> optInst = manager.getApplicableZone(player);
if (!optInst.isPresent()) {
return;
}
CursedMineInstance inst = optInst.get();
Optional<ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
if (!optHeldItem.isPresent()) {
event.setCancelled(true);
return;
}
for (Transaction<BlockSnapshot> block : event.getTransactions()) {
BlockType originalType = block.getOriginal().getState().getType();
if (cursedOres.contains(originalType)) {
// we were having some multi-firing problems
if (inst.recordBlockBreak(player, new BlockRecord(block.getOriginal()))) {
/*if (Probability.getChance(3000)) {
ChatUtil.send(player, "You feel as though a spirit is trying to tell you something...");
player.getInventory().addItem(BookUtil.Lore.Areas.theGreatMine());
}*/
ExperienceOrb xpOrb = (ExperienceOrb) player.getWorld().createEntity(EntityTypes.EXPERIENCE_ORB, block.getOriginal().getLocation().get().getPosition());
xpOrb.offer(Keys.CONTAINED_EXPERIENCE, (70 - player.getLocation().getBlockY()) / 2);
inst.eatFood(player);
inst.poison(player, 6);
inst.ghost(player, originalType);
}
} else if (stealableFluids.contains(originalType)) {
inst.recordBlockBreak(player, new BlockRecord(block.getOriginal()));
} else {
block.setCustom(block.getOriginal());
}
}
}
use of org.spongepowered.api.event.Listener in project ProjectWorlds by trentech.
the class EventManager method onRespawnPlayerEvent.
@Listener
public void onRespawnPlayerEvent(RespawnPlayerEvent event) {
World world = event.getFromTransform().getExtent();
WorldProperties properties = world.getProperties();
String worldName = properties.getGameRule("spawnOnDeath").get();
Optional<World> optionalSpawnWorld = Sponge.getServer().getWorld(worldName);
if (!optionalSpawnWorld.isPresent()) {
return;
}
World spawnWorld = optionalSpawnWorld.get();
Transform<World> transform = event.getToTransform().setLocation(spawnWorld.getSpawnLocation());
event.setToTransform(transform);
}
use of org.spongepowered.api.event.Listener in project ProjectWorlds by trentech.
the class EventManager method onDamageEntityEvent.
@Listener
public void onDamageEntityEvent(DamageEntityEvent event, @Root EntityDamageSource damageSource) {
if (!(event.getTargetEntity() instanceof Player)) {
return;
}
Player victim = (Player) event.getTargetEntity();
if (!isValidPlayer(damageSource)) {
return;
}
World world = victim.getWorld();
WorldProperties properties = world.getProperties();
if (!properties.isPVPEnabled() || victim.hasPermission("pjw.override.pvp")) {
event.setCancelled(true);
}
}
use of org.spongepowered.api.event.Listener in project ProjectWorlds by trentech.
the class EventManager method onChangeWorldWeatherEvent.
@Listener
public void onChangeWorldWeatherEvent(ChangeWorldWeatherEvent event) {
World world = event.getTargetWorld();
WorldProperties properties = world.getProperties();
if (properties.getGameRule("doWeatherCycle").get().equalsIgnoreCase("false")) {
event.setCancelled(true);
}
}
use of org.spongepowered.api.event.Listener in project LuckPerms by lucko.
the class SpongeConnectionListener method onClientAuth.
@Listener(order = Order.EARLY)
@IsCancelled(Tristate.UNDEFINED)
public void onClientAuth(ClientConnectionEvent.Auth e) {
/* Called when the player first attempts a connection with the server.
Listening on AFTER_PRE priority to allow plugins to modify username / UUID data here. (auth plugins) */
final GameProfile profile = e.getProfile();
final String username = profile.getName().orElseThrow(() -> new RuntimeException("No username present for user " + profile.getUniqueId()));
if (this.plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
this.plugin.getLogger().info("Processing auth event for " + profile.getUniqueId() + " - " + profile.getName());
}
recordConnection(profile.getUniqueId());
/* Actually process the login for the connection.
We do this here to delay the login until the data is ready.
If the login gets cancelled later on, then this will be cleaned up.
This includes:
- loading uuid data
- loading permissions
- creating a user instance in the UserManager for this connection.
- setting up cached data. */
try {
User user = loadUser(profile.getUniqueId(), username);
this.plugin.getEventFactory().handleUserLoginProcess(profile.getUniqueId(), username, user);
} catch (Exception ex) {
this.plugin.getLogger().severe("Exception occurred whilst loading data for " + profile.getUniqueId() + " - " + profile.getName());
ex.printStackTrace();
this.deniedAsyncLogin.add(profile.getUniqueId());
e.setCancelled(true);
e.setMessageCancelled(false);
// noinspection deprecation
e.setMessage(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(Message.LOADING_ERROR.asString(this.plugin.getLocaleManager())));
}
}
Aggregations