Initial rank rewrite and quest database fixes

This commit is contained in:
AlexTheCoder 2017-08-02 12:44:35 -04:00
parent 2d9da9bc3a
commit ef4aeaaf64
644 changed files with 10723 additions and 12055 deletions

View File

@ -1,166 +0,0 @@
package mineplex.core.common;
import org.bukkit.ChatColor;
import org.bukkit.DyeColor;
import org.bukkit.entity.Player;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayerBase;
public enum Rank
{
//Staff
LT("Leader", "lt", ChatColor.DARK_RED, "Leaders manage the operation of their respective team \nor projects. They usually operate on affairs within \nthe staff, development, or management team.", 11, DyeColor.RED),
OWNER("Owner", "owner", ChatColor.DARK_RED, "Owners are the founders of Mineplex. \nEach owner manages a different aspect of the \nserver and ensures its efficient operation.", 55, DyeColor.RED),
DEVELOPER("Dev", "dev", ChatColor.DARK_RED, "Developers work behind the scenes to \ncreate new games and features, and fix bugs to \ngive the best experience.", 5, DyeColor.RED),
ADMIN("Admin", "adm", ChatColor.DARK_RED, "An Administrators role is to manage \ntheir respective Senior Moderator team \nand all moderators within it.", 10, DyeColor.RED),
JNR_DEV("Jr.Dev", "jrdev", ChatColor.GOLD, "Junior Developers work behind the scenes to \ncreate new games and features, and fix bugs to \ngive the best experience.", -1, DyeColor.ORANGE),
SUPPORT("Support", "spp", ChatColor.BLUE, "Support agents handle tickets and \nprovide customer service.", 47, DyeColor.BLUE),
CMOD("C.Mod", "cmod", ChatColor.GOLD, "Clans Moderators are members of the Clans Management Senior Mod team. \nTheir duties include moderation and support within the Clans servers. \n\nFor assistance, contact them using " + F.elem("/a <message>") + ".", 32, DyeColor.ORANGE),
EVENT_MODERATOR("Sr.Mod", "srmod_event", ChatColor.GOLD, "Senior Moderators are members of a special \nSenior Moderator team where they have to fulfill specific tasks. \nJust like Moderators, you can always ask them for help. \n\nFor assistance, contact them using " + F.elem("/a <message>") + ".", 44, DyeColor.ORANGE),
SNR_MODERATOR("Sr.Mod", "srmod", ChatColor.GOLD, "Senior Moderators are members of a special \nSenior Moderator team where they have to fulfill specific tasks. \nJust like Moderators, you can always ask them for help. \n\nFor assistance, contact them using " + F.elem("/a <message>") + ".", 44, DyeColor.ORANGE),
CMA("Mod", "mod_cma", ChatColor.GOLD, "Moderators enforce rules and provide help to \nanyone with questions or concerns. \n\nFor assistance, contact them using " + F.elem("/a <message>") + ".", 32, DyeColor.ORANGE),
MODERATOR("Mod", "mod", ChatColor.GOLD, "Moderators enforce rules and provide help to \nanyone with questions or concerns. \n\nFor assistance, contact them using " + F.elem("/a <message>") + ".", 32, DyeColor.ORANGE),
HELPER("Trainee", "train", ChatColor.GOLD, "Trainees are moderators-in-training. \nTheir duties include enforcing the rules and \nproviding help to anyone with questions or concerns. \n\nFor assistance, contact them using " + F.elem("/a <message>") + ".", 24, DyeColor.ORANGE),
MAPLEAD("MapLead", "mapl", ChatColor.BLUE, "Map Leaders are leaders of the Mineplex Build Team. \nThey oversee the creation of new maps and manage Builders.", 25, DyeColor.BLUE),
MAPPER("Mapper", "mapp", ChatColor.BLUE, "These senior staff members work closely with \nthe development and design teams to build new \nmaps for new and old content!", 100, DyeColor.BLUE),
MAPDEV("Builder", "mapd", ChatColor.BLUE, "These creative staff members help \nbuild maps for your favorite games!", 26, DyeColor.BLUE),
MEDIA("Media", "media", ChatColor.BLUE, "The Media rank is given to talented artists who are\n endorsed to create content for Mineplex.", -1, DyeColor.BLUE),
EVENT("Event", "evnt", ChatColor.WHITE, "A member of the official Mineplex Events team!", -1, DyeColor.WHITE),
//Media
YOUTUBE("YouTube", "yt", ChatColor.RED, "A YouTuber who creates content for \nor related to Mineplex.", 22, DyeColor.RED),
YOUTUBE_SMALL("YT", "ytsm", ChatColor.DARK_PURPLE, "A YouTuber who creates content for \nor related to Mineplex. \n\nThey have fewer subscribers than full YouTubers.", 20, DyeColor.PURPLE),
TWITCH("Twitch", "tw", ChatColor.DARK_PURPLE, "A Twitch streamer who often features \nMineplex in their streams.", 21, DyeColor.PURPLE),
//Player
ETERNAL("Eternal", "et", ChatColor.DARK_AQUA, true, "Fantastic and magical, no one \nexcept the time lords truly understand \nthe power of this rank.\n\nThe fifth purchasable rank at Mineplex.com/shop", 18, DyeColor.CYAN),
TITAN("Titan", "t", ChatColor.RED, true, "Ancient myths spoke of a gigantic being \nwith immense power... \n\nThe fourth purchasable rank at Mineplex.com/shop", 15, DyeColor.RED),
LEGEND("Legend", "l", ChatColor.GREEN, true, "Years they have told stories of this rank, \nonly for the legends to be true. \n\nThe third purchasable rank at Mineplex.com/shop", 14, DyeColor.GREEN),
HERO("Hero", "h", ChatColor.LIGHT_PURPLE, true, "There are many stories of a \nvaliant Hero who was brave enough to \ntame the most fearsome dragon in the land. \n\nThe second purchasable rank at Mineplex.com/shop", 13, DyeColor.MAGENTA),
ULTRA("Ultra", "u", ChatColor.AQUA, true, "A first step into the stories of the mist. \nOnly those brave enough may enter. \n\nThe first purchasable rank at Mineplex.com/shop", 12, DyeColor.LIGHT_BLUE),
ALL("", "", ChatColor.WHITE, null, -1, DyeColor.WHITE);
private ChatColor _color;
private boolean _donor;
private String _description;
private int _forumId;
private DyeColor _dyeColor;
public String Name;
public String ScoreboardTag;
Rank(String name, String scoreboardTag, ChatColor color, String description, int forumId, DyeColor dyeColor)
{
_color = color;
Name = name;
_donor = false;
_description = description;
ScoreboardTag = scoreboardTag;
_forumId = forumId;
_dyeColor = dyeColor;
}
Rank(String name, String scoreboardTag, ChatColor color, boolean donor, String description, int forumId, DyeColor dyeColor)
{
_color = color;
Name = name;
_donor = donor;
_description = description;
ScoreboardTag = scoreboardTag;
_forumId = forumId;
_dyeColor = dyeColor;
}
public String getDescription()
{
return _description;
}
public void setName(String name)
{
Name = name;
}
public String getRawTag()
{
if (Name.equalsIgnoreCase("ALL"))
return "";
return Name;
}
public boolean has(Rank rank)
{
return has(null, rank, false);
}
public boolean has(Player player, Rank rank, boolean inform)
{
return has(player, rank, null, inform);
}
public boolean has(Player player, Rank rank, Rank[] specific, boolean inform)
{
//Specific Rank
if (specific != null)
{
for (Rank curRank : specific)
{
if (compareTo(curRank) == 0)
{
return true;
}
}
}
//
if (compareTo(rank) <= 0)
return true;
if (inform)
{
UtilPlayerBase.message(player, C.mHead + "Permissions> " +
C.mBody + "This requires Permission Rank [" +
C.mHead + rank.Name.toUpperCase() +
C.mBody + "].");
}
return false;
}
public String getTag(boolean bold, boolean uppercase)
{
if (Name.equalsIgnoreCase("ALL"))
return "";
String name = Name;
if (uppercase)
name = Name.toUpperCase();
if (bold) return _color + C.Bold + name;
else return _color + name;
}
public ChatColor getColor()
{
return _color;
}
public boolean isDonor()
{
return _donor;
}
public int getForumId()
{
return _forumId;
}
public DyeColor getDyeColor()
{
return _dyeColor;
}
}

View File

@ -2,7 +2,6 @@ package mineplex.core.common.util;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import mineplex.core.common.Rank;
import mineplex.core.common.currency.Currency; import mineplex.core.common.currency.Currency;
public class F public class F
@ -103,23 +102,10 @@ public class F
{ {
return C.wFrame + "[" + C.wField + field + C.wFrame + "] " + C.mBody + data + " "; return C.wFrame + "[" + C.wField + field + C.wFrame + "] " + C.mBody + data + " ";
} }
public static String help(String cmd, String body, Rank rank)
{
return rank.getColor() + cmd + " " + C.mBody + body + " " + rank(rank);
}
public static String help(String cmd, String body, Rank rank, ChatColor displayColor) public static String help(String cmd, String body, ChatColor displayColor)
{ {
return displayColor + cmd + " " + C.mBody + body + " " + rank(rank); return displayColor + cmd + " " + C.mBody + body;
}
public static String rank(Rank rank)
{
if (rank == Rank.ALL)
return rank.getColor() + "Player";
return rank.getTag(false, false);
} }
public static String value(String variable, int value) public static String value(String variable, int value)

View File

