Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ jobs:
cp -r EssentialsAntiBuild/build/docs/javadoc/ javadocs/EssentialsAntiBuild/
cp -r EssentialsChat/build/docs/javadoc/ javadocs/EssentialsChat/
cp -r EssentialsDiscord/build/docs/javadoc/ javadocs/EssentialsDiscord/
cp -r EssentialsDiscordLink/build/docs/javadoc/ javadocs/EssentialsDiscordLink/
cp -r EssentialsGeoIP/build/docs/javadoc/ javadocs/EssentialsGeoIP/
cp -r EssentialsProtect/build/docs/javadoc/ javadocs/EssentialsProtect/
cp -r EssentialsSpawn/build/docs/javadoc/ javadocs/EssentialsSpawn/
Expand Down
2 changes: 1 addition & 1 deletion .idea/checkstyle-idea.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,26 @@ public void onPlayerMove(final PlayerMoveEvent event) {
return;
}

if (!ess.getSettings().cancelAfkOnMove() && !ess.getSettings().getFreezeAfkPlayers()) {
event.getHandlers().unregister(this);
final User user = ess.getUser(event.getPlayer());

if (ess.getSettings().isDebug()) {
ess.getLogger().log(Level.INFO, "Unregistering move listener");
if (user.isFreeze()) {
final Location from = event.getFrom();
final Location to = event.getTo().clone();
to.setX(from.getX());
to.setY(from.getY());
to.setZ(from.getZ());
try {
event.setTo(LocationUtil.getSafeDestination(ess, to));
} catch (final Exception ex) {
event.setTo(to);
}
return;
}

if (!ess.getSettings().cancelAfkOnMove() && !ess.getSettings().getFreezeAfkPlayers()) {
return;
}

final User user = ess.getUser(event.getPlayer());
if (user.isAfk() && ess.getSettings().getFreezeAfkPlayers()) {
final Location from = event.getFrom();
final Location origTo = event.getTo();
Expand Down
4 changes: 4 additions & 0 deletions Essentials/src/main/java/com/earth2me/essentials/IUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -336,4 +336,8 @@ public void setTime(long time) {
List<String> getPastUsernames();

void addPastUsername(String username);

boolean isFreeze();

void setFreeze(boolean freeze);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.earth2me.essentials;

import net.ess3.api.IUser;
import net.essentialsx.api.v2.services.mail.MailService;
import net.essentialsx.api.v2.events.UserMailEvent;
import net.essentialsx.api.v2.services.mail.MailMessage;
import net.essentialsx.api.v2.services.mail.MailSender;
import net.essentialsx.api.v2.services.mail.MailService;
import org.bukkit.Bukkit;
import org.bukkit.plugin.ServicePriority;

import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -35,6 +37,12 @@ public void sendLegacyMail(IUser recipient, String message) {
}

private void sendMail(IUser recipient, MailMessage message) {
final UserMailEvent event = new UserMailEvent(recipient, message);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}

final ArrayList<MailMessage> messages = recipient.getMailMessages();
messages.add(0, message);
recipient.setMailList(messages);
Expand Down
11 changes: 11 additions & 0 deletions Essentials/src/main/java/com/earth2me/essentials/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
private String lastHomeConfirmation;
private long lastHomeConfirmationTimestamp;
private Boolean toggleShout;
private boolean freeze = false;
private transient final List<String> signCopy = Lists.newArrayList("", "", "", "");
private transient long lastVanishTime = System.currentTimeMillis();

Expand Down Expand Up @@ -1191,6 +1192,16 @@ public List<String> getSignCopy() {
return signCopy;
}

@Override
public boolean isFreeze() {
return freeze;
}

@Override
public void setFreeze(boolean freeze) {
this.freeze = freeze;
}

public boolean isBaltopExempt() {
if (getBase().isOnline()) {
final boolean exempt = isAuthorized("essentials.balancetop.exclude");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public class Commandessentials extends EssentialsCommand {
"EssentialsAntiBuild",
"EssentialsChat",
"EssentialsDiscord",
"EssentialsDiscordLink",
"EssentialsGeoIP",
"EssentialsProtect",
"EssentialsSpawn",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
import java.math.BigDecimal;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -303,6 +305,19 @@ public Map<String, CommentedConfigurationNode> getMap() {
return ConfigurateUtil.getMap(configurationNode);
}

public Map<String, String> getStringMap(String path) {
final CommentedConfigurationNode node = getInternal(path);
if (node == null || !node.isMap()) {
return Collections.emptyMap();
}

final Map<String, String> map = new LinkedHashMap<>();
for (Map.Entry<Object, CommentedConfigurationNode> entry : node.childrenMap().entrySet()) {
map.put(String.valueOf(entry.getKey()), String.valueOf(entry.getValue().rawScalar()));
}
return map;
}

public void removeProperty(String path) {
final CommentedConfigurationNode node = getInternal(path);
if (node != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@
import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.TriState;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;

import java.util.List;
import java.util.function.Function;
import java.util.function.Supplier;

public interface IPermissionsHandler {
String getGroup(Player base);
boolean addToGroup(OfflinePlayer base, String group);

List<String> getGroups(Player base);
boolean removeFromGroup(OfflinePlayer base, String group);

String getGroup(OfflinePlayer base);

List<String> getGroups(OfflinePlayer base);

List<String> getGroups();

boolean canBuild(Player base, String group);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
import com.earth2me.essentials.perm.impl.SuperpermsHandler;
import com.earth2me.essentials.utils.TriState;
import com.google.common.collect.ImmutableSet;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand All @@ -34,7 +36,7 @@ public PermissionsHandler(final Essentials plugin, final boolean useSuperperms)
}

@Override
public String getGroup(final Player base) {
public String getGroup(final OfflinePlayer base) {
final long start = System.nanoTime();
String group = handler.getGroup(base);
if (group == null) {
Expand All @@ -45,16 +47,42 @@ public String getGroup(final Player base) {
}

@Override
public List<String> getGroups(final Player base) {
public List<String> getGroups(final OfflinePlayer base) {
final long start = System.nanoTime();
List<String> groups = handler.getGroups(base);
final List<String> groups = new ArrayList<>();
groups.add(defaultGroup);
groups.addAll(handler.getGroups(base));
checkPermLag(start, String.format("Getting groups for %s", base.getName()));
return Collections.unmodifiableList(groups);
}

@Override
public List<String> getGroups() {
final long start = System.nanoTime();
List<String> groups = handler.getGroups();
if (groups == null || groups.isEmpty()) {
groups = Collections.singletonList(defaultGroup);
}
checkPermLag(start, String.format("Getting groups for %s", base.getName()));
checkPermLag(start, "Getting all groups");
return Collections.unmodifiableList(groups);
}

@Override
public boolean addToGroup(OfflinePlayer base, String group) {
final long start = System.nanoTime();
final boolean result = handler.addToGroup(base, group);
checkPermLag(start, String.format("Adding group to %s", base.getName()));
return result;
}

@Override
public boolean removeFromGroup(OfflinePlayer base, String group) {
final long start = System.nanoTime();
final boolean result = handler.removeFromGroup(base, group);
checkPermLag(start, String.format("Removing group from %s", base.getName()));
return result;
}

@Override
public boolean canBuild(final Player base, final String group) {
return handler.canBuild(base, group);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.milkbowl.vault.chat.Chat;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
Expand Down Expand Up @@ -32,13 +33,34 @@ private boolean setupProviders() {
}

@Override
public String getGroup(final Player base) {
return perms.getPrimaryGroup(base);
public String getGroup(final OfflinePlayer base) {
if (base.isOnline()) {
return perms.getPrimaryGroup(base.getPlayer());
}
return perms.getPrimaryGroup(null, base);
}

@Override
public List<String> getGroups(final OfflinePlayer base) {
if (base.isOnline()) {
return Arrays.asList(perms.getPlayerGroups(base.getPlayer()));
}
return Arrays.asList(perms.getPlayerGroups(null, base));
}

@Override
public List<String> getGroups() {
return Arrays.asList(perms.getGroups());
}

@Override
public boolean addToGroup(OfflinePlayer base, String group) {
return perms.playerAddGroup(null, base, group);
}

@Override
public List<String> getGroups(final Player base) {
return Arrays.asList(perms.getPlayerGroups(base));
public boolean removeFromGroup(OfflinePlayer base, String group) {
return perms.playerRemoveGroup(null, base, group);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.earth2me.essentials.perm.IPermissionsHandler;
import com.earth2me.essentials.utils.TriState;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionAttachmentInfo;
Expand All @@ -21,12 +22,27 @@ protected boolean emulateWildcards() {
}

@Override
public String getGroup(final Player base) {
public boolean addToGroup(OfflinePlayer base, String group) {
return false;
}

@Override
public boolean removeFromGroup(OfflinePlayer base, String group) {
return false;
}

@Override
public String getGroup(final OfflinePlayer base) {
return null;
}

@Override
public List<String> getGroups(final OfflinePlayer base) {
return null;
}

@Override
public List<String> getGroups(final Player base) {
public List<String> getGroups() {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package net.essentialsx.api.v2.events;

import net.ess3.api.IUser;
import net.essentialsx.api.v2.services.mail.MailMessage;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;

/**
* Called when mail is sent to a {@link net.ess3.api.IUser IUser} by another player or the console.
*/
public class UserMailEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();

private final IUser recipient;
private final MailMessage message;
private boolean canceled;

public UserMailEvent(IUser recipient, MailMessage message) {
this.recipient = recipient;
this.message = message;
}

/**
* Gets the recipient of this mail.
* @return the recipient.
*/
public IUser getRecipient() {
return recipient;
}

/**
* Gets the underlying {@link MailMessage} for this mail.
* @return the message.
*/
public MailMessage getMessage() {
return message;
}

@Override
public void setCancelled(boolean cancel) {
this.canceled = cancel;
}

@Override
public boolean isCancelled() {
return canceled;
}

@Override
public HandlerList getHandlers() {
return handlers;
}

public static HandlerList getHandlerList() {
return handlers;
}
}
Loading