Skip to content

Commit

Permalink
Update to newer lib. 1.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Wertik committed Jan 16, 2021
1 parent 3f5193a commit 6142ce5
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 49 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>space.devport.wertik.custommessages</groupId>
<artifactId>CustomMessages</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>

<name>CustomMessages</name>

Expand Down Expand Up @@ -96,7 +96,7 @@
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>19.0.0</version>
<version>20.1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand All @@ -108,7 +108,7 @@
<dependency>
<groupId>space.devport.utils</groupId>
<artifactId>DevportUtils</artifactId>
<version>3.7.0-SNAPSHOT</version>
<version>4.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
package space.devport.wertik.custommessages;

import lombok.Getter;
import lombok.extern.java.Log;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import org.bukkit.ChatColor;
import org.bukkit.event.HandlerList;
import space.devport.utils.DevportPlugin;
import space.devport.utils.UsageFlag;
import space.devport.utils.logging.DebugLevel;
import space.devport.utils.utility.VersionUtil;
import space.devport.wertik.custommessages.commands.MessageCommand;
import space.devport.wertik.custommessages.listeners.Listeners;
import space.devport.wertik.custommessages.listeners.PlayerListener;
import space.devport.wertik.custommessages.system.MessageManager;
import space.devport.wertik.custommessages.system.UserManager;

