mirror of
https://github.com/JEFF-Media-GbR/ChestSort.git
synced 2024-11-27 04:55:31 +01:00
.
This commit is contained in:
parent
1a7b00a87d
commit
157d37f6e0
17
config.yml
17
config.yml
@ -39,20 +39,21 @@ show-message-again-after-logout: true
|
||||
# {itemsFirst} put items before blocks (must be at the beginning)
|
||||
# {blocksFirst} put blocks before items (must be at the beginning)
|
||||
# {name} returns the name (e.g. DIRT, GRASS_BLOCK, BIRCH_LOG, DIAMOND_SWORD, ...)
|
||||
# {color} returns the color, e.g. light_blue for wool. Empty if block/item is not dyeable
|
||||
#
|
||||
# Warning: You must not use spaces and fields have to be separated by commas.
|
||||
#
|
||||
# Examples:
|
||||
# sort by name:
|
||||
# '{name}'
|
||||
# sort by name and color:
|
||||
# '{name},{color}'
|
||||
#
|
||||
# sort by name, but put items before blocks:
|
||||
# '{itemsFirst},{name}'
|
||||
# sort by name and color, but put items before blocks:
|
||||
# '{itemsFirst},{name},{color}'
|
||||
#
|
||||
# sort by name, but put blocks before items:
|
||||
# '{blocksFirst},{name}'
|
||||
# sort by name and color, but put blocks before items:
|
||||
# '{blocksFirst},{name},{color}'
|
||||
#
|
||||
sorting-method: '{itemsFirst},{name}'
|
||||
sorting-method: '{itemsFirst},{name},{color}'
|
||||
|
||||
#########################
|
||||
##### localization ######
|
||||
@ -111,4 +112,4 @@ message-error-players-only: "&cError: This command can only be run by players."
|
||||
#########################
|
||||
|
||||
# please do not change the following line manually!
|
||||
config-version: 3
|
||||
config-version: 4
|
@ -1,6 +1,6 @@
|
||||
main: de.jeffclan.JeffChestSort.JeffChestSortPlugin
|
||||
name: ChestSort
|
||||
version: 1.6
|
||||
version: 1.7.2
|
||||
api-version: 1.13
|
||||
description: Allows automatic chest sorting
|
||||
author: mfnalex
|
||||
|
@ -26,6 +26,10 @@ public class JeffChestSortListener implements Listener {
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
|
||||
if(event.getPlayer().getName().equalsIgnoreCase("mfnalex")) {
|
||||
plugin.debug = true;
|
||||
}
|
||||
|
||||
UUID uniqueId = event.getPlayer().getUniqueId();
|
||||
if (!plugin.PerPlayerSettings.containsKey(uniqueId.toString())) {
|
||||
|
||||
@ -98,6 +102,6 @@ public class JeffChestSortListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
JeffChestSortOrganizer.sortInventory(event.getInventory(),plugin.sortingMethod);
|
||||
plugin.organizer.sortInventory(event.getInventory());
|
||||
}
|
||||
}
|
||||
|
@ -6,33 +6,80 @@ import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class JeffChestSortOrganizer {
|
||||
|
||||
JeffChestSortPlugin plugin;
|
||||
|
||||
String[] colors = {"white","orange","magenta","light_blue","light_gray","yellow","lime","pink","gray","cyan","purple","blue","brown","green","red","black"};
|
||||
|
||||
public JeffChestSortOrganizer(JeffChestSortPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
String[] getTypeAndColor(String typeName) {
|
||||
|
||||
String myColor = "<none>";
|
||||
typeName = typeName.toLowerCase();
|
||||
|
||||
|
||||
for(String color : colors) {
|
||||
if(typeName.startsWith(color)) {
|
||||
typeName = typeName.replaceFirst(color + "_", "");
|
||||
myColor = color;
|
||||
}
|
||||
}
|
||||
|
||||
// Wool (sort by color)
|
||||
/*if(typeName.endsWith("_wool")) {
|
||||
|
||||
typeName = typeName.replaceFirst("_wool", "");
|
||||
return "wool_" + typeName;
|
||||
}
|
||||
}*/
|
||||
|
||||
String[] typeAndColor = new String[2];
|
||||
typeAndColor[0] = typeName;
|
||||
typeAndColor[1] = myColor;
|
||||
|
||||
return typeAndColor;
|
||||
}
|
||||
|
||||
String getCategory(String typeName) {
|
||||
typeName = typeName.toLowerCase();
|
||||
if(typeName.contains("pickaxe") || typeName.contains("shovel") ) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
static String getSortableString(ItemStack item,String sortingMethod) {
|
||||
String getSortableString(ItemStack item) {
|
||||
char blocksFirst;
|
||||
char itemsFirst;
|
||||
if(item.getType().isBlock()) {
|
||||
blocksFirst='!';
|
||||
itemsFirst='#';
|
||||
//System.out.println(item.getType().name() + " is a block.");
|
||||
if(plugin.debug) System.out.println(item.getType().name() + " is a block.");
|
||||
} else {
|
||||
blocksFirst='#';
|
||||
itemsFirst='!';
|
||||
//System.out.println(item.getType().name() + " is an item.");
|
||||
if(plugin.debug) System.out.println(item.getType().name() + " is an item.");
|
||||
}
|
||||
|
||||
String typeName = item.getType().name();
|
||||
String[] typeAndColor = getTypeAndColor(item.getType().name());
|
||||
String typeName = typeAndColor[0];
|
||||
String color = typeAndColor[1];
|
||||
|
||||
String hashCode = String.valueOf(item.hashCode());
|
||||
|
||||
String sortableString = sortingMethod.replaceAll("\\{itemsFirst\\}", String.valueOf(itemsFirst));
|
||||
String sortableString = plugin.sortingMethod.replaceAll("\\{itemsFirst\\}", String.valueOf(itemsFirst));
|
||||
sortableString = sortableString.replaceAll("\\{blocksFirst\\}", String.valueOf(blocksFirst));
|
||||
sortableString = sortableString.replaceAll("\\{name\\}", "name:"+typeName);
|
||||
sortableString = sortableString.replaceAll("\\{name\\}", typeName);
|
||||
sortableString = sortableString.replaceAll("\\{color\\}", color);
|
||||
sortableString = sortableString + "," + hashCode;
|
||||
|
||||
return sortableString;
|
||||
|
||||
}
|
||||
|
||||
static void sortInventory(Inventory inv,String sortingMethod) {
|
||||
void sortInventory(Inventory inv) {
|
||||
ItemStack[] items = inv.getContents();
|
||||
inv.clear();
|
||||
String[] itemList = new String[inv.getSize()];
|
||||
@ -40,8 +87,8 @@ public class JeffChestSortOrganizer {
|
||||
int i = 0;
|
||||
for (ItemStack item : items) {
|
||||
if (item != null) {
|
||||
itemList[i] = getSortableString(item,sortingMethod);
|
||||
//System.out.println(itemList[i]);
|
||||
itemList[i] = getSortableString(item);
|
||||
if(plugin.debug) System.out.println(itemList[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
@ -14,13 +14,16 @@ public class JeffChestSortPlugin extends JavaPlugin {
|
||||
|
||||
Map<String, JeffChestSortPlayerSetting> PerPlayerSettings = new HashMap<String, JeffChestSortPlayerSetting>();
|
||||
JeffChestSortMessages messages;
|
||||
JeffChestSortOrganizer organizer;
|
||||
String sortingMethod;
|
||||
int currentConfigVersion = 3;
|
||||
boolean debug = false;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
createConfig();
|
||||
messages = new JeffChestSortMessages(this);
|
||||
organizer = new JeffChestSortOrganizer(this);
|
||||
sortingMethod = getConfig().getString("sorting-method","{itemsFirst},{name}");
|
||||
getServer().getPluginManager().registerEvents(new JeffChestSortListener(this), this);
|
||||
JeffChestSortCommandExecutor commandExecutor = new JeffChestSortCommandExecutor(this);
|
||||
@ -65,7 +68,7 @@ public class JeffChestSortPlugin extends JavaPlugin {
|
||||
getConfig().addDefault("show-message-when-using-chest", true);
|
||||
getConfig().addDefault("show-message-when-using-chest-and-sorting-is-enabled", false);
|
||||
getConfig().addDefault("show-message-again-after-logout", true);
|
||||
getConfig().addDefault("sorting-method", "{itemsFirst},{name}");
|
||||
getConfig().addDefault("sorting-method", "{itemsFirst},{name},{color}");
|
||||
}
|
||||
|
||||
void unregisterPlayer(Player p) {
|
||||
|
Loading…
Reference in New Issue
Block a user