Merge pull request #47 from TBMCPlugins/dev

Added CG user to chat event & other improvements
This commit is contained in:
Norbi Peti 2018-07-20 13:22:10 +02:00 committed by GitHub
commit 07b52a5b54
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
35 changed files with 154 additions and 173 deletions

View file

@ -12,8 +12,6 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="ButtonCore (1) (com.github.TBMCPlugins.ButtonCore)" />
<orderEntry type="module" module-name="ButtonCore (1) (com.github.TBMCPlugins.ButtonCore)" />
<orderEntry type="module" module-name="ButtonCore (1) (com.github.TBMCPlugins.ButtonCore)" />
<orderEntry type="library" name="Maven: org.reflections:reflections:0.9.10" level="project" />
<orderEntry type="library" name="Maven: com.google.code.findbugs:annotations:2.0.1" level="project" />
<orderEntry type="library" name="Maven: org.javassist:javassist:3.20.0-GA" level="project" />

View file

@ -8,7 +8,7 @@ public class BCUMain {
System.out.println("Getting list of repositories...");
List<String> plugins = PluginUpdater.GetPluginNames();
System.out.println("Removing non-Maven projects...");
plugins.removeIf(plugin -> !PluginUpdater.isMaven(plugin, "master"));
plugins.removeIf(plugin -> PluginUpdater.isNotMaven(plugin, "master"));
System.out.println(plugins.stream().collect(Collectors.joining("\n")));
for (String plugin : plugins) { //TODO: We don't want to apply it all at once, especially to unused/unowned repos
} //TODO: Add it to ButtonCore - or actually as a plugin or ButtonProcessor

View file

@ -29,14 +29,13 @@ public class MainPlugin extends JavaPlugin {
public static boolean Test;
public static Essentials ess;
private PluginDescriptionFile pdfFile;
private Logger logger;
@Override
public void onEnable() {
// Logs "Plugin Enabled", registers commands
Instance = this;
pdfFile = getDescription();
PluginDescriptionFile pdf = getDescription();
logger = getLogger();
setupPermissions();
Test = getConfig().getBoolean("test", true);
@ -66,7 +65,7 @@ public class MainPlugin extends JavaPlugin {
}
ess = Essentials.getPlugin(Essentials.class);
new RandomTP().onEnable(this); //It registers it's command
logger.info(pdfFile.getName() + " has been Enabled (V." + pdfFile.getVersion() + ") Test: " + Test + ".");
logger.info(pdf.getName() + " has been Enabled (V." + pdf.getVersion() + ") Test: " + Test + ".");
}
@Override

View file

@ -53,7 +53,7 @@ public class PlayerListener implements Listener {
public void onSystemChat(TBMCSystemChatEvent event) {
if (event.isHandled())
return; // Only handle here if ButtonChat couldn't
Bukkit.getOnlinePlayers().stream().filter(p -> event.shouldSendTo(p))
Bukkit.getOnlinePlayers().stream().filter(event::shouldSendTo)
.forEach(p -> p.sendMessage(event.getChannel().DisplayName.substring(0, 2) + event.getMessage()));
}
}

View file

@ -24,6 +24,8 @@ public class ScheduledRestartCommand extends TBMCCommandBase {
if (args.length > 0)
ticks = Integer.parseInt(args[0]);
} catch (NumberFormatException e) {
sender.sendMessage("§cError: Ticks must be a number.");
return false;
}
if (ticks < 20) {
sender.sendMessage("§cError: Ticks must be more than 20.");
@ -33,14 +35,14 @@ public class ScheduledRestartCommand extends TBMCCommandBase {
restartbar = Bukkit.createBossBar("Server restart in " + ticks / 20f, BarColor.RED, BarStyle.SOLID,
BarFlag.DARKEN_SKY);
restartbar.setProgress(1);
Bukkit.getOnlinePlayers().stream().forEach(p -> restartbar.addPlayer(p));
Bukkit.getOnlinePlayers().forEach(p -> restartbar.addPlayer(p));
sender.sendMessage("Scheduled restart in " + ticks / 20f);
ScheduledServerRestartEvent e = new ScheduledServerRestartEvent(ticks);
Bukkit.getPluginManager().callEvent(e);
restarttask = Bukkit.getScheduler().runTaskTimer(MainPlugin.Instance, () -> {
if (restartcounter < 0) {
restarttask.cancel();
restartbar.getPlayers().stream().forEach(p -> restartbar.removePlayer(p));
restartbar.getPlayers().forEach(p -> restartbar.removePlayer(p));
Bukkit.spigot().restart();
}
if (restartcounter % 200 == 0)

View file

@ -20,7 +20,7 @@ public class TestPrepare {
Bukkit.setServer(Mockito.mock(Server.class, new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
public Object answer(InvocationOnMock invocation) {
if (returns(invocation, String.class))
return "test";
if (returns(invocation, Logger.class))

View file

@ -11,23 +11,22 @@ import org.bukkit.command.CommandSender;
public class UpdatePluginCommand extends TBMCCommandBase {
@Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
if (args.length == 0) {
sender.sendMessage("Downloading plugin names...");
boolean first = true;
for (String plugin : PluginUpdater.GetPluginNames()) {
if (first) {
sender.sendMessage("§6---- Plugin names ----");
first = false;
}
sender.sendMessage("- " + plugin);
}
return true;
} else {
Bukkit.getScheduler().runTaskAsynchronously(MainPlugin.Instance, () -> {
TBMCCoreAPI.UpdatePlugin(args[0], sender, args.length == 1 ? "master" : args[1]);
});
return true;
}
Bukkit.getScheduler().runTaskAsynchronously(MainPlugin.Instance, () -> {
if (args.length == 0) {
sender.sendMessage("Downloading plugin names...");
boolean first = true;
for (String plugin : PluginUpdater.GetPluginNames()) {
if (first) {
sender.sendMessage("§6---- Plugin names ----");
first = false;
}
sender.sendMessage("- " + plugin);
}
} else {
TBMCCoreAPI.UpdatePlugin(args[0], sender, args.length == 1 ? "master" : args[1]);
}
});
return true;
}
@Override

View file

@ -22,11 +22,8 @@ abstract class EventExceptionHandler { // https://gist.github.com/aadnk/5430459
* Represents an event executor that does nothing. This is not really necessary in the current
* implementation of CraftBukkit, but we will take no chances.
*/
private static EventExecutor NULL_EXECUTOR = new EventExecutor() {
@Override
public void execute(Listener listener, Event event) throws EventException {
// Do nothing
}
private static final EventExecutor NULL_EXECUTOR = (listener, event) -> {
// Do nothing
};
private final RegisteredListener delegate;

View file

@ -55,7 +55,7 @@ public class PluginUpdater {
error(sender, "Can't find branch \"" + branch + "\" for plugin \"" + correctname + "\"");
return false;
}
if (!isMaven(correctname, correctbranch.get())) {
if (isNotMaven(correctname, correctbranch.get())) {
error(sender, "The plugin doesn't appear to have a pom.xml. Make sure it's a Maven project.");
return false;
}
@ -98,21 +98,21 @@ public class PluginUpdater {
}
/**
* Checks if pom.xml is present for the project.
* Checks if pom.xml is not present for the project.
*
* @param pluginname
* Does not have to match case
* @param branch
* Does not have to match case
*/
public static boolean isMaven(String pluginname, String branch) {
public static boolean isNotMaven(String pluginname, String branch) {
try {
return !TBMCCoreAPI
return TBMCCoreAPI
.DownloadString(
"https://raw.githubusercontent.com/TBMCPlugins/" + pluginname + "/" + branch + "/pom.xml")
.equals("404: Not Found\n");
} catch (IOException e1) {
return false;
return true;
}
}
@ -172,7 +172,7 @@ public class PluginUpdater {
public static class UpdatedEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private JsonObject data;
private final JsonObject data;
public UpdatedEvent(JsonObject data) {
this.data = data;

View file

@ -6,7 +6,7 @@ import org.bukkit.event.HandlerList;
public class ScheduledServerRestartEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private int restartticks;
private final int restartticks;
public ScheduledServerRestartEvent(int restartticks) {
this.restartticks = restartticks;

View file

@ -1,6 +1,7 @@
package buttondevteam.lib;
import buttondevteam.lib.chat.Channel;
import buttondevteam.lib.player.ChromaGamerBase;
import lombok.Getter;
import org.bukkit.command.CommandSender;
import org.bukkit.event.HandlerList;
@ -15,25 +16,28 @@ import javax.annotation.Nullable;
*/
@Getter
public class TBMCChatEvent extends TBMCChatEventBase {
public TBMCChatEvent(CommandSender sender, Channel channel, String message, int score, boolean fromcmd, String groupid) {
public TBMCChatEvent(CommandSender sender, ChromaGamerBase user, Channel channel, String message, int score, boolean fromcmd, String groupid) {
super(channel, message, score, groupid);
this.sender = sender;
this.fromcmd = fromcmd;
this.ignoreSenderPermissions = false;
this.user = user;
}
public TBMCChatEvent(CommandSender sender, Channel channel, String message, int score, boolean fromcmd, String groupid, boolean ignoreSenderPermissions) {
public TBMCChatEvent(CommandSender sender, ChromaGamerBase user, Channel channel, String message, int score, boolean fromcmd, String groupid, boolean ignoreSenderPermissions) {
super(channel, message, score, groupid);
this.sender = sender;
this.user = user;
this.fromcmd = fromcmd;
this.ignoreSenderPermissions = ignoreSenderPermissions;
}
private static final HandlerList handlers = new HandlerList();
private CommandSender sender;
private boolean fromcmd;
private final CommandSender sender;
private final boolean fromcmd;
private final boolean ignoreSenderPermissions;
private final ChromaGamerBase user;
// TODO: Message object with data?
/**

View file

@ -1,6 +1,8 @@
package buttondevteam.lib;
import buttondevteam.lib.chat.Channel;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.command.CommandSender;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
@ -13,13 +15,16 @@ import org.bukkit.event.HandlerList;
* @author NorbiPeti
*
*/
@Getter
public class TBMCChatPreprocessEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private Channel channel;
private CommandSender sender;
private final Channel channel;
private final CommandSender sender;
@Setter
private String message;
private boolean cancelled;
@Setter
private boolean cancelled;
public TBMCChatPreprocessEvent(CommandSender sender, Channel channel, String message) {
this.sender = sender;
@ -31,22 +36,6 @@ public class TBMCChatPreprocessEvent extends Event implements Cancellable {
* public TBMCPlayer getPlayer() { return TBMCPlayer.getPlayer(sender); // TODO: Get Chroma user }
*/
public Channel getChannel() {
return channel;
}
public CommandSender getSender() {
return sender;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
@Override
public HandlerList getHandlers() {
return handlers;
@ -55,14 +44,4 @@ public class TBMCChatPreprocessEvent extends Event implements Cancellable {
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View file

@ -12,7 +12,6 @@ import org.bukkit.plugin.Plugin;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
@ -21,7 +20,7 @@ import java.util.List;
import java.util.Map.Entry;
public class TBMCCoreAPI {
static List<String> coders = new ArrayList<String>() {
static final List<String> coders = new ArrayList<String>() {
private static final long serialVersionUID = -4462159250738367334L;
{
add("Alisolarflare");
@ -59,7 +58,7 @@ public class TBMCCoreAPI {
return PluginUpdater.UpdatePlugin(name, sender, branch);
}
public static String DownloadString(String urlstr) throws MalformedURLException, IOException {
public static String DownloadString(String urlstr) throws IOException {
URL url = new URL(urlstr);
URLConnection con = url.openConnection();
con.setRequestProperty("User-Agent", "TBMCPlugins");

View file

@ -5,7 +5,7 @@ import org.bukkit.event.HandlerList;
public class TBMCDebugMessageEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private String message;
private final String message;
private boolean sent;
public TBMCDebugMessageEvent(String message) {

View file

@ -24,7 +24,7 @@ public class Channel {
*/
public final Function<CommandSender, RecipientTestResult> filteranderrormsg;
private static List<Channel> channels = new ArrayList<>();
private static final List<Channel> channels = new ArrayList<>();
/**
* Creates a channel.
@ -66,12 +66,11 @@ public class Channel {
* generated automatically.
*
* @param permgroup The group that can access the channel or <b>null</b> to only allow OPs.
* @return
* @return If has access
*/
public static Function<CommandSender, RecipientTestResult> inGroupFilter(String permgroup) {
return noScoreResult(
s -> s.isOp() || (permgroup != null
? s instanceof Player && MainPlugin.permission != null && MainPlugin.permission.playerInGroup((Player) s, permgroup) : false),
s -> s.isOp() || (permgroup != null && (s instanceof Player && MainPlugin.permission != null && MainPlugin.permission.playerInGroup((Player) s, permgroup))),
"You need to be a(n) " + (permgroup != null ? permgroup : "OP") + " to use this channel.");
}

View file

@ -6,7 +6,7 @@ import org.bukkit.event.HandlerList;
public class ChatChannelRegisterEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private Channel channel;
private final Channel channel;
public ChatChannelRegisterEvent(Channel channel) {
this.channel = channel;

View file

@ -0,0 +1,46 @@
package buttondevteam.lib.chat;
import buttondevteam.lib.player.ChromaGamerBase;
import lombok.Builder;
import lombok.Getter;
import lombok.NonNull;
import org.bukkit.command.CommandSender;
@Builder
@Getter
public class ChatMessage {
/**
* The MC channel to send the message to.
*/
private final Channel channel;
/**
* The sender which sends the message.
*/
private final CommandSender sender;
/**
* The Chroma user which sends the message.
*/
private final ChromaGamerBase user;
/**
* The message to send as the user.
*/
private final String message;
/**
* Indicates whether the message comes from running a command (like /tableflip). Implemented to be used from Discord.
*/
private boolean fromCommand;
/**
* The sender which we should check for permissions. Same as {@link #sender} by default.
*/
private CommandSender permCheck;
private static ChatMessageBuilder builder() {
return new ChatMessageBuilder();
}
@NonNull
public static ChatMessageBuilder builder(Channel channel, CommandSender sender, ChromaGamerBase user, String message) {
return builder().channel(channel).sender(sender).user(user).message(message);
}
}

View file

@ -6,7 +6,7 @@ import java.util.ArrayList;
import java.util.List;
public class ChatRoom extends Channel {
private List<CommandSender> usersInRoom = new ArrayList<>();
private final List<CommandSender> usersInRoom = new ArrayList<>();
public ChatRoom(String displayname, Color color, String command) {
<ChatRoom>super(displayname, color, command, noScoreResult((this_, s) -> this_.usersInRoom.contains(s),

View file

@ -20,7 +20,7 @@ public @interface CommandClass {
*
* @return If the command is mod only
*/
public boolean modOnly() default false;
boolean modOnly() default false;
/**
* The command's path, or name if top-level command.<br>
@ -30,10 +30,10 @@ public @interface CommandClass {
*
* @return The command path, <i>which is the command class name by default</i> (removing any "command" from it)
*/
public String path() default "";
String path() default "";
/**
* Exclude this class from the path. Useful if more commands share some property but aren't subcommands of a common command. See {@link CommandClass} for more details.
*/
public boolean excludeFromPath() default false;
boolean excludeFromPath() default false;
}

View file

@ -12,5 +12,5 @@ import java.lang.annotation.*;
@Target(ElementType.TYPE)
@Inherited
public @interface OptionallyPlayerCommandClass {
public boolean playerOnly();
boolean playerOnly();
}

View file

@ -2,7 +2,7 @@ package buttondevteam.lib.chat;
public enum Priority {
Low(0), Normal(1), High(2);
private int val;
private final int val;
Priority(int v) {
val = v;

View file

@ -7,6 +7,7 @@ import buttondevteam.lib.TBMCChatPreprocessEvent;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.TBMCSystemChatEvent;
import buttondevteam.lib.chat.Channel.RecipientTestResult;
import lombok.val;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -26,7 +27,7 @@ import java.util.function.Consumer;
public class TBMCChatAPI {
private static HashMap<String, TBMCCommandBase> commands = new HashMap<String, TBMCCommandBase>();
private static final HashMap<String, TBMCCommandBase> commands = new HashMap<>();
public static HashMap<String, TBMCCommandBase> GetCommands() {
return commands;
@ -77,7 +78,7 @@ public class TBMCChatAPI {
addToCmds.accept("/" + cmd.getKey());
}
}
return cmds.toArray(new String[cmds.size()]);
return cmds.toArray(new String[0]); //Apparently it's faster to use an empty array in modern Java
}
/**
@ -149,7 +150,7 @@ public class TBMCChatAPI {
try {
TBMCCommandBase c;
if (params.length > 0)
c = thecmdclass.getConstructor(Arrays.stream(params).map(p -> p.getClass()).toArray(Class[]::new))
c = thecmdclass.getConstructor(Arrays.stream(params).map(Object::getClass).toArray(Class[]::new))
.newInstance(params);
else
c = thecmdclass.newInstance();
@ -205,70 +206,31 @@ public class TBMCChatAPI {
return false;
}
/**
* Sends a chat message to Minecraft. Make sure that the channel is registered with {@link #RegisterChatChannel(Channel)}.
*
* @param channel
* The channel to send to
* @param sender
* The sender to send from
* @param message
* The message to send
* @return The event cancelled state
*/
public static boolean SendChatMessage(Channel channel, CommandSender sender, String message) {
return SendChatMessage(channel, sender, message, false);
}
/**
* Sends a chat message to Minecraft. Make sure that the channel is registered with {@link #RegisterChatChannel(Channel)}.<br>
* This will also send the error message to the sender, if they can't send the message.
*
* @param channel The channel to send to
* @param sender The sender to send from
* @param message The message to send
* @param fromcommand Whether this message comes from running a command, used to determine whether to delete Discord messages for example
* @param cm The message to send
* @return The event cancelled state
*/
public static boolean SendChatMessage(Channel channel, CommandSender sender, String message, boolean fromcommand) {
return sendChatMessageInternal(channel, sender, message, fromcommand, sender);
}
private static boolean sendChatMessageInternal(Channel channel, CommandSender sender, String message, boolean fromcommand, CommandSender permcheck) {
if (!Channel.getChannels().contains(channel))
throw new RuntimeException("Channel " + channel.DisplayName + " not registered!");
RecipientTestResult rtr = getScoreOrSendError(channel, permcheck);
public static boolean SendChatMessage(ChatMessage cm) {
if (!Channel.getChannels().contains(cm.getChannel()))
throw new RuntimeException("Channel " + cm.getChannel().DisplayName + " not registered!");
val permcheck = cm.getPermCheck() == null ? cm.getSender() : cm.getPermCheck();
RecipientTestResult rtr = getScoreOrSendError(cm.getChannel(), permcheck);
int score = rtr.score;
if (score == -1 || rtr.groupID == null)
return true;
TBMCChatPreprocessEvent eventPre = new TBMCChatPreprocessEvent(sender, channel, message);
TBMCChatPreprocessEvent eventPre = new TBMCChatPreprocessEvent(cm.getSender(), cm.getChannel(), cm.getMessage());
Bukkit.getPluginManager().callEvent(eventPre);
if (eventPre.isCancelled())
return true;
TBMCChatEvent event;
if (permcheck == sender)
event = new TBMCChatEvent(sender, channel, eventPre.getMessage(), score, fromcommand, rtr.groupID);
else
event = new TBMCChatEvent(sender, channel, eventPre.getMessage(), score, fromcommand, rtr.groupID, true);
event = new TBMCChatEvent(cm.getSender(), cm.getUser(), cm.getChannel(), eventPre.getMessage(), score, cm.isFromCommand(), rtr.groupID, permcheck != cm.getSender());
Bukkit.getPluginManager().callEvent(event);
return event.isCancelled();
}
/**
* Sends a chat message to Minecraft. Make sure that the channel is registered with {@link #RegisterChatChannel(Channel)}.<br>
* This will not check if the sender has permission.
*
* @param channel The channel to send to
* @param sender The sender to send from
* @param message The message to send
* @param fromcommand Whether this message comes from running a command, used to determine whether to delete Discord messages for example
* @param permcheck The sender to check permissions
* @return The event cancelled state
*/
public static boolean SendChatMessageDontCheckSender(Channel channel, CommandSender sender, String message, boolean fromcommand, CommandSender permcheck) {
return sendChatMessageInternal(channel, sender, message, fromcommand, permcheck);
}
/**
* Sends a regular message to Minecraft. Make sure that the channel is registered with {@link #RegisterChatChannel(Channel)}.
*

View file

@ -40,7 +40,7 @@ public abstract class TBMCCommandBase {
return path;
}
private final String getcmdpath() {
private String getcmdpath() {
if (!getClass().isAnnotationPresent(CommandClass.class))
throw new RuntimeException(
"No @CommandClass annotation on command class " + getClass().getSimpleName() + "!");
@ -72,11 +72,10 @@ public abstract class TBMCCommandBase {
}
public final boolean isPlayerOnly() {
return this instanceof PlayerCommandBase ? true
: this instanceof OptionallyPlayerCommandBase
? getClass().isAnnotationPresent(OptionallyPlayerCommandClass.class)
? getClass().getAnnotation(OptionallyPlayerCommandClass.class).playerOnly() : true
: false;
return this instanceof PlayerCommandBase ||
(this instanceof OptionallyPlayerCommandBase &&
(!getClass().isAnnotationPresent(OptionallyPlayerCommandClass.class)
|| getClass().getAnnotation(OptionallyPlayerCommandClass.class).playerOnly()));
}
private final boolean modonly;
@ -88,7 +87,7 @@ public abstract class TBMCCommandBase {
return modonly;
}
private final boolean ismodonly() {
private boolean ismodonly() {
if (!getClass().isAnnotationPresent(CommandClass.class))
throw new RuntimeException(
"No @CommandClass annotation on command class " + getClass().getSimpleName() + "!");

View file

@ -1,5 +1,5 @@
package buttondevteam.lib.chat;
public interface TellrawSerializableEnum {
public String getName();
String getName();
}

View file

@ -72,10 +72,10 @@ public abstract class ChromaGamerBase implements AutoCloseable {
/***
* Loads a user from disk and returns the user object. Make sure to use the subclasses' methods, where possible, like {@link TBMCPlayerBase#getPlayer(java.util.UUID, Class)}
*
* @param fname
* @param cl
* @return
*
* @param fname Filename without .yml, usually UUID
* @param cl User class
* @return The user object
*/
public static <T extends ChromaGamerBase> T getUser(String fname, Class<T> cl) {
try {
@ -194,7 +194,7 @@ public abstract class ChromaGamerBase implements AutoCloseable {
}
@SuppressWarnings("rawtypes")
private HashMap<String, PlayerData> datamap = new HashMap<>();
private final HashMap<String, PlayerData> datamap = new HashMap<>();
/**
* Use from a data() method, which is in a method with the name of the key. For example, use flair() for the enclosing method of the outer data() to save to and load from "flair"
@ -225,7 +225,7 @@ public abstract class ChromaGamerBase implements AutoCloseable {
}
@SuppressWarnings("rawtypes")
private HashMap<String, EnumPlayerData> dataenummap = new HashMap<>();
private final HashMap<String, EnumPlayerData> dataenummap = new HashMap<>();
/**
* Use from a data() method, which is in a method with the name of the key. For example, use flair() for the enclosing method of the outer data() to save to and load from "flair"

View file

@ -3,9 +3,9 @@ package buttondevteam.lib.player;
import org.bukkit.configuration.file.YamlConfiguration;
public class EnumPlayerData<T extends Enum<T>> {
private PlayerData<String> data;
private Class<T> cl;
private T def;
private final PlayerData<String> data;
private final Class<T> cl;
private final T def;
public EnumPlayerData(String name, YamlConfiguration yaml, Class<T> cl, T def) {
data = new PlayerData<String>(name, yaml, "");

View file

@ -3,9 +3,9 @@ package buttondevteam.lib.player;
import org.bukkit.configuration.file.YamlConfiguration;
public class PlayerData<T> {
private String name;
private YamlConfiguration yaml;
private T def;
private final String name;
private final YamlConfiguration yaml;
private final T def;
public PlayerData(String name, YamlConfiguration yaml, T def) {
this.name = name;

View file

@ -19,9 +19,9 @@ import java.util.stream.Collectors;
public class TBMCPlayerGetInfoEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private ChromaGamerBase player;
private List<String> infolines;
private InfoTarget target;
private final ChromaGamerBase player;
private final List<String> infolines;
private final InfoTarget target;
TBMCPlayerGetInfoEvent(ChromaGamerBase player, InfoTarget target) {
this.player = player;

View file

@ -7,8 +7,8 @@ import org.bukkit.event.HandlerList;
public class TBMCPlayerJoinEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private TBMCPlayerBase player;
private Player player_;
private final TBMCPlayerBase player;
private final Player player_;
public TBMCPlayerJoinEvent(TBMCPlayerBase player, Player player_) {
this.player = player;

View file

@ -6,7 +6,7 @@ import org.bukkit.event.HandlerList;
public class TBMCPlayerLoadEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private TBMCPlayerBase player;
private final TBMCPlayerBase player;
public TBMCPlayerLoadEvent(TBMCPlayerBase player) {
this.player = player;

View file

@ -7,8 +7,8 @@ import org.bukkit.event.HandlerList;
public class TBMCPlayerQuitEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private TBMCPlayerBase player;
private Player player_;
private final TBMCPlayerBase player;
private final Player player_;
public TBMCPlayerQuitEvent(TBMCPlayerBase player, Player player_) {
this.player = player;

View file

@ -6,7 +6,7 @@ import org.bukkit.event.HandlerList;
public class TBMCPlayerSaveEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private TBMCPlayerBase player;
private final TBMCPlayerBase player;
public TBMCPlayerSaveEvent(TBMCPlayerBase player) {
this.player = player;

View file

@ -6,7 +6,7 @@ import org.bukkit.event.HandlerList;
public class TBMCYEEHAWEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private CommandSender sender;
private final CommandSender sender;
public TBMCYEEHAWEvent(CommandSender sender) {
this.sender = sender;

View file

@ -49,9 +49,7 @@ public class DebugPotato {
List<String> tempList = new ArrayList<String>();
for(String line: message){
tempList = WordWrap(line.toString());
for (String s: tempList){
outputList.add(s);
}
outputList.addAll(tempList);
}
this.message = outputList;
}

View file

@ -32,13 +32,13 @@ public class PlayerDataTest extends TestCase {
assertEquals("Test", p.PlayerName().get());
assertEquals(TestEnum.A, p.testenum().get());
assertEquals((short) 0, (short) p.TestShort().get());
assertEquals(false, (boolean) p.TestBool().get());
assertFalse(p.TestBool().get());
p.testenum().set(TestEnum.B);
assertEquals(TestEnum.B, p.testenum().get());
p.TestShort().set((short) 5);
assertEquals((short) 5, (short) p.TestShort().get());
p.TestBool().set(true);
assertEquals(true, (boolean) p.TestBool().get());
assertTrue(p.TestBool().get());
} catch (Exception e) {
throw e;
}
@ -46,7 +46,7 @@ public class PlayerDataTest extends TestCase {
assertEquals("Test", p.PlayerName().get());
assertEquals(TestEnum.B, p.testenum().get());
assertEquals((short) 5, (short) p.TestShort().get());
assertEquals(true, (boolean) p.TestBool().get());
assertTrue(p.TestBool().get());
} catch (Exception e) {
throw e;
}