use of com.easterlyn.EasterlynCore in project Easterlyn by Easterlyn.
the class ChannelManagementListener method onPlayerChat.
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerChat(AsyncPlayerChatEvent event) {
RegisteredServiceProvider<EasterlynCore> easterlynRSP = chat.getServer().getServicesManager().getRegistration(EasterlynCore.class);
if (easterlynRSP == null) {
event.getPlayer().sendMessage("Easterlyn core plugin is not enabled! " + "Please report this to @Staff on Discord immediately!");
return;
}
event.setCancelled(true);
EasterlynCore core = easterlynRSP.getProvider();
User user = core.getUserManager().getUser(event.getPlayer().getUniqueId());
event.getPlayer().setDisplayName(user.getDisplayName());
Channel channel = null;
// #channel message parsing
if (event.getMessage().length() > 0 && event.getMessage().charAt(0) == '#') {
int space = event.getMessage().indexOf(' ');
if (space == -1) {
space = event.getMessage().length();
}
String channelName = event.getMessage().substring(1, space);
if (space == event.getMessage().length()) {
core.getLocaleManager().sendMessage(event.getPlayer(), "chat.common.no_content", "{value}", '#' + channelName);
return;
}
channel = chat.getChannels().get(channelName);
if (channel == null) {
core.getLocaleManager().sendMessage(event.getPlayer(), "chat.common.no_matching_channel", "{value}", '#' + channelName);
return;
}
if (!user.getStorage().getStringList(EasterlynChat.USER_CHANNELS).contains(channel.getName())) {
core.getLocaleManager().sendMessage(event.getPlayer(), "chat.common.not_listening_to_channel", "{value}", channel.getDisplayName());
return;
}
event.setMessage(event.getMessage().substring(space + 1));
}
// User's channel
if (channel == null) {
String currentChannelName = user.getStorage().getString(EasterlynChat.USER_CURRENT);
if (currentChannelName != null) {
channel = chat.getChannels().get(currentChannelName);
}
if (channel == null) {
core.getLocaleManager().sendMessage(event.getPlayer(), "chat.common.not_listening_to_channel");
return;
}
}
new UserChatEvent(user, channel, event.getMessage()).send();
}
use of com.easterlyn.EasterlynCore in project Easterlyn by Easterlyn.
the class ChannelManagementListener method onPlayerJoin.
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerJoin(PlayerJoinEvent event) {
RegisteredServiceProvider<EasterlynCore> easterlynProvider = chat.getServer().getServicesManager().getRegistration(EasterlynCore.class);
if (easterlynProvider == null) {
return;
}
EasterlynCore core = easterlynProvider.getProvider();
User user = core.getUserManager().getUser(event.getPlayer().getUniqueId());
event.getPlayer().setDisplayName(user.getDisplayName());
List<String> savedChannels = user.getStorage().getStringList(EasterlynChat.USER_CHANNELS);
List<String> channels = savedChannels.stream().filter(channelName -> {
Channel channel = chat.getChannels().get(channelName);
if (channel == null) {
return false;
}
if (channel.isWhitelisted(user)) {
channel.getMembers().add(user.getUniqueId());
return true;
}
return false;
}).collect(Collectors.toList());
if (channels.size() != savedChannels.size()) {
user.getStorage().set(EasterlynChat.USER_CHANNELS, channels);
if (!channels.contains(user.getStorage().getString(EasterlynChat.USER_CURRENT))) {
user.getStorage().set(EasterlynChat.USER_CURRENT, null);
}
}
addMainChannel(user, channels);
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm");
String time = dateFormat.format(new Date());
chat.getServer().getOnlinePlayers().forEach(player -> {
User otherUser;
if (player.getUniqueId().equals(user.getUniqueId())) {
otherUser = user;
} else {
otherUser = core.getUserManager().getUser(player.getUniqueId());
}
BaseComponent component = new TextComponent();
component.addExtra(user.getMention());
String locale = core.getLocaleManager().getLocale(player);
for (TextComponent textComponent : StringUtil.toJSON(core.getLocaleManager().getValue("chat.common.join", locale))) {
component.addExtra(textComponent);
}
List<String> commonChannels = otherUser.getStorage().getStringList(EasterlynChat.USER_CHANNELS);
commonChannels.retainAll(channels);
StringJoiner stringJoiner = new StringJoiner(", #", "#", " ").setEmptyValue("");
for (String channel : commonChannels) {
stringJoiner.add(channel);
}
String merged = stringJoiner.toString();
if (commonChannels.size() > 1) {
int lastComma = merged.lastIndexOf(',');
int firstSegmentIndex = commonChannels.size() > 2 ? lastComma + 1 : lastComma;
merged = merged.substring(0, firstSegmentIndex) + core.getLocaleManager().getValue("chat.common.and", locale) + merged.substring(lastComma + 1);
}
for (TextComponent textComponent : StringUtil.toJSON(merged)) {
if (!textComponent.getText().isEmpty()) {
component.addExtra(textComponent);
}
}
for (TextComponent textComponent : StringUtil.toJSON(core.getLocaleManager().getValue("chat.common.at", locale, "{time}", time))) {
component.addExtra(textComponent);
}
otherUser.sendMessage(component);
});
event.setJoinMessage("");
}
use of com.easterlyn.EasterlynCore in project Easterlyn by Easterlyn.
the class EffectAdjacentBlockModifier method applyEffect.
@Override
public void applyEffect(@NotNull LivingEntity entity, int level, @Nullable Event event) {
if (!(event instanceof BlockBreakEvent)) {
return;
}
RegisteredServiceProvider<EasterlynCore> registration = getPlugin().getServer().getServicesManager().getRegistration(EasterlynCore.class);
if (registration == null) {
return;
}
BlockUpdateManager budManager = registration.getProvider().getBlockUpdateManager();
BlockBreakEvent breakEvent = (BlockBreakEvent) event;
Player player = breakEvent.getPlayer();
int currentCount = 0;
for (BlockFace face : faces) {
Block relative = breakEvent.getBlock().getRelative(face);
if (handleAdjacentBlock(player, relative, currentCount)) {
budManager.queueBlock(relative);
}
}
}
use of com.easterlyn.EasterlynCore in project Easterlyn by Easterlyn.
the class PVPKeepInventory method onEntityDamageByEntity.
@EventHandler(ignoreCancelled = true)
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
if (!(event.getEntity() instanceof Player)) {
return;
}
boolean playerDamage = false;
if (event.getDamager() instanceof Player) {
playerDamage = true;
} else if (event.getDamager() instanceof Firework) {
Firework firework = (Firework) event.getDamager();
playerDamage = firework.getSpawningEntity() != null || firework.getShooter() instanceof Player;
} else if (event.getDamager() instanceof Projectile) {
playerDamage = ((Projectile) event.getDamager()).getShooter() instanceof Player;
}
if (!playerDamage) {
return;
}
RegisteredServiceProvider<EasterlynCore> easterlynProvider = Bukkit.getServer().getServicesManager().getRegistration(EasterlynCore.class);
if (easterlynProvider == null) {
return;
}
User user = easterlynProvider.getProvider().getUserManager().getUser(event.getEntity().getUniqueId());
user.getTemporaryStorage().put(key, System.currentTimeMillis());
}
use of com.easterlyn.EasterlynCore in project Easterlyn by Easterlyn.
the class Machine method remove.
/**
* Removes this machine's blocks and listing.
*
* @param storage the ConfigurationSection of data specific to the given Machine
*/
void remove(@NotNull ConfigurationSection storage) {
disable(storage);
Block key = getKey(storage).getBlock();
for (Block block : this.getMachines().getMachineBlocks(key)) {
RegisteredServiceProvider<EasterlynCore> easterlynRSP = Bukkit.getServer().getServicesManager().getRegistration(EasterlynCore.class);
block.setType(Material.AIR, easterlynRSP == null);
if (easterlynRSP != null) {
easterlynRSP.getProvider().getBlockUpdateManager().queueBlock(block);
}
}
key.setType(Material.AIR);
getMachines().removeMachineFromMemory(key);
}
Aggregations