@Log
public class MessagePlugin extends DevportPlugin {

private MessagePlaceholders placeholders;

@Getter
private MessageManager messageManager;
private MessageManager messageManager = new MessageManager(this);

@Getter
private UserManager userManager;
private UserManager userManager = new UserManager(this);

@Getter
private Listeners listeners;
private PlayerListener playerListener;

public static MessagePlugin getInstance() {
return getPlugin(MessagePlugin.class);
Expand All @@ -36,22 +39,19 @@ public ChatColor getColor() {

@Override
public void onPluginEnable() {
this.messageManager = new MessageManager(this);
this.userManager = new UserManager(this);

messageManager.load();
messageManager.loadOptions();

userManager.load();

setupPlaceholders();

this.listeners = new Listeners(this);
listeners.registerListeners();
this.playerListener = new PlayerListener(this);
playerListener.registerListeners();

new MessageLanguage(this);
new MessageLanguage(this).register();

addMainCommand(new MessageCommand(this));
registerMainCommand(new MessageCommand(this));
}

private void unregisterPlaceholders() {
Expand All @@ -65,7 +65,7 @@ private void unregisterPlaceholders() {

placeholders.unregister();
this.placeholders = null;
consoleOutput.debug("Unregistered placeholder expansion.");
log.log(DebugLevel.DEBUG, "Unregistered placeholder expansion.");
}
}

Expand All @@ -78,7 +78,7 @@ private void setupPlaceholders() {

this.placeholders = new MessagePlaceholders(this);
placeholders.register();
consoleOutput.info("Found PlaceholderAPI! Registered expansion.");
log.info("Found PlaceholderAPI! Registered expansion.");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package space.devport.wertik.custommessages.commands;

import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import space.devport.utils.commands.MainCommand;
import space.devport.utils.commands.struct.CommandResult;
import space.devport.wertik.custommessages.MessagePlugin;
Expand All @@ -12,16 +13,16 @@
public class MessageCommand extends MainCommand {

public MessageCommand(MessagePlugin plugin) {
super("custommessages");
super(plugin, "custommessages");

addSubCommand(new ReloadSubCommand(plugin));
addSubCommand(new SetSubCommand(plugin));
addSubCommand(new PreviewSubCommand(plugin));
addSubCommand(new MenuSubCommand(plugin));
withSubCommand(new ReloadSubCommand(plugin));
withSubCommand(new SetSubCommand(plugin));
withSubCommand(new PreviewSubCommand(plugin));
withSubCommand(new MenuSubCommand(plugin));
}

@Override
protected CommandResult perform(CommandSender sender, String label, String[] args) {
protected @NotNull CommandResult perform(@NotNull CommandSender sender, @NotNull String label, String[] args) {
return super.perform(sender, label, args);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ public abstract class MessageSubCommand extends SubCommand {
protected final MessagePlugin plugin;

public MessageSubCommand(MessagePlugin plugin, String name) {
super(name);
setPermissions();
super(plugin, name);
this.plugin = plugin;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public MenuSubCommand(MessagePlugin plugin) {
}

@Override
protected CommandResult perform(CommandSender sender, String label, String[] args) {
protected @NotNull CommandResult perform(@NotNull CommandSender sender, @NotNull String label, String[] args) {

MessageType type = CommandUtils.parseType(sender, args[0]);

Expand All @@ -42,7 +42,7 @@ protected CommandResult perform(CommandSender sender, String label, String[] arg
target = (Player) sender;
}

new MessageMenu(target, type).open(target);
new MessageMenu(plugin, target, type).open(target);
if (target != sender)
plugin.getManager(LanguageManager.class).getPrefixed("Commands.Menu.Done-Others")
.replace("%type%", type.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public PreviewSubCommand(MessagePlugin plugin) {
}

@Override
protected CommandResult perform(CommandSender sender, String label, String[] args) {
protected @NotNull CommandResult perform(@NotNull CommandSender sender, @NotNull String label, String[] args) {

MessageType type = CommandUtils.parseType(sender, args[0]);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package space.devport.wertik.custommessages.gui;

import lombok.extern.java.Log;
import org.bukkit.entity.Player;
import space.devport.utils.CustomisationManager;
import space.devport.utils.logging.DebugLevel;
import space.devport.utils.menu.Menu;
import space.devport.utils.menu.MenuBuilder;
import space.devport.utils.menu.item.MatrixItem;
Expand All @@ -13,6 +15,7 @@

import java.util.List;

@Log
public class MessageMenu extends Menu {

private final MessagePlugin plugin;
Expand All @@ -25,20 +28,20 @@ public class MessageMenu extends Menu {

private int page;

public MessageMenu(Player player, MessageType type, int page) {
super("custommessages_preview");
public MessageMenu(MessagePlugin plugin, Player player, MessageType type, int page) {
super("custommessages_preview", plugin);
this.player = player;
this.type = type;
this.plugin = MessagePlugin.getInstance();

this.page = page;
this.slotsPerPage = countMatrixSlots(plugin.getManager(CustomisationManager.class).getMenuBuilder("message-overview").construct(), 'm');
this.slotsPerPage = countMatrixSlots(plugin.getManager(CustomisationManager.class).getMenu("message-overview").construct(), 'm');

build();
}

public MessageMenu(Player player, MessageType type) {
this(player, type, 1);
public MessageMenu(MessagePlugin plugin, Player player, MessageType type) {
this(plugin, player, type, 1);
}

private int countMatrixSlots(MenuBuilder menuBuilder, char character) {
Expand All @@ -55,7 +58,7 @@ private void build() {
User user = plugin.getUserManager().getOrCreateUser(player);
String usedMessage = user.getMessage(type);

MenuBuilder menuBuilder = new MenuBuilder(plugin.getManager(CustomisationManager.class).getMenuBuilder("message-overview").construct());
MenuBuilder menuBuilder = plugin.getManager(CustomisationManager.class).getMenu("message-overview").construct();

MatrixItem messageMatrix = menuBuilder.getMatrixItem('m');
messageMatrix.clear();
Expand All @@ -77,7 +80,7 @@ private void build() {
String key = messages.get(i);
MenuItem item = new MenuItem(usedMessage.equals(key) ? messageItemTaken : messageItem);

item.getItemBuilder().getPlaceholders()
item.getPrefab().getPlaceholders()
.add("%message_name%", key)
.add("%message_formatted%", plugin.getMessageManager().getFormattedMessage(player, type, key));

Expand All @@ -91,7 +94,7 @@ private void build() {
}

for (MenuItem i : messageMatrix.getMenuItems()) {
plugin.getConsoleOutput().debug(i.getItemBuilder().getPlaceholders().getPlaceholderCache().toString());
log.log(DebugLevel.DEBUG, i.getPrefab().getPlaceholders().getPlaceholderCache().toString());
}

// Page control and close
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package space.devport.wertik.custommessages.listeners;

import lombok.extern.java.Log;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand All @@ -15,12 +16,13 @@
import java.util.HashMap;
import java.util.Map;

public class Listeners {
@Log
public class PlayerListener {

private final MessagePlugin plugin;
private final MessageManager messageManager;

public Listeners(MessagePlugin plugin) {
public PlayerListener(MessagePlugin plugin) {
this.plugin = plugin;
this.messageManager = plugin.getMessageManager();
}
Expand Down Expand Up @@ -52,7 +54,7 @@ public void onKick(PlayerKickEvent event) {
}
});

plugin.getConsoleOutput().info("Registered " + this.registeredListeners.size() + " listener(s)...");
log.info("Registered " + this.registeredListeners.size() + " listener(s)...");
}

public void registerListener(MessageType type, Listener listener) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.base.Strings;
import lombok.Getter;
import lombok.extern.java.Log;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -19,6 +20,7 @@
import java.util.List;
import java.util.Map;

@Log
public class MessageManager {

private final MessagePlugin plugin;
Expand Down Expand Up @@ -70,7 +72,7 @@ public void load() {
}
}

plugin.getConsoleOutput().info("Loaded " + this.loadedMessages.values().stream().map(m -> m.getMessages().values()).count() + " message(s)...");
log.info("Loaded " + this.loadedMessages.values().stream().map(m -> m.getMessages().values()).count() + " message(s)...");
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package space.devport.wertik.custommessages.system;

import lombok.extern.java.Log;
import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import space.devport.utils.ConsoleOutput;
import space.devport.utils.utility.json.GsonHelper;
import space.devport.wertik.custommessages.MessagePlugin;
import space.devport.wertik.custommessages.system.struct.User;
Expand All @@ -13,6 +13,7 @@
import java.util.Map;
import java.util.UUID;

@Log
public class UserManager {

private final MessagePlugin plugin;
Expand Down Expand Up @@ -61,9 +62,9 @@ public void load() {
this.loadedUsers.clear();
this.loadedUsers.putAll(users);

ConsoleOutput.getInstance().info("Loaded " + this.loadedUsers.size() + " user(s)...");
log.info("Loaded " + this.loadedUsers.size() + " user(s)...");
}).exceptionally(e -> {
ConsoleOutput.getInstance().err("Could not load users: " + e.getMessage());
log.severe("Could not load users: " + e.getMessage());
e.printStackTrace();
return null;
});
Expand All @@ -77,7 +78,7 @@ private void purgeEmpty() {
count++;
}
}
plugin.getConsoleOutput().info("Purged " + count + " empty account(s)...");
log.info("Purged " + count + " empty account(s)...");
}

public void save() {
Expand All @@ -86,9 +87,9 @@ public void save() {
final Map<UUID, User> finalCache = new HashMap<>(this.loadedUsers);

gsonHelper.save(finalCache, plugin.getDataFolder().getPath() + "/data.json").thenRunAsync(() -> {
ConsoleOutput.getInstance().info("Saved " + finalCache.size() + " user(s)...");
log.info("Saved " + finalCache.size() + " user(s)...");
}).exceptionally(e -> {
ConsoleOutput.getInstance().err("Could not save users: " + e.getMessage());
log.severe("Could not save users: " + e.getMessage());
e.printStackTrace();
return null;
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package space.devport.wertik.custommessages.system.struct;

import com.cryptomorin.xseries.messages.Titles;
import com.google.common.base.Strings;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;
import space.devport.utils.text.StringUtil;
import space.devport.utils.xseries.messages.ActionBar;
import space.devport.utils.xseries.messages.Titles;
import space.devport.wertik.custommessages.MessagePlugin;

public enum MessagePosition {
Expand Down
Loading

0 comments on commit 6142ce5

Please sign in to comment.