mirror of
https://github.com/JEFF-Media-GbR/ChestSort.git
synced 2024-12-02 15:43:22 +01:00
8.13.0-SNAPSHOT
This commit is contained in:
parent
9d821f98be
commit
3870e63a1e
@ -1,6 +1,7 @@
|
||||
# Changelog
|
||||
## 8.13.0-SNAPSHOT
|
||||
- Updated Chinese (Traditional) translation
|
||||
- Added option to log ChestSort actions in a log file (default: false)
|
||||
|
||||
## 8.12.2
|
||||
- Fixes NullPointerException when using EssentialsX' /ec command in Minecraft 1.12
|
||||
|
@ -70,7 +70,7 @@ public class ChestSortInvSortCommand implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
plugin.lgr.logSort(p, ChestSortLogger.SortCause.CMD_ISORT);
|
||||
plugin.organizer.sortInventory(p.getInventory(), start, end);
|
||||
p.sendMessage(plugin.messages.MSG_PLAYERINVSORTED);
|
||||
|
||||
|
@ -40,6 +40,8 @@ public class ChestSortListener implements Listener {
|
||||
// Put player into our perPlayerSettings map
|
||||
plugin.registerPlayerIfNeeded(event.getPlayer());
|
||||
|
||||
plugin.lgr.logPlayerJoin(event.getPlayer());
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -89,6 +91,8 @@ public class ChestSortListener implements Listener {
|
||||
ChestSortPlayerSetting setting = plugin.perPlayerSettings.get(p.getUniqueId().toString());
|
||||
if (!setting.invSortingEnabled) return;
|
||||
|
||||
plugin.lgr.logSort(p, ChestSortLogger.SortCause.INV_CLOSE);
|
||||
|
||||
plugin.organizer.sortInventory(p.getInventory(), 9, 35);
|
||||
|
||||
}
|
||||
@ -122,6 +126,8 @@ public class ChestSortListener implements Listener {
|
||||
|
||||
// Finally call the Organizer to sort the inventory
|
||||
|
||||
plugin.lgr.logSort(p, ChestSortLogger.SortCause.CONT_CLOSE);
|
||||
|
||||
// Llama inventories need special start/end slots
|
||||
if (LlamaUtils.belongsToLlama(event.getInventory())) {
|
||||
ChestedHorse llama = (ChestedHorse) event.getInventory().getHolder();
|
||||
@ -163,6 +169,9 @@ public class ChestSortListener implements Listener {
|
||||
|
||||
// Finally call the Organizer to sort the inventory
|
||||
|
||||
plugin.lgr.logSort(p, ChestSortLogger.SortCause.CONT_OPEN);
|
||||
|
||||
|
||||
// Llama inventories need special start/end slots
|
||||
if (LlamaUtils.belongsToLlama(event.getInventory())) {
|
||||
ChestedHorse llama = (ChestedHorse) event.getInventory().getHolder();
|
||||
@ -284,6 +293,9 @@ public class ChestSortListener implements Listener {
|
||||
if (isReadyToSort(p)) {
|
||||
|
||||
// Finally call the Organizer to sort the inventory
|
||||
|
||||
plugin.lgr.logSort(p, ChestSortLogger.SortCause.EC_OPEN);
|
||||
|
||||
plugin.organizer.sortInventory(event.getInventory());
|
||||
}
|
||||
}
|
||||
@ -327,6 +339,7 @@ public class ChestSortListener implements Listener {
|
||||
InventoryHolder holder = event.getClickedInventory().getHolder();
|
||||
|
||||
boolean sort = false;
|
||||
ChestSortLogger.SortCause cause = null;
|
||||
|
||||
ChestSortPlayerSetting setting = plugin.perPlayerSettings.get(p.getUniqueId().toString());
|
||||
|
||||
@ -341,6 +354,7 @@ public class ChestSortListener implements Listener {
|
||||
}
|
||||
switch (event.getClick()) {
|
||||
case MIDDLE:
|
||||
cause = ChestSortLogger.SortCause.H_MIDDLE;
|
||||
//if(plugin.getConfig().getBoolean("hotkeys.middle-click")) {
|
||||
if (setting.middleClick) {
|
||||
if (event.getWhoClicked().getGameMode() != GameMode.CREATIVE) {
|
||||
@ -353,6 +367,7 @@ public class ChestSortListener implements Listener {
|
||||
}
|
||||
break;
|
||||
case DOUBLE_CLICK:
|
||||
cause = ChestSortLogger.SortCause.H_DOUBLE;
|
||||
//if(plugin.getConfig().getBoolean("hotkeys.double-click")) {
|
||||
if (setting.doubleClick) {
|
||||
// We need getCursor() instead of getCurrentItem(), because after picking up the item, it is gone into the cursor
|
||||
@ -362,6 +377,7 @@ public class ChestSortListener implements Listener {
|
||||
}
|
||||
break;
|
||||
case SHIFT_LEFT:
|
||||
cause = ChestSortLogger.SortCause.H_SHIFT;
|
||||
//if(plugin.getConfig().getBoolean("hotkeys.shift-click")) {
|
||||
if (setting.shiftClick) {
|
||||
if (event.getCurrentItem() == null || (event.getCurrentItem() != null && event.getCurrentItem().getType() == Material.AIR)) {
|
||||
@ -370,6 +386,7 @@ public class ChestSortListener implements Listener {
|
||||
}
|
||||
break;
|
||||
case SHIFT_RIGHT:
|
||||
cause = ChestSortLogger.SortCause.H_SHIFTRIGHT;
|
||||
//if(plugin.getConfig().getBoolean("hotkeys.shift-right-click")) {
|
||||
if (setting.shiftRightClick) {
|
||||
if (event.getCurrentItem() == null || (event.getCurrentItem() != null && event.getCurrentItem().getType() == Material.AIR)) {
|
||||
@ -392,12 +409,13 @@ public class ChestSortListener implements Listener {
|
||||
}
|
||||
|
||||
if (LlamaUtils.belongsToLlama(event.getClickedInventory())) {
|
||||
plugin.lgr.logSort(p,cause);
|
||||
ChestedHorse llama = (ChestedHorse) event.getInventory().getHolder();
|
||||
plugin.organizer.sortInventory(event.getClickedInventory(), 2, LlamaUtils.getLlamaChestSize(llama) + 1);
|
||||
plugin.organizer.updateInventoryView(event);
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.lgr.logSort(p,cause);
|
||||
plugin.organizer.sortInventory(event.getClickedInventory());
|
||||
plugin.organizer.updateInventoryView(event);
|
||||
} else if (holder instanceof Player) {
|
||||
@ -406,9 +424,11 @@ public class ChestSortListener implements Listener {
|
||||
}
|
||||
|
||||
if (event.getSlotType() == SlotType.QUICKBAR) {
|
||||
plugin.lgr.logSort(p,cause);
|
||||
plugin.organizer.sortInventory(p.getInventory(), 0, 8);
|
||||
plugin.organizer.updateInventoryView(event);
|
||||
} else if (event.getSlotType() == SlotType.CONTAINER) {
|
||||
plugin.lgr.logSort(p,cause);
|
||||
plugin.organizer.sortInventory(p.getInventory(), 9, 35);
|
||||
plugin.organizer.updateInventoryView(event);
|
||||
}
|
||||
@ -469,7 +489,7 @@ public class ChestSortListener implements Listener {
|
||||
}
|
||||
|
||||
if (e.isLeftClick() && setting.leftClick) {
|
||||
|
||||
plugin.lgr.logSort(p, ChestSortLogger.SortCause.H_LEFT);
|
||||
if (setting.getCurrentDoubleClick(plugin, ChestSortPlayerSetting.DoubleClickType.LEFT_CLICK)
|
||||
== ChestSortPlayerSetting.DoubleClickType.LEFT_CLICK) {
|
||||
// Left double click: put everything into destination
|
||||
@ -481,6 +501,7 @@ public class ChestSortListener implements Listener {
|
||||
}
|
||||
|
||||
} else if (e.isRightClick() && setting.rightClick) {
|
||||
plugin.lgr.logSort(p, ChestSortLogger.SortCause.H_RIGHT);
|
||||
if (setting.getCurrentDoubleClick(plugin, ChestSortPlayerSetting.DoubleClickType.RIGHT_CLICK)
|
||||
== ChestSortPlayerSetting.DoubleClickType.RIGHT_CLICK) {
|
||||
// Right double click: put everything into player inventory
|
||||
|
69
src/main/java/de/jeff_media/ChestSort/ChestSortLogger.java
Normal file
69
src/main/java/de/jeff_media/ChestSort/ChestSortLogger.java
Normal file
@ -0,0 +1,69 @@
|
||||
package de.jeff_media.ChestSort;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.FileHandler;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.SimpleFormatter;
|
||||
|
||||
public class ChestSortLogger {
|
||||
|
||||
ChestSortPlugin plugin;
|
||||
boolean log;
|
||||
Logger logger;
|
||||
|
||||
ChestSortLogger(ChestSortPlugin plugin, boolean log) {
|
||||
if(!log) return;
|
||||
plugin.getLogger().info("=======================================");
|
||||
plugin.getLogger().info(" CHESTSORT LOGGER ACTIVATED!");
|
||||
plugin.getLogger().info("=======================================");
|
||||
this.plugin=plugin;
|
||||
this.log=log;
|
||||
logger = Logger.getLogger("ChestSortLogger");
|
||||
logger.setUseParentHandlers(false);
|
||||
FileHandler fh;
|
||||
try {
|
||||
fh = new FileHandler(plugin.getDataFolder()+ File.separator+"ChestSort.log");
|
||||
logger.addHandler(fh);
|
||||
SimpleFormatter formatter = new SimpleFormatter();
|
||||
fh.setFormatter(formatter);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private String getPlayerSettings(Player p) {
|
||||
if(plugin.perPlayerSettings.containsKey(p.getUniqueId().toString())) {
|
||||
ChestSortPlayerSetting s = plugin.perPlayerSettings.get(p.getUniqueId().toString());
|
||||
return String.format("sorting: %s, invsorting: %s, middle-click: %s, shift-click: %s, double-click: %s, shift-right-click: %s, left-click: %s, right-click: %s, seen-msg: %s",
|
||||
s.sortingEnabled, s.invSortingEnabled, s.middleClick, s.shiftClick, s.doubleClick, s.shiftRightClick, s.leftClick, s.rightClick, s.hasSeenMessage);
|
||||
} else {
|
||||
return "null";
|
||||
}
|
||||
}
|
||||
|
||||
private void log(String s) {
|
||||
if(!log) return;
|
||||
logger.info(s);
|
||||
}
|
||||
|
||||
void logSort(Player p, @Nullable SortCause cause) {
|
||||
if(!log) return;
|
||||
String settings = getPlayerSettings(p);
|
||||
if(cause==null) cause = SortCause.UNKNOWN;
|
||||
log(String.format("SORT: Player: %s, Cause: %s, Settings: {%s}",p.getName(),cause.name(),settings));
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
void logPlayerJoin(Player p) {
|
||||
if(!log) return;
|
||||
String settings = getPlayerSettings(p);
|
||||
log(String.format("JOIN: Player: %s, Settings: {%s}",p.getName(),settings));
|
||||
}
|
||||
}
|
@ -57,6 +57,7 @@ import de.jeff_media.ChestSort.utils.Utils;
|
||||
|
||||
public class ChestSortPlugin extends JavaPlugin {
|
||||
|
||||
ChestSortLogger lgr;
|
||||
Map<String, ChestSortPlayerSetting> perPlayerSettings = new HashMap<>();
|
||||
ChestSortMessages messages;
|
||||
ChestSortOrganizer organizer;
|
||||
@ -67,7 +68,7 @@ public class ChestSortPlugin extends JavaPlugin {
|
||||
String sortingMethod;
|
||||
ArrayList<String> disabledWorlds;
|
||||
ChestSortAPI api;
|
||||
final int currentConfigVersion = 34;
|
||||
final int currentConfigVersion = 35;
|
||||
boolean usingMatchingConfig = true;
|
||||
protected boolean debug = false;
|
||||
boolean verbose = true;
|
||||
@ -182,6 +183,7 @@ public class ChestSortPlugin extends JavaPlugin {
|
||||
getConfig().addDefault("additional-hotkeys.left-click", false);
|
||||
getConfig().addDefault("additional-hotkeys.right-click", false);
|
||||
getConfig().addDefault("dump", false);
|
||||
getConfig().addDefault("log", false);
|
||||
|
||||
getConfig().addDefault("hook-crackshot", true);
|
||||
getConfig().addDefault("hook-crackshot-prefix", "crackshot_weapon");
|
||||
@ -438,7 +440,7 @@ public class ChestSortPlugin extends JavaPlugin {
|
||||
saveDefaultCategories();
|
||||
|
||||
verbose = getConfig().getBoolean("verbose");
|
||||
|
||||
lgr = new ChestSortLogger(this,getConfig().getBoolean("log"));
|
||||
messages = new ChestSortMessages(this);
|
||||
organizer = new ChestSortOrganizer(this);
|
||||
settingsGUI = new ChestSortSettingsGUI(this);
|
||||
|
@ -568,6 +568,9 @@ dump: false
|
||||
# Debug mode - you probably do not want this.
|
||||
debug: false
|
||||
|
||||
# Enable log - you probably do not want this.
|
||||
log: false
|
||||
|
||||
# Please DO NOT change the following line manually!
|
||||
# It is used by the automatic config updater.
|
||||
config-version: 34
|
||||
config-version: 35
|
@ -24,10 +24,10 @@ commands:
|
||||
invsort:
|
||||
description: Toggle automatic inventory sorting or sorts the player's inventory.
|
||||
usage: |
|
||||
/<command> -- Sort your inventory
|
||||
/<command> toggle -- Toggle automatic inventory sorting
|
||||
/<command> on -- Enable automatic inventory sorting
|
||||
/<command> off -- Disable automatic inventory sorting
|
||||
/<command> inv -- Sort your inventory
|
||||
/<command> hotbar -- Sort your hotbar
|
||||
/<command> all -- Sort your inventory and hotbar
|
||||
/<command> help -- Shows help about this command
|
||||
|
Loading…
Reference in New Issue
Block a user