moved classes to packages

This commit is contained in:
mfnalex 2021-05-30 20:52:40 +02:00
parent e3921c8347
commit 8abe5206d6
17 changed files with 172 additions and 137 deletions

View File

@ -28,10 +28,24 @@
package de.jeff_media.chestsort; package de.jeff_media.chestsort;
import at.pcgamingfreaks.Minepacks.Bukkit.API.MinepacksPlugin; import at.pcgamingfreaks.Minepacks.Bukkit.API.MinepacksPlugin;
import de.jeff_media.chestsort.commands.ChestSortAdminCommand;
import de.jeff_media.chestsort.commands.ChestSortChestSortCommand;
import de.jeff_media.chestsort.commands.ChestSortInvSortCommand;
import de.jeff_media.chestsort.commands.ChestSortTabCompleter;
import de.jeff_media.chestsort.config.ChestSortConfigUpdater;
import de.jeff_media.chestsort.config.Messages;
import de.jeff_media.chestsort.config.Config; import de.jeff_media.chestsort.config.Config;
import de.jeff_media.chestsort.data.ChestSortCategory;
import de.jeff_media.chestsort.data.ChestSortPlayerSetting;
import de.jeff_media.chestsort.gui.ChestSortSettingsGUI;
import de.jeff_media.chestsort.handlers.ChestSortDebugger;
import de.jeff_media.chestsort.handlers.ChestSortLogger;
import de.jeff_media.chestsort.handlers.ChestSortOrganizer;
import de.jeff_media.chestsort.handlers.ChestSortPermissionsHandler;
import de.jeff_media.chestsort.hooks.EnderContainersHook; import de.jeff_media.chestsort.hooks.EnderContainersHook;
import de.jeff_media.chestsort.hooks.GenericGUIHook; import de.jeff_media.chestsort.hooks.GenericGUIHook;
import de.jeff_media.chestsort.hooks.PlayerVaultsHook; import de.jeff_media.chestsort.hooks.PlayerVaultsHook;
import de.jeff_media.chestsort.listeners.ChestSortListener;
import de.jeff_media.chestsort.placeholders.ChestSortPlaceholders; import de.jeff_media.chestsort.placeholders.ChestSortPlaceholders;
import de.jeff_media.chestsort.utils.Utils; import de.jeff_media.chestsort.utils.Utils;
import de.jeff_media.jefflib.JeffLib; import de.jeff_media.jefflib.JeffLib;
@ -45,7 +59,6 @@ import org.bukkit.Material;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import org.bukkit.inventory.Inventory;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -54,33 +67,33 @@ import java.util.*;
public class ChestSortPlugin extends JavaPlugin { public class ChestSortPlugin extends JavaPlugin {
private static double updateCheckInterval = 4 * 60 * 60; // in seconds. We check on startup and every 4 hours public static double updateCheckInterval = 4 * 60 * 60; // in seconds. We check on startup and every 4 hours
final int currentConfigVersion = 50; public final int currentConfigVersion = 50;
final boolean hotkeyGUI = true; public final boolean hotkeyGUI = true;
public EnderContainersHook enderContainersHook; public EnderContainersHook enderContainersHook;
public GenericGUIHook genericHook; public GenericGUIHook genericHook;
public boolean hookCrackShot = false; public boolean hookCrackShot = false;
public boolean hookInventoryPages = false; public boolean hookInventoryPages = false;
public boolean hookMinepacks = false; public boolean hookMinepacks = false;
public PlayerVaultsHook playerVaultsHook; public PlayerVaultsHook playerVaultsHook;
protected boolean debug = false; public boolean debug = false;
ArrayList<String> disabledWorlds; public ArrayList<String> disabledWorlds;
HashMap<UUID, Long> hotkeyCooldown; public HashMap<UUID, Long> hotkeyCooldown;
ChestSortLogger lgr; public ChestSortLogger lgr;
ChestSortListener listener; public ChestSortListener listener;
// 1.14.4 = 1_14_R1 // 1.14.4 = 1_14_R1
// 1.8.0 = 1_8_R1 // 1.8.0 = 1_8_R1
int mcMinorVersion; // 14 for 1.14, 13 for 1.13, ... public int mcMinorVersion; // 14 for 1.14, 13 for 1.13, ...
String mcVersion; // 1.13.2 = 1_13_R2 public String mcVersion; // 1.13.2 = 1_13_R2
ChestSortMessages messages; public Messages messages;
public ChestSortOrganizer organizer; public ChestSortOrganizer organizer;
Map<String, ChestSortPlayerSetting> perPlayerSettings = new HashMap<>(); public Map<String, ChestSortPlayerSetting> perPlayerSettings = new HashMap<>();
ChestSortPermissionsHandler permissionsHandler; public ChestSortPermissionsHandler permissionsHandler;
ChestSortSettingsGUI settingsGUI; public ChestSortSettingsGUI settingsGUI;
String sortingMethod; public String sortingMethod;
UpdateChecker updateChecker; public UpdateChecker updateChecker;
boolean usingMatchingConfig = true; public boolean usingMatchingConfig = true;
boolean verbose = true; public boolean verbose = true;
private static ChestSortPlugin instance; private static ChestSortPlugin instance;
public static ChestSortPlugin getInstance() { public static ChestSortPlugin getInstance() {
@ -209,11 +222,11 @@ public class ChestSortPlugin extends JavaPlugin {
if (perPlayerSettings == null) { if (perPlayerSettings == null) {
perPlayerSettings = new HashMap<>(); perPlayerSettings = new HashMap<>();
} }
listener.plugin.registerPlayerIfNeeded(p); registerPlayerIfNeeded(p);
return perPlayerSettings.get(p.getUniqueId().toString()).sortingEnabled; return perPlayerSettings.get(p.getUniqueId().toString()).sortingEnabled;
} }
void load(boolean reload) { public void load(boolean reload) {
if (reload) { if (reload) {
unregisterAllPlayers(); unregisterAllPlayers();
@ -248,7 +261,7 @@ public class ChestSortPlugin extends JavaPlugin {
verbose = getConfig().getBoolean("verbose"); verbose = getConfig().getBoolean("verbose");
lgr = new ChestSortLogger(this, getConfig().getBoolean("log")); lgr = new ChestSortLogger(this, getConfig().getBoolean("log"));
messages = new ChestSortMessages(this); messages = new Messages(this);
organizer = new ChestSortOrganizer(this); organizer = new ChestSortOrganizer(this);
settingsGUI = new ChestSortSettingsGUI(this); settingsGUI = new ChestSortSettingsGUI(this);
try { try {
@ -423,7 +436,7 @@ public class ChestSortPlugin extends JavaPlugin {
} }
void registerPlayerIfNeeded(Player p) { public void registerPlayerIfNeeded(Player p) {
// Players are stored by their UUID, so that name changes don't break player's // Players are stored by their UUID, so that name changes don't break player's
// settings // settings
UUID uniqueId = p.getUniqueId(); UUID uniqueId = p.getUniqueId();
@ -652,7 +665,7 @@ public class ChestSortPlugin extends JavaPlugin {
} }
// Unregister a player and save their settings in the playerdata folder // Unregister a player and save their settings in the playerdata folder
void unregisterPlayer(Player p) { public void unregisterPlayer(Player p) {
// File will be named by the player's uuid. This will prevent problems on player // File will be named by the player's uuid. This will prevent problems on player
// name changes. // name changes.
UUID uniqueId = p.getUniqueId(); UUID uniqueId = p.getUniqueId();

View File

@ -1,5 +1,6 @@
package de.jeff_media.chestsort; package de.jeff_media.chestsort.commands;
import de.jeff_media.chestsort.ChestSortPlugin;
import de.jeff_media.jefflib.NBTAPI; import de.jeff_media.jefflib.NBTAPI;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;

View File

@ -1,5 +1,9 @@
package de.jeff_media.chestsort; package de.jeff_media.chestsort.commands;
import de.jeff_media.chestsort.config.Messages;
import de.jeff_media.chestsort.handlers.ChestSortDebugger;
import de.jeff_media.chestsort.data.ChestSortPlayerSetting;
import de.jeff_media.chestsort.ChestSortPlugin;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -10,9 +14,9 @@ import org.jetbrains.annotations.NotNull;
public class ChestSortChestSortCommand implements CommandExecutor { public class ChestSortChestSortCommand implements CommandExecutor {
final ChestSortPlugin plugin; private final ChestSortPlugin plugin;
ChestSortChestSortCommand(ChestSortPlugin plugin) { public ChestSortChestSortCommand(ChestSortPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
@ -63,7 +67,7 @@ public class ChestSortChestSortCommand implements CommandExecutor {
} }
} }
sender.sendMessage(plugin.messages.MSG_PLAYERSONLY); sender.sendMessage(Messages.MSG_PLAYERSONLY);
return true; return true;
} }
@ -79,7 +83,7 @@ public class ChestSortChestSortCommand implements CommandExecutor {
if(args[0].equalsIgnoreCase("hotkey") || args[0].equalsIgnoreCase("hotkeys")) { if(args[0].equalsIgnoreCase("hotkey") || args[0].equalsIgnoreCase("hotkeys")) {
if(!plugin.hotkeyGUI) { if(!plugin.hotkeyGUI) {
p.sendMessage(plugin.messages.MSG_ERR_HOTKEYSDISABLED); p.sendMessage(Messages.MSG_ERR_HOTKEYSDISABLED);
return true; return true;
} }
@ -97,7 +101,7 @@ public class ChestSortChestSortCommand implements CommandExecutor {
&& !args[0].equalsIgnoreCase("toggle") && !args[0].equalsIgnoreCase("toggle")
&& !args[0].equalsIgnoreCase("on") && !args[0].equalsIgnoreCase("on")
&& !args[0].equalsIgnoreCase("off")) { && !args[0].equalsIgnoreCase("off")) {
p.sendMessage(String.format(plugin.messages.MSG_INVALIDOPTIONS,"\""+args[0]+"\"","\"toggle\", \"on\", \"off\", \"hotkeys\"")); p.sendMessage(String.format(Messages.MSG_INVALIDOPTIONS,"\""+args[0]+"\"","\"toggle\", \"on\", \"off\", \"hotkeys\""));
return true; return true;
} }
if(args.length==0 || args[0].equalsIgnoreCase("toggle")) { if(args.length==0 || args[0].equalsIgnoreCase("toggle")) {
@ -112,9 +116,9 @@ public class ChestSortChestSortCommand implements CommandExecutor {
setting.hasSeenMessage=true; setting.hasSeenMessage=true;
if (setting.sortingEnabled) { if (setting.sortingEnabled) {
p.sendMessage(plugin.messages.MSG_ACTIVATED); p.sendMessage(Messages.MSG_ACTIVATED);
} else { } else {
p.sendMessage(plugin.messages.MSG_DEACTIVATED); p.sendMessage(Messages.MSG_DEACTIVATED);
} }
return true; return true;

View File

@ -1,5 +1,9 @@
package de.jeff_media.chestsort; package de.jeff_media.chestsort.commands;
import de.jeff_media.chestsort.config.Messages;
import de.jeff_media.chestsort.handlers.ChestSortLogger;
import de.jeff_media.chestsort.data.ChestSortPlayerSetting;
import de.jeff_media.chestsort.ChestSortPlugin;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
@ -11,7 +15,7 @@ public class ChestSortInvSortCommand implements CommandExecutor {
final ChestSortPlugin plugin; final ChestSortPlugin plugin;
ChestSortInvSortCommand(ChestSortPlugin plugin) { public ChestSortInvSortCommand(ChestSortPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
@ -27,7 +31,7 @@ public class ChestSortInvSortCommand implements CommandExecutor {
if (!(sender instanceof Player)) { if (!(sender instanceof Player)) {
if(args.length==0) { if(args.length==0) {
sender.sendMessage(plugin.messages.MSG_PLAYERSONLY); sender.sendMessage(Messages.MSG_PLAYERSONLY);
return true; return true;
} }
// Console can sort player's inventories // Console can sort player's inventories
@ -44,7 +48,7 @@ public class ChestSortInvSortCommand implements CommandExecutor {
args = new String[0]; args = new String[0];
} }
//sender.sendMessage(plugin.messages.MSG_PLAYERSONLY); //sender.sendMessage(Messages.MSG_PLAYERSONLY);
//return true; //return true;
} }
@ -73,29 +77,29 @@ public class ChestSortInvSortCommand implements CommandExecutor {
end=35; end=35;
} else if(args[0].equalsIgnoreCase("on")) { } else if(args[0].equalsIgnoreCase("on")) {
setting.enableInvSorting(); setting.enableInvSorting();
p.sendMessage(plugin.messages.MSG_INVACTIVATED); p.sendMessage(Messages.MSG_INVACTIVATED);
return true; return true;
} else if(args[0].equalsIgnoreCase("off")) { } else if(args[0].equalsIgnoreCase("off")) {
setting.disableInvSorting(); setting.disableInvSorting();
p.sendMessage(plugin.messages.MSG_INVDEACTIVATED); p.sendMessage(Messages.MSG_INVDEACTIVATED);
return true; return true;
} else if(args[0].equalsIgnoreCase("toggle")) { } else if(args[0].equalsIgnoreCase("toggle")) {
setting.toggleInvSorting(); setting.toggleInvSorting();
if(setting.invSortingEnabled) { if(setting.invSortingEnabled) {
p.sendMessage(plugin.messages.MSG_INVACTIVATED); p.sendMessage(Messages.MSG_INVACTIVATED);
} else { } else {
p.sendMessage(plugin.messages.MSG_INVDEACTIVATED); p.sendMessage(Messages.MSG_INVDEACTIVATED);
} }
return true; return true;
} }
else { else {
p.sendMessage(String.format(plugin.messages.MSG_INVALIDOPTIONS,"\""+args[0]+"\"","\"on\", \"off\", \"toggle\", \"inv\", \"hotbar\", \"all\"")); p.sendMessage(String.format(Messages.MSG_INVALIDOPTIONS,"\""+args[0]+"\"","\"on\", \"off\", \"toggle\", \"inv\", \"hotbar\", \"all\""));
return true; return true;
} }
} }
plugin.lgr.logSort(p, ChestSortLogger.SortCause.CMD_ISORT); plugin.lgr.logSort(p, ChestSortLogger.SortCause.CMD_ISORT);
plugin.organizer.sortInventory(p.getInventory(), start, end); plugin.organizer.sortInventory(p.getInventory(), start, end);
p.sendMessage(plugin.messages.MSG_PLAYERINVSORTED); p.sendMessage(Messages.MSG_PLAYERINVSORTED);
return true; return true;

View File

@ -1,4 +1,4 @@
package de.jeff_media.chestsort; package de.jeff_media.chestsort.commands;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

View File

@ -1,4 +1,4 @@
package de.jeff_media.chestsort; package de.jeff_media.chestsort.config;
import java.io.*; import java.io.*;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -7,6 +7,7 @@ import java.util.ArrayList;
import java.util.Map; import java.util.Map;
import java.util.Scanner; import java.util.Scanner;
import de.jeff_media.chestsort.ChestSortPlugin;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
@ -25,7 +26,7 @@ public class ChestSortConfigUpdater {
// config version // config version
// Don't worry! Your changes will be kept // Don't worry! Your changes will be kept
void updateConfig() { public void updateConfig() {
// hotkeys has been renamed to sorting-hotkeys // hotkeys has been renamed to sorting-hotkeys
if(plugin.getConfig().isSet("hotkeys.middle-click")) { if(plugin.getConfig().isSet("hotkeys.middle-click")) {

View File

@ -1,9 +1,10 @@
package de.jeff_media.chestsort; package de.jeff_media.chestsort.config;
import de.jeff_media.chestsort.ChestSortPlugin;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
public class ChestSortMessages { public class Messages {
final String MSG_GUI_LEFTCLICKOUTSIDE, MSG_CONTAINER_SORTED; public static String MSG_GUI_LEFTCLICKOUTSIDE, MSG_CONTAINER_SORTED;
// Messages can be customized in the config.yml // Messages can be customized in the config.yml
// To avoid problems with missing messages in the config, the default messages // To avoid problems with missing messages in the config, the default messages
@ -12,18 +13,18 @@ public class ChestSortMessages {
// When creating pull requests that feature a message to the player, please // When creating pull requests that feature a message to the player, please
// stick to this scheme // stick to this scheme
final ChestSortPlugin plugin; public static ChestSortPlugin plugin;
final String MSG_ACTIVATED, MSG_DEACTIVATED, MSG_INVACTIVATED, MSG_INVDEACTIVATED, MSG_COMMANDMESSAGE, MSG_COMMANDMESSAGE2, MSG_PLAYERSONLY, public static String MSG_ACTIVATED, MSG_DEACTIVATED, MSG_INVACTIVATED, MSG_INVDEACTIVATED, MSG_COMMANDMESSAGE, MSG_COMMANDMESSAGE2, MSG_PLAYERSONLY,
MSG_PLAYERINVSORTED, MSG_INVALIDOPTIONS; MSG_PLAYERINVSORTED, MSG_INVALIDOPTIONS;
final String MSG_GUI_ENABLED, MSG_GUI_DISABLED; public static String MSG_GUI_ENABLED, MSG_GUI_DISABLED;
final String MSG_GUI_MIDDLECLICK, MSG_GUI_SHIFTCLICK, MSG_GUI_DOUBLECLICK, MSG_GUI_SHIFTRIGHTCLICK, MSG_GUI_LEFTCLICK, MSG_GUI_RIGHTCLICK; public static String MSG_GUI_MIDDLECLICK, MSG_GUI_SHIFTCLICK, MSG_GUI_DOUBLECLICK, MSG_GUI_SHIFTRIGHTCLICK, MSG_GUI_LEFTCLICK, MSG_GUI_RIGHTCLICK;
final String MSG_ERR_HOTKEYSDISABLED; public static String MSG_ERR_HOTKEYSDISABLED;
ChestSortMessages(ChestSortPlugin plugin) { public Messages(ChestSortPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
MSG_CONTAINER_SORTED = ChatColor.translateAlternateColorCodes('&', plugin.getConfig() MSG_CONTAINER_SORTED = ChatColor.translateAlternateColorCodes('&', plugin.getConfig()

View File

@ -1,6 +1,8 @@
package de.jeff_media.chestsort.utils; package de.jeff_media.chestsort.data;
import de.jeff_media.chestsort.utils.Utils;
public class CategoryLinePair { public class CategoryLinePair {
final String categoryName; final String categoryName;
final String formattedPosition; final String formattedPosition;
@ -13,7 +15,7 @@ public class CategoryLinePair {
public CategoryLinePair(String categoryName,short position,boolean sticky) { public CategoryLinePair(String categoryName,short position,boolean sticky) {
this.categoryName=categoryName; this.categoryName=categoryName;
this.formattedPosition=Utils.shortToStringWithLeadingZeroes(position); this.formattedPosition= Utils.shortToStringWithLeadingZeroes(position);
this.position=position; this.position=position;
this.sticky=sticky; this.sticky=sticky;
} }

View File

@ -1,4 +1,4 @@
package de.jeff_media.chestsort; package de.jeff_media.chestsort.data;
import de.jeff_media.chestsort.utils.TypeMatchPositionPair; import de.jeff_media.chestsort.utils.TypeMatchPositionPair;
@ -12,16 +12,16 @@ public class ChestSortCategory implements Comparable<ChestSortCategory>{
// "COARSE_DIRT" will not match the typeMatch "dirt" // "COARSE_DIRT" will not match the typeMatch "dirt"
// "COARSE_DIRT" will match the typeMatch "*dirt" // "COARSE_DIRT" will match the typeMatch "*dirt"
final String name; public final String name;
boolean sticky = false; boolean sticky = false;
final TypeMatchPositionPair[] typeMatches; public final TypeMatchPositionPair[] typeMatches;
ChestSortCategory(String name, TypeMatchPositionPair[] typeMatchPositionPairs) { public ChestSortCategory(String name, TypeMatchPositionPair[] typeMatchPositionPairs) {
this.name = name; this.name = name;
this.typeMatches = typeMatchPositionPairs; this.typeMatches = typeMatchPositionPairs;
} }
void setSticky() { public void setSticky() {
this.sticky=true; this.sticky=true;
} }
@ -31,7 +31,7 @@ public class ChestSortCategory implements Comparable<ChestSortCategory>{
// Checks whether a the given itemname fits into this category and returns the line number. 0 means not found // Checks whether a the given itemname fits into this category and returns the line number. 0 means not found
short matches(String itemname) { public short matches(String itemname) {
// Very, very simple wildcard checks // Very, very simple wildcard checks
for (TypeMatchPositionPair typeMatchPositionPair : typeMatches) { for (TypeMatchPositionPair typeMatchPositionPair : typeMatches) {

View File

@ -1,5 +1,6 @@
package de.jeff_media.chestsort; package de.jeff_media.chestsort.data;
import de.jeff_media.chestsort.ChestSortPlugin;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
@ -17,23 +18,29 @@ public class ChestSortPlayerSetting {
public boolean invSortingEnabled; public boolean invSortingEnabled;
// Hotkey settings // Hotkey settings
boolean middleClick, shiftClick, doubleClick, shiftRightClick, leftClick, rightClick, leftClickOutside; public boolean middleClick;
public boolean shiftClick;
public boolean doubleClick;
public boolean shiftRightClick;
public boolean leftClick;
public boolean rightClick;
public boolean leftClickOutside;
Inventory guiInventory = null; public Inventory guiInventory = null;
// Did we already show the message how to activate sorting? // Did we already show the message how to activate sorting?
boolean hasSeenMessage = false; public boolean hasSeenMessage = false;
// Do we have to save these settings? // Do we have to save these settings?
boolean changed; public boolean changed;
DoubleClickType currentDoubleClick = DoubleClickType.NONE; DoubleClickType currentDoubleClick = DoubleClickType.NONE;
enum DoubleClickType { public enum DoubleClickType {
NONE, RIGHT_CLICK, LEFT_CLICK NONE, RIGHT_CLICK, LEFT_CLICK
} }
ChestSortPlayerSetting(boolean sortingEnabled, boolean invSortingEnabled, boolean middleClick, boolean shiftClick, boolean doubleClick, boolean shiftRightClick, boolean leftClick, boolean rightClick, boolean leftCLickOutside, boolean changed) { public ChestSortPlayerSetting(boolean sortingEnabled, boolean invSortingEnabled, boolean middleClick, boolean shiftClick, boolean doubleClick, boolean shiftRightClick, boolean leftClick, boolean rightClick, boolean leftCLickOutside, boolean changed) {
this.sortingEnabled = sortingEnabled; this.sortingEnabled = sortingEnabled;
this.middleClick = middleClick; this.middleClick = middleClick;
this.shiftClick = shiftClick; this.shiftClick = shiftClick;
@ -46,7 +53,7 @@ public class ChestSortPlayerSetting {
this.changed = changed; this.changed = changed;
} }
DoubleClickType getCurrentDoubleClick(ChestSortPlugin plugin, DoubleClickType click) { public DoubleClickType getCurrentDoubleClick(ChestSortPlugin plugin, DoubleClickType click) {
if(click == DoubleClickType.NONE) return DoubleClickType.NONE; if(click == DoubleClickType.NONE) return DoubleClickType.NONE;
if(currentDoubleClick == click) { if(currentDoubleClick == click) {
currentDoubleClick = DoubleClickType.NONE; currentDoubleClick = DoubleClickType.NONE;
@ -60,55 +67,55 @@ public class ChestSortPlayerSetting {
return DoubleClickType.NONE; return DoubleClickType.NONE;
} }
void toggleMiddleClick() { public void toggleMiddleClick() {
middleClick = !middleClick; middleClick = !middleClick;
changed = true; changed = true;
} }
void toggleShiftClick() { public void toggleShiftClick() {
shiftClick = !shiftClick; shiftClick = !shiftClick;
changed = true; changed = true;
} }
void toggleDoubleClick() { public void toggleDoubleClick() {
doubleClick = !doubleClick; doubleClick = !doubleClick;
changed = true; changed = true;
} }
void toggleShiftRightClick() { public void toggleShiftRightClick() {
shiftRightClick = !shiftRightClick; shiftRightClick = !shiftRightClick;
changed = true; changed = true;
} }
void toggleLeftClickOutside() { public void toggleLeftClickOutside() {
leftClickOutside = !leftClickOutside; leftClickOutside = !leftClickOutside;
changed = true; changed = true;
} }
void toggleLeftClick() { public void toggleLeftClick() {
leftClick = !leftClick; leftClick = !leftClick;
changed = true; changed = true;
} }
void toggleRightClick() { public void toggleRightClick() {
rightClick = !rightClick; rightClick = !rightClick;
changed = true; changed = true;
} }
void enableChestSorting() { public void enableChestSorting() {
sortingEnabled = true; sortingEnabled = true;
changed = true; changed = true;
} }
void disableChestSorting() { public void disableChestSorting() {
sortingEnabled = false; sortingEnabled = false;
changed = true; changed = true;
} }
void toggleChestSorting() { public void toggleChestSorting() {
sortingEnabled = !sortingEnabled; sortingEnabled = !sortingEnabled;
changed = true; changed = true;
} }
void enableInvSorting() { public void enableInvSorting() {
invSortingEnabled = true; invSortingEnabled = true;
changed = true; changed = true;
} }
void disableInvSorting() { public void disableInvSorting() {
invSortingEnabled = false; invSortingEnabled = false;
changed = true; changed = true;
} }
void toggleInvSorting() { public void toggleInvSorting() {
invSortingEnabled = !invSortingEnabled; invSortingEnabled = !invSortingEnabled;
changed = true; changed = true;
} }

View File

@ -1,5 +1,8 @@
package de.jeff_media.chestsort; package de.jeff_media.chestsort.gui;
import de.jeff_media.chestsort.ChestSortPlugin;
import de.jeff_media.chestsort.config.Messages;
import de.jeff_media.chestsort.data.ChestSortPlayerSetting;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
@ -32,7 +35,7 @@ public class ChestSortSettingsGUI implements Listener {
MiddleClick, ShiftClick, DoubleClick, ShiftRightClick, LeftClick, RightClick, LeftClickOutside MiddleClick, ShiftClick, DoubleClick, ShiftRightClick, LeftClick, RightClick, LeftClickOutside
} }
ChestSortSettingsGUI(ChestSortPlugin plugin) { public ChestSortSettingsGUI(ChestSortPlugin plugin) {
this.plugin=plugin; this.plugin=plugin;
} }
@ -42,36 +45,36 @@ public class ChestSortSettingsGUI implements Listener {
if(active) { if(active) {
is = new ItemStack(green); is = new ItemStack(green);
suffix = plugin.messages.MSG_GUI_ENABLED; suffix = Messages.MSG_GUI_ENABLED;
} }
else { else {
is = new ItemStack(red); is = new ItemStack(red);
suffix = plugin.messages.MSG_GUI_DISABLED; suffix = Messages.MSG_GUI_DISABLED;
} }
ItemMeta meta = is.getItemMeta(); ItemMeta meta = is.getItemMeta();
switch(hotkey) { switch(hotkey) {
case MiddleClick: case MiddleClick:
meta.setDisplayName(ChatColor.RESET + plugin.messages.MSG_GUI_MIDDLECLICK + ": " + suffix); meta.setDisplayName(ChatColor.RESET + Messages.MSG_GUI_MIDDLECLICK + ": " + suffix);
break; break;
case ShiftClick: case ShiftClick:
meta.setDisplayName(ChatColor.RESET + plugin.messages.MSG_GUI_SHIFTCLICK + ": " + suffix); meta.setDisplayName(ChatColor.RESET + Messages.MSG_GUI_SHIFTCLICK + ": " + suffix);
break; break;
case DoubleClick: case DoubleClick:
meta.setDisplayName(ChatColor.RESET + plugin.messages.MSG_GUI_DOUBLECLICK + ": " + suffix); meta.setDisplayName(ChatColor.RESET + Messages.MSG_GUI_DOUBLECLICK + ": " + suffix);
break; break;
case ShiftRightClick: case ShiftRightClick:
meta.setDisplayName(ChatColor.RESET + plugin.messages.MSG_GUI_SHIFTRIGHTCLICK + ": " + suffix); meta.setDisplayName(ChatColor.RESET + Messages.MSG_GUI_SHIFTRIGHTCLICK + ": " + suffix);
break; break;
case LeftClickOutside: case LeftClickOutside:
meta.setDisplayName(ChatColor.RESET + plugin.messages.MSG_GUI_LEFTCLICKOUTSIDE + ": " + suffix); meta.setDisplayName(ChatColor.RESET + Messages.MSG_GUI_LEFTCLICKOUTSIDE + ": " + suffix);
break; break;
case LeftClick: case LeftClick:
meta.setDisplayName(ChatColor.RESET + plugin.messages.MSG_GUI_LEFTCLICK + ": "+ suffix); meta.setDisplayName(ChatColor.RESET + Messages.MSG_GUI_LEFTCLICK + ": "+ suffix);
break; break;
case RightClick: case RightClick:
meta.setDisplayName(ChatColor.RESET + plugin.messages.MSG_GUI_RIGHTCLICK + ": "+ suffix); meta.setDisplayName(ChatColor.RESET + Messages.MSG_GUI_RIGHTCLICK + ": "+ suffix);
break; break;
default: default:
break; break;
@ -82,7 +85,7 @@ public class ChestSortSettingsGUI implements Listener {
return is; return is;
} }
void openGUI(Player player) { public void openGUI(Player player) {
Inventory inventory = createGUI("ChestSort", player); Inventory inventory = createGUI("ChestSort", player);
ChestSortPlayerSetting setting = plugin.perPlayerSettings.get(player.getUniqueId().toString()); ChestSortPlayerSetting setting = plugin.perPlayerSettings.get(player.getUniqueId().toString());
@ -118,7 +121,7 @@ public class ChestSortSettingsGUI implements Listener {
return; return;
} }
Player p = (Player) event.getWhoClicked(); Player p = (Player) event.getWhoClicked();
plugin.listener.plugin.registerPlayerIfNeeded(p); plugin.registerPlayerIfNeeded(p);
ChestSortPlayerSetting setting = plugin.perPlayerSettings.get(p.getUniqueId().toString()); ChestSortPlayerSetting setting = plugin.perPlayerSettings.get(p.getUniqueId().toString());
if(setting.guiInventory==null) { if(setting.guiInventory==null) {

View File

@ -1,5 +1,6 @@
package de.jeff_media.chestsort; package de.jeff_media.chestsort.handlers;
import de.jeff_media.chestsort.ChestSortPlugin;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -10,7 +11,7 @@ public class ChestSortDebugger implements @NotNull Listener {
private final ChestSortPlugin plugin; private final ChestSortPlugin plugin;
ChestSortDebugger(ChestSortPlugin plugin) { public ChestSortDebugger(ChestSortPlugin plugin) {
plugin.getLogger().warning("======================================="); plugin.getLogger().warning("=======================================");
plugin.getLogger().warning(" CHESTSORT DEBUG MODE ACTIVATED!"); plugin.getLogger().warning(" CHESTSORT DEBUG MODE ACTIVATED!");
plugin.getLogger().warning("Only use this for development purposes!"); plugin.getLogger().warning("Only use this for development purposes!");

View File

@ -1,5 +1,7 @@
package de.jeff_media.chestsort; package de.jeff_media.chestsort.handlers;
import de.jeff_media.chestsort.ChestSortPlugin;
import de.jeff_media.chestsort.data.ChestSortPlayerSetting;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -15,7 +17,7 @@ public class ChestSortLogger {
boolean log; boolean log;
Logger logger; Logger logger;
ChestSortLogger(ChestSortPlugin plugin, boolean log) { public ChestSortLogger(ChestSortPlugin plugin, boolean log) {
if(!log) return; if(!log) return;
plugin.getLogger().info("======================================="); plugin.getLogger().info("=======================================");
plugin.getLogger().info(" CHESTSORT LOGGER ACTIVATED!"); plugin.getLogger().info(" CHESTSORT LOGGER ACTIVATED!");
@ -50,18 +52,18 @@ public class ChestSortLogger {
logger.info(s); logger.info(s);
} }
void logSort(Player p, @Nullable SortCause cause) { public void logSort(Player p, @Nullable SortCause cause) {
if(!log) return; if(!log) return;
String settings = getPlayerSettings(p); String settings = getPlayerSettings(p);
if(cause==null) cause = SortCause.UNKNOWN; if(cause==null) cause = SortCause.UNKNOWN;
log(String.format("SORT: Player: %s, Cause: %s, Settings: {%s}",p.getName(),cause.name(),settings)); log(String.format("SORT: Player: %s, Cause: %s, Settings: {%s}",p.getName(),cause.name(),settings));
} }
enum SortCause { public enum SortCause {
UNKNOWN, INV_CLOSE, CONT_CLOSE, CONT_OPEN, EC_OPEN, H_MIDDLE, H_SHIFT, H_DOUBLE, H_SHIFTRIGHT, H_LEFT, H_RIGHT, CMD_ISORT UNKNOWN, INV_CLOSE, CONT_CLOSE, CONT_OPEN, EC_OPEN, H_MIDDLE, H_SHIFT, H_DOUBLE, H_SHIFTRIGHT, H_LEFT, H_RIGHT, CMD_ISORT
} }
void logPlayerJoin(Player p) { public void logPlayerJoin(Player p) {
if(!log) return; if(!log) return;
String settings = getPlayerSettings(p); String settings = getPlayerSettings(p);
log(String.format("JOIN: Player: %s, Settings: {%s}",p.getName(),settings)); log(String.format("JOIN: Player: %s, Settings: {%s}",p.getName(),settings));

View File

@ -1,12 +1,14 @@
package de.jeff_media.chestsort; package de.jeff_media.chestsort.handlers;
import de.jeff_media.chestsort.ChestSortEvent;
import de.jeff_media.chestsort.ChestSortPlugin;
import de.jeff_media.chestsort.data.ChestSortCategory;
import de.jeff_media.chestsort.hooks.CrackShotHook; import de.jeff_media.chestsort.hooks.CrackShotHook;
import de.jeff_media.chestsort.hooks.InventoryPagesHook; import de.jeff_media.chestsort.hooks.InventoryPagesHook;
import de.jeff_media.chestsort.hooks.SlimeFunHook; import de.jeff_media.chestsort.hooks.SlimeFunHook;
import de.jeff_media.chestsort.utils.CategoryLinePair; import de.jeff_media.chestsort.data.CategoryLinePair;
import de.jeff_media.chestsort.utils.TypeMatchPositionPair; import de.jeff_media.chestsort.utils.TypeMatchPositionPair;
import de.jeff_media.chestsort.utils.Utils; import de.jeff_media.chestsort.utils.Utils;
import de.jeff_media.chestsort.ChestSortEvent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
@ -55,10 +57,10 @@ public class ChestSortOrganizer {
final CrackShotHook crackShotHook; final CrackShotHook crackShotHook;
final InventoryPagesHook inventoryPagesHook; final InventoryPagesHook inventoryPagesHook;
// We store a list of all Category objects // We store a list of all Category objects
final ArrayList<ChestSortCategory> categories = new ArrayList<>(); public final ArrayList<ChestSortCategory> categories = new ArrayList<>();
final ArrayList<String> stickyCategoryNames = new ArrayList<>(); final ArrayList<String> stickyCategoryNames = new ArrayList<>();
ChestSortOrganizer(ChestSortPlugin plugin) { public ChestSortOrganizer(ChestSortPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
// Load Categories // Load Categories
@ -333,7 +335,7 @@ public class ChestSortOrganizer {
// This method takes a sortable item name and checks all categories for a match // This method takes a sortable item name and checks all categories for a match
// If none, matches, return "<none>" (it will be put behind all categorized // If none, matches, return "<none>" (it will be put behind all categorized
// items when sorting by category) // items when sorting by category)
CategoryLinePair getCategoryLinePair(String typeName) { public CategoryLinePair getCategoryLinePair(String typeName) {
typeName = typeName.toLowerCase(); typeName = typeName.toLowerCase();
for (ChestSortCategory cat : categories) { for (ChestSortCategory cat : categories) {
short matchingLineNumber = cat.matches(typeName); short matchingLineNumber = cat.matches(typeName);
@ -345,7 +347,7 @@ public class ChestSortOrganizer {
} }
// Generate a map of "{placeholder}", "sortString" pairs for an ItemStack // Generate a map of "{placeholder}", "sortString" pairs for an ItemStack
Map<String, String> getSortableMap(ItemStack item) { public Map<String, String> getSortableMap(ItemStack item) {
if (item == null) { if (item == null) {
// Empty map for non-item // Empty map for non-item
return new HashMap<String, String>(); return new HashMap<String, String>();

View File

@ -1,8 +1,9 @@
package de.jeff_media.chestsort; package de.jeff_media.chestsort.handlers;
import java.util.HashMap; import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
import de.jeff_media.chestsort.ChestSortPlugin;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionAttachment; import org.bukkit.permissions.PermissionAttachment;
@ -11,12 +12,12 @@ public class ChestSortPermissionsHandler {
final HashMap<UUID,PermissionAttachment> permissions; final HashMap<UUID,PermissionAttachment> permissions;
final ChestSortPlugin plugin; final ChestSortPlugin plugin;
ChestSortPermissionsHandler(ChestSortPlugin plugin) { public ChestSortPermissionsHandler(ChestSortPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
this.permissions = new HashMap<>(); this.permissions = new HashMap<>();
} }
void addPermissions(Player p) { public void addPermissions(Player p) {
if(plugin.getConfig().getBoolean("use-permissions")) return; if(plugin.getConfig().getBoolean("use-permissions")) return;
if(permissions.containsKey(p.getUniqueId())) return; if(permissions.containsKey(p.getUniqueId())) return;
PermissionAttachment attachment = p.addAttachment(plugin); PermissionAttachment attachment = p.addAttachment(plugin);
@ -25,7 +26,7 @@ public class ChestSortPermissionsHandler {
permissions.put(p.getUniqueId(), attachment); permissions.put(p.getUniqueId(), attachment);
} }
void removePermissions(Player p) { public void removePermissions(Player p) {
if(plugin.getConfig().getBoolean("use-permissions")) return; if(plugin.getConfig().getBoolean("use-permissions")) return;
if(!permissions.containsKey(p.getUniqueId())) return; if(!permissions.containsKey(p.getUniqueId())) return;
PermissionAttachment attachment = permissions.get(p.getUniqueId()); PermissionAttachment attachment = permissions.get(p.getUniqueId());

View File

@ -1,5 +1,11 @@
package de.jeff_media.chestsort; package de.jeff_media.chestsort.listeners;
import de.jeff_media.chestsort.ChestSortEvent;
import de.jeff_media.chestsort.config.Messages;
import de.jeff_media.chestsort.handlers.ChestSortLogger;
import de.jeff_media.chestsort.ChestSortPlugin;
import de.jeff_media.chestsort.ISortable;
import de.jeff_media.chestsort.data.ChestSortPlayerSetting;
import de.jeff_media.chestsort.hooks.*; import de.jeff_media.chestsort.hooks.*;
import de.jeff_media.chestsort.utils.LlamaUtils; import de.jeff_media.chestsort.utils.LlamaUtils;
import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.ChatMessageType;
@ -33,12 +39,12 @@ import java.util.Map;
public class ChestSortListener implements Listener { public class ChestSortListener implements Listener {
final ChestSortPlugin plugin; final ChestSortPlugin plugin;
final MinepacksHook minepacksHook; public final MinepacksHook minepacksHook;
final HeadDatabaseHook headDatabaseHook; final HeadDatabaseHook headDatabaseHook;
final CrateReloadedHook crateReloadedHook; final CrateReloadedHook crateReloadedHook;
final GoldenCratesHook goldenCratesHook; final GoldenCratesHook goldenCratesHook;
ChestSortListener(ChestSortPlugin plugin) { public ChestSortListener(ChestSortPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
this.minepacksHook = new MinepacksHook(plugin); this.minepacksHook = new MinepacksHook(plugin);
this.headDatabaseHook = new HeadDatabaseHook(plugin); this.headDatabaseHook = new HeadDatabaseHook(plugin);
@ -60,7 +66,7 @@ public class ChestSortListener implements Listener {
Container containerState = (Container) clickedBlock.getState(); Container containerState = (Container) clickedBlock.getState();
Inventory inventory = containerState.getInventory(); Inventory inventory = containerState.getInventory();
plugin.organizer.sortInventory(inventory); plugin.organizer.sortInventory(inventory);
event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(plugin.messages.MSG_CONTAINER_SORTED)); event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(Messages.MSG_CONTAINER_SORTED));
} }
@EventHandler @EventHandler
@ -323,7 +329,7 @@ public class ChestSortListener implements Listener {
if (!setting.hasSeenMessage) { if (!setting.hasSeenMessage) {
setting.hasSeenMessage = true; setting.hasSeenMessage = true;
if (plugin.getConfig().getBoolean("show-message-when-using-chest")) { if (plugin.getConfig().getBoolean("show-message-when-using-chest")) {
p.sendMessage(plugin.messages.MSG_COMMANDMESSAGE); p.sendMessage(Messages.MSG_COMMANDMESSAGE);
} }
} }
return false; return false;
@ -340,7 +346,7 @@ public class ChestSortListener implements Listener {
if (!setting.hasSeenMessage) { if (!setting.hasSeenMessage) {
setting.hasSeenMessage = true; setting.hasSeenMessage = true;
if (plugin.getConfig().getBoolean("show-message-when-using-chest-and-sorting-is-enabled")) { if (plugin.getConfig().getBoolean("show-message-when-using-chest-and-sorting-is-enabled")) {
p.sendMessage(plugin.messages.MSG_COMMANDMESSAGE2); p.sendMessage(Messages.MSG_COMMANDMESSAGE2);
} }
} }
} }
@ -634,7 +640,7 @@ public class ChestSortListener implements Listener {
chestSortEvent.setPlayer(e.getWhoClicked()); chestSortEvent.setPlayer(e.getWhoClicked());
chestSortEvent.setLocation(e.getWhoClicked().getLocation()); chestSortEvent.setLocation(e.getWhoClicked().getLocation());
chestSortEvent.setSortableMaps(new HashMap<ItemStack, Map<String, String>>()); chestSortEvent.setSortableMaps(new HashMap<>());
for (ItemStack item : e.getInventory().getContents()) { for (ItemStack item : e.getInventory().getContents()) {
chestSortEvent.getSortableMaps().put(item, plugin.organizer.getSortableMap(item)); chestSortEvent.getSortableMaps().put(item, plugin.organizer.getSortableMap(item));
} }

View File

@ -73,19 +73,6 @@ public class ChestSortPlaceholders extends PlaceholderExpansion {
return main.getDescription().getVersion(); return main.getDescription().getVersion();
} }
/**
* This is the method called when a placeholder with our identifier
* is found and needs a value.
* <br>We specify the value identifier in this method.
* <br>Since version 2.9.1 can you use OfflinePlayers in your requests.
*
* @param player
* A {@link org.bukkit.Player Player}.
* @param identifier
* A String containing the identifier/value.
*
* @return possibly-null String of the requested identifier.
*/
@Override @Override
public String onPlaceholderRequest(Player player, String identifier){ public String onPlaceholderRequest(Player player, String identifier){