use of com.easterlyn.user.User 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.user.User in project Easterlyn by Easterlyn.
the class ListCommand method list.
@CommandAlias("list|ls")
@Description("{@@sink.module.list.description}")
@CommandPermission("easterlyn.command.list")
@Syntax("")
@CommandCompletion("")
public void list(BukkitCommandIssuer issuer) {
Player sender = issuer.getPlayer();
UserRank[] ranks = UserRank.values();
Multimap<String, User> groupedUsers = HashMultimap.create();
int total = 0;
for (Player player : Bukkit.getOnlinePlayers()) {
if (sender != null && !sender.canSee(player)) {
continue;
}
++total;
for (int i = ranks.length - 1; i >= 0; --i) {
UserRank rank = ranks[i];
if (i == 0 || player.hasPermission(rank.getPermission())) {
groupedUsers.put(rank.getFriendlyName(), core.getUserManager().getUser(player.getUniqueId()));
break;
}
}
}
if (ThreadLocalRandom.current().nextDouble() < .001) {
Map<String, String> easterEgg = new HashMap<>();
easterEgg.put("name", "Herobrine");
easterEgg.put("color", ChatColor.BLACK.toString());
groupedUsers.put(UserRank.MEMBER.getFriendlyName(), new AutoUser(core, easterEgg));
}
issuer.sendInfo(MessageKey.of("sink.module.list.header"), "{value}", String.valueOf(total), "{max}", String.valueOf(Bukkit.getMaxPlayers()));
for (int i = ranks.length - 1; i >= 0; --i) {
String groupName = ranks[i].getFriendlyName();
if (i > 0 && groupName.equals(ranks[i - 1].getFriendlyName()) || !groupedUsers.containsKey(groupName)) {
continue;
}
Collection<User> users = groupedUsers.get(groupName);
List<BaseComponent> components = new ArrayList<>(users.size() * 2 + 2);
TextComponent component = new TextComponent(groupName);
component.setColor(ranks[i].getColor());
components.add(component);
component = new TextComponent(": ");
component.setColor(ChatColor.YELLOW);
components.add(component);
TextComponent separator = new TextComponent(", ");
separator.setColor(ChatColor.YELLOW);
users.forEach(user -> {
components.add(user.getMention());
components.add(separator);
});
components.remove(components.size() - 1);
issuer.getIssuer().spigot().sendMessage(components.toArray(new BaseComponent[0]));
}
}
use of com.easterlyn.user.User 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.user.User in project Easterlyn by Easterlyn.
the class MessageCommand method sendMessage.
@CommandAlias("reply|r")
@Description("{@@chat.commands.reply.description}")
@CommandPermission("easterlyn.command.message")
@Syntax("<message>")
@CommandCompletion("")
public void sendMessage(@Flags(CoreContexts.SELF) BukkitCommandIssuer sender, String message) {
User target = replies.get(sender.getUniqueId());
if (target == null) {
core.getLocaleManager().sendMessage(sender.getIssuer(), "chat.commands.reply.error.no_target");
return;
}
sendMessage(sender, target, message);
}
use of com.easterlyn.user.User in project Easterlyn by Easterlyn.
the class MessageCommand method sendMessage.
@CommandAlias("message|msg|m|whisper|w|pm|tell|t")
@Description("{@@chat.commands.message.description}")
@CommandPermission("easterlyn.command.message")
@Syntax("<recipient> <message>")
@CommandCompletion("@player")
public void sendMessage(BukkitCommandIssuer sender, @Flags(CoreContexts.ONLINE) User target, String message) {
User issuer;
if (sender.isPlayer()) {
issuer = core.getUserManager().getUser(sender.getUniqueId());
} else {
Map<String, String> userData = new HashMap<>();
userData.put("name", sender.getIssuer().getName());
issuer = new AutoUser(core, userData);
// For the purpose of allowing replies to console, set target's reply target.
replies.put(target.getUniqueId(), issuer);
}
replies.put(issuer.getUniqueId(), target);
Channel channel = chat.getChannels().get("pm");
if (channel == null) {
ReportableEvent.call("Channel #pm not set up when executing /message!");
core.getLocaleManager().sendMessage(sender.getIssuer(), "chat.commands.message.error.pm_channel");
return;
}
List<UUID> recipients = new ArrayList<>();
if (!(issuer instanceof AutoUser)) {
recipients.add(issuer.getUniqueId());
}
if (!(target instanceof AutoUser)) {
recipients.add(target.getUniqueId());
}
new UserChatEvent(issuer, channel, target.getDisplayName() + ": " + message).send(recipients);
}
Aggregations