@ -1,20 +1,21 @@
package mineplex.core; package mineplex.core;
import mineplex.core.account.CoreClient; import java.util.List;
import mineplex.core.account.CoreClientManager; import java.util.concurrent.ThreadLocalRandom;
import mineplex.core.common.Rank; import java.util.function.Predicate;
import mineplex.core.common.util.UtilMath; import java.util.stream.Collectors;
import mineplex.core.incognito.IncognitoManager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.List; import mineplex.core.account.CoreClient;
import java.util.concurrent.ThreadLocalRandom; import mineplex.core.account.CoreClientManager;
import java.util.function.Predicate; import mineplex.core.account.permissions.PermissionGroup;
import java.util.stream.Collectors; import mineplex.core.common.util.UtilMath;
import mineplex.core.incognito.IncognitoManager;
/** /**
* A helper for selecting arbitrary players given a set of conditions * A helper for selecting arbitrary players given a set of conditions
@ -74,13 +75,13 @@ public class PlayerSelector
public static final Predicate<Player> NOT_SPECTATING = player -> player.getGameMode() != GameMode.SPECTATOR; public static final Predicate<Player> NOT_SPECTATING = player -> player.getGameMode() != GameMode.SPECTATOR;
/** /**
* This condition will return true if the player has one of the given ranks * This condition will return true if the player has one of the given ranks as their primary
* *
* @param useDisguisedRank Whether to use the disguised rank of the player should they be disguised * @param useDisguisedRank Whether to use the disguised rank of the player should they be disguised
* @param ranks The ranks to check * @param ranks The ranks to check
* @return The resulting criterion * @return The resulting criterion
*/ */
public static Predicate<Player> hasAnyRank(boolean useDisguisedRank, Rank... ranks) public static Predicate<Player> hasAnyRank(boolean useDisguisedRank, PermissionGroup... groups)
{ {
return player -> return player ->
{ {
@ -90,11 +91,11 @@ public class PlayerSelector
return true; return true;
} }
CoreClient client = coreClientManager.Get(player); CoreClient client = coreClientManager.Get(player);
Rank rank = useDisguisedRank ? client.getRealOrDisguisedRank() : client.GetRank(); PermissionGroup group = useDisguisedRank ? client.getRealOrDisguisedPrimaryGroup() : client.getPrimaryGroup();
for (Rank requiredRank : ranks) for (PermissionGroup requiredGroup : groups)
{ {
if (rank == requiredRank) if (group.getIdentifier().equals(requiredGroup.getIdentifier()))
{ {
return true; return true;
} }
@ -119,4 +120,4 @@ public class PlayerSelector
{ {
return player -> UtilMath.offset(player.getLocation(), center) <= radius; return player -> UtilMath.offset(player.getLocation(), center) <= radius;
} }
} }

View File

@ -1,15 +1,15 @@
package mineplex.core.account; package mineplex.core.account;
import mineplex.core.account.event.OnlineRankUpdateEvent; import java.util.HashSet;
import mineplex.core.common.Rank; import java.util.Set;
import mineplex.core.common.util.C; import java.util.UUID;
import mineplex.core.common.util.UtilPlayer; import java.util.stream.Collectors;
import mineplex.serverdata.Utility;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.UUID; import mineplex.core.Managers;
import mineplex.core.account.permissions.PermissionGroup;
import mineplex.serverdata.Utility;
public class CoreClient public class CoreClient
{ {
@ -18,8 +18,8 @@ public class CoreClient
private String _name; private String _name;
private UUID _uuid; private UUID _uuid;
private Player _player; private Player _player;
private Rank _rank, _lastRank; private PermissionGroup _primary, _lastPrimary;
private Rank _tempRank, _lastTemp; private Set<PermissionGroup> _extra = new HashSet<>();
/* /*
* Disguise info * Disguise info
@ -27,7 +27,7 @@ public class CoreClient
private String _disguisedName; private String _disguisedName;
private String _disguisedSkin; private String _disguisedSkin;
private UUID _disguisedUUID; private UUID _disguisedUUID;
private Rank _disguisedRank; private PermissionGroup _disguisedPrimary;
public CoreClient(Player player) public CoreClient(Player player)
{ {
@ -72,60 +72,73 @@ public class CoreClient
{ {
_accountId = accountId; _accountId = accountId;
} }
public Rank GetRank() protected PermissionGroup getRawPrimaryGroup()
{ {
return GetRank(false); return _primary;
} }
public Rank GetRank(boolean bypass) public PermissionGroup getPrimaryGroup()
{ {
if (_rank == null) if (_primary == null)
_rank = Rank.ALL;
if (bypass || _tempRank == null)
return _rank;
else
return _tempRank;
}
public Rank GetLastRank(boolean temp)
{
if (temp)
{ {
if ((_lastTemp == null) && (_tempRank == null)) _primary = Managers.get(CoreClientManager.class).getPermissionManager().getGroup("player");
{ }
return _rank;
} return _primary;
else if (_lastTemp == null) }
{
return _tempRank; public Set<PermissionGroup> getAdditionalGroups()
} {
return _lastTemp; return _extra;
}
public PermissionGroup getLastPrimaryGroup()
{
if (_lastPrimary == null)
{
return _primary;
}
return _lastPrimary;
}
public boolean isMemberOf(PermissionGroup group)
{
if (_extra.contains(group))
{
return true;
}
return group.equals(_primary);
}
public void setPrimaryGroup(PermissionGroup group)
{
if (_primary != null)
{
_lastPrimary = _primary;
} }
else else
{ {
if (_lastRank == null) return _rank; _lastPrimary = group;
return _lastRank;
} }
_primary = group;
} }
public void SetRank(Rank rank, boolean temp) public void addAdditionalGroup(PermissionGroup group)
{ {
if (temp) if (!isMemberOf(group))
{ {
if (_lastTemp == null) _lastTemp = rank; _extra.add(group);
else _lastTemp = _tempRank;
_lastRank = _rank;
_tempRank = rank;
}
else
{
if (_rank != null) _lastRank = _rank;
else _lastRank = rank;
_rank = rank;
} }
} }
public void removeAdditionalGroup(PermissionGroup group)
{
_extra.remove(group);
}
public long getNetworkSessionLoginTime() public long getNetworkSessionLoginTime()
{ {
@ -136,7 +149,8 @@ public class CoreClient
{ {
_disguisedName = null; _disguisedName = null;
_disguisedSkin = null; _disguisedSkin = null;
_disguisedRank = null; _lastPrimary = _disguisedPrimary;
_disguisedPrimary = null;
_disguisedUUID = null; _disguisedUUID = null;
} }
@ -150,9 +164,9 @@ public class CoreClient
return _disguisedSkin; return _disguisedSkin;
} }
public Rank getDisguisedRank() public PermissionGroup getDisguisedPrimaryGroup()
{ {
return _disguisedRank; return _disguisedPrimary;
} }
public UUID getDisguisedAsUUID() public UUID getDisguisedAsUUID()
@ -169,20 +183,28 @@ public class CoreClient
return !_name.equalsIgnoreCase(_disguisedName); return !_name.equalsIgnoreCase(_disguisedName);
} }
public void disguise(String name, UUID uuid, Rank rank) public void disguise(String name, UUID uuid, PermissionGroup group)
{ {
_disguisedName = name; _disguisedName = name;
_disguisedUUID = uuid; _disguisedUUID = uuid;
_disguisedRank = rank; _disguisedPrimary = group;
if (_primary != null)
{
_lastPrimary = _primary;
}
else
{
_lastPrimary = group;
}
} }
public Rank getRealOrDisguisedRank() public PermissionGroup getRealOrDisguisedPrimaryGroup()
{ {
if (_disguisedRank != null) if (_disguisedPrimary != null)
{ {
return _disguisedRank; return _disguisedPrimary;
} }
return GetRank(); return getPrimaryGroup();
} }
public void setNetworkSessionLoginTime(long loginTime) public void setNetworkSessionLoginTime(long loginTime)
@ -190,22 +212,12 @@ public class CoreClient
_networkSessionLoginTime = loginTime; _networkSessionLoginTime = loginTime;
} }
public void resetTemp()
{
if (_tempRank != null)
{
OnlineRankUpdateEvent event = new OnlineRankUpdateEvent(_player, _tempRank, _rank, true);
Bukkit.getPluginManager().callEvent(event);
_lastTemp = _tempRank;
_tempRank = null;
UtilPlayer.message(_player, C.cGold + "Your test rank has been reset!");
}
}
public String getRealOrDisguisedName() public String getRealOrDisguisedName()
{ {
if (getDisguisedAs() != null) if (getDisguisedAs() != null)
{
return getDisguisedAs(); return getDisguisedAs();
}
return getName(); return getName();
} }
@ -217,7 +229,8 @@ public class CoreClient
", _name='" + _name + '\'' + ", _name='" + _name + '\'' +
", _uuid=" + _uuid + ", _uuid=" + _uuid +
", _player=" + _player + ", _player=" + _player +
", _rank=" + _rank + ", _primary=" + _primary +
", _extra=[" + _extra.stream().map(PermissionGroup::toString).collect(Collectors.joining(", ")) + "]" +
'}'; '}';
} }
} }

View File

@ -8,15 +8,16 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.stream.Collectors;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
@ -33,33 +34,57 @@ import com.google.gson.Gson;
import mineplex.cache.player.PlayerCache; import mineplex.cache.player.PlayerCache;
import mineplex.cache.player.PlayerInfo; import mineplex.cache.player.PlayerInfo;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.account.command.TestRank; import mineplex.core.account.command.RanksCommand;
import mineplex.core.account.command.UpdateRank;
import mineplex.core.account.event.ClientUnloadEvent; import mineplex.core.account.event.ClientUnloadEvent;
import mineplex.core.account.event.ClientWebResponseEvent; import mineplex.core.account.event.ClientWebResponseEvent;
import mineplex.core.account.event.RankSaveEvent; import mineplex.core.account.event.OnlineGroupAddEvent;
import mineplex.core.account.event.OnlineGroupRemoveEvent;
import mineplex.core.account.event.OnlinePrimaryGroupUpdateEvent;
import mineplex.core.account.permissions.GroupPermission;
import mineplex.core.account.permissions.PermissionGroup;
import mineplex.core.account.permissions.PermissionManager;
import mineplex.core.account.redis.AddPermissionGroup;
import mineplex.core.account.redis.AddPermissionGroupHandler;
import mineplex.core.account.redis.ClearGroups;
import mineplex.core.account.redis.ClearGroupsHandler;
import mineplex.core.account.redis.PrimaryGroupUpdate;
import mineplex.core.account.redis.PrimaryGroupUpdateHandler;
import mineplex.core.account.redis.RemovePermissionGroup;
import mineplex.core.account.redis.RemovePermissionGroupHandler;
import mineplex.core.account.repository.AccountRepository; import mineplex.core.account.repository.AccountRepository;
import mineplex.core.account.repository.token.ClientToken; import mineplex.core.account.repository.token.ClientToken;
import mineplex.core.common.Rank; import mineplex.core.common.Pair;
import mineplex.core.common.timing.TimingManager; import mineplex.core.common.timing.TimingManager;
import mineplex.core.common.util.Callback; import mineplex.core.common.util.Callback;
import mineplex.core.common.util.UUIDFetcher; import mineplex.core.common.util.UUIDFetcher;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTasks; import mineplex.core.common.util.UtilTasks;
import mineplex.core.common.util.UtilTime;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.utils.UtilGameProfile; import mineplex.core.utils.UtilGameProfile;
import mineplex.core.utils.UtilScheduler; import mineplex.core.utils.UtilScheduler;
import mineplex.serverdata.commands.ServerCommandManager;
public class CoreClientManager extends MiniPlugin public class CoreClientManager extends MiniPlugin
{ {
public static final String JOIN_FULL_PERMISSION = "mineplex.core.account.joinfull";
public static final String RANK_COMMAND_PERMISSION = "mineplex.core.account.rankcommand";
public static final String ADD_RANK_COMMAND_PERMISSION = "mineplex.core.account.addrank";
public static final String RANK_INFO_COMMAND_PERMISSION = "mineplex.core.account.rankinfo";
public static final String LIST_RANKS_COMMAND_PERMISSION = "mineplex.core.account.listranks";
public static final String REMOVE_RANK_COMMAND_PERMISSION = "mineplex.core.account.removerank";
public static final String RESET_PLAYER_COMMAND_PERMISSION = "mineplex.core.account.resetplayer";
public static final String SET_RANK_COMMAND_PERMISSION = "mineplex.core.account.setrank";
private static final Map<String, Object> CLIENT_LOGIN_LOCKS = new ConcurrentHashMap<>(); private static final Map<String, Object> CLIENT_LOGIN_LOCKS = new ConcurrentHashMap<>();
private JavaPlugin _plugin; private JavaPlugin _plugin;
private AccountRepository _repository; private AccountRepository _repository;
private PermissionManager _perm;
private Map<UUID, CoreClient> _clientList = new HashMap<>(); private Map<UUID, CoreClient> _clientList = new HashMap<>();
private HashSet<UUID> _duplicateLoginGlitchPreventionList = new HashSet<>(); private Set<UUID> _duplicateLoginGlitchPreventionList = new HashSet<>();
private List<ILoginProcessor> _loginProcessors = new ArrayList<>(); private List<ILoginProcessor> _loginProcessors = new ArrayList<>();
@ -68,30 +93,45 @@ public class CoreClientManager extends MiniPlugin
private static AtomicInteger _clientsConnecting = new AtomicInteger(0); private static AtomicInteger _clientsConnecting = new AtomicInteger(0);
private static AtomicInteger _clientsProcessing = new AtomicInteger(0); private static AtomicInteger _clientsProcessing = new AtomicInteger(0);
private final Rank WHITELIST_BYPASS;
private final Set<UUID> _reservedSlots = Sets.newConcurrentHashSet(); private final Set<UUID> _reservedSlots = Sets.newConcurrentHashSet();
public CoreClientManager(JavaPlugin plugin) public CoreClientManager(JavaPlugin plugin)
{
this(plugin, Rank.MODERATOR);
}
public CoreClientManager(JavaPlugin plugin, Rank whitelistBypass)
{ {
super("Client Manager", plugin); super("Client Manager", plugin);
_plugin = plugin; _plugin = plugin;
_repository = new AccountRepository(); _repository = new AccountRepository();
WHITELIST_BYPASS = whitelistBypass; _perm = new PermissionManager(plugin, this);
UtilScheduler.runEvery(UpdateType.TICK, this::checkForIllegalAccounts); UtilScheduler.runEvery(UpdateType.TICK, this::checkForIllegalAccounts);
ServerCommandManager.getInstance().registerCommandType(AddPermissionGroup.class, new AddPermissionGroupHandler(this));
ServerCommandManager.getInstance().registerCommandType(ClearGroups.class, new ClearGroupsHandler(this));
ServerCommandManager.getInstance().registerCommandType(PrimaryGroupUpdate.class, new PrimaryGroupUpdateHandler(this));
ServerCommandManager.getInstance().registerCommandType(RemovePermissionGroup.class, new RemovePermissionGroupHandler(this));
generatePermissions();
}
private void generatePermissions()
{
_perm.setPermission(_perm.getGroup("ultra"), GroupPermission.of(JOIN_FULL_PERMISSION), true, true);
_perm.setPermission(_perm.getGroup("admin"), GroupPermission.of(RANK_COMMAND_PERMISSION), true, true);
_perm.setPermission(_perm.getGroup("admin"), GroupPermission.of(ADD_RANK_COMMAND_PERMISSION), true, true);
_perm.setPermission(_perm.getGroup("admin"), GroupPermission.of(RANK_INFO_COMMAND_PERMISSION), true, true);
_perm.setPermission(_perm.getGroup("admin"), GroupPermission.of(LIST_RANKS_COMMAND_PERMISSION), true, true);
_perm.setPermission(_perm.getGroup("admin"), GroupPermission.of(REMOVE_RANK_COMMAND_PERMISSION), true, true);
_perm.setPermission(_perm.getGroup("admin"), GroupPermission.of(RESET_PLAYER_COMMAND_PERMISSION), true, true);
_perm.setPermission(_perm.getGroup("admin"), GroupPermission.of(SET_RANK_COMMAND_PERMISSION), true, true);
} }
private void checkForIllegalAccounts() { private void checkForIllegalAccounts()
{
// Use getOnlinePlayers because in the future, I might change UtilServer.getPlayers to account for vanish // Use getOnlinePlayers because in the future, I might change UtilServer.getPlayers to account for vanish
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers())
if (Get(player).getAccountId() == -1) { {
if (Get(player).getAccountId() == -1)
{
// ew ew getim outta here // ew ew getim outta here
player.kickPlayer("There was a problem logging you in"); player.kickPlayer("There was a problem logging you in");
} }
@ -102,12 +142,16 @@ public class CoreClientManager extends MiniPlugin
{ {
return _repository; return _repository;
} }
public PermissionManager getPermissionManager()
{
return _perm;
}
@Override @Override
public void addCommands() public void addCommands()
{ {
addCommand(new UpdateRank(this)); addCommand(new RanksCommand(this));
addCommand(new TestRank(this));
} }
public CoreClient Add(String name, UUID uuid) public CoreClient Add(String name, UUID uuid)
@ -209,7 +253,9 @@ public class CoreClientManager extends MiniPlugin
_clientsProcessing.incrementAndGet(); _clientsProcessing.incrementAndGet();
if (!LoadClient(Add(event.getName(), event.getUniqueId()), event.getUniqueId(), event.getAddress().getHostAddress())) if (!LoadClient(Add(event.getName(), event.getUniqueId()), event.getUniqueId(), event.getAddress().getHostAddress()))
{
event.disallow(Result.KICK_OTHER, "There was a problem logging you in."); event.disallow(Result.KICK_OTHER, "There was a problem logging you in.");
}
} }
catch (Exception exception) catch (Exception exception)
{ {
@ -220,19 +266,6 @@ public class CoreClientManager extends MiniPlugin
{ {
_clientsProcessing.decrementAndGet(); _clientsProcessing.decrementAndGet();
} }
if (Bukkit.hasWhitelist() && !Get(event.getUniqueId()).GetRank().has(WHITELIST_BYPASS))
{
for (OfflinePlayer player : Bukkit.getWhitelistedPlayers())
{
if (player.getName().equalsIgnoreCase(event.getName()))
{
return;
}
}
event.disallow(Result.KICK_WHITELIST, "You are not whitelisted my friend.");
}
} }
finally finally
{ {
@ -280,8 +313,23 @@ public class CoreClientManager extends MiniPlugin
} }
CoreClient client = Add(token.Name, uuid); CoreClient client = Add(token.Name, uuid);
client.SetRank(Rank.valueOf(token.Rank), false); Pair<Integer, Pair<String, Set<String>>> result = _repository.login(_loginProcessors, uuid, client.getName());
client.setAccountId(_repository.login(_loginProcessors, uuid, client.getName()));
client.setAccountId(result.getLeft().intValue());
if (result.getRight().getLeft() == null)
{
PermissionGroup newGroup = _perm.getGroupFromLegacy(token.Rank);
client.setPrimaryGroup(newGroup);
_repository.setPrimaryGroup(client.getAccountId(), newGroup.getIdentifier(), null);
}
else
{
client.setPrimaryGroup(_perm.getGroup(result.getRight().getLeft()));
}
for (String id : result.getRight().getRight())
{
client.addAdditionalGroup(_perm.getGroup(id));
}
Bukkit.getServer().getPluginManager().callEvent(new ClientWebResponseEvent(response, uuid)); Bukkit.getServer().getPluginManager().callEvent(new ClientWebResponseEvent(response, uuid));
@ -323,9 +371,7 @@ public class CoreClientManager extends MiniPlugin
if (uuid == null) if (uuid == null)
{ {
uuid = UtilGameProfile.getProfileByName(playerName, false, profile -> uuid = UtilGameProfile.getProfileByName(playerName, false, profile -> {}).get().getId();
{
}).get().getId();
} }
String response = ""; String response = "";
@ -342,8 +388,23 @@ public class CoreClientManager extends MiniPlugin
token = gson.fromJson(response, ClientToken.class); token = gson.fromJson(response, ClientToken.class);
CoreClient client = Add(playerName, uuid); CoreClient client = Add(playerName, uuid);
client.SetRank(Rank.valueOf(token.Rank), false); Pair<Integer, Pair<String, Set<String>>> result = _repository.login(_loginProcessors, uuid, client.getName());
client.setAccountId(_repository.login(_loginProcessors, uuid, client.getName()));
client.setAccountId(result.getLeft().intValue());
if (result.getRight().getLeft() == null)
{
PermissionGroup newGroup = _perm.getGroupFromLegacy(token.Rank);
client.setPrimaryGroup(newGroup);
_repository.setPrimaryGroup(client.getAccountId(), newGroup.getIdentifier(), null);
}
else
{
client.setPrimaryGroup(_perm.getGroup(result.getRight().getLeft()));
}
for (String id : result.getRight().getRight())
{
client.addAdditionalGroup(_perm.getGroup(id));
}
// JSON sql response // JSON sql response
Bukkit.getServer().getPluginManager().callEvent(new ClientWebResponseEvent(response, uuid)); Bukkit.getServer().getPluginManager().callEvent(new ClientWebResponseEvent(response, uuid));
@ -402,8 +463,23 @@ public class CoreClientManager extends MiniPlugin
token = gson.fromJson(response, ClientToken.class); token = gson.fromJson(response, ClientToken.class);
CoreClient client = Add(playerName, uuid); CoreClient client = Add(playerName, uuid);
client.SetRank(Rank.valueOf(token.Rank), false); Pair<Integer, Pair<String, Set<String>>> result = _repository.login(_loginProcessors, uuid, client.getName());
client.setAccountId(_repository.login(_loginProcessors, uuid, client.getName()));
client.setAccountId(result.getLeft().intValue());
if (result.getRight().getLeft() == null)
{
PermissionGroup newGroup = _perm.getGroupFromLegacy(token.Rank);
client.setPrimaryGroup(newGroup);
_repository.setPrimaryGroup(client.getAccountId(), newGroup.getIdentifier(), null);
}
else
{
client.setPrimaryGroup(_perm.getGroup(result.getRight().getLeft()));
}
for (String id : result.getRight().getRight())
{
client.addAdditionalGroup(_perm.getGroup(id));
}
// JSON sql response // JSON sql response
Bukkit.getServer().getPluginManager().callEvent(new ClientWebResponseEvent(response, uuid)); Bukkit.getServer().getPluginManager().callEvent(new ClientWebResponseEvent(response, uuid));
@ -436,25 +512,32 @@ public class CoreClientManager extends MiniPlugin
long timeStart = System.currentTimeMillis(); long timeStart = System.currentTimeMillis();
CLIENT_LOGIN_LOCKS.put(client.getName(), new Object()); CLIENT_LOGIN_LOCKS.put(client.getName(), new Object());
ClientToken token = null;
Gson gson = new Gson(); Gson gson = new Gson();
runAsync(new Runnable() runAsync(() ->
{ {
@Override try
public void run()
{ {
try Pair<Integer, Pair<String, Set<String>>> result = _repository.login(_loginProcessors, uuid, client.getName());
client.setAccountId(result.getLeft().intValue());
if (result.getRight().getLeft() == null)
{ {
client.setAccountId(_repository.login(_loginProcessors, uuid, client.getName())); client.setPrimaryGroup(null);
} }
catch (SQLException e) else
{ {
// TODO Auto-generated catch block client.setPrimaryGroup(_perm.getGroup(result.getRight().getLeft()));
e.printStackTrace(); }
for (String id : result.getRight().getRight())
{
client.addAdditionalGroup(_perm.getGroup(id));
} }
CLIENT_LOGIN_LOCKS.remove(client.getName());
} }
catch (SQLException e)
{
e.printStackTrace();
}
CLIENT_LOGIN_LOCKS.remove(client.getName());
}); });
TimingManager.start(client.getName() + " GetClient."); TimingManager.start(client.getName() + " GetClient.");
@ -462,11 +545,6 @@ public class CoreClientManager extends MiniPlugin
TimingManager.stop(client.getName() + " GetClient."); TimingManager.stop(client.getName() + " GetClient.");
TimingManager.start(client.getName() + " Event."); TimingManager.start(client.getName() + " Event.");
token = gson.fromJson(response, ClientToken.class);
client.SetRank(Rank.valueOf(token.Rank), false);
// _repository.updateMysqlRank(uuid.toString(), token.Rank, token.RankPerm, new Timestamp(Date.parse(token.RankExpire)).toString());
// JSON sql response // JSON sql response
Bukkit.getServer().getPluginManager().callEvent(new ClientWebResponseEvent(response, uuid)); Bukkit.getServer().getPluginManager().callEvent(new ClientWebResponseEvent(response, uuid));
@ -490,6 +568,16 @@ public class CoreClientManager extends MiniPlugin
{ {
System.out.println("MYSQL TOO LONG TO LOGIN...."); System.out.println("MYSQL TOO LONG TO LOGIN....");
} }
ClientToken token = gson.fromJson(response, ClientToken.class);
if (client.getRawPrimaryGroup() == null)
{
String mssqlRank = token.Rank;
PermissionGroup newGroup = _perm.getGroupFromLegacy(mssqlRank);
client.setPrimaryGroup(newGroup);
_repository.setPrimaryGroup(client.getAccountId(), newGroup.getIdentifier(), null);
}
TimingManager.stop(client.getName() + " LoadClient Total."); TimingManager.stop(client.getName() + " LoadClient Total.");
@ -520,7 +608,7 @@ public class CoreClientManager extends MiniPlugin
CoreClient client = Get(event.getPlayer().getUniqueId()); CoreClient client = Get(event.getPlayer().getUniqueId());
if (client == null || client.GetRank() == null) if (client == null || client.getRawPrimaryGroup() == null)
{ {
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "There was an error logging you in. Please reconnect."); event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "There was an error logging you in. Please reconnect.");
return; return;
@ -533,7 +621,7 @@ public class CoreClientManager extends MiniPlugin
// Reserved Slot Check // Reserved Slot Check
if (Bukkit.getOnlinePlayers().size() + _reservedSlots.size() >= Bukkit.getServer().getMaxPlayers()) if (Bukkit.getOnlinePlayers().size() + _reservedSlots.size() >= Bukkit.getServer().getMaxPlayers())
{ {
if (client.GetRank().has(event.getPlayer(), Rank.ULTRA, false)) if (_perm.hasPermission(client, GroupPermission.of(JOIN_FULL_PERMISSION)))
{ {
event.allow(); event.allow();
event.setResult(PlayerLoginEvent.Result.ALLOWED); event.setResult(PlayerLoginEvent.Result.ALLOWED);
@ -546,7 +634,7 @@ public class CoreClientManager extends MiniPlugin
public void reserveFor(UUID player) public void reserveFor(UUID player)
{ {
this._reservedSlots.add(player); _reservedSlots.add(player);
} }
public void unreserve(UUID uuid) public void unreserve(UUID uuid)
@ -560,14 +648,14 @@ public class CoreClientManager extends MiniPlugin
if (event.getReason().contains("You logged in from another location")) if (event.getReason().contains("You logged in from another location"))
{ {
_duplicateLoginGlitchPreventionList.add(event.getPlayer().getUniqueId()); _duplicateLoginGlitchPreventionList.add(event.getPlayer().getUniqueId());
Bukkit.getScheduler().runTask(_plugin, new Runnable() Bukkit.getScheduler().runTask(_plugin, () ->
{ {
public void run() if (!_clientList.containsKey(event.getPlayer().getUniqueId()))
{ {
if (!_clientList.containsKey(event.getPlayer().getUniqueId())) return; return;
Player p = _clientList.get(event.getPlayer().getUniqueId()).GetPlayer();
p.kickPlayer("You're already logged in.");
} }
Player p = _clientList.get(event.getPlayer().getUniqueId()).GetPlayer();
p.kickPlayer("You're already logged in.");
}); });
} }
} }
@ -589,108 +677,232 @@ public class CoreClientManager extends MiniPlugin
_duplicateLoginGlitchPreventionList.remove(event.getPlayer().getUniqueId()); _duplicateLoginGlitchPreventionList.remove(event.getPlayer().getUniqueId());
} }
} }
public void SaveRank(final String name, final UUID uuid, Rank rank, boolean perm) public void setPrimaryGroup(Player player, final PermissionGroup group, Runnable after)
{ {
_repository.saveRank(new Callback<Rank>() setPrimaryGroup(Get(player).getAccountId(), group, () ->
{ {
public void run(Rank newRank) PermissionGroup old = Get(player).getPrimaryGroup();
Get(player).setPrimaryGroup(group);
UtilServer.CallEvent(new OnlinePrimaryGroupUpdateEvent(player, old, group));
if (after != null)
{ {
if (_plugin.getServer().getPlayer(name) != null) after.run();
{
CoreClient client = Get(name);
client.SetRank(newRank, false);
}
UtilServer.CallEvent(new RankSaveEvent(uuid, newRank));
} }
}, name, uuid, rank, perm); });
} }
public void SaveRank(final Callback<Rank> callback, final String name, final UUID uuid, Rank rank, boolean perm) public void setPrimaryGroup(final int accountId, final PermissionGroup group, Runnable after)
{ {
_repository.saveRank(new Callback<Rank>() _repository.setPrimaryGroup(accountId, group.getIdentifier(), after);
}
public void addAdditionalGroup(Player player, final PermissionGroup group, Consumer<Boolean> successCallback)
{
addAdditionalGroup(Get(player).getAccountId(), group, success ->
{ {
public void run(Rank newRank) if (success.booleanValue())
{ {
if (_plugin.getServer().getPlayer(name) != null) Get(player).addAdditionalGroup(group);
{ UtilServer.CallEvent(new OnlineGroupAddEvent(player, group));
CoreClient client = Get(name);
client.SetRank(newRank, false);
}
if (callback != null)
callback.run(newRank);
UtilServer.CallEvent(new RankSaveEvent(uuid, newRank));
} }
}, name, uuid, rank, perm); if (successCallback != null)
{
successCallback.accept(success);
}
});
}
public void addAdditionalGroup(final int accountId, final PermissionGroup group, Consumer<Boolean> successCallback)
{
_repository.addAdditionalGroup(accountId, group.getIdentifier(), success ->
{
if (successCallback != null)
{
successCallback.accept(success);
}
if (!success.booleanValue())
{
System.out.println("Error adding additional group " + group.getIdentifier() + " to account " + accountId + "!");
}
});
}
public void removeAdditionalGroup(Player player, final PermissionGroup group, Consumer<Boolean> successCallback)
{
removeAdditionalGroup(Get(player).getAccountId(), group, success ->
{
if (success.booleanValue())
{
Get(player).removeAdditionalGroup(group);
UtilServer.CallEvent(new OnlineGroupRemoveEvent(player, group));
}
if (successCallback != null)
{
successCallback.accept(success);
}
});
}
public void removeAdditionalGroup(final int accountId, final PermissionGroup group, Consumer<Boolean> successCallback)
{
_repository.removeAdditionalGroup(accountId, group.getIdentifier(), success ->
{
if (successCallback != null)
{
successCallback.accept(success);
}
if (!success.booleanValue())
{
System.out.println("Error removing additional group " + group.getIdentifier() + " from account " + accountId + "!");
}
});
}
public void clearGroups(Player player, Consumer<Boolean> successCallback)
{
clearGroups(Get(player).getAccountId(), success ->
{
if (success.booleanValue())
{
PermissionGroup old = Get(player).getPrimaryGroup();
Set<PermissionGroup> cleared = Sets.newHashSet(Get(player).getAdditionalGroups());
Get(player).setPrimaryGroup(_perm.getGroup("player"));
Get(player).getAdditionalGroups().clear();
UtilServer.CallEvent(new OnlinePrimaryGroupUpdateEvent(player, old, _perm.getGroup("player")));
for (PermissionGroup clr : cleared)
{
UtilServer.CallEvent(new OnlineGroupRemoveEvent(player, clr));
}
}
if (successCallback != null)
{
successCallback.accept(success);
}
});
}
public void clearGroups(final int accountId, Consumer<Boolean> successCallback)
{
_repository.clearGroups(accountId, success ->
{
if (successCallback != null)
{
successCallback.accept(success);
}
if (!success.booleanValue())
{
System.out.println("Error clearing groups from account " + accountId + "!");
}
});
}
public void fetchGroups(final int accountId, Consumer<Pair<PermissionGroup, Set<PermissionGroup>>> resultCallback, Runnable onError)
{
_repository.fetchGroups(accountId, pair ->
{
AtomicReference<PermissionGroup> primaryReference = new AtomicReference<>();
UUID uuid;
if (pair.getLeft() == null && (uuid = _repository.getClientUUID(accountId)) != null)
{
runAsync(() ->
{
String legacy = loadOfflineClient(uuid).Rank;
PermissionGroup defaultGroup = _perm.getGroup("player");
PermissionGroup loaded = _perm.getGroupFromLegacy(legacy);
if (loaded == null)
{
primaryReference.compareAndSet(null, defaultGroup);
}
else
{
primaryReference.compareAndSet(null, loaded);
}
});
long start = System.currentTimeMillis();
while (primaryReference.get() == null && !UtilTime.elapsed(start, 5000)) {}
primaryReference.compareAndSet(null, _perm.getGroup("player"));
}
else
{
PermissionGroup defaultGroup = _perm.getGroup("player");
PermissionGroup loaded = _perm.getGroup(pair.getLeft());
if (loaded == null)
{
primaryReference.set(defaultGroup);
}
else
{
primaryReference.set(loaded);
}
}
final Set<PermissionGroup> additional = pair.getRight().stream().map(_perm::getGroup).filter(Objects::nonNull).collect(Collectors.toSet());
UtilServer.runSync(() -> resultCallback.accept(Pair.create(primaryReference.get(), additional)));
}, () ->
{
if (onError != null)
{
onError.run();
}
System.out.println("Error fetching groups of account " + accountId + "!");
});
} }
public void checkPlayerNameExact(final Callback<Boolean> callback, final String playerName) public void checkPlayerNameExact(final Callback<Boolean> callback, final String playerName)
{ {
_repository.matchPlayerName(new Callback<List<String>>() _repository.matchPlayerName(matches ->
{ {
public void run(List<String> matches) for (String match : matches)
{ {
for (String match : matches) if (match.equalsIgnoreCase(playerName))
{ {
if (match.equalsIgnoreCase(playerName)) callback.run(true);
{
callback.run(true);
}
} }
callback.run(false);
} }
callback.run(false);
}, playerName); }, playerName);
} }
public void checkPlayerName(final Player caller, final String playerName, final Callback<String> callback) public void checkPlayerName(final Player caller, final String playerName, final Callback<String> callback)
{ {
_repository.matchPlayerName(new Callback<List<String>>() _repository.matchPlayerName(matches ->
{ {
public void run(List<String> matches) String tempName = null;
for (String match : matches)
{ {
String tempName = null; if (match.equalsIgnoreCase(playerName))
for (String match : matches)
{ {
if (match.equalsIgnoreCase(playerName)) tempName = match;
{ break;
tempName = match;
break;
}
} }
final String matchedName = tempName;
if (matchedName != null)
{
for (Iterator<String> matchIterator = matches.iterator(); matchIterator.hasNext(); )
{
if (!matchIterator.next().equalsIgnoreCase(playerName))
{
matchIterator.remove();
}
}
}
UtilPlayer.searchOffline(matches, new Callback<String>()
{
public void run(final String target)
{
if (target == null)
{
callback.run(matchedName);
return;
}
callback.run(matchedName);
}
}, caller, playerName, true);
} }
final String matchedName = tempName;
if (matchedName != null)
{
for (Iterator<String> matchIterator = matches.iterator(); matchIterator.hasNext(); )
{
if (!matchIterator.next().equalsIgnoreCase(playerName))
{
matchIterator.remove();
}
}
}
UtilPlayer.searchOffline(matches, target ->
{
if (target == null)
{
callback.run(matchedName);
return;
}
callback.run(matchedName);
}, caller, playerName, true);
}, playerName); }, playerName);
} }
@ -726,29 +938,8 @@ public class CoreClientManager extends MiniPlugin
} }
} }
@EventHandler
public void debug(UpdateEvent event)
{
if (event.getType() != UpdateType.SLOWER)
return;
// System.out.println("=====");
// System.out.println("Connecting : " + _clientsConnecting.get());
// System.out.println("Processing : " + _clientsProcessing.get());
// System.out.println("=====");
}
public void addStoredProcedureLoginProcessor(ILoginProcessor processor) public void addStoredProcedureLoginProcessor(ILoginProcessor processor)
{ {
_loginProcessors.add(processor); _loginProcessors.add(processor);
} }
}
public boolean hasRank(Player player, Rank rank)
{
CoreClient client = Get(player);
if (client == null)
return false;
return client.GetRank().has(rank);
}
}

View File

@ -0,0 +1,99 @@
package mineplex.core.account.command;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClient;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.event.OnlineGroupAddEvent;
import mineplex.core.account.permissions.PermissionGroup;
import mineplex.core.command.CommandBase;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
public class AddRankCommand extends CommandBase<CoreClientManager>
{
public AddRankCommand(CoreClientManager plugin)
{
super(plugin, CoreClientManager.ADD_RANK_COMMAND_PERMISSION, "add");
}
@Override
public void Execute(Player caller, String[] args)
{
if (args.length < 2)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "Usage: /rank " + _aliasUsed + " <Player> <Rank>"));
return;
}
final String target = args[0];
final PermissionGroup group = Plugin.getPermissionManager().getGroup(args[1]);
if (group == null)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "Rank " + F.elem(args[1]) + " does not exist!"));
return;
}
Plugin.runAsync(() ->
{
UUID uuid = Plugin.loadUUIDFromDB(target);
Plugin.runSync(() ->
{
if (uuid == null)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), F.elem(target) + " was not found!"));
}
else
{
if (Bukkit.getPlayer(uuid) != null)
{
final CoreClient client = Plugin.Get(uuid);
Plugin.addAdditionalGroup(client.getAccountId(), group, success ->
{
if (success.booleanValue())
{
client.addAdditionalGroup(group);
UtilServer.CallEvent(new OnlineGroupAddEvent(Bukkit.getPlayer(uuid), group));
UtilPlayer.message(Bukkit.getPlayer(uuid), F.main(Plugin.getName(), "You have gained sub-rank " + F.elem(group.getIdentifier()) + "!"));
UtilPlayer.message(caller, F.main(Plugin.getName(), "You have added sub-rank " + F.elem(group.getIdentifier()) + " to " + F.elem(target) + "!"));
}
else
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "An error occurred while adding sub-rank " + F.elem(group.getIdentifier()) + " to " + F.elem(target) + "! They may already have it."));
}
});
}
else
{
Plugin.loadAccountIdFromUUID(uuid, id ->
{
Plugin.runSync(() ->
{
if (id.intValue() == -1)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), F.elem(target) + " was not found!"));
}
else
{
Plugin.addAdditionalGroup(id.intValue(), group, success ->
{
if (success.booleanValue())
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "You have added sub-rank " + F.elem(group.getIdentifier()) + " to " + F.elem(target) + "!"));
}
else
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "An error occurred while adding sub-rank " + F.elem(group.getIdentifier()) + " to " + F.elem(target) + "! They may already have it."));
}
});
}
});
});
}
}
});
});
}
}

View File

@ -0,0 +1,93 @@
package mineplex.core.account.command;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClient;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.permissions.PermissionGroup;
import mineplex.core.command.CommandBase;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
public class InfoPlayerCommand extends CommandBase<CoreClientManager>
{
public InfoPlayerCommand(CoreClientManager plugin)
{
super(plugin, CoreClientManager.RANK_INFO_COMMAND_PERMISSION, "info");
}
@Override
public void Execute(Player caller, String[] args)
{
if (args.length < 1)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "Usage: /rank " + _aliasUsed + " <Player>"));
return;
}
final String target = args[0];
Plugin.runAsync(() ->
{
UUID uuid = Plugin.loadUUIDFromDB(target);
Plugin.runSync(() ->
{
if (uuid == null)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), F.elem(target) + " was not found!"));
}
else
{
if (Bukkit.getPlayer(uuid) != null)
{
final CoreClient client = Plugin.Get(uuid);
Plugin.fetchGroups(client.getAccountId(), pair ->
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "Rank Information of " + target + ":"));
UtilPlayer.message(caller, C.cBlue + "Primary: " + pair.getLeft().getIdentifier());
UtilPlayer.message(caller, C.cBlue + "Additional (" + pair.getRight().size() + "):");
for (PermissionGroup group : pair.getRight())
{
UtilPlayer.message(caller, C.cBlue + "- " + C.cGray + group.getIdentifier());
}
}, () ->
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "An error occurred while listing " + F.elem(target) + "'s ranks!"));
});
}
else
{
Plugin.loadAccountIdFromUUID(uuid, id ->
{
Plugin.runSync(() ->
{
if (id.intValue() == -1)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), F.elem(target) + " was not found!"));
}
else
{
Plugin.fetchGroups(id.intValue(), pair ->
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "Rank Information of " + target + ":"));
UtilPlayer.message(caller, C.cBlue + "Primary: " + pair.getLeft().getIdentifier());
UtilPlayer.message(caller, C.cBlue + "Additional (" + pair.getRight().size() + "):");
for (PermissionGroup group : pair.getRight())
{
UtilPlayer.message(caller, C.cBlue + "- " + C.cGray + group.getIdentifier());
}
}, () ->
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "An error occurred while listing " + F.elem(target) + "'s ranks!"));
});
}
});
});
}
}
});
});
}
}

View File

@ -0,0 +1,28 @@
package mineplex.core.account.command;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.permissions.PermissionGroup;
import mineplex.core.command.CommandBase;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
public class ListRanksCommand extends CommandBase<CoreClientManager>
{
public ListRanksCommand(CoreClientManager plugin)
{
super(plugin, CoreClientManager.LIST_RANKS_COMMAND_PERMISSION, "list");
}
@Override
public void Execute(Player caller, String[] args)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "Available Ranks:"));
for (PermissionGroup group : Plugin.getPermissionManager().getGroups())
{
UtilPlayer.message(caller, C.cBlue + "- " + C.cGray + group.getIdentifier());
}
}
}

View File

@ -0,0 +1,35 @@
package mineplex.core.account.command;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager;
import mineplex.core.command.MultiCommandBase;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
public class RanksCommand extends MultiCommandBase<CoreClientManager>
{
public RanksCommand(CoreClientManager plugin)
{
super(plugin, CoreClientManager.RANK_COMMAND_PERMISSION, "rank", "ranks", "permissions");
AddCommand(new AddRankCommand(plugin));
AddCommand(new InfoPlayerCommand(plugin));
AddCommand(new ListRanksCommand(plugin));
AddCommand(new RemoveRankCommand(plugin));
AddCommand(new ResetPlayerCommand(plugin));
AddCommand(new SetRankCommand(plugin));
}
@Override
protected void Help(Player caller, String[] args)
{
UtilPlayer.message(caller, F.help("/" + _aliasUsed + " clear <Player>", "Resets a player's ranks to default", ChatColor.DARK_RED));
UtilPlayer.message(caller, F.help("/" + _aliasUsed + " set <Player> <Rank>", "Sets a player's primary rank", ChatColor.DARK_RED));
UtilPlayer.message(caller, F.help("/" + _aliasUsed + " add <Player> <Rank>", "Adds a sub-rank to a player", ChatColor.DARK_RED));
UtilPlayer.message(caller, F.help("/" + _aliasUsed + " remove <Player> <Rank>", "Removes a sub-rank from a player", ChatColor.DARK_RED));
UtilPlayer.message(caller, F.help("/" + _aliasUsed + " list", "Lists all existing ranks", ChatColor.DARK_RED));
UtilPlayer.message(caller, F.help("/" + _aliasUsed + " info <Player>", "Displays a player's rank information", ChatColor.DARK_RED));
}
}

View File

@ -0,0 +1,99 @@
package mineplex.core.account.command;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClient;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.event.OnlineGroupRemoveEvent;
import mineplex.core.account.permissions.PermissionGroup;
import mineplex.core.command.CommandBase;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
public class RemoveRankCommand extends CommandBase<CoreClientManager>
{
public RemoveRankCommand(CoreClientManager plugin)
{
super(plugin, CoreClientManager.REMOVE_RANK_COMMAND_PERMISSION, "remove");
}
@Override
public void Execute(Player caller, String[] args)
{
if (args.length < 2)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "Usage: /rank " + _aliasUsed + " <Player> <Rank>"));
return;
}
final String target = args[0];
final PermissionGroup group = Plugin.getPermissionManager().getGroup(args[1]);
if (group == null)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "Rank " + F.elem(args[1]) + " does not exist!"));
return;
}
Plugin.runAsync(() ->
{
UUID uuid = Plugin.loadUUIDFromDB(target);
Plugin.runSync(() ->
{
if (uuid == null)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), F.elem(target) + " was not found!"));
}
else
{
if (Bukkit.getPlayer(uuid) != null)
{
final CoreClient client = Plugin.Get(uuid);
Plugin.removeAdditionalGroup(client.getAccountId(), group, success ->
{
if (success.booleanValue())
{
client.removeAdditionalGroup(group);
UtilServer.CallEvent(new OnlineGroupRemoveEvent(Bukkit.getPlayer(uuid), group));
UtilPlayer.message(Bukkit.getPlayer(uuid), F.main(Plugin.getName(), "You have lost sub-rank " + F.elem(group.getIdentifier()) + "!"));
UtilPlayer.message(caller, F.main(Plugin.getName(), "You have removed sub-rank " + F.elem(group.getIdentifier()) + " from " + F.elem(target) + "!"));
}
else
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "An error occurred while removing sub-rank " + F.elem(group.getIdentifier()) + " from " + F.elem(target) + "! They may not have it."));
}
});
}
else
{
Plugin.loadAccountIdFromUUID(uuid, id ->
{
Plugin.runSync(() ->
{
if (id.intValue() == -1)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), F.elem(target) + " was not found!"));
}
else
{
Plugin.removeAdditionalGroup(id.intValue(), group, success ->
{
if (success.booleanValue())
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "You have removed sub-rank " + F.elem(group.getIdentifier()) + " from " + F.elem(target) + "!"));
}
else
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "An error occurred while removing sub-rank " + F.elem(group.getIdentifier()) + " from " + F.elem(target) + "! They may not have it."));
}
});
}
});
});
}
}
});
});
}
}

View File

@ -0,0 +1,104 @@
package mineplex.core.account.command;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.google.common.collect.Sets;
import mineplex.core.account.CoreClient;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.event.OnlineGroupRemoveEvent;
import mineplex.core.account.event.OnlinePrimaryGroupUpdateEvent;
import mineplex.core.account.permissions.PermissionGroup;
import mineplex.core.command.CommandBase;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
public class ResetPlayerCommand extends CommandBase<CoreClientManager>
{
public ResetPlayerCommand(CoreClientManager plugin)
{
super(plugin, CoreClientManager.RESET_PLAYER_COMMAND_PERMISSION, "clear");
}
@Override
public void Execute(Player caller, String[] args)
{
if (args.length < 1)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "Usage: /rank " + _aliasUsed + " <Player>"));
return;
}
final String target = args[0];
Plugin.runAsync(() ->
{
UUID uuid = Plugin.loadUUIDFromDB(target);
Plugin.runSync(() ->
{
if (uuid == null)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), F.elem(target) + " was not found!"));
}
else
{
if (Bukkit.getPlayer(uuid) != null)
{
final CoreClient client = Plugin.Get(uuid);
Plugin.clearGroups(client.getAccountId(), success ->
{
if (success.booleanValue())
{
PermissionGroup old = client.getPrimaryGroup();
client.setPrimaryGroup(Plugin.getPermissionManager().getGroup("player"));
Set<PermissionGroup> cleared = Sets.newHashSet(client.getAdditionalGroups());
client.getAdditionalGroups().clear();
UtilServer.CallEvent(new OnlinePrimaryGroupUpdateEvent(Bukkit.getPlayer(uuid), old, client.getPrimaryGroup()));
for (PermissionGroup clr : cleared)
{
UtilServer.CallEvent(new OnlineGroupRemoveEvent(Bukkit.getPlayer(uuid), clr));
}
UtilPlayer.message(Bukkit.getPlayer(uuid), F.main(Plugin.getName(), "Your ranks have been cleared!"));
UtilPlayer.message(caller, F.main(Plugin.getName(), "You have cleared " + F.elem(target + "'s") + " ranks!"));
}
else
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "An error occurred while clearing " + F.elem(target) + "'s ranks!"));
}
});
}
else
{
Plugin.loadAccountIdFromUUID(uuid, id ->
{
Plugin.runSync(() ->
{
if (id.intValue() == -1)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), F.elem(target) + " was not found!"));
}
else
{
Plugin.clearGroups(id.intValue(), success ->
{
if (success.booleanValue())
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "You have cleared " + F.elem(target + "'s") + " ranks!"));
}
else
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "An error occurred while clearing " + F.elem(target) + "'s ranks!"));
}
});
}
});
});
}
}
});
});
}
}

View File

@ -0,0 +1,91 @@
package mineplex.core.account.command;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClient;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.event.OnlinePrimaryGroupUpdateEvent;
import mineplex.core.account.permissions.PermissionGroup;
import mineplex.core.command.CommandBase;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
public class SetRankCommand extends CommandBase<CoreClientManager>
{
public SetRankCommand(CoreClientManager plugin)
{
super(plugin, CoreClientManager.SET_RANK_COMMAND_PERMISSION, "set");
}
@Override
public void Execute(Player caller, String[] args)
{
if (args.length < 2)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "Usage: /rank " + _aliasUsed + " <Player> <Rank>"));
return;
}
final String target = args[0];
final PermissionGroup group = Plugin.getPermissionManager().getGroup(args[1]);
if (group == null)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "Rank " + F.elem(args[1]) + " does not exist!"));
return;
}
if (!group.canBePrimary())
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "That rank cannot be primary!"));
return;
}
Plugin.runAsync(() ->
{
UUID uuid = Plugin.loadUUIDFromDB(target);
Plugin.runSync(() ->
{
if (uuid == null)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), F.elem(target) + " was not found!"));
}
else
{
if (Bukkit.getPlayer(uuid) != null)
{
final CoreClient client = Plugin.Get(uuid);
Plugin.setPrimaryGroup(client.getAccountId(), group, () ->
{
PermissionGroup old = client.getPrimaryGroup();
client.setPrimaryGroup(group);
UtilServer.CallEvent(new OnlinePrimaryGroupUpdateEvent(Bukkit.getPlayer(uuid), old, client.getPrimaryGroup()));
UtilPlayer.message(Bukkit.getPlayer(uuid), F.main(Plugin.getName(), "Your rank has been updated to " + F.elem(group.getIdentifier()) + "!"));
UtilPlayer.message(caller, F.main(Plugin.getName(), "You have updated " + F.elem(target + "'s") + " rank to " + F.elem(group.getIdentifier()) + "!"));
});
}
else
{
Plugin.loadAccountIdFromUUID(uuid, id ->
{
Plugin.runSync(() ->
{
if (id.intValue() == -1)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), F.elem(target) + " was not found!"));
}
else
{
Plugin.setPrimaryGroup(id.intValue(), group, () ->
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "You have updated " + F.elem(target + "'s") + " rank to " + F.elem(group.getIdentifier()) + "!"));
});
}
});
});
}
}
});
});
}
}

View File

@ -1,84 +0,0 @@
package mineplex.core.account.command;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.event.OnlineRankUpdateEvent;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
public class TestRank extends CommandBase<CoreClientManager>
{
public TestRank(CoreClientManager plugin)
{
super(plugin, Rank.ALL, "testRank");
}
@Override
public void Execute(final Player caller, String[] args)
{
if (!Plugin.Get(caller).GetRank(true).has(Rank.SNR_MODERATOR))
{
UtilPlayer.message(caller, F.main("Permissions", "This requires Permission Rank [" + Rank.SNR_MODERATOR.getTag(false, true) + C.cGray + "]."));
return;
}
if (!UtilServer.isTestServer())
{
UtilPlayer.message(caller, F.main(Plugin.getName(), F.elem("This command can only be used on test servers!")));
return;
}
if (args == null)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "/" + _aliasUsed + " MODERATOR"));
}
else
{
if (args.length == 0)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "Rank argument missing."));
return;
}
if (args[0].equalsIgnoreCase("RESET"))
{
Plugin.Get(caller).resetTemp();
}
else
{
Rank tempRank = null;
try
{
tempRank = Rank.valueOf(args[0].toUpperCase());
}
catch (Exception ex)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), ChatColor.RED + "" + ChatColor.BOLD + "Invalid rank!"));
return;
}
if (!Plugin.Get(caller).GetRank(true).has(Rank.JNR_DEV))
{
if (tempRank.has(Rank.TWITCH))
{
UtilPlayer.message(caller, F.main("Command", "You can only test Player ranks!"));
return;
}
}
Plugin.Get(caller).SetRank(tempRank, true);
UtilPlayer.message(caller, F.main(Plugin.getName(), "Your rank has been set to " + tempRank.getTag(false, false) + C.cGray + "!"));
UtilPlayer.message(caller, F.main("NOTICE", "This is only to be used for testing purposes. Misuse of this command will result in a demotion."));
OnlineRankUpdateEvent event = new OnlineRankUpdateEvent(caller, Plugin.Get(caller).GetRank(true), Plugin.Get(caller).GetRank(), true);
Bukkit.getPluginManager().callEvent(event);
}
}
}
}

View File

@ -1,130 +0,0 @@
package mineplex.core.account.command;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.event.OnlineRankUpdateEvent;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UUIDFetcher;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.serverdata.commands.UpdateRankCommand;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
public class UpdateRank extends CommandBase<CoreClientManager>
{
public UpdateRank(CoreClientManager plugin)
{
super(plugin, Rank.ADMIN, "updateRank");
}
@Override
public void Execute(final Player caller, String[] args)
{
if (args == null)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "/" + _aliasUsed + " joeschmo MODERATOR"));
}
else
{
if (args.length == 0)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "Player argument missing."));
return;
}
final String playerName = args[0];
Rank tempRank = null;
try
{
tempRank = Rank.valueOf(args[1]);
}
catch (Exception ex)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), ChatColor.RED + "" + ChatColor.BOLD + "Invalid rank!"));
return;
}
final Rank rank = tempRank;
Plugin.runAsync(() ->
{
new UpdateRankCommand(caller.getName(), caller.getUniqueId().toString(), playerName, rank.name()).publish();
});
Plugin.getRepository().matchPlayerName(new Callback<List<String>>()
{
public void run(List<String> matches)
{
boolean matchedExact = false;
for (String match : matches)
{
if (match.equalsIgnoreCase(playerName))
{
matchedExact = true;
}
}
if (matchedExact)
{
for (Iterator<String> matchIterator = matches.iterator(); matchIterator.hasNext();)
{
if (!matchIterator.next().equalsIgnoreCase(playerName))
{
matchIterator.remove();
}
}
}
if (UtilPlayer.isOnline(playerName))
{
Player p = UtilServer.getServer().getPlayer(playerName);
if (Plugin.Get(p).GetRank() != Plugin.Get(p).GetRank(true))
Plugin.Get(p).resetTemp();
OnlineRankUpdateEvent event = new OnlineRankUpdateEvent(caller, Plugin.Get(caller).GetRank(), rank, false);
Plugin.Get(p).SetRank(rank, false);
Bukkit.getPluginManager().callEvent(event);
UtilPlayer.message(p, F.main(Plugin.getName(), "Your rank has been updated to " + rank.Name + "!"));
}
UtilPlayer.searchOffline(matches, new Callback<String>()
{
public void run(final String target)
{
if (target == null)
{
return;
}
UUID uuid = Plugin.loadUUIDFromDB(playerName);
if (uuid == null)
uuid = UUIDFetcher.getUUIDOf(playerName);
Plugin.getRepository().saveRank(new Callback<Rank>()
{
public void run(Rank rank)
{
caller.sendMessage(F.main(Plugin.getName(), target + "'s rank has been updated to " + rank.Name + "!"));
}
}, target, uuid, rank, true);
}
}, caller, playerName, true);
}
}, playerName);
}
}
}

View File

@ -0,0 +1,38 @@
package mineplex.core.account.event;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class GroupAddEvent extends Event
{
private static final HandlerList handlers = new HandlerList();
private int _accountId;
private String _groupIdentifier;
public GroupAddEvent(int accountId, String groupIdentifier)
{
_accountId = accountId;
_groupIdentifier = groupIdentifier;
}
public int getAccountId()
{
return _accountId;
}
public String getGroupIdentifier()
{
return _groupIdentifier;
}
public HandlerList getHandlers()
{
return handlers;
}
public static HandlerList getHandlerList()
{
return handlers;
}
}

View File

@ -0,0 +1,38 @@
package mineplex.core.account.event;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class GroupRemoveEvent extends Event
{
private static final HandlerList handlers = new HandlerList();
private int _accountId;
private String _groupIdentifier;
public GroupRemoveEvent(int accountId, String groupIdentifier)
{
_accountId = accountId;
_groupIdentifier = groupIdentifier;
}
public int getAccountId()
{
return _accountId;
}
public String getGroupIdentifier()
{
return _groupIdentifier;
}
public HandlerList getHandlers()
{
return handlers;
}
public static HandlerList getHandlerList()
{
return handlers;
}
}

View File

@ -0,0 +1,41 @@
package mineplex.core.account.event;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import mineplex.core.account.permissions.PermissionGroup;
public class OnlineGroupAddEvent extends Event
{
private static final HandlerList handlers = new HandlerList();
private Player _player;
private PermissionGroup _group;
public OnlineGroupAddEvent(Player player, PermissionGroup group)
{
_player = player;
_group = group;
}
public Player getPlayer()
{
return _player;
}
public PermissionGroup getGroup()
{
return _group;
}
public HandlerList getHandlers()
{
return handlers;
}
public static HandlerList getHandlerList()
{
return handlers;
}
}

View File

@ -0,0 +1,41 @@
package mineplex.core.account.event;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import mineplex.core.account.permissions.PermissionGroup;
public class OnlineGroupRemoveEvent extends Event
{
private static final HandlerList handlers = new HandlerList();
private Player _player;
private PermissionGroup _group;
public OnlineGroupRemoveEvent(Player player, PermissionGroup group)
{
_player = player;
_group = group;
}
public Player getPlayer()
{
return _player;
}
public PermissionGroup getGroup()
{
return _group;
}
public HandlerList getHandlers()
{
return handlers;
}
public static HandlerList getHandlerList()
{
return handlers;
}
}

View File

@ -1,25 +1,23 @@
package mineplex.core.account.event; package mineplex.core.account.event;
import mineplex.core.common.Rank;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
public class OnlineRankUpdateEvent extends Event import mineplex.core.account.permissions.PermissionGroup;
public class OnlinePrimaryGroupUpdateEvent extends Event
{ {
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
private Player _player; private Player _player;
private Rank _from, _to; private PermissionGroup _from, _to;
private boolean _temp;
public OnlineRankUpdateEvent(Player player, Rank from, Rank to, boolean temp) public OnlinePrimaryGroupUpdateEvent(Player player, PermissionGroup from, PermissionGroup to)
{ {
_player = player; _player = player;
_from = from; _from = from;
_to = to; _to = to;
_temp = temp;
} }
public Player getPlayer() public Player getPlayer()
@ -27,21 +25,16 @@ public class OnlineRankUpdateEvent extends Event
return _player; return _player;
} }
public Rank getFrom() public PermissionGroup getFrom()
{ {
return _from; return _from;
} }
public Rank getTo() public PermissionGroup getTo()
{ {
return _to; return _to;
} }
public boolean isTemporary()
{
return _temp;
}
public HandlerList getHandlers() public HandlerList getHandlers()
{ {
return handlers; return handlers;
@ -51,5 +44,4 @@ public class OnlineRankUpdateEvent extends Event
{ {
return handlers; return handlers;
} }
}
}

View File

@ -0,0 +1,38 @@
package mineplex.core.account.event;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class PrimaryGroupUpdateEvent extends Event
{
private static final HandlerList handlers = new HandlerList();
private int _accountId;
private String _groupIdentifier;
public PrimaryGroupUpdateEvent(int accountId, String groupIdentifier)
{
_accountId = accountId;
_groupIdentifier = groupIdentifier;
}
public int getAccountId()
{
return _accountId;
}
public String getGroupIdentifier()
{
return _groupIdentifier;
}
public HandlerList getHandlers()
{
return handlers;
}
public static HandlerList getHandlerList()
{
return handlers;
}
}

View File

@ -1,42 +0,0 @@
package mineplex.core.account.event;
import java.util.UUID;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import mineplex.core.common.Rank;
public class RankSaveEvent extends Event
{
private static final HandlerList handlers = new HandlerList();
private UUID _uuid;
private Rank _rank;
public RankSaveEvent(UUID uuid, Rank rank)
{
_uuid = uuid;
_rank = rank;
}
public UUID getUUID()
{
return _uuid;
}
public Rank getRank()
{
return _rank;
}
public HandlerList getHandlers()
{
return handlers;
}
public static HandlerList getHandlerList()
{
return handlers;
}
}

View File

@ -0,0 +1,35 @@
package mineplex.core.account.permissions;
import java.util.Objects;
public class GroupPermission
{
private final String _identifier;
public GroupPermission(String identifier)
{
_identifier = Objects.requireNonNull(identifier, "Permission identifier cannot be null");
}
@Override
public int hashCode()
{
return _identifier.hashCode();
}
@Override
public boolean equals(Object o)
{
if (o == null || !(o instanceof GroupPermission))
{
return false;
}
return _identifier.hashCode() == ((GroupPermission)o)._identifier.hashCode();
}
public static GroupPermission of(String identifier)
{
return new GroupPermission(identifier);
}
}

View File

@ -0,0 +1,109 @@
package mineplex.core.account.permissions;
import java.util.Arrays;
import java.util.Collections;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import org.bukkit.ChatColor;
public class PermissionGroup
{
protected final Object LOCK = new Object();
private final String _id, _display, _description;
private final ChatColor _color;
private final int _forumId;
private final boolean _canBePrimary;
private final Set<Integer> _inherited;
public PermissionGroup(String identifier, String display, String description, ChatColor color, int forumId, boolean canBePrimary, String... inherited)
{
_id = Objects.requireNonNull(identifier, "Group identifier cannot be null").toLowerCase();
_display = Objects.requireNonNull(display, "Group display cannot be null");
_description = Objects.requireNonNull(description, "Group description cannot be null");
_color = Objects.requireNonNull(color, "Group color cannot be null");
_forumId = forumId;
_canBePrimary = canBePrimary;
_inherited = Collections.unmodifiableSet(Arrays.asList(inherited).stream().map(i -> i.hashCode()).collect(Collectors.toSet()));
}
public String getIdentifier()
{
return _id;
}
public String getDisplay(boolean color, boolean uppercase, boolean bold, boolean defaultIdentifier)
{
StringBuilder builder = new StringBuilder();
if (uppercase)
{
builder.append((_display.isEmpty() && defaultIdentifier) ? _id.toUpperCase() :_display.toUpperCase());
}
else
{
builder.append((_display.isEmpty() && defaultIdentifier) ? (_id.substring(0, 1).toUpperCase() + _id.substring(1)) :_display);
}
if (bold)
{
builder.insert(0, ChatColor.BOLD);
}
if (color)
{
builder.insert(0, _color);
}
return builder.toString();
}
public String getDescription()
{
return _description;
}
public int getForumId()
{
return _forumId;
}
public ChatColor getColor()
{
return _color;
}
public boolean canBePrimary()
{
return _canBePrimary;
}
public boolean inherits(PermissionGroup group)
{
return _inherited.contains(group._id.hashCode());
}
@Override
public String toString()
{
return _id;
}
@Override
public int hashCode()
{
return _id.hashCode();
}
@Override
public boolean equals(Object o)
{
if (o == null || !(o instanceof PermissionGroup))
{
return false;
}
return ((PermissionGroup)o)._id.hashCode() == _id.hashCode();
}
}

View File

@ -0,0 +1,317 @@
package mineplex.core.account.permissions;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import com.google.common.collect.Sets;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClient;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Pair;
import mineplex.core.common.util.F;
public class PermissionManager extends MiniPlugin
{
private final CoreClientManager _clientManager;
private final Map<String, PermissionGroup> _groups = new HashMap<>();
private final Map<PermissionGroup, Map<GroupPermission, Boolean>> _specific = new HashMap<>();
private final Map<PermissionGroup, Map<GroupPermission, Boolean>> _inheritable = new HashMap<>();
public PermissionManager(JavaPlugin plugin, CoreClientManager client)
{
super("Permission Manager");
_clientManager = client;
generateGroups();
}
private Set<GroupPermission> getPermissions(PermissionGroup group, boolean allowSpecific)
{
Set<GroupPermission> perms = new HashSet<>();
if (group == null)
{
return perms;
}
_groups.values().forEach(g ->
{
if (group.inherits(g))
{
perms.addAll(getPermissions(g, false));
}
});
synchronized (group.LOCK)
{
_inheritable.get(group).entrySet().forEach(p ->
{
if (p.getValue().booleanValue())
{
perms.add(p.getKey());
}
else
{
perms.remove(p.getKey());
}
});
if (allowSpecific)
{
_specific.get(group).entrySet().forEach(p ->
{
if (p.getValue().booleanValue())
{
perms.add(p.getKey());
}
else
{
perms.remove(p.getKey());
}
});
}
}
return perms;
}
private void generateGroups()
{
//STAFF
createPermissionGroup(new PermissionGroup("builder", "Builder", "These creative staff members help \nbuild maps for your favorite games!", ChatColor.BLUE, 26, true, "eternal"));
createPermissionGroup(new PermissionGroup("mapper", "Mapper", "These senior staff members work closely with \nthe development and design teams to build new \nmaps for new and old content!", ChatColor.BLUE, 100, true, "builder"));
createPermissionGroup(new PermissionGroup("maplead", "MapLead", "Map Leaders are leaders of the Mineplex Build Team. \nThey oversee the creation of new maps and manage Builders.", ChatColor.BLUE, 25, true, "mapper"));
createPermissionGroup(new PermissionGroup("trainee", "Trainee", "Trainees are moderators-in-training. \nTheir duties include enforcing the rules and \nproviding help to anyone with questions or concerns. \n\nFor assistance, contact them using " + F.elem("/a <message>") + ".", ChatColor.GOLD, 24, true, "maplead"));
createPermissionGroup(new PermissionGroup("mod", "Mod", "Moderators enforce rules and provide help to \nanyone with questions or concerns. \n\nFor assistance, contact them using " + F.elem("/a <message>") + ".", ChatColor.GOLD, 32, true, "trainee"));
createPermissionGroup(new PermissionGroup("srmod", "Sr.Mod", "Senior Moderators are members of a special \nSenior Moderator team where they have to fulfill specific tasks. \nJust like Moderators, you can always ask them for help. \n\nFor assistance, contact them using " + F.elem("/a <message>") + ".", ChatColor.GOLD, 44, true, "mod"));
createPermissionGroup(new PermissionGroup("support", "Support", "Support agents handle tickets and \nprovide customer service.", ChatColor.BLUE, 47, true, "srmod"));
createPermissionGroup(new PermissionGroup("admin", "Admin", "An Administrators role is to manage \ntheir respective Senior Moderator team \nand all moderators within it.", ChatColor.DARK_RED, 10, true, "support", "content"));
createPermissionGroup(new PermissionGroup("dev", "Dev", "Developers work behind the scenes to \ncreate new games and features, and fix bugs to \ngive the best experience.", ChatColor.DARK_RED, 5, true, "admin"));
createPermissionGroup(new PermissionGroup("lt", "Leader", "Leaders manage the operation of their respective team \nor projects. They usually operate on affairs within \nthe staff, development, or management team.", ChatColor.DARK_RED, 11, true, "dev"));
createPermissionGroup(new PermissionGroup("owner", "Owner", "Owners are the core managers of Mineplex. \nEach owner manages a different aspect of the \nserver and ensures its efficient operation.", ChatColor.DARK_RED, 55, true, "lt"));
//SUB-GROUPS
createPermissionGroup(new PermissionGroup("cmod", "", "Members of the Clans Management team.", ChatColor.WHITE, 32, false));
createPermissionGroup(new PermissionGroup("eventmod", "", "Members of the Event Management team.", ChatColor.WHITE, -1, false));
createPermissionGroup(new PermissionGroup("cma", "", "Members of the Clans Management Assistance team.", ChatColor.WHITE, -1, false));
//CONTENT
createPermissionGroup(new PermissionGroup("content", "", "", ChatColor.WHITE, -1, false, "eternal"));
createPermissionGroup(new PermissionGroup("twitch", "Twitch", "A Twitch streamer who often features \nMineplex in their streams.", ChatColor.DARK_PURPLE, 21, true, "content"));
createPermissionGroup(new PermissionGroup("yt", "YT", "A YouTuber who creates content for \nor related to Mineplex. \n\nThey have fewer subscribers than full YouTubers.", ChatColor.DARK_PURPLE, 20, true, "content"));
createPermissionGroup(new PermissionGroup("youtube", "YouTube", "A YouTuber who creates content for \nor related to Mineplex.", ChatColor.RED, 22, true, "content"));
//PLAYER
createPermissionGroup(new PermissionGroup("player", "", "", ChatColor.WHITE, -1, true));
createPermissionGroup(new PermissionGroup("ultra", "Ultra", "A first step into the stories of the mist. \nOnly those brave enough may enter. \n\nThe first purchasable rank at Mineplex.com/shop", ChatColor.AQUA, 12, true, "player"));
createPermissionGroup(new PermissionGroup("hero", "Hero", "There are many stories of a \nvaliant Hero who was brave enough to \ntame the most fearsome dragon in the land. \n\nThe second purchasable rank at Mineplex.com/shop", ChatColor.LIGHT_PURPLE, 13, true, "ultra"));
createPermissionGroup(new PermissionGroup("legend", "Legend", "Years they have told stories of this rank, \nonly for the legends to be true. \n\nThe third purchasable rank at Mineplex.com/shop", ChatColor.GREEN, 14, true, "hero"));
createPermissionGroup(new PermissionGroup("titan", "Titan", "Ancient myths spoke of a gigantic being \nwith immense power... \n\nThe fourth purchasable rank at Mineplex.com/shop", ChatColor.RED, 15, true, "legend"));
createPermissionGroup(new PermissionGroup("eternal", "Eternal", "Fantastic and magical, no one \nexcept the time lords truly understand \nthe power of this rank.\n\nThe fifth purchasable rank at Mineplex.com/shop", ChatColor.DARK_AQUA, 18, true, "titan"));
}
public Collection<PermissionGroup> getGroups()
{
Set<PermissionGroup> groups = Sets.newHashSet(_groups.values());
return groups;
}
public PermissionGroup getGroup(String identifier)
{
if (identifier == null)
{
return null;
}
return _groups.get(identifier.toLowerCase());
}
public PermissionGroup getGroupFromLegacy(String legacyValue)
{
if (legacyValue == null)
{
return null;
}
String legacy = legacyValue == null ? "all" : legacyValue.toLowerCase();
String current = null;
if (legacy.equals("developer"))
{
current = "dev";
}
else if (legacy.equals("jnr_dev"))
{
current = "player";
}
else if (legacy.equals("event_moderator"))
{
current = "eventmod";
}
else if (legacy.equals("snr_moderator"))
{
current = "srmod";
}
else if (legacy.equals("moderator"))
{
current = "mod";
}
else if (legacy.equals("helper"))
{
current = "trainee";
}
else if (legacy.equals("mapdev"))
{
current = "builder";
}
else if (legacy.equals("media"))
{
current = "player";
}
else if (legacy.equals("youtube_small"))
{
current = "yt";
}
else if (legacy.equals("all"))
{
current = "player";
}
return getGroup(current);
}
/**
* Checks if a group is an ancestor of a base group rather than just a direct parent
*/
public boolean inheritsFully(PermissionGroup base, PermissionGroup check)
{
if (base == null || check == null)
{
return false;
}
if (base.inherits(check))
{
return true;
}
for (PermissionGroup group : _groups.values())
{
if (base.inherits(group))
{
boolean inherits = inheritsFully(group, check);
if (inherits)
{
return true;
}
}
}
return false;
}
public boolean hasPermission(PermissionGroup group, GroupPermission permission)
{
Set<GroupPermission> total = getPermissions(group, true);
return total.contains(permission);
}
public boolean hasPermission(CoreClient client, GroupPermission permission)
{
if (hasPermission(client.getPrimaryGroup(), permission))
{
return true;
}
for (PermissionGroup group : client.getAdditionalGroups())
{
if (hasPermission(group, permission))
{
return true;
}
}
return false;
}
public boolean hasPermission(Pair<PermissionGroup, Set<PermissionGroup>> groups, GroupPermission permission)
{
if (hasPermission(groups.getLeft(), permission))
{
return true;
}
for (PermissionGroup group : groups.getRight())
{
if (hasPermission(group, permission))
{
return true;
}
}
return false;
}
public boolean hasPermission(Player player, GroupPermission permission)
{
CoreClient client = _clientManager.Get(player);
return hasPermission(client, permission);
}
private void createPermissionGroup(PermissionGroup group)
{
if (group == null)
{
throw new NullPointerException("Cannot register a null group");
}
if (_groups.containsKey(group.getIdentifier()))
{
throw new IllegalArgumentException("That group is already registered");
}
_groups.put(group.getIdentifier().toLowerCase(), group);
_inheritable.put(group, new HashMap<>());
_specific.put(group, new HashMap<>());
}
public void setPermission(PermissionGroup group, GroupPermission permission, boolean inheritable, boolean value)
{
if (group == null)
{
return;
}
synchronized (group.LOCK)
{
if (inheritable)
{
_inheritable.computeIfAbsent(group, (g) -> new HashMap<>()).put(permission, Boolean.valueOf(value));
}
else
{
_specific.computeIfAbsent(group, (g) -> new HashMap<>()).put(permission, Boolean.valueOf(value));
}
}
}
public void revokePermission(PermissionGroup group, GroupPermission permission, boolean inheritable)
{
if (group == null)
{
return;
}
synchronized (group.LOCK)
{
if (inheritable)
{
_inheritable.computeIfAbsent(group, (g) -> new HashMap<>()).remove(permission);
}
else
{
_specific.computeIfAbsent(group, (g) -> new HashMap<>()).remove(permission);
}
}
}
}

View File

@ -0,0 +1,25 @@
package mineplex.core.account.redis;
import mineplex.serverdata.commands.ServerCommand;
public class AddPermissionGroup extends ServerCommand
{
private final int _accountId;
private final String _groupIdentifier;
public AddPermissionGroup(int accountId, String groupIdentifier)
{
_accountId = accountId;
_groupIdentifier = groupIdentifier;
}
public int getAccountId()
{
return _accountId;
}
public String getGroupIdentifier()
{
return _groupIdentifier;
}
}

View File

@ -0,0 +1,41 @@
package mineplex.core.account.redis;
import java.util.Optional;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.permissions.PermissionGroup;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.serverdata.commands.CommandCallback;
public class AddPermissionGroupHandler implements CommandCallback<AddPermissionGroup>
{
private final CoreClientManager _clientManager;
public AddPermissionGroupHandler(CoreClientManager clientManager)
{
_clientManager = clientManager;
}
@Override
public void run(AddPermissionGroup command)
{
_clientManager.runSync(() ->
{
Optional<Player> opt = Bukkit.getOnlinePlayers().stream().map(Player.class::cast).filter(player -> _clientManager.getAccountId(player) == command.getAccountId()).findAny();
if (opt.isPresent())
{
PermissionGroup group = _clientManager.getPermissionManager().getGroup(command.getGroupIdentifier());
if (group != null)
{
_clientManager.Get(opt.get()).addAdditionalGroup(group);
UtilPlayer.message(opt.get(), F.main(_clientManager.getName(), "You have gained sub-rank " + F.elem(group.getIdentifier()) + "!"));
}
}
});
}
}

View File

@ -0,0 +1,18 @@
package mineplex.core.account.redis;
import mineplex.serverdata.commands.ServerCommand;
public class ClearGroups extends ServerCommand
{
private final int _accountId;
public ClearGroups(int accountId)
{
_accountId = accountId;
}
public int getAccountId()
{
return _accountId;
}
}

View File

@ -0,0 +1,39 @@
package mineplex.core.account.redis;
import java.util.Optional;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.permissions.PermissionGroup;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.serverdata.commands.CommandCallback;
public class ClearGroupsHandler implements CommandCallback<ClearGroups>
{
private final CoreClientManager _clientManager;
public ClearGroupsHandler(CoreClientManager clientManager)
{
_clientManager = clientManager;
}
@Override
public void run(ClearGroups command)
{
_clientManager.runSync(() ->
{
Optional<Player> opt = Bukkit.getOnlinePlayers().stream().map(Player.class::cast).filter(player -> _clientManager.getAccountId(player) == command.getAccountId()).findAny();
if (opt.isPresent())
{
PermissionGroup group = _clientManager.getPermissionManager().getGroup("player");
_clientManager.Get(opt.get()).setPrimaryGroup(group);
_clientManager.Get(opt.get()).getAdditionalGroups().clear();
UtilPlayer.message(opt.get(), F.main(_clientManager.getName(), "Your ranks have been cleared!"));
}
});
}
}

View File

@ -0,0 +1,25 @@
package mineplex.core.account.redis;
import mineplex.serverdata.commands.ServerCommand;
public class PrimaryGroupUpdate extends ServerCommand
{
private final int _accountId;
private final String _groupIdentifier;
public PrimaryGroupUpdate(int accountId, String groupIdentifier)
{
_accountId = accountId;
_groupIdentifier = groupIdentifier;
}
public int getAccountId()
{
return _accountId;
}
public String getGroupIdentifier()
{
return _groupIdentifier;
}
}

View File

@ -0,0 +1,42 @@
package mineplex.core.account.redis;
import java.util.Optional;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.permissions.PermissionGroup;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.serverdata.commands.CommandCallback;
public class PrimaryGroupUpdateHandler implements CommandCallback<PrimaryGroupUpdate>
{
private final CoreClientManager _clientManager;
public PrimaryGroupUpdateHandler(CoreClientManager clientManager)
{
_clientManager = clientManager;
}
@Override
public void run(PrimaryGroupUpdate command)
{
_clientManager.runSync(() ->
{
Optional<Player> opt = Bukkit.getOnlinePlayers().stream().map(Player.class::cast).filter(player -> _clientManager.getAccountId(player) == command.getAccountId()).findAny();
if (opt.isPresent())
{
PermissionGroup group = _clientManager.getPermissionManager().getGroup(command.getGroupIdentifier());
if (group == null)
{
group = _clientManager.getPermissionManager().getGroup("player");
}
_clientManager.Get(opt.get()).setPrimaryGroup(group);
UtilPlayer.message(opt.get(), F.main(_clientManager.getName(), "Your rank has been updated to " + F.elem(group.getIdentifier()) + "!"));
}
});
}
}

View File

@ -0,0 +1,25 @@
package mineplex.core.account.redis;
import mineplex.serverdata.commands.ServerCommand;
public class RemovePermissionGroup extends ServerCommand
{
private final int _accountId;
private final String _groupIdentifier;
public RemovePermissionGroup(int accountId, String groupIdentifier)
{
_accountId = accountId;
_groupIdentifier = groupIdentifier;
}
public int getAccountId()
{
return _accountId;
}
public String getGroupIdentifier()
{
return _groupIdentifier;
}
}

View File

@ -0,0 +1,41 @@
package mineplex.core.account.redis;
import java.util.Optional;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.permissions.PermissionGroup;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.serverdata.commands.CommandCallback;
public class RemovePermissionGroupHandler implements CommandCallback<RemovePermissionGroup>
{
private final CoreClientManager _clientManager;
public RemovePermissionGroupHandler(CoreClientManager clientManager)
{
_clientManager = clientManager;
}
@Override
public void run(RemovePermissionGroup command)
{
_clientManager.runSync(() ->
{
Optional<Player> opt = Bukkit.getOnlinePlayers().stream().map(Player.class::cast).filter(player -> _clientManager.getAccountId(player) == command.getAccountId()).findAny();
if (opt.isPresent())
{
PermissionGroup group = _clientManager.getPermissionManager().getGroup(command.getGroupIdentifier());
if (group != null)
{
_clientManager.Get(opt.get()).removeAdditionalGroup(group);
UtilPlayer.message(opt.get(), F.main(_clientManager.getName(), "You have lost sub-rank " + F.elem(group.getIdentifier()) + "!"));
}
}
});
}
}

View File

@ -5,8 +5,13 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -16,27 +21,32 @@ import com.google.gson.reflect.TypeToken;
import mineplex.cache.player.PlayerCache; import mineplex.cache.player.PlayerCache;
import mineplex.core.account.ILoginProcessor; import mineplex.core.account.ILoginProcessor;
import mineplex.core.account.event.RankSaveEvent; import mineplex.core.account.event.GroupAddEvent;
import mineplex.core.account.event.GroupRemoveEvent;
import mineplex.core.account.event.PrimaryGroupUpdateEvent;
import mineplex.core.account.repository.token.LoginToken; import mineplex.core.account.repository.token.LoginToken;
import mineplex.core.account.repository.token.RankUpdateToken; import mineplex.core.common.Pair;
import mineplex.core.common.Rank;
import mineplex.core.common.util.Callback; import mineplex.core.common.util.Callback;
import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilServer;
import mineplex.core.database.MinecraftRepository; import mineplex.core.database.MinecraftRepository;
import mineplex.serverdata.database.DBPool; import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.ResultSetCallable; import mineplex.serverdata.database.column.ColumnInt;
import mineplex.serverdata.database.column.ColumnVarChar; import mineplex.serverdata.database.column.ColumnVarChar;
public class AccountRepository extends MinecraftRepository public class AccountRepository extends MinecraftRepository
{ {
private static String CREATE_ACCOUNT_TABLE = "CREATE TABLE IF NOT EXISTS accounts (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(100), name VARCHAR(40), gems INT, rank VARCHAR(40), rankPerm BOOL, rankExpire LONG, lastLogin LONG, totalPlayTime LONG, PRIMARY KEY (id), UNIQUE INDEX uuidIndex (uuid), UNIQUE INDEX nameIndex (name), INDEX rankIndex (rank));"; private static String CREATE_ACCOUNT_TABLE = "CREATE TABLE IF NOT EXISTS accounts (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(100), name VARCHAR(40), gems INT, lastLogin LONG, totalPlayTime LONG, PRIMARY KEY (id), UNIQUE INDEX uuidIndex (uuid), UNIQUE INDEX nameIndex (name));";
private static String ACCOUNT_LOGIN_NEW = "INSERT INTO accounts (uuid, name, lastLogin) values(?, ?, now());"; private static String ACCOUNT_LOGIN_NEW = "INSERT INTO accounts (uuid, name, lastLogin) values(?, ?, now());";
private static String UPDATE_ACCOUNT_RANK = "UPDATE accounts SET rank=?, rankPerm=false, rankExpire=now() + INTERVAL 1 MONTH WHERE uuid = ?;";
private static String UPDATE_ACCOUNT_RANK_DONOR = "UPDATE accounts SET rank=?, donorRank=?, rankPerm=false, rankExpire=now() + INTERVAL 1 MONTH WHERE uuid = ?;"; private static String CREATE_RANKS_TABLE = "CREATE TABLE IF NOT EXISTS accountRanks (id INT NOT NULL AUTO_INCREMENT, accountId INT NOT NULL, rankIdentifier VARCHAR(40), primaryGroup BOOL, PRIMARY KEY(id), INDEX accountIndex (accountId), INDEX rankIndex (rankIdentifier), UNIQUE INDEX additionalIndex (accountId, rankIdentifier, primaryGroup), FOREIGN KEY (accountId) REFERENCES accounts(id));";
private static String UPDATE_ACCOUNT_RANK_PERM = "UPDATE accounts SET rank=?, rankPerm=true WHERE uuid = ?;"; private static String UPDATE_PRIMARY_RANK = "UPDATE accountRanks SET rankIdentifier=? WHERE accountId=? AND primaryGroup=true;";
private static String UPDATE_ACCOUNT_RANK_DONOR_PERM = "UPDATE accounts SET rank=?, donorRank=?, rankPerm=true WHERE uuid = ?;"; private static String ADD_PRIMARY_RANK = "INSERT INTO accountRanks (accountId, rankIdentifier, primaryGroup) VALUES (?, NULL, true);";
private static String ADD_ADDITIONAL_RANK = "INSERT INTO accountRanks (accountId, rankIdentifier, primaryGroup) VALUES (?, ?, false);";
private static String REMOVE_ADDITIONAL_RANK = "DELETE FROM accountRanks WHERE accountId=? AND rankIdentifier=? AND primaryGroup=false;";
private static String REMOVE_ADDITIONAL_RANKS = "DELETE FROM accountRanks WHERE accountId=? AND primaryGroup=false;";
private static String SELECT_ACCOUNT_UUID_BY_NAME = "SELECT uuid FROM accounts WHERE name = ? ORDER BY lastLogin DESC;"; private static String SELECT_ACCOUNT_UUID_BY_NAME = "SELECT uuid FROM accounts WHERE name = ? ORDER BY lastLogin DESC;";
private static String SELECT_ACCOUNT_UUID_BY_ID = "SELECT uuid FROM accounts WHERE id= DESC;";
private static String SELECT_ACCOUNT_ID_BY_UUID = "SELECT id FROM accounts WHERE accounts.uuid = ? LIMIT 1"; private static String SELECT_ACCOUNT_ID_BY_UUID = "SELECT id FROM accounts WHERE accounts.uuid = ? LIMIT 1";
public AccountRepository() public AccountRepository()
@ -44,10 +54,12 @@ public class AccountRepository extends MinecraftRepository
super(DBPool.getAccount()); super(DBPool.getAccount());
} }
public int login(final List<ILoginProcessor> loginProcessors, final UUID uuid, final String name) throws SQLException public Pair<Integer, Pair<String, Set<String>>> login(final List<ILoginProcessor> loginProcessors, final UUID uuid, final String name) throws SQLException
{ {
// First we try to grab the account id from cache - this saves an extra trip to database // First we try to grab the account id from cache - this saves an extra trip to database
int accountId = PlayerCache.getInstance().getAccountId(uuid); int accountId = PlayerCache.getInstance().getAccountId(uuid);
String primaryId = null;
Set<String> extraIds = new HashSet<>();
System.out.println("LOGIN... IDLE: " + ((BasicDataSource) DBPool.getAccount()).getNumIdle() + " ACTIVE: " + ((BasicDataSource) DBPool.getAccount()).getNumActive()); System.out.println("LOGIN... IDLE: " + ((BasicDataSource) DBPool.getAccount()).getNumIdle() + " ACTIVE: " + ((BasicDataSource) DBPool.getAccount()).getNumActive());
try (Connection connection = getConnection(); Statement statement = connection.createStatement()) try (Connection connection = getConnection(); Statement statement = connection.createStatement())
@ -65,19 +77,15 @@ public class AccountRepository extends MinecraftRepository
else else
{ {
// Player doesn't exist in our database, add them to the accounts table // Player doesn't exist in our database, add them to the accounts table
final List<Integer> tempList = new ArrayList<Integer>(1); final List<Integer> tempList = new ArrayList<>(1);
executeInsert(ACCOUNT_LOGIN_NEW, new ResultSetCallable() executeInsert(connection, ACCOUNT_LOGIN_NEW, rs ->
{ {
@Override while (rs.next())
public void processResultSet(ResultSet resultSet) throws SQLException
{ {
while (resultSet.next()) tempList.add(rs.getInt(1));
{
tempList.add(resultSet.getInt(1));
}
} }
}, new ColumnVarChar("uuid", 100, uuid.toString()), new ColumnVarChar("name", 100, name)); }, () -> {}, new ColumnVarChar("uuid", 100, uuid.toString()), new ColumnVarChar("name", 100, name));
accountId = tempList.get(0); accountId = tempList.get(0);
} }
@ -86,6 +94,34 @@ public class AccountRepository extends MinecraftRepository
{ {
System.out.println(name + " Loaded Account ID From Cache [" + name + " - " + accountId + "]"); System.out.println(name + " Loaded Account ID From Cache [" + name + " - " + accountId + "]");
} }
{
statement.execute("SELECT * FROM accountRanks WHERE accountId=" + accountId + ";");
try (ResultSet rankSet = statement.getResultSet())
{
boolean anyRows = false;
while (rankSet.next())
{
anyRows = true;
String id = rankSet.getString("rankIdentifier");
boolean primary = rankSet.getBoolean("primaryGroup");
if (primary)
{
primaryId = id;
}
else
{
extraIds.add(id);
}
}
if (!anyRows)
{
statement.execute(UPDATE_PRIMARY_RANK.replace("?", "" + accountId));
}
}
}
final int finalId = accountId; final int finalId = accountId;
final String uuidString = uuid.toString(); final String uuidString = uuid.toString();
@ -120,7 +156,7 @@ public class AccountRepository extends MinecraftRepository
} }
return accountId; return Pair.create(Integer.valueOf(accountId), Pair.create(primaryId, extraIds));
} }
public void getAccountId(UUID uuid, Callback<Integer> callback) public void getAccountId(UUID uuid, Callback<Integer> callback)
@ -150,67 +186,256 @@ public class AccountRepository extends MinecraftRepository
public UUID getClientUUID(String name) public UUID getClientUUID(String name)
{ {
final List<UUID> uuids = new ArrayList<UUID>(); final List<UUID> uuids = new LinkedList<>();
executeQuery(SELECT_ACCOUNT_UUID_BY_NAME, new ResultSetCallable() executeQuery(SELECT_ACCOUNT_UUID_BY_NAME, resultSet ->
{ {
@Override while (resultSet.next())
public void processResultSet(ResultSet resultSet) throws SQLException
{ {
while (resultSet.next()) uuids.add(UUID.fromString(resultSet.getString(1)));
{
uuids.add(UUID.fromString(resultSet.getString(1)));
}
} }
}, new ColumnVarChar("name", 100, name)); }, new ColumnVarChar("name", 100, name));
if (uuids.size() > 0) if (uuids.size() > 0)
return uuids.get(0);
else
return null;
}
public void saveRank(final Callback<Rank> callback, final String name, final UUID uuid, final Rank rank, final boolean perm)
{
final RankUpdateToken token = new RankUpdateToken();
token.Name = name;
token.Rank = rank.toString();
token.Perm = perm;
final Consumer<Rank> extraCallback = response ->
{ {
if (rank == Rank.ULTRA || rank == Rank.HERO || rank == Rank.LEGEND || rank == Rank.TITAN) return uuids.get(0);
}
else
{
return null;
}
}
public UUID getClientUUID(final int accountId)
{
StringBuilder uuidBuilder = new StringBuilder();
executeQuery(SELECT_ACCOUNT_UUID_BY_ID, resultSet ->
{
if (resultSet.next())
{ {
if (rank.isDonor()) uuidBuilder.append(resultSet.getString("uuid"));
}
}, new ColumnInt("id", accountId));
if (uuidBuilder.length() == 0)
{
return null;
}
else
{
return UUID.fromString(uuidBuilder.toString());
}
}
public void setPrimaryGroup(final int accountId, final String rankIdentifier, Runnable after)
{
UtilServer.runAsync(() ->
{
try (Connection c = getConnection())
{
try (Statement s = c.createStatement();
ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM accountRanks WHERE accountId=" + accountId + " AND primaryGroup=true;");
)
{ {
if (perm) if (!rs.next())
executeUpdate(UPDATE_ACCOUNT_RANK_DONOR_PERM, new ColumnVarChar("rank", 100, rank.toString()), new ColumnVarChar("donorRank", 100, rank.toString()), new ColumnVarChar("uuid", 100, uuid.toString())); {
else s.execute(ADD_PRIMARY_RANK.replace("?", "" + accountId));
executeUpdate(UPDATE_ACCOUNT_RANK_DONOR, new ColumnVarChar("rank", 100, rank.toString()), new ColumnVarChar("donorRank", 100, rank.toString()), new ColumnVarChar("uuid", 100, uuid.toString())); }
} }
if (perm)
executeUpdate(UPDATE_ACCOUNT_RANK_DONOR_PERM, new ColumnVarChar("rank", 100, rank.toString()), new ColumnVarChar("donorRank", 100, rank.toString()), new ColumnVarChar("uuid", 100, uuid.toString()));
else
executeUpdate(UPDATE_ACCOUNT_RANK_DONOR, new ColumnVarChar("rank", 100, rank.toString()), new ColumnVarChar("donorRank", 100, rank.toString()), new ColumnVarChar("uuid", 100, uuid.toString()));
}
else
{
if (perm)
executeUpdate(UPDATE_ACCOUNT_RANK_PERM, new ColumnVarChar("rank", 100, rank.toString()), new ColumnVarChar("uuid", 100, uuid.toString()));
else
executeUpdate(UPDATE_ACCOUNT_RANK, new ColumnVarChar("rank", 100, rank.toString()), new ColumnVarChar("uuid", 100, uuid.toString()));
}
UtilServer.runSync(() ->
{
if (callback != null)
callback.run(response);
UtilServer.CallEvent(new RankSaveEvent(uuid, rank)); executeUpdate(c, UPDATE_PRIMARY_RANK, () -> {}, new ColumnInt("accountId", accountId), new ColumnVarChar("rankIdentifier", rankIdentifier.length(), rankIdentifier));
});
UtilServer.runSync(() ->
{
if (after != null)
{
after.run();
}
UtilServer.CallEvent(new PrimaryGroupUpdateEvent(accountId, rankIdentifier));
});
}
catch (SQLException e)
{
e.printStackTrace();
}
});
}
public void addAdditionalGroup(final int accountId, final String rankIdentifier, Consumer<Boolean> successCallback)
{
UtilServer.runAsync(() ->
{
executeInsert(ADD_ADDITIONAL_RANK, rs ->
{
if (rs.next())
{
UtilServer.runSync(() ->
{
if (successCallback != null)
{
successCallback.accept(Boolean.TRUE);
}
UtilServer.CallEvent(new GroupAddEvent(accountId, rankIdentifier));
});
}
else
{
if (successCallback != null)
{
UtilServer.runSync(() -> successCallback.accept(Boolean.FALSE));
}
}
}, () ->
{
if (successCallback != null)
{
UtilServer.runSync(() -> successCallback.accept(Boolean.FALSE));
}
}, new ColumnInt("accountId", accountId), new ColumnVarChar("rankIdentifier", rankIdentifier.length(), rankIdentifier));
});
}
public void removeAdditionalGroup(final int accountId, final String rankIdentifier, Consumer<Boolean> successCallback)
{
UtilServer.runAsync(() ->
{
AtomicBoolean callbackRun = new AtomicBoolean();
int updated = executeUpdate(REMOVE_ADDITIONAL_RANK, () ->
{
callbackRun.set(true);
if (successCallback != null)
{
UtilServer.runSync(() -> successCallback.accept(Boolean.FALSE));
}
}, new ColumnInt("accountId", accountId), new ColumnVarChar("rankIdentifier", rankIdentifier.length(), rankIdentifier));
if (!callbackRun.get())
{
if (updated > 0)
{
UtilServer.runSync(() ->
{
if (successCallback != null)
{
successCallback.accept(Boolean.TRUE);
}
UtilServer.CallEvent(new GroupRemoveEvent(accountId, rankIdentifier));
});
}
else
{
UtilServer.runSync(() -> successCallback.accept(Boolean.FALSE));
}
}
});
}
public void clearGroups(final int accountId, Consumer<Boolean> successCallback)
{
UtilServer.runAsync(() ->
{
AtomicBoolean success = new AtomicBoolean(true);
Set<String> removed = new HashSet<>();
try (Connection c = getConnection())
{
try (Statement s = c.createStatement())
{
try (ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM accountRanks WHERE accountId=" + accountId + " AND primaryGroup=true;"))
{
if (!rs.next())
{
s.execute(ADD_PRIMARY_RANK.replace("?", "" + accountId));
}
}
try (ResultSet rs = s.executeQuery("SELECT * FROM accountRanks WHERE accountId=" + accountId + ";"))
{
while (rs.next())
{
if (!rs.getBoolean("primaryGroup"))
{
removed.add(rs.getString("rankIdentifier"));
}
}
}
}
executeUpdate(c, UPDATE_PRIMARY_RANK, () -> {}, new ColumnInt("accountId", accountId), new ColumnVarChar("rankIdentifier", "player".length(), "player"));
executeUpdate(c, REMOVE_ADDITIONAL_RANKS, () -> success.set(false), new ColumnInt("accountId", accountId));
}
catch (SQLException e)
{
e.printStackTrace();
success.set(false);
}
if (successCallback != null || success.get())
{
UtilServer.runSync(() ->
{
if (successCallback != null)
{
successCallback.accept(Boolean.valueOf(success.get()));
}
UtilServer.CallEvent(new PrimaryGroupUpdateEvent(accountId, "player"));
for (String ident : removed)
{
UtilServer.CallEvent(new GroupRemoveEvent(accountId, ident));
}
});
}
});
}
public void fetchGroups(final int accountId, Consumer<Pair<String, Set<String>>> resultCallback, Runnable onError)
{
fetchGroups(accountId, resultCallback, onError, true);
}
public void fetchGroups(final int accountId, Consumer<Pair<String, Set<String>>> resultCallback, Runnable onError, boolean runAsync)
{
Runnable r = () ->
{
AtomicBoolean errored = new AtomicBoolean();
AtomicReference<String> primary = new AtomicReference<>();
Set<String> additional = new HashSet<>();
executeQuery("SELECT * FROM accountRanks WHERE accountId=?;", rs ->
{
if (rs.getBoolean("primaryGroup"))
{
primary.set(rs.getString("rankIdentifier"));
}
else
{
additional.add(rs.getString("rankIdentifier"));
}
}, () ->
{
if (onError != null)
{
errored.set(true);
UtilServer.runSync(onError);
}
}, new ColumnInt("accountId", accountId));
if (!errored.get())
{
if (resultCallback != null)
{
resultCallback.accept(Pair.create(primary.get(), additional));
}
}
}; };
handleMSSQLCall("PlayerAccount/RankUpdate", String.format("Error saving %s's rank: ", token.Name), token, Rank.class, extraCallback); if (runAsync)
{
UtilServer.runAsync(r);
}
else
{
r.run();
}
} }
public void matchPlayerName(final Callback<List<String>> callback, final String userName) public void matchPlayerName(final Callback<List<String>> callback, final String userName)
@ -222,4 +447,4 @@ public class AccountRepository extends MinecraftRepository
{ {
return handleSyncMSSQLCallStream("PlayerAccount/GetAccount", playerName); return handleSyncMSSQLCallStream("PlayerAccount/GetAccount", playerName);
} }
} }

