- Rewritten testrank system

- Multiple rank improvements for real-time use
- Removed /updaterank from Jr.Dev
This commit is contained in:
AlexTheCoder 2015-09-24 11:44:45 -04:00
parent 2b902c5193
commit a488bfab3e
7 changed files with 228 additions and 17 deletions

View File

@ -1,8 +1,12 @@
package mineplex.core.account;
import mineplex.core.account.event.OnlineRankUpdateEvent;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilPlayer;
import mineplex.serverdata.Utility;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class CoreClient
@ -12,8 +16,9 @@ public class CoreClient
private String _name;
private String _disguisedAs;
private Player _player;
private Rank _rank;
private Rank _rank, _lastRank;
private Rank _disguisedRank;
private Rank _tempRank, _lastTemp;
private boolean _disguised;
public CoreClient(Player player)
@ -58,18 +63,58 @@ public class CoreClient
{
_accountId = accountId;
}
public Rank GetRank()
{
return GetRank(false);
}
public Rank GetRank(boolean bypass)
{
if (_rank == null)
_rank = Rank.ALL;
return _rank;
if (bypass || _tempRank == null)
return _rank;
else
return _tempRank;
}
public void SetRank(Rank rank)
public Rank GetLastRank(boolean temp)
{
_rank = rank;
if (temp)
{
if ((_lastTemp == null) && (_tempRank == null))
{
return _rank;
}
else if (_lastTemp == null)
{
return _tempRank;
}
return _lastTemp;
}
else
{
if (_lastRank == null) return _rank;
return _lastRank;
}
}
public void SetRank(Rank rank, boolean temp)
{
if (temp)
{
if (_lastTemp == null) _lastTemp = rank;
else _lastTemp = _tempRank;
_tempRank = rank;
}
else
{
if (_rank != null) _lastRank = _rank;
else _lastRank = rank;
_rank = rank;
}
}
public long getNetworkSessionLoginTime()
@ -111,4 +156,16 @@ public class CoreClient
{
_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!");
}
}
}

View File

@ -9,6 +9,7 @@ import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import mineplex.core.MiniPlugin;
import mineplex.core.account.command.TestRank;
import mineplex.core.account.command.UpdateRank;
import mineplex.core.account.event.ClientUnloadEvent;
import mineplex.core.account.event.ClientWebResponseEvent;
@ -74,6 +75,7 @@ public class CoreClientManager extends MiniPlugin
public void addCommands()
{
addCommand(new UpdateRank(this));
addCommand(new TestRank(this));
}
public CoreClient Add(String name)
@ -245,7 +247,7 @@ public class CoreClientManager extends MiniPlugin
token = gson.fromJson(response, ClientToken.class);
CoreClient client = Add(playerName);
client.SetRank(Rank.valueOf(token.Rank));
client.SetRank(Rank.valueOf(token.Rank), false);
client.setAccountId(_repository.login(_loginProcessors, _querylessLoginProcessors, uuid.toString(), client.GetPlayerName()));
// JSON sql response
@ -305,7 +307,7 @@ public class CoreClientManager extends MiniPlugin
token = gson.fromJson(response, ClientToken.class);
client.SetRank(Rank.valueOf(token.Rank));
client.SetRank(Rank.valueOf(token.Rank), false);
// _repository.updateMysqlRank(uuid.toString(), token.Rank, token.RankPerm, new Timestamp(Date.parse(token.RankExpire)).toString());
@ -418,7 +420,7 @@ public class CoreClientManager extends MiniPlugin
{
CoreClient client = Get(name);
client.SetRank(newRank);
client.SetRank(newRank, false);
}
}
}, name, uuid, rank, perm);

View File

@ -0,0 +1,77 @@
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 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.JNR_DEV))
{
UtilPlayer.message(caller, F.main("Permissions", "This requires Permission Rank [" + Rank.JNR_DEV.getTag(false, true) + C.cGray + "]."));
return;
}
boolean testServer = Plugin.getPlugin().getConfig().getString("serverstatus.group").equalsIgnoreCase("Testing");
if (!testServer)
{
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;
}
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

@ -4,34 +4,36 @@ import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
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 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, new Rank[] {Rank.JNR_DEV /*On test servers only*/}, "updateRank");
super(plugin, Rank.ADMIN, "updateRank");
}
@Override
public void Execute(final Player caller, String[] args)
{
boolean testServer = Plugin.getPlugin().getConfig().getString("serverstatus.group").equalsIgnoreCase("Testing");
if (Plugin.Get(caller).GetRank() == Rank.JNR_DEV && !testServer)
if (!Plugin.Get(caller).GetRank(true).has(caller, Rank.ADMIN, true))
{
F.main(Plugin.getName(), F.elem(Rank.JNR_DEV.getTag(true, true)) + "s are only permitted to set ranks on test servers!");
return;
}
boolean testServer = Plugin.getPlugin().getConfig().getString("serverstatus.group").equalsIgnoreCase("Testing");
if (args == null)
{
@ -93,6 +95,19 @@ public class UpdateRank extends CommandBase<CoreClientManager>
}
}
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, true);
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)

View File

@ -0,0 +1,55 @@
package mineplex.core.account.event;
import mineplex.core.common.Rank;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class OnlineRankUpdateEvent extends Event
{
private static final HandlerList handlers = new HandlerList();
private Player _player;
private Rank _from, _to;
private boolean _temp;
public OnlineRankUpdateEvent(Player player, Rank from, Rank to, boolean temp)
{
_player = player;
_from = from;
_to = to;
_temp = temp;
}
public Player getPlayer()
{
return _player;
}
public Rank getFrom()
{
return _from;
}
public Rank getTo()
{
return _to;
}
public boolean isTemporary()
{
return _temp;
}
public HandlerList getHandlers()
{
return handlers;
}
public static HandlerList getHandlerList()
{
return handlers;
}
}

View File

@ -35,7 +35,7 @@ public class RankReward extends Reward
if (rank == null)
return new RewardData(getRarity().getColor() + "Rank Upgrade Error", new ItemStack(Material.PAPER), getRarity());
_clientManager.Get(player).SetRank(rank);
_clientManager.Get(player).SetRank(rank, false);
_clientManager.getRepository().saveRank(null, player.getName(), player.getUniqueId(), rank, true);
return new RewardData(getRarity().getColor() + rank.Name + " Rank", new ItemStack(Material.NETHER_STAR), getRarity());

View File

@ -740,6 +740,11 @@ public class HubManager extends MiniClientPlugin<HubClient>
//Display Rank
obj.getScore(C.cGold + C.Bold + "Rank").setScore(line--);
//Remove Old
player.getScoreboard().resetScores(_clientManager.Get(player).GetLastRank(false).Name);
player.getScoreboard().resetScores(_clientManager.Get(player).GetLastRank(true).Name);
player.getScoreboard().resetScores("No Rank");
//Add New
if (GetClients().Get(player).GetRank().has(Rank.ULTRA))
obj.getScore(GetClients().Get(player).GetRank().Name).setScore(line--);
else if (GetDonation().Get(player.getName()).OwnsUnknownPackage("SuperSmashMobs ULTRA") ||