Formatting fixes (and bugs), chat debug and tests improved, fixed F NPE, plugin name list made async #67

Merged
NorbiPeti merged 10 commits from dev into master 2017-07-04 16:27:08 +00:00
4 changed files with 17 additions and 19 deletions
Showing only changes of commit 2b48aba75e - Show all commits

View file

@ -15,34 +15,31 @@ import buttondevteam.lib.player.TBMCPlayerBase;
@PlayerClass(pluginname = "ButtonChat")
public class ChatPlayer extends TBMCPlayerBase {
public PlayerData<String> UserName() {
return data();
return data(null);
}
public List<String> UserNames() {
PlayerData<List<String>> data = data();
if (data.get() == null)
data.set(new ArrayList<String>());
return data.get();
return data(new ArrayList<String>()).get();
}
public PlayerData<Integer> FlairTime() {
return data();
return data(FlairTimeNone);
}
public EnumPlayerData<FlairStates> FlairState() {
return dataEnum(FlairStates.class);
return dataEnum(FlairStates.class, FlairStates.NoComment);
}
public PlayerData<Integer> FCount() {
return data();
return data(0);
}
public PlayerData<Integer> FDeaths() {
return data();
return data(0);
}
public PlayerData<Boolean> FlairCheater() {
return data();
return data(false);
}
public boolean RPMode = true;
@ -68,7 +65,7 @@ public class ChatPlayer extends TBMCPlayerBase {
* @return The flair
*/
public String GetFormattedFlair(boolean noformats) {
int time = FlairTime().getOrDefault(FlairTimeNone);
int time = FlairTime().get();
if (time == FlairTimeCantPress)
return String.format(noformats ? "(can't press)" : "§r(--s)§r");
if (time == FlairTimeNonPresser)
@ -108,9 +105,9 @@ public class ChatPlayer extends TBMCPlayerBase {
}
public short GetFlairColor() {
if (FlairCheater().getOrDefault(false))
if (FlairCheater().get())
return 0x5;
final int flairTime = FlairTime().getOrDefault(FlairTimeNone);
final int flairTime = FlairTime().get();
if (flairTime == FlairTimeNonPresser)
return 0x7;
else if (flairTime == FlairTimeCantPress)

View file

@ -186,8 +186,9 @@ public class ChatProcessing {
: "-"))))
.addExtra(new TellrawPart(String.format(
"Respect: %s%s%s",
(mp != null ? (mp.FCount().getOrDefault(0)
/ (double) mp.FDeaths().getOrDefault(0))
(mp != null
? (mp.FCount().get()
/ (double) mp.FDeaths().get())
: "Infinite"),
(mp != null && mp.UserName().get() != null
&& !mp.UserName().get().isEmpty()

View file

@ -144,7 +144,7 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
*/
if (!mp.UserNames().contains(author))
mp.UserNames().add(author);
if (mp.FlairState().getOrDefault(FlairStates.NoComment).equals(FlairStates.NoComment)) {
if (mp.FlairState().get().equals(FlairStates.NoComment)) {
mp.FlairState().set(FlairStates.Commented);
ConfirmUserMessage(mp);
}

View file

@ -156,8 +156,8 @@ public class PlayerListener implements Listener {
public void run() {
if (ActiveF) {
ActiveF = false;
if (FPlayer != null && FPlayer.FCount().getOrDefault(0) < Integer.MAX_VALUE - 1)
FPlayer.FCount().set(FPlayer.FCount().getOrDefault(0) + Fs.size());
if (FPlayer != null && FPlayer.FCount().get() < Integer.MAX_VALUE - 1)
FPlayer.FCount().set(FPlayer.FCount().get() + Fs.size());
Bukkit.broadcastMessage("§b" + Fs.size() + " " + (Fs.size() == 1 ? "person" : "people")
+ " paid their respects.§r");
Fs.clear();
@ -263,7 +263,7 @@ public class PlayerListener implements Listener {
final String flair = cp.GetFormattedFlair(e.getTarget() != InfoTarget.MCCommand);
if (flair.length() > 0)
e.addInfo("/r/TheButton flair: " + flair);
e.addInfo("Respect: " + (double) cp.FCount().getOrDefault(0) / (double) cp.FDeaths().getOrDefault(0));
e.addInfo("Respect: " + (double) cp.FCount().get() / (double) cp.FDeaths().get());
} catch (Exception ex) {
TBMCCoreAPI.SendException("Error while providing chat info for player " + e.getPlayer().getFileName(), ex);
}