View File

@ -5,4 +5,4 @@ public class Rank
public int RankId; public int RankId;
public String Name; public String Name;
} }

View File

@ -7,7 +7,7 @@ import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Rank; import mineplex.core.account.permissions.GroupPermission;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilTime;
import mineplex.core.game.GameDisplay; import mineplex.core.game.GameDisplay;
@ -310,7 +310,7 @@ public enum AchievementCategory
String displayName = _statDisplays[i].getDisplayName(); String displayName = _statDisplays[i].getDisplayName();
// Skip showing Losses, Kills, Deaths for other players // Skip showing Losses, Kills, Deaths for other players
if (!clientManager.Get(player).GetRank().has(Rank.MODERATOR) && !player.getName().equals(targetName) && (displayName.contains("Losses") || displayName.contains("Kills") || displayName.contains("Deaths") || displayName.equals("Time In Game") || displayName.equals("Games Played"))) if (!clientManager.getPermissionManager().hasPermission(player, GroupPermission.of(AchievementManager.SEE_FULL_STATS_PERMISSION)) && !player.getName().equals(targetName) && (displayName.contains("Losses") || displayName.contains("Kills") || displayName.contains("Deaths") || displayName.equals("Time In Game") || displayName.equals("Games Played")))
continue; continue;
double statNumber = 0; double statNumber = 0;

