use of com.easterlyn.user.User in project Easterlyn by Easterlyn.
the class BackCommand method onPlayerTeleport.
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerTeleport(PlayerTeleportEvent event) {
switch(event.getCause()) {
case COMMAND:
case END_GATEWAY:
case PLUGIN:
break;
case CHORUS_FRUIT:
case END_PORTAL:
case ENDER_PEARL:
case NETHER_PORTAL:
case SPECTATE:
case UNKNOWN:
default:
return;
}
User user = core.getUserManager().getUser(event.getPlayer().getUniqueId());
user.getStorage().set(BACK_LOCATION, event.getFrom());
}
use of com.easterlyn.user.User in project Easterlyn by Easterlyn.
the class Transportalizer method getFailureMessage.
@Nullable
private String getFailureMessage(Player player, Entity entity, boolean push, Location from, Location to, ConfigurationSection storage, int cost) {
if (push && entity instanceof Player) {
// Sender must have button access to send players
if (!ProtectionUtil.canUseButtonsAt(player, to)) {
return ChatColor.RED + "You do not have access to the location specified!";
}
return null;
}
if (!push && entity instanceof Player) {
RegisteredServiceProvider<EasterlynCore> registration = getMachines().getServer().getServicesManager().getRegistration(EasterlynCore.class);
if (registration == null) {
return "Easterlyn core plugin not loaded! Cannot pull players.";
}
if (player.getUniqueId().equals(entity.getUniqueId())) {
return null;
}
User target = registration.getProvider().getUserManager().getUser(entity.getUniqueId());
User issuer = registration.getProvider().getUserManager().getUser(player.getUniqueId());
if (target.setPendingRequest(new Request() {
@Override
public void accept() {
if (getFuel(storage) < cost) {
target.sendMessage("Transportalizer is too low on fuel! Ask " + issuer.getDisplayName() + " to add more!");
}
Player localTarget = target.getPlayer();
if (localTarget == null) {
return;
}
teleport(entity, from, to);
setFuel(storage, getFuel(storage) - cost);
}
@Override
public void decline() {
target.sendMessage("Request declined!");
}
})) {
target.sendMessage(issuer.getUniqueId(), issuer.getDisplayName() + " is requesting to transportalize you!\n" + "Use /accept or /decline to manage the request.");
// Blank message won't actually send, but will preclude immediate transportalization.
return "";
}
return null;
}
// Ender dragon or ender dragon parts
if (entity instanceof ComplexLivingEntity || entity instanceof ComplexEntityPart) {
return ChatColor.RED + "Great effort, but you can't transportalize a dragon.";
}
if (entity instanceof ArmorStand) {
// Armor stand manipulation requires the ability to build
if (!ProtectionUtil.canBuildAt(player, from) || !ProtectionUtil.canBuildAt(player, to)) {
return ChatColor.RED + "You do not have access to the location specified!";
}
return null;
}
if (entity instanceof Monster || entity instanceof Explosive || entity instanceof ExplosiveMinecart) {
// Hostiles, TNT, wither projectiles, fireballs, etc. require build permissions
if (!ProtectionUtil.canOpenChestsAt(player, from) || !ProtectionUtil.canBuildAt(player, to)) {
return ChatColor.RED + "You do not have access to the location specified!";
}
return null;
}
// Generic push/pull requires chest access in send location and full access in arrival location
if (!ProtectionUtil.canOpenChestsAt(player, from) || !ProtectionUtil.canMobsSpawn(to) && !ProtectionUtil.canBuildAt(player, to)) {
return ChatColor.RED + "You do not have access to the location specified!";
}
return null;
}
use of com.easterlyn.user.User in project Easterlyn by Easterlyn.
the class EasterlynSpectators method onEnable.
@Override
public void onEnable() {
PermissionUtil.addParent("easterlyn.spectators.unrestricted", UserRank.STAFF.getPermission());
PermissionUtil.addParent("easterlyn.spectators.nightvision", UserRank.MODERATOR.getPermission());
Event.register(BlockBreakEvent.class, event -> {
if (event.getPlayer().hasPermission("easterlyn.spectators.unrestricted")) {
return;
}
RegisteredServiceProvider<EasterlynCore> registration = getServer().getServicesManager().getRegistration(EasterlynCore.class);
if (registration == null) {
return;
}
User user = registration.getProvider().getUserManager().getUser(event.getPlayer().getUniqueId());
long spectatore = user.getStorage().getLong(USER_SPECTATE_COOLDOWN, 0);
if (spectatore < System.currentTimeMillis()) {
return;
}
for (BlockFace face : new BlockFace[] { BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST, BlockFace.UP, BlockFace.SELF, BlockFace.DOWN }) {
Block block = event.getBlock().getRelative(face);
if (block.getType() == Material.NETHER_QUARTZ_ORE) {
block.setType(Material.NETHERRACK);
}
if (block.getType().name().endsWith("_ORE")) {
block.setType(Material.STONE);
}
}
}, this, EventPriority.LOW);
Event.register(PlayerQuitEvent.class, event -> {
RegisteredServiceProvider<EasterlynCore> registration = getServer().getServicesManager().getRegistration(EasterlynCore.class);
if (registration == null) {
return;
}
Player player = event.getPlayer();
if (player.getGameMode() != GameMode.SPECTATOR) {
return;
}
User user = registration.getProvider().getUserManager().getUser(player.getUniqueId());
Location spectateReturn = user.getStorage().getSerializable(USER_SPECTATE_RETURN, Location.class);
if (spectateReturn == null) {
return;
}
player.teleport(spectateReturn);
}, this);
Event.register(PlayerJoinEvent.class, event -> {
RegisteredServiceProvider<EasterlynCore> registration = getServer().getServicesManager().getRegistration(EasterlynCore.class);
if (registration == null) {
return;
}
Player player = event.getPlayer();
User user = registration.getProvider().getUserManager().getUser(player.getUniqueId());
Location spectateReturn = user.getStorage().getSerializable(USER_SPECTATE_RETURN, Location.class);
if (spectateReturn == null) {
return;
}
user.getStorage().set(USER_SPECTATE_RETURN, null);
user.getStorage().set(USER_SPECTATE_COOLDOWN, System.currentTimeMillis() + 480000L);
player.teleport(spectateReturn);
if (player.getGameMode() == GameMode.SPECTATOR) {
player.setGameMode(GameMode.SURVIVAL);
}
}, this);
Event.register(PlayerTeleportEvent.class, event -> {
if (event.getCause() != PlayerTeleportEvent.TeleportCause.SPECTATE) {
return;
}
RegisteredServiceProvider<EasterlynCore> registration = getServer().getServicesManager().getRegistration(EasterlynCore.class);
if (registration == null) {
return;
}
Player player = event.getPlayer();
User user = registration.getProvider().getUserManager().getUser(player.getUniqueId());
// Don't block request-based teleportation
if (user.getStorage().getBoolean(USER_SPECTPA)) {
return;
}
Location spectateReturn = user.getStorage().getSerializable(USER_SPECTATE_RETURN, Location.class);
if (spectateReturn != null) {
event.setCancelled(true);
player.sendMessage("Spectating via hotbar is currently disabled. Please use `/spectpa`!");
}
}, this);
Event.register(PlayerGameModeChangeEvent.class, event -> {
RegisteredServiceProvider<EasterlynCore> registration = getServer().getServicesManager().getRegistration(EasterlynCore.class);
if (registration == null) {
return;
}
Player player = event.getPlayer();
if (player.getGameMode() != GameMode.SPECTATOR) {
return;
}
User user = registration.getProvider().getUserManager().getUser(player.getUniqueId());
Location spectateReturn = user.getStorage().getSerializable(USER_SPECTATE_RETURN, Location.class);
if (spectateReturn != null) {
event.setCancelled(true);
}
}, this);
RegisteredServiceProvider<EasterlynCore> registration = getServer().getServicesManager().getRegistration(EasterlynCore.class);
if (registration != null) {
register(registration.getProvider());
}
Event.register(PluginEnableEvent.class, pluginEnableEvent -> {
if (pluginEnableEvent.getPlugin() instanceof EasterlynCore) {
register((EasterlynCore) pluginEnableEvent.getPlugin());
}
}, this);
}
use of com.easterlyn.user.User in project Easterlyn by Easterlyn.
the class DeathPointCommand method onPlayerTeleport.
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerTeleport(PlayerDeathEvent event) {
User user = core.getUserManager().getUser(event.getEntity().getUniqueId());
user.getStorage().set(DEATH_LOCATION, event.getEntity().getLocation());
}
use of com.easterlyn.user.User in project Easterlyn by Easterlyn.
the class LoginCommands method onPlayerJoin.
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event) {
User user = core.getUserManager().getUser(event.getPlayer().getUniqueId());
user.getStorage().getStringList(ONLOGIN).forEach(string -> event.getPlayer().chat(string));
}
Aggregations