mirror of
https://github.com/JEFF-Media-GbR/ChestSort.git
synced 2025-01-22 08:02:33 +01:00
Closes: #61
This commit is contained in:
parent
c17fd9dc5a
commit
e2e05c0c3f
@ -1,4 +1,8 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
## 8.5
|
||||||
|
- Updated French translation
|
||||||
|
- Fixed InventoryPages support: when using &f at the beginning of button names, it was not detected by ChestSort as button
|
||||||
|
|
||||||
## 8.4
|
## 8.4
|
||||||
- Fixes InventoryPages support for the new hotkeys
|
- Fixes InventoryPages support for the new hotkeys
|
||||||
|
|
||||||
|
@ -47,11 +47,11 @@ public class JeffChestSortAdditionalHotkeyListener implements Listener {
|
|||||||
JeffChestSortPlayerSetting setting = plugin.perPlayerSettings.get(p.getUniqueId().toString());
|
JeffChestSortPlayerSetting setting = plugin.perPlayerSettings.get(p.getUniqueId().toString());
|
||||||
|
|
||||||
if(e.isLeftClick() && setting.leftClick) {
|
if(e.isLeftClick() && setting.leftClick) {
|
||||||
plugin.invhelper.stuffPlayerInventoryIntoAnother(p.getInventory(), e.getInventory());
|
plugin.organizer.stuffPlayerInventoryIntoAnother(p.getInventory(), e.getInventory());
|
||||||
plugin.sortInventory(e.getInventory());
|
plugin.sortInventory(e.getInventory());
|
||||||
plugin.invhelper.updateInventoryView(e.getInventory());
|
plugin.organizer.updateInventoryView(e.getInventory());
|
||||||
} else if(e.isRightClick() && setting.rightClick) {
|
} else if(e.isRightClick() && setting.rightClick) {
|
||||||
plugin.invhelper.stuffInventoryIntoAnother(e.getInventory(), p.getInventory(),e.getInventory());
|
plugin.organizer.stuffInventoryIntoAnother(e.getInventory(), p.getInventory(),e.getInventory());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,7 +348,7 @@ public class JeffChestSortListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
plugin.organizer.sortInventory(event.getClickedInventory());
|
plugin.organizer.sortInventory(event.getClickedInventory());
|
||||||
plugin.invhelper.updateInventoryView(event);
|
plugin.organizer.updateInventoryView(event);
|
||||||
return;
|
return;
|
||||||
} else if(holder instanceof Player) {
|
} else if(holder instanceof Player) {
|
||||||
|
|
||||||
@ -358,12 +358,12 @@ public class JeffChestSortListener implements Listener {
|
|||||||
|
|
||||||
if(event.getSlotType() == SlotType.QUICKBAR) {
|
if(event.getSlotType() == SlotType.QUICKBAR) {
|
||||||
plugin.organizer.sortInventory(p.getInventory(),0,8);
|
plugin.organizer.sortInventory(p.getInventory(),0,8);
|
||||||
plugin.invhelper.updateInventoryView(event);
|
plugin.organizer.updateInventoryView(event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if(event.getSlotType() == SlotType.CONTAINER) {
|
else if(event.getSlotType() == SlotType.CONTAINER) {
|
||||||
plugin.organizer.sortInventory(p.getInventory(),9,35);
|
plugin.organizer.sortInventory(p.getInventory(),9,35);
|
||||||
plugin.invhelper.updateInventoryView(event);
|
plugin.organizer.updateInventoryView(event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -6,14 +6,20 @@ import java.io.FilenameFilter;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.event.inventory.InventoryType;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.inventory.meta.PotionMeta;
|
import org.bukkit.inventory.meta.PotionMeta;
|
||||||
@ -39,7 +45,11 @@ public class JeffChestSortOrganizer {
|
|||||||
|
|
||||||
JeffChestSortPlugin plugin;
|
JeffChestSortPlugin plugin;
|
||||||
CrackShotHook crackShotHook;
|
CrackShotHook crackShotHook;
|
||||||
public InventoryPagesHook inventoryPagesHook; // public for InventoryHelper
|
InventoryPagesHook inventoryPagesHook;
|
||||||
|
|
||||||
|
private static final int maxInventorySize=54;
|
||||||
|
private static final int playerInvStartSlot=9; // Inclusive
|
||||||
|
private static final int playerInvEndSlot=35; // Inclusive
|
||||||
|
|
||||||
// All available colors in the game. We will strip this from the item names and
|
// All available colors in the game. We will strip this from the item names and
|
||||||
// keep the color in a separate variable
|
// keep the color in a separate variable
|
||||||
@ -387,6 +397,14 @@ public class JeffChestSortOrganizer {
|
|||||||
for (int i = endSlot + 1; i < inv.getSize(); i++) {
|
for (int i = endSlot + 1; i < inv.getSize(); i++) {
|
||||||
items[i] = null;
|
items[i] = null;
|
||||||
}
|
}
|
||||||
|
// Get rid of all stuff that contains more than maxStackSize
|
||||||
|
for(int i = 0; i<endSlot; i++) {
|
||||||
|
if(inv.getItem(i) != null && inv.getItem(i).getAmount() > inv.getItem(i).getMaxStackSize()) {
|
||||||
|
//System.out.println("Debug: "+inv.getItem(i).getMaxStackSize());
|
||||||
|
//items[i] = null;
|
||||||
|
//unsortableSlots.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
// If InventoryPages is installed: get rid of the buttons
|
// If InventoryPages is installed: get rid of the buttons
|
||||||
if(plugin.hookInventoryPages) {
|
if(plugin.hookInventoryPages) {
|
||||||
for(int i = startSlot; i<= endSlot; i++) {
|
for(int i = startSlot; i<= endSlot; i++) {
|
||||||
@ -498,5 +516,61 @@ public class JeffChestSortOrganizer {
|
|||||||
}
|
}
|
||||||
return totalEnchants;
|
return totalEnchants;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateInventoryView(InventoryClickEvent event) {
|
||||||
|
for(HumanEntity viewer : event.getViewers()) {
|
||||||
|
if(viewer instanceof Player) {
|
||||||
|
Player playerViewer = (Player) viewer;
|
||||||
|
playerViewer.updateInventory();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateInventoryView(Inventory inventory) {
|
||||||
|
for(HumanEntity viewer : inventory.getViewers()) {
|
||||||
|
if(viewer instanceof Player) {
|
||||||
|
Player playerViewer = (Player) viewer;
|
||||||
|
playerViewer.updateInventory();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stuffInventoryIntoAnother(Inventory source, Inventory destination,Inventory origSource) {
|
||||||
|
|
||||||
|
ArrayList<ItemStack> leftovers = new ArrayList<ItemStack>();
|
||||||
|
|
||||||
|
for(int i = 0;i<source.getSize();i++) {
|
||||||
|
|
||||||
|
ItemStack current = source.getItem(i);
|
||||||
|
|
||||||
|
if(current == null) continue;
|
||||||
|
|
||||||
|
source.clear(i);
|
||||||
|
HashMap<Integer,ItemStack> currentLeftovers = destination.addItem(current);
|
||||||
|
|
||||||
|
for(ItemStack currentLeftover : currentLeftovers.values()) {
|
||||||
|
leftovers.add(currentLeftover);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
origSource.addItem(leftovers.toArray(new ItemStack[leftovers.size()]));
|
||||||
|
updateInventoryView(destination);
|
||||||
|
updateInventoryView(source);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stuffPlayerInventoryIntoAnother(PlayerInventory source,
|
||||||
|
Inventory destination) {
|
||||||
|
boolean destinationIsShulkerBox = destination.getType() == InventoryType.SHULKER_BOX;
|
||||||
|
Inventory temp = Bukkit.createInventory(null, maxInventorySize);
|
||||||
|
for(int i = playerInvStartSlot;i<=playerInvEndSlot;i++) {
|
||||||
|
if(source.getItem(i)==null) continue;
|
||||||
|
if(plugin.hookInventoryPages && plugin.organizer.inventoryPagesHook.isButton(source.getItem(i), i, source)) continue;
|
||||||
|
if(destinationIsShulkerBox && source.getItem(i).getType().name().endsWith("SHULKER_BOX")) continue;
|
||||||
|
temp.addItem(source.getItem(i));
|
||||||
|
source.clear(i);
|
||||||
|
}
|
||||||
|
stuffInventoryIntoAnother(temp,destination,source);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -50,15 +50,13 @@ 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;
|
||||||
|
|
||||||
import de.jeffclan.utils.InventoryHelper;
|
|
||||||
import de.jeffclan.utils.Utils;
|
import de.jeffclan.utils.Utils;
|
||||||
|
|
||||||
public class JeffChestSortPlugin extends JavaPlugin {
|
public class JeffChestSortPlugin extends JavaPlugin {
|
||||||
|
|
||||||
Map<String, JeffChestSortPlayerSetting> perPlayerSettings = new HashMap<String, JeffChestSortPlayerSetting>();
|
Map<String, JeffChestSortPlayerSetting> perPlayerSettings = new HashMap<String, JeffChestSortPlayerSetting>();
|
||||||
JeffChestSortMessages messages;
|
JeffChestSortMessages messages;
|
||||||
public JeffChestSortOrganizer organizer;
|
JeffChestSortOrganizer organizer;
|
||||||
InventoryHelper invhelper;
|
|
||||||
JeffChestSortUpdateChecker updateChecker;
|
JeffChestSortUpdateChecker updateChecker;
|
||||||
JeffChestSortListener listener;
|
JeffChestSortListener listener;
|
||||||
JeffChestSortAdditionalHotkeyListener additionalHotkeys;
|
JeffChestSortAdditionalHotkeyListener additionalHotkeys;
|
||||||
@ -245,7 +243,6 @@ public class JeffChestSortPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
// Organizer will load all category files and will be ready to sort stuff
|
// Organizer will load all category files and will be ready to sort stuff
|
||||||
organizer = new JeffChestSortOrganizer(this);
|
organizer = new JeffChestSortOrganizer(this);
|
||||||
invhelper = new InventoryHelper(this);
|
|
||||||
|
|
||||||
settingsGUI = new JeffChestSortSettingsGUI(this);
|
settingsGUI = new JeffChestSortSettingsGUI(this);
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ public class InventoryPagesHook {
|
|||||||
prevMat = Material.valueOf(inventoryPagesConfig.getString("items.prev.id"));
|
prevMat = Material.valueOf(inventoryPagesConfig.getString("items.prev.id"));
|
||||||
nextMat = Material.valueOf(inventoryPagesConfig.getString("items.next.id"));
|
nextMat = Material.valueOf(inventoryPagesConfig.getString("items.next.id"));
|
||||||
noPageMat = Material.valueOf(inventoryPagesConfig.getString("items.noPage.id"));
|
noPageMat = Material.valueOf(inventoryPagesConfig.getString("items.noPage.id"));
|
||||||
|
|
||||||
prevName = ChatColor.translateAlternateColorCodes('&', inventoryPagesConfig.getString("items.prev.name"));
|
prevName = ChatColor.translateAlternateColorCodes('&', inventoryPagesConfig.getString("items.prev.name"));
|
||||||
nextName = ChatColor.translateAlternateColorCodes('&', inventoryPagesConfig.getString("items.next.name"));
|
nextName = ChatColor.translateAlternateColorCodes('&', inventoryPagesConfig.getString("items.next.name"));
|
||||||
noPageName = ChatColor.translateAlternateColorCodes('&', inventoryPagesConfig.getString("items.noPage.name"));
|
noPageName = ChatColor.translateAlternateColorCodes('&', inventoryPagesConfig.getString("items.noPage.name"));
|
||||||
@ -62,9 +62,13 @@ public class InventoryPagesHook {
|
|||||||
|
|
||||||
//System.out.println("Checking if slot " + slot + " "+ item.toString() + " is button");
|
//System.out.println("Checking if slot " + slot + " "+ item.toString() + " is button");
|
||||||
|
|
||||||
|
// When using &f as color, we manually have to add this to the string because it gets removed by InventoryPages
|
||||||
|
if(prevName.startsWith("§f")) prevName = prevName.substring(2,prevName.length());
|
||||||
|
if(nextName.startsWith("§f")) nextName = nextName.substring(2,nextName.length());
|
||||||
|
if(noPageName.startsWith("§f")) noPageName = noPageName.substring(2,noPageName.length());
|
||||||
|
|
||||||
if(slot == prevSlot ) {
|
if(slot == prevSlot ) {
|
||||||
if(item.getType() == prevMat && item.getItemMeta().getDisplayName().equals(prevName)) {
|
if(item.getType() == prevMat && (item.getItemMeta().getDisplayName().equals(prevName))) {
|
||||||
return true;
|
return true;
|
||||||
} else if(item.getType() == noPageMat && item.getItemMeta().getDisplayName().equals(noPageName)) {
|
} else if(item.getType() == noPageMat && item.getItemMeta().getDisplayName().equals(noPageName)) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -1,86 +0,0 @@
|
|||||||
package de.jeffclan.utils;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
|
||||||
import org.bukkit.event.inventory.InventoryType;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
|
||||||
|
|
||||||
import de.jeffclan.JeffChestSort.JeffChestSortPlugin;
|
|
||||||
|
|
||||||
public class InventoryHelper {
|
|
||||||
|
|
||||||
private JeffChestSortPlugin plugin;
|
|
||||||
|
|
||||||
private static final int maxInventorySize=54;
|
|
||||||
private static final int playerInvStartSlot=9; // Inclusive
|
|
||||||
private static final int playerInvEndSlot=35; // Inclusive
|
|
||||||
|
|
||||||
public InventoryHelper(JeffChestSortPlugin jeffChestSortPlugin) {
|
|
||||||
this.plugin = jeffChestSortPlugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateInventoryView(InventoryClickEvent event) {
|
|
||||||
for(HumanEntity viewer : event.getViewers()) {
|
|
||||||
if(viewer instanceof Player) {
|
|
||||||
Player playerViewer = (Player) viewer;
|
|
||||||
playerViewer.updateInventory();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateInventoryView(Inventory inventory) {
|
|
||||||
for(HumanEntity viewer : inventory.getViewers()) {
|
|
||||||
if(viewer instanceof Player) {
|
|
||||||
Player playerViewer = (Player) viewer;
|
|
||||||
playerViewer.updateInventory();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stuffInventoryIntoAnother(Inventory source, Inventory destination,Inventory origSource) {
|
|
||||||
|
|
||||||
ArrayList<ItemStack> leftovers = new ArrayList<ItemStack>();
|
|
||||||
|
|
||||||
for(int i = 0;i<source.getSize();i++) {
|
|
||||||
|
|
||||||
ItemStack current = source.getItem(i);
|
|
||||||
|
|
||||||
if(current == null) continue;
|
|
||||||
|
|
||||||
source.clear(i);
|
|
||||||
HashMap<Integer,ItemStack> currentLeftovers = destination.addItem(current);
|
|
||||||
|
|
||||||
for(ItemStack currentLeftover : currentLeftovers.values()) {
|
|
||||||
leftovers.add(currentLeftover);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
origSource.addItem(leftovers.toArray(new ItemStack[leftovers.size()]));
|
|
||||||
updateInventoryView(destination);
|
|
||||||
updateInventoryView(source);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stuffPlayerInventoryIntoAnother(PlayerInventory source,
|
|
||||||
Inventory destination) {
|
|
||||||
boolean destinationIsShulkerBox = destination.getType() == InventoryType.SHULKER_BOX;
|
|
||||||
Inventory temp = Bukkit.createInventory(null, maxInventorySize);
|
|
||||||
for(int i = playerInvStartSlot;i<=playerInvEndSlot;i++) {
|
|
||||||
if(source.getItem(i)==null) continue;
|
|
||||||
if(plugin.hookInventoryPages && plugin.organizer.inventoryPagesHook.isButton(source.getItem(i), i, source)) continue;
|
|
||||||
if(destinationIsShulkerBox && source.getItem(i).getType().name().endsWith("SHULKER_BOX")) continue;
|
|
||||||
temp.addItem(source.getItem(i));
|
|
||||||
source.clear(i);
|
|
||||||
}
|
|
||||||
stuffInventoryIntoAnother(temp,destination,source);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -315,25 +315,24 @@ message-gui-right-click: "Empty Chest (Right-Click)"
|
|||||||
#message-gui-left-click: "Fill Chest (Left-Click)"
|
#message-gui-left-click: "Fill Chest (Left-Click)"
|
||||||
#message-gui-right-click: "Empty Chest (Right-Click)"
|
#message-gui-right-click: "Empty Chest (Right-Click)"
|
||||||
|
|
||||||
##### French / Français - Thanks to automatizer, demon57730 and FichdlMaa for translating!
|
##### French / Français - Thanks to automatizer, demon57730, FichdlMaa and Stalk3r77 for translating!
|
||||||
##### Note: Some messages are still untranslated. Please send me your translation at SpigotMC
|
#message-when-using-chest: "&7Astuce : Tape &6/chestsort&7 pour activer le classement automatique."
|
||||||
#message-when-using-chest: "&7Remarque: Tape &6/chestsort&7 pour activer le classement automatique."
|
#message-when-using-chest2: "&7Astuce : Tape &6/chestsort&7 pour désactiver le classement automatique."
|
||||||
#message-when-using-chest2: "&7Remarque: Tape &6/chestsort&7 pour désactiver le classement automatique."
|
|
||||||
#message-sorting-disabled: "&7Le classement automatique a été &cdésactivé&7."
|
#message-sorting-disabled: "&7Le classement automatique a été &cdésactivé&7."
|
||||||
#message-sorting-enabled: "&7Le classement automatique a été &aactivé&7."
|
#message-sorting-enabled: "&7Le classement automatique a été &aactivé&7."
|
||||||
#message-inv-sorting-disabled: "&7Le classement automatique d'inventaire a été &cdésactivé&7."
|
#message-inv-sorting-disabled: "&7Le classement automatique d'inventaire a été &cdésactivé&7."
|
||||||
#message-inv-sorting-enabled: "&7Le classement automatique d'inventaire a été &aactivé&7."
|
#message-inv-sorting-enabled: "&7Le classement automatique d'inventaire a été &aactivé&7."
|
||||||
#message-player-inventory-sorted: "&7Ton inventaire a été trié."
|
#message-player-inventory-sorted: "&7Ton inventaire a été trié."
|
||||||
#message-error-players-only: "&cErreur: Cette commande ne peut être utilisée que par des joueurs."
|
#message-error-players-only: "&cErreur : Cette commande ne peut être utilisée que par des joueurs."
|
||||||
#message-error-invalid-options: "&cErreur: Option inconnue %s. Les options valides sont %s."
|
#message-error-invalid-options: "&cErreur : Option inconnue %s. Les options valides sont %s."
|
||||||
#message-gui-enabled: "&aActivé"
|
#message-gui-enabled: "&aActivé"
|
||||||
#message-gui-disabled: "&cDésactivé"
|
#message-gui-disabled: "&cDésactivé"
|
||||||
#message-gui-middle-click: "Clic du milieu"
|
#message-gui-middle-click: "Clic molette"
|
||||||
#message-gui-shift-click: "Maj. + Clic"
|
#message-gui-shift-click: "Maj. + Clic"
|
||||||
#message-gui-double-click: "Double-Clic"
|
#message-gui-double-click: "Double-Clic"
|
||||||
#message-gui-shift-right-click: "Shift + Clic droit"
|
#message-gui-shift-right-click: "Shift + Clic droit"
|
||||||
#message-gui-left-click: "Fill Chest (Left-Click)"
|
#message-gui-left-click: "Remplir le coffre (Clic-gauche)"
|
||||||
#message-gui-right-click: "Empty Chest (Right-Click)"
|
#message-gui-right-click: "Vider le coffre (Clic-droit)"
|
||||||
|
|
||||||
##### German
|
##### German
|
||||||
#message-when-using-chest: "&7Hinweis: Benutze &6/chestsort&7 um die automatische Kistensortierung zu aktivieren."
|
#message-when-using-chest: "&7Hinweis: Benutze &6/chestsort&7 um die automatische Kistensortierung zu aktivieren."
|
||||||
|
Loading…
Reference in New Issue
Block a user