View File

@ -1,6 +1,7 @@
package mineplex.core.achievement; package mineplex.core.achievement;
import mineplex.core.stats.PlayerStats; import java.util.UUID;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -8,25 +9,24 @@ import org.bukkit.event.player.PlayerQuitEvent;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.account.permissions.GroupPermission;
import mineplex.core.account.permissions.PermissionManager;
import mineplex.core.achievement.command.StatsCommand; import mineplex.core.achievement.command.StatsCommand;
import mineplex.core.achievement.ui.AchievementShop; import mineplex.core.achievement.ui.AchievementShop;
import mineplex.core.common.Rank;
import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.donation.DonationManager; import mineplex.core.donation.DonationManager;
import mineplex.core.elo.EloManager; import mineplex.core.elo.EloManager;
import mineplex.core.incognito.IncognitoManager; import mineplex.core.incognito.IncognitoManager;
import mineplex.core.stats.PlayerStats;
import mineplex.core.stats.StatsManager; import mineplex.core.stats.StatsManager;
import mineplex.core.stats.event.StatChangeEvent; import mineplex.core.stats.event.StatChangeEvent;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
public class AchievementManager extends MiniPlugin public class AchievementManager extends MiniPlugin
{ {
private static final List<String> NO_FAKE_LEVELS = Arrays.asList("samczsun"); public static final String FAKE_LEVEL_TIER_PERMISSION = "mineplex.core.achievement.fakelevel.";
public static final String SEE_FULL_STATS_PERMISSION = "mineplex.core.achievement.seefullstats";
public static final String STATS_COMMAND_PERMISSION = "mineplex.core.achievement.guicommand";
private CoreClientManager _clientManager; private CoreClientManager _clientManager;
private IncognitoManager _incognitoManager; private IncognitoManager _incognitoManager;
private StatsManager _statsManager; private StatsManager _statsManager;
@ -49,6 +49,20 @@ public class AchievementManager extends MiniPlugin
_eloManager = eloManager; _eloManager = eloManager;
_clientManager = clientManager; _clientManager = clientManager;
_shop = new AchievementShop(this, _statsManager, clientManager, donationManager, "Achievement"); _shop = new AchievementShop(this, _statsManager, clientManager, donationManager, "Achievement");
generatePermissions();
}
private void generatePermissions()
{
PermissionManager pm = _clientManager.getPermissionManager();
pm.setPermission(pm.getGroup("mod"), GroupPermission.of(SEE_FULL_STATS_PERMISSION), true, true);
pm.setPermission(pm.getGroup("mod"), GroupPermission.of(FAKE_LEVEL_TIER_PERMISSION + 1), true, true);
pm.setPermission(pm.getGroup("srmod"), GroupPermission.of(FAKE_LEVEL_TIER_PERMISSION + 2), true, true);
pm.setPermission(pm.getGroup("admin"), GroupPermission.of(FAKE_LEVEL_TIER_PERMISSION + 3), true, true);
pm.setPermission(pm.getGroup("lt"), GroupPermission.of(FAKE_LEVEL_TIER_PERMISSION + 4), true, true);
pm.setPermission(pm.getGroup("player"), GroupPermission.of(STATS_COMMAND_PERMISSION), true, true);
} }
public AchievementData get(Player player, Achievement type) public AchievementData get(Player player, Achievement type)
@ -199,32 +213,33 @@ public class AchievementManager extends MiniPlugin
return true; return true;
} }
public int getMineplexLevelNumber(Player sender, Rank rank) public int getMineplexLevelNumber(Player sender)
{ {
int level = get(sender, Achievement.GLOBAL_MINEPLEX_LEVEL).getLevel(); int level = get(sender, Achievement.GLOBAL_MINEPLEX_LEVEL).getLevel();
if (NO_FAKE_LEVELS.contains(sender.getName())) if (_clientManager.getPermissionManager().hasPermission(sender, GroupPermission.of(FAKE_LEVEL_TIER_PERMISSION + 4)))
{ {
return level;
}
if (rank.has(Rank.MODERATOR))
level = Math.max(level, 5);
if (rank.has(Rank.SNR_MODERATOR))
level = Math.max(level, 15);
if (rank.has(Rank.JNR_DEV))
level = Math.max(level, 25);
if (rank.has(Rank.ADMIN))
level = Math.max(level, 30 + get(sender, Achievement.GLOBAL_GEM_HUNTER).getLevel());
if (rank.has(Rank.OWNER))
level = Math.max(level, 50 + get(sender, Achievement.GLOBAL_GEM_HUNTER).getLevel()); level = Math.max(level, 50 + get(sender, Achievement.GLOBAL_GEM_HUNTER).getLevel());
}
else if (_clientManager.getPermissionManager().hasPermission(sender, GroupPermission.of(FAKE_LEVEL_TIER_PERMISSION + 3)))
{
level = Math.max(level, 30 + get(sender, Achievement.GLOBAL_GEM_HUNTER).getLevel());
}
else if (_clientManager.getPermissionManager().hasPermission(sender, GroupPermission.of(FAKE_LEVEL_TIER_PERMISSION + 2)))
{
level = Math.max(level, 15);
}
else if (_clientManager.getPermissionManager().hasPermission(sender, GroupPermission.of(FAKE_LEVEL_TIER_PERMISSION + 1)))
{
level = Math.max(level, 5);
}
return level; return level;
} }
public String getMineplexLevel(Player sender, Rank rank) public String getMineplexLevel(Player sender)
{ {
return Achievement.getExperienceString(getMineplexLevelNumber(sender, rank)) + " " + ChatColor.RESET; return Achievement.getExperienceString(getMineplexLevelNumber(sender)) + " " + ChatColor.RESET;
} }
public CoreClientManager getClientManager() public CoreClientManager getClientManager()
@ -246,4 +261,4 @@ public class AchievementManager extends MiniPlugin
{ {
return _statsManager; return _statsManager;
} }
} }

View File

@ -1,23 +1,19 @@
package mineplex.core.achievement.command; package mineplex.core.achievement.command;
import mineplex.core.stats.PlayerStats;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import mineplex.core.account.permissions.GroupPermission;
import mineplex.core.achievement.AchievementManager; import mineplex.core.achievement.AchievementManager;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import java.sql.SQLException;
public class StatsCommand extends CommandBase<AchievementManager> public class StatsCommand extends CommandBase<AchievementManager>
{ {
public StatsCommand(AchievementManager plugin) public StatsCommand(AchievementManager plugin)
{ {
super(plugin, Rank.ALL, "stats"); super(plugin, AchievementManager.STATS_COMMAND_PERMISSION, "stats");
} }
@Override @Override
@ -33,7 +29,7 @@ public class StatsCommand extends CommandBase<AchievementManager>
if (target == null) if (target == null)
{ {
if (Plugin.getClientManager().hasRank(caller, Rank.MODERATOR)) attemptOffline(caller, args); if (Plugin.getClientManager().getPermissionManager().hasPermission(caller, GroupPermission.of(AchievementManager.SEE_FULL_STATS_PERMISSION))) attemptOffline(caller, args);
return; return;
} }
@ -73,4 +69,4 @@ public class StatsCommand extends CommandBase<AchievementManager>
}); });
} }
} }
} }

View File

@ -51,6 +51,8 @@ import mineplex.core.MiniPlugin;
import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin;
import mineplex.core.account.CoreClient; import mineplex.core.account.CoreClient;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.account.permissions.GroupPermission;
import mineplex.core.account.permissions.PermissionManager;
import mineplex.core.antihack.actions.AntiHackAction; import mineplex.core.antihack.actions.AntiHackAction;
import mineplex.core.antihack.actions.BanwaveAction; import mineplex.core.antihack.actions.BanwaveAction;
import mineplex.core.antihack.actions.GEPBanAction; import mineplex.core.antihack.actions.GEPBanAction;
@ -68,7 +70,6 @@ import mineplex.core.antihack.gep.GwenExtremePrejudice;
import mineplex.core.antihack.guardians.GuardianManager; import mineplex.core.antihack.guardians.GuardianManager;
import mineplex.core.antihack.logging.AntihackLogger; import mineplex.core.antihack.logging.AntihackLogger;
import mineplex.core.antihack.redisnotifications.GwenBanNotification; import mineplex.core.antihack.redisnotifications.GwenBanNotification;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilServer;
@ -127,6 +128,14 @@ public class AntiHack extends MiniPlugin
private static final String USER_HAS_BEEN_BANNED_BANWAVE = USER_HAS_BEEN_BANNED; private static final String USER_HAS_BEEN_BANNED_BANWAVE = USER_HAS_BEEN_BANNED;
public static final int ID_LENGTH = 5; public static final int ID_LENGTH = 5;
public static final String SEE_GUARDIANS_PERMISSION = "mineplex.core.antihack.seeguardians";
public static final String SEE_ALERTS_PERMISSION = "mineplex.core.antihack.seealerts";
public static final String SILENTLY_BANNED_PERMISSION = "mineplex.core.antihack.silentlybanned";
public static final String ANTICHEAT_TOGGLE_COMMAND_PERMISSION = "mineplex.core.antihack.togglecommand";
public static final String DETAILED_MESSAGES_COMMAND_PERMISSION = "mineplex.core.antihack.detailedmessages";
public static final String GET_VLS_COMMAND_PERMISSION = "mineplex.core.antihack.getvls";
public static final String TEST_BAN_COMMAND_PERMISSION = "mineplex.core.antihack.testban";
private final Cache<String, Integer> _cooldown = CacheBuilder.newBuilder() private final Cache<String, Integer> _cooldown = CacheBuilder.newBuilder()
.concurrencyLevel(1) .concurrencyLevel(1)
@ -174,7 +183,7 @@ public class AntiHack extends MiniPlugin
{ {
player.spigot().sendMessage(detailed); player.spigot().sendMessage(detailed);
} }
else if (_clientManager.Get(player).GetRank().has(Rank.HELPER) && (violation.getOriginatingServer().equals(_thisServer) || _preferences.get(player).isActive(Preference.GLOBAL_GWEN_REPORTS))) else if (_clientManager.getPermissionManager().hasPermission(player, GroupPermission.of(SEE_ALERTS_PERMISSION)) && (violation.getOriginatingServer().equals(_thisServer) || _preferences.get(player).isActive(Preference.GLOBAL_GWEN_REPORTS)))
{ {
player.spigot().sendMessage(minimal); player.spigot().sendMessage(minimal);
} }
@ -182,6 +191,29 @@ public class AntiHack extends MiniPlugin
}); });
new GwenExtremePrejudice(UtilServer.getPlugin()); new GwenExtremePrejudice(UtilServer.getPlugin());
generatePermissions();
}
private void generatePermissions()
{
PermissionManager pm = _clientManager.getPermissionManager();
pm.setPermission(pm.getGroup("player"), GroupPermission.of(SEE_GUARDIANS_PERMISSION), true, true);
pm.setPermission(pm.getGroup("builder"), GroupPermission.of(SEE_GUARDIANS_PERMISSION), true, false);
pm.setPermission(pm.getGroup("admin"), GroupPermission.of(SEE_GUARDIANS_PERMISSION), true, true);
pm.setPermission(pm.getGroup("content"), GroupPermission.of(SILENTLY_BANNED_PERMISSION), true, true);
pm.setPermission(pm.getGroup("trainee"), GroupPermission.of(SILENTLY_BANNED_PERMISSION), true, true);
pm.setPermission(pm.getGroup("trainee"), GroupPermission.of(SEE_ALERTS_PERMISSION), true, true);
if (UtilServer.isTestServer())
{
pm.setPermission(pm.getGroup("dev"), GroupPermission.of(ANTICHEAT_TOGGLE_COMMAND_PERMISSION), true, true);
pm.setPermission(pm.getGroup("dev"), GroupPermission.of(TEST_BAN_COMMAND_PERMISSION), true, true);
}
pm.setPermission(pm.getGroup("dev"), GroupPermission.of(DETAILED_MESSAGES_COMMAND_PERMISSION), true, true);
pm.setPermission(pm.getGroup("dev"), GroupPermission.of(GET_VLS_COMMAND_PERMISSION), true, true);
} }
@Override @Override
@ -232,7 +264,7 @@ public class AntiHack extends MiniPlugin
{ {
runAsync(() -> runAsync(() ->
{ {
new GwenBanNotification(_thisServer, player.getName(), player.getUniqueId().toString(), coreClient.GetRank().name(), CheckManager.getCheckSimpleName(cause), id, gep).publish(); new GwenBanNotification(_thisServer, player.getName(), player.getUniqueId().toString(), coreClient.getPrimaryGroup().getIdentifier(), CheckManager.getCheckSimpleName(cause), id, gep).publish();
}); });
_punish.AddPunishment(coreClient.getName(), Category.Hacking, finalMessage, AntiHack.NAME, 3, true, hoursBanned, true, after); _punish.AddPunishment(coreClient.getName(), Category.Hacking, finalMessage, AntiHack.NAME, 3, true, hoursBanned, true, after);
@ -245,7 +277,7 @@ public class AntiHack extends MiniPlugin
} }
}; };
if (coreClient.GetRank().has(Rank.TWITCH)) if (_clientManager.getPermissionManager().hasPermission(player, GroupPermission.of(SILENTLY_BANNED_PERMISSION)))
{ {
doPunish.accept(result -> doPunish.accept(result ->
{ {
@ -294,7 +326,7 @@ public class AntiHack extends MiniPlugin
} }
}; };
if (coreClient.GetRank().has(Rank.TWITCH)) if (_clientManager.getPermissionManager().hasPermission(player, GroupPermission.of(SILENTLY_BANNED_PERMISSION)))
{ {
doPunish.accept(response -> {}); doPunish.accept(response -> {});
} }

View File

@ -66,7 +66,7 @@ public class BanWaveManager extends MiniPlugin
{ {
runAsync(() -> runAsync(() ->
{ {
new GwenBanwaveNotification(UtilServer.getServerName(), player.getName(), player.getUniqueId().toString(), client.GetRank().name(), CheckManager.getCheckSimpleName(checkClass), id, timeToBan).publish(); new GwenBanwaveNotification(UtilServer.getServerName(), player.getName(), player.getUniqueId().toString(), client.getPrimaryGroup().getIdentifier(), CheckManager.getCheckSimpleName(checkClass), id, timeToBan).publish();
}); });
JsonObject custom = new JsonObject(); JsonObject custom = new JsonObject();

View File

@ -4,7 +4,6 @@ import org.bukkit.entity.Player;
import mineplex.core.antihack.AntiHack; import mineplex.core.antihack.AntiHack;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
@ -12,7 +11,7 @@ public class AnticheatOffCommand extends CommandBase<AntiHack>
{ {
public AnticheatOffCommand(AntiHack plugin) public AnticheatOffCommand(AntiHack plugin)
{ {
super(plugin, Rank.DEVELOPER, "acoff"); super(plugin, AntiHack.ANTICHEAT_TOGGLE_COMMAND_PERMISSION, "acoff");
} }
@Override @Override
@ -21,4 +20,4 @@ public class AnticheatOffCommand extends CommandBase<AntiHack>
Plugin.disableAnticheat(); Plugin.disableAnticheat();
UtilPlayer.message(caller, F.main(Plugin.getName(), "Disabled anticheat")); UtilPlayer.message(caller, F.main(Plugin.getName(), "Disabled anticheat"));
} }
} }

View File

@ -4,7 +4,6 @@ import org.bukkit.entity.Player;
import mineplex.core.antihack.AntiHack; import mineplex.core.antihack.AntiHack;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
@ -12,7 +11,7 @@ public class AnticheatOnCommand extends CommandBase<AntiHack>
{ {
public AnticheatOnCommand(AntiHack plugin) public AnticheatOnCommand(AntiHack plugin)
{ {
super(plugin, Rank.DEVELOPER, "acon"); super(plugin, AntiHack.ANTICHEAT_TOGGLE_COMMAND_PERMISSION, "acon");
} }
@Override @Override
@ -21,4 +20,4 @@ public class AnticheatOnCommand extends CommandBase<AntiHack>
Plugin.enableAnticheat(); Plugin.enableAnticheat();
UtilPlayer.message(caller, F.main(Plugin.getName(), "Enabled anticheat")); UtilPlayer.message(caller, F.main(Plugin.getName(), "Enabled anticheat"));
} }
} }

View File

@ -4,7 +4,6 @@ import org.bukkit.entity.Player;
import mineplex.core.antihack.AntiHack; import mineplex.core.antihack.AntiHack;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
@ -12,7 +11,7 @@ public class DetailedMessagesCommand extends CommandBase<AntiHack>
{ {
public DetailedMessagesCommand(AntiHack plugin) public DetailedMessagesCommand(AntiHack plugin)
{ {
super(plugin, Rank.DEVELOPER, "detailedmessages"); super(plugin, AntiHack.DETAILED_MESSAGES_COMMAND_PERMISSION, "detailedmessages");
} }
@Override @Override
@ -27,4 +26,4 @@ public class DetailedMessagesCommand extends CommandBase<AntiHack>
UtilPlayer.message(caller, F.main(Plugin.getName(), "Detailed messages disabled")); UtilPlayer.message(caller, F.main(Plugin.getName(), "Detailed messages disabled"));
} }
} }
} }

View File

@ -9,7 +9,6 @@ import com.mineplex.anticheat.checks.CheckManager;
import mineplex.core.antihack.AntiHack; import mineplex.core.antihack.AntiHack;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
@ -17,7 +16,7 @@ public class GetVlsCommand extends CommandBase<AntiHack>
{ {
public GetVlsCommand(AntiHack plugin) public GetVlsCommand(AntiHack plugin)
{ {
super(plugin, Rank.DEVELOPER, "getvls"); super(plugin, AntiHack.GET_VLS_COMMAND_PERMISSION, "getvls");
} }
@Override @Override
@ -44,4 +43,4 @@ public class GetVlsCommand extends CommandBase<AntiHack>
UtilPlayer.message(caller, F.main(Plugin.getName(), "No player specified")); UtilPlayer.message(caller, F.main(Plugin.getName(), "No player specified"));
} }
} }
} }

View File

@ -8,7 +8,6 @@ import org.bukkit.entity.Player;
import mineplex.core.antihack.AntiHack; import mineplex.core.antihack.AntiHack;
import mineplex.core.antihack.animations.BanwaveAnimationSpin; import mineplex.core.antihack.animations.BanwaveAnimationSpin;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
@ -17,7 +16,7 @@ public class TestBanCommand extends CommandBase<AntiHack>
{ {
public TestBanCommand(AntiHack plugin) public TestBanCommand(AntiHack plugin)
{ {
super(plugin, Rank.DEVELOPER, "testban"); super(plugin, AntiHack.TEST_BAN_COMMAND_PERMISSION, "testban");
} }
@Override @Override
@ -48,4 +47,4 @@ public class TestBanCommand extends CommandBase<AntiHack>
UtilPlayer.message(caller, F.main(Plugin.getName(), "No player specified")); UtilPlayer.message(caller, F.main(Plugin.getName(), "No player specified"));
} }
} }
} }

View File

@ -1,16 +1,9 @@
package mineplex.core.antihack.guardians; package mineplex.core.antihack.guardians;
import com.mineplex.spigot.ChunkAddEntityEvent; import java.util.Random;
import mineplex.core.Managers; import java.util.UUID;
import mineplex.core.account.CoreClientManager; import java.util.function.Function;
import mineplex.core.common.Rank;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilServer;
import mineplex.core.disguise.DisguiseManager;
import mineplex.core.disguise.disguises.DisguiseGuardian;
import mineplex.core.event.StackerEvent;
import net.minecraft.server.v1_8_R3.EntityArmorStand;
import net.minecraft.server.v1_8_R3.EntityPlayer;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftArmorStand; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftArmorStand;
@ -23,9 +16,19 @@ import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.Random; import com.mineplex.spigot.ChunkAddEntityEvent;
import java.util.UUID;
import java.util.function.Function; import mineplex.core.Managers;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.permissions.GroupPermission;
import mineplex.core.antihack.AntiHack;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilServer;
import mineplex.core.disguise.DisguiseManager;
import mineplex.core.disguise.disguises.DisguiseGuardian;
import mineplex.core.event.StackerEvent;
import net.minecraft.server.v1_8_R3.EntityArmorStand;
import net.minecraft.server.v1_8_R3.EntityPlayer;
public class AntiHackGuardian implements Listener public class AntiHackGuardian implements Listener
{ {
@ -115,16 +118,10 @@ public class AntiHackGuardian implements Listener
if (!hideForStaff) return true; if (!hideForStaff) return true;
// Don't let Builder -> Admin see it // Don't let Builder -> Admin see it
Rank rank = clientManager.Get(player).GetRank(); if (!clientManager.getPermissionManager().hasPermission(player, GroupPermission.of(AntiHack.SEE_GUARDIANS_PERMISSION)))
if (rank.has(Rank.MAPDEV))
{ {
if (!rank.has(Rank.ADMIN))
{
return false;
}
}
if (rank == Rank.EVENT)
return false; return false;
}
return true; return true;
}); });
} }

