use of com.easterlyn.EasterlynCore in project Easterlyn by Easterlyn.
the class EffectTunnelBore method applyEffect.
@Override
public void applyEffect(@NotNull LivingEntity entity, int level, @Nullable Event event) {
if (!(event instanceof BlockBreakEvent) || event instanceof IndirectBreakEvent) {
return;
}
BlockBreakEvent breakEvent = (BlockBreakEvent) event;
Player player = breakEvent.getPlayer();
if (player.isSneaking()) {
// Sneak to mine single blocks
return;
}
Block block = breakEvent.getBlock();
if (!BlockUtil.isCorrectTool(player.getInventory().getItemInMainHand(), breakEvent.getBlock().getType())) {
// Require correct tool used
return;
}
RegisteredServiceProvider<EasterlynCore> registration = getPlugin().getServer().getServicesManager().getRegistration(EasterlynCore.class);
if (registration == null) {
return;
}
BlockUpdateManager budManager = registration.getProvider().getBlockUpdateManager();
/*
* Forgiveness of .25 hardness allows indirect breaking of most common related materials
* while not excessively increasing risk of accidents inside builds. Allows for mining gravel
* via sand and dirt, etc.
*/
float hardness = block.getType().getHardness() + 0.25F;
for (BlockFace yLevel : levels) {
if (block.getY() == 0 && yLevel == BlockFace.DOWN) {
continue;
}
Block relativeCenter = block.getRelative(yLevel);
if (yLevel != BlockFace.SELF) {
if (handleBlock(hardness, relativeCenter, player, budManager)) {
return;
}
}
for (BlockFace face : faces) {
if (handleBlock(hardness, relativeCenter.getRelative(face), player, budManager)) {
return;
}
}
}
player.updateInventory();
}
use of com.easterlyn.EasterlynCore 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.EasterlynCore in project Easterlyn by Easterlyn.
the class PVPKeepInventory method onPlayerDeath.
@EventHandler(ignoreCancelled = true)
public void onPlayerDeath(PlayerDeathEvent event) {
RegisteredServiceProvider<EasterlynCore> easterlynProvider = Bukkit.getServer().getServicesManager().getRegistration(EasterlynCore.class);
if (easterlynProvider == null) {
return;
}
User user = easterlynProvider.getProvider().getUserManager().getUser(event.getEntity().getUniqueId());
Object object = user.getTemporaryStorage().get(key);
if (!(object instanceof Long)) {
return;
}
long timestamp = (long) object;
if (timestamp < System.currentTimeMillis() - 6000L) {
return;
}
event.setDroppedExp(ExperienceUtil.getExp(event.getEntity()));
int dropped = ExperienceUtil.getExp(event.getEntity()) / 10;
if (dropped > 30) {
dropped = 30;
}
event.setDroppedExp(dropped);
ExperienceUtil.changeExp(event.getEntity(), -dropped);
event.setKeepLevel(true);
event.setKeepInventory(true);
event.getDrops().clear();
}
use of com.easterlyn.EasterlynCore in project Easterlyn by Easterlyn.
the class BottleExperience method onPlayerItemConsume.
@EventHandler(ignoreCancelled = true)
public void onPlayerItemConsume(PlayerItemConsumeEvent event) {
RegisteredServiceProvider<EasterlynCore> easterlynProvider = Bukkit.getServer().getServicesManager().getRegistration(EasterlynCore.class);
if (easterlynProvider == null) {
return;
}
User user = easterlynProvider.getProvider().getUserManager().getUser(event.getPlayer().getUniqueId());
user.getTemporaryStorage().put(keyBottleCreate, System.currentTimeMillis() + 2000);
}
use of com.easterlyn.EasterlynCore in project Easterlyn by Easterlyn.
the class MinecraftBridge method setup.
public void setup() {
client.getEventDispatcher().on(MessageCreateEvent.class).flatMap(event -> Mono.fromRunnable(() -> {
if (event.getMessage().getAuthor().isEmpty() || event.getMessage().getAuthor().get().isBot()) {
return;
}
User author = event.getMessage().getAuthor().get();
String msg = event.getMessage().getContent();
MessageChannel channel = event.getMessage().getChannel().block();
String command = null;
String commandData = null;
if (msg.startsWith(plugin.getCommandPrefix())) {
int prefixLength = plugin.getCommandPrefix().length();
int space = msg.indexOf(' ');
if (space < prefixLength) {
space = msg.length();
}
command = msg.substring(prefixLength, space).toLowerCase();
commandData = msg.substring(space < msg.length() ? space + 1 : space);
}
if (command != null && command.equals("link")) {
UUID pendingLink = plugin.getPendingLink(commandData);
if (pendingLink == null) {
channel.createMessage("Invalid link code! If your code expired, rerun `/link` in" + " Minecraft.\n" + "If you're having trouble, try clicking the message to" + " copy the code!");
} else {
plugin.addLink(pendingLink, author.getId());
}
}
boolean main = channel instanceof GuildMessageChannel && plugin.isChannelType(channel.getId(), ChannelType.MAIN);
if (!main && command == null) {
return;
}
DiscordUser sender = plugin.getUser(author.getId());
if (sender == null) {
Snowflake id = author.getId();
if (warnings.getIfPresent(id) != null) {
return;
}
warnings.put(id, true);
channel.createMessage(author.getMention() + ", you must run `/link` in Minecraft to use this" + " feature!").subscribe();
return;
}
if (command != null) {
handleCommand(sender, channel, command, commandData);
return;
}
handleDiscordChat(sender, event.getMessage());
}).onErrorResume(error -> {
System.out.println("Caught exception handling Discord event:");
error.printStackTrace();
return Mono.empty();
}).thenReturn(event)).subscribe();
Event.register(UserChatEvent.class, event -> {
// TODO may want to try to softdepend on chat instead of hard
if (event.isAsynchronous()) {
handleMinecraftChat(event);
} else {
// Ensure handling is done asynchronously even if chat is somehow sent on main thread
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> handleMinecraftChat(event));
}
}, plugin);
Event.register(PlayerCommandPreprocessEvent.class, event -> {
if (event.getPlayer().hasPermission("easterlyn.discord.exempt.commandlog")) {
return;
}
RegisteredServiceProvider<EasterlynCore> registration = plugin.getServer().getServicesManager().getRegistration(EasterlynCore.class);
if (registration == null) {
return;
}
int space = event.getMessage().indexOf(' ');
String commandName = event.getMessage().substring(1, space > 0 ? space : event.getMessage().length()).toLowerCase();
SimpleCommandMap commandMap = registration.getProvider().getSimpleCommandMap();
if (commandMap == null) {
return;
}
Command command = commandMap.getCommand(commandName);
if (command != null && !plugin.getConfig().getStringList("command-log-blacklist").contains(command.getName())) {
plugin.postMessage(ChannelType.LOG, event.getPlayer().getName() + " issued command: " + event.getMessage());
}
}, plugin, EventPriority.MONITOR);
Event.register(PlayerJoinEvent.class, event -> plugin.postMessage(ChannelType.MAIN, ChatColor.stripColor(event.getPlayer().getDisplayName()) + " logs in."), plugin, EventPriority.MONITOR);
Event.register(PlayerQuitEvent.class, event -> plugin.postMessage(ChannelType.MAIN, ChatColor.stripColor(event.getPlayer().getDisplayName()) + " logs out."), plugin);
}
Aggregations