mirror of
https://github.com/JEFF-Media-GbR/ChestSort.git
synced 2024-11-26 20:48:12 +01:00
Revert "Convert the project to use Maven"
This commit is contained in:
parent
f6a77b5440
commit
fe27292d4a
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +0,0 @@
|
||||
.idea/
|
||||
target/
|
||||
bin/
|
@ -1,176 +1,176 @@
|
||||
#########################
|
||||
##### ChestSort #####
|
||||
#########################
|
||||
|
||||
#
|
||||
# Please note that players will need the chestsort.use permission
|
||||
# or have to be OP to be able to use automatic chest sorting.
|
||||
#
|
||||
|
||||
# when set to false, new players will have to run /chestsort
|
||||
# once to enable automatic chest sorting.
|
||||
sorting-enabled-by-default: false
|
||||
|
||||
# when set to true, players with sorting DISABLED will be
|
||||
# shown a message on how to enable automatic chest sorting
|
||||
# when they use a chest for the first time.
|
||||
# consider setting this to true when you disable sorting by default.
|
||||
# see also -> message-when-using-chest
|
||||
show-message-when-using-chest: true
|
||||
|
||||
# when set to true, players with sorting ENABLED will be
|
||||
# shown a message on how to disable automatic chest sorting
|
||||
# when they use a chest for the first time.
|
||||
# consider setting this to true when you enable sorting by default.
|
||||
# see also -> message-when-using-chest2
|
||||
show-message-when-using-chest-and-sorting-is-enabled: false
|
||||
|
||||
# when set to true, the messages are shown again when a player
|
||||
# logs out and back in and then uses a chest again.
|
||||
show-message-again-after-logout: true
|
||||
|
||||
# to sort by category, we need category files. ChestSort comes
|
||||
# with a number of pregenerated category files, named
|
||||
# 900-valuables.txt, 910-tools.txt, 920-combat.txt, ...
|
||||
# If you wish to edit those, you can disable the generation of these
|
||||
# files, because otherwise all your changes in the pregenerated
|
||||
# files will be overwritten on each server startup.
|
||||
auto-generate-category-files: true
|
||||
|
||||
# should we check for updates?
|
||||
# when enabled, a message is printed in the console if a new
|
||||
# version has been found, and OPs will be notified when they
|
||||
# join the server
|
||||
# When set to true, we will check for updates on startup and every 24 hours
|
||||
# When set to on-startup, we will only check on startup
|
||||
# When set to false, don't check for updates
|
||||
check-for-updates: true
|
||||
|
||||
# when set to true, show some verbose information on startup
|
||||
verbose: true
|
||||
|
||||
#########################
|
||||
#### disabled worlds ####
|
||||
#########################
|
||||
|
||||
# You can disable ChestSort for certain worlds. Each world's name has to
|
||||
# be on a separate line, starting with a hyphen and followed by a space
|
||||
|
||||
# Example:
|
||||
#
|
||||
# disabled-worlds:
|
||||
# - world_nether
|
||||
# - world_the_end
|
||||
|
||||
disabled-worlds:
|
||||
|
||||
##########################
|
||||
##### Sorting Method #####
|
||||
##########################
|
||||
|
||||
# Advanced: how to sort things! See below for examples.
|
||||
# Only change this if you know what you are doing.
|
||||
#
|
||||
# Available variables:
|
||||
# {category} order stuff by category as defined in plugins/ChestSort/categories/<category>.txt
|
||||
# {itemsFirst} put items before blocks
|
||||
# {blocksFirst} put blocks before items
|
||||
# {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 and color:
|
||||
# '{name},{color}'
|
||||
#
|
||||
# sort by name and color, but put items before blocks:
|
||||
# '{itemsFirst},{name},{color}'
|
||||
#
|
||||
# sort by name and color, but put blocks before items:
|
||||
# '{blocksFirst},{name},{color}'
|
||||
#
|
||||
# sort by category, then put items before blocks and sort by name and color
|
||||
# '{category},{itemsFirst},{name},{color}'
|
||||
#
|
||||
sorting-method: '{category},{itemsFirst},{name},{color}'
|
||||
|
||||
#########################
|
||||
##### localization ######
|
||||
#########################
|
||||
|
||||
# Available color codes:
|
||||
# &0 Black &6 Gold &c Red
|
||||
# &1 Dark Blue &7 Gray &d Light Purple
|
||||
# &2 Dark Green &8 Dark Gray &e Yellow
|
||||
# &3 Dark Aqua &9 Blue &f White
|
||||
# &4 Dark Red &a Green
|
||||
# &5 Dark Purple &b Aqua
|
||||
|
||||
# Available formatting codes:
|
||||
# &k Obfuscated &m Strikethrough
|
||||
# &l Bold &o Italic
|
||||
# &n Underline &r Reset
|
||||
|
||||
##### English
|
||||
message-when-using-chest: "&7Hint: Type &6/chestsort&7 to enable automatic chest sorting."
|
||||
message-when-using-chest2: "&7Hint: Type &6/chestsort&7 to disable automatic chest sorting."
|
||||
message-sorting-disabled: "&7Automatic chest sorting has been &cdisabled&7."
|
||||
message-sorting-enabled: "&7Automatic chest sorting has been &aenabled&7."
|
||||
message-error-players-only: "&cError: This command can only be run by players."
|
||||
|
||||
##### Chinese - Thanks to qsefthuopq for translating! -> https://www.spigotmc.org/members/qsefthuopq.339953/
|
||||
#message-when-using-chest: "&7提示: 输入 &6/chestsort&7 来启用自动整理箱子."
|
||||
#message-when-using-chest2: "&7提示: 输入 &6/chestsort&7 来关闭自动整理箱子."
|
||||
#message-sorting-disabled: "&7自动整理箱子已 &c关闭&7."
|
||||
#message-sorting-enabled: "&7自动整理箱子已 &a启用&7."
|
||||
#message-error-players-only: "&c错误: 指令只能由玩家运行."
|
||||
|
||||
##### Traditional Chinese 繁體中文
|
||||
#message-when-using-chest: "&7小提醒: 輸入 &6/chestsort&7 來開啟自動整理箱子"
|
||||
#message-when-using-chest2: "&7小提醒: 輸入 &6/chestsort&7 來關閉自動整理箱子"
|
||||
#message-sorting-disabled: "&7自動整理箱子已 &c關閉&7"
|
||||
#message-sorting-enabled: "&7自動整理箱子已 &a開啟&7"
|
||||
#message-error-players-only: "&c錯誤: 這個指令只能由玩家使用"
|
||||
|
||||
##### French - Thanks to automatizer for translating! -> https://www.spigotmc.org/members/automatizer.26188/
|
||||
#message-when-using-chest: "&7Astuce: Écris &6/chestsort&7 pour activer le classement automatique."
|
||||
#message-when-using-chest2: "&7Astuce: Écris &6/chestsort&7 pour désactiver le classement automatique."
|
||||
#message-sorting-disabled: "&7Le classement automatique a été &cdésactivé&7."
|
||||
#message-sorting-enabled: "&7Le classement automatique a été &aactivé&7."
|
||||
#message-error-players-only: "&cErreur: Cette commande ne peut être utilisée que par des joueurs."
|
||||
|
||||
##### German
|
||||
#message-when-using-chest: "&7Hinweis: Benutze &6/chestsort&7 um die automatische Kistensortierung zu aktivieren."
|
||||
#message-when-using-chest2: "&7Hinweis: Benutze &6/chestsort&7 um die automatische Kistensortierung zu deaktivieren."
|
||||
#message-sorting-disabled: "&7Automatische Kistensortierung &cdeaktiviert&7."
|
||||
#message-sorting-enabled: "&7Automatische Kistensortierung &aaktiviert&7."
|
||||
#message-error-players-only: "&cFehler: Dieser Befehl ist nur für Spieler verfügbar."
|
||||
|
||||
##### Italian - Translated with Google. Please tell me if something is wrong :)
|
||||
#message-when-using-chest: "&7Nota: inserire &6/chestsort&7 per abilitare l'ordinamento automatico dei bauli."
|
||||
#message-when-using-chest2: "&7Nota: inserire &6/chestsort&7 per disabilitare l'ordinamento automatico dei bauli."
|
||||
#message-sorting-disabled: "&7L'ordinamento automatico dei bauli è stato &cdisattivato&7."
|
||||
#message-sorting-enabled: "&7L'ordinamento automatico dei bauli è stato &aattivato&7."
|
||||
#message-error-players-only: "&cErrore: questo comando è disponibile solo per i giocatori."
|
||||
|
||||
##### Japanese
|
||||
#message-when-using-chest: "&7ヒント: &6/chestsort&7 と入力して自動チェスト整理を有効にできます。"
|
||||
#message-when-using-chest2: "&7ヒント: &6/chestsort&7 と入力すると自動チェスト整理を無効にできます。"
|
||||
#message-sorting-disabled: "&7自動チェスト整理は現在 &cOFF&7です。"
|
||||
#message-sorting-enabled: "&7自動チェスト整理は現在 &aON&7です。"
|
||||
#message-error-players-only: "&cエラー: このコマンドはプレイヤーのみ実行できます。"
|
||||
|
||||
##### Spanish - Thanks to Bers_ for translating! -> https://www.spigotmc.org/members/bers_.146126/
|
||||
#message-when-using-chest: "&7Pista: Usa &6/chestsort&7 para activar el orden automático de los cofres."
|
||||
#message-when-using-chest2: "&7Pista: Usa &6/chestsort&7 para desactivar el orden automático de los cofres."
|
||||
#message-sorting-disabled: "&7Orden automático de los cofres &cdesactivado&7."
|
||||
#message-sorting-enabled: "&7Orden automático de los cofres &aactivado&7."
|
||||
#message-error-players-only: "&cError: Este comando solo puede ser ejecutado por jugadores."
|
||||
|
||||
#########################
|
||||
##### Done! #####
|
||||
#########################
|
||||
|
||||
# please do not change the following line manually!
|
||||
config-version: 6
|
||||
#########################
|
||||
##### ChestSort #####
|
||||
#########################
|
||||
|
||||
#
|
||||
# Please note that players will need the chestsort.use permission
|
||||
# or have to be OP to be able to use automatic chest sorting.
|
||||
#
|
||||
|
||||
# when set to false, new players will have to run /chestsort
|
||||
# once to enable automatic chest sorting.
|
||||
sorting-enabled-by-default: false
|
||||
|
||||
# when set to true, players with sorting DISABLED will be
|
||||
# shown a message on how to enable automatic chest sorting
|
||||
# when they use a chest for the first time.
|
||||
# consider setting this to true when you disable sorting by default.
|
||||
# see also -> message-when-using-chest
|
||||
show-message-when-using-chest: true
|
||||
|
||||
# when set to true, players with sorting ENABLED will be
|
||||
# shown a message on how to disable automatic chest sorting
|
||||
# when they use a chest for the first time.
|
||||
# consider setting this to true when you enable sorting by default.
|
||||
# see also -> message-when-using-chest2
|
||||
show-message-when-using-chest-and-sorting-is-enabled: false
|
||||
|
||||
# when set to true, the messages are shown again when a player
|
||||
# logs out and back in and then uses a chest again.
|
||||
show-message-again-after-logout: true
|
||||
|
||||
# to sort by category, we need category files. ChestSort comes
|
||||
# with a number of pregenerated category files, named
|
||||
# 900-valuables.txt, 910-tools.txt, 920-combat.txt, ...
|
||||
# If you wish to edit those, you can disable the generation of these
|
||||
# files, because otherwise all your changes in the pregenerated
|
||||
# files will be overwritten on each server startup.
|
||||
auto-generate-category-files: true
|
||||
|
||||
# should we check for updates?
|
||||
# when enabled, a message is printed in the console if a new
|
||||
# version has been found, and OPs will be notified when they
|
||||
# join the server
|
||||
# When set to true, we will check for updates on startup and every 24 hours
|
||||
# When set to on-startup, we will only check on startup
|
||||
# When set to false, don't check for updates
|
||||
check-for-updates: true
|
||||
|
||||
# when set to true, show some verbose information on startup
|
||||
verbose: true
|
||||
|
||||
#########################
|
||||
#### disabled worlds ####
|
||||
#########################
|
||||
|
||||
# You can disable ChestSort for certain worlds. Each world's name has to
|
||||
# be on a separate line, starting with a hyphen and followed by a space
|
||||
|
||||
# Example:
|
||||
#
|
||||
# disabled-worlds:
|
||||
# - world_nether
|
||||
# - world_the_end
|
||||
|
||||
disabled-worlds:
|
||||
|
||||
##########################
|
||||
##### Sorting Method #####
|
||||
##########################
|
||||
|
||||
# Advanced: how to sort things! See below for examples.
|
||||
# Only change this if you know what you are doing.
|
||||
#
|
||||
# Available variables:
|
||||
# {category} order stuff by category as defined in plugins/ChestSort/categories/<category>.txt
|
||||
# {itemsFirst} put items before blocks
|
||||
# {blocksFirst} put blocks before items
|
||||
# {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 and color:
|
||||
# '{name},{color}'
|
||||
#
|
||||
# sort by name and color, but put items before blocks:
|
||||
# '{itemsFirst},{name},{color}'
|
||||
#
|
||||
# sort by name and color, but put blocks before items:
|
||||
# '{blocksFirst},{name},{color}'
|
||||
#
|
||||
# sort by category, then put items before blocks and sort by name and color
|
||||
# '{category},{itemsFirst},{name},{color}'
|
||||
#
|
||||
sorting-method: '{category},{itemsFirst},{name},{color}'
|
||||
|
||||
#########################
|
||||
##### localization ######
|
||||
#########################
|
||||
|
||||
# Available color codes:
|
||||
# &0 Black &6 Gold &c Red
|
||||
# &1 Dark Blue &7 Gray &d Light Purple
|
||||
# &2 Dark Green &8 Dark Gray &e Yellow
|
||||
# &3 Dark Aqua &9 Blue &f White
|
||||
# &4 Dark Red &a Green
|
||||
# &5 Dark Purple &b Aqua
|
||||
|
||||
# Available formatting codes:
|
||||
# &k Obfuscated &m Strikethrough
|
||||
# &l Bold &o Italic
|
||||
# &n Underline &r Reset
|
||||
|
||||
##### English
|
||||
message-when-using-chest: "&7Hint: Type &6/chestsort&7 to enable automatic chest sorting."
|
||||
message-when-using-chest2: "&7Hint: Type &6/chestsort&7 to disable automatic chest sorting."
|
||||
message-sorting-disabled: "&7Automatic chest sorting has been &cdisabled&7."
|
||||
message-sorting-enabled: "&7Automatic chest sorting has been &aenabled&7."
|
||||
message-error-players-only: "&cError: This command can only be run by players."
|
||||
|
||||
##### Chinese - Thanks to qsefthuopq for translating! -> https://www.spigotmc.org/members/qsefthuopq.339953/
|
||||
#message-when-using-chest: "&7提示: 输入 &6/chestsort&7 来启用自动整理箱子."
|
||||
#message-when-using-chest2: "&7提示: 输入 &6/chestsort&7 来关闭自动整理箱子."
|
||||
#message-sorting-disabled: "&7自动整理箱子已 &c关闭&7."
|
||||
#message-sorting-enabled: "&7自动整理箱子已 &a启用&7."
|
||||
#message-error-players-only: "&c错误: 指令只能由玩家运行."
|
||||
|
||||
##### Traditional Chinese 繁體中文
|
||||
#message-when-using-chest: "&7小提醒: 輸入 &6/chestsort&7 來開啟自動整理箱子"
|
||||
#message-when-using-chest2: "&7小提醒: 輸入 &6/chestsort&7 來關閉自動整理箱子"
|
||||
#message-sorting-disabled: "&7自動整理箱子已 &c關閉&7"
|
||||
#message-sorting-enabled: "&7自動整理箱子已 &a開啟&7"
|
||||
#message-error-players-only: "&c錯誤: 這個指令只能由玩家使用"
|
||||
|
||||
##### French - Thanks to automatizer for translating! -> https://www.spigotmc.org/members/automatizer.26188/
|
||||
#message-when-using-chest: "&7Astuce: Écris &6/chestsort&7 pour activer le classement automatique."
|
||||
#message-when-using-chest2: "&7Astuce: Écris &6/chestsort&7 pour désactiver le classement automatique."
|
||||
#message-sorting-disabled: "&7Le classement automatique a été &cdésactivé&7."
|
||||
#message-sorting-enabled: "&7Le classement automatique a été &aactivé&7."
|
||||
#message-error-players-only: "&cErreur: Cette commande ne peut être utilisée que par des joueurs."
|
||||
|
||||
##### German
|
||||
#message-when-using-chest: "&7Hinweis: Benutze &6/chestsort&7 um die automatische Kistensortierung zu aktivieren."
|
||||
#message-when-using-chest2: "&7Hinweis: Benutze &6/chestsort&7 um die automatische Kistensortierung zu deaktivieren."
|
||||
#message-sorting-disabled: "&7Automatische Kistensortierung &cdeaktiviert&7."
|
||||
#message-sorting-enabled: "&7Automatische Kistensortierung &aaktiviert&7."
|
||||
#message-error-players-only: "&cFehler: Dieser Befehl ist nur für Spieler verfügbar."
|
||||
|
||||
##### Italian - Translated with Google. Please tell me if something is wrong :)
|
||||
#message-when-using-chest: "&7Nota: inserire &6/chestsort&7 per abilitare l'ordinamento automatico dei bauli."
|
||||
#message-when-using-chest2: "&7Nota: inserire &6/chestsort&7 per disabilitare l'ordinamento automatico dei bauli."
|
||||
#message-sorting-disabled: "&7L'ordinamento automatico dei bauli è stato &cdisattivato&7."
|
||||
#message-sorting-enabled: "&7L'ordinamento automatico dei bauli è stato &aattivato&7."
|
||||
#message-error-players-only: "&cErrore: questo comando è disponibile solo per i giocatori."
|
||||
|
||||
##### Japanese
|
||||
#message-when-using-chest: "&7ヒント: &6/chestsort&7 と入力して自動チェスト整理を有効にできます。"
|
||||
#message-when-using-chest2: "&7ヒント: &6/chestsort&7 と入力すると自動チェスト整理を無効にできます。"
|
||||
#message-sorting-disabled: "&7自動チェスト整理は現在 &cOFF&7です。"
|
||||
#message-sorting-enabled: "&7自動チェスト整理は現在 &aON&7です。"
|
||||
#message-error-players-only: "&cエラー: このコマンドはプレイヤーのみ実行できます。"
|
||||
|
||||
##### Spanish - Thanks to Bers_ for translating! -> https://www.spigotmc.org/members/bers_.146126/
|
||||
#message-when-using-chest: "&7Pista: Usa &6/chestsort&7 para activar el orden automático de los cofres."
|
||||
#message-when-using-chest2: "&7Pista: Usa &6/chestsort&7 para desactivar el orden automático de los cofres."
|
||||
#message-sorting-disabled: "&7Orden automático de los cofres &cdesactivado&7."
|
||||
#message-sorting-enabled: "&7Orden automático de los cofres &aactivado&7."
|
||||
#message-error-players-only: "&cError: Este comando solo puede ser ejecutado por jugadores."
|
||||
|
||||
#########################
|
||||
##### Done! #####
|
||||
#########################
|
||||
|
||||
# please do not change the following line manually!
|
||||
config-version: 6
|
@ -1,20 +1,20 @@
|
||||
main: de.jeffclan.JeffChestSort.JeffChestSortPlugin
|
||||
name: ChestSort
|
||||
version: 3.4
|
||||
api-version: 1.13
|
||||
description: Allows automatic chest sorting
|
||||
author: mfnalex
|
||||
website: https://www.spigotmc.org/resources/1-13-chestsort.59773/
|
||||
prefix: ChestSort
|
||||
database: false
|
||||
loadbefore:
|
||||
- InvUnload
|
||||
commands:
|
||||
chestsort:
|
||||
description: Toggle automatic chest sorting
|
||||
usage: /<command>
|
||||
aliases: sort
|
||||
permission: chestsort.use
|
||||
permissions:
|
||||
chestsort.use:
|
||||
description: Allows usage of automatic chest sorting
|
||||
main: de.jeffclan.JeffChestSort.JeffChestSortPlugin
|
||||
name: ChestSort
|
||||
version: 3.4
|
||||
api-version: 1.13
|
||||
description: Allows automatic chest sorting
|
||||
author: mfnalex
|
||||
website: https://www.spigotmc.org/resources/1-13-chestsort.59773/
|
||||
prefix: ChestSort
|
||||
database: false
|
||||
loadbefore:
|
||||
- InvUnload
|
||||
commands:
|
||||
chestsort:
|
||||
description: Toggle automatic chest sorting
|
||||
usage: /<command>
|
||||
aliases: sort
|
||||
permission: chestsort.use
|
||||
permissions:
|
||||
chestsort.use:
|
||||
description: Allows usage of automatic chest sorting
|
60
pom.xml
60
pom.xml
@ -1,60 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>de.jeffclan</groupId>
|
||||
<artifactId>JeffChestSort</artifactId>
|
||||
<version>3.4</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>JeffChestSort</name>
|
||||
<url>https://www.spigotmc.org/resources/1-11-1-13-chestsort-api.59773/</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<configuration>
|
||||
<finalName>ChestSort</finalName>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>bungeecord-repo</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.13.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -1,60 +1,60 @@
|
||||
package de.jeffclan.JeffChestSort;
|
||||
|
||||
public class JeffChestSortCategory {
|
||||
|
||||
// Represents a sorting category
|
||||
// Includes an array of strings called typeMatches
|
||||
// A typeMatch is like a regular expression, but it only supports * as
|
||||
// placeholders
|
||||
// e.g. "DIRT" will match the typeMatch "dirt"
|
||||
// "COARSE_DIRT" will not match the typeMatch "dirt"
|
||||
// "COARSE_DIRT" will match the typeMatch "*dirt"
|
||||
|
||||
String name;
|
||||
String[] typeMatches;
|
||||
|
||||
JeffChestSortCategory(String name, String[] typeMatches) {
|
||||
this.name = name;
|
||||
this.typeMatches = typeMatches;
|
||||
}
|
||||
|
||||
boolean matches(String itemname) {
|
||||
|
||||
boolean asteriskBefore = false;
|
||||
boolean asteriskAfter = false;
|
||||
|
||||
for (String typeMatch : typeMatches) {
|
||||
|
||||
if (typeMatch.startsWith("*")) {
|
||||
asteriskBefore = true;
|
||||
typeMatch = typeMatch.substring(1);
|
||||
}
|
||||
if (typeMatch.endsWith("*")) {
|
||||
asteriskAfter = true;
|
||||
typeMatch = typeMatch.substring(0, typeMatch.length() - 1);
|
||||
}
|
||||
|
||||
if (asteriskBefore == false && asteriskAfter == false) {
|
||||
if (itemname.equalsIgnoreCase(typeMatch)) {
|
||||
|
||||
return true;
|
||||
}
|
||||
} else if (asteriskBefore == true && asteriskAfter == true) {
|
||||
if (itemname.contains(typeMatch)) {
|
||||
return true;
|
||||
}
|
||||
} else if (asteriskBefore == true && asteriskAfter == false) {
|
||||
if (itemname.endsWith(typeMatch)) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (itemname.startsWith(typeMatch)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
package de.jeffclan.JeffChestSort;
|
||||
|
||||
public class JeffChestSortCategory {
|
||||
|
||||
// Represents a sorting category
|
||||
// Includes an array of strings called typeMatches
|
||||
// A typeMatch is like a regular expression, but it only supports * as
|
||||
// placeholders
|
||||
// e.g. "DIRT" will match the typeMatch "dirt"
|
||||
// "COARSE_DIRT" will not match the typeMatch "dirt"
|
||||
// "COARSE_DIRT" will match the typeMatch "*dirt"
|
||||
|
||||
String name;
|
||||
String[] typeMatches;
|
||||
|
||||
JeffChestSortCategory(String name, String[] typeMatches) {
|
||||
this.name = name;
|
||||
this.typeMatches = typeMatches;
|
||||
}
|
||||
|
||||
boolean matches(String itemname) {
|
||||
|
||||
boolean asteriskBefore = false;
|
||||
boolean asteriskAfter = false;
|
||||
|
||||
for (String typeMatch : typeMatches) {
|
||||
|
||||
if (typeMatch.startsWith("*")) {
|
||||
asteriskBefore = true;
|
||||
typeMatch = typeMatch.substring(1);
|
||||
}
|
||||
if (typeMatch.endsWith("*")) {
|
||||
asteriskAfter = true;
|
||||
typeMatch = typeMatch.substring(0, typeMatch.length() - 1);
|
||||
}
|
||||
|
||||
if (asteriskBefore == false && asteriskAfter == false) {
|
||||
if (itemname.equalsIgnoreCase(typeMatch)) {
|
||||
|
||||
return true;
|
||||
}
|
||||
} else if (asteriskBefore == true && asteriskAfter == true) {
|
||||
if (itemname.contains(typeMatch)) {
|
||||
return true;
|
||||
}
|
||||
} else if (asteriskBefore == true && asteriskAfter == false) {
|
||||
if (itemname.endsWith(typeMatch)) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (itemname.startsWith(typeMatch)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -1,48 +1,48 @@
|
||||
package de.jeffclan.JeffChestSort;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class JeffChestSortCommandExecutor implements CommandExecutor {
|
||||
|
||||
JeffChestSortPlugin plugin;
|
||||
|
||||
JeffChestSortCommandExecutor(JeffChestSortPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command arg1, String arg2, String[] arg3) {
|
||||
|
||||
if (arg1.getName().equalsIgnoreCase("chestsort")) {
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(plugin.messages.MSG_PLAYERSONLY);
|
||||
return true;
|
||||
}
|
||||
|
||||
Player p = (Player) sender;
|
||||
|
||||
// fix for Spigot's stupid /reload function
|
||||
plugin.listener.registerPlayerIfNeeded(p);
|
||||
|
||||
JeffChestSortPlayerSetting setting = plugin.PerPlayerSettings.get(p.getUniqueId().toString());
|
||||
setting.sortingEnabled = !setting.sortingEnabled;
|
||||
setting.hasSeenMessage=true;
|
||||
|
||||
if (setting.sortingEnabled) {
|
||||
p.sendMessage(plugin.messages.MSG_ACTIVATED);
|
||||
} else {
|
||||
p.sendMessage(plugin.messages.MSG_DEACTIVATED);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
package de.jeffclan.JeffChestSort;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class JeffChestSortCommandExecutor implements CommandExecutor {
|
||||
|
||||
JeffChestSortPlugin plugin;
|
||||
|
||||
JeffChestSortCommandExecutor(JeffChestSortPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command arg1, String arg2, String[] arg3) {
|
||||
|
||||
if (arg1.getName().equalsIgnoreCase("chestsort")) {
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(plugin.messages.MSG_PLAYERSONLY);
|
||||
return true;
|
||||
}
|
||||
|
||||
Player p = (Player) sender;
|
||||
|
||||
// fix for Spigot's stupid /reload function
|
||||
plugin.listener.registerPlayerIfNeeded(p);
|
||||
|
||||
JeffChestSortPlayerSetting setting = plugin.PerPlayerSettings.get(p.getUniqueId().toString());
|
||||
setting.sortingEnabled = !setting.sortingEnabled;
|
||||
setting.hasSeenMessage=true;
|
||||
|
||||
if (setting.sortingEnabled) {
|
||||
p.sendMessage(plugin.messages.MSG_ACTIVATED);
|
||||
} else {
|
||||
p.sendMessage(plugin.messages.MSG_DEACTIVATED);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -1,125 +1,125 @@
|
||||
package de.jeffclan.JeffChestSort;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.io.File;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.block.DoubleChest;
|
||||
import org.bukkit.block.ShulkerBox;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class JeffChestSortListener implements Listener {
|
||||
|
||||
JeffChestSortPlugin plugin;
|
||||
|
||||
JeffChestSortListener(JeffChestSortPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
|
||||
if (event.getPlayer().getName().equalsIgnoreCase("mfnalex")) {
|
||||
plugin.debug = true;
|
||||
}
|
||||
|
||||
if (event.getPlayer().isOp()) {
|
||||
plugin.updateChecker.sendUpdateMessage(event.getPlayer());
|
||||
}
|
||||
|
||||
registerPlayerIfNeeded(event.getPlayer());
|
||||
|
||||
|
||||
}
|
||||
|
||||
void registerPlayerIfNeeded(Player p) {
|
||||
UUID uniqueId = p.getUniqueId();
|
||||
if (!plugin.PerPlayerSettings.containsKey(uniqueId.toString())) {
|
||||
|
||||
File playerFile = new File(plugin.getDataFolder() + File.separator + "playerdata",
|
||||
p.getUniqueId().toString() + ".yml");
|
||||
YamlConfiguration playerConfig = YamlConfiguration.loadConfiguration(playerFile);
|
||||
|
||||
boolean activeForThisPlayer;
|
||||
|
||||
if (!playerFile.exists()) {
|
||||
activeForThisPlayer = plugin.getConfig().getBoolean("sorting-enabled-by-default");
|
||||
} else {
|
||||
activeForThisPlayer = playerConfig.getBoolean("sortingEnabled");
|
||||
}
|
||||
|
||||
JeffChestSortPlayerSetting newSettings = new JeffChestSortPlayerSetting(activeForThisPlayer);
|
||||
if (!plugin.getConfig().getBoolean("show-message-again-after-logout")) {
|
||||
newSettings.hasSeenMessage = playerConfig.getBoolean("hasSeenMessage");
|
||||
}
|
||||
plugin.PerPlayerSettings.put(uniqueId.toString(), newSettings);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
plugin.unregisterPlayer(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClose(InventoryCloseEvent event) {
|
||||
|
||||
if (!(event.getPlayer() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player p = (Player) event.getPlayer();
|
||||
|
||||
if (!p.hasPermission("chestsort.use")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(plugin.disabledWorlds.contains(p.getWorld().getName().toLowerCase())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't sort automatically when player is spectator or in adventure mode
|
||||
if (p.getGameMode() == GameMode.SPECTATOR || p.getGameMode() == GameMode.ADVENTURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Fixes exception when using /reload
|
||||
registerPlayerIfNeeded(p);
|
||||
|
||||
JeffChestSortPlayerSetting setting = plugin.PerPlayerSettings.get(p.getUniqueId().toString());
|
||||
|
||||
if (!(event.getInventory().getHolder() instanceof Chest)
|
||||
&& !(event.getInventory().getHolder() instanceof DoubleChest)
|
||||
&& !(event.getInventory().getHolder() instanceof ShulkerBox)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!plugin.sortingEnabled(p)) {
|
||||
if (!setting.hasSeenMessage) {
|
||||
setting.hasSeenMessage = true;
|
||||
if (plugin.getConfig().getBoolean("show-message-when-using-chest")) {
|
||||
p.sendMessage(plugin.messages.MSG_COMMANDMESSAGE);
|
||||
}
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
if (!setting.hasSeenMessage) {
|
||||
setting.hasSeenMessage = true;
|
||||
if (plugin.getConfig().getBoolean("show-message-when-using-chest-and-sorting-is-enabled")) {
|
||||
p.sendMessage(plugin.messages.MSG_COMMANDMESSAGE2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
plugin.organizer.sortInventory(event.getInventory());
|
||||
|
||||
}
|
||||
}
|
||||
package de.jeffclan.JeffChestSort;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.io.File;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.block.DoubleChest;
|
||||
import org.bukkit.block.ShulkerBox;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class JeffChestSortListener implements Listener {
|
||||
|
||||
JeffChestSortPlugin plugin;
|
||||
|
||||
JeffChestSortListener(JeffChestSortPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
|
||||
if (event.getPlayer().getName().equalsIgnoreCase("mfnalex")) {
|
||||
plugin.debug = true;
|
||||
}
|
||||
|
||||
if (event.getPlayer().isOp()) {
|
||||
plugin.updateChecker.sendUpdateMessage(event.getPlayer());
|
||||
}
|
||||
|
||||
registerPlayerIfNeeded(event.getPlayer());
|
||||
|
||||
|
||||
}
|
||||
|
||||
void registerPlayerIfNeeded(Player p) {
|
||||
UUID uniqueId = p.getUniqueId();
|
||||
if (!plugin.PerPlayerSettings.containsKey(uniqueId.toString())) {
|
||||
|
||||
File playerFile = new File(plugin.getDataFolder() + File.separator + "playerdata",
|
||||
p.getUniqueId().toString() + ".yml");
|
||||
YamlConfiguration playerConfig = YamlConfiguration.loadConfiguration(playerFile);
|
||||
|
||||
boolean activeForThisPlayer;
|
||||
|
||||
if (!playerFile.exists()) {
|
||||
activeForThisPlayer = plugin.getConfig().getBoolean("sorting-enabled-by-default");
|
||||
} else {
|
||||
activeForThisPlayer = playerConfig.getBoolean("sortingEnabled");
|
||||
}
|
||||
|
||||
JeffChestSortPlayerSetting newSettings = new JeffChestSortPlayerSetting(activeForThisPlayer);
|
||||
if (!plugin.getConfig().getBoolean("show-message-again-after-logout")) {
|
||||
newSettings.hasSeenMessage = playerConfig.getBoolean("hasSeenMessage");
|
||||
}
|
||||
plugin.PerPlayerSettings.put(uniqueId.toString(), newSettings);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
plugin.unregisterPlayer(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClose(InventoryCloseEvent event) {
|
||||
|
||||
if (!(event.getPlayer() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player p = (Player) event.getPlayer();
|
||||
|
||||
if (!p.hasPermission("chestsort.use")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(plugin.disabledWorlds.contains(p.getWorld().getName().toLowerCase())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't sort automatically when player is spectator or in adventure mode
|
||||
if (p.getGameMode() == GameMode.SPECTATOR || p.getGameMode() == GameMode.ADVENTURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Fixes exception when using /reload
|
||||
registerPlayerIfNeeded(p);
|
||||
|
||||
JeffChestSortPlayerSetting setting = plugin.PerPlayerSettings.get(p.getUniqueId().toString());
|
||||
|
||||
if (!(event.getInventory().getHolder() instanceof Chest)
|
||||
&& !(event.getInventory().getHolder() instanceof DoubleChest)
|
||||
&& !(event.getInventory().getHolder() instanceof ShulkerBox)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!plugin.sortingEnabled(p)) {
|
||||
if (!setting.hasSeenMessage) {
|
||||
setting.hasSeenMessage = true;
|
||||
if (plugin.getConfig().getBoolean("show-message-when-using-chest")) {
|
||||
p.sendMessage(plugin.messages.MSG_COMMANDMESSAGE);
|
||||
}
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
if (!setting.hasSeenMessage) {
|
||||
setting.hasSeenMessage = true;
|
||||
if (plugin.getConfig().getBoolean("show-message-when-using-chest-and-sorting-is-enabled")) {
|
||||
p.sendMessage(plugin.messages.MSG_COMMANDMESSAGE2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
plugin.organizer.sortInventory(event.getInventory());
|
||||
|
||||
}
|
||||
}
|
@ -1,30 +1,30 @@
|
||||
package de.jeffclan.JeffChestSort;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class JeffChestSortMessages {
|
||||
|
||||
JeffChestSortPlugin plugin;
|
||||
|
||||
final String MSG_ACTIVATED, MSG_DEACTIVATED, MSG_COMMANDMESSAGE, MSG_COMMANDMESSAGE2, MSG_PLAYERSONLY;
|
||||
|
||||
JeffChestSortMessages(JeffChestSortPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
MSG_ACTIVATED = ChatColor.translateAlternateColorCodes('&', plugin.getConfig()
|
||||
.getString("message-sorting-enabled", "&7Automatic chest sorting has been &aenabled&7.&r"));
|
||||
|
||||
MSG_DEACTIVATED = ChatColor.translateAlternateColorCodes('&', plugin.getConfig()
|
||||
.getString("message-sorting-disabled", "&7Automatic chest sorting has been &cdisabled&7.&r"));
|
||||
|
||||
MSG_COMMANDMESSAGE = ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString(
|
||||
"message-when-using-chest", "&7Hint: Type &6/chestsort&7 to enable automatic chest sorting."));
|
||||
|
||||
MSG_COMMANDMESSAGE2 = ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString(
|
||||
"message-when-using-chest2", "&7Hint: Type &6/chestsort&7 to disable automatic chest sorting."));
|
||||
|
||||
MSG_PLAYERSONLY = ChatColor.translateAlternateColorCodes('&', plugin.getConfig()
|
||||
.getString("message-error-players-only", "&cError: This command can only be run by players.&r"));
|
||||
}
|
||||
|
||||
}
|
||||
package de.jeffclan.JeffChestSort;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class JeffChestSortMessages {
|
||||
|
||||
JeffChestSortPlugin plugin;
|
||||
|
||||
final String MSG_ACTIVATED, MSG_DEACTIVATED, MSG_COMMANDMESSAGE, MSG_COMMANDMESSAGE2, MSG_PLAYERSONLY;
|
||||
|
||||
JeffChestSortMessages(JeffChestSortPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
MSG_ACTIVATED = ChatColor.translateAlternateColorCodes('&', plugin.getConfig()
|
||||
.getString("message-sorting-enabled", "&7Automatic chest sorting has been &aenabled&7.&r"));
|
||||
|
||||
MSG_DEACTIVATED = ChatColor.translateAlternateColorCodes('&', plugin.getConfig()
|
||||
.getString("message-sorting-disabled", "&7Automatic chest sorting has been &cdisabled&7.&r"));
|
||||
|
||||
MSG_COMMANDMESSAGE = ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString(
|
||||
"message-when-using-chest", "&7Hint: Type &6/chestsort&7 to enable automatic chest sorting."));
|
||||
|
||||
MSG_COMMANDMESSAGE2 = ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString(
|
||||
"message-when-using-chest2", "&7Hint: Type &6/chestsort&7 to disable automatic chest sorting."));
|
||||
|
||||
MSG_PLAYERSONLY = ChatColor.translateAlternateColorCodes('&', plugin.getConfig()
|
||||
.getString("message-error-players-only", "&cError: This command can only be run by players.&r"));
|
||||
}
|
||||
|
||||
}
|
@ -1,273 +1,273 @@
|
||||
package de.jeffclan.JeffChestSort;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class JeffChestSortOrganizer {
|
||||
|
||||
/*
|
||||
* DEPRECATED: THE FOLLOWING INFOS ARE OUTDATED
|
||||
* I HAVE REPLACED THE UUID CONNECTION WITH AN ARRAY THAT REFERS TO THE ACTUAL ITEMSTACK
|
||||
* Thoughts before implementing:
|
||||
* We create a string from each item that can be sorted.
|
||||
* We will omit certain parts of the name and put them behind the main name for sorting reasons.
|
||||
* E.g. ACACIA_LOG -> LOG_ACACIA (so all LOGs are grouped)
|
||||
* Diamond, Gold, Iron, Stone, Wood does NOT have to be sorted, because they are already alphabetically in the right order
|
||||
* We identify the ItemStack by its hashcode, which is appended to the sorting string.
|
||||
*/
|
||||
|
||||
JeffChestSortPlugin plugin;
|
||||
|
||||
static final String[] colors = { "white", "orange", "magenta", "light_blue", "light_gray", "yellow", "lime", "pink", "gray",
|
||||
"cyan", "purple", "blue", "brown", "green", "red", "black" };
|
||||
static final String[] woodNames = { "acacia", "birch", "jungle", "oak", "spruce", "dark_oak" };
|
||||
|
||||
ArrayList<JeffChestSortCategory> categories = new ArrayList<JeffChestSortCategory>();
|
||||
|
||||
JeffChestSortOrganizer(JeffChestSortPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
|
||||
// Load Categories
|
||||
File categoriesFolder = new File(plugin.getDataFolder().getAbsolutePath() + File.separator + "categories" + File.separator);
|
||||
File[] listOfCategoryFiles = categoriesFolder.listFiles();
|
||||
|
||||
for (File file : listOfCategoryFiles) {
|
||||
if (file.isFile()) {
|
||||
String categoryName = file.getName().replaceFirst(".txt", "");
|
||||
|
||||
try {
|
||||
categories.add(new JeffChestSortCategory(categoryName,getArrayFromCategoryFile(file)));
|
||||
if(plugin.verbose) {
|
||||
plugin.getLogger().info("Loaded category file "+file.getName());
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
plugin.getLogger().warning("Could not load category file: "+file.getName());
|
||||
//e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
String[] getArrayFromCategoryFile(File file) throws FileNotFoundException {
|
||||
Scanner sc = new Scanner(file);
|
||||
List<String> lines = new ArrayList<String>();
|
||||
while (sc.hasNextLine()) {
|
||||
//if(!sc.nextLine().startsWith("#")) {
|
||||
lines.add(sc.nextLine());
|
||||
//}
|
||||
}
|
||||
|
||||
String[] arr = lines.toArray(new String[0]);
|
||||
sc.close();
|
||||
return arr;
|
||||
}
|
||||
|
||||
|
||||
String[] getTypeAndColor(String typeName) {
|
||||
|
||||
// [0] = TypeName
|
||||
// [1] = Color
|
||||
|
||||
String myColor = "<none>";
|
||||
typeName = typeName.toLowerCase();
|
||||
|
||||
for (String color : colors) {
|
||||
if (typeName.startsWith(color)) {
|
||||
typeName = typeName.replaceFirst(color + "_", "");
|
||||
myColor = color;
|
||||
}
|
||||
}
|
||||
|
||||
for(String woodName : woodNames) {
|
||||
if(typeName.equals(woodName+"_wood")) {
|
||||
typeName = "log_wood";
|
||||
myColor = woodName;
|
||||
}
|
||||
else if(typeName.startsWith(woodName)) {
|
||||
typeName = typeName.replaceFirst(woodName+"_", "");
|
||||
myColor = woodName;
|
||||
}
|
||||
else if(typeName.equals("stripped_"+woodName+"_log")) {
|
||||
//typeName = typeName.replaceFirst("stripped_"+woodName+"_", "stripped_");
|
||||
typeName = "log_stripped";
|
||||
myColor = woodName;
|
||||
} else if(typeName.equals("stripped_"+woodName+"_wood")) {
|
||||
typeName = "log_wood_stripped";
|
||||
myColor = woodName;
|
||||
}
|
||||
}
|
||||
|
||||
// Egg has to be put in front to group spawn eggs
|
||||
// E.g. cow_spawn_egg -> egg_cow_spawn
|
||||
if(typeName.endsWith("_egg")) {
|
||||
typeName = typeName.replaceFirst("_egg", "");
|
||||
typeName = "egg_" + typeName;
|
||||
}
|
||||
|
||||
// polished_andesite -> andesite_polished
|
||||
if(typeName.startsWith("polished_")) {
|
||||
typeName = typeName.replaceFirst("polished_", "");
|
||||
typeName = typeName + "_polished";
|
||||
}
|
||||
|
||||
if(typeName.equalsIgnoreCase("wet_sponge")) {
|
||||
typeName = "sponge_wet";
|
||||
}
|
||||
|
||||
|
||||
if(typeName.equalsIgnoreCase("carved_pumpkin")) {
|
||||
typeName = "pumpkin_carved";
|
||||
}
|
||||
|
||||
// Sort armor: helmet, chestplate, leggings, boots
|
||||
if(typeName.endsWith("helmet")) {
|
||||
typeName = typeName.replaceFirst("helmet", "1_helmet");
|
||||
} else if(typeName.endsWith("chestplate")) {
|
||||
typeName = typeName.replaceFirst("chestplate", "2_chestplate");
|
||||
} else if(typeName.endsWith("leggings")) {
|
||||
typeName = typeName.replaceFirst("leggings", "3_leggings");
|
||||
} else if(typeName.endsWith("boots")) {
|
||||
typeName = typeName.replaceFirst("boots", "4_boots");
|
||||
}
|
||||
|
||||
// Group horse armor
|
||||
if(typeName.endsWith("horse_armor")) {
|
||||
typeName = typeName.replaceFirst("_horse_armor", "");
|
||||
typeName = "horse_armor_" + typeName;
|
||||
}
|
||||
|
||||
String[] typeAndColor = new String[2];
|
||||
typeAndColor[0] = typeName;
|
||||
typeAndColor[1] = myColor;
|
||||
|
||||
return typeAndColor;
|
||||
}
|
||||
|
||||
String getCategory(String typeName) {
|
||||
|
||||
typeName = typeName.toLowerCase();
|
||||
|
||||
for (JeffChestSortCategory cat : categories) {
|
||||
if (cat.matches(typeName)) {
|
||||
return cat.name;
|
||||
}
|
||||
}
|
||||
|
||||
return "<none>";
|
||||
}
|
||||
|
||||
String getSortableString(ItemStack item) {
|
||||
char blocksFirst;
|
||||
char itemsFirst;
|
||||
if (item.getType().isBlock()) {
|
||||
blocksFirst = '!';
|
||||
itemsFirst = '#';
|
||||
} else {
|
||||
blocksFirst = '#';
|
||||
itemsFirst = '!';
|
||||
}
|
||||
|
||||
String[] typeAndColor = getTypeAndColor(item.getType().name());
|
||||
String typeName = typeAndColor[0];
|
||||
String color = typeAndColor[1];
|
||||
String category = getCategory(item.getType().name());
|
||||
|
||||
String hashCode = String.valueOf(getBetterHash(item));
|
||||
|
||||
String sortableString = plugin.sortingMethod.replaceAll("\\{itemsFirst\\}", String.valueOf(itemsFirst));
|
||||
sortableString = sortableString.replaceAll("\\{blocksFirst\\}", String.valueOf(blocksFirst));
|
||||
sortableString = sortableString.replaceAll("\\{name\\}", typeName);
|
||||
sortableString = sortableString.replaceAll("\\{color\\}", color);
|
||||
sortableString = sortableString.replaceAll("\\{category\\}", category);
|
||||
sortableString = sortableString + "," + hashCode;
|
||||
|
||||
return sortableString;
|
||||
|
||||
}
|
||||
|
||||
void sortInventory(Inventory inv) {
|
||||
sortInventory(inv,0,inv.getSize()-1);
|
||||
}
|
||||
|
||||
void sortInventory(Inventory inv,int startSlot, int endSlot) {
|
||||
|
||||
// This has been optimized as of ChestSort 3.2.
|
||||
// The hashCode is just kept for legacy reasons, it is actually not needed.
|
||||
|
||||
if(plugin.debug) {
|
||||
System.out.println(" ");
|
||||
System.out.println(" ");
|
||||
}
|
||||
|
||||
|
||||
// We copy the complete inventory into an array
|
||||
ItemStack[] items = inv.getContents();
|
||||
|
||||
// Get rid of all stuff before startSlot and after endSlot
|
||||
for(int i = 0; i<startSlot;i++) {
|
||||
items[i] = null;
|
||||
}
|
||||
for(int i=endSlot+1;i<inv.getSize();i++) {
|
||||
items[i] = null;
|
||||
}
|
||||
|
||||
// Remove the stuff that we took from the original inventory
|
||||
for(int i = startSlot; i<=endSlot;i++) {
|
||||
inv.clear(i);
|
||||
}
|
||||
|
||||
// We don't want to have stacks of null
|
||||
ArrayList<ItemStack> nonNullItemsList = new ArrayList<ItemStack>();
|
||||
for(ItemStack item : items) {
|
||||
if(item!=null) {
|
||||
nonNullItemsList.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
// We don't need the copied inventory anymore
|
||||
items=null;
|
||||
|
||||
// We need the list as array
|
||||
ItemStack[] nonNullItems = nonNullItemsList.toArray(new ItemStack[nonNullItemsList.size()]);
|
||||
|
||||
// Sort the array with ItemStacks according to our sortable String
|
||||
Arrays.sort(nonNullItems,new Comparator<ItemStack>(){
|
||||
public int compare(ItemStack s1,ItemStack s2){
|
||||
return(getSortableString(s1).compareTo(getSortableString(s2)));
|
||||
}});
|
||||
|
||||
// put everything back in a temporary inventory to combine ItemStacks even when using strict slot sorting
|
||||
// Thanks to SnackMix for this idea!
|
||||
Inventory tempInventory = Bukkit.createInventory(null, 63);
|
||||
|
||||
for(ItemStack item : nonNullItems) {
|
||||
if(plugin.debug) System.out.println(getSortableString(item));
|
||||
tempInventory.addItem(item);
|
||||
}
|
||||
|
||||
int currentSlot = startSlot;
|
||||
for(ItemStack item : tempInventory.getContents()) {
|
||||
if(item==null) continue;
|
||||
inv.setItem(currentSlot, item);
|
||||
currentSlot++;
|
||||
}
|
||||
}
|
||||
|
||||
private static int getBetterHash(ItemStack item) {
|
||||
// I wanted to fix the skull problems here. Instead, I ended up not using the hashCode at all.
|
||||
// I still left this here because it is nice to see the hashcodes when debug is enabled
|
||||
return item.hashCode();
|
||||
}
|
||||
|
||||
}
|
||||
package de.jeffclan.JeffChestSort;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class JeffChestSortOrganizer {
|
||||
|
||||
/*
|
||||
* DEPRECATED: THE FOLLOWING INFOS ARE OUTDATED
|
||||
* I HAVE REPLACED THE UUID CONNECTION WITH AN ARRAY THAT REFERS TO THE ACTUAL ITEMSTACK
|
||||
* Thoughts before implementing:
|
||||
* We create a string from each item that can be sorted.
|
||||
* We will omit certain parts of the name and put them behind the main name for sorting reasons.
|
||||
* E.g. ACACIA_LOG -> LOG_ACACIA (so all LOGs are grouped)
|
||||
* Diamond, Gold, Iron, Stone, Wood does NOT have to be sorted, because they are already alphabetically in the right order
|
||||
* We identify the ItemStack by its hashcode, which is appended to the sorting string.
|
||||
*/
|
||||
|
||||
JeffChestSortPlugin plugin;
|
||||
|
||||
static final String[] colors = { "white", "orange", "magenta", "light_blue", "light_gray", "yellow", "lime", "pink", "gray",
|
||||
"cyan", "purple", "blue", "brown", "green", "red", "black" };
|
||||
static final String[] woodNames = { "acacia", "birch", "jungle", "oak", "spruce", "dark_oak" };
|
||||
|
||||
ArrayList<JeffChestSortCategory> categories = new ArrayList<JeffChestSortCategory>();
|
||||
|
||||
JeffChestSortOrganizer(JeffChestSortPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
|
||||
// Load Categories
|
||||
File categoriesFolder = new File(plugin.getDataFolder().getAbsolutePath() + File.separator + "categories" + File.separator);
|
||||
File[] listOfCategoryFiles = categoriesFolder.listFiles();
|
||||
|
||||
for (File file : listOfCategoryFiles) {
|
||||
if (file.isFile()) {
|
||||
String categoryName = file.getName().replaceFirst(".txt", "");
|
||||
|
||||
try {
|
||||
categories.add(new JeffChestSortCategory(categoryName,getArrayFromCategoryFile(file)));
|
||||
if(plugin.verbose) {
|
||||
plugin.getLogger().info("Loaded category file "+file.getName());
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
plugin.getLogger().warning("Could not load category file: "+file.getName());
|
||||
//e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
String[] getArrayFromCategoryFile(File file) throws FileNotFoundException {
|
||||
Scanner sc = new Scanner(file);
|
||||
List<String> lines = new ArrayList<String>();
|
||||
while (sc.hasNextLine()) {
|
||||
//if(!sc.nextLine().startsWith("#")) {
|
||||
lines.add(sc.nextLine());
|
||||
//}
|
||||
}
|
||||
|
||||
String[] arr = lines.toArray(new String[0]);
|
||||
sc.close();
|
||||
return arr;
|
||||
}
|
||||
|
||||
|
||||
String[] getTypeAndColor(String typeName) {
|
||||
|
||||
// [0] = TypeName
|
||||
// [1] = Color
|
||||
|
||||
String myColor = "<none>";
|
||||
typeName = typeName.toLowerCase();
|
||||
|
||||
for (String color : colors) {
|
||||
if (typeName.startsWith(color)) {
|
||||
typeName = typeName.replaceFirst(color + "_", "");
|
||||
myColor = color;
|
||||
}
|
||||
}
|
||||
|
||||
for(String woodName : woodNames) {
|
||||
if(typeName.equals(woodName+"_wood")) {
|
||||
typeName = "log_wood";
|
||||
myColor = woodName;
|
||||
}
|
||||
else if(typeName.startsWith(woodName)) {
|
||||
typeName = typeName.replaceFirst(woodName+"_", "");
|
||||
myColor = woodName;
|
||||
}
|
||||
else if(typeName.equals("stripped_"+woodName+"_log")) {
|
||||
//typeName = typeName.replaceFirst("stripped_"+woodName+"_", "stripped_");
|
||||
typeName = "log_stripped";
|
||||
myColor = woodName;
|
||||
} else if(typeName.equals("stripped_"+woodName+"_wood")) {
|
||||
typeName = "log_wood_stripped";
|
||||
myColor = woodName;
|
||||
}
|
||||
}
|
||||
|
||||
// Egg has to be put in front to group spawn eggs
|
||||
// E.g. cow_spawn_egg -> egg_cow_spawn
|
||||
if(typeName.endsWith("_egg")) {
|
||||
typeName = typeName.replaceFirst("_egg", "");
|
||||
typeName = "egg_" + typeName;
|
||||
}
|
||||
|
||||
// polished_andesite -> andesite_polished
|
||||
if(typeName.startsWith("polished_")) {
|
||||
typeName = typeName.replaceFirst("polished_", "");
|
||||
typeName = typeName + "_polished";
|
||||
}
|
||||
|
||||
if(typeName.equalsIgnoreCase("wet_sponge")) {
|
||||
typeName = "sponge_wet";
|
||||
}
|
||||
|
||||
|
||||
if(typeName.equalsIgnoreCase("carved_pumpkin")) {
|
||||
typeName = "pumpkin_carved";
|
||||
}
|
||||
|
||||
// Sort armor: helmet, chestplate, leggings, boots
|
||||
if(typeName.endsWith("helmet")) {
|
||||
typeName = typeName.replaceFirst("helmet", "1_helmet");
|
||||
} else if(typeName.endsWith("chestplate")) {
|
||||
typeName = typeName.replaceFirst("chestplate", "2_chestplate");
|
||||
} else if(typeName.endsWith("leggings")) {
|
||||
typeName = typeName.replaceFirst("leggings", "3_leggings");
|
||||
} else if(typeName.endsWith("boots")) {
|
||||
typeName = typeName.replaceFirst("boots", "4_boots");
|
||||
}
|
||||
|
||||
// Group horse armor
|
||||
if(typeName.endsWith("horse_armor")) {
|
||||
typeName = typeName.replaceFirst("_horse_armor", "");
|
||||
typeName = "horse_armor_" + typeName;
|
||||
}
|
||||
|
||||
String[] typeAndColor = new String[2];
|
||||
typeAndColor[0] = typeName;
|
||||
typeAndColor[1] = myColor;
|
||||
|
||||
return typeAndColor;
|
||||
}
|
||||
|
||||
String getCategory(String typeName) {
|
||||
|
||||
typeName = typeName.toLowerCase();
|
||||
|
||||
for (JeffChestSortCategory cat : categories) {
|
||||
if (cat.matches(typeName)) {
|
||||
return cat.name;
|
||||
}
|
||||
}
|
||||
|
||||
return "<none>";
|
||||
}
|
||||
|
||||
String getSortableString(ItemStack item) {
|
||||
char blocksFirst;
|
||||
char itemsFirst;
|
||||
if (item.getType().isBlock()) {
|
||||
blocksFirst = '!';
|
||||
itemsFirst = '#';
|
||||
} else {
|
||||
blocksFirst = '#';
|
||||
itemsFirst = '!';
|
||||
}
|
||||
|
||||
String[] typeAndColor = getTypeAndColor(item.getType().name());
|
||||
String typeName = typeAndColor[0];
|
||||
String color = typeAndColor[1];
|
||||
String category = getCategory(item.getType().name());
|
||||
|
||||
String hashCode = String.valueOf(getBetterHash(item));
|
||||
|
||||
String sortableString = plugin.sortingMethod.replaceAll("\\{itemsFirst\\}", String.valueOf(itemsFirst));
|
||||
sortableString = sortableString.replaceAll("\\{blocksFirst\\}", String.valueOf(blocksFirst));
|
||||
sortableString = sortableString.replaceAll("\\{name\\}", typeName);
|
||||
sortableString = sortableString.replaceAll("\\{color\\}", color);
|
||||
sortableString = sortableString.replaceAll("\\{category\\}", category);
|
||||
sortableString = sortableString + "," + hashCode;
|
||||
|
||||
return sortableString;
|
||||
|
||||
}
|
||||
|
||||
void sortInventory(Inventory inv) {
|
||||
sortInventory(inv,0,inv.getSize()-1);
|
||||
}
|
||||
|
||||
void sortInventory(Inventory inv,int startSlot, int endSlot) {
|
||||
|
||||
// This has been optimized as of ChestSort 3.2.
|
||||
// The hashCode is just kept for legacy reasons, it is actually not needed.
|
||||
|
||||
if(plugin.debug) {
|
||||
System.out.println(" ");
|
||||
System.out.println(" ");
|
||||
}
|
||||
|
||||
|
||||
// We copy the complete inventory into an array
|
||||
ItemStack[] items = inv.getContents();
|
||||
|
||||
// Get rid of all stuff before startSlot and after endSlot
|
||||
for(int i = 0; i<startSlot;i++) {
|
||||
items[i] = null;
|
||||
}
|
||||
for(int i=endSlot+1;i<inv.getSize();i++) {
|
||||
items[i] = null;
|
||||
}
|
||||
|
||||
// Remove the stuff that we took from the original inventory
|
||||
for(int i = startSlot; i<=endSlot;i++) {
|
||||
inv.clear(i);
|
||||
}
|
||||
|
||||
// We don't want to have stacks of null
|
||||
ArrayList<ItemStack> nonNullItemsList = new ArrayList<ItemStack>();
|
||||
for(ItemStack item : items) {
|
||||
if(item!=null) {
|
||||
nonNullItemsList.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
// We don't need the copied inventory anymore
|
||||
items=null;
|
||||
|
||||
// We need the list as array
|
||||
ItemStack[] nonNullItems = nonNullItemsList.toArray(new ItemStack[nonNullItemsList.size()]);
|
||||
|
||||
// Sort the array with ItemStacks according to our sortable String
|
||||
Arrays.sort(nonNullItems,new Comparator<ItemStack>(){
|
||||
public int compare(ItemStack s1,ItemStack s2){
|
||||
return(getSortableString(s1).compareTo(getSortableString(s2)));
|
||||
}});
|
||||
|
||||
// put everything back in a temporary inventory to combine ItemStacks even when using strict slot sorting
|
||||
// Thanks to SnackMix for this idea!
|
||||
Inventory tempInventory = Bukkit.createInventory(null, 63);
|
||||
|
||||
for(ItemStack item : nonNullItems) {
|
||||
if(plugin.debug) System.out.println(getSortableString(item));
|
||||
tempInventory.addItem(item);
|
||||
}
|
||||
|
||||
int currentSlot = startSlot;
|
||||
for(ItemStack item : tempInventory.getContents()) {
|
||||
if(item==null) continue;
|
||||
inv.setItem(currentSlot, item);
|
||||
currentSlot++;
|
||||
}
|
||||
}
|
||||
|
||||
private static int getBetterHash(ItemStack item) {
|
||||
// I wanted to fix the skull problems here. Instead, I ended up not using the hashCode at all.
|
||||
// I still left this here because it is nice to see the hashcodes when debug is enabled
|
||||
return item.hashCode();
|
||||
}
|
||||
|
||||
}
|
@ -1,15 +1,15 @@
|
||||
package de.jeffclan.JeffChestSort;
|
||||
|
||||
public class JeffChestSortPlayerSetting {
|
||||
|
||||
// Sorting enabled for this player?
|
||||
boolean sortingEnabled;
|
||||
|
||||
// Did we already show the message how to activate sorting?
|
||||
boolean hasSeenMessage = false;
|
||||
|
||||
JeffChestSortPlayerSetting(boolean sortingEnabled) {
|
||||
this.sortingEnabled = sortingEnabled;
|
||||
}
|
||||
|
||||
}
|
||||
package de.jeffclan.JeffChestSort;
|
||||
|
||||
public class JeffChestSortPlayerSetting {
|
||||
|
||||
// Sorting enabled for this player?
|
||||
boolean sortingEnabled;
|
||||
|
||||
// Did we already show the message how to activate sorting?
|
||||
boolean hasSeenMessage = false;
|
||||
|
||||
JeffChestSortPlayerSetting(boolean sortingEnabled) {
|
||||
this.sortingEnabled = sortingEnabled;
|
||||
}
|
||||
|
||||
}
|
@ -1,244 +1,244 @@
|
||||
package de.jeffclan.JeffChestSort;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import de.jeffclan.utils.Utils;
|
||||
|
||||
public class JeffChestSortPlugin extends JavaPlugin {
|
||||
|
||||
Map<String, JeffChestSortPlayerSetting> PerPlayerSettings = new HashMap<String, JeffChestSortPlayerSetting>();
|
||||
JeffChestSortMessages messages;
|
||||
JeffChestSortOrganizer organizer;
|
||||
JeffChestSortUpdateChecker updateChecker;
|
||||
JeffChestSortListener listener;
|
||||
String sortingMethod;
|
||||
ArrayList<String> disabledWorlds;
|
||||
int currentConfigVersion = 6;
|
||||
boolean usingMatchingConfig = true;
|
||||
boolean debug = false;
|
||||
boolean verbose = true;
|
||||
private long updateCheckInterval = 86400; // in seconds. We check on startup and every 24 hours (if you never restart your server)
|
||||
|
||||
public void sortInventory(Inventory inv) {
|
||||
this.organizer.sortInventory(inv);
|
||||
}
|
||||
|
||||
public void sortInventory(Inventory inv, int startSlot, int endSlot) {
|
||||
this.organizer.sortInventory(inv,startSlot,endSlot);
|
||||
}
|
||||
|
||||
void createConfig() {
|
||||
this.saveDefaultConfig();
|
||||
|
||||
// Config version prior to 5? Then it must have been generated by ChestSort 1.x
|
||||
if (getConfig().getInt("config-version", 0) < 5) {
|
||||
getLogger().warning("========================================================");
|
||||
getLogger().warning("You are using a config file that has been generated");
|
||||
getLogger().warning("prior to ChestSort version 2.0.0.");
|
||||
getLogger().warning("To allow everyone to use the new features, your config");
|
||||
getLogger().warning("has been renamed to config.old.yml and a new one has");
|
||||
getLogger().warning("been generated. Please examine the new config file to");
|
||||
getLogger().warning("see the new possibilities and adjust your settings.");
|
||||
getLogger().warning("========================================================");
|
||||
|
||||
File configFile = new File(getDataFolder().getAbsolutePath() + File.separator + "config.yml");
|
||||
File oldConfigFile = new File(getDataFolder().getAbsolutePath() + File.separator + "config.old.yml");
|
||||
if (oldConfigFile.getAbsoluteFile().exists()) {
|
||||
oldConfigFile.getAbsoluteFile().delete();
|
||||
}
|
||||
configFile.getAbsoluteFile().renameTo(oldConfigFile.getAbsoluteFile());
|
||||
saveDefaultConfig();
|
||||
try {
|
||||
getConfig().load(configFile.getAbsoluteFile());
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
getLogger().warning("Could not load freshly generated config file!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else if (getConfig().getInt("config-version", 0) != currentConfigVersion) {
|
||||
getLogger().warning("========================================================");
|
||||
getLogger().warning("YOU ARE USING AN OLD CONFIG FILE!");
|
||||
getLogger().warning("This is not a problem, as ChestSort will just use the");
|
||||
getLogger().warning("default settings for unset values. However, if you want");
|
||||
getLogger().warning("to configure the new options, please go to");
|
||||
getLogger().warning("https://www.spigotmc.org/resources/1-13-chestsort.59773/");
|
||||
getLogger().warning("and replace your config.yml with the new one. You can");
|
||||
getLogger().warning("then insert your old changes into the new file.");
|
||||
getLogger().warning("========================================================");
|
||||
usingMatchingConfig = false;
|
||||
}
|
||||
|
||||
File playerDataFolder = new File(getDataFolder().getPath() + File.separator + "playerdata");
|
||||
if (!playerDataFolder.getAbsoluteFile().exists()) {
|
||||
playerDataFolder.mkdir();
|
||||
}
|
||||
File categoriesFolder = new File(getDataFolder().getPath() + File.separator + "categories");
|
||||
if (!categoriesFolder.getAbsoluteFile().exists()) {
|
||||
categoriesFolder.mkdir();
|
||||
}
|
||||
|
||||
getConfig().addDefault("sorting-enabled-by-default", false);
|
||||
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", "{category},{itemsFirst},{name},{color}");
|
||||
getConfig().addDefault("check-for-updates", "true");
|
||||
getConfig().addDefault("auto-generate-category-files", true);
|
||||
getConfig().addDefault("verbose", true);
|
||||
|
||||
disabledWorlds = (ArrayList<String>) getConfig().getStringList("disabled-worlds");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
for (Player p : getServer().getOnlinePlayers()) {
|
||||
unregisterPlayer(p);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
createConfig();
|
||||
saveDefaultCategories();
|
||||
verbose = getConfig().getBoolean("verbose");
|
||||
messages = new JeffChestSortMessages(this);
|
||||
organizer = new JeffChestSortOrganizer(this);
|
||||
updateChecker = new JeffChestSortUpdateChecker(this);
|
||||
listener = new JeffChestSortListener(this);
|
||||
sortingMethod = getConfig().getString("sorting-method");
|
||||
getServer().getPluginManager().registerEvents(listener, this);
|
||||
JeffChestSortCommandExecutor commandExecutor = new JeffChestSortCommandExecutor(this);
|
||||
this.getCommand("chestsort").setExecutor(commandExecutor);
|
||||
|
||||
if (verbose) {
|
||||
getLogger().info("Current sorting method: " + sortingMethod);
|
||||
getLogger().info("Sorting enabled by default: " + getConfig().getBoolean("sorting-enabled-by-default"));
|
||||
getLogger().info("Auto generate category files: " + getConfig().getBoolean("auto-generate-category-files"));
|
||||
getLogger().info("Check for updates: " + getConfig().getString("check-for-updates"));
|
||||
}
|
||||
if (getConfig().getString("check-for-updates", "true").equalsIgnoreCase("true")) {
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
|
||||
public void run() {
|
||||
updateChecker.checkForUpdate();
|
||||
}
|
||||
}, 0L, updateCheckInterval * 20);
|
||||
} else if (getConfig().getString("check-for-updates", "true").equalsIgnoreCase("on-startup")) {
|
||||
updateChecker.checkForUpdate();
|
||||
}
|
||||
|
||||
Metrics metrics = new Metrics(this);
|
||||
|
||||
metrics.addCustomChart(new Metrics.SimplePie("sorting_method", () -> sortingMethod));
|
||||
metrics.addCustomChart(new Metrics.SimplePie("config_version",
|
||||
() -> Integer.toString(getConfig().getInt("config-version", 0))));
|
||||
metrics.addCustomChart(
|
||||
new Metrics.SimplePie("check_for_updates", () -> getConfig().getString("check-for-updates", "true")));
|
||||
metrics.addCustomChart(new Metrics.SimplePie("show_message_when_using_chest",
|
||||
() -> Boolean.toString(getConfig().getBoolean("show-message-when-using-chest"))));
|
||||
metrics.addCustomChart(new Metrics.SimplePie("show_message_when_using_chest_and_sorting_is_enabl",
|
||||
() -> Boolean.toString(getConfig().getBoolean("show-message-when-using-chest-and-sorting-is-enabled"))));
|
||||
metrics.addCustomChart(new Metrics.SimplePie("show_message_again_after_logout",
|
||||
() -> Boolean.toString(getConfig().getBoolean("show-message-again-after-logout"))));
|
||||
metrics.addCustomChart(new Metrics.SimplePie("sorting_enabled_by_default",
|
||||
() -> Boolean.toString(getConfig().getBoolean("sorting-enabled-by-default"))));
|
||||
metrics.addCustomChart(
|
||||
new Metrics.SimplePie("using_matching_config_version", () -> Boolean.toString(usingMatchingConfig)));
|
||||
|
||||
}
|
||||
|
||||
private void saveDefaultCategories() {
|
||||
String[] defaultCategories = { "900-valuables", "910-tools", "920-combat", "930-brewing", "940-food",
|
||||
"950-redstone", "960-wood", "970-stone", "980-plants", "981-corals" };
|
||||
|
||||
if (getConfig().getBoolean("auto-generate-category-files", true) != true) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
for (String category : defaultCategories) {
|
||||
|
||||
FileOutputStream fopDefault = null;
|
||||
File fileDefault;
|
||||
|
||||
try {
|
||||
InputStream in = getClass()
|
||||
.getResourceAsStream("/categories/" + category + ".default.txt");
|
||||
|
||||
fileDefault = new File(getDataFolder().getAbsolutePath() + File.separator + "categories"
|
||||
+ File.separator + category + ".txt");
|
||||
fopDefault = new FileOutputStream(fileDefault);
|
||||
|
||||
// if file doesnt exists, then create it
|
||||
// if (!fileDefault.getAbsoluteFile().exists()) {
|
||||
fileDefault.createNewFile();
|
||||
// }
|
||||
|
||||
// get the content in bytes
|
||||
byte[] contentInBytes = Utils.getBytes(in);
|
||||
|
||||
fopDefault.write(contentInBytes);
|
||||
fopDefault.flush();
|
||||
fopDefault.close();
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (fopDefault != null) {
|
||||
fopDefault.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean sortingEnabled(Player p) {
|
||||
|
||||
// The following is for all the lazy server admins who use /reload instead of properly restarting their
|
||||
// server ;) I am sometimes getting stacktraces although it is clearly stated that /reload is NOT
|
||||
// supported. So, here is a quick fix
|
||||
if(PerPlayerSettings == null) {
|
||||
PerPlayerSettings = new HashMap<String, JeffChestSortPlayerSetting>();
|
||||
}
|
||||
listener.registerPlayerIfNeeded(p);
|
||||
// End of quick fix
|
||||
|
||||
return PerPlayerSettings.get(p.getUniqueId().toString()).sortingEnabled;
|
||||
}
|
||||
|
||||
void unregisterPlayer(Player p) {
|
||||
UUID uniqueId = p.getUniqueId();
|
||||
if (PerPlayerSettings.containsKey(uniqueId.toString())) {
|
||||
JeffChestSortPlayerSetting setting = PerPlayerSettings.get(p.getUniqueId().toString());
|
||||
File playerFile = new File(getDataFolder() + File.separator + "playerdata",
|
||||
p.getUniqueId().toString() + ".yml");
|
||||
YamlConfiguration playerConfig = YamlConfiguration.loadConfiguration(playerFile);
|
||||
playerConfig.set("sortingEnabled", setting.sortingEnabled);
|
||||
playerConfig.set("hasSeenMessage", setting.hasSeenMessage);
|
||||
try {
|
||||
playerConfig.save(playerFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
PerPlayerSettings.remove(uniqueId.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
package de.jeffclan.JeffChestSort;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import de.jeffclan.utils.Utils;
|
||||
|
||||
public class JeffChestSortPlugin extends JavaPlugin {
|
||||
|
||||
Map<String, JeffChestSortPlayerSetting> PerPlayerSettings = new HashMap<String, JeffChestSortPlayerSetting>();
|
||||
JeffChestSortMessages messages;
|
||||
JeffChestSortOrganizer organizer;
|
||||
JeffChestSortUpdateChecker updateChecker;
|
||||
JeffChestSortListener listener;
|
||||
String sortingMethod;
|
||||
ArrayList<String> disabledWorlds;
|
||||
int currentConfigVersion = 6;
|
||||
boolean usingMatchingConfig = true;
|
||||
boolean debug = false;
|
||||
boolean verbose = true;
|
||||
private long updateCheckInterval = 86400; // in seconds. We check on startup and every 24 hours (if you never restart your server)
|
||||
|
||||
public void sortInventory(Inventory inv) {
|
||||
this.organizer.sortInventory(inv);
|
||||
}
|
||||
|
||||
public void sortInventory(Inventory inv, int startSlot, int endSlot) {
|
||||
this.organizer.sortInventory(inv,startSlot,endSlot);
|
||||
}
|
||||
|
||||
void createConfig() {
|
||||
this.saveDefaultConfig();
|
||||
|
||||
// Config version prior to 5? Then it must have been generated by ChestSort 1.x
|
||||
if (getConfig().getInt("config-version", 0) < 5) {
|
||||
getLogger().warning("========================================================");
|
||||
getLogger().warning("You are using a config file that has been generated");
|
||||
getLogger().warning("prior to ChestSort version 2.0.0.");
|
||||
getLogger().warning("To allow everyone to use the new features, your config");
|
||||
getLogger().warning("has been renamed to config.old.yml and a new one has");
|
||||
getLogger().warning("been generated. Please examine the new config file to");
|
||||
getLogger().warning("see the new possibilities and adjust your settings.");
|
||||
getLogger().warning("========================================================");
|
||||
|
||||
File configFile = new File(getDataFolder().getAbsolutePath() + File.separator + "config.yml");
|
||||
File oldConfigFile = new File(getDataFolder().getAbsolutePath() + File.separator + "config.old.yml");
|
||||
if (oldConfigFile.getAbsoluteFile().exists()) {
|
||||
oldConfigFile.getAbsoluteFile().delete();
|
||||
}
|
||||
configFile.getAbsoluteFile().renameTo(oldConfigFile.getAbsoluteFile());
|
||||
saveDefaultConfig();
|
||||
try {
|
||||
getConfig().load(configFile.getAbsoluteFile());
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
getLogger().warning("Could not load freshly generated config file!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else if (getConfig().getInt("config-version", 0) != currentConfigVersion) {
|
||||
getLogger().warning("========================================================");
|
||||
getLogger().warning("YOU ARE USING AN OLD CONFIG FILE!");
|
||||
getLogger().warning("This is not a problem, as ChestSort will just use the");
|
||||
getLogger().warning("default settings for unset values. However, if you want");
|
||||
getLogger().warning("to configure the new options, please go to");
|
||||
getLogger().warning("https://www.spigotmc.org/resources/1-13-chestsort.59773/");
|
||||
getLogger().warning("and replace your config.yml with the new one. You can");
|
||||
getLogger().warning("then insert your old changes into the new file.");
|
||||
getLogger().warning("========================================================");
|
||||
usingMatchingConfig = false;
|
||||
}
|
||||
|
||||
File playerDataFolder = new File(getDataFolder().getPath() + File.separator + "playerdata");
|
||||
if (!playerDataFolder.getAbsoluteFile().exists()) {
|
||||
playerDataFolder.mkdir();
|
||||
}
|
||||
File categoriesFolder = new File(getDataFolder().getPath() + File.separator + "categories");
|
||||
if (!categoriesFolder.getAbsoluteFile().exists()) {
|
||||
categoriesFolder.mkdir();
|
||||
}
|
||||
|
||||
getConfig().addDefault("sorting-enabled-by-default", false);
|
||||
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", "{category},{itemsFirst},{name},{color}");
|
||||
getConfig().addDefault("check-for-updates", "true");
|
||||
getConfig().addDefault("auto-generate-category-files", true);
|
||||
getConfig().addDefault("verbose", true);
|
||||
|
||||
disabledWorlds = (ArrayList<String>) getConfig().getStringList("disabled-worlds");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
for (Player p : getServer().getOnlinePlayers()) {
|
||||
unregisterPlayer(p);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
createConfig();
|
||||
saveDefaultCategories();
|
||||
verbose = getConfig().getBoolean("verbose");
|
||||
messages = new JeffChestSortMessages(this);
|
||||
organizer = new JeffChestSortOrganizer(this);
|
||||
updateChecker = new JeffChestSortUpdateChecker(this);
|
||||
listener = new JeffChestSortListener(this);
|
||||
sortingMethod = getConfig().getString("sorting-method");
|
||||
getServer().getPluginManager().registerEvents(listener, this);
|
||||
JeffChestSortCommandExecutor commandExecutor = new JeffChestSortCommandExecutor(this);
|
||||
this.getCommand("chestsort").setExecutor(commandExecutor);
|
||||
|
||||
if (verbose) {
|
||||
getLogger().info("Current sorting method: " + sortingMethod);
|
||||
getLogger().info("Sorting enabled by default: " + getConfig().getBoolean("sorting-enabled-by-default"));
|
||||
getLogger().info("Auto generate category files: " + getConfig().getBoolean("auto-generate-category-files"));
|
||||
getLogger().info("Check for updates: " + getConfig().getString("check-for-updates"));
|
||||
}
|
||||
if (getConfig().getString("check-for-updates", "true").equalsIgnoreCase("true")) {
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
|
||||
public void run() {
|
||||
updateChecker.checkForUpdate();
|
||||
}
|
||||
}, 0L, updateCheckInterval * 20);
|
||||
} else if (getConfig().getString("check-for-updates", "true").equalsIgnoreCase("on-startup")) {
|
||||
updateChecker.checkForUpdate();
|
||||
}
|
||||
|
||||
Metrics metrics = new Metrics(this);
|
||||
|
||||
metrics.addCustomChart(new Metrics.SimplePie("sorting_method", () -> sortingMethod));
|
||||
metrics.addCustomChart(new Metrics.SimplePie("config_version",
|
||||
() -> Integer.toString(getConfig().getInt("config-version", 0))));
|
||||
metrics.addCustomChart(
|
||||
new Metrics.SimplePie("check_for_updates", () -> getConfig().getString("check-for-updates", "true")));
|
||||
metrics.addCustomChart(new Metrics.SimplePie("show_message_when_using_chest",
|
||||
() -> Boolean.toString(getConfig().getBoolean("show-message-when-using-chest"))));
|
||||
metrics.addCustomChart(new Metrics.SimplePie("show_message_when_using_chest_and_sorting_is_enabl",
|
||||
() -> Boolean.toString(getConfig().getBoolean("show-message-when-using-chest-and-sorting-is-enabled"))));
|
||||
metrics.addCustomChart(new Metrics.SimplePie("show_message_again_after_logout",
|
||||
() -> Boolean.toString(getConfig().getBoolean("show-message-again-after-logout"))));
|
||||
metrics.addCustomChart(new Metrics.SimplePie("sorting_enabled_by_default",
|
||||
() -> Boolean.toString(getConfig().getBoolean("sorting-enabled-by-default"))));
|
||||
metrics.addCustomChart(
|
||||
new Metrics.SimplePie("using_matching_config_version", () -> Boolean.toString(usingMatchingConfig)));
|
||||
|
||||
}
|
||||
|
||||
private void saveDefaultCategories() {
|
||||
String[] defaultCategories = { "900-valuables", "910-tools", "920-combat", "930-brewing", "940-food",
|
||||
"950-redstone", "960-wood", "970-stone", "980-plants", "981-corals" };
|
||||
|
||||
if (getConfig().getBoolean("auto-generate-category-files", true) != true) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
for (String category : defaultCategories) {
|
||||
|
||||
FileOutputStream fopDefault = null;
|
||||
File fileDefault;
|
||||
|
||||
try {
|
||||
InputStream in = getClass()
|
||||
.getResourceAsStream("/de/jeffclan/utils/categories/" + category + ".default.txt");
|
||||
|
||||
fileDefault = new File(getDataFolder().getAbsolutePath() + File.separator + "categories"
|
||||
+ File.separator + category + ".txt");
|
||||
fopDefault = new FileOutputStream(fileDefault);
|
||||
|
||||
// if file doesnt exists, then create it
|
||||
// if (!fileDefault.getAbsoluteFile().exists()) {
|
||||
fileDefault.createNewFile();
|
||||
// }
|
||||
|
||||
// get the content in bytes
|
||||
byte[] contentInBytes = Utils.getBytes(in);
|
||||
|
||||
fopDefault.write(contentInBytes);
|
||||
fopDefault.flush();
|
||||
fopDefault.close();
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (fopDefault != null) {
|
||||
fopDefault.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean sortingEnabled(Player p) {
|
||||
|
||||
// The following is for all the lazy server admins who use /reload instead of properly restarting their
|
||||
// server ;) I am sometimes getting stacktraces although it is clearly stated that /reload is NOT
|
||||
// supported. So, here is a quick fix
|
||||
if(PerPlayerSettings == null) {
|
||||
PerPlayerSettings = new HashMap<String, JeffChestSortPlayerSetting>();
|
||||
}
|
||||
listener.registerPlayerIfNeeded(p);
|
||||
// End of quick fix
|
||||
|
||||
return PerPlayerSettings.get(p.getUniqueId().toString()).sortingEnabled;
|
||||
}
|
||||
|
||||
void unregisterPlayer(Player p) {
|
||||
UUID uniqueId = p.getUniqueId();
|
||||
if (PerPlayerSettings.containsKey(uniqueId.toString())) {
|
||||
JeffChestSortPlayerSetting setting = PerPlayerSettings.get(p.getUniqueId().toString());
|
||||
File playerFile = new File(getDataFolder() + File.separator + "playerdata",
|
||||
p.getUniqueId().toString() + ".yml");
|
||||
YamlConfiguration playerConfig = YamlConfiguration.loadConfiguration(playerFile);
|
||||
playerConfig.set("sortingEnabled", setting.sortingEnabled);
|
||||
playerConfig.set("hasSeenMessage", setting.hasSeenMessage);
|
||||
try {
|
||||
playerConfig.save(playerFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
PerPlayerSettings.remove(uniqueId.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,70 +1,70 @@
|
||||
package de.jeffclan.JeffChestSort;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class JeffChestSortUpdateChecker {
|
||||
|
||||
private JeffChestSortPlugin plugin;
|
||||
|
||||
JeffChestSortUpdateChecker(JeffChestSortPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
String latestVersionLink = "https://api.jeff-media.de/chestsort/chestsort-latest-version.txt";
|
||||
String downloadLink = "https://www.spigotmc.org/resources/1-13-chestsort.59773/";
|
||||
private String currentVersion = "undefined";
|
||||
private String latestVersion = "undefined";
|
||||
|
||||
void sendUpdateMessage(Player p) {
|
||||
if(!latestVersion.equals("undefined")) {
|
||||
if (!currentVersion.equals(latestVersion)) {
|
||||
p.sendMessage(ChatColor.GRAY + "There is a new version of " + ChatColor.GOLD + "ChestSort" + ChatColor.GRAY
|
||||
+ " available.");
|
||||
p.sendMessage(ChatColor.GRAY + "Please download at " + downloadLink);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void checkForUpdate() {
|
||||
|
||||
plugin.getLogger().info("Checking for available updates...");
|
||||
|
||||
try {
|
||||
|
||||
HttpURLConnection httpcon = (HttpURLConnection) new URL(latestVersionLink).openConnection();
|
||||
httpcon.addRequestProperty("User-Agent", "ChestSort/"+plugin.getDescription().getVersion());
|
||||
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(httpcon.getInputStream()));
|
||||
|
||||
String inputLine = reader.readLine().trim();
|
||||
|
||||
latestVersion = inputLine;
|
||||
currentVersion = plugin.getDescription().getVersion().trim();
|
||||
|
||||
|
||||
if (latestVersion.equals(currentVersion)) {
|
||||
plugin.getLogger().info("You are using the latest version of ChestSort.");
|
||||
} else {
|
||||
plugin.getLogger().warning("========================================================");
|
||||
plugin.getLogger().warning("There is a new version of ChestSort available!");
|
||||
plugin.getLogger().warning("Latest : " + inputLine);
|
||||
plugin.getLogger().warning("Current: " + currentVersion);
|
||||
plugin.getLogger().warning("Please update to the newest version. Download:");
|
||||
plugin.getLogger().warning(downloadLink);
|
||||
plugin.getLogger().warning("========================================================");
|
||||
}
|
||||
|
||||
reader.close();
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().warning("Could not check for updates.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
package de.jeffclan.JeffChestSort;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class JeffChestSortUpdateChecker {
|
||||
|
||||
private JeffChestSortPlugin plugin;
|
||||
|
||||
JeffChestSortUpdateChecker(JeffChestSortPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
String latestVersionLink = "https://api.jeff-media.de/chestsort/chestsort-latest-version.txt";
|
||||
String downloadLink = "https://www.spigotmc.org/resources/1-13-chestsort.59773/";
|
||||
private String currentVersion = "undefined";
|
||||
private String latestVersion = "undefined";
|
||||
|
||||
void sendUpdateMessage(Player p) {
|
||||
if(!latestVersion.equals("undefined")) {
|
||||
if (!currentVersion.equals(latestVersion)) {
|
||||
p.sendMessage(ChatColor.GRAY + "There is a new version of " + ChatColor.GOLD + "ChestSort" + ChatColor.GRAY
|
||||
+ " available.");
|
||||
p.sendMessage(ChatColor.GRAY + "Please download at " + downloadLink);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void checkForUpdate() {
|
||||
|
||||
plugin.getLogger().info("Checking for available updates...");
|
||||
|
||||
try {
|
||||
|
||||
HttpURLConnection httpcon = (HttpURLConnection) new URL(latestVersionLink).openConnection();
|
||||
httpcon.addRequestProperty("User-Agent", "ChestSort/"+plugin.getDescription().getVersion());
|
||||
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(httpcon.getInputStream()));
|
||||
|
||||
String inputLine = reader.readLine().trim();
|
||||
|
||||
latestVersion = inputLine;
|
||||
currentVersion = plugin.getDescription().getVersion().trim();
|
||||
|
||||
|
||||
if (latestVersion.equals(currentVersion)) {
|
||||
plugin.getLogger().info("You are using the latest version of ChestSort.");
|
||||
} else {
|
||||
plugin.getLogger().warning("========================================================");
|
||||
plugin.getLogger().warning("There is a new version of ChestSort available!");
|
||||
plugin.getLogger().warning("Latest : " + inputLine);
|
||||
plugin.getLogger().warning("Current: " + currentVersion);
|
||||
plugin.getLogger().warning("Please update to the newest version. Download:");
|
||||
plugin.getLogger().warning(downloadLink);
|
||||
plugin.getLogger().warning("========================================================");
|
||||
}
|
||||
|
||||
reader.close();
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().warning("Could not check for updates.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,30 +1,30 @@
|
||||
package de.jeffclan.utils;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class Utils {
|
||||
public static byte[] getBytes(InputStream is) throws IOException {
|
||||
|
||||
int len;
|
||||
int size = 1024;
|
||||
byte[] buf;
|
||||
|
||||
if (is instanceof ByteArrayInputStream) {
|
||||
size = is.available();
|
||||
buf = new byte[size];
|
||||
len = is.read(buf, 0, size);
|
||||
} else {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
buf = new byte[size];
|
||||
while ((len = is.read(buf, 0, size)) != -1)
|
||||
bos.write(buf, 0, len);
|
||||
buf = bos.toByteArray();
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
package de.jeffclan.utils;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class Utils {
|
||||
public static byte[] getBytes(InputStream is) throws IOException {
|
||||
|
||||
int len;
|
||||
int size = 1024;
|
||||
byte[] buf;
|
||||
|
||||
if (is instanceof ByteArrayInputStream) {
|
||||
size = is.available();
|
||||
buf = new byte[size];
|
||||
len = is.read(buf, 0, size);
|
||||
} else {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
buf = new byte[size];
|
||||
while ((len = is.read(buf, 0, size)) != -1)
|
||||
bos.write(buf, 0, len);
|
||||
buf = bos.toByteArray();
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,27 +1,27 @@
|
||||
diamond
|
||||
emerald
|
||||
diamond_ore
|
||||
emerald_ore
|
||||
iron_ingot
|
||||
iron_ore
|
||||
gold_ingot
|
||||
gold_ore
|
||||
gold_block
|
||||
diamond_block
|
||||
iron_block
|
||||
lapis_lazuli
|
||||
lapis_block
|
||||
obsidian
|
||||
beacon
|
||||
conduit
|
||||
scute
|
||||
elytra
|
||||
ender_pearl
|
||||
ender_eye
|
||||
*_horse_armor
|
||||
music_disc_*
|
||||
heart_of_the_sea
|
||||
nautilus_shell
|
||||
gold_nugget
|
||||
iron_nugget
|
||||
diamond
|
||||
emerald
|
||||
diamond_ore
|
||||
emerald_ore
|
||||
iron_ingot
|
||||
iron_ore
|
||||
gold_ingot
|
||||
gold_ore
|
||||
gold_block
|
||||
diamond_block
|
||||
iron_block
|
||||
lapis_lazuli
|
||||
lapis_block
|
||||
obsidian
|
||||
beacon
|
||||
conduit
|
||||
scute
|
||||
elytra
|
||||
ender_pearl
|
||||
ender_eye
|
||||
*_horse_armor
|
||||
music_disc_*
|
||||
heart_of_the_sea
|
||||
nautilus_shell
|
||||
gold_nugget
|
||||
iron_nugget
|
||||
enchanted_book
|
@ -1,10 +1,10 @@
|
||||
*_pickaxe
|
||||
*_shovel
|
||||
*_hoe
|
||||
*_axe
|
||||
flint_and_steel
|
||||
fishing_rod
|
||||
compass
|
||||
clock
|
||||
shears
|
||||
*_pickaxe
|
||||
*_shovel
|
||||
*_hoe
|
||||
*_axe
|
||||
flint_and_steel
|
||||
fishing_rod
|
||||
compass
|
||||
clock
|
||||
shears
|
||||
lead
|
@ -1,13 +1,13 @@
|
||||
turtle_helmet
|
||||
bow
|
||||
arrow
|
||||
*_sword
|
||||
*_helmet
|
||||
*_chestplate
|
||||
*_leggings
|
||||
*_boots
|
||||
spectral_arrow
|
||||
tipped_arrow
|
||||
shield
|
||||
totem_of_undying
|
||||
turtle_helmet
|
||||
bow
|
||||
arrow
|
||||
*_sword
|
||||
*_helmet
|
||||
*_chestplate
|
||||
*_leggings
|
||||
*_boots
|
||||
spectral_arrow
|
||||
tipped_arrow
|
||||
shield
|
||||
totem_of_undying
|
||||
trident
|
@ -1,15 +1,15 @@
|
||||
ghast_tear
|
||||
potion
|
||||
glass_bottle
|
||||
fermented_spider_eye
|
||||
blaze_powder
|
||||
magma_cream
|
||||
brewing_stand
|
||||
cauldron
|
||||
glistering_melon_slice
|
||||
golden_carrot
|
||||
rabbit_foot
|
||||
dragon_breath
|
||||
splash_potion
|
||||
lingering_potion
|
||||
ghast_tear
|
||||
potion
|
||||
glass_bottle
|
||||
fermented_spider_eye
|
||||
blaze_powder
|
||||
magma_cream
|
||||
brewing_stand
|
||||
cauldron
|
||||
glistering_melon_slice
|
||||
golden_carrot
|
||||
rabbit_foot
|
||||
dragon_breath
|
||||
splash_potion
|
||||
lingering_potion
|
||||
phantom_membrane
|
@ -1,30 +1,30 @@
|
||||
apple
|
||||
baked_potato
|
||||
beef
|
||||
beetroot
|
||||
beetroot_soup
|
||||
bread
|
||||
mushroom_stew
|
||||
porkchop
|
||||
cooked_porkchop
|
||||
cod
|
||||
salmon
|
||||
cooked_cod
|
||||
cooked_salmon
|
||||
cake
|
||||
cookie
|
||||
melon_slice
|
||||
dried_kelp
|
||||
cooked_beef
|
||||
chicken
|
||||
cooked_chicken
|
||||
carrot
|
||||
potato
|
||||
pumpkin_pie
|
||||
rabbit
|
||||
cooked_rabbit
|
||||
rabbit_stew
|
||||
mutton
|
||||
cooked_mutton
|
||||
wheat
|
||||
apple
|
||||
baked_potato
|
||||
beef
|
||||
beetroot
|
||||
beetroot_soup
|
||||
bread
|
||||
mushroom_stew
|
||||
porkchop
|
||||
cooked_porkchop
|
||||
cod
|
||||
salmon
|
||||
cooked_cod
|
||||
cooked_salmon
|
||||
cake
|
||||
cookie
|
||||
melon_slice
|
||||
dried_kelp
|
||||
cooked_beef
|
||||
chicken
|
||||
cooked_chicken
|
||||
carrot
|
||||
potato
|
||||
pumpkin_pie
|
||||
rabbit
|
||||
cooked_rabbit
|
||||
rabbit_stew
|
||||
mutton
|
||||
cooked_mutton
|
||||
wheat
|
||||
*_seeds
|
@ -1,23 +1,23 @@
|
||||
dispenser
|
||||
note_block
|
||||
sticky_piston
|
||||
piston
|
||||
tnt
|
||||
lever
|
||||
*_pressure_plate
|
||||
redstone
|
||||
*_button
|
||||
redstone_lamp
|
||||
redstone_torch
|
||||
tripwire_hook
|
||||
trapped_chest
|
||||
daylight_detector
|
||||
redstone_block
|
||||
redstone_ore
|
||||
hopper
|
||||
dropper
|
||||
iron_trapdoor
|
||||
observer
|
||||
iron_door
|
||||
repeater
|
||||
dispenser
|
||||
note_block
|
||||
sticky_piston
|
||||
piston
|
||||
tnt
|
||||
lever
|
||||
*_pressure_plate
|
||||
redstone
|
||||
*_button
|
||||
redstone_lamp
|
||||
redstone_torch
|
||||
tripwire_hook
|
||||
trapped_chest
|
||||
daylight_detector
|
||||
redstone_block
|
||||
redstone_ore
|
||||
hopper
|
||||
dropper
|
||||
iron_trapdoor
|
||||
observer
|
||||
iron_door
|
||||
repeater
|
||||
comparator
|
Loading…
Reference in New Issue
Block a user