View File

@ -1,14 +1,5 @@
package mineplex.core.antihack.guardians; package mineplex.core.antihack.guardians;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import mineplex.core.MiniPlugin;
import mineplex.core.PlayerSelector;
import mineplex.core.ReflectivelyCreateMiniPlugin;
import mineplex.core.common.Rank;
import mineplex.core.common.util.UtilLambda;
import org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -16,6 +7,18 @@ import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.Function; import java.util.function.Function;
import org.bukkit.entity.Player;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import mineplex.core.Managers;
import mineplex.core.MiniPlugin;
import mineplex.core.PlayerSelector;
import mineplex.core.ReflectivelyCreateMiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.UtilLambda;
@ReflectivelyCreateMiniPlugin @ReflectivelyCreateMiniPlugin
public class GuardianManager extends MiniPlugin public class GuardianManager extends MiniPlugin
{ {
@ -80,19 +83,18 @@ public class GuardianManager extends MiniPlugin
UtilLambda.and( UtilLambda.and(
PlayerSelector.NOT_VANISHED, PlayerSelector.NOT_VANISHED,
PlayerSelector.hasAnyRank(false, PlayerSelector.hasAnyRank(false,
Rank.ALL, Managers.get(CoreClientManager.class).getPermissionManager().getGroup("player"),
Rank.ULTRA, Managers.get(CoreClientManager.class).getPermissionManager().getGroup("ultra"),
Rank.HERO, Managers.get(CoreClientManager.class).getPermissionManager().getGroup("hero"),
Rank.LEGEND, Managers.get(CoreClientManager.class).getPermissionManager().getGroup("legend"),
Rank.TITAN, Managers.get(CoreClientManager.class).getPermissionManager().getGroup("titan"),
Rank.TWITCH, Managers.get(CoreClientManager.class).getPermissionManager().getGroup("twitch"),
Rank.YOUTUBE_SMALL, Managers.get(CoreClientManager.class).getPermissionManager().getGroup("yt"),
Rank.YOUTUBE, Managers.get(CoreClientManager.class).getPermissionManager().getGroup("youtube"),
Rank.MEDIA, Managers.get(CoreClientManager.class).getPermissionManager().getGroup("admin"),
Rank.ADMIN, Managers.get(CoreClientManager.class).getPermissionManager().getGroup("dev"),
Rank.DEVELOPER, Managers.get(CoreClientManager.class).getPermissionManager().getGroup("lt"),
Rank.OWNER, Managers.get(CoreClientManager.class).getPermissionManager().getGroup("owner")
Rank.LT
), ),
player -> !_stalking.contains(player.getUniqueId()), player -> !_stalking.contains(player.getUniqueId()),
player -> _stalkingCooldown.getIfPresent(player.getUniqueId()) == null player -> _stalkingCooldown.getIfPresent(player.getUniqueId()) == null
@ -126,4 +128,4 @@ public class GuardianManager extends MiniPlugin
{ {
_guardians.add(guardian); _guardians.add(guardian);
} }
} }

View File

@ -6,7 +6,6 @@ import java.nio.charset.StandardCharsets;
import java.util.Base64; import java.util.Base64;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -19,20 +18,18 @@ import org.tukaani.xz.XZOutputStream;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonNull; import com.google.gson.JsonNull;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.mineplex.anticheat.api.PlayerViolationEvent;
import com.mineplex.anticheat.checks.Check;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.account.permissions.GroupPermission;
import mineplex.core.account.permissions.PermissionManager;
import mineplex.core.antihack.AntiHack; import mineplex.core.antihack.AntiHack;
import mineplex.core.antihack.ViolationLevels;
import mineplex.core.antihack.logging.builtin.PartyInfoMetadata; import mineplex.core.antihack.logging.builtin.PartyInfoMetadata;
import mineplex.core.antihack.logging.builtin.PlayerInfoMetadata; import mineplex.core.antihack.logging.builtin.PlayerInfoMetadata;
import mineplex.core.antihack.logging.builtin.ServerInfoMetadata; import mineplex.core.antihack.logging.builtin.ServerInfoMetadata;
import mineplex.core.antihack.logging.builtin.ViolationInfoMetadata; import mineplex.core.antihack.logging.builtin.ViolationInfoMetadata;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilServer;
@ -41,6 +38,8 @@ import mineplex.core.common.util.UtilServer;
public class AntihackLogger extends MiniPlugin public class AntihackLogger extends MiniPlugin
{ {
public static final Gson GSON = new Gson(); public static final Gson GSON = new Gson();
private static final String SAVE_METADATA_COMMAND_PERMISSION = "mineplex.core.antihack.savemetadatacommand";
private final CoreClientManager _clientManager = require(CoreClientManager.class); private final CoreClientManager _clientManager = require(CoreClientManager.class);
@ -64,7 +63,9 @@ public class AntihackLogger extends MiniPlugin
{ {
if (UtilServer.isTestServer()) if (UtilServer.isTestServer())
{ {
addCommand(new CommandBase<AntihackLogger>(this, Rank.SNR_MODERATOR, "savemetadata") PermissionManager pm = _clientManager.getPermissionManager();
pm.setPermission(pm.getGroup("srmod"), GroupPermission.of(SAVE_METADATA_COMMAND_PERMISSION), true, true);
addCommand(new CommandBase<AntihackLogger>(this, SAVE_METADATA_COMMAND_PERMISSION, "savemetadata")
{ {
@Override @Override
public void Execute(Player caller, String[] args) public void Execute(Player caller, String[] args)
@ -139,13 +140,13 @@ public class AntihackLogger extends MiniPlugin
public void registerMetadata(AnticheatMetadata metadata) public void registerMetadata(AnticheatMetadata metadata)
{ {
if (!this._metadata.containsKey(metadata.getId())) if (!_metadata.containsKey(metadata.getId()))
{ {
this._metadata.put(metadata.getId(), metadata); _metadata.put(metadata.getId(), metadata);
} }
else else
{ {
throw new IllegalArgumentException("Attempting to register: " + metadata.getId()); throw new IllegalArgumentException("Attempting to register: " + metadata.getId());
} }
} }
} }

View File

@ -1,23 +1,27 @@
package mineplex.core.aprilfools; package mineplex.core.aprilfools;
import java.util.Map;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import mineplex.core.Managers;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.permissions.GroupPermission;
import mineplex.core.account.permissions.PermissionManager;
import mineplex.core.aprilfools.command.PirateSongCommand; import mineplex.core.aprilfools.command.PirateSongCommand;
import mineplex.core.common.Rank;
import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.twofactor.TwoFactorAuth; import mineplex.core.twofactor.TwoFactorAuth;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import java.util.Map;
public class AprilFoolsManager extends MiniPlugin public class AprilFoolsManager extends MiniPlugin
{ {
/** /**
* Manually can be toggled to enable or disable the April Fools activities. * Manually can be toggled to enable or disable the April Fools activities.
*/ */
@ -76,13 +80,8 @@ public class AprilFoolsManager extends MiniPlugin
.put("developer", "firstmate") .put("developer", "firstmate")
.put("admin", "firstmate") .put("admin", "firstmate")
.build(); .build();
private static final Map<Rank, String> RANK_REPLACEMENTS = ImmutableMap.<Rank, String>builder()
.put(Rank.ETERNAL, "Captain") public static final String PIRATE_SONG_COMMAND_PERMISSION = "mineplex.core.aprilfools.piratesong";
.put(Rank.TITAN, "FirstMate")
.put(Rank.LEGEND, "Boatswain")
.put(Rank.HERO, "Gunner")
.put(Rank.ULTRA, "Parrot")
.build();
private static AprilFoolsManager _instance; private static AprilFoolsManager _instance;
private final AprilFoolsRepository _repository; private final AprilFoolsRepository _repository;
@ -100,14 +99,14 @@ public class AprilFoolsManager extends MiniPlugin
_twoFA = require(TwoFactorAuth.class); _twoFA = require(TwoFactorAuth.class);
setEnabled(true); setEnabled(true);
_enabledTitle = UtilServer.isHubServer() || UtilServer.isTestServer(); _enabledTitle = UtilServer.isHubServer() || UtilServer.isTestServer();
if (_enabled) generatePermissions();
{ }
for (Map.Entry<Rank, String> entry : RANK_REPLACEMENTS.entrySet())
{ private void generatePermissions()
entry.getKey().setName(entry.getValue()); {
} PermissionManager pm = Managers.get(CoreClientManager.class).getPermissionManager();
} pm.setPermission(pm.getGroup("admin"), GroupPermission.of(PIRATE_SONG_COMMAND_PERMISSION), true, true);
} }
@Override @Override
@ -251,4 +250,4 @@ public class AprilFoolsManager extends MiniPlugin
return _instance; return _instance;
} }
} }

View File

@ -1,28 +1,28 @@
package mineplex.core.aprilfools.command; package mineplex.core.aprilfools.command;
import mineplex.core.aprilfools.AprilFoolsManager;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.UtilTextMiddle;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import mineplex.core.aprilfools.AprilFoolsManager;
import mineplex.core.command.CommandBase;
import mineplex.core.common.util.UtilTextMiddle;
public class PirateSongCommand extends CommandBase<AprilFoolsManager> public class PirateSongCommand extends CommandBase<AprilFoolsManager>
{ {
private static final String[] PIRATE_SONG =
private static final String[] PIRATE_SONG = { {
"Are you ready kids?", "Are you ready kids?",
"Aye aye captain!", "Aye aye captain!",
"I can't hear you!", "I can't hear you!",
"AYE AYE CAPTAIN!", "AYE AYE CAPTAIN!",
"OOOOOOOOOOOOH", "OOOOOOOOOOOOH",
"Who lives in a pineapple under the sea?", "Who lives in a pineapple under the sea?",
"Spongebob Squarepants!" "Spongebob Squarepants!"
}; };
public PirateSongCommand(AprilFoolsManager plugin) public PirateSongCommand(AprilFoolsManager plugin)
{ {
super(plugin, Rank.ADMIN, "piratesong"); super(plugin, AprilFoolsManager.PIRATE_SONG_COMMAND_PERMISSION, "piratesong");
} }
@Override @Override
@ -45,4 +45,4 @@ public class PirateSongCommand extends CommandBase<AprilFoolsManager>
} }
}, 20, 100); }, 20, 100);
} }
} }

View File

@ -12,7 +12,8 @@ import com.google.common.collect.ImmutableSet;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Rank; import mineplex.core.account.permissions.GroupPermission;
import mineplex.core.account.permissions.PermissionManager;
import mineplex.core.powerplayclub.PowerPlayClubRepository; import mineplex.core.powerplayclub.PowerPlayClubRepository;
public class BetaWhitelist extends MiniPlugin public class BetaWhitelist extends MiniPlugin
@ -40,6 +41,9 @@ public class BetaWhitelist extends MiniPlugin
.add(UUID.fromString("6795643a-2b61-41bf-9429-c7549fd128a8")) // umGim .add(UUID.fromString("6795643a-2b61-41bf-9429-c7549fd128a8")) // umGim
.add(UUID.fromString("47ba454a-4999-42f4-a269-2f4114ceb3c7")) // falconviii .add(UUID.fromString("47ba454a-4999-42f4-a269-2f4114ceb3c7")) // falconviii
.build(); .build();
private static final String BYPASS_WHITELIST_PERMISSION = "mineplex.core.beta.bypasswhitelist";
private final CoreClientManager _clientManager; private final CoreClientManager _clientManager;
private final PowerPlayClubRepository _powerPlayClubRepository; private final PowerPlayClubRepository _powerPlayClubRepository;
@ -48,14 +52,22 @@ public class BetaWhitelist extends MiniPlugin
super("Beta Whitelist"); super("Beta Whitelist");
_clientManager = clientManager; _clientManager = clientManager;
_powerPlayClubRepository = powerPlayRepository; _powerPlayClubRepository = powerPlayRepository;
generatePermissions();
}
private void generatePermissions()
{
PermissionManager pm = _clientManager.getPermissionManager();
pm.setPermission(pm.getGroup("ultra"), GroupPermission.of(BYPASS_WHITELIST_PERMISSION), true, true);
} }
@EventHandler @EventHandler
public void onJoin(PlayerJoinEvent event) public void onJoin(PlayerJoinEvent event)
{ {
Player player = event.getPlayer(); Player player = event.getPlayer();
Rank rank = _clientManager.Get(player).GetRank(true); if (_clientManager.getPermissionManager().hasPermission(player, GroupPermission.of(BYPASS_WHITELIST_PERMISSION)) // If this player is Ultra+
if (rank.has(Rank.ULTRA) // If this player is Ultra+
|| _powerPlayClubRepository.getCachedData(player).isSubscribed() // a PPC subscriber, || _powerPlayClubRepository.getCachedData(player).isSubscribed() // a PPC subscriber,
|| EXTRA_PLAYERS.contains(player.getUniqueId())) // or explicitly whitelisted, || EXTRA_PLAYERS.contains(player.getUniqueId())) // or explicitly whitelisted,
{ {
@ -65,4 +77,4 @@ public class BetaWhitelist extends MiniPlugin
// Otherwise, kick them out // Otherwise, kick them out
event.getPlayer().kickPlayer("Sorry, you aren't whitelisted on this beta server.\n\nSubscribe to " + ChatColor.GOLD + "Power Play Club " + ChatColor.WHITE + "at " + ChatColor.GREEN + "mineplex.com/shop" + ChatColor.WHITE + "!"); event.getPlayer().kickPlayer("Sorry, you aren't whitelisted on this beta server.\n\nSubscribe to " + ChatColor.GOLD + "Power Play Club " + ChatColor.WHITE + "at " + ChatColor.GREEN + "mineplex.com/shop" + ChatColor.WHITE + "!");
} }
} }

View File

@ -36,6 +36,8 @@ import mineplex.core.account.CoreClient;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.account.ILoginProcessor; import mineplex.core.account.ILoginProcessor;
import mineplex.core.account.event.ClientUnloadEvent; import mineplex.core.account.event.ClientUnloadEvent;
import mineplex.core.account.permissions.GroupPermission;
import mineplex.core.account.permissions.PermissionManager;
import mineplex.core.bonuses.animations.AnimationCarl; import mineplex.core.bonuses.animations.AnimationCarl;
import mineplex.core.bonuses.commands.AnimationCommand; import mineplex.core.bonuses.commands.AnimationCommand;
import mineplex.core.bonuses.commands.GuiCommand; import mineplex.core.bonuses.commands.GuiCommand;
@ -48,7 +50,6 @@ import mineplex.core.bonuses.gui.buttons.PowerPlayClubButton;
import mineplex.core.bonuses.redis.VoteHandler; import mineplex.core.bonuses.redis.VoteHandler;
import mineplex.core.bonuses.redis.VotifierCommand; import mineplex.core.bonuses.redis.VotifierCommand;
import mineplex.core.common.Pair; import mineplex.core.common.Pair;
import mineplex.core.common.Rank;
import mineplex.core.common.currency.GlobalCurrency; import mineplex.core.common.currency.GlobalCurrency;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback; import mineplex.core.common.util.Callback;
@ -93,6 +94,18 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
private static long timeOffSet = 0; private static long timeOffSet = 0;
public static final String ETERNAL_BONUS_PERMISSION = "mineplex.core.bonus.eternal";
public static final String TITAN_BONUS_PERMISSION = "mineplex.core.bonus.titan";
public static final String LEGEND_BONUS_PERMISSION = "mineplex.core.bonus.legend";
public static final String HERO_BONUS_PERMISSION = "mineplex.core.bonus.hero";
public static final String ULTRA_BONUS_PERMISSION = "mineplex.core.bonus.ultra";
public static final String MONTHLY_BONUS_PERMISSION = "mineplex.core.bonus.monthly";
public static final String ALLOW_COMMAND_PERMISSION = "mineplex.core.bonus.allowcommand";
public static final String ANIMATION_COMMAND_PERMISSION = "mineplex.core.bonus.animation";
public static final String GUI_COMMAND_PERMISSION = "mineplex.core.bonus.gui";
public static final String POWER_PLAY_COMMAND_PERMISSION = "mineplex.core.bonus.powerplay";
public static final String TICKET_COMMAND_PERMISSION = "mineplex.core.bonus.ticket";
private ArrayList<Object> _pendingExplosions = new ArrayList<>(); private ArrayList<Object> _pendingExplosions = new ArrayList<>();
private ArrayList<Player> _pendingExplosionsPlayers = new ArrayList<>(); private ArrayList<Player> _pendingExplosionsPlayers = new ArrayList<>();
private final Map<UUID, Pair<String, Integer>> _homeServerMap = new ConcurrentHashMap<>(); private final Map<UUID, Pair<String, Integer>> _homeServerMap = new ConcurrentHashMap<>();
@ -186,6 +199,8 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
_creeperName = "Carl"; _creeperName = "Carl";
updateOffSet(); updateOffSet();
generatePermissions();
} }
public BonusManager(JavaPlugin plugin, Location carlLocation, PlayWireManager playWireManager, CoreClientManager clientManager, DonationManager donationManager, PollManager pollManager, NpcManager npcManager, HologramManager hologramManager, StatsManager statsManager, InventoryManager inventoryManager, PetManager petManager, FacebookManager facebookManager, YoutubeManager youtubeManager, GadgetManager gadgetManager, ThankManager thankManager, String creeperName) public BonusManager(JavaPlugin plugin, Location carlLocation, PlayWireManager playWireManager, CoreClientManager clientManager, DonationManager donationManager, PollManager pollManager, NpcManager npcManager, HologramManager hologramManager, StatsManager statsManager, InventoryManager inventoryManager, PetManager petManager, FacebookManager facebookManager, YoutubeManager youtubeManager, GadgetManager gadgetManager, ThankManager thankManager, String creeperName)
@ -288,8 +303,26 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
} }
}); });
} }
generatePermissions();
}
private void generatePermissions()
{
PermissionManager pm = _clientManager.getPermissionManager();
pm.setPermission(pm.getGroup("ultra"), GroupPermission.of(MONTHLY_BONUS_PERMISSION), true, true);
pm.setPermission(pm.getGroup("ultra"), GroupPermission.of(ULTRA_BONUS_PERMISSION), true, true);
pm.setPermission(pm.getGroup("hero"), GroupPermission.of(HERO_BONUS_PERMISSION), true, true);
pm.setPermission(pm.getGroup("legend"), GroupPermission.of(LEGEND_BONUS_PERMISSION), true, true);
pm.setPermission(pm.getGroup("titan"), GroupPermission.of(TITAN_BONUS_PERMISSION), true, true);
pm.setPermission(pm.getGroup("eternal"), GroupPermission.of(ETERNAL_BONUS_PERMISSION), true, true);
//pm.setPermission(pm.getGroup("mod"), GroupPermission.of(ALLOW_COMMAND_PERMISSION), true, true);
pm.setPermission(pm.getGroup("dev"), GroupPermission.of(ANIMATION_COMMAND_PERMISSION), true, true);
pm.setPermission(pm.getGroup("dev"), GroupPermission.of(GUI_COMMAND_PERMISSION), true, true);
pm.setPermission(pm.getGroup("admin"), GroupPermission.of(POWER_PLAY_COMMAND_PERMISSION), true, true);
pm.setPermission(pm.getGroup("admin"), GroupPermission.of(TICKET_COMMAND_PERMISSION), true, true);
} }
@Override @Override
public void addCommands() public void addCommands()
@ -746,29 +779,27 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
public BonusAmount getRankBonusAmount(Player player) public BonusAmount getRankBonusAmount(Player player)
{ {
Rank rank = _clientManager.Get(player).GetRank();
BonusAmount data = new BonusAmount(); BonusAmount data = new BonusAmount();
if (rank.has(Rank.ETERNAL)) if (_clientManager.getPermissionManager().hasPermission(player, GroupPermission.of(ETERNAL_BONUS_PERMISSION)))
{ {
data.setIlluminatedChests(2); data.setIlluminatedChests(2);
data.setMythicalChests(2); data.setMythicalChests(2);
data.setOmegaChests(1); data.setOmegaChests(1);
} }
else if (rank.has(Rank.TITAN)) else if (_clientManager.getPermissionManager().hasPermission(player, GroupPermission.of(TITAN_BONUS_PERMISSION)))
{ {
data.setMythicalChests(5); data.setMythicalChests(5);
} }
else if (rank.has(Rank.LEGEND)) else if (_clientManager.getPermissionManager().hasPermission(player, GroupPermission.of(LEGEND_BONUS_PERMISSION)))
{ {
data.setMythicalChests(3); data.setMythicalChests(3);
} }
else if (rank.has(Rank.HERO)) else if (_clientManager.getPermissionManager().hasPermission(player, GroupPermission.of(HERO_BONUS_PERMISSION)))
{ {
data.setMythicalChests(2); data.setMythicalChests(2);
} }
else if (rank.has(Rank.ULTRA)) else if (_clientManager.getPermissionManager().hasPermission(player, GroupPermission.of(ULTRA_BONUS_PERMISSION)))
{ {
data.setMythicalChests(1); data.setMythicalChests(1);
} }
@ -984,16 +1015,15 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
if (canVote(player)) availableRewards++; if (canVote(player)) availableRewards++;
if (_playWireManager.Get(player) != null && _playWireManager.Get(player).getAccountId() != -1 && _playWireManager.canRedeemTickets(_playWireManager.Get(player))) availableRewards++; if (_playWireManager.Get(player) != null && _playWireManager.Get(player).getAccountId() != -1 && _playWireManager.canRedeemTickets(_playWireManager.Get(player))) availableRewards++;
if (_youtubeManager.canYoutube(player)) availableRewards++; if (_youtubeManager.canYoutube(player)) availableRewards++;
if (canRank(player) && _clientManager.hasRank(player, Rank.ULTRA) && isPastAugust()) availableRewards++; if (canRank(player) && _clientManager.getPermissionManager().hasPermission(player, GroupPermission.of(MONTHLY_BONUS_PERMISSION)) && isPastAugust()) availableRewards++;
if (canDaily(player)) availableRewards++; if (canDaily(player)) availableRewards++;
if (getPollManager().getNextPoll(_pollManager.Get(player), _clientManager.Get(player).GetRank()) != null) availableRewards++; if (getPollManager().getNextPoll(_pollManager.Get(player), _clientManager.Get(player).getPrimaryGroup()) != null) availableRewards++;
if (!_facebookManager.hasRedeemed(player)) availableRewards++; if (!_facebookManager.hasRedeemed(player)) availableRewards++;
if (_thankManager.Get(player).getThankToClaim() > 0) availableRewards++; if (_thankManager.Get(player).getThankToClaim() > 0) availableRewards++;
if (PowerPlayClubButton.isAvailable(player, _powerPlayClubRepository)) availableRewards++; if (PowerPlayClubButton.isAvailable(player, _powerPlayClubRepository)) availableRewards++;
Hologram hologram; Hologram hologram;
if (client.getHologram() == null) if (client.getHologram() == null)
{ {
double yAdd = 2.3; double yAdd = 2.3;
@ -1090,7 +1120,9 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
final BonusClientData clientData = Get(event.getUniqueId()); final BonusClientData clientData = Get(event.getUniqueId());
if (clientData.getHologram() != null) if (clientData.getHologram() != null)
{
clientData.getHologram().stop(); clientData.getHologram().stop();
}
// Save streaks // Save streaks
runAsync(() -> _repository.saveStreak(clientData.getAccountId(), clientData)); runAsync(() -> _repository.saveStreak(clientData.getAccountId(), clientData));
@ -1143,12 +1175,14 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
{ {
if (Recharge.Instance.use(player, "Carl Inform", 240000, false, false)) if (Recharge.Instance.use(player, "Carl Inform", 240000, false, false))
{ {
if (_pollManager.hasPoll(player) || canVote(player) || _youtubeManager.canYoutube(player) || (_playWireManager.Get(player) != null && _playWireManager.Get(player).getAccountId() != -1 && _playWireManager.canRedeemTickets(_playWireManager.Get(player))) || (canRank(player) && _clientManager.hasRank(player, Rank.ULTRA) && isPastAugust()) || canDaily(player) || PowerPlayClubButton.isAvailable(player, _powerPlayClubRepository)) if (_pollManager.hasPoll(player) || canVote(player) || _youtubeManager.canYoutube(player) || (_playWireManager.Get(player) != null && _playWireManager.Get(player).getAccountId() != -1 && _playWireManager.canRedeemTickets(_playWireManager.Get(player))) || (canRank(player) && _clientManager.getPermissionManager().hasPermission(player, GroupPermission.of(MONTHLY_BONUS_PERMISSION)) && isPastAugust()) || canDaily(player) || PowerPlayClubButton.isAvailable(player, _powerPlayClubRepository))
{ {
if (_showCarl.containsKey(player.getName())) if (_showCarl.containsKey(player.getName()))
{ {
if (_plugin.getClass().getSimpleName().equalsIgnoreCase("Hub") || _plugin.getClass().getSimpleName().equalsIgnoreCase("ClansHub")) if (_plugin.getClass().getSimpleName().equalsIgnoreCase("Hub") || _plugin.getClass().getSimpleName().equalsIgnoreCase("ClansHub"))
{
UtilPlayer.message(player, C.cDGreen + C.Bold + _creeperName + " the Creeper>" + C.cGreen + " Hey " + player.getName().replace("s", "sss") + "! I have sssome amazing rewardsss for you! Come sssee me!"); UtilPlayer.message(player, C.cDGreen + C.Bold + _creeperName + " the Creeper>" + C.cGreen + " Hey " + player.getName().replace("s", "sss") + "! I have sssome amazing rewardsss for you! Come sssee me!");
}
} }
} }
} }
@ -1232,4 +1266,4 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
{ {
return _carlNpc; return _carlNpc;
} }
} }

View File

@ -1,16 +1,14 @@
package mineplex.core.bonuses.commands; package mineplex.core.bonuses.commands;
import java.util.Arrays; import org.bukkit.entity.Player;
import mineplex.core.bonuses.BonusManager; import mineplex.core.bonuses.BonusManager;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.command.CommandCenter; import mineplex.core.command.CommandCenter;
import mineplex.core.command.ICommand; import mineplex.core.command.ICommand;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import org.bukkit.entity.Player;
/** /**
* Allows players to run rank-specific commands * Allows players to run rank-specific commands
@ -18,12 +16,11 @@ import org.bukkit.entity.Player;
*/ */
public class AllowCommand extends CommandBase<BonusManager> public class AllowCommand extends CommandBase<BonusManager>
{ {
private BonusManager _plugin; private BonusManager _plugin;
public AllowCommand(BonusManager plugin) public AllowCommand(BonusManager plugin)
{ {
super(plugin, Rank.MODERATOR, "allowCommand", "allowCmd"); super(plugin, BonusManager.ALLOW_COMMAND_PERMISSION, "allowCommand", "allowCmd");
_plugin = plugin; _plugin = plugin;
} }
@ -42,9 +39,7 @@ public class AllowCommand extends CommandBase<BonusManager>
return; return;
} }
ICommand iCommand = commands.get(args[1]); ICommand iCommand = commands.get(args[1]);
Rank playerRank = _plugin.getClientManager().Get(caller).GetRank(); if (!_plugin.getClientManager().getPermissionManager().hasPermission(caller, iCommand.getPermission()))
if (playerRank.compareTo(iCommand.GetRequiredRank()) > 0
&& Arrays.asList(iCommand.GetSpecificRanks()).contains(playerRank))
{ {
UtilPlayer.message(caller, F.main("Allow Command", "You're not allowed to use that command!")); UtilPlayer.message(caller, F.main("Allow Command", "You're not allowed to use that command!"));
return; return;
@ -79,5 +74,4 @@ public class AllowCommand extends CommandBase<BonusManager>
UtilPlayer.message(caller, F.main("Allow Command", "You allowed the player " + F.name(receiver.getName()) + " to use the command " + F.elem(args[1]) + "!")); UtilPlayer.message(caller, F.main("Allow Command", "You allowed the player " + F.name(receiver.getName()) + " to use the command " + F.elem(args[1]) + "!"));
UtilPlayer.message(receiver, F.main("Allow Command", "The player " + F.name(caller.getName()) + " allowed you to use the command " + F.elem(args[1]) + "!")); UtilPlayer.message(receiver, F.main("Allow Command", "The player " + F.name(caller.getName()) + " allowed you to use the command " + F.elem(args[1]) + "!"));
} }
}
}

View File

@ -3,10 +3,9 @@ package mineplex.core.bonuses.commands;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.reward.RewardType;
import mineplex.core.bonuses.BonusManager; import mineplex.core.bonuses.BonusManager;
import mineplex.core.command.CommandBase;
import mineplex.core.reward.RewardType;
public class AnimationCommand extends CommandBase<BonusManager>{ public class AnimationCommand extends CommandBase<BonusManager>{
@ -14,7 +13,7 @@ public class AnimationCommand extends CommandBase<BonusManager>{
public AnimationCommand(BonusManager plugin) public AnimationCommand(BonusManager plugin)
{ {
super(plugin, Rank.DEVELOPER, "animation"); super(plugin, BonusManager.ANIMATION_COMMAND_PERMISSION, "animation");
_plugin = plugin; _plugin = plugin;
} }
@ -30,5 +29,4 @@ public class AnimationCommand extends CommandBase<BonusManager>{
} }
} }
} }

View File

@ -2,22 +2,20 @@ package mineplex.core.bonuses.commands;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.bonuses.BonusManager; import mineplex.core.bonuses.BonusManager;
import mineplex.core.bonuses.gui.BonusGui; import mineplex.core.bonuses.gui.BonusGui;
import mineplex.core.command.CommandBase;
public class GuiCommand extends CommandBase<BonusManager> public class GuiCommand extends CommandBase<BonusManager>
{ {
public GuiCommand(BonusManager plugin) public GuiCommand(BonusManager plugin)
{ {
super(plugin, Rank.DEVELOPER, "bonus"); super(plugin, BonusManager.GUI_COMMAND_PERMISSION, "bonus");
} }
@Override @Override
public void Execute(Player caller, String[] args) public void Execute(Player caller, String[] args)
{ {
new BonusGui(Plugin.getPlugin(), caller, Plugin, Plugin.getRewardManager(), Plugin.getFacebookManager(), Plugin.getYoutubeManager(), Plugin.getThankManager(), Plugin.getPlayWireManager()).openInventory(); new BonusGui(Plugin.getPlugin(), caller, Plugin, Plugin.getRewardManager(), Plugin.getFacebookManager(), Plugin.getYoutubeManager(), Plugin.getThankManager(), Plugin.getPlayWireManager()).openInventory();
} }
}
}

View File

@ -1,26 +1,25 @@
package mineplex.core.bonuses.commands; package mineplex.core.bonuses.commands;
import mineplex.core.bonuses.BonusManager;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.powerplayclub.PowerPlayData;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.YearMonth; import java.time.YearMonth;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import mineplex.core.bonuses.BonusManager;
import mineplex.core.command.CommandBase;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.powerplayclub.PowerPlayData;
public class PowerPlayCommand extends CommandBase<BonusManager> public class PowerPlayCommand extends CommandBase<BonusManager>
{ {
private BonusManager _bonusManager; private BonusManager _bonusManager;
public PowerPlayCommand(BonusManager manager) public PowerPlayCommand(BonusManager manager)
{ {
super(manager, Rank.JNR_DEV, "powerplay"); super(manager, BonusManager.POWER_PLAY_COMMAND_PERMISSION, "powerplay");
_bonusManager = manager; _bonusManager = manager;
} }
@ -45,4 +44,4 @@ public class PowerPlayCommand extends CommandBase<BonusManager>
caller.sendMessage(ChatColor.GREEN + "Gave a month's subscription to " + player.getName()); caller.sendMessage(ChatColor.GREEN + "Gave a month's subscription to " + player.getName());
} }
} }

View File

@ -1,19 +1,18 @@
package mineplex.core.bonuses.commands; package mineplex.core.bonuses.commands;
import org.bukkit.entity.Player;
import mineplex.core.bonuses.BonusManager;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.Callback; import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.bonuses.BonusManager;
import org.bukkit.entity.Player;
public class TicketCommand extends CommandBase<BonusManager> public class TicketCommand extends CommandBase<BonusManager>
{ {
public TicketCommand(BonusManager plugin) public TicketCommand(BonusManager plugin)
{ {
super(plugin, Rank.ADMIN, "ticket"); super(plugin, BonusManager.TICKET_COMMAND_PERMISSION, "ticket");
} }
@Override @Override
@ -65,4 +64,4 @@ public class TicketCommand extends CommandBase<BonusManager>
UtilPlayer.message(caller, F.main("Carl", "Invalid Ticket Amount")); UtilPlayer.message(caller, F.main("Carl", "Invalid Ticket Amount"));
} }
} }
} }

View File

@ -2,6 +2,15 @@ package mineplex.core.bonuses.gui.buttons;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.bonuses.BonusAmount; import mineplex.core.bonuses.BonusAmount;
@ -19,14 +28,6 @@ import mineplex.core.poll.Poll;
import mineplex.core.poll.PollManager; import mineplex.core.poll.PollManager;
import mineplex.core.recharge.Recharge; import mineplex.core.recharge.Recharge;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
public class PollButton extends SimpleGui implements GuiItem { public class PollButton extends SimpleGui implements GuiItem {
protected boolean _create; protected boolean _create;
@ -56,7 +57,7 @@ public class PollButton extends SimpleGui implements GuiItem {
{ {
if (_create) if (_create)
{ {
this._poll = _pollManager.getNextPoll(_pollManager.Get(getPlayer()), _clientManager.Get(getPlayer()).GetRank()); _poll = _pollManager.getNextPoll(_pollManager.Get(getPlayer()), _clientManager.Get(getPlayer()).getPrimaryGroup());
if (_poll != null) if (_poll != null)
{ {
@ -77,7 +78,7 @@ public class PollButton extends SimpleGui implements GuiItem {
@Override @Override
public ItemStack getObject() public ItemStack getObject()
{ {
ArrayList<String> lore = new ArrayList<>(); List<String> lore = new ArrayList<>();
if (_poll == null) if (_poll == null)
{ {
lore.add(""); lore.add("");
@ -128,14 +129,15 @@ public class PollButton extends SimpleGui implements GuiItem {
public GuiItem getQuestionItem(String question) public GuiItem getQuestionItem(String question)
{ {
List<String> lore = new ArrayList<>();
ArrayList<String> lore = new ArrayList<>();
lore.add(""); lore.add("");
for (String string : wrap(question)) for (String string : wrap(question))
{
lore.add(C.cWhite + string); lore.add(C.cWhite + string);
}
lore.add(""); lore.add("");
int i = 1; int i = 1;
for(String str : _poll.getAnswers()) for (String str : _poll.getAnswers())
{ {
lore.add(C.cAqua + "" + i + ".) " + C.cWhite + str); lore.add(C.cAqua + "" + i + ".) " + C.cWhite + str);
i++; i++;
@ -181,21 +183,20 @@ public class PollButton extends SimpleGui implements GuiItem {
private class AnswerItem implements GuiItem private class AnswerItem implements GuiItem
{ {
private int _num;
private int num;
private AnswerItem(Poll poll, int num) private AnswerItem(Poll poll, int num)
{ {
this.num = num; _num = num;
} }
@Override @Override
public ItemStack getObject() public ItemStack getObject()
{ {
ArrayList<String> lore = new ArrayList<>(); List<String> lore = new ArrayList<>();
lore.add(""); lore.add("");
lore.add(C.cWhite + getPoll().getAnswers()[num]); lore.add(C.cWhite + getPoll().getAnswers()[_num]);
return ItemStackFactory.Instance.CreateStack(Material.EMERALD, (byte) 0, 1, ChatColor.GREEN + "Option " + (num + 1), lore); return ItemStackFactory.Instance.CreateStack(Material.EMERALD, (byte) 0, 1, ChatColor.GREEN + "Option " + (_num + 1), lore);
} }
@Override @Override
@ -208,11 +209,11 @@ public class PollButton extends SimpleGui implements GuiItem {
_create = true; _create = true;
_pollManager.answerPoll(getPlayer(), _poll, num + 1); _pollManager.answerPoll(getPlayer(), _poll, _num + 1);
getPlayer().playSound(getPlayer().getLocation(), Sound.NOTE_PLING, 1, 1.6f); getPlayer().playSound(getPlayer().getLocation(), Sound.NOTE_PLING, 1, 1.6f);
new TimedMessageWindow(getPlugin(), getPlayer(), ItemStackFactory.Instance.CreateStack(Material.EMERALD_BLOCK, (byte) 0, 1, ChatColor.GREEN + "Your anwser:", wrap(getPoll().getAnswers()[num])), ChatColor.GREEN + "Moo", 6 * 9, 50, getMaster()).openInventory(); new TimedMessageWindow(getPlugin(), getPlayer(), ItemStackFactory.Instance.CreateStack(Material.EMERALD_BLOCK, (byte) 0, 1, ChatColor.GREEN + "Your anwser:", wrap(getPoll().getAnswers()[_num])), ChatColor.GREEN + "Moo", 6 * 9, 50, getMaster()).openInventory();
_bonusManager.addPendingExplosion(getPlayer(), "POLL"); _bonusManager.addPendingExplosion(getPlayer(), "POLL");
getPlayer().closeInventory(); getPlayer().closeInventory();
} }
@ -227,4 +228,4 @@ public class PollButton extends SimpleGui implements GuiItem {
@Override @Override
public void close() {} public void close() {}
} }

View File

@ -187,7 +187,7 @@ public class RankBonusButton implements GuiItem, Listener {
} }
lore.add(" "); lore.add(" ");
lore.add(C.cYellow + "Rank: " + C.cWhite + _bonusManager.getClientManager().Get(_player).GetRank().Name); lore.add(C.cYellow + "Rank: " + C.cWhite + _bonusManager.getClientManager().Get(_player).getPrimaryGroup().getDisplay(false, false, false, true));
BonusAmount bonusAmount = _bonusManager.getRankBonusAmount(_player); BonusAmount bonusAmount = _bonusManager.getRankBonusAmount(_player);
bonusAmount.addLore(lore); bonusAmount.addLore(lore);
} }

View File

@ -1,7 +1,29 @@
package mineplex.core.boosters; package mineplex.core.boosters;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.account.permissions.GroupPermission;
import mineplex.core.account.permissions.PermissionManager;
import mineplex.core.boosters.command.BoosterCommand; import mineplex.core.boosters.command.BoosterCommand;
import mineplex.core.boosters.event.BoosterActivateEvent; import mineplex.core.boosters.event.BoosterActivateEvent;
import mineplex.core.boosters.event.BoosterExpireEvent; import mineplex.core.boosters.event.BoosterExpireEvent;
@ -21,18 +43,6 @@ import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.thank.ThankManager; import mineplex.core.thank.ThankManager;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.*;
/** /**
* BoosterManager handles the majority of logic for creating and getting Boosters. Every BoosterManager stores a cache * BoosterManager handles the majority of logic for creating and getting Boosters. Every BoosterManager stores a cache
@ -58,6 +68,12 @@ public class BoosterManager extends MiniPlugin
public static final ItemStack INTERFACE_ITEM = ItemStackFactory.Instance.CreateStack(Material.EMERALD, (byte)0, 1, ChatColor.RESET + C.cGreen + "Game Amplifiers"); public static final ItemStack INTERFACE_ITEM = ItemStackFactory.Instance.CreateStack(Material.EMERALD, (byte)0, 1, ChatColor.RESET + C.cGreen + "Game Amplifiers");
// Slot for the booster gui item // Slot for the booster gui item
public static final int INTERFACE_SLOT = 7; public static final int INTERFACE_SLOT = 7;
public static final String ADD_BOOSTER_COMMAND_PERMISSION = "mineplex.core.booster.add";
public static final String BOOSTER_COMMAND_PERMISSION = "mineplex.core.booster.command";
public static final String BOOSTER_GUI_COMMAND_PERMISSION = "mineplex.core.booster.gui";
public static final String RELOAD_BOOSTERS_COMMAND_PERMISSION = "mineplex.core.booster.reload";
public static final String THANK_COMMAND_PERMISSION = "mineplex.core.booster.thank";
private BoosterRepository _repository; private BoosterRepository _repository;
private CoreClientManager _clientManager; private CoreClientManager _clientManager;
@ -100,6 +116,19 @@ public class BoosterManager extends MiniPlugin
_giveInterfaceItem = canActivateBoosters(); _giveInterfaceItem = canActivateBoosters();
new BoosterUpdateRepository(plugin); new BoosterUpdateRepository(plugin);
generatePermissions();
}
private void generatePermissions()
{
PermissionManager pm = _clientManager.getPermissionManager();
pm.setPermission(pm.getGroup("player"), GroupPermission.of(BOOSTER_COMMAND_PERMISSION), true, true);
pm.setPermission(pm.getGroup("player"), GroupPermission.of(THANK_COMMAND_PERMISSION), true, true);
pm.setPermission(pm.getGroup("dev"), GroupPermission.of(ADD_BOOSTER_COMMAND_PERMISSION), true, true);
pm.setPermission(pm.getGroup("dev"), GroupPermission.of(RELOAD_BOOSTERS_COMMAND_PERMISSION), true, true);
pm.setPermission(pm.getGroup("dev"), GroupPermission.of(BOOSTER_GUI_COMMAND_PERMISSION), true, true);
} }
@Override @Override
@ -397,4 +426,4 @@ public class BoosterManager extends MiniPlugin
{ {
runSync(() -> getPluginManager().callEvent(event)); runSync(() -> getPluginManager().callEvent(event));
} }
} }

View File

@ -1,13 +1,14 @@
package mineplex.core.boosters.command; package mineplex.core.boosters.command;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import mineplex.core.boosters.BoosterApiResponse; import mineplex.core.boosters.BoosterApiResponse;
import mineplex.core.boosters.BoosterManager; import mineplex.core.boosters.BoosterManager;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.Callback; import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import org.bukkit.entity.Player;
/** /**
* @author Shaun Bennett * @author Shaun Bennett
@ -16,7 +17,7 @@ public class AddCommand extends CommandBase<BoosterManager>
{ {
public AddCommand(BoosterManager plugin) public AddCommand(BoosterManager plugin)
{ {
super(plugin, Rank.DEVELOPER, "add"); super(plugin, BoosterManager.ADD_BOOSTER_COMMAND_PERMISSION, "add");
} }
@Override @Override
@ -49,6 +50,6 @@ public class AddCommand extends CommandBase<BoosterManager>
private void help(Player caller) private void help(Player caller)
{ {
UtilPlayer.message(caller, F.help("amplifier add <servergroup>", "Add an amplifier to that server group", Rank.DEVELOPER)); UtilPlayer.message(caller, F.help("amplifier add <servergroup>", "Add an amplifier to that server group", ChatColor.DARK_RED));
} }
} }

View File

@ -1,12 +1,12 @@
package mineplex.core.boosters.command; package mineplex.core.boosters.command;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import mineplex.core.boosters.BoosterManager; import mineplex.core.boosters.BoosterManager;
import mineplex.core.command.CommandBase;
import mineplex.core.command.MultiCommandBase; import mineplex.core.command.MultiCommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import org.bukkit.entity.Player;
/** /**
* @author Shaun Bennett * @author Shaun Bennett
@ -15,7 +15,7 @@ public class BoosterCommand extends MultiCommandBase<BoosterManager>
{ {
public BoosterCommand(BoosterManager plugin) public BoosterCommand(BoosterManager plugin)
{ {
super(plugin, Rank.ALL, "amplifier"); super(plugin, BoosterManager.BOOSTER_COMMAND_PERMISSION, "amplifier");
AddCommand(new AddCommand(plugin)); AddCommand(new AddCommand(plugin));
AddCommand(new GuiCommand(plugin)); AddCommand(new GuiCommand(plugin));
@ -26,8 +26,8 @@ public class BoosterCommand extends MultiCommandBase<BoosterManager>
@Override @Override
protected void Help(Player caller, String[] args) protected void Help(Player caller, String[] args)
{ {
UtilPlayer.message(caller, F.help("amplifier add <group>", "Add an amplifier to that group", Rank.DEVELOPER)); UtilPlayer.message(caller, F.help("amplifier add <group>", "Add an amplifier to that group", ChatColor.DARK_RED));
UtilPlayer.message(caller, F.help("amplifier gui", "Open Amplifier GUI", Rank.DEVELOPER)); UtilPlayer.message(caller, F.help("amplifier gui", "Open Amplifier GUI", ChatColor.DARK_RED));
UtilPlayer.message(caller, F.help("amplifier thank <group>", "Thank an Amplifier for a specific Booster Group", Rank.ALL)); UtilPlayer.message(caller, F.help("amplifier thank <group>", "Thank an Amplifier for a specific Booster Group", ChatColor.WHITE));
} }
} }

View File

@ -1,9 +1,9 @@
package mineplex.core.boosters.command; package mineplex.core.boosters.command;
import org.bukkit.entity.Player;
import mineplex.core.boosters.BoosterManager; import mineplex.core.boosters.BoosterManager;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import org.bukkit.entity.Player;
/** /**
* @author Shaun Bennett * @author Shaun Bennett
@ -12,7 +12,7 @@ public class GuiCommand extends CommandBase<BoosterManager>
{ {
public GuiCommand(BoosterManager plugin) public GuiCommand(BoosterManager plugin)
{ {
super(plugin, Rank.DEVELOPER, "gui"); super(plugin, BoosterManager.BOOSTER_GUI_COMMAND_PERMISSION, "gui");
} }
@Override @Override
@ -20,4 +20,4 @@ public class GuiCommand extends CommandBase<BoosterManager>
{ {
Plugin.openShop(caller); Plugin.openShop(caller);
} }
} }

View File

@ -1,16 +1,11 @@
package mineplex.core.boosters.command; package mineplex.core.boosters.command;
import mineplex.core.boosters.Booster;
import mineplex.core.boosters.BoosterManager;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.List; import mineplex.core.boosters.BoosterManager;
import java.util.Map; import mineplex.core.command.CommandBase;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
/** /**
* @author Shaun Bennett * @author Shaun Bennett
@ -19,17 +14,18 @@ public class ReloadCommand extends CommandBase<BoosterManager>
{ {
public ReloadCommand(BoosterManager plugin) public ReloadCommand(BoosterManager plugin)
{ {
super(plugin, Rank.DEVELOPER, "reload"); super(plugin, BoosterManager.RELOAD_BOOSTERS_COMMAND_PERMISSION, "reload");
} }
@Override @Override
public void Execute(Player caller, String[] args) public void Execute(Player caller, String[] args)
{ {
Plugin.getBoostersAsync(data -> { Plugin.getBoostersAsync(data ->
{
if (data != null) if (data != null)
{ {
UtilPlayer.message(caller, F.main("Amplifier", "Amplifiers reloaded!")); UtilPlayer.message(caller, F.main("Amplifier", "Amplifiers reloaded!"));
} }
}); });
} }
} }

View File

@ -1,17 +1,17 @@
package mineplex.core.boosters.command; package mineplex.core.boosters.command;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import mineplex.core.boosters.Booster; import mineplex.core.boosters.Booster;
import mineplex.core.boosters.BoosterManager; import mineplex.core.boosters.BoosterManager;
import mineplex.core.boosters.tips.BoosterThankManager; import mineplex.core.boosters.tips.BoosterThankManager;
import mineplex.core.boosters.tips.TipAddResult; import mineplex.core.boosters.tips.TipAddResult;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.currency.GlobalCurrency; import mineplex.core.common.currency.GlobalCurrency;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
/** /**
* @author Shaun Bennett * @author Shaun Bennett
@ -20,7 +20,7 @@ public class ThankCommand extends CommandBase<BoosterManager>
{ {
public ThankCommand(BoosterManager plugin) public ThankCommand(BoosterManager plugin)
{ {
super(plugin, Rank.ALL, "thank"); super(plugin, BoosterManager.THANK_COMMAND_PERMISSION, "thank");
} }
@Override @Override
@ -71,4 +71,4 @@ public class ThankCommand extends CommandBase<BoosterManager>
}); });
} }
} }
} }

View File

@ -11,23 +11,31 @@ import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Rank; import mineplex.core.account.permissions.GroupPermission;
import mineplex.core.account.permissions.PermissionManager;
import mineplex.core.botspam.command.BotSpamCommand;
import mineplex.core.botspam.repository.BotSpamRepository;
import mineplex.core.message.PrivateMessageEvent; import mineplex.core.message.PrivateMessageEvent;
import mineplex.core.punish.Category; import mineplex.core.punish.Category;
import mineplex.core.punish.Punish; import mineplex.core.punish.Punish;
import mineplex.core.botspam.command.BotSpamCommand;
import mineplex.core.botspam.repository.BotSpamRepository;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import mineplex.serverdata.commands.ServerCommandManager; import mineplex.serverdata.commands.ServerCommandManager;
public class BotSpamManager extends MiniPlugin public class BotSpamManager extends MiniPlugin
{ {
public static final String BYPASS_BOTSPAM_PERMISSION = "mineplex.core.botspam.bypass";
public static final String BOTSPAM_COMMAND_PERMISSION = "mineplex.core.botspam.command";
public static final String ADD_BOTSPAM_COMMAND_PERMISSION = "mineplex.core.botspam.add";
public static final String TOGGLE_BOTSPAM_COMMAND_PERMISSION = "mineplex.core.botspam.toggle";
public static final String UPDATE_BOTSPAM_COMMAND_PERMISSION = "mineplex.core.botspam.update";
public static final String LIST_BOTSPAM_COMMAND_PERMISSION = "mineplex.core.botspam.list";
private Punish _punish; private Punish _punish;
private CoreClientManager _clientManager; private CoreClientManager _clientManager;
private BotSpamRepository _repository; private BotSpamRepository _repository;
private volatile ArrayList<SpamText> _spam = new ArrayList<SpamText>(); private volatile List<SpamText> _spam = new ArrayList<>();
public BotSpamManager(JavaPlugin plugin, CoreClientManager clientManager, Punish punish) public BotSpamManager(JavaPlugin plugin, CoreClientManager clientManager, Punish punish)
{ {
@ -39,6 +47,20 @@ public class BotSpamManager extends MiniPlugin
_spam = _repository.getSpamText(); _spam = _repository.getSpamText();
ServerCommandManager.getInstance().registerCommandType(ForceUpdateCommand.class, command -> runAsync(() -> _spam = _repository.getSpamText())); ServerCommandManager.getInstance().registerCommandType(ForceUpdateCommand.class, command -> runAsync(() -> _spam = _repository.getSpamText()));
generatePermissions();
}
private void generatePermissions()
{
PermissionManager pm = _clientManager.getPermissionManager();
pm.setPermission(pm.getGroup("trainee"), GroupPermission.of(BYPASS_BOTSPAM_PERMISSION), true, true);
pm.setPermission(pm.getGroup("admin"), GroupPermission.of(BOTSPAM_COMMAND_PERMISSION), true, true);
pm.setPermission(pm.getGroup("admin"), GroupPermission.of(ADD_BOTSPAM_COMMAND_PERMISSION), true, true);
pm.setPermission(pm.getGroup("admin"), GroupPermission.of(TOGGLE_BOTSPAM_COMMAND_PERMISSION), true, true);
pm.setPermission(pm.getGroup("admin"), GroupPermission.of(UPDATE_BOTSPAM_COMMAND_PERMISSION), true, true);
pm.setPermission(pm.getGroup("admin"), GroupPermission.of(LIST_BOTSPAM_COMMAND_PERMISSION), true, true);
} }
@EventHandler @EventHandler
@ -46,11 +68,11 @@ public class BotSpamManager extends MiniPlugin
{ {
Player recipient = event.getRecipient(); Player recipient = event.getRecipient();
// Ignore messages sent to staff members // Ignore messages sent to staff members
if (_clientManager.hasRank(recipient, Rank.HELPER)) if (_clientManager.getPermissionManager().hasPermission(recipient, GroupPermission.of(BYPASS_BOTSPAM_PERMISSION)))
return; return;
// Ignore messages sent by staff members // Ignore messages sent by staff members
if (_clientManager.hasRank(event.getSender(), Rank.HELPER)) if (_clientManager.getPermissionManager().hasPermission(event.getSender(), GroupPermission.of(BYPASS_BOTSPAM_PERMISSION)))
return; return;
for (SpamText spamText : _spam) for (SpamText spamText : _spam)
@ -68,7 +90,7 @@ public class BotSpamManager extends MiniPlugin
public void onChat(final AsyncPlayerChatEvent event) public void onChat(final AsyncPlayerChatEvent event)
{ {
// Ignore messages sent by staff members // Ignore messages sent by staff members
if (_clientManager.hasRank(event.getPlayer(), Rank.HELPER)) if (_clientManager.getPermissionManager().hasPermission(event.getPlayer(), GroupPermission.of(BYPASS_BOTSPAM_PERMISSION)))
return; return;
for (final SpamText spamText : _spam) for (final SpamText spamText : _spam)
@ -98,7 +120,9 @@ public class BotSpamManager extends MiniPlugin
_spam = _repository.getSpamText(); _spam = _repository.getSpamText();
if (callback != null) if (callback != null)
{
runSync(callback); runSync(callback);
}
}); });
} }
@ -114,7 +138,9 @@ public class BotSpamManager extends MiniPlugin
spamText.setEnabledBy(caller); spamText.setEnabledBy(caller);
if (callback != null) if (callback != null)
{
callback.run(); callback.run();
}
}); });
}); });
} }
@ -131,7 +157,9 @@ public class BotSpamManager extends MiniPlugin
spamText.setDisabledBy(caller); spamText.setDisabledBy(caller);
if (callback != null) if (callback != null)
{
callback.run(); callback.run();
}
}); });
}); });
} }
@ -155,4 +183,4 @@ public class BotSpamManager extends MiniPlugin
{ {
addCommand(new BotSpamCommand(this)); addCommand(new BotSpamCommand(this));
} }
} }

View File

@ -3,18 +3,17 @@ package mineplex.core.botspam.command;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import mineplex.core.botspam.BotSpamManager;
import mineplex.core.botspam.SpamText; import mineplex.core.botspam.SpamText;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.botspam.BotSpamManager;
public class BotSpamAddCommand extends CommandBase<BotSpamManager> public class BotSpamAddCommand extends CommandBase<BotSpamManager>
{ {
public BotSpamAddCommand(BotSpamManager plugin) public BotSpamAddCommand(BotSpamManager plugin)
{ {
super(plugin, Rank.ADMIN, "add"); super(plugin, BotSpamManager.ADD_BOTSPAM_COMMAND_PERMISSION, "add");
} }
@Override @Override
@ -50,4 +49,4 @@ public class BotSpamAddCommand extends CommandBase<BotSpamManager>
UtilPlayer.message(caller, F.main("BotSpam", "/botspam add <text>")); UtilPlayer.message(caller, F.main("BotSpam", "/botspam add <text>"));
} }
} }
} }

View File

@ -4,7 +4,6 @@ import org.bukkit.entity.Player;
import mineplex.core.botspam.BotSpamManager; import mineplex.core.botspam.BotSpamManager;
import mineplex.core.command.MultiCommandBase; import mineplex.core.command.MultiCommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
@ -12,7 +11,7 @@ public class BotSpamCommand extends MultiCommandBase<BotSpamManager>
{ {
public BotSpamCommand(BotSpamManager plugin) public BotSpamCommand(BotSpamManager plugin)
{ {
super(plugin, Rank.ADMIN, "botban", "botspam"); super(plugin, BotSpamManager.BOTSPAM_COMMAND_PERMISSION, "botban", "botspam");
AddCommand(new BotSpamAddCommand(Plugin)); AddCommand(new BotSpamAddCommand(Plugin));
AddCommand(new BotSpamEnableCommand(Plugin)); AddCommand(new BotSpamEnableCommand(Plugin));
@ -30,4 +29,4 @@ public class BotSpamCommand extends MultiCommandBase<BotSpamManager>
UtilPlayer.message(caller, F.main("BotSpam", "/botspam disable <text id>")); UtilPlayer.message(caller, F.main("BotSpam", "/botspam disable <text id>"));
UtilPlayer.message(caller, F.main("BotSpam", "/botspam globalupdate")); UtilPlayer.message(caller, F.main("BotSpam", "/botspam globalupdate"));
} }
} }

View File

@ -2,10 +2,9 @@ package mineplex.core.botspam.command;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import mineplex.core.botspam.BotSpamManager;
import mineplex.core.botspam.SpamText; import mineplex.core.botspam.SpamText;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.botspam.BotSpamManager;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
@ -13,7 +12,7 @@ public class BotSpamDisableCommand extends CommandBase<BotSpamManager>
{ {
public BotSpamDisableCommand(BotSpamManager plugin) public BotSpamDisableCommand(BotSpamManager plugin)
{ {
super(plugin, Rank.ADMIN, "disable"); super(plugin, BotSpamManager.TOGGLE_BOTSPAM_COMMAND_PERMISSION, "disable");
} }
@Override @Override
@ -59,6 +58,5 @@ public class BotSpamDisableCommand extends CommandBase<BotSpamManager>
{ {
UtilPlayer.message(caller, F.main("BotSpam", "/botspam disable <text id>")); UtilPlayer.message(caller, F.main("BotSpam", "/botspam disable <text id>"));
} }
} }
} }

View File

@ -2,10 +2,9 @@ package mineplex.core.botspam.command;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import mineplex.core.botspam.BotSpamManager;
import mineplex.core.botspam.SpamText; import mineplex.core.botspam.SpamText;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.botspam.BotSpamManager;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
@ -13,7 +12,7 @@ public class BotSpamEnableCommand extends CommandBase<BotSpamManager>
{ {
public BotSpamEnableCommand(BotSpamManager plugin) public BotSpamEnableCommand(BotSpamManager plugin)
{ {
super(plugin, Rank.ADMIN, "enable"); super(plugin, BotSpamManager.TOGGLE_BOTSPAM_COMMAND_PERMISSION, "enable");
} }
@Override @Override
@ -59,6 +58,5 @@ public class BotSpamEnableCommand extends CommandBase<BotSpamManager>
{ {
UtilPlayer.message(caller, F.main("BotSpam", "/botspam enable <text id>")); UtilPlayer.message(caller, F.main("BotSpam", "/botspam enable <text id>"));
} }
} }
} }

View File

@ -4,9 +4,7 @@ import org.bukkit.entity.Player;
import mineplex.core.botspam.BotSpamManager; import mineplex.core.botspam.BotSpamManager;
import mineplex.core.botspam.ForceUpdateCommand; import mineplex.core.botspam.ForceUpdateCommand;
import mineplex.core.botspam.SpamText;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.serverdata.commands.ServerCommandManager; import mineplex.serverdata.commands.ServerCommandManager;
@ -15,7 +13,7 @@ public class BotSpamGlobalUpdateCommand extends CommandBase<BotSpamManager>
{ {
public BotSpamGlobalUpdateCommand(BotSpamManager plugin) public BotSpamGlobalUpdateCommand(BotSpamManager plugin)
{ {
super(plugin, Rank.ADMIN, "globalupdate"); super(plugin, BotSpamManager.UPDATE_BOTSPAM_COMMAND_PERMISSION, "globalupdate");
} }
@Override @Override
@ -24,4 +22,4 @@ public class BotSpamGlobalUpdateCommand extends CommandBase<BotSpamManager>
ServerCommandManager.getInstance().publishCommand(new ForceUpdateCommand()); ServerCommandManager.getInstance().publishCommand(new ForceUpdateCommand());
UtilPlayer.message(caller, F.main("Botspam", "Forced an update across all servers!")); UtilPlayer.message(caller, F.main("Botspam", "Forced an update across all servers!"));
} }
} }

View File

@ -3,28 +3,26 @@ package mineplex.core.botspam.command;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import mineplex.core.botspam.BotSpamManager; import mineplex.core.botspam.BotSpamManager;
import mineplex.core.botspam.SpamText; import mineplex.core.botspam.SpamText;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
public class BotSpamListCommand extends CommandBase<BotSpamManager> public class BotSpamListCommand extends CommandBase<BotSpamManager>
{ {
public BotSpamListCommand(BotSpamManager plugin) public BotSpamListCommand(BotSpamManager plugin)
{ {
super(plugin, Rank.ADMIN, "list"); super(plugin, BotSpamManager.LIST_BOTSPAM_COMMAND_PERMISSION, "list");
} }
@Override @Override
@ -207,4 +205,4 @@ public class BotSpamListCommand extends CommandBase<BotSpamManager>
caller.spigot().sendMessage(pageSwitch.create()); caller.spigot().sendMessage(pageSwitch.create());
} }
} }

View File

@ -1,25 +1,26 @@
package mineplex.core.chat; package mineplex.core.chat;
import mineplex.core.MiniPlugin; import java.io.BufferedReader;
import mineplex.core.account.CoreClientManager; import java.io.DataOutputStream;
import mineplex.core.achievement.AchievementManager; import java.io.IOException;
import mineplex.core.antispam.AntiSpamManager; import java.io.InputStreamReader;
import mineplex.core.chat.command.BroadcastCommand; import java.net.URL;
import mineplex.core.chat.command.ChatSlowCommand; import java.nio.charset.Charset;
import mineplex.core.chat.command.SilenceCommand; import java.security.cert.X509Certificate;
import mineplex.core.common.Rank; import java.util.ArrayList;
import mineplex.core.common.util.C; import java.util.HashMap;
import mineplex.core.common.util.F; import java.util.List;
import mineplex.core.common.util.UtilPlayer; import java.util.Map;
import mineplex.core.common.util.UtilServer; import java.util.UUID;
import mineplex.core.common.util.UtilText; import java.util.function.Function;
import mineplex.core.common.util.UtilTime;
import mineplex.core.incognito.IncognitoManager; import javax.net.ssl.HostnameVerifier;
import mineplex.core.preferences.Preference; import javax.net.ssl.HttpsURLConnection;
import mineplex.core.preferences.PreferencesManager; import javax.net.ssl.SSLContext;
import mineplex.core.recharge.Recharge; import javax.net.ssl.SSLSession;
import mineplex.core.updater.UpdateType; import javax.net.ssl.TrustManager;
import mineplex.core.updater.event.UpdateEvent; import javax.net.ssl.X509TrustManager;
import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.Validate;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -34,28 +35,40 @@ import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue; import org.json.simple.JSONValue;
import javax.net.ssl.HostnameVerifier; import mineplex.core.MiniPlugin;
import javax.net.ssl.HttpsURLConnection; import mineplex.core.account.CoreClientManager;
import javax.net.ssl.SSLContext; import mineplex.core.account.permissions.GroupPermission;
import javax.net.ssl.SSLSession; import mineplex.core.account.permissions.PermissionManager;
import javax.net.ssl.TrustManager; import mineplex.core.achievement.AchievementManager;
import javax.net.ssl.X509TrustManager; import mineplex.core.chat.command.BroadcastCommand;
import java.io.BufferedReader; import mineplex.core.chat.command.ChatSlowCommand;
import java.io.DataOutputStream; import mineplex.core.chat.command.SilenceCommand;
import java.io.IOException; import mineplex.core.common.util.C;
import java.io.InputStreamReader; import mineplex.core.common.util.F;
import java.net.URL; import mineplex.core.common.util.UtilPlayer;
import java.nio.charset.Charset; import mineplex.core.common.util.UtilServer;
import java.security.cert.X509Certificate; import mineplex.core.common.util.UtilText;
import java.util.ArrayList; import mineplex.core.common.util.UtilTime;
import java.util.HashMap; import mineplex.core.incognito.IncognitoManager;
import java.util.Iterator; import mineplex.core.preferences.Preference;
import java.util.List; import mineplex.core.preferences.PreferencesManager;
import java.util.UUID; import mineplex.core.recharge.Recharge;
import java.util.function.Function; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
public class Chat extends MiniPlugin public class Chat extends MiniPlugin
{ {
public static final String ALLOW_CAPS_PERMISSION = "mineplex.core.chat.allowcaps";
public static final String BYPASS_COOLDOWN_PERMISSION = "mineplex.core.chat.bypasscooldown";
public static final String BYPASS_SLOW_PERMISSION = "mineplex.core.chat.bypasschatslow";
public static final String BYPASS_SILENCE_PERMISSION = "mineplex.core.chat.bypasssilence";
public static final String BYPASS_SIGNS_PERMISSION = "mineplex.core.chat.bypasssigns";
public static final String ALLOW_HACKUSATE_PERMISSION = "mineplex.core.chat.allowhackusate";
public static final String ALLOW_SIMILAR_PERMISSION = "mineplex.core.chat.allowsimilar";
public static final String SILENCE_COMMAND_PERMISSION = "mineplex.core.chat.silence";
public static final String SLOW_CHAT_COMMAND_PERMISSION = "mineplex.core.chat.chatslow";
public static final String BROADCAST_COMMAND_PERMISSION = "mineplex.core.chat.broadcast";
private CoreClientManager _clientManager; private CoreClientManager _clientManager;
private PreferencesManager _preferences; private PreferencesManager _preferences;
private AchievementManager _achievements; private AchievementManager _achievements;
@ -73,7 +86,7 @@ public class Chat extends MiniPlugin
private List<Function<AsyncPlayerChatEvent, Boolean>> _highPriorityFilters = new ArrayList<>(); private List<Function<AsyncPlayerChatEvent, Boolean>> _highPriorityFilters = new ArrayList<>();
private List<Function<AsyncPlayerChatEvent, Boolean>> _lowPriorityFilters = new ArrayList<>(); private List<Function<AsyncPlayerChatEvent, Boolean>> _lowPriorityFilters = new ArrayList<>();
private HashMap<UUID, MessageData> _playerLastMessage = new HashMap<UUID, MessageData>(); private Map<UUID, MessageData> _playerLastMessage = new HashMap<>();
public Chat(JavaPlugin plugin, IncognitoManager incognitoManager, CoreClientManager clientManager, PreferencesManager preferences, AchievementManager achievements, String serverName) public Chat(JavaPlugin plugin, IncognitoManager incognitoManager, CoreClientManager clientManager, PreferencesManager preferences, AchievementManager achievements, String serverName)
{ {
@ -93,6 +106,23 @@ public class Chat extends MiniPlugin
{ {
e.printStackTrace(); e.printStackTrace();
} }
generatePermissions();
}
private void generatePermissions()
{
PermissionManager pm = _clientManager.getPermissionManager();
pm.setPermission(pm.getGroup("admin"), GroupPermission.of(ALLOW_CAPS_PERMISSION), true, true);
pm.setPermission(pm.getGroup("mod"), GroupPermission.of(BYPASS_COOLDOWN_PERMISSION), true, true);
pm.setPermission(pm.getGroup("trainee"), GroupPermission.of(BYPASS_SLOW_PERMISSION), true, true);
pm.setPermission(pm.getGroup("mod"), GroupPermission.of(BYPASS_SILENCE_PERMISSION), true, true);
pm.setPermission(pm.getGroup("admin"), GroupPermission.of(BYPASS_SIGNS_PERMISSION), true, true);
pm.setPermission(pm.getGroup("trainee"), GroupPermission.of(ALLOW_HACKUSATE_PERMISSION), true, true);
pm.setPermission(pm.getGroup("mod"), GroupPermission.of(ALLOW_SIMILAR_PERMISSION), true, true);
pm.setPermission(pm.getGroup("admin"), GroupPermission.of(SILENCE_COMMAND_PERMISSION), true, true);
pm.setPermission(pm.getGroup("srmod"), GroupPermission.of(SLOW_CHAT_COMMAND_PERMISSION), true, true);
pm.setPermission(pm.getGroup("mod"), GroupPermission.of(BROADCAST_COMMAND_PERMISSION), true, true);
} }
@Override @Override
@ -190,7 +220,7 @@ public class Chat extends MiniPlugin
if (_silenced == 0) if (_silenced == 0)
return false; return false;
if (_clientManager.Get(player).GetRank().has(player, Rank.MODERATOR, false)) if (_clientManager.getPermissionManager().hasPermission(player, GroupPermission.of(BYPASS_SILENCE_PERMISSION)))
return false; return false;
if (_silenced == -1) if (_silenced == -1)
@ -208,7 +238,10 @@ public class Chat extends MiniPlugin
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onSignChange(SignChangeEvent event) public void onSignChange(SignChangeEvent event)
{ {
if (_clientManager.Get(event.getPlayer()).GetRank().has(Rank.ADMIN)) return; if (_clientManager.getPermissionManager().hasPermission(event.getPlayer(), GroupPermission.of(BYPASS_SIGNS_PERMISSION)))
{
return;
}
// Prevent silenced players from using signs // Prevent silenced players from using signs
if (SilenceCheck(event.getPlayer())) if (SilenceCheck(event.getPlayer()))
@ -343,13 +376,13 @@ public class Chat extends MiniPlugin
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
else if (!_clientManager.Get(sender).GetRank().has(Rank.MODERATOR) && else if (!_clientManager.getPermissionManager().hasPermission(sender, GroupPermission.of(BYPASS_COOLDOWN_PERMISSION)) &&
!Recharge.Instance.use(sender, "Chat Message", 400, false, false)) !Recharge.Instance.use(sender, "Chat Message", 400, false, false))
{ {
UtilPlayer.message(sender, F.main("Chat", "You are sending messages too fast.")); UtilPlayer.message(sender, F.main("Chat", "You are sending messages too fast."));
event.setCancelled(true); event.setCancelled(true);
} }
else if (!_clientManager.Get(sender).GetRank().has(Rank.HELPER) && else if (!_clientManager.getPermissionManager().hasPermission(sender, GroupPermission.of(ALLOW_HACKUSATE_PERMISSION)) &&
msgContainsHack(event.getMessage())) msgContainsHack(event.getMessage()))
{ {
UtilPlayer.message(sender, F.main("Chat", UtilPlayer.message(sender, F.main("Chat",
@ -363,12 +396,12 @@ public class Chat extends MiniPlugin
MessageData lastMessage = _playerLastMessage.get(sender.getUniqueId()); MessageData lastMessage = _playerLastMessage.get(sender.getUniqueId());
long chatSlowTime = 1000L * _chatSlow; long chatSlowTime = 1000L * _chatSlow;
long timeDiff = System.currentTimeMillis() - lastMessage.getTimeSent(); long timeDiff = System.currentTimeMillis() - lastMessage.getTimeSent();
if (timeDiff < chatSlowTime && !_clientManager.Get(sender).GetRank().has(Rank.HELPER)) if (timeDiff < chatSlowTime && !_clientManager.getPermissionManager().hasPermission(sender, GroupPermission.of(BYPASS_SLOW_PERMISSION)))
{ {
UtilPlayer.message(sender, F.main("Chat", "Chat slow enabled. Please wait " + F.time(UtilTime.convertString(chatSlowTime - timeDiff, 1, UtilTime.TimeUnit.FIT)))); UtilPlayer.message(sender, F.main("Chat", "Chat slow enabled. Please wait " + F.time(UtilTime.convertString(chatSlowTime - timeDiff, 1, UtilTime.TimeUnit.FIT))));
event.setCancelled(true); event.setCancelled(true);
} }
else if (!_clientManager.Get(sender).GetRank().has(Rank.MODERATOR) && else if (!_clientManager.getPermissionManager().hasPermission(sender, GroupPermission.of(ALLOW_SIMILAR_PERMISSION)) &&
UtilText.isStringSimilar(event.getMessage(), lastMessage.getMessage(), 0.8f)) UtilText.isStringSimilar(event.getMessage(), lastMessage.getMessage(), 0.8f))
{ {
UtilPlayer.message(sender, F.main("Chat", "This message is too similar to your previous message.")); UtilPlayer.message(sender, F.main("Chat", "This message is too similar to your previous message."));
@ -379,7 +412,7 @@ public class Chat extends MiniPlugin
if (!event.isCancelled()) if (!event.isCancelled())
{ {
String oldMessage = event.getMessage(); String oldMessage = event.getMessage();
if (!_clientManager.Get(sender).GetRank().has(Rank.ADMIN)) if (!_clientManager.getPermissionManager().hasPermission(sender, GroupPermission.of(ALLOW_CAPS_PERMISSION)))
{ {
int capsCount = 0; int capsCount = 0;
for (char c : oldMessage.toCharArray()) for (char c : oldMessage.toCharArray())
@ -669,5 +702,4 @@ public class Chat extends MiniPlugin
_lowPriorityFilters.add(restriction); _lowPriorityFilters.add(restriction);
} }
} }
}
}

View File

@ -4,7 +4,6 @@ import org.bukkit.entity.Player;
import mineplex.core.chat.Chat; import mineplex.core.chat.Chat;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilServer;
@ -13,7 +12,7 @@ public class BroadcastCommand extends CommandBase<Chat>
{ {
public BroadcastCommand(Chat plugin) public BroadcastCommand(Chat plugin)
{ {
super(plugin, Rank.MODERATOR, "s"); super(plugin, Chat.BROADCAST_COMMAND_PERMISSION, "s");
} }
@Override @Override
@ -35,4 +34,4 @@ public class BroadcastCommand extends CommandBase<Chat>
UtilServer.broadcast(caller.getName(), announcement); UtilServer.broadcast(caller.getName(), announcement);
} }
} }

View File

@ -4,7 +4,6 @@ import org.bukkit.entity.Player;
import mineplex.core.chat.Chat; import mineplex.core.chat.Chat;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
@ -12,7 +11,7 @@ public class ChatSlowCommand extends CommandBase<Chat>
{ {
public ChatSlowCommand(Chat plugin) public ChatSlowCommand(Chat plugin)
{ {
super(plugin, Rank.SNR_MODERATOR, "chatslow"); super(plugin, Chat.SLOW_CHAT_COMMAND_PERMISSION, "chatslow");
} }
@Override @Override
@ -48,4 +47,4 @@ public class ChatSlowCommand extends CommandBase<Chat>
{ {
UtilPlayer.message(caller, F.main("Chat", "Usage: /chatslow <seconds>")); UtilPlayer.message(caller, F.main("Chat", "Usage: /chatslow <seconds>"));
} }
} }

View File

@ -4,7 +4,6 @@ import org.bukkit.entity.Player;
import mineplex.core.chat.Chat; import mineplex.core.chat.Chat;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
@ -12,7 +11,7 @@ public class SilenceCommand extends CommandBase<Chat>
{ {
public SilenceCommand(Chat plugin) public SilenceCommand(Chat plugin)
{ {
super(plugin, Rank.ADMIN, "silence"); super(plugin, Chat.SILENCE_COMMAND_PERMISSION, "silence");
} }
@Override @Override
@ -47,4 +46,4 @@ public class SilenceCommand extends CommandBase<Chat>
UtilPlayer.message(caller, F.main("Chat", "Invalid Time Parameter.")); UtilPlayer.message(caller, F.main("Chat", "Invalid Time Parameter."));
} }
} }
} }

View File

@ -11,6 +11,8 @@ import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.account.permissions.GroupPermission;
import mineplex.core.account.permissions.PermissionManager;
import mineplex.core.chatsnap.command.ChatSnapCommand; import mineplex.core.chatsnap.command.ChatSnapCommand;
import mineplex.core.message.PrivateMessageEvent; import mineplex.core.message.PrivateMessageEvent;
@ -19,6 +21,8 @@ import mineplex.core.message.PrivateMessageEvent;
*/ */
public class SnapshotPlugin extends MiniPlugin public class SnapshotPlugin extends MiniPlugin
{ {
public static final String CHAT_SNAP_COMMAND_PERMISSION = "mineplex.core.chatsnap.command";
private final SnapshotManager _snapshotManager; private final SnapshotManager _snapshotManager;
private final CoreClientManager _clientManager; private final CoreClientManager _clientManager;
@ -27,6 +31,15 @@ public class SnapshotPlugin extends MiniPlugin
super("ChatSnap", plugin); super("ChatSnap", plugin);
_snapshotManager = snapshotManager; _snapshotManager = snapshotManager;
_clientManager = clientManager; _clientManager = clientManager;
generatePermissions();
}
private void generatePermissions()
{
PermissionManager pm = _clientManager.getPermissionManager();
pm.setPermission(pm.getGroup("titan"), GroupPermission.of(CHAT_SNAP_COMMAND_PERMISSION), true, true);
} }
public SnapshotManager getSnapshotManager() public SnapshotManager getSnapshotManager()
@ -79,4 +92,4 @@ public class SnapshotPlugin extends MiniPlugin
String message = e.getMessage(); String message = e.getMessage();
return new SnapshotMessage(senderId, recipientId, message); return new SnapshotMessage(senderId, recipientId, message);
} }
} }

View File

@ -9,7 +9,6 @@ import mineplex.core.chatsnap.SnapshotMessage;
import mineplex.core.chatsnap.SnapshotPlugin; import mineplex.core.chatsnap.SnapshotPlugin;
import mineplex.core.chatsnap.SnapshotRepository; import mineplex.core.chatsnap.SnapshotRepository;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.jsonchat.ClickEvent; import mineplex.core.common.jsonchat.ClickEvent;
import mineplex.core.common.jsonchat.JsonMessage; import mineplex.core.common.jsonchat.JsonMessage;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
@ -23,7 +22,7 @@ public class ChatSnapCommand extends CommandBase<SnapshotPlugin>
{ {
public ChatSnapCommand(SnapshotPlugin plugin) public ChatSnapCommand(SnapshotPlugin plugin)
{ {
super(plugin, Rank.TITAN, "chatsnap"); super(plugin, SnapshotPlugin.CHAT_SNAP_COMMAND_PERMISSION, "chatsnap");
} }
@Override @Override
@ -68,4 +67,4 @@ public class ChatSnapCommand extends CommandBase<SnapshotPlugin>
UtilPlayer.message(player, F.main(Plugin.getName(), C.cRed + "Invalid Usage: " + F.elem("/" + _aliasUsed))); UtilPlayer.message(player, F.main(Plugin.getName(), C.cRed + "Invalid Usage: " + F.elem("/" + _aliasUsed)));
} }
} }
} }

View File

@ -15,34 +15,23 @@ import org.bukkit.entity.Player;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.PlayerSelector; import mineplex.core.PlayerSelector;
import mineplex.core.common.Rank; import mineplex.core.account.permissions.GroupPermission;
import mineplex.core.common.util.UtilLambda; import mineplex.core.common.util.UtilLambda;
import mineplex.core.recharge.Recharge; import mineplex.core.recharge.Recharge;
public abstract class CommandBase<PluginType extends MiniPlugin> implements ICommand public abstract class CommandBase<PluginType extends MiniPlugin> implements ICommand
{ {
private Rank _requiredRank; private final GroupPermission _permission;
private Rank[] _specificRank;
private List<String> _aliases; private List<String> _aliases;
protected PluginType Plugin; protected PluginType Plugin;
protected String _aliasUsed; protected String _aliasUsed;
protected CommandCenter _commandCenter; protected CommandCenter _commandCenter;
public CommandBase(PluginType plugin, Rank requiredRank, String... aliases) public CommandBase(PluginType plugin, String permission, String... aliases)
{ {
Plugin = plugin; Plugin = plugin;
_requiredRank = requiredRank; _permission = GroupPermission.of(permission);
_aliases = Arrays.asList(aliases);
}
public CommandBase(PluginType plugin, Rank requiredRank, Rank[] specificRank, String... aliases)
{
Plugin = plugin;
_requiredRank = requiredRank;
_specificRank = specificRank;
_aliases = Arrays.asList(aliases); _aliases = Arrays.asList(aliases);
} }
@ -56,19 +45,9 @@ public abstract class CommandBase<PluginType extends MiniPlugin> implements ICom
_aliasUsed = alias; _aliasUsed = alias;
} }
public Rank GetRequiredRank() public GroupPermission getPermission()
{ {
return _requiredRank; return _permission;
}
public void setRequiredRank(Rank rank)
{
_requiredRank = rank;
}
public Rank[] GetSpecificRanks()
{
return _specificRank;
} }
public void SetCommandCenter(CommandCenter commandCenter) public void SetCommandCenter(CommandCenter commandCenter)
@ -158,4 +137,4 @@ public abstract class CommandBase<PluginType extends MiniPlugin> implements ICom
} }
return null; return null;
} }
} }

View File

@ -1,17 +1,11 @@
package mineplex.core.command; package mineplex.core.command;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import net.minecraft.server.v1_8_R3.PacketPlayInTabComplete;
import net.minecraft.server.v1_8_R3.PacketPlayOutTabComplete;
import net.minecraft.server.v1_8_R3.PlayerConnection;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -22,15 +16,19 @@ import com.google.common.collect.Lists;
import mineplex.core.Managers; import mineplex.core.Managers;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Rank; import mineplex.core.account.permissions.GroupPermission;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilPlayerBase;
import mineplex.core.packethandler.IPacketHandler; import mineplex.core.packethandler.IPacketHandler;
import mineplex.core.packethandler.PacketHandler; import mineplex.core.packethandler.PacketHandler;
import mineplex.core.packethandler.PacketInfo; import mineplex.core.packethandler.PacketInfo;
import mineplex.core.recharge.Recharge; import mineplex.core.recharge.Recharge;
import net.minecraft.server.v1_8_R3.PacketPlayInTabComplete;
import net.minecraft.server.v1_8_R3.PacketPlayOutTabComplete;
import net.minecraft.server.v1_8_R3.PlayerConnection;
public class CommandCenter implements Listener, IPacketHandler public class CommandCenter implements Listener, IPacketHandler
{ {
@ -45,6 +43,8 @@ public class CommandCenter implements Listener, IPacketHandler
private final PacketHandler _packetHandler = Managers.require(PacketHandler.class); private final PacketHandler _packetHandler = Managers.require(PacketHandler.class);
private static AtomicIntegerFieldUpdater<PlayerConnection> chatSpamField = null; private static AtomicIntegerFieldUpdater<PlayerConnection> chatSpamField = null;
public static final String BLOCKED_COMMAND_PERMISSION = "mineplex.core.command.blockedexecute";
static static
{ {
@ -83,6 +83,8 @@ public class CommandCenter implements Listener, IPacketHandler
public void setClientManager(CoreClientManager clientManager) public void setClientManager(CoreClientManager clientManager)
{ {
ClientManager = clientManager; ClientManager = clientManager;
clientManager.getPermissionManager().setPermission(clientManager.getPermissionManager().getGroup("dev"), GroupPermission.of(BLOCKED_COMMAND_PERMISSION), true, true);
} }
@EventHandler @EventHandler
@ -104,7 +106,7 @@ public class CommandCenter implements Listener, IPacketHandler
{ {
event.setCancelled(true); event.setCancelled(true);
if (ClientManager.Get(event.getPlayer()).GetRank().has(event.getPlayer(), command.GetRequiredRank(), command.GetSpecificRanks(), true) if (ClientManager.getPermissionManager().hasPermission(event.getPlayer(), command.getPermission())
|| UtilPlayer.isCommandAllowed(event.getPlayer(), commandName.toLowerCase())) || UtilPlayer.isCommandAllowed(event.getPlayer(), commandName.toLowerCase()))
{ {
if (!Recharge.Instance.use(event.getPlayer(), "Command", 500, false, false)) if (!Recharge.Instance.use(event.getPlayer(), "Command", 500, false, false))
@ -122,10 +124,14 @@ public class CommandCenter implements Listener, IPacketHandler
command.Execute(event.getPlayer(), args); command.Execute(event.getPlayer(), args);
} }
else
{
UtilPlayerBase.message(event.getPlayer(), C.mHead + "Permissions> " + C.mBody + "You do not have permission for that.");
}
return; return;
} }
if (BLOCKED_COMMANDS.contains(commandName.toLowerCase()) && !(event.getPlayer().isOp() || ClientManager.Get(event.getPlayer()).GetRank().has(Rank.DEVELOPER))) if (BLOCKED_COMMANDS.contains(commandName.toLowerCase()) && !(event.getPlayer().isOp() || ClientManager.getPermissionManager().hasPermission(event.getPlayer(), GroupPermission.of(BLOCKED_COMMAND_PERMISSION))))
{ {
event.setCancelled(true); event.setCancelled(true);
event.getPlayer().sendMessage(MESSAGE); event.getPlayer().sendMessage(MESSAGE);
@ -199,7 +205,7 @@ public class CommandCenter implements Listener, IPacketHandler
if (command != null) if (command != null)
{ {
if (ClientManager.Get(packetInfo.getPlayer()).GetRank().has(packetInfo.getPlayer(), command.GetRequiredRank(), command.GetSpecificRanks(), false) if (ClientManager.getPermissionManager().hasPermission(packetInfo.getPlayer(), command.getPermission())
|| UtilPlayer.isCommandAllowed(packetInfo.getPlayer(), commandName.toLowerCase())) || UtilPlayer.isCommandAllowed(packetInfo.getPlayer(), commandName.toLowerCase()))
{ {
List<String> tmpres = command.onTabComplete(packetInfo.getPlayer(), commandName.toLowerCase(), args); List<String> tmpres = command.onTabComplete(packetInfo.getPlayer(), commandName.toLowerCase(), args);
@ -216,7 +222,7 @@ public class CommandCenter implements Listener, IPacketHandler
// System.out.println("Path 2"); // System.out.println("Path 2");
for (ICommand command : Commands.values()) for (ICommand command : Commands.values())
{ {
if (ClientManager.Get(packetInfo.getPlayer()).GetRank().has(packetInfo.getPlayer(), command.GetRequiredRank(), command.GetSpecificRanks(), false) if (ClientManager.getPermissionManager().hasPermission(packetInfo.getPlayer(), command.getPermission())
|| UtilPlayer.isCommandAllowed(packetInfo.getPlayer(), commandName.toLowerCase())) || UtilPlayer.isCommandAllowed(packetInfo.getPlayer(), commandName.toLowerCase()))
{ {
for (String alias : command.Aliases()) for (String alias : command.Aliases())
@ -236,4 +242,4 @@ public class CommandCenter implements Listener, IPacketHandler
} }
} }
} }
} }

View File

@ -3,12 +3,12 @@ package mineplex.core.command;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import mineplex.core.common.Rank;
import mineplex.core.lifetimes.Component;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import mineplex.core.account.permissions.GroupPermission;
import mineplex.core.lifetimes.Component;
public interface ICommand extends Component public interface ICommand extends Component
{ {
void SetCommandCenter(CommandCenter commandCenter); void SetCommandCenter(CommandCenter commandCenter);
@ -17,9 +17,8 @@ public interface ICommand extends Component
Collection<String> Aliases(); Collection<String> Aliases();
void SetAliasUsed(String name); void SetAliasUsed(String name);
Rank GetRequiredRank(); GroupPermission getPermission();
Rank[] GetSpecificRanks();
@Override @Override
default void activate() default void activate()
@ -34,4 +33,4 @@ public interface ICommand extends Component
} }
List<String> onTabComplete(CommandSender sender, String commandLabel, String[] args); List<String> onTabComplete(CommandSender sender, String commandLabel, String[] args);
} }

View File

@ -7,11 +7,9 @@ package mineplex.core.command;
*/ */
public interface LoggedCommand public interface LoggedCommand
{ {
default void execute(long time, String username, String command, String args) default void execute(long time, String username, String command, String args)
{ {
LoggingServerCommand cmd = new LoggingServerCommand(time, username, command, args); LoggingServerCommand cmd = new LoggingServerCommand(time, username, command, args);
cmd.publish(); cmd.publish();
} }
}
}

View File

@ -21,4 +21,4 @@ public class LoggingServerCommand extends ServerCommand
_command = command; _command = command;
_args = args; _args = args;
} }
} }

View File

@ -9,23 +9,17 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.common.Rank; import mineplex.core.common.util.C;
import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilPlayerBase;
public abstract class MultiCommandBase<PluginType extends MiniPlugin> extends CommandBase<PluginType> public abstract class MultiCommandBase<PluginType extends MiniPlugin> extends CommandBase<PluginType>
{ {
private NautHashMap<String, ICommand> Commands; private NautHashMap<String, ICommand> Commands;
public MultiCommandBase(PluginType plugin, Rank rank, String... aliases) public MultiCommandBase(PluginType plugin, String permission, String... aliases)
{ {
super(plugin, rank, aliases); super(plugin, permission, aliases);
Commands = new NautHashMap<>();
}
public MultiCommandBase(PluginType plugin, Rank rank, Rank[] specificRanks, String... aliases)
{
super(plugin, rank, specificRanks, aliases);
Commands = new NautHashMap<>(); Commands = new NautHashMap<>();
} }
@ -72,11 +66,18 @@ public abstract class MultiCommandBase<PluginType extends MiniPlugin> extends Co
ICommand command = Commands.get(commandName); ICommand command = Commands.get(commandName);
if (command != null && _commandCenter.ClientManager.Get(caller).GetRank().has(caller, command.GetRequiredRank(), command.GetSpecificRanks(), true)) if (command != null)
{ {
command.SetAliasUsed(commandName); if (_commandCenter.ClientManager.getPermissionManager().hasPermission(caller, command.getPermission()))
{
command.Execute(caller, newArgs); command.SetAliasUsed(commandName);
command.Execute(caller, newArgs);
}
else
{
UtilPlayerBase.message(caller, C.mHead + "Permissions> " + C.mBody + "You do not have permission for that.");
}
} }
else else
{ {
@ -105,7 +106,7 @@ public abstract class MultiCommandBase<PluginType extends MiniPlugin> extends Co
Stream<ICommand> stream = Commands.values().stream(); Stream<ICommand> stream = Commands.values().stream();
if (sender instanceof Player) if (sender instanceof Player)
{ {
stream = stream.filter(command -> _commandCenter.GetClientManager().Get((Player) sender).GetRank().has((Player) sender, command.GetRequiredRank(), command.GetSpecificRanks(), false)); stream = stream.filter(command -> _commandCenter.GetClientManager().getPermissionManager().hasPermission((Player)sender, command.getPermission()));
} }
return getMatches(args[0], stream.map(ICommand::Aliases).flatMap(Collection::stream)); return getMatches(args[0], stream.map(ICommand::Aliases).flatMap(Collection::stream));
} }
@ -114,4 +115,4 @@ public abstract class MultiCommandBase<PluginType extends MiniPlugin> extends Co
} }
protected abstract void Help(Player caller, String[] args); protected abstract void Help(Player caller, String[] args);
} }

View File

@ -25,6 +25,8 @@ import mineplex.core.Managers;
import mineplex.core.MiniDbClientPlugin; import mineplex.core.MiniDbClientPlugin;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.account.ILoginProcessor; import mineplex.core.account.ILoginProcessor;
import mineplex.core.account.permissions.GroupPermission;
import mineplex.core.account.permissions.PermissionManager;
import mineplex.core.common.jsonchat.ClickEvent; import mineplex.core.common.jsonchat.ClickEvent;
import mineplex.core.common.jsonchat.JsonMessage; import mineplex.core.common.jsonchat.JsonMessage;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
@ -71,6 +73,24 @@ import mineplex.serverdata.servers.ServerRepository;
public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData> public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
{ {
public static final String OWN_COMMUNITY_PERMISSION = "mineplex.core.communities.own";
public static final String COMMUNITY_CHAT_COMMAND_PERMISSION = "mineplex.core.communities.chat";
public static final String COMMUNITY_COMMAND_PERMISSION = "mineplex.core.communities.command";
public static final String COMMUNITY_DESCRIPTION_COMMAND_PERMISSION = "mineplex.core.communities.description";
public static final String COMMUNITY_DESCRIPTION_STAFF_COMMAND_PERMISSION = "mineplex.core.communities.description.staff";
public static final String COMMUNITY_DISBAND_COMMAND_PERMISSION = "mineplex.core.communities.disband";
public static final String COMMUNITY_DISBAND_STAFF_COMMAND_PERMISSION = "mineplex.core.communities.disband.staff";
public static final String COMMUNITY_INVITE_COMMAND_PERMISSION = "mineplex.core.communities.invite";
public static final String COMMUNITY_INVITE_STAFF_COMMAND_PERMISSION = "mineplex.core.communities.invite.staff";
public static final String COMMUNITY_JOIN_COMMAND_PERMISSION = "mineplex.core.communities.join";
public static final String COMMUNITY_MCS_COMMAND_PERMISSION = "mineplex.core.communities.mcs";
public static final String COMMUNITY_MCS_STAFF_COMMAND_PERMISSION = "mineplex.core.communities.mcs.staff";
public static final String COMMUNITY_MENU_COMMAND_PERMISSION = "mineplex.core.communities.menu";
public static final String COMMUNITY_RENAME_COMMAND_PERMISSION = "mineplex.core.communities.rename";
public static final String COMMUNITY_RENAME_STAFF_COMMAND_PERMISSION = "mineplex.core.communities.rename.staff";
public static final String COMMUNITY_UNINVITE_COMMAND_PERMISSION = "mineplex.core.communities.uninvite";
public static final String COMMUNITY_UNINVITE_STAFF_COMMAND_PERMISSION = "mineplex.core.communities.uninvite.staff";
private final int UPDATE_CYCLE_SECONDS = 10; // The number of seconds between dirty communities refreshes private final int UPDATE_CYCLE_SECONDS = 10; // The number of seconds between dirty communities refreshes
private final int CACHE_INVALIDATION_SECONDS = 300; // The number of seconds between full communities refreshes private final int CACHE_INVALIDATION_SECONDS = 300; // The number of seconds between full communities refreshes
public final Pattern ALPHA_NUMERIC_PATTERN = Pattern.compile("[^A-Za-z0-9]"); public final Pattern ALPHA_NUMERIC_PATTERN = Pattern.compile("[^A-Za-z0-9]");
@ -183,6 +203,31 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
ServerCommandManager.getInstance().registerCommandType(CommunityUpdateMembership.class, new CommunityUpdateMembershipHandler(this)); ServerCommandManager.getInstance().registerCommandType(CommunityUpdateMembership.class, new CommunityUpdateMembershipHandler(this));
ServerCommandManager.getInstance().registerCommandType(CommunityUpdateName.class, new CommunityUpdateNameHandler(this)); ServerCommandManager.getInstance().registerCommandType(CommunityUpdateName.class, new CommunityUpdateNameHandler(this));
ServerCommandManager.getInstance().registerCommandType(CommunityUpdateSetting.class, new CommunityUpdateSettingHandler(this)); ServerCommandManager.getInstance().registerCommandType(CommunityUpdateSetting.class, new CommunityUpdateSettingHandler(this));
generatePermissions();
}
private void generatePermissions()
{
PermissionManager pm = getClientManager().getPermissionManager();
pm.setPermission(pm.getGroup("eternal"), GroupPermission.of(OWN_COMMUNITY_PERMISSION), true, true);
pm.setPermission(pm.getGroup("player"), GroupPermission.of(COMMUNITY_CHAT_COMMAND_PERMISSION), true, true);
pm.setPermission(pm.getGroup("player"), GroupPermission.of(COMMUNITY_COMMAND_PERMISSION), true, true);
pm.setPermission(pm.getGroup("player"), GroupPermission.of(COMMUNITY_DESCRIPTION_COMMAND_PERMISSION), true, true);
pm.setPermission(pm.getGroup("admin"), GroupPermission.of(COMMUNITY_DESCRIPTION_STAFF_COMMAND_PERMISSION), true, true);
pm.setPermission(pm.getGroup("eternal"), GroupPermission.of(COMMUNITY_DISBAND_COMMAND_PERMISSION), true, true);
pm.setPermission(pm.getGroup("admin"), GroupPermission.of(COMMUNITY_DISBAND_STAFF_COMMAND_PERMISSION), true, true);
pm.setPermission(pm.getGroup("player"), GroupPermission.of(COMMUNITY_INVITE_COMMAND_PERMISSION), true, true);
pm.setPermission(pm.getGroup("admin"), GroupPermission.of(COMMUNITY_INVITE_STAFF_COMMAND_PERMISSION), true, true);
pm.setPermission(pm.getGroup("player"), GroupPermission.of(COMMUNITY_JOIN_COMMAND_PERMISSION), true, true);
pm.setPermission(pm.getGroup("player"), GroupPermission.of(COMMUNITY_MCS_COMMAND_PERMISSION), true, true);
pm.setPermission(pm.getGroup("admin"), GroupPermission.of(COMMUNITY_MCS_STAFF_COMMAND_PERMISSION), true, true);
pm.setPermission(pm.getGroup("player"), GroupPermission.of(COMMUNITY_MENU_COMMAND_PERMISSION), true, true);
pm.setPermission(pm.getGroup("eternal"), GroupPermission.of(COMMUNITY_RENAME_COMMAND_PERMISSION), true, true);
pm.setPermission(pm.getGroup("admin"), GroupPermission.of(COMMUNITY_RENAME_STAFF_COMMAND_PERMISSION), true, true);
pm.setPermission(pm.getGroup("player"), GroupPermission.of(COMMUNITY_UNINVITE_COMMAND_PERMISSION), true, true);
pm.setPermission(pm.getGroup("admin"), GroupPermission.of(COMMUNITY_UNINVITE_STAFF_COMMAND_PERMISSION), true, true);
} }
public boolean ownsCommunity(UUID uuid) public boolean ownsCommunity(UUID uuid)

View File

@ -4,7 +4,6 @@ import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.communities.Community; import mineplex.core.communities.Community;
@ -14,7 +13,7 @@ public class CommunityChatCommand extends CommandBase<CommunityManager>
{ {
public CommunityChatCommand(CommunityManager plugin) public CommunityChatCommand(CommunityManager plugin)
{ {
super(plugin, Rank.ALL, "chat"); super(plugin, CommunityManager.COMMUNITY_CHAT_COMMAND_PERMISSION, "chat");
} }
@Override @Override
@ -22,7 +21,7 @@ public class CommunityChatCommand extends CommandBase<CommunityManager>
{ {
if (args.length < 1) if (args.length < 1)
{ {
UtilPlayer.message(caller, F.help("/com chat <community>", "Selects which community you chat to", Rank.ALL, ChatColor.AQUA)); UtilPlayer.message(caller, F.help("/com chat <community>", "Selects which community you chat to", ChatColor.DARK_AQUA));
return; return;
} }
Community c = Plugin.getLoadedCommunity(args[0]); Community c = Plugin.getLoadedCommunity(args[0]);

View File

@ -4,7 +4,6 @@ import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import mineplex.core.command.MultiCommandBase; import mineplex.core.command.MultiCommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.communities.Community; import mineplex.core.communities.Community;
@ -16,7 +15,7 @@ public class CommunityCommand extends MultiCommandBase<CommunityManager>
{ {
public CommunityCommand(CommunityManager plugin) public CommunityCommand(CommunityManager plugin)
{ {
super(plugin, Rank.ALL, "community", "communities", "com"); super(plugin, CommunityManager.COMMUNITY_COMMAND_PERMISSION, "community", "communities", "com");
AddCommand(new CommunityChatCommand(plugin)); AddCommand(new CommunityChatCommand(plugin));
AddCommand(new CommunityCreateCommand(plugin)); AddCommand(new CommunityCreateCommand(plugin));
@ -38,17 +37,16 @@ public class CommunityCommand extends MultiCommandBase<CommunityManager>
if (args[0].equalsIgnoreCase("help")) if (args[0].equalsIgnoreCase("help"))
{ {
UtilPlayer.message(caller, F.main(Plugin.getName(), "Community Commands:")); UtilPlayer.message(caller, F.main(Plugin.getName(), "Community Commands:"));
UtilPlayer.message(caller, F.help("/com <community>", "Opens a community's menu", Rank.ALL, ChatColor.DARK_AQUA)); UtilPlayer.message(caller, F.help("/com <community>", "Opens a community's menu", ChatColor.DARK_AQUA));
//UtilPlayer.message(caller, F.help("/com menu", "Opens your community menu", Rank.ALL)); UtilPlayer.message(caller, F.help("/com invite <player> <community>", "Invites a player to a community you manage", ChatColor.DARK_AQUA));
UtilPlayer.message(caller, F.help("/com invite <player> <community>", "Invites a player to a community you manage", Rank.ALL, ChatColor.DARK_AQUA)); UtilPlayer.message(caller, F.help("/com uninvite <player> <community>", "Revokes a player's invitation to a community you manage", ChatColor.DARK_AQUA));
UtilPlayer.message(caller, F.help("/com uninvite <player> <community>", "Revokes a player's invitation to a community you manage", Rank.ALL, ChatColor.DARK_AQUA)); UtilPlayer.message(caller, F.help("/com join <community>", "Joins a community that is open or you have been invited to", ChatColor.DARK_AQUA));
UtilPlayer.message(caller, F.help("/com join <community>", "Joins a community that is open or you have been invited to", Rank.ALL, ChatColor.DARK_AQUA)); UtilPlayer.message(caller, F.help("/com chat <community>", "Selects which community you chat to", ChatColor.DARK_AQUA));
UtilPlayer.message(caller, F.help("/com chat <community>", "Selects which community you chat to", Rank.ALL, ChatColor.DARK_AQUA)); UtilPlayer.message(caller, F.help("/com create <name>", "Creates a new community", ChatColor.DARK_AQUA));
UtilPlayer.message(caller, F.help("/com create <name>", "Creates a new community", Rank.ETERNAL, ChatColor.DARK_AQUA)); UtilPlayer.message(caller, F.help("/com rename <community> <name>", "Changes the name of a community you own", ChatColor.DARK_AQUA));
UtilPlayer.message(caller, F.help("/com rename <community> <name>", "Changes the name of a community you own", Rank.ETERNAL, ChatColor.DARK_AQUA)); UtilPlayer.message(caller, F.help("/com mcs <community>", "Opens the Mineplex Community Server of a community you manage", ChatColor.DARK_AQUA));
UtilPlayer.message(caller, F.help("/com mcs <community>", "Opens the Mineplex Community Server of a community you manage", Rank.ALL, ChatColor.DARK_AQUA)); UtilPlayer.message(caller, F.help("/com description <community> <description>", "Sets the description of a community you manage", ChatColor.DARK_AQUA));
UtilPlayer.message(caller, F.help("/com description <community> <description>", "Sets the description of a community you manage", Rank.ALL, ChatColor.DARK_AQUA)); UtilPlayer.message(caller, F.help("/com disband <community>", "Disbands a community you own", ChatColor.DARK_AQUA));
UtilPlayer.message(caller, F.help("/com disband <community>", "Disbands a community you own", Rank.ETERNAL, ChatColor.DARK_AQUA));
return; return;
} }
Community community = Plugin.getLoadedCommunity(args[0]); Community community = Plugin.getLoadedCommunity(args[0]);

View File

@ -9,7 +9,6 @@ import mineplex.core.Managers;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.chat.Chat; import mineplex.core.chat.Chat;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.communities.Community; import mineplex.core.communities.Community;
@ -19,7 +18,7 @@ public class CommunityCreateCommand extends CommandBase<CommunityManager>
{ {
public CommunityCreateCommand(CommunityManager plugin) public CommunityCreateCommand(CommunityManager plugin)
{ {
super(plugin, Rank.ETERNAL, "create"); super(plugin, CommunityManager.OWN_COMMUNITY_PERMISSION, "create");
} }
@Override @Override
@ -27,7 +26,7 @@ public class CommunityCreateCommand extends CommandBase<CommunityManager>
{ {
if (args.length < 1) if (args.length < 1)
{ {
UtilPlayer.message(caller, F.help("/com create <name>", "Creates a new community", Rank.ETERNAL, ChatColor.AQUA)); UtilPlayer.message(caller, F.help("/com create <name>", "Creates a new community", ChatColor.DARK_AQUA));
return; return;
} }
Community c = Plugin.getLoadedCommunity(args[0]); Community c = Plugin.getLoadedCommunity(args[0]);

View File

@ -5,9 +5,9 @@ import org.bukkit.entity.Player;
import mineplex.core.Managers; import mineplex.core.Managers;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.account.permissions.GroupPermission;
import mineplex.core.chat.Chat; import mineplex.core.chat.Chat;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.communities.Community; import mineplex.core.communities.Community;
@ -20,7 +20,7 @@ public class CommunityDescriptionCommand extends CommandBase<CommunityManager>
{ {
public CommunityDescriptionCommand(CommunityManager plugin) public CommunityDescriptionCommand(CommunityManager plugin)
{ {
super(plugin, Rank.ALL, "description"); super(plugin, CommunityManager.COMMUNITY_DESCRIPTION_COMMAND_PERMISSION, "description");
} }
@Override @Override
@ -28,7 +28,7 @@ public class CommunityDescriptionCommand extends CommandBase<CommunityManager>
{ {
if (args.length < 2) if (args.length < 2)
{ {
UtilPlayer.message(caller, F.help("/com description <community> <description>", "Sets the description of a community you manage", Rank.ALL, ChatColor.AQUA)); UtilPlayer.message(caller, F.help("/com description <community> <description>", "Sets the description of a community you manage", ChatColor.DARK_AQUA));
return; return;
} }
Community c = Plugin.getLoadedCommunity(args[0]); Community c = Plugin.getLoadedCommunity(args[0]);
@ -44,7 +44,7 @@ public class CommunityDescriptionCommand extends CommandBase<CommunityManager>
} }
if (c.getMembers().getOrDefault(caller.getUniqueId(), new CommunityMemberInfo(caller.getName(), caller.getUniqueId(), -1, CommunityRole.MEMBER, -1L)).Role.ordinal() > CommunityRole.COLEADER.ordinal()) if (c.getMembers().getOrDefault(caller.getUniqueId(), new CommunityMemberInfo(caller.getName(), caller.getUniqueId(), -1, CommunityRole.MEMBER, -1L)).Role.ordinal() > CommunityRole.COLEADER.ordinal())
{ {
if (!Managers.get(CoreClientManager.class).Get(caller).GetRank().has(Rank.ADMIN)) if (!Managers.get(CoreClientManager.class).getPermissionManager().hasPermission(caller, GroupPermission.of(CommunityManager.COMMUNITY_DESCRIPTION_STAFF_COMMAND_PERMISSION)))
{ {
UtilPlayer.message(caller, F.main(Plugin.getName(), "You are not a co-leader of " + F.name(c.getName()) + "!")); UtilPlayer.message(caller, F.main(Plugin.getName(), "You are not a co-leader of " + F.name(c.getName()) + "!"));
return; return;

View File

@ -5,8 +5,8 @@ import org.bukkit.entity.Player;
import mineplex.core.Managers; import mineplex.core.Managers;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.account.permissions.GroupPermission;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.communities.Community; import mineplex.core.communities.Community;
@ -18,7 +18,7 @@ public class CommunityDisbandCommand extends CommandBase<CommunityManager>
{ {
public CommunityDisbandCommand(CommunityManager plugin) public CommunityDisbandCommand(CommunityManager plugin)
{ {
super(plugin, Rank.ETERNAL, "disband"); super(plugin, CommunityManager.COMMUNITY_DISBAND_COMMAND_PERMISSION, "disband");
} }
@Override @Override
@ -26,7 +26,7 @@ public class CommunityDisbandCommand extends CommandBase<CommunityManager>
{ {
if (args.length < 1) if (args.length < 1)
{ {
UtilPlayer.message(caller, F.help("/com disband <community>", "Disbands a community you own", Rank.ETERNAL, ChatColor.AQUA)); UtilPlayer.message(caller, F.help("/com disband <community>", "Disbands a community you own", ChatColor.DARK_AQUA));
return; return;
} }
Community c = Plugin.getLoadedCommunity(args[0]); Community c = Plugin.getLoadedCommunity(args[0]);
@ -37,7 +37,7 @@ public class CommunityDisbandCommand extends CommandBase<CommunityManager>
} }
if (c.getMembers().getOrDefault(caller.getUniqueId(), new CommunityMemberInfo(caller.getName(), caller.getUniqueId(), -1, CommunityRole.MEMBER, -1L)).Role != CommunityRole.LEADER) if (c.getMembers().getOrDefault(caller.getUniqueId(), new CommunityMemberInfo(caller.getName(), caller.getUniqueId(), -1, CommunityRole.MEMBER, -1L)).Role != CommunityRole.LEADER)
{ {
if (!Managers.get(CoreClientManager.class).Get(caller).GetRank().has(Rank.ADMIN)) if (!Managers.get(CoreClientManager.class).getPermissionManager().hasPermission(caller, GroupPermission.of(CommunityManager.COMMUNITY_DISBAND_STAFF_COMMAND_PERMISSION)))
{ {
UtilPlayer.message(caller, F.main(Plugin.getName(), "You are not the leader of " + F.name(c.getName()) + "!")); UtilPlayer.message(caller, F.main(Plugin.getName(), "You are not the leader of " + F.name(c.getName()) + "!"));
return; return;

View File

@ -5,8 +5,8 @@ import org.bukkit.entity.Player;
import mineplex.core.Managers; import mineplex.core.Managers;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.account.permissions.GroupPermission;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.communities.Community; import mineplex.core.communities.Community;
@ -18,7 +18,7 @@ public class CommunityInviteCommand extends CommandBase<CommunityManager>
{ {
public CommunityInviteCommand(CommunityManager plugin) public CommunityInviteCommand(CommunityManager plugin)
{ {
super(plugin, Rank.ALL, "invite"); super(plugin, CommunityManager.COMMUNITY_INVITE_COMMAND_PERMISSION, "invite");
} }
@Override @Override
@ -26,7 +26,7 @@ public class CommunityInviteCommand extends CommandBase<CommunityManager>
{ {
if (args.length < 2) if (args.length < 2)
{ {
UtilPlayer.message(caller, F.help("/com invite <player> <community>", "Invites a player to a community you manage", Rank.ALL, ChatColor.AQUA)); UtilPlayer.message(caller, F.help("/com invite <player> <community>", "Invites a player to a community you manage", ChatColor.DARK_AQUA));
return; return;
} }
String player = args[0]; String player = args[0];
@ -38,7 +38,7 @@ public class CommunityInviteCommand extends CommandBase<CommunityManager>
} }
if (c.getMembers().getOrDefault(caller.getUniqueId(), new CommunityMemberInfo(caller.getName(), caller.getUniqueId(), -1, CommunityRole.MEMBER, -1L)).Role.ordinal() > CommunityRole.COLEADER.ordinal()) if (c.getMembers().getOrDefault(caller.getUniqueId(), new CommunityMemberInfo(caller.getName(), caller.getUniqueId(), -1, CommunityRole.MEMBER, -1L)).Role.ordinal() > CommunityRole.COLEADER.ordinal())
{ {
if (!Managers.get(CoreClientManager.class).Get(caller).GetRank().has(Rank.ADMIN)) if (!Managers.get(CoreClientManager.class).getPermissionManager().hasPermission(caller, GroupPermission.of(CommunityManager.COMMUNITY_INVITE_STAFF_COMMAND_PERMISSION)))
{ {
UtilPlayer.message(caller, F.main(Plugin.getName(), "You are not a co-leader of " + F.name(c.getName()) + "!")); UtilPlayer.message(caller, F.main(Plugin.getName(), "You are not a co-leader of " + F.name(c.getName()) + "!"));
return; return;

View File

@ -4,7 +4,6 @@ import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.communities.Community; import mineplex.core.communities.Community;
@ -15,7 +14,7 @@ public class CommunityJoinCommand extends CommandBase<CommunityManager>
{ {
public CommunityJoinCommand(CommunityManager plugin) public CommunityJoinCommand(CommunityManager plugin)
{ {
super(plugin, Rank.ALL, "join"); super(plugin, CommunityManager.COMMUNITY_JOIN_COMMAND_PERMISSION, "join");
} }
@Override @Override
@ -23,7 +22,7 @@ public class CommunityJoinCommand extends CommandBase<CommunityManager>
{ {
if (args.length < 1) if (args.length < 1)
{ {
UtilPlayer.message(caller, F.help("/com join <community>", "Joins a community that is open or you have been invited to", Rank.ALL, ChatColor.AQUA)); UtilPlayer.message(caller, F.help("/com join <community>", "Joins a community that is open or you have been invited to", ChatColor.DARK_AQUA));
return; return;
} }
Community c = Plugin.getLoadedCommunity(args[0]); Community c = Plugin.getLoadedCommunity(args[0]);

View File

@ -5,8 +5,8 @@ import org.bukkit.entity.Player;
import mineplex.core.Managers; import mineplex.core.Managers;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.account.permissions.GroupPermission;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.communities.Community; import mineplex.core.communities.Community;
@ -19,7 +19,7 @@ public class CommunityMCSCommand extends CommandBase<CommunityManager>
{ {
public CommunityMCSCommand(CommunityManager plugin) public CommunityMCSCommand(CommunityManager plugin)
{ {
super(plugin, Rank.ALL, "mcs"); super(plugin, CommunityManager.COMMUNITY_MCS_COMMAND_PERMISSION, "mcs");
} }
@Override @Override
@ -27,7 +27,7 @@ public class CommunityMCSCommand extends CommandBase<CommunityManager>
{ {
if (args.length < 1) if (args.length < 1)
{ {
UtilPlayer.message(caller, F.help("/com mcs <community>", "Opens the Mineplex Community Server of a community you manage", Rank.ALL, ChatColor.AQUA)); UtilPlayer.message(caller, F.help("/com mcs <community>", "Opens the Mineplex Community Server of a community you manage", ChatColor.DARK_AQUA));
return; return;
} }
Community c = Plugin.getLoadedCommunity(args[0]); Community c = Plugin.getLoadedCommunity(args[0]);
@ -38,7 +38,7 @@ public class CommunityMCSCommand extends CommandBase<CommunityManager>
} }
if (c.getMembers().getOrDefault(caller.getUniqueId(), new CommunityMemberInfo(caller.getName(), caller.getUniqueId(), -1, CommunityRole.MEMBER, -1L)).Role.ordinal() > CommunityRole.COLEADER.ordinal()) if (c.getMembers().getOrDefault(caller.getUniqueId(), new CommunityMemberInfo(caller.getName(), caller.getUniqueId(), -1, CommunityRole.MEMBER, -1L)).Role.ordinal() > CommunityRole.COLEADER.ordinal())
{ {
if (!Managers.get(CoreClientManager.class).Get(caller).GetRank().has(Rank.ADMIN)) if (!Managers.get(CoreClientManager.class).getPermissionManager().hasPermission(caller, GroupPermission.of(CommunityManager.COMMUNITY_MCS_STAFF_COMMAND_PERMISSION)))
{ {
UtilPlayer.message(caller, F.main(Plugin.getName(), "You are not a co-leader of " + F.name(c.getName()) + "!")); UtilPlayer.message(caller, F.main(Plugin.getName(), "You are not a co-leader of " + F.name(c.getName()) + "!"));
return; return;

View File

@ -3,7 +3,6 @@ package mineplex.core.communities.commands;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.communities.CommunityManager; import mineplex.core.communities.CommunityManager;
import mineplex.core.communities.gui.overview.CommunityOverviewPage; import mineplex.core.communities.gui.overview.CommunityOverviewPage;
@ -11,7 +10,7 @@ public class CommunityMenuCommand extends CommandBase<CommunityManager>
{ {
public CommunityMenuCommand(CommunityManager plugin) public CommunityMenuCommand(CommunityManager plugin)
{ {
super(plugin, Rank.ALL, "menu"); super(plugin, CommunityManager.COMMUNITY_MENU_COMMAND_PERMISSION, "menu");
} }
@Override @Override

View File

@ -7,9 +7,9 @@ import org.bukkit.entity.Player;
import mineplex.core.Managers; import mineplex.core.Managers;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.account.permissions.GroupPermission;
import mineplex.core.chat.Chat; import mineplex.core.chat.Chat;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.communities.Community; import mineplex.core.communities.Community;
@ -21,7 +21,7 @@ public class CommunityRenameCommand extends CommandBase<CommunityManager>
{ {
public CommunityRenameCommand(CommunityManager plugin) public CommunityRenameCommand(CommunityManager plugin)
{ {
super(plugin, Rank.ETERNAL, "rename"); super(plugin, CommunityManager.COMMUNITY_RENAME_COMMAND_PERMISSION, "rename");
} }
@Override @Override
@ -29,7 +29,7 @@ public class CommunityRenameCommand extends CommandBase<CommunityManager>
{ {
if (args.length < 2) if (args.length < 2)
{ {
UtilPlayer.message(caller, F.help("/com rename <community> <name>", "Changes the name of a community you own", Rank.ETERNAL, ChatColor.AQUA)); UtilPlayer.message(caller, F.help("/com rename <community> <name>", "Changes the name of a community you own", ChatColor.DARK_AQUA));
return; return;
} }
Community c = Plugin.getLoadedCommunity(args[0]); Community c = Plugin.getLoadedCommunity(args[0]);
@ -41,7 +41,7 @@ public class CommunityRenameCommand extends CommandBase<CommunityManager>
} }
if (c.getMembers().getOrDefault(caller.getUniqueId(), new CommunityMemberInfo(caller.getName(), caller.getUniqueId(), -1, CommunityRole.MEMBER, -1L)).Role != CommunityRole.LEADER) if (c.getMembers().getOrDefault(caller.getUniqueId(), new CommunityMemberInfo(caller.getName(), caller.getUniqueId(), -1, CommunityRole.MEMBER, -1L)).Role != CommunityRole.LEADER)
{ {
if (!Managers.get(CoreClientManager.class).Get(caller).GetRank().has(Rank.ADMIN)) if (!Managers.get(CoreClientManager.class).getPermissionManager().hasPermission(caller, GroupPermission.of(CommunityManager.COMMUNITY_RENAME_STAFF_COMMAND_PERMISSION)))
{ {
UtilPlayer.message(caller, F.main(Plugin.getName(), "You are not the leader of " + F.name(c.getName()) + "!")); UtilPlayer.message(caller, F.main(Plugin.getName(), "You are not the leader of " + F.name(c.getName()) + "!"));
return; return;

View File

@ -5,8 +5,8 @@ import org.bukkit.entity.Player;
import mineplex.core.Managers; import mineplex.core.Managers;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.account.permissions.GroupPermission;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.communities.Community; import mineplex.core.communities.Community;
@ -18,7 +18,7 @@ public class CommunityUnInviteCommand extends CommandBase<CommunityManager>
{ {
public CommunityUnInviteCommand(CommunityManager plugin) public CommunityUnInviteCommand(CommunityManager plugin)
{ {
super(plugin, Rank.ALL, "uninvite"); super(plugin, CommunityManager.COMMUNITY_UNINVITE_COMMAND_PERMISSION, "uninvite");
} }
@Override @Override
@ -26,7 +26,7 @@ public class CommunityUnInviteCommand extends CommandBase<CommunityManager>
{ {
if (args.length < 2) if (args.length < 2)
{ {
UtilPlayer.message(caller, F.help("/com uninvite <player> <community>", "Revokes a player's invitation to a community you manage", Rank.ALL, ChatColor.AQUA)); UtilPlayer.message(caller, F.help("/com uninvite <player> <community>", "Revokes a player's invitation to a community you manage", ChatColor.DARK_AQUA));
return; return;
} }
String player = args[0]; String player = args[0];
@ -38,7 +38,7 @@ public class CommunityUnInviteCommand extends CommandBase<CommunityManager>
} }
if (c.getMembers().getOrDefault(caller.getUniqueId(), new CommunityMemberInfo(caller.getName(), caller.getUniqueId(), -1, CommunityRole.MEMBER, -1L)).Role.ordinal() > CommunityRole.COLEADER.ordinal()) if (c.getMembers().getOrDefault(caller.getUniqueId(), new CommunityMemberInfo(caller.getName(), caller.getUniqueId(), -1, CommunityRole.MEMBER, -1L)).Role.ordinal() > CommunityRole.COLEADER.ordinal())
{ {
if (!Managers.get(CoreClientManager.class).Get(caller).GetRank().has(Rank.ADMIN)) if (!Managers.get(CoreClientManager.class).getPermissionManager().hasPermission(caller, GroupPermission.of(CommunityManager.COMMUNITY_UNINVITE_STAFF_COMMAND_PERMISSION)))
{ {
UtilPlayer.message(caller, F.main(Plugin.getName(), "You are not a co-leader of " + F.name(c.getName()) + "!")); UtilPlayer.message(caller, F.main(Plugin.getName(), "You are not a co-leader of " + F.name(c.getName()) + "!"));
return; return;

View File

@ -5,10 +5,11 @@ import org.bukkit.event.inventory.ClickType;
import mineplex.core.Managers; import mineplex.core.Managers;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Rank; import mineplex.core.account.permissions.GroupPermission;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.communities.Community; import mineplex.core.communities.Community;
import mineplex.core.communities.CommunityManager;
import mineplex.core.communities.CommunityMemberInfo; import mineplex.core.communities.CommunityMemberInfo;
import mineplex.core.communities.CommunityRole; import mineplex.core.communities.CommunityRole;
import mineplex.core.communities.gui.CommunitiesGUIButton; import mineplex.core.communities.gui.CommunitiesGUIButton;
@ -18,6 +19,7 @@ public class CommunityMemberButton extends CommunitiesGUIButton
private Player _viewer; private Player _viewer;
private Community _community; private Community _community;
private CommunityMemberInfo _info; private CommunityMemberInfo _info;
private boolean _fetching = false;
public CommunityMemberButton(Player viewer, Community community, CommunityMemberInfo info) public CommunityMemberButton(Player viewer, Community community, CommunityMemberInfo info)
{ {
@ -37,6 +39,10 @@ public class CommunityMemberButton extends CommunitiesGUIButton
@Override @Override
public void handleClick(ClickType type) public void handleClick(ClickType type)
{ {
if (_fetching)
{
return;
}
if (type == ClickType.SHIFT_RIGHT) if (type == ClickType.SHIFT_RIGHT)
{ {
if (getCommunityManager().Get(_viewer).getRoleIn(_community) != null && getCommunityManager().Get(_viewer).getRoleIn(_community).ordinal() < _info.Role.ordinal()) if (getCommunityManager().Get(_viewer).getRoleIn(_community) != null && getCommunityManager().Get(_viewer).getRoleIn(_community).ordinal() < _info.Role.ordinal())
@ -59,13 +65,25 @@ public class CommunityMemberButton extends CommunitiesGUIButton
UtilPlayer.message(_viewer, F.main(getCommunityManager().getName(), F.name(_info.Name) + " can only own one community at a time!")); UtilPlayer.message(_viewer, F.main(getCommunityManager().getName(), F.name(_info.Name) + " can only own one community at a time!"));
return; return;
} }
if (!Rank.valueOf(Managers.get(CoreClientManager.class).loadOfflineClient(_info.UUID).Rank).has(Rank.ETERNAL)) CoreClientManager clientManager = Managers.get(CoreClientManager.class);
_fetching = true;
clientManager.fetchGroups(_info.AccountId, pair ->
{
if (clientManager.getPermissionManager().hasPermission(pair, GroupPermission.of(CommunityManager.OWN_COMMUNITY_PERMISSION)))
{
getCommunityManager().handleRoleUpdate(_viewer, _community, _info, CommunityRole.LEADER);
getCommunityManager().handleRoleUpdate(_viewer, _community, _community.getMembers().get(_viewer.getUniqueId()), CommunityRole.COLEADER);
}
else
{
UtilPlayer.message(_viewer, F.main(getCommunityManager().getName(), "Only Eternal rank and above can own a community!"));
}
_fetching = false;
}, () ->
{ {
UtilPlayer.message(_viewer, F.main(getCommunityManager().getName(), "Only Eternal rank and above can own a community!")); UtilPlayer.message(_viewer, F.main(getCommunityManager().getName(), "Only Eternal rank and above can own a community!"));
return; _fetching = false;
} });
getCommunityManager().handleRoleUpdate(_viewer, _community, _info, CommunityRole.LEADER);
getCommunityManager().handleRoleUpdate(_viewer, _community, _community.getMembers().get(_viewer.getUniqueId()), CommunityRole.COLEADER);
} }
} }
} }

View File

@ -2,7 +2,6 @@ package mineplex.core.cosmetic.ui.page;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
@ -12,12 +11,10 @@ import mineplex.core.donation.DonationManager;
import mineplex.core.gadget.gadgets.wineffect.rankrooms.WinEffectRankBased; import mineplex.core.gadget.gadgets.wineffect.rankrooms.WinEffectRankBased;
import mineplex.core.gadget.types.Gadget; import mineplex.core.gadget.types.Gadget;
import mineplex.core.gadget.types.GadgetType; import mineplex.core.gadget.types.GadgetType;
import mineplex.core.shop.item.IButton;
import mineplex.core.shop.item.ShopItem; import mineplex.core.shop.item.ShopItem;
public class WinEffectPage extends GadgetPage public class WinEffectPage extends GadgetPage
{ {
public WinEffectPage(CosmeticManager plugin, CosmeticShop shop, CoreClientManager clientManager, DonationManager donationManager, String name, public WinEffectPage(CosmeticManager plugin, CosmeticShop shop, CoreClientManager clientManager, DonationManager donationManager, String name,
Player player) Player player)
{ {
@ -34,7 +31,7 @@ public class WinEffectPage extends GadgetPage
if (gadget instanceof WinEffectRankBased) if (gadget instanceof WinEffectRankBased)
{ {
WinEffectRankBased rankBased = (WinEffectRankBased) gadget; WinEffectRankBased rankBased = (WinEffectRankBased) gadget;
if (getClientManager().Get(getPlayer()).GetRank().has(rankBased.getRank())) if (getClientManager().getPermissionManager().hasPermission(getPlayer(), rankBased.getUnlockPermission()))
{ {
addGadget(gadget, slot); addGadget(gadget, slot);
} }
@ -61,13 +58,9 @@ public class WinEffectPage extends GadgetPage
} }
} }
addButton(4, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[]{}, 1, false), new IButton() addButton(4, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[]{}, 1, false), (player, clickType) ->
{ {
public void onClick(Player player, ClickType clickType) getShop().openPageForPlayer(getPlayer(), new Menu(getPlugin(), getShop(), getClientManager(), getDonationManager(), player));
{
getShop().openPageForPlayer(getPlayer(), new Menu(getPlugin(), getShop(), getClientManager(), getDonationManager(), player));
}
}); });
} }
}
}

View File

@ -4,22 +4,14 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import mineplex.core.Managers;
import mineplex.core.MiniPlugin;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.updater.UpdateType;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.creature.command.MobCommand;
import mineplex.core.creature.event.CreatureSpawnCustomEvent;
import mineplex.core.itemstack.ItemStackFactory;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.*; import org.bukkit.entity.Creeper;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Skeleton.SkeletonType; import org.bukkit.entity.Skeleton.SkeletonType;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
@ -31,14 +23,43 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import mineplex.core.Managers;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.permissions.GroupPermission;
import mineplex.core.account.permissions.PermissionManager;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.creature.command.MobCommand;
import mineplex.core.creature.event.CreatureSpawnCustomEvent;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
public class Creature extends MiniPlugin public class Creature extends MiniPlugin
{ {
public static final String MOB_COMMAND_PERMISSION = "mineplex.core.mob.command";
public static final String KILL_MOB_COMMAND_PERMISSION = "mineplex.core.mob.kill";
private boolean _spawnForce = false; private boolean _spawnForce = false;
private boolean _disableCustom = false; private boolean _disableCustom = false;
public Creature(JavaPlugin plugin) public Creature(JavaPlugin plugin)
{ {
super("Creature", plugin); super("Creature", plugin);
generatePermissions();
}
private void generatePermissions()
{
PermissionManager pm = Managers.get(CoreClientManager.class).getPermissionManager();
pm.setPermission(pm.getGroup("admin"), GroupPermission.of(MOB_COMMAND_PERMISSION), true, true);
pm.setPermission(pm.getGroup("admin"), GroupPermission.of(KILL_MOB_COMMAND_PERMISSION), true, true);
} }
@Override @Override
@ -315,4 +336,4 @@ public class Creature extends MiniPlugin
{ {
_disableCustom = var; _disableCustom = var;
} }
} }

View File

@ -1,26 +0,0 @@
package mineplex.core.creature.command;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.creature.Creature;
public class HelpCommand extends CommandBase<Creature>
{
public HelpCommand(Creature plugin)
{
super(plugin, Rank.ADMIN, "help");
}
@Override
public void Execute(Player caller, String[] args)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "Commands List;"));
UtilPlayer.message(caller, F.help("/mob", "List Entities", Rank.MODERATOR));
UtilPlayer.message(caller, F.help("/mob kill <Type>", "Remove Entities of Type", Rank.ADMIN));
UtilPlayer.message(caller, F.help("/mob <Type> (# baby lock angry s# <Prof>)", "Create", Rank.ADMIN));
UtilPlayer.message(caller, F.desc("Professions", "Butcher, Blacksmith, Farmer, Librarian, Priest"));
}
}

View File

@ -9,7 +9,6 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilEnt; import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
@ -21,7 +20,7 @@ public class KillCommand extends CommandBase<Creature>
{ {
public KillCommand(Creature plugin) public KillCommand(Creature plugin)
{ {
super(plugin, Rank.ADMIN, "kill", "k"); super(plugin, Creature.KILL_MOB_COMMAND_PERMISSION, "kill", "k");
} }
@Override @Override
@ -70,4 +69,4 @@ public class KillCommand extends CommandBase<Creature>
UtilPlayer.message(caller, F.main(Plugin.getName(), "Killed " + target + ". " + count + " Removed.")); UtilPlayer.message(caller, F.main(Plugin.getName(), "Killed " + target + ". " + count + " Removed."));
} }
} }

Some files were not shown because too many files have changed in this diff Show More