Added #17 and fixed stuff

This commit is contained in:
Norbi Peti 2016-04-24 19:46:41 +02:00
parent a23d9dfb25
commit b39a2888d5
6 changed files with 91 additions and 93 deletions

Binary file not shown.

View file

@ -219,7 +219,7 @@ public class ChatProcessing {
String.format(
"\",\"color\":\"%s\"},{\"text\":\"§b@console§r\",\"color\":\"blue\"},{\"text\":\"",
colormode)); //TODO: Add optional username option to setflair
System.out.println("\007");
System.out.println("\007"); //TODO: Only store flair times and detect the reset (#17)
}
}

View file

@ -41,7 +41,7 @@ public class Commands implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command cmd, String label,
String[] args) {
if (sender instanceof Player) {
Player player = (Player) sender;
final Player player = (Player) sender;
switch (cmd.getName()) {
case "u": {
if (args.length < 1)
@ -88,8 +88,6 @@ public class Commands implements CommandExecutor {
p.Working = true;
Timer timer = new Timer();
PlayerJoinTimerTask tt = new PlayerJoinTimerTask() {
Player player = Bukkit.getPlayer(mp.UUID);
@Override
public void run() {
try {
@ -129,7 +127,7 @@ public class Commands implements CommandExecutor {
}
if (!p.FlairState.equals(FlairStates.Ignored)) {
p.FlairState = FlairStates.Ignored;
p.SetFlairTime("");
p.SetFlair(MaybeOfflinePlayer.FlairTimeNone);
p.UserName = "";
player.sendMessage("§bYou have removed your flair. You can still use /u accept to get one.§r");
} else
@ -478,47 +476,55 @@ public class Commands implements CommandExecutor {
}
private static void SetPlayerFlair(Player player,
MaybeOfflinePlayer targetplayer, short flaircolor, String flairtime) {
if (targetplayer.GetFlairColor() == 0x00 || flairtime.length() > 0) {
targetplayer.SetFlair(flaircolor, flairtime);
targetplayer.FlairState = FlairStates.Accepted;
MaybeOfflinePlayer targetplayer, short flairtime, boolean cheater,
String username) {
targetplayer.SetFlair(flairtime, cheater);
targetplayer.FlairState = FlairStates.Accepted;
if (username == null)
targetplayer.UserName = "";
SendMessage(player,
"§bThe flair has been set. Player: "
+ targetplayer.PlayerName + " Flair: "
+ targetplayer.GetFormattedFlair() + "§r");
} else {
SendMessage(
player,
"§cSorry, but you can't change an existing flair. (Use -- as time to set non-presser or can't press)");
SendMessage(Bukkit.getPlayer(targetplayer.UUID),
"§cYour flair cannot be changed.");
else {
targetplayer.UserName = username;
if (!targetplayer.UserNames.contains(username))
targetplayer.UserNames.add(username);
}
SendMessage(player,
"§bThe flair has been set. Player: " + targetplayer.PlayerName
+ " Flair: " + targetplayer.GetFormattedFlair() + "§r");
}
// TODO: Put commands into separate classes
private static void DoSetFlair(Player player, String[] args) {
// args[0] is "admin" - args[1] is "setflair"
if (args.length < 4) {
SendMessage(player,
"§cUsage: /u admin setflair <playername> <flaircolor> [number]");
if (args.length < 5) {
SendMessage(
player,
"§cUsage: /u admin setflair <playername> <flairtime> <cheater(true/false)> [username]");
return;
}
Player p = Bukkit.getPlayer(args[2]);
if (p == null) {
SendMessage(player, "§cPLayer not found.&r");
SendMessage(player, "§cPlayer not found.&r");
return;
}
short flaircolor = 0x00;
short flairtime = 0x00;
try {
flaircolor = Short.parseShort(args[3], 16);
flairtime = Short.parseShort(args[3]);
} catch (Exception e) {
SendMessage(player,
"§cFlaircolor must be a hexadecimal number (don't include &).");
SendMessage(player, "§cFlairtime must be a number.");
return;
}
boolean cheater = false;
if (args[4].equalsIgnoreCase("true"))
cheater = true;
else if (args[4].equalsIgnoreCase("false"))
cheater = false;
else {
SendMessage(player, "§cUnknown value for cheater parameter.");
return;
}
SetPlayerFlair(player,
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()),
flaircolor, (args.length < 5 ? "" : args[4]));
flairtime, cheater, (args.length > 5 ? args[5] : null));
}
private static void DoUpdatePlugin(Player player) { // 2015.08.10.

View file

@ -15,8 +15,7 @@ public class MaybeOfflinePlayer {
public String PlayerName;
public String UserName;
public List<String> UserNames;
private String FlairTime;
private short FlairColor;
private short FlairTime;
public FlairStates FlairState;
public boolean RPMode = true;
public boolean PressedF;
@ -30,6 +29,10 @@ public class MaybeOfflinePlayer {
public boolean RainbowPresserColorMode = false;
public String OtherColorMode = "";
public boolean ChatOnly = false;
public boolean FlairCheater = false;
public static final short FlairTimeNonPresser = -1;
public static final short FlairTimeCantPress = -2;
public static final short FlairTimeNone = -3;
public UUID UUID;
@ -39,8 +42,7 @@ public class MaybeOfflinePlayer {
if (!AllPlayers.containsKey(uuid)) {
MaybeOfflinePlayer player = new MaybeOfflinePlayer();
player.UUID = uuid;
player.FlairColor = 0;
player.FlairTime = "";
player.FlairTime = 0;
player.FlairState = FlairStates.NoComment;
player.UserNames = new ArrayList<>();
AllPlayers.put(uuid, player);
@ -56,8 +58,11 @@ public class MaybeOfflinePlayer {
MaybeOfflinePlayer mp = AddPlayerIfNeeded(java.util.UUID
.fromString(cs2.getString("uuid")));
mp.UserName = cs2.getString("username");
mp.FlairColor = (short) cs2.getInt("flaircolor");
mp.FlairTime = cs2.getString("flairtime");
String tmp = cs2.getString("flairtime");
if (tmp.equals("--"))
mp.FlairTime = FlairTimeNonPresser;
else if (tmp.length() > 0)
mp.FlairTime = Short.parseShort(tmp);
String flairstate = cs2.getString("flairstate");
if (flairstate != null)
mp.FlairState = FlairStates.valueOf(flairstate);
@ -67,6 +72,7 @@ public class MaybeOfflinePlayer {
mp.UserNames = cs2.getStringList("usernames");
mp.FCount = cs2.getInt("fcount");
mp.FDeaths = cs2.getInt("fdeaths");
mp.FlairCheater = cs2.getBoolean("flaircheater");
}
}
@ -76,48 +82,42 @@ public class MaybeOfflinePlayer {
ConfigurationSection cs2 = cs.createSection(mp.UUID.toString());
cs2.set("playername", mp.PlayerName);
cs2.set("username", mp.UserName);
cs2.set("flaircolor", mp.FlairColor);
cs2.set("flairtime", mp.FlairTime);
cs2.set("flairstate", mp.FlairState.toString());
cs2.set("uuid", mp.UUID.toString());
cs2.set("usernames", mp.UserNames);
cs2.set("fcount", mp.FCount);
cs2.set("fdeaths", mp.FDeaths);
cs2.set("flaircheater", mp.FlairCheater);
}
}
public static MaybeOfflinePlayer GetFromName(String name) {
for (MaybeOfflinePlayer mp : AllPlayers.values())
if (mp.PlayerName.equalsIgnoreCase(name))
return mp;
return null;
return AllPlayers.get(Bukkit.getPlayer(name).getUniqueId());
}
public String GetFormattedFlair() {
if (FlairColor == 0x00)
if (FlairTime == FlairTimeCantPress)
return String.format("§r(--s)§r");
if (FlairTime == FlairTimeNonPresser)
return String.format("§7(--s)§r");
if (FlairTime == FlairTimeNone)
return "";
if (FlairTime == null || FlairTime.length() == 0)
return String.format("§%x(??s)§r", FlairColor);
return String.format("§%x(%ss)§r", FlairColor, FlairTime);
return String.format("§%x(%ss)§r", GetFlairColor(), FlairTime);
}
public void SetFlairColor(int color) {
FlairColor = (short) color;
SetFlair2();
}
public void SetFlairTime(String time) {
public void SetFlair(short time) {
FlairTime = time;
SetFlair2();
FlairUpdate();
}
public void SetFlair(int color, String time) {
FlairColor = (short) color;
public void SetFlair(short time, boolean cheater) {
FlairTime = time;
SetFlair2();
FlairCheater = cheater;
FlairUpdate();
}
private void SetFlair2() {
public void FlairUpdate() {
// Flairs from Command Block The Button - Teams
// PluginMain.Instance.getServer().getScoreboardManager().getMainScoreboard().getTeams().add()
@ -127,10 +127,28 @@ public class MaybeOfflinePlayer {
}
public short GetFlairColor() {
return FlairColor;
if (FlairCheater)
return 0x5;
if (FlairTime == -1)
return 0x7;
else if (FlairTime == -2)
return 0xf;
else if (FlairTime <= 60 && FlairTime >= 52)
return 0x5;
else if (FlairTime <= 51 && FlairTime >= 42)
return 0x9;
else if (FlairTime <= 41 && FlairTime >= 32)
return 0xa;
else if (FlairTime <= 31 && FlairTime >= 22)
return 0xe;
else if (FlairTime <= 21 && FlairTime >= 11)
return 0x6;
else if (FlairTime <= 11 && FlairTime >= 0)
return 0xc;
return 0xf;
}
public String GetFlairTime() {
public short GetFlairTime() {
return FlairTime;
}

View file

@ -139,7 +139,7 @@ public class PlayerListener implements Listener {
mp.RPMode = true;
mp.SetFlairColor(mp.GetFlairColor()); // Update display
mp.FlairUpdate(); // Update display
boolean ispremium = ((FastLoginBukkit) FastLoginBukkit
.getPlugin(FastLoginBukkit.class)).getEnabledPremium()

View file

@ -243,33 +243,9 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
p.UserName = username;
p.FlairState = FlairStates.Recognised;
switch (flairclass) {
case "press-1":
p.SetFlairColor(0xc);
break;
case "press-2":
p.SetFlairColor(0x6);
break;
case "press-3":
p.SetFlairColor(0xe);
break;
case "press-4":
p.SetFlairColor(0xa);
break;
case "press-5":
p.SetFlairColor(0x9);
break;
case "press-6":
p.SetFlairColor(0x5);
break;
case "no-press":
p.SetFlairColor(0x7);
break;
case "cheater":
p.SetFlairColor(0x5);
break;
case "cant-press":
p.SetFlairColor(0xf);
break;
p.SetFlair((short) 0x5, true);
return;
case "unknown":
if (text.equals("-1")) // If true, only non-presser/can't press; if
// false, any flair (but we can still detect
@ -277,36 +253,34 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
{
try {
if (CheckForJoinDate(p)) {
p.SetFlair(0x7, "--");
p.SetFlair(MaybeOfflinePlayer.FlairTimeNonPresser);
} else {
p.SetFlair(0xf, "--");
p.SetFlair(MaybeOfflinePlayer.FlairTimeCantPress);
}
} catch (Exception e) {
p.FlairState = FlairStates.Commented; // Flair unknown
p.SetFlairColor(0);
p.SetFlair(MaybeOfflinePlayer.FlairTimeNone);
e.printStackTrace();
}
} else {
try {
if (CheckForJoinDate(p)) {
p.FlairState = FlairStates.Commented; // Flair unknown
p.SetFlairColor(0);
p.SetFlair(MaybeOfflinePlayer.FlairTimeNone);
} else {
p.SetFlair(0xf, "--");
p.SetFlair(MaybeOfflinePlayer.FlairTimeCantPress);
}
} catch (Exception e) {
p.FlairState = FlairStates.Commented; // Flair unknown
p.SetFlairColor(0);
p.SetFlair(MaybeOfflinePlayer.FlairTimeNone);
e.printStackTrace();
}
}
return;
default:
return;
break;
}
if (text.equals("-1"))
text = "--";
p.SetFlairTime(text);
p.SetFlair(Short.parseShort(text));
}
public static boolean CheckForJoinDate(MaybeOfflinePlayer mp)