Compare commits
21 Commits
36f4896dce
...
f28908d3aa
Author | SHA1 | Date | |
---|---|---|---|
f28908d3aa | |||
1043e1805e | |||
4d001c0432 | |||
047f54094a | |||
882e58e38e | |||
f5d60cd7e4 | |||
2d7192ae9b | |||
49bd873392 | |||
054ea4931d | |||
76afccf285 | |||
52b74cb772 | |||
1c5402cf6e | |||
571fa366bc | |||
b82f47fb3b | |||
f559ace08b | |||
4b41a6198d | |||
84ec5838d4 | |||
e2b72802d0 | |||
653ba71f73 | |||
eda31a1df2 | |||
8ba67b35d1 |
18
README.md
18
README.md
@ -1,6 +1,6 @@
|
|||||||

|

|
||||||
### An 'All-in-one' plugin for MC servers.
|
### An 'All-in-one' plugin for MC servers.
|
||||||
#### TabList Customizing, Custom Advancement, Connect messages, AutoSave, Logger
|
#### TabList Customizing, Server Password, Clear Dropped Items, Custom Advancement, Connect messages, AutoSave, Logger
|
||||||
[](https://ci.ditservices.hu/job/SimplifyTools/)   [](https://bstats.org/plugin/bukkit/SimplifyTools/15108) 
|
[](https://ci.ditservices.hu/job/SimplifyTools/)   [](https://bstats.org/plugin/bukkit/SimplifyTools/15108) 
|
||||||
<br>[Changelog](docs/ChangeLog.md)
|
<br>[Changelog](docs/ChangeLog.md)
|
||||||
<hr>
|
<hr>
|
||||||
@ -12,13 +12,15 @@
|
|||||||
- **Tab Manager** - Allows you to specify colored texts, with animations on the tab window.
|
- **Tab Manager** - Allows you to specify colored texts, with animations on the tab window.
|
||||||
Also you can display the average ping, Server RAM statistics.
|
Also you can display the average ping, Server RAM statistics.
|
||||||

|

|
||||||
- **Automatic/command saving** - Allows you to schedule auto saving of the world/player data on your server, or you can initiate a save by a command.
|
- **Gameplay statistics** - You can check your gameplay statistics such as player/mob kills, etc.
|
||||||
|
(Note: The plugin just shows the stats not recording itself, so stats before installing this plugin are counted too.)
|
||||||
|

|
||||||
|
- **Server Password** - Allows you to set a server password *(same password for all players)*, ability to: skip auth for OP players, hide inventory, disable moving, building, until providing correct password `/slogin {PASSWORD}`
|
||||||
|
- **Clearing Dropped Items** - Set an interval in seconds to remove dropped items. Ability to broadcast clearing before 1min, 10sec, skip items and/or worlds.
|
||||||
- **Custom Connect/Disconnect messages** - Allows you to customize the message that is broadcasted when someone joins or leaves the server.
|
- **Custom Connect/Disconnect messages** - Allows you to customize the message that is broadcasted when someone joins or leaves the server.
|
||||||

|

|
||||||
|
- **Automatic/command saving** - Allows you to schedule auto saving of the world/player data on your server, or you can initiate a save by a command.
|
||||||
- **Plugin Manager** - Allows you to unload/load plugins without a server restart. (Disabled by default since v1.2.1)
|
- **Plugin Manager** - Allows you to unload/load plugins without a server restart. (Disabled by default since v1.2.1)
|
||||||
- **Gameplay statistics** - You can check your gameplay statistics such as player/mob kills, etc.
|
|
||||||
(Note: The plugin just shows the stats not recording itself, so stats before installing this plugin are counted too.)
|
|
||||||

|
|
||||||
- **Custom Advancement Messages** - You can customize the advancement messages in three categories: advancement, goal, challenge.
|
- **Custom Advancement Messages** - You can customize the advancement messages in three categories: advancement, goal, challenge.
|
||||||
(Note: The advancement names are currently only can be displayed in english. In future versions there will be a feature to translate to any languages.)
|
(Note: The advancement names are currently only can be displayed in english. In future versions there will be a feature to translate to any languages.)
|
||||||

|

|
||||||
@ -32,6 +34,12 @@ _________________
|
|||||||
_________________
|
_________________
|
||||||
### [Commands & Permissions](docs/cmd_perms.md)
|
### [Commands & Permissions](docs/cmd_perms.md)
|
||||||
_________________
|
_________________
|
||||||
|
### Translation
|
||||||
|
Under the plugin's directory inside the lang folder you can add your own translation. <br>
|
||||||
|
Just copy-paste [en.yml](src/main/resources/en.yml) and translate the strings to your language. <br>
|
||||||
|
In the config.yml you can set the newly created language (for example: de.yml) to like this: `language: 'de'` and your translation will be used. <br>
|
||||||
|
Feel free to open a pull request and your language can be added to the plugin.
|
||||||
|
_________________
|
||||||
### [Building from source](docs/BUILDING.md)
|
### [Building from source](docs/BUILDING.md)
|
||||||
_________________
|
_________________
|
||||||
### If you have an idea or bug report [Create an issue](https://github.com/LabodiDavid/SimplifyTools/issues/new/choose) or [Create a pull request](https://github.com/LabodiDavid/SimplifyTools/compare)
|
### If you have an idea or bug report [Create an issue](https://github.com/LabodiDavid/SimplifyTools/issues/new/choose) or [Create a pull request](https://github.com/LabodiDavid/SimplifyTools/compare)
|
||||||
|
@ -1,5 +1,13 @@
|
|||||||
# SimplifyTools - Changelog
|
# SimplifyTools - Changelog
|
||||||
|
- **1.2.4**
|
||||||
|
- Added *Server password feature*
|
||||||
|
- Added *Clearing dropped items feature*
|
||||||
|
- Implemented customizable translation
|
||||||
|
- Added total play time to stats command
|
||||||
|
- Tab completer optimalizations
|
||||||
|
- Minor refactors/optimalizations
|
||||||
|
- Prepared support for 1.21.5 (Not tested yet)
|
||||||
|
- From now running newer untested server versions is allowed
|
||||||
- **1.2.3**
|
- **1.2.3**
|
||||||
- Added support for version up to 1.21.4
|
- Added support for version up to 1.21.4
|
||||||
- The plugin now depends on, <b>requires ProtocolLib</b> (https://github.com/dmulloy2/ProtocolLib/)
|
- The plugin now depends on, <b>requires ProtocolLib</b> (https://github.com/dmulloy2/ProtocolLib/)
|
||||||
|
@ -5,12 +5,14 @@ You can use the following commands to use the features of SimplifyTools.
|
|||||||
- **/st ping**: Displays your ping to the current server.<br />Requires `st.ping`
|
- **/st ping**: Displays your ping to the current server.<br />Requires `st.ping`
|
||||||
- **/st tps**: Displays plugin calculated TPS.<br />Requires `st.tps`
|
- **/st tps**: Displays plugin calculated TPS.<br />Requires `st.tps`
|
||||||
- **/st stats**: Displays your gameplay statistics.<br />Requires `st.stats`
|
- **/st stats**: Displays your gameplay statistics.<br />Requires `st.stats`
|
||||||
|
- **/slogin**: Used to login if server password enabled.<br />Requires `st.slogin`
|
||||||
- **/st save-all**: Saves the players, worlds data on the server.<br />Requires `st.save`
|
- **/st save-all**: Saves the players, worlds data on the server.<br />Requires `st.save`
|
||||||
- **/st pmanager** <LOAD/UNLOAD>: A built-in plugin manager.<br />Requires `st.pmanager.*`
|
- **/st pmanager** <LOAD/UNLOAD>: A built-in plugin manager.<br />Requires `st.pmanager.*`
|
||||||
- **/st pmanager load** <PLUGIN-NAME>: Plugin loading.<br />Requires `st.pmanager.load (can be inherited from st.pmanager.*)`
|
- **/st pmanager load** <PLUGIN-NAME>: Plugin loading.<br />Requires `st.pmanager.load (can be inherited from st.pmanager.*)`
|
||||||
- **/st pmanager unload** <PLUGIN-NAME>: Plugin unload.<br />Requires `st.pmanager.unload (can be inherited from st.pmanager.*)`
|
- **/st pmanager unload** <PLUGIN-NAME>: Plugin unload.<br />Requires `st.pmanager.unload (can be inherited from st.pmanager.*)`
|
||||||
- **/st reload**: Plugin settings reload.<br />Requires `st.reload`
|
- **/st reload**: Plugin settings reload.<br />Requires `st.reload`
|
||||||
|
## SimplifyTools - Permissions
|
||||||
|
- `st.slogin.skip` - If has this permission the user dont have to provide server password upon connect if enabled.
|
||||||
## SimplifyTools - Wildcard Permissions
|
## SimplifyTools - Wildcard Permissions
|
||||||
|
|
||||||
- **st.*** - Wildcard permission for all commands, permissions for this plugin.
|
- **st.*** - Wildcard permission for all commands, permissions for this plugin.
|
||||||
|
9
pom.xml
9
pom.xml
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>hu.ditservices</groupId>
|
<groupId>hu.ditservices</groupId>
|
||||||
<artifactId>SimplifyTools</artifactId>
|
<artifactId>SimplifyTools</artifactId>
|
||||||
<version>1.2.3</version>
|
<version>1.2.4</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>SimplifyTools</name>
|
<name>SimplifyTools</name>
|
||||||
@ -110,6 +110,11 @@
|
|||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.tchristofferson</groupId>
|
||||||
|
<artifactId>ConfigUpdater</artifactId>
|
||||||
|
<version>2.2-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.jeff_media</groupId>
|
<groupId>com.jeff_media</groupId>
|
||||||
<artifactId>SpigotUpdateChecker</artifactId>
|
<artifactId>SpigotUpdateChecker</artifactId>
|
||||||
@ -126,7 +131,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>spigot-api</artifactId>
|
<artifactId>spigot-api</artifactId>
|
||||||
<version>1.21.4-R0.1-SNAPSHOT</version>
|
<version>1.21.5-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- from downloaded craftbukkit-x.xx.x.jar\META-INF\versions\ -->
|
<!-- from downloaded craftbukkit-x.xx.x.jar\META-INF\versions\ -->
|
||||||
|
@ -1,241 +0,0 @@
|
|||||||
package com.tchristofferson.configupdater;
|
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class ConfigUpdater {
|
|
||||||
|
|
||||||
//Used for separating keys in the keyBuilder inside parseComments method
|
|
||||||
private static final char SEPARATOR = '.';
|
|
||||||
|
|
||||||
public static void update(Plugin plugin, String resourceName, File toUpdate, String... ignoredSections) throws IOException {
|
|
||||||
update(plugin, resourceName, toUpdate, Arrays.asList(ignoredSections));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void update(Plugin plugin, String resourceName, File toUpdate, List<String> ignoredSections) throws IOException {
|
|
||||||
Preconditions.checkArgument(toUpdate.exists(), "The toUpdate file doesn't exist!");
|
|
||||||
|
|
||||||
FileConfiguration defaultConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(plugin.getResource(resourceName), StandardCharsets.UTF_8));
|
|
||||||
FileConfiguration currentConfig = YamlConfiguration.loadConfiguration(toUpdate);
|
|
||||||
Map<String, String> comments = parseComments(plugin, resourceName, defaultConfig);
|
|
||||||
Map<String, String> ignoredSectionsValues = parseIgnoredSections(toUpdate, currentConfig, comments, ignoredSections == null ? Collections.emptyList() : ignoredSections);
|
|
||||||
|
|
||||||
// will write updated config file "contents" to a string
|
|
||||||
StringWriter writer = new StringWriter();
|
|
||||||
write(defaultConfig, currentConfig, new BufferedWriter(writer), comments, ignoredSectionsValues);
|
|
||||||
String value = writer.toString(); // config contents
|
|
||||||
|
|
||||||
Path toUpdatePath = toUpdate.toPath();
|
|
||||||
if (!value.equals(new String(Files.readAllBytes(toUpdatePath), StandardCharsets.UTF_8))) { // if updated contents are not the same as current file contents, update
|
|
||||||
Files.write(toUpdatePath, value.getBytes(StandardCharsets.UTF_8));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void write(FileConfiguration defaultConfig, FileConfiguration currentConfig, BufferedWriter writer, Map<String, String> comments, Map<String, String> ignoredSectionsValues) throws IOException {
|
|
||||||
//Used for converting objects to yaml, then cleared
|
|
||||||
FileConfiguration parserConfig = new YamlConfiguration();
|
|
||||||
|
|
||||||
keyLoop: for (String fullKey : defaultConfig.getKeys(true)) {
|
|
||||||
String indents = KeyBuilder.getIndents(fullKey, SEPARATOR);
|
|
||||||
|
|
||||||
if (ignoredSectionsValues.isEmpty()) {
|
|
||||||
writeCommentIfExists(comments, writer, fullKey, indents);
|
|
||||||
} else {
|
|
||||||
for (Map.Entry<String, String> entry : ignoredSectionsValues.entrySet()) {
|
|
||||||
if (entry.getKey().equals(fullKey)) {
|
|
||||||
writer.write(ignoredSectionsValues.get(fullKey) + "\n");
|
|
||||||
continue keyLoop;
|
|
||||||
} else if (KeyBuilder.isSubKeyOf(entry.getKey(), fullKey, SEPARATOR)) {
|
|
||||||
continue keyLoop;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
writeCommentIfExists(comments, writer, fullKey, indents);
|
|
||||||
}
|
|
||||||
|
|
||||||
Object currentValue = currentConfig.get(fullKey);
|
|
||||||
|
|
||||||
if (currentValue == null)
|
|
||||||
currentValue = defaultConfig.get(fullKey);
|
|
||||||
|
|
||||||
String[] splitFullKey = fullKey.split("[" + SEPARATOR + "]");
|
|
||||||
String trailingKey = splitFullKey[splitFullKey.length - 1];
|
|
||||||
|
|
||||||
if (currentValue instanceof ConfigurationSection) {
|
|
||||||
writer.write(indents + trailingKey + ":");
|
|
||||||
|
|
||||||
if (!((ConfigurationSection) currentValue).getKeys(false).isEmpty())
|
|
||||||
writer.write("\n");
|
|
||||||
else
|
|
||||||
writer.write(" {}\n");
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
parserConfig.set(trailingKey, currentValue);
|
|
||||||
String yaml = parserConfig.saveToString();
|
|
||||||
yaml = yaml.substring(0, yaml.length() - 1).replace("\n", "\n" + indents);
|
|
||||||
String toWrite = indents + yaml + "\n";
|
|
||||||
parserConfig.set(trailingKey, null);
|
|
||||||
writer.write(toWrite);
|
|
||||||
}
|
|
||||||
|
|
||||||
String danglingComments = comments.get(null);
|
|
||||||
|
|
||||||
if (danglingComments != null)
|
|
||||||
writer.write(danglingComments);
|
|
||||||
|
|
||||||
writer.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
//Returns a map of key comment pairs. If a key doesn't have any comments it won't be included in the map.
|
|
||||||
private static Map<String, String> parseComments(Plugin plugin, String resourceName, FileConfiguration defaultConfig) throws IOException {
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(plugin.getResource(resourceName)));
|
|
||||||
Map<String, String> comments = new LinkedHashMap<>();
|
|
||||||
StringBuilder commentBuilder = new StringBuilder();
|
|
||||||
KeyBuilder keyBuilder = new KeyBuilder(defaultConfig, SEPARATOR);
|
|
||||||
|
|
||||||
String line;
|
|
||||||
while ((line = reader.readLine()) != null) {
|
|
||||||
String trimmedLine = line.trim();
|
|
||||||
|
|
||||||
//Only getting comments for keys. A list/array element comment(s) not supported
|
|
||||||
if (trimmedLine.startsWith("-")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (trimmedLine.isEmpty() || trimmedLine.startsWith("#")) {//Is blank line or is comment
|
|
||||||
commentBuilder.append(trimmedLine).append("\n");
|
|
||||||
} else {//is a valid yaml key
|
|
||||||
keyBuilder.parseLine(trimmedLine);
|
|
||||||
String key = keyBuilder.toString();
|
|
||||||
|
|
||||||
//If there is a comment associated with the key it is added to comments map and the commentBuilder is reset
|
|
||||||
if (commentBuilder.length() > 0) {
|
|
||||||
comments.put(key, commentBuilder.toString());
|
|
||||||
commentBuilder.setLength(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Remove the last key from keyBuilder if current path isn't a config section or if it is empty to prepare for the next key
|
|
||||||
if (!keyBuilder.isConfigSectionWithKeys()) {
|
|
||||||
keyBuilder.removeLastKey();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
reader.close();
|
|
||||||
|
|
||||||
if (commentBuilder.length() > 0)
|
|
||||||
comments.put(null, commentBuilder.toString());
|
|
||||||
|
|
||||||
return comments;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Map<String, String> parseIgnoredSections(File toUpdate, FileConfiguration currentConfig, Map<String, String> comments, List<String> ignoredSections) throws IOException {
|
|
||||||
BufferedReader reader = new BufferedReader(new FileReader(toUpdate));
|
|
||||||
Map<String, String> ignoredSectionsValues = new LinkedHashMap<>(ignoredSections.size());
|
|
||||||
KeyBuilder keyBuilder = new KeyBuilder(currentConfig, SEPARATOR);
|
|
||||||
StringBuilder valueBuilder = new StringBuilder();
|
|
||||||
|
|
||||||
String currentIgnoredSection = null;
|
|
||||||
String line;
|
|
||||||
lineLoop : while ((line = reader.readLine()) != null) {
|
|
||||||
String trimmedLine = line.trim();
|
|
||||||
|
|
||||||
if (trimmedLine.isEmpty() || trimmedLine.startsWith("#"))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (trimmedLine.startsWith("-")) {
|
|
||||||
for (String ignoredSection : ignoredSections) {
|
|
||||||
boolean isIgnoredParent = ignoredSection.equals(keyBuilder.toString());
|
|
||||||
|
|
||||||
if (isIgnoredParent || keyBuilder.isSubKeyOf(ignoredSection)) {
|
|
||||||
valueBuilder.append("\n").append(line);
|
|
||||||
continue lineLoop;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
keyBuilder.parseLine(trimmedLine);
|
|
||||||
String fullKey = keyBuilder.toString();
|
|
||||||
|
|
||||||
//If building the value for an ignored section and this line is no longer a part of the ignored section,
|
|
||||||
// write the valueBuilder, reset it, and set the current ignored section to null
|
|
||||||
if (currentIgnoredSection != null && !KeyBuilder.isSubKeyOf(currentIgnoredSection, fullKey, SEPARATOR)) {
|
|
||||||
ignoredSectionsValues.put(currentIgnoredSection, valueBuilder.toString());
|
|
||||||
valueBuilder.setLength(0);
|
|
||||||
currentIgnoredSection = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (String ignoredSection : ignoredSections) {
|
|
||||||
boolean isIgnoredParent = ignoredSection.equals(fullKey);
|
|
||||||
|
|
||||||
if (isIgnoredParent || keyBuilder.isSubKeyOf(ignoredSection)) {
|
|
||||||
if (valueBuilder.length() > 0)
|
|
||||||
valueBuilder.append("\n");
|
|
||||||
|
|
||||||
String comment = comments.get(fullKey);
|
|
||||||
|
|
||||||
if (comment != null) {
|
|
||||||
String indents = KeyBuilder.getIndents(fullKey, SEPARATOR);
|
|
||||||
valueBuilder.append(indents).append(comment.replace("\n", "\n" + indents));//Should end with new line (\n)
|
|
||||||
valueBuilder.setLength(valueBuilder.length() - indents.length());//Get rid of trailing \n and spaces
|
|
||||||
}
|
|
||||||
|
|
||||||
valueBuilder.append(line);
|
|
||||||
|
|
||||||
//Set the current ignored section for future iterations of while loop
|
|
||||||
//Don't set currentIgnoredSection to any ignoredSection sub-keys
|
|
||||||
if (isIgnoredParent)
|
|
||||||
currentIgnoredSection = fullKey;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
reader.close();
|
|
||||||
|
|
||||||
if (valueBuilder.length() > 0)
|
|
||||||
ignoredSectionsValues.put(currentIgnoredSection, valueBuilder.toString());
|
|
||||||
|
|
||||||
return ignoredSectionsValues;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void writeCommentIfExists(Map<String, String> comments, BufferedWriter writer, String fullKey, String indents) throws IOException {
|
|
||||||
String comment = comments.get(fullKey);
|
|
||||||
|
|
||||||
//Comments always end with new line (\n)
|
|
||||||
if (comment != null)
|
|
||||||
//Replaces all '\n' with '\n' + indents except for the last one
|
|
||||||
writer.write(indents + comment.substring(0, comment.length() - 1).replace("\n", "\n" + indents) + "\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
//Input: 'key1.key2' Result: 'key1'
|
|
||||||
private static void removeLastKey(StringBuilder keyBuilder) {
|
|
||||||
if (keyBuilder.length() == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
String keyString = keyBuilder.toString();
|
|
||||||
//Must be enclosed in brackets in case a regex special character is the separator
|
|
||||||
String[] split = keyString.split("[" + SEPARATOR + "]");
|
|
||||||
//Makes sure begin index isn't < 0 (error). Occurs when there is only one key in the path
|
|
||||||
int minIndex = Math.max(0, keyBuilder.length() - split[split.length - 1].length() - 1);
|
|
||||||
keyBuilder.replace(minIndex, keyBuilder.length(), "");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void appendNewLine(StringBuilder builder) {
|
|
||||||
if (builder.length() > 0)
|
|
||||||
builder.append("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,116 +0,0 @@
|
|||||||
package com.tchristofferson.configupdater;
|
|
||||||
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
|
|
||||||
public class KeyBuilder implements Cloneable {
|
|
||||||
|
|
||||||
private final FileConfiguration config;
|
|
||||||
private final char separator;
|
|
||||||
private final StringBuilder builder;
|
|
||||||
|
|
||||||
public KeyBuilder(FileConfiguration config, char separator) {
|
|
||||||
this.config = config;
|
|
||||||
this.separator = separator;
|
|
||||||
this.builder = new StringBuilder();
|
|
||||||
}
|
|
||||||
|
|
||||||
private KeyBuilder(KeyBuilder keyBuilder) {
|
|
||||||
this.config = keyBuilder.config;
|
|
||||||
this.separator = keyBuilder.separator;
|
|
||||||
this.builder = new StringBuilder(keyBuilder.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void parseLine(String line) {
|
|
||||||
line = line.trim();
|
|
||||||
String[] currentSplitLine = line.split(":");
|
|
||||||
String key = currentSplitLine[0].replace("'", "").replace("\"", "");
|
|
||||||
|
|
||||||
//Checks keyBuilder path against config to see if the path is valid.
|
|
||||||
//If the path doesn't exist in the config it keeps removing last key in keyBuilder.
|
|
||||||
while (builder.length() > 0 && !config.contains(builder.toString() + separator + key)) {
|
|
||||||
removeLastKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
//Add the separator if there is already a key inside keyBuilder
|
|
||||||
//If currentSplitLine[0] is 'key2' and keyBuilder contains 'key1' the result will be 'key1.' if '.' is the separator
|
|
||||||
if (builder.length() > 0)
|
|
||||||
builder.append(separator);
|
|
||||||
|
|
||||||
//Appends the current key to keyBuilder
|
|
||||||
//If keyBuilder is 'key1.' and currentSplitLine[0] is 'key2' the resulting keyBuilder will be 'key1.key2' if separator is '.'
|
|
||||||
builder.append(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLastKey() {
|
|
||||||
if (builder.length() == 0)
|
|
||||||
return "";
|
|
||||||
|
|
||||||
return builder.toString().split("[" + separator + "]")[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEmpty() {
|
|
||||||
return builder.length() == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Checks to see if the full key path represented by this instance is a sub-key of the key parameter
|
|
||||||
public boolean isSubKeyOf(String parentKey) {
|
|
||||||
return isSubKeyOf(parentKey, builder.toString(), separator);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Checks to see if subKey is a sub-key of the key path this instance represents
|
|
||||||
public boolean isSubKey(String subKey) {
|
|
||||||
return isSubKeyOf(builder.toString(), subKey, separator);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isSubKeyOf(String parentKey, String subKey, char separator) {
|
|
||||||
if (parentKey.isEmpty())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return subKey.startsWith(parentKey)
|
|
||||||
&& subKey.substring(parentKey.length()).startsWith(String.valueOf(separator));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getIndents(String key, char separator) {
|
|
||||||
String[] splitKey = key.split("[" + separator + "]");
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
|
|
||||||
for (int i = 1; i < splitKey.length; i++) {
|
|
||||||
builder.append(" ");
|
|
||||||
}
|
|
||||||
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isConfigSection() {
|
|
||||||
String key = builder.toString();
|
|
||||||
return config.isConfigurationSection(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isConfigSectionWithKeys() {
|
|
||||||
String key = builder.toString();
|
|
||||||
return config.isConfigurationSection(key) && !config.getConfigurationSection(key).getKeys(false).isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
//Input: 'key1.key2' Result: 'key1'
|
|
||||||
public void removeLastKey() {
|
|
||||||
if (builder.length() == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
String keyString = builder.toString();
|
|
||||||
//Must be enclosed in brackets in case a regex special character is the separator
|
|
||||||
String[] split = keyString.split("[" + separator + "]");
|
|
||||||
//Makes sure begin index isn't < 0 (error). Occurs when there is only one key in the path
|
|
||||||
int minIndex = Math.max(0, builder.length() - split[split.length - 1].length() - 1);
|
|
||||||
builder.replace(minIndex, builder.length(), "");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected KeyBuilder clone() {
|
|
||||||
return new KeyBuilder(this);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +1,17 @@
|
|||||||
package hu.ditservices;
|
package hu.ditservices;
|
||||||
|
|
||||||
import hu.ditservices.handlers.DITTabCompleter;
|
import hu.ditservices.handlers.*;
|
||||||
import hu.ditservices.handlers.SaveHandler;
|
import hu.ditservices.listeners.*;
|
||||||
import hu.ditservices.handlers.TabHandler;
|
|
||||||
import hu.ditservices.utils.*;
|
import hu.ditservices.utils.*;
|
||||||
import hu.ditservices.utils.Math;
|
import hu.ditservices.utils.Math;
|
||||||
import org.bstats.bukkit.Metrics;
|
import org.bstats.bukkit.Metrics;
|
||||||
import hu.ditservices.handlers.CommandHandler;
|
|
||||||
import hu.ditservices.listeners.ChatEvents;
|
|
||||||
import hu.ditservices.listeners.LogChat;
|
|
||||||
import hu.ditservices.listeners.LogCommand;
|
|
||||||
import hu.ditservices.listeners.LogConnect;
|
|
||||||
import com.tchristofferson.configupdater.ConfigUpdater;
|
import com.tchristofferson.configupdater.ConfigUpdater;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.PluginCommand;
|
import org.bukkit.command.PluginCommand;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
@ -26,8 +21,7 @@ import com.jeff_media.updatechecker.UserAgentBuilder;
|
|||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.lang.management.ManagementFactory;
|
import java.lang.management.ManagementFactory;
|
||||||
import java.util.Collections;
|
import java.util.*;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public final class STPlugin extends JavaPlugin implements CommandExecutor, Listener {
|
public final class STPlugin extends JavaPlugin implements CommandExecutor, Listener {
|
||||||
@ -38,6 +32,9 @@ public final class STPlugin extends JavaPlugin implements CommandExecutor, Liste
|
|||||||
|
|
||||||
public long ServerStartTime;
|
public long ServerStartTime;
|
||||||
|
|
||||||
|
private YamlConfiguration langConfig;
|
||||||
|
private ServerPasswordData serverPasswordData;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
instance = this;
|
instance = this;
|
||||||
@ -68,11 +65,24 @@ public final class STPlugin extends JavaPlugin implements CommandExecutor, Liste
|
|||||||
getServer().getPluginManager().registerEvents(new ChatEvents(this), this);
|
getServer().getPluginManager().registerEvents(new ChatEvents(this), this);
|
||||||
this.log.info(ChatColor.stripColor(this.getPrefix()) + "Custom Advancement Messages enabled!");
|
this.log.info(ChatColor.stripColor(this.getPrefix()) + "Custom Advancement Messages enabled!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.config.isSet("ServerPassword.enabled") && this.config.getBoolean("ServerPassword.enabled")) {
|
||||||
|
this.serverPasswordData = new ServerPasswordData(this);
|
||||||
|
PluginCommand sloginCommand = this.getCommand("slogin");
|
||||||
|
sloginCommand.setExecutor(new LoginCommandHandler(this));
|
||||||
|
getServer().getPluginManager().registerEvents(new ServerPasswordEvents(this), this);
|
||||||
|
this.log.info(ChatColor.stripColor(this.getPrefix()) + "Server Password enabled!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scheduleTasks() {
|
private void scheduleTasks() {
|
||||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new TPS(), 0, 1);
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new TPS(), 0, 1);
|
||||||
|
|
||||||
|
if (this.config.getBoolean("ClearDropItems.enabled")) {
|
||||||
|
new ClearDropItemsTask(this).runTaskTimer(this, 20L, 20L);
|
||||||
|
this.log.info(ChatColor.stripColor(this.getPrefix()) + "Clear dropped items enabled!");
|
||||||
|
}
|
||||||
|
|
||||||
if (this.config.getBoolean("Saving.enabled") && this.config.getInt("Saving.interval") > 0) {
|
if (this.config.getBoolean("Saving.enabled") && this.config.getInt("Saving.interval") > 0) {
|
||||||
long intervalTicks = Math.convert(Math.Convert.SECONDS, Math.Convert.TICKS, instance.config.getInt("Saving.interval"));
|
long intervalTicks = Math.convert(Math.Convert.SECONDS, Math.Convert.TICKS, instance.config.getInt("Saving.interval"));
|
||||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new SaveHandler(), 0L, intervalTicks);
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new SaveHandler(), 0L, intervalTicks);
|
||||||
@ -98,10 +108,11 @@ public final class STPlugin extends JavaPlugin implements CommandExecutor, Liste
|
|||||||
private boolean initPlugin() {
|
private boolean initPlugin() {
|
||||||
try {
|
try {
|
||||||
this.ServerStartTime = ManagementFactory.getRuntimeMXBean().getStartTime();
|
this.ServerStartTime = ManagementFactory.getRuntimeMXBean().getStartTime();
|
||||||
if (Version.ServerVersion.isCurrentLower(Version.ServerVersion.v1_12_R1) ||
|
if (Version.ServerVersion.isCurrentLower(Version.ServerVersion.v1_12_R1)) {
|
||||||
Version.ServerVersion.isCurrentHigher(Version.ServerVersion.v1_21_4_R1))
|
throw new Exception("The server version is not supported! Update to to atleast 1.12 version to use this plugin!");
|
||||||
{
|
}
|
||||||
throw new Exception("The server version is not supported! Update to a version between 1.12 - 1.21.4 to run this plugin.");
|
if (Version.ServerVersion.isCurrentHigher(Version.ServerVersion.v1_21_5_R1)) {
|
||||||
|
this.log.warning(ChatColor.stripColor(this.getPrefix()) + "You are running a server version which is not tested with this plugin, errors can be occur!");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.reload()) {
|
if (this.reload()) {
|
||||||
@ -121,8 +132,8 @@ public final class STPlugin extends JavaPlugin implements CommandExecutor, Liste
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
this.log.warning("[SimplifyTools] - INITIALIZATION ERROR: " + e.getMessage());
|
this.log.warning(ChatColor.stripColor(this.getPrefix()) + "INITIALIZATION ERROR: " + e.getMessage());
|
||||||
this.log.warning("[SimplifyTools] - Plugin disabled!");
|
this.log.warning(ChatColor.stripColor(this.getPrefix()) + "Plugin disabled!");
|
||||||
this.setEnabled(false);
|
this.setEnabled(false);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -180,6 +191,56 @@ public final class STPlugin extends JavaPlugin implements CommandExecutor, Liste
|
|||||||
return returnText.toString();
|
return returnText.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ServerPasswordData getServerPasswordData() {
|
||||||
|
return this.serverPasswordData;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void copyDefaultLang(String filename, File langFolder) {
|
||||||
|
File outFile = new File(langFolder, filename);
|
||||||
|
|
||||||
|
if (!outFile.exists()) {
|
||||||
|
try (InputStream in = getResource(filename);
|
||||||
|
OutputStream out = new FileOutputStream(outFile)) {
|
||||||
|
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int length;
|
||||||
|
while ((length = in.read(buffer)) > 0) {
|
||||||
|
out.write(buffer, 0, length);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
this.log.warning(ChatColor.stripColor(this.getPrefix()) + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initLocalization() throws IOException {
|
||||||
|
File langFolder = new File(getDataFolder(), "lang");
|
||||||
|
if (!langFolder.exists()) {
|
||||||
|
langFolder.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] languages = {"en", "hu"};
|
||||||
|
for (String l : languages) {
|
||||||
|
File langFile = new File(langFolder, l + ".yml");
|
||||||
|
if (!langFile.exists()) {
|
||||||
|
copyDefaultLang(l + ".yml", langFolder);
|
||||||
|
}
|
||||||
|
ConfigUpdater.update(this, l + ".yml", langFile, Collections.emptyList());
|
||||||
|
}
|
||||||
|
|
||||||
|
String lang = this.config.getString("language", "en");
|
||||||
|
File langFile = new File(getDataFolder(), "lang" + File.separator + lang + ".yml");
|
||||||
|
if (!langFile.exists()) {
|
||||||
|
getLogger().warning("Language file for '" + lang + "' not found. Falling back to English.");
|
||||||
|
langFile = new File(getDataFolder(), "lang" + File.separator + "en.yml");
|
||||||
|
}
|
||||||
|
this.langConfig = YamlConfiguration.loadConfiguration(langFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTranslatedText(String key) {
|
||||||
|
return langConfig.getString(key, "Translation not found: " + key);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean reload(){
|
public boolean reload(){
|
||||||
File configFile = new File(getDataFolder(), "config.yml");
|
File configFile = new File(getDataFolder(), "config.yml");
|
||||||
|
|
||||||
@ -189,10 +250,16 @@ public final class STPlugin extends JavaPlugin implements CommandExecutor, Liste
|
|||||||
}
|
}
|
||||||
ConfigUpdater.update(this, "config.yml", configFile, Collections.emptyList());
|
ConfigUpdater.update(this, "config.yml", configFile, Collections.emptyList());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
this.log.warning(ChatColor.stripColor(this.getPrefix()) + e.getMessage());
|
||||||
}
|
}
|
||||||
reloadConfig();
|
reloadConfig();
|
||||||
this.config = getConfig();
|
this.config = getConfig();
|
||||||
|
try {
|
||||||
|
this.initLocalization();
|
||||||
|
} catch (IOException e) {
|
||||||
|
this.log.warning(ChatColor.stripColor(this.getPrefix()) + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ public class PingCommand {
|
|||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
try {
|
try {
|
||||||
player.sendMessage(plugin.getPrefix() + "Your response time to the server: " + Server.getPlayerPing(player) + " ms");
|
player.sendMessage(plugin.getPrefix() + plugin.getTranslatedText("cmd.ping") + Server.getPlayerPing(player) + " ms");
|
||||||
return true;
|
return true;
|
||||||
} catch (IllegalArgumentException | SecurityException e) {
|
} catch (IllegalArgumentException | SecurityException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -11,30 +11,30 @@ public class PluginManagerCommand {
|
|||||||
public static boolean LoadPlugin(CommandSender sender, String[] args){
|
public static boolean LoadPlugin(CommandSender sender, String[] args){
|
||||||
Plugin plugin = Bukkit.getPluginManager().getPlugin(args[2]);
|
Plugin plugin = Bukkit.getPluginManager().getPlugin(args[2]);
|
||||||
if (plugin == null) {
|
if (plugin == null) {
|
||||||
sender.sendMessage(STPlugin.getInstance().getPrefix()+"Plugin not exist!");
|
sender.sendMessage(STPlugin.getInstance().getPrefix()+ STPlugin.getInstance().getTranslatedText("pmanager.not.exist"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (plugin.isEnabled()){
|
if (plugin.isEnabled()){
|
||||||
sender.sendMessage(STPlugin.getInstance().getPrefix()+"Plugin "+plugin.getName()+" already enabled!");
|
sender.sendMessage(STPlugin.getInstance().getPrefix()+"Plugin "+plugin.getName()+STPlugin.getInstance().getTranslatedText("pmanager.already.enabled"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getPluginManager().enablePlugin(plugin);
|
Bukkit.getPluginManager().enablePlugin(plugin);
|
||||||
sender.sendMessage(STPlugin.getInstance().getPrefix()+"Plugin "+plugin.getName()+" successfully enabled!");
|
sender.sendMessage(STPlugin.getInstance().getPrefix()+"Plugin "+plugin.getName()+STPlugin.getInstance().getTranslatedText("pmanager.success.enabled"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
public static boolean UnloadPlugin(CommandSender sender, String[] args){
|
public static boolean UnloadPlugin(CommandSender sender, String[] args){
|
||||||
Plugin plugin = Bukkit.getPluginManager().getPlugin(args[2]);
|
Plugin plugin = Bukkit.getPluginManager().getPlugin(args[2]);
|
||||||
if (plugin == null) {
|
if (plugin == null) {
|
||||||
sender.sendMessage(STPlugin.getInstance().getPrefix()+"Plugin not exist!");
|
sender.sendMessage(STPlugin.getInstance().getPrefix()+STPlugin.getInstance().getTranslatedText("pmanager.not.exist"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!plugin.isEnabled()){
|
if (!plugin.isEnabled()){
|
||||||
sender.sendMessage(STPlugin.getInstance().getPrefix()+"Plugin "+plugin.getName()+" already disabled!");
|
sender.sendMessage(STPlugin.getInstance().getPrefix()+"Plugin "+plugin.getName()+STPlugin.getInstance().getTranslatedText("pmanager.already.disabled"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Bukkit.getPluginManager().disablePlugin(plugin);
|
Bukkit.getPluginManager().disablePlugin(plugin);
|
||||||
sender.sendMessage(STPlugin.getInstance().getPrefix()+"Plugin "+plugin.getName()+" successfully disabled!");
|
sender.sendMessage(STPlugin.getInstance().getPrefix()+"Plugin "+plugin.getName()+STPlugin.getInstance().getTranslatedText("pmanager.success.disabled"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,15 +9,18 @@ public class SettingsCommand {
|
|||||||
public static boolean Run(CommandSender sender) {
|
public static boolean Run(CommandSender sender) {
|
||||||
STPlugin plugin = STPlugin.getInstance();
|
STPlugin plugin = STPlugin.getInstance();
|
||||||
|
|
||||||
|
String enabled = plugin.getTranslatedText("settings.enabled");
|
||||||
|
String disabled = plugin.getTranslatedText("settings.disabled");
|
||||||
|
|
||||||
sender.sendMessage( ChatColor.GREEN+" === Plugin Information === " + "\n"
|
sender.sendMessage( ChatColor.GREEN+" === Plugin Information === " + "\n"
|
||||||
+ ChatColor.GREEN+"Plugin Version: " + ChatColor.translateAlternateColorCodes('&',"&a[&fSimplify&7Tools&2] &4- &f") + plugin.getDescription().getVersion() + "\n"
|
+ ChatColor.GREEN + "Plugin " + plugin.getTranslatedText("version.pre.text") + ChatColor.translateAlternateColorCodes('&',"&a[&fSimplify&7Tools&2] &4- &f") + plugin.getDescription().getVersion() + "\n"
|
||||||
+ ChatColor.GREEN+"Server Version: " + Version.ServerVersion.getCurrent().toString() + "\n"
|
+ ChatColor.GREEN + plugin.getTranslatedText("settings.server") + plugin.getTranslatedText("version.pre.text") + Version.ServerVersion.getCurrent().toString() + "\n"
|
||||||
+ ChatColor.GREEN+" -------- Features -------- " + "\n"
|
+ ChatColor.GREEN + " -------- " + plugin.getTranslatedText("settings.features") +" -------- " + "\n"
|
||||||
+ ChatColor.GREEN+"Tab customization: "+(plugin.getConfig().getBoolean("Tab.enabled") ? ChatColor.GREEN + "Enabled" : ChatColor.RED+"Disabled") + "\n"
|
+ ChatColor.GREEN + plugin.getTranslatedText("settings.feature.tab") + (plugin.getConfig().getBoolean("Tab.enabled") ? ChatColor.GREEN + enabled : ChatColor.RED + disabled) + "\n"
|
||||||
+ ChatColor.GREEN+"Custom Advancement Msg: " + (plugin.getConfig().getBoolean("CustomAdvancement.enabled") ? ChatColor.GREEN+"Enabled" : ChatColor.RED+"Disabled") + "\n"
|
+ ChatColor.GREEN + plugin.getTranslatedText("settings.feature.CustomAdvancementMsg") + (plugin.getConfig().getBoolean("CustomAdvancement.enabled") ? ChatColor.GREEN + enabled : ChatColor.RED + disabled) + "\n"
|
||||||
+ ChatColor.GREEN+"Auto saving: " + (plugin.getConfig().getBoolean("Saving.enabled") ? ChatColor.GREEN+"Enabled" : ChatColor.RED+"Disabled") + "\n"
|
+ ChatColor.GREEN + plugin.getTranslatedText("settings.feature.AutoSave") + (plugin.getConfig().getBoolean("Saving.enabled") ? ChatColor.GREEN + enabled : ChatColor.RED + disabled) + "\n"
|
||||||
+ ChatColor.GREEN+"Plugin manager: " + (plugin.getConfig().getBoolean("PluginManager.enabled") ? ChatColor.GREEN+"Enabled" : ChatColor.RED+"Disabled") + "\n"
|
+ ChatColor.GREEN + plugin.getTranslatedText("settings.feature.pmanager") + (plugin.getConfig().getBoolean("PluginManager.enabled") ? ChatColor.GREEN + enabled : ChatColor.RED + disabled) + "\n"
|
||||||
+ ChatColor.GREEN+" ========================== "
|
+ ChatColor.GREEN + " ========================== "
|
||||||
);
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -10,13 +10,23 @@ public class StatCommand {
|
|||||||
public static boolean Run(CommandSender sender){
|
public static boolean Run(CommandSender sender){
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
|
|
||||||
player.sendMessage(STPlugin.getInstance().getPrefix()+ ChatColor.GREEN+" === Your statistics === ");
|
// Calculate total play time from ticks (Minecraft runs at 20 ticks per second)
|
||||||
player.sendMessage(ChatColor.AQUA+"Connects: "+(player.getStatistic(Statistic.LEAVE_GAME)+1));
|
long totalTicks = player.getStatistic(Statistic.TOTAL_WORLD_TIME);
|
||||||
player.sendMessage(ChatColor.AQUA+"Deaths: "+player.getStatistic(Statistic.DEATHS));
|
long totalSeconds = totalTicks / 20;
|
||||||
player.sendMessage(ChatColor.AQUA+"Mob kills: "+player.getStatistic(Statistic.MOB_KILLS));
|
long hours = totalSeconds / 3600;
|
||||||
player.sendMessage(ChatColor.AQUA+"Player kills: "+player.getStatistic(Statistic.PLAYER_KILLS));
|
long minutes = (totalSeconds % 3600) / 60;
|
||||||
player.sendMessage(ChatColor.AQUA+"Sleep count: "+player.getStatistic(Statistic.SLEEP_IN_BED));
|
long seconds = totalSeconds % 60;
|
||||||
player.sendMessage(ChatColor.AQUA+"Enchant count: "+player.getStatistic(Statistic.ITEM_ENCHANTED));
|
STPlugin plugin = STPlugin.getInstance();
|
||||||
|
plugin.getTranslatedText("");
|
||||||
|
|
||||||
|
player.sendMessage(STPlugin.getInstance().getPrefix() + ChatColor.GREEN + " === "+plugin.getTranslatedText("stats.header")+" === ");
|
||||||
|
player.sendMessage(ChatColor.AQUA+plugin.getTranslatedText("stats.connects") + (player.getStatistic(Statistic.LEAVE_GAME)+1));
|
||||||
|
player.sendMessage(ChatColor.AQUA+plugin.getTranslatedText("stats.deaths") + player.getStatistic(Statistic.DEATHS));
|
||||||
|
player.sendMessage(ChatColor.AQUA+plugin.getTranslatedText("stats.MobKills") + player.getStatistic(Statistic.MOB_KILLS));
|
||||||
|
player.sendMessage(ChatColor.AQUA+plugin.getTranslatedText("stats.PlayerKills") + player.getStatistic(Statistic.PLAYER_KILLS));
|
||||||
|
player.sendMessage(ChatColor.AQUA+plugin.getTranslatedText("stats.sleeps") + player.getStatistic(Statistic.SLEEP_IN_BED));
|
||||||
|
player.sendMessage(ChatColor.AQUA+plugin.getTranslatedText("stats.enchants") + player.getStatistic(Statistic.ITEM_ENCHANTED));
|
||||||
|
player.sendMessage(ChatColor.AQUA + plugin.getTranslatedText("stats.totaltime") + hours + plugin.getTranslatedText("stats.hour") + minutes + plugin.getTranslatedText("stats.minutes") + seconds + plugin.getTranslatedText("stats.seconds"));
|
||||||
player.sendMessage(ChatColor.GREEN+" =================== ");
|
player.sendMessage(ChatColor.GREEN+" =================== ");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,76 @@
|
|||||||
|
package hu.ditservices.handlers;
|
||||||
|
|
||||||
|
import hu.ditservices.STPlugin;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.Item;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ClearDropItemsTask extends BukkitRunnable {
|
||||||
|
private final STPlugin plugin;
|
||||||
|
private int countdown;
|
||||||
|
private final int interval; // In seconds
|
||||||
|
private final List<String> exceptItemList;
|
||||||
|
private final List<String> exceptWorldList;
|
||||||
|
private final boolean shouldBroadcast;
|
||||||
|
|
||||||
|
public ClearDropItemsTask(STPlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.interval = plugin.getConfig().getInt("ClearDropItems.interval", 300);
|
||||||
|
this.countdown = this.interval;
|
||||||
|
// Get the exception list from the config (should be a list of item type names, e.g., ["DIAMOND", "GOLD_INGOT"])
|
||||||
|
this.exceptItemList = plugin.getConfig().getStringList("ClearDropItems.except");
|
||||||
|
this.exceptWorldList = plugin.getConfig().getStringList("ClearDropItems.skipWorlds");
|
||||||
|
this.shouldBroadcast = plugin.getConfig().getBoolean("ClearDropItems.broadcastMsg", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (this.shouldBroadcast) {
|
||||||
|
if (countdown == 60) {
|
||||||
|
Bukkit.broadcastMessage(plugin.getPrefix() + ChatColor.RED + plugin.getTranslatedText("cleardropitems.oneMin"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (countdown == 10) {
|
||||||
|
Bukkit.broadcastMessage(plugin.getPrefix() + ChatColor.RED + plugin.getTranslatedText("cleardropitems.tenSec"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (countdown <= 0) {
|
||||||
|
int removed = 0;
|
||||||
|
|
||||||
|
for (World world : Bukkit.getWorlds()) {
|
||||||
|
if (this.exceptWorldList.contains(world.getName())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (Entity entity : world.getEntities()) {
|
||||||
|
|
||||||
|
if (entity instanceof Item) {
|
||||||
|
Item item = (Item) entity;
|
||||||
|
String itemType = item.getItemStack().getType().toString();
|
||||||
|
// Check if the item is in the exception list
|
||||||
|
boolean isException = this.exceptItemList.stream()
|
||||||
|
.anyMatch(ex -> ex.equalsIgnoreCase(itemType));
|
||||||
|
if (!isException) {
|
||||||
|
item.remove();
|
||||||
|
removed++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.shouldBroadcast) {
|
||||||
|
Bukkit.broadcastMessage(plugin.getPrefix() + ChatColor.GREEN + plugin.getTranslatedText("cleardropitems.cleared").replace("%REMOVECOUNT%",String.valueOf(removed)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset the countdown to the interval for the next cycle
|
||||||
|
countdown = interval;
|
||||||
|
} else {
|
||||||
|
countdown--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -18,7 +18,7 @@ public class CommandHandler implements CommandExecutor {
|
|||||||
|
|
||||||
public CommandHandler(final STPlugin instance) {
|
public CommandHandler(final STPlugin instance) {
|
||||||
this.plugin = instance;
|
this.plugin = instance;
|
||||||
this.noArgMsg = plugin.getPrefix() + ChatColor.DARK_RED + "To list all SimplifyTools commands use the '/help SIMPLIFYTOOLS' command!";
|
this.noArgMsg = plugin.getPrefix() + ChatColor.DARK_RED + plugin.getTranslatedText("list.help");
|
||||||
this.cd = new Cooldown(plugin);
|
this.cd = new Cooldown(plugin);
|
||||||
this.config = plugin.getConfig();
|
this.config = plugin.getConfig();
|
||||||
}
|
}
|
||||||
@ -44,7 +44,7 @@ public class CommandHandler implements CommandExecutor {
|
|||||||
|
|
||||||
if (command.getName().equals("st") && (args.length == 0 || args[0].contains("help")))
|
if (command.getName().equals("st") && (args.length == 0 || args[0].contains("help")))
|
||||||
{
|
{
|
||||||
sender.sendMessage(plugin.getPrefix() + ChatColor.GREEN+"Version: " + plugin.getDescription().getVersion());
|
sender.sendMessage(plugin.getPrefix() + ChatColor.GREEN+plugin.getTranslatedText("version.pre.text") + plugin.getDescription().getVersion());
|
||||||
sender.sendMessage(this.noArgMsg);
|
sender.sendMessage(this.noArgMsg);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -58,13 +58,13 @@ public class CommandHandler implements CommandExecutor {
|
|||||||
|
|
||||||
if(plugin.reload()){
|
if(plugin.reload()){
|
||||||
sender.sendMessage(plugin.getPrefix()+ChatColor.GREEN+"Successfully reload!" + "\n"
|
sender.sendMessage(plugin.getPrefix()+ChatColor.GREEN+"Successfully reload!" + "\n"
|
||||||
+ plugin.getPrefix() + ChatColor.RED + "Notice: Restart your server if the settings didn't applied.");
|
+ plugin.getPrefix() + ChatColor.RED + plugin.getTranslatedText("notice.settings.not.applied"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command.getName().equals("st") && args[0].contains("tps") && sender.hasPermission("st.tps")) {
|
if (command.getName().equals("st") && args[0].contains("tps") && sender.hasPermission("st.tps")) {
|
||||||
sender.sendMessage(plugin.getPrefix() + ChatColor.GREEN+"Plugin Calculated TPS: "+TPS.getColor()+String.format("%.2f", TPS.getTPS()));
|
sender.sendMessage(plugin.getPrefix() + ChatColor.GREEN+plugin.getTranslatedText("plugin.calculated.tps")+TPS.getColor()+String.format("%.2f", TPS.getTPS()));
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -72,7 +72,7 @@ public class CommandHandler implements CommandExecutor {
|
|||||||
if (command.getName().equalsIgnoreCase("st") && args[0].contains("pmanager")) {
|
if (command.getName().equalsIgnoreCase("st") && args[0].contains("pmanager")) {
|
||||||
if (sender.hasPermission("st.pmanager.unload") || sender.hasPermission("st.pmanager.load") || sender.hasPermission("st.pmanager")) {
|
if (sender.hasPermission("st.pmanager.unload") || sender.hasPermission("st.pmanager.load") || sender.hasPermission("st.pmanager")) {
|
||||||
if (args.length==1){
|
if (args.length==1){
|
||||||
sender.sendMessage(plugin.getPrefix() + ChatColor.DARK_RED+"Invalid arguments!");
|
sender.sendMessage(plugin.getPrefix() + ChatColor.DARK_RED+plugin.getTranslatedText("invalid.arguments"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (config.getBoolean("PluginManager.enabled")) {
|
if (config.getBoolean("PluginManager.enabled")) {
|
||||||
@ -85,7 +85,7 @@ public class CommandHandler implements CommandExecutor {
|
|||||||
PluginManagerCommand.UnloadPlugin(sender, args);
|
PluginManagerCommand.UnloadPlugin(sender, args);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(plugin.getPrefix() + ChatColor.DARK_RED + "Plugin manager commands are disabled in the config!");
|
sender.sendMessage(plugin.getPrefix() + ChatColor.DARK_RED + plugin.getTranslatedText("pmanager.disabled"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package hu.ditservices.handlers;
|
package hu.ditservices.handlers;
|
||||||
|
|
||||||
|
import hu.ditservices.STPlugin;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.*;
|
import org.bukkit.command.*;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
@ -58,8 +59,12 @@ public class DITTabCompleter implements TabCompleter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("pmanager")&& args[1].equalsIgnoreCase("unload") || args[1].equalsIgnoreCase("load")) {
|
if (args[0].equalsIgnoreCase("pmanager") && args[1].equalsIgnoreCase("unload") || args[1].equalsIgnoreCase("load")) {
|
||||||
if (args.length == 3) {
|
if ((args.length == 3) && STPlugin.getInstance().getConfig().getBoolean("PluginManager.enabled") &
|
||||||
|
(commandSender.hasPermission("st.pmanager")
|
||||||
|
|| commandSender.hasPermission("st.pmanager.load")
|
||||||
|
|| commandSender.hasPermission("st.pmanager.unload"))
|
||||||
|
) {
|
||||||
result.clear();
|
result.clear();
|
||||||
PluginManager pm = Bukkit.getServer().getPluginManager();
|
PluginManager pm = Bukkit.getServer().getPluginManager();
|
||||||
for (Plugin pl : pm.getPlugins()) {
|
for (Plugin pl : pm.getPlugins()) {
|
||||||
|
@ -1,185 +0,0 @@
|
|||||||
package hu.ditservices.handlers;
|
|
||||||
/*
|
|
||||||
import hu.ditservices.DITSystem;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.PluginCommand;
|
|
||||||
import org.bukkit.command.SimpleCommandMap;
|
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.plugin.*;
|
|
||||||
import java.io.File;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
|
|
||||||
public class DitPluginManager {
|
|
||||||
private static DITSystem plugin;
|
|
||||||
public DitPluginManager(DITSystem instance){
|
|
||||||
plugin = instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int load(final String pluginName) {
|
|
||||||
PluginManager pm = Bukkit.getServer().getPluginManager();
|
|
||||||
boolean there = false;
|
|
||||||
for (Plugin pl : pm.getPlugins()){
|
|
||||||
if (pl.getName().toLowerCase().startsWith(pluginName)){
|
|
||||||
there = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (there)
|
|
||||||
{ return 1;} //plugin already exists
|
|
||||||
else {
|
|
||||||
String name = "";
|
|
||||||
String path = plugin.getDataFolder().getParent();
|
|
||||||
File folder = new File(path);
|
|
||||||
ArrayList<File> files = new ArrayList<File>();
|
|
||||||
File[] listOfFiles = folder.listFiles();
|
|
||||||
for (File compare : listOfFiles) {
|
|
||||||
if (compare.isFile()) {
|
|
||||||
try {
|
|
||||||
name = plugin.getPluginLoader().getPluginDescription(compare).getName();
|
|
||||||
} catch (InvalidDescriptionException e) {
|
|
||||||
plugin.getLogger().warning("[Loading Plugin] " + compare.getName() + " didn't match");
|
|
||||||
}
|
|
||||||
if (name.toLowerCase().startsWith(pluginName.toLowerCase())) {
|
|
||||||
files.add(compare);
|
|
||||||
try {
|
|
||||||
Bukkit.getServer().getPluginManager().loadPlugin(compare);
|
|
||||||
} catch (UnknownDependencyException e) {
|
|
||||||
return 2; //missing dependent plugin
|
|
||||||
} catch (InvalidPluginException e) {
|
|
||||||
return -1; //not a plugin
|
|
||||||
} catch (InvalidDescriptionException e) {
|
|
||||||
return 3; //invalid description
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Plugin[] plugins = pm.getPlugins();
|
|
||||||
for (Plugin pl : plugins) {
|
|
||||||
for (File compare : files) {
|
|
||||||
try {
|
|
||||||
if (pl.getName().equalsIgnoreCase(plugin.getPluginLoader().getPluginDescription(compare).getName()))
|
|
||||||
if (!pl.isEnabled()){
|
|
||||||
pm.enablePlugin(pl);
|
|
||||||
}else { return 5; }
|
|
||||||
} catch (InvalidDescriptionException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0; //success
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static int unload(String pluginName) {
|
|
||||||
pluginName = pluginName.toLowerCase().trim();
|
|
||||||
PluginManager manager = Bukkit.getServer().getPluginManager();
|
|
||||||
SimplePluginManager spm = (SimplePluginManager) manager;
|
|
||||||
SimpleCommandMap commandMap = null;
|
|
||||||
List<Plugin> plugins = null;
|
|
||||||
Map<String, Plugin> lookupNames = null;
|
|
||||||
Map<String, Command> knownCommands = null;
|
|
||||||
Map<Event, SortedSet<RegisteredListener>> listeners = null;
|
|
||||||
boolean reloadlisteners = true;
|
|
||||||
try {
|
|
||||||
if (spm != null) {
|
|
||||||
Field pluginsField = spm.getClass().getDeclaredField("plugins");
|
|
||||||
pluginsField.setAccessible(true);
|
|
||||||
plugins = (List<Plugin>) pluginsField.get(spm);
|
|
||||||
|
|
||||||
Field lookupNamesField = spm.getClass().getDeclaredField("lookupNames");
|
|
||||||
lookupNamesField.setAccessible(true);
|
|
||||||
lookupNames = (Map<String, Plugin>) lookupNamesField.get(spm);
|
|
||||||
|
|
||||||
try {
|
|
||||||
Field listenersField = spm.getClass().getDeclaredField("listeners");
|
|
||||||
listenersField.setAccessible(true);
|
|
||||||
listeners = (Map<Event, SortedSet<RegisteredListener>>) listenersField.get(spm);
|
|
||||||
} catch (Exception e) {
|
|
||||||
reloadlisteners = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Field commandMapField = spm.getClass().getDeclaredField("commandMap");
|
|
||||||
commandMapField.setAccessible(true);
|
|
||||||
commandMap = (SimpleCommandMap) commandMapField.get(spm);
|
|
||||||
|
|
||||||
Field knownCommandsField = commandMap.getClass().getDeclaredField("knownCommands");
|
|
||||||
knownCommandsField.setAccessible(true);
|
|
||||||
knownCommands = (Map<String, Command>) knownCommandsField.get(commandMap);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
boolean in = false;
|
|
||||||
|
|
||||||
for (Plugin pl : Bukkit.getServer().getPluginManager().getPlugins()) {
|
|
||||||
if (in)
|
|
||||||
break;
|
|
||||||
if (pl.getName().toLowerCase().startsWith(pluginName.toLowerCase())) {
|
|
||||||
if (pl.isEnabled()) {
|
|
||||||
manager.disablePlugin(pl);
|
|
||||||
if (plugins != null && plugins.contains(pl))
|
|
||||||
plugins.remove(pl);
|
|
||||||
|
|
||||||
if (lookupNames != null && lookupNames.containsKey(pl.getName())) {
|
|
||||||
lookupNames.remove(pl.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (listeners != null && reloadlisteners) {
|
|
||||||
for (SortedSet<RegisteredListener> set : listeners.values()) {
|
|
||||||
for (Iterator<RegisteredListener> it = set.iterator(); it.hasNext(); ) {
|
|
||||||
RegisteredListener value = it.next();
|
|
||||||
|
|
||||||
if (value.getPlugin() == pl) {
|
|
||||||
it.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (commandMap != null) {
|
|
||||||
|
|
||||||
for (Iterator<Map.Entry<String, Command>> it = knownCommands.entrySet().iterator(); it.hasNext(); ) {
|
|
||||||
Map.Entry<String, Command> entry = it.next();
|
|
||||||
if (entry.getValue() instanceof PluginCommand) {
|
|
||||||
PluginCommand c = (PluginCommand) entry.getValue();
|
|
||||||
if (c.getPlugin() == pl) {
|
|
||||||
c.unregister(commandMap);
|
|
||||||
it.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (Plugin plu : Bukkit.getServer().getPluginManager().getPlugins()) {
|
|
||||||
if (plu.getDescription().getDepend() != null) {
|
|
||||||
for (String depend : plu.getDescription().getDepend()) {
|
|
||||||
if (depend.equalsIgnoreCase(pl.getName())) {
|
|
||||||
plugin.getLogger().info("[Unloading Plugin] " + plu.getName() + " must be disabled!");
|
|
||||||
unload(plu.getName());
|
|
||||||
return 1; //dependencies also disabled
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
in = true;
|
|
||||||
} else { return 5; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!in) {
|
|
||||||
plugin.getLogger().info("Not an existing plugin");
|
|
||||||
return -1; //non-existent
|
|
||||||
}
|
|
||||||
System.gc();
|
|
||||||
return 0; //success
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
*/
|
|
@ -0,0 +1,63 @@
|
|||||||
|
package hu.ditservices.handlers;
|
||||||
|
|
||||||
|
import hu.ditservices.STPlugin;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class LoginCommandHandler implements CommandExecutor {
|
||||||
|
|
||||||
|
private final STPlugin plugin;
|
||||||
|
|
||||||
|
public LoginCommandHandler(STPlugin instance) {
|
||||||
|
this.plugin = instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Method to authenticate the player
|
||||||
|
public boolean authenticate(Player player, String password) {
|
||||||
|
if (plugin.getServerPasswordData().getServerPassword().equals(password)) {
|
||||||
|
if (plugin.getConfig().getBoolean("ServerPassword.preventInventory")) {
|
||||||
|
player.getInventory().setContents(plugin.getServerPasswordData().getInventoryMap().get(player.getUniqueId()));
|
||||||
|
player.getInventory().setArmorContents(plugin.getServerPasswordData().getArmorMap().get(player.getUniqueId()));
|
||||||
|
}
|
||||||
|
plugin.getServerPasswordData().getAuthenticatedPlayers().put(player.getUniqueId(), true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if (!(sender instanceof Player)) {
|
||||||
|
sender.sendMessage("Only players can execute this command.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = (Player) sender;
|
||||||
|
UUID pUuid = player.getUniqueId();
|
||||||
|
|
||||||
|
if (args.length != 1) {
|
||||||
|
player.sendMessage(plugin.getTranslatedText("cmd.usage.login"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (plugin.getServerPasswordData().getAuthenticatedPlayers().getOrDefault(pUuid,false)) {
|
||||||
|
player.sendMessage(ChatColor.GREEN + plugin.getTranslatedText("serverpassword.already.auth"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.authenticate(player, args[0])) {
|
||||||
|
player.sendMessage(ChatColor.GREEN + plugin.getTranslatedText("serverpassword.success.auth"));
|
||||||
|
plugin.getServerPasswordData().getInventoryMap().remove(pUuid);
|
||||||
|
plugin.getServerPasswordData().getArmorMap().remove(pUuid);
|
||||||
|
} else {
|
||||||
|
player.sendMessage(ChatColor.RED + plugin.getTranslatedText("serverpassword.incorrect"));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -39,9 +39,10 @@ public class TabHandler {
|
|||||||
|
|
||||||
if(this.init()){
|
if(this.init()){
|
||||||
if (headerComponents.isEmpty() && footerComponents.isEmpty()){
|
if (headerComponents.isEmpty() && footerComponents.isEmpty()){
|
||||||
plugin.getLogger().warning(plugin.getPrefix()+"TAB customization disabled because empty customization config or feature related errors!");
|
plugin.getLogger().warning(ChatColor.stripColor(plugin.getPrefix()) + "TAB customization disabled because empty customization config or feature related errors!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
plugin.getLogger().info("- TAB customization enabled!");
|
||||||
this.updateTab();
|
this.updateTab();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,7 +150,7 @@ public class TabHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
plugin.getLogger().warning(ChatColor.stripColor(plugin.getPrefix()) + e.getMessage());
|
||||||
}
|
}
|
||||||
},0,Math.convert(Math.Convert.SECONDS,Math.Convert.TICKS,this.refreshRate));
|
},0,Math.convert(Math.Convert.SECONDS,Math.Convert.TICKS,this.refreshRate));
|
||||||
|
|
||||||
@ -184,7 +185,7 @@ public class TabHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
e.printStackTrace();
|
plugin.getLogger().warning(ChatColor.stripColor(plugin.getPrefix()) + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
127
src/main/java/hu/ditservices/listeners/ServerPasswordEvents.java
Normal file
127
src/main/java/hu/ditservices/listeners/ServerPasswordEvents.java
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
package hu.ditservices.listeners;
|
||||||
|
|
||||||
|
import hu.ditservices.STPlugin;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class ServerPasswordEvents implements Listener {
|
||||||
|
private STPlugin plugin;
|
||||||
|
private FileConfiguration config;
|
||||||
|
|
||||||
|
public ServerPasswordEvents(STPlugin instance){
|
||||||
|
this.plugin = instance;
|
||||||
|
this.config = plugin.getConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean skipIfOpPlayer(Player player)
|
||||||
|
{
|
||||||
|
return (player.isOp() && config.getBoolean("ServerPassword.exceptOps")) || player.hasPermission("st.slogin.skip");
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
|
if (skipIfOpPlayer(player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((!config.getBoolean("ServerPassword.rememberUntilRestart"))
|
||||||
|
|| (!plugin.getServerPasswordData().getAuthenticatedPlayers().getOrDefault(player.getUniqueId(),false))) {
|
||||||
|
plugin.getServerPasswordData().getAuthenticatedPlayers().put(player.getUniqueId(),false);
|
||||||
|
if (config.getBoolean("ServerPassword.preventInventory")) {
|
||||||
|
// Store and clear inventory
|
||||||
|
plugin.getServerPasswordData().getInventoryMap().put(player.getUniqueId(), player.getInventory().getContents());
|
||||||
|
plugin.getServerPasswordData().getArmorMap().put(player.getUniqueId(), player.getInventory().getArmorContents());
|
||||||
|
player.getInventory().clear();
|
||||||
|
player.getInventory().setArmorContents(null);
|
||||||
|
}
|
||||||
|
player.sendMessage(ChatColor.RED + plugin.getTranslatedText("serverpassword.enabled"));
|
||||||
|
player.sendMessage(plugin.getTranslatedText("serverpassword.note"));
|
||||||
|
BukkitRunnable authReminder = new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
// Check if the player is authenticated, default to false if not present.
|
||||||
|
if (plugin.getServerPasswordData().getAuthenticatedPlayers().getOrDefault(player.getUniqueId(), false)) {
|
||||||
|
this.cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
player.sendMessage(ChatColor.RED + plugin.getTranslatedText("serverpassword.login"));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
authReminder.runTaskTimer(plugin, 0L, 100L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerMove(PlayerMoveEvent event) {
|
||||||
|
if (skipIfOpPlayer(event.getPlayer())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ((!plugin.getServerPasswordData().getAuthenticatedPlayers().getOrDefault(event.getPlayer().getUniqueId(),false))
|
||||||
|
&& config.getBoolean("ServerPassword.preventMove")) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
|
if (skipIfOpPlayer(event.getPlayer())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ((!plugin.getServerPasswordData().getAuthenticatedPlayers().getOrDefault(event.getPlayer().getUniqueId(),false))
|
||||||
|
&& config.getBoolean("ServerPassword.preventBuild")) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onBlockPlace(BlockPlaceEvent event) {
|
||||||
|
if (skipIfOpPlayer(event.getPlayer())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ((!plugin.getServerPasswordData().getAuthenticatedPlayers().getOrDefault(event.getPlayer().getUniqueId(),false))
|
||||||
|
&& config.getBoolean("ServerPassword.preventBuild")) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
UUID uuid = player.getUniqueId();
|
||||||
|
|
||||||
|
if (skipIfOpPlayer(player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (plugin.getServerPasswordData().getAuthenticatedPlayers().getOrDefault(uuid, false)) {
|
||||||
|
if (!config.getBoolean("ServerPassword.rememberUntilRestart")) {
|
||||||
|
plugin.getServerPasswordData().getAuthenticatedPlayers().remove(uuid);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (plugin.getConfig().getBoolean("ServerPassword.preventInventory")) {
|
||||||
|
if (plugin.getServerPasswordData().getInventoryMap().containsKey(uuid)) {
|
||||||
|
player.getInventory().setContents(plugin.getServerPasswordData().getInventoryMap().get(uuid));
|
||||||
|
plugin.getServerPasswordData().getInventoryMap().remove(uuid);
|
||||||
|
}
|
||||||
|
if (plugin.getServerPasswordData().getArmorMap().containsKey(uuid)) {
|
||||||
|
player.getInventory().setArmorContents(plugin.getServerPasswordData().getArmorMap().get(uuid));
|
||||||
|
plugin.getServerPasswordData().getArmorMap().remove(uuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,5 @@
|
|||||||
package hu.ditservices.utils;
|
package hu.ditservices.utils;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class Math {
|
public class Math {
|
||||||
public enum Convert {
|
public enum Convert {
|
||||||
TICKS,SECONDS,MINUTES,HOURS
|
TICKS,SECONDS,MINUTES,HOURS
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package hu.ditservices.utils;
|
package hu.ditservices.utils;
|
||||||
|
|
||||||
|
import hu.ditservices.STPlugin;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import java.lang.Math;
|
import java.lang.Math;
|
||||||
|
|
||||||
@ -50,7 +52,8 @@ public class Server {
|
|||||||
}
|
}
|
||||||
return player.getPing();
|
return player.getPing();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
STPlugin plugin = STPlugin.getInstance();
|
||||||
|
plugin.getLogger().warning(ChatColor.stripColor(plugin.getPrefix()) + e.getMessage());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
40
src/main/java/hu/ditservices/utils/ServerPasswordData.java
Normal file
40
src/main/java/hu/ditservices/utils/ServerPasswordData.java
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package hu.ditservices.utils;
|
||||||
|
|
||||||
|
import hu.ditservices.STPlugin;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class ServerPasswordData {
|
||||||
|
private STPlugin plugin;
|
||||||
|
public ServerPasswordData(STPlugin instance) {
|
||||||
|
this.plugin = instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Maps to store inventory, armor, and authentication status
|
||||||
|
private final Map<UUID, ItemStack[]> inventoryMap = new HashMap<>();
|
||||||
|
private final Map<UUID, ItemStack[]> armorMap = new HashMap<>();
|
||||||
|
private final Map<UUID, Boolean> authenticatedPlayers = new HashMap<>();
|
||||||
|
|
||||||
|
// Getter for the inventory map
|
||||||
|
public Map<UUID, ItemStack[]> getInventoryMap() {
|
||||||
|
return inventoryMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getter for the armor map
|
||||||
|
public Map<UUID, ItemStack[]> getArmorMap() {
|
||||||
|
return armorMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getter for the authenticated players map
|
||||||
|
public Map<UUID, Boolean> getAuthenticatedPlayers() {
|
||||||
|
return authenticatedPlayers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getServerPassword() {
|
||||||
|
return this.plugin.getConfig().getString("ServerPassword.password");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,10 @@
|
|||||||
package hu.ditservices.utils;
|
package hu.ditservices.utils;
|
||||||
|
|
||||||
|
import hu.ditservices.STPlugin;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class Version {
|
public class Version {
|
||||||
@ -37,7 +42,8 @@ public class Version {
|
|||||||
v1_21_1_R1,
|
v1_21_1_R1,
|
||||||
v1_21_2_R1,
|
v1_21_2_R1,
|
||||||
v1_21_3_R1,
|
v1_21_3_R1,
|
||||||
v1_21_4_R1;
|
v1_21_4_R1,
|
||||||
|
v1_21_5_R1;
|
||||||
|
|
||||||
private int value;
|
private int value;
|
||||||
|
|
||||||
@ -76,6 +82,38 @@ public class Version {
|
|||||||
return arrayVersion;
|
return arrayVersion;
|
||||||
}*/
|
}*/
|
||||||
public static String[] getArrayVersion() {
|
public static String[] getArrayVersion() {
|
||||||
|
if (arrayVersion == null) {
|
||||||
|
String version = null;
|
||||||
|
try {
|
||||||
|
// Check if the Paper method getMinecraftVersion exists
|
||||||
|
Method minecraftVersionMethod = Bukkit.getServer().getClass().getMethod("getMinecraftVersion");
|
||||||
|
if (minecraftVersionMethod != null) {
|
||||||
|
version = (String) minecraftVersionMethod.invoke(Bukkit.getServer());
|
||||||
|
}
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
// The method doesn't exist in this server version; fall back below.
|
||||||
|
} catch (Exception e) {
|
||||||
|
STPlugin plugin = STPlugin.getInstance();
|
||||||
|
plugin.getLogger().warning(ChatColor.stripColor(plugin.getPrefix()) + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback: use Bukkit version if no version was obtained or it's empty.
|
||||||
|
if (version == null || version.trim().isEmpty()) {
|
||||||
|
version = Bukkit.getServer().getBukkitVersion();
|
||||||
|
// Remove any suffix (e.g., "-R0.1-SNAPSHOT") for consistency.
|
||||||
|
int dashIndex = version.indexOf('-');
|
||||||
|
if (dashIndex != -1) {
|
||||||
|
version = version.substring(0, dashIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construct a legacy-style version string.
|
||||||
|
String legacyVersion = "v" + version.replace('.', '_') + "_R1";
|
||||||
|
arrayVersion = new String[] { legacyVersion };
|
||||||
|
}
|
||||||
|
return arrayVersion;
|
||||||
|
}
|
||||||
|
/*public static String[] getArrayVersion() {
|
||||||
if (arrayVersion == null) {
|
if (arrayVersion == null) {
|
||||||
String packageName = org.bukkit.Bukkit.getServer().getClass().getPackage().getName();
|
String packageName = org.bukkit.Bukkit.getServer().getClass().getPackage().getName();
|
||||||
String[] splitPackageName = packageName.split("\\.");
|
String[] splitPackageName = packageName.split("\\.");
|
||||||
@ -96,7 +134,7 @@ public class Version {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return arrayVersion;
|
return arrayVersion;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
public static boolean isCurrentEqualOrHigher(ServerVersion v) {
|
public static boolean isCurrentEqualOrHigher(ServerVersion v) {
|
||||||
return getCurrent().value >= v.value;
|
return getCurrent().value >= v.value;
|
||||||
|
@ -1,95 +0,0 @@
|
|||||||
/*
|
|
||||||
package hu.ditservices.utils.reflection;
|
|
||||||
|
|
||||||
import hu.ditservices.utils.Version;
|
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
public final class ClazzContainer {
|
|
||||||
private static Class<?> packet, ChatComponentTextClass, CraftPlayerClass, IChatBaseComponentClass, PacketPlayOutPlayerListHeaderFooterClass;
|
|
||||||
private static Object ChatComponentText, IChatBaseComponent;
|
|
||||||
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
IChatBaseComponentClass = classByName("net.minecraft.network.chat", "IChatBaseComponent");
|
|
||||||
packet = classByName("net.minecraft.network.protocol", "Packet");
|
|
||||||
} catch (Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public ClazzContainer(){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Class<?> classByName(String newPackageName, String name) throws ClassNotFoundException {
|
|
||||||
if (Version.ServerVersion.isCurrentLower(Version.ServerVersion.v1_17_R1) || newPackageName == null) {
|
|
||||||
newPackageName = "net.minecraft.server." + Version.ServerVersion.getArrayVersion()[3];
|
|
||||||
}
|
|
||||||
|
|
||||||
return Class.forName(newPackageName + "." + name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Object buildChatComponentText(String text) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
|
|
||||||
Constructor<?> constructor;
|
|
||||||
if (Version.ServerVersion.isCurrentEqualOrHigher(Version.ServerVersion.v1_17_R1)){
|
|
||||||
if (ChatComponentTextClass == null){
|
|
||||||
ChatComponentTextClass = Reflection.getClass("net.minecraft.network.chat.ChatComponentText");
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor = ChatComponentTextClass.getConstructor(String.class);
|
|
||||||
return constructor.newInstance(text);
|
|
||||||
}else{
|
|
||||||
if (ChatComponentTextClass == null){
|
|
||||||
ChatComponentTextClass = Reflection.getClass("net.minecraft.server.%v.ChatComponentText");
|
|
||||||
}
|
|
||||||
constructor = Reflection.getClass("net.minecraft.server.%v.ChatComponentText").getConstructor(String.class);
|
|
||||||
return constructor.newInstance(text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Object buildPacketPlayOutPlayerListHeaderFooter(Object header, Object footer) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
|
|
||||||
Constructor<?> constructor;
|
|
||||||
Field headerField;
|
|
||||||
Field footerField;
|
|
||||||
Object packet;
|
|
||||||
if (Version.ServerVersion.isCurrentEqualOrHigher(Version.ServerVersion.v1_17_R1)){
|
|
||||||
if (PacketPlayOutPlayerListHeaderFooterClass == null){
|
|
||||||
PacketPlayOutPlayerListHeaderFooterClass = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutPlayerListHeaderFooter");
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
if (PacketPlayOutPlayerListHeaderFooterClass == null){
|
|
||||||
PacketPlayOutPlayerListHeaderFooterClass = Reflection.getClass("net.minecraft.server.%v.PacketPlayOutPlayerListHeaderFooter");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (Version.ServerVersion.isCurrentEqualOrLower(Version.ServerVersion.v1_12_R1)){
|
|
||||||
constructor = PacketPlayOutPlayerListHeaderFooterClass.getConstructor();
|
|
||||||
packet = constructor.newInstance();
|
|
||||||
try {
|
|
||||||
headerField = packet.getClass().getDeclaredField("a");
|
|
||||||
headerField.setAccessible(true);
|
|
||||||
headerField.set(packet, buildChatComponentText((String) header));
|
|
||||||
footerField = packet.getClass().getDeclaredField("b");
|
|
||||||
footerField.setAccessible(true);
|
|
||||||
footerField.set(packet, buildChatComponentText((String) footer));
|
|
||||||
} catch (Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
constructor = PacketPlayOutPlayerListHeaderFooterClass.getConstructor(IChatBaseComponentClass,IChatBaseComponentClass);
|
|
||||||
packet = constructor.newInstance(header,footer);
|
|
||||||
}
|
|
||||||
return packet;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static Class<?> getIChatBaseComponent() {
|
|
||||||
return IChatBaseComponentClass;
|
|
||||||
}
|
|
||||||
public static Class<?> getPacket() {
|
|
||||||
return packet;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
@ -1,126 +0,0 @@
|
|||||||
/*
|
|
||||||
package hu.ditservices.utils.reflection;
|
|
||||||
|
|
||||||
import hu.ditservices.utils.Version;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
public class Reflection {
|
|
||||||
|
|
||||||
private static Method playerHandleMethod, sendPacketMethod, chatSerializerMethodA,chatSerializerMethodgetString;
|
|
||||||
private static Field playerConnectionField;
|
|
||||||
private static Class<?> chatSerializer;
|
|
||||||
|
|
||||||
private Reflection(){}
|
|
||||||
|
|
||||||
|
|
||||||
public static Class<?> getClass(String name) {
|
|
||||||
try {
|
|
||||||
return Class.forName(name.replace("%v",Version.ServerVersion.getCurrent().toString()));
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Class<?> getCraftClass(String className) throws ClassNotFoundException {
|
|
||||||
return Class.forName("org.bukkit.craftbukkit." + Version.ServerVersion.getArrayVersion()[3] + "." + className);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Object getPlayerHandle(Player player) throws Exception {
|
|
||||||
if (playerHandleMethod == null) {
|
|
||||||
playerHandleMethod = player.getClass().getDeclaredMethod("getHandle");
|
|
||||||
}
|
|
||||||
|
|
||||||
return playerHandleMethod.invoke(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void sendPacket(Player player, Object packet) {
|
|
||||||
if (player == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
Object playerHandle = getPlayerHandle(player);
|
|
||||||
|
|
||||||
if (playerConnectionField == null) {
|
|
||||||
playerConnectionField = playerHandle.getClass().getDeclaredField(
|
|
||||||
(Version.ServerVersion.isCurrentEqualOrHigher(Version.ServerVersion.v1_17_R1) ? "b" : "playerConnection"));
|
|
||||||
}
|
|
||||||
|
|
||||||
Object playerConnection = playerConnectionField.get(playerHandle);
|
|
||||||
|
|
||||||
if (sendPacketMethod == null) {
|
|
||||||
sendPacketMethod = playerConnection.getClass().getDeclaredMethod(
|
|
||||||
Version.ServerVersion.isCurrentEqualOrHigher(Version.ServerVersion.v1_18_R1) ? "a" : "sendPacket",
|
|
||||||
ClazzContainer.getPacket());
|
|
||||||
}
|
|
||||||
|
|
||||||
sendPacketMethod.invoke(playerConnection, packet);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getChatSerializerString(Object serializer) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
|
||||||
if (chatSerializerMethodgetString==null){
|
|
||||||
if (Version.ServerVersion.isCurrentEqualOrLower(Version.ServerVersion.v1_12_R1)){
|
|
||||||
chatSerializerMethodgetString = ClazzContainer.getIChatBaseComponent().getDeclaredMethod("getText");
|
|
||||||
}else{
|
|
||||||
chatSerializerMethodgetString = ClazzContainer.getIChatBaseComponent().getDeclaredMethod("getString");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (String) chatSerializerMethodgetString.invoke(serializer);
|
|
||||||
//return (String) ClazzContainer.getIChatBaseComponent().cast(chatSerializerMethodgetString.invoke(serializer));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static Object asChatSerializer(String json) throws Exception {
|
|
||||||
try {
|
|
||||||
if (Version.ServerVersion.isCurrentEqualOrHigher(Version.ServerVersion.v1_17_R1)){
|
|
||||||
if (chatSerializer==null){
|
|
||||||
chatSerializer = Class.forName("net.minecraft.network.chat.IChatBaseComponent$ChatSerializer");
|
|
||||||
}
|
|
||||||
|
|
||||||
}else{
|
|
||||||
if (chatSerializer==null){
|
|
||||||
chatSerializer = Class.forName("net.minecraft.server." + Version.ServerVersion.getArrayVersion()[3] + ".IChatBaseComponent$ChatSerializer");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (chatSerializerMethodA == null) {
|
|
||||||
chatSerializerMethodA = chatSerializer.getMethod("a", String.class);
|
|
||||||
}
|
|
||||||
} catch (Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return chatSerializerMethodA.invoke(chatSerializer,json);
|
|
||||||
//return ClazzContainer.getIChatBaseComponent().cast(chatSerializerMethodA.invoke(chatSerializer, json));
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
/*public static Class<?> getNMSClassRegex(String nmsClass) {
|
|
||||||
|
|
||||||
String version = null;
|
|
||||||
Pattern pat = Pattern.compile("net\\.minecraft\\.(?:server)?\\.(v(?:\\d_)+R\\d)");
|
|
||||||
for (Package p : Package.getPackages()) {
|
|
||||||
String name = p.getName();
|
|
||||||
Matcher m = pat.matcher(name);
|
|
||||||
if (m.matches()) version = m.group(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (version == null) return null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
return Class.forName(String.format(nmsClass, version));
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}*//*
|
|
||||||
|
|
||||||
}
|
|
||||||
*/
|
|
@ -11,6 +11,9 @@
|
|||||||
# ██████╔╝██║██║░╚═╝░██║██║░░░░░███████╗██║██║░░░░░░░░██║░░░░░░██║░░░╚█████╔╝╚█████╔╝███████╗██████╔╝
|
# ██████╔╝██║██║░╚═╝░██║██║░░░░░███████╗██║██║░░░░░░░░██║░░░░░░██║░░░╚█████╔╝╚█████╔╝███████╗██████╔╝
|
||||||
# ╚═════╝░╚═╝╚═╝░░░░░╚═╝╚═╝░░░░░╚══════╝╚═╝╚═╝░░░░░░░░╚═╝░░░░░░╚═╝░░░░╚════╝░░╚════╝░╚══════╝╚═════╝░
|
# ╚═════╝░╚═╝╚═╝░░░░░╚═╝╚═╝░░░░░╚══════╝╚═╝╚═╝░░░░░░░░╚═╝░░░░░░╚═╝░░░░╚════╝░░╚════╝░╚══════╝╚═════╝░
|
||||||
#
|
#
|
||||||
|
# Localization options
|
||||||
|
# Currently these languages included by default: en, hu. You can add another language in the lang folder.
|
||||||
|
language: 'en'
|
||||||
# Logging options
|
# Logging options
|
||||||
# If you enable one of them, a txt file will be created every day automatically with the current date.
|
# If you enable one of them, a txt file will be created every day automatically with the current date.
|
||||||
Log:
|
Log:
|
||||||
@ -61,24 +64,55 @@ Tab:
|
|||||||
CustomMsg:
|
CustomMsg:
|
||||||
enabled: false
|
enabled: false
|
||||||
connect: '{PREFIX}{NAME} &aconnected to the server.'
|
connect: '{PREFIX}{NAME} &aconnected to the server.'
|
||||||
disconnect: '{PREFIX}{NAME} leaved the game.'
|
disconnect: '{PREFIX}{NAME} left the game.'
|
||||||
|
|
||||||
# Auto Save options
|
# Auto Save options
|
||||||
# Saves Worlds/Users data to disk.
|
# Saves Worlds/Users data to disk.
|
||||||
# Note: You can do a save like this with the /st save-all command.
|
# Note: You can do a save like this with the /st save-all command.
|
||||||
# NOTICE: You will need a full MC server restart when you want to apply new settings here.
|
# NOTICE: You will need a full MC server restart when you want to apply new settings here.
|
||||||
Saving:
|
Saving:
|
||||||
enabled: true
|
enabled: false
|
||||||
onDisconnect: true # When a player disconnects
|
onDisconnect: true # When a player disconnects
|
||||||
interval: 1800 # Auto saving interval in SECONDS. If this set to zero it means disabled.
|
interval: 1800 # Auto saving interval in SECONDS. If this set to zero it means disabled.
|
||||||
broadcastMsgProgress: '{PREFIX}Auto save in progress..'
|
broadcastMsgProgress: '{PREFIX}Auto save in progress..'
|
||||||
broadcastMsgDone: '{PREFIX}Auto save done.'
|
broadcastMsgDone: '{PREFIX}Auto save done.'
|
||||||
|
|
||||||
|
# Server Password options
|
||||||
|
# You can configure a same password for all players on the server.
|
||||||
|
# Players not logged in can't move, cant build/destroy.
|
||||||
|
ServerPassword:
|
||||||
|
enabled: false
|
||||||
|
password: 'changeme'
|
||||||
|
exceptOps: true # Server operators don't need to login.
|
||||||
|
rememberUntilRestart: true # Set this to 'false' to player need to provide password each login.
|
||||||
|
# Otherwise, each player need to provide password only once until the server is restarted.
|
||||||
|
# Below settings are preventing the related actions until the password was not given by the player if the setting is 'true'.
|
||||||
|
preventInventory: true
|
||||||
|
preventMove: true
|
||||||
|
preventBuild: true
|
||||||
|
|
||||||
|
# Dropped items clearing options
|
||||||
|
ClearDropItems:
|
||||||
|
enabled: false
|
||||||
|
interval: 300 # Interval in seconds between each clear cycle
|
||||||
|
broadcastMsg: true # Broadcasts alerts before clearing 1 minutes and 10 seconds before and when cleared. Set this to 'false' to make cleaning silently.
|
||||||
|
# Dropped items that should always be kept (never cleared)
|
||||||
|
except:
|
||||||
|
- DIAMOND
|
||||||
|
- GOLD_INGOT
|
||||||
|
# - COAL
|
||||||
|
# - IRON_INGOT
|
||||||
|
# - BREAD
|
||||||
|
# Worlds to skip (dropped items in these worlds won't be cleared)
|
||||||
|
skipWorlds:
|
||||||
|
- world_nether
|
||||||
|
- world_the_end
|
||||||
|
|
||||||
# Cooldown options (only applicable for this plugin!)
|
# Cooldown options (only applicable for this plugin!)
|
||||||
Cooldown:
|
Cooldown:
|
||||||
enabled: true
|
enabled: true
|
||||||
# The time must be passed between using this plugin commands.
|
# The time must be passed between using this plugin commands.
|
||||||
seconds: 2 #The command cooldown in seconds
|
seconds: 1 #The command cooldown in seconds
|
||||||
Msg: '{PREFIX} Please wait {SECONDS} seconds!' # The message when the user spamming a command
|
Msg: '{PREFIX} Please wait {SECONDS} seconds!' # The message when the user spamming a command
|
||||||
#
|
#
|
||||||
# Plugin Manager - Enable/Disable plugins without server restart
|
# Plugin Manager - Enable/Disable plugins without server restart
|
||||||
|
42
src/main/resources/en.yml
Normal file
42
src/main/resources/en.yml
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
version.pre.text: "Version: "
|
||||||
|
action.success.reload: "Successfully reload!"
|
||||||
|
notice.settings.not.applied: "Notice: Restart your server if the settings didn't applied."
|
||||||
|
plugin.calculated.tps: "Plugin Calculated TPS: "
|
||||||
|
invalid.arguments: "Invalid arguments!"
|
||||||
|
pmanager.disabled: "Plugin manager commands are disabled in the config!"
|
||||||
|
serverpassword.enabled: "There is server password enabled on this server!"
|
||||||
|
serverpassword.note: "Note: This means the same password for all players."
|
||||||
|
serverpassword.login: "Please login using /slogin <password>"
|
||||||
|
serverpassword.already.auth: "You are already authenticated."
|
||||||
|
serverpassword.success.auth: "You have been authenticated."
|
||||||
|
serverpassword.incorrect: "Incorrect password. Try again."
|
||||||
|
cmd.usage.login: "Usage: /slogin <PASSWORD>"
|
||||||
|
settings.server: "Server "
|
||||||
|
settings.features: "Features"
|
||||||
|
settings.enabled: "Enabled"
|
||||||
|
settings.disabled: "Disabled"
|
||||||
|
settings.feature.tab: "Tab customization: "
|
||||||
|
settings.feature.CustomAdvancementMsg: "Custom Advancement Msg: "
|
||||||
|
settings.feature.AutoSave: "Auto saving: "
|
||||||
|
settings.feature.pmanager: "Plugin manager: "
|
||||||
|
stats.header: "Your statistics"
|
||||||
|
stats.connects: "Connects: "
|
||||||
|
stats.deaths: "Deaths: "
|
||||||
|
stats.MobKills: "Mob kills: "
|
||||||
|
stats.PlayerKills: "Player kills: "
|
||||||
|
stats.sleeps: "Sleeps: "
|
||||||
|
stats.enchants: "Enchants: "
|
||||||
|
stats.totaltime: "Total Play Time: "
|
||||||
|
stats.hour: "h "
|
||||||
|
stats.minutes: "m "
|
||||||
|
stats.seconds: "s"
|
||||||
|
cmd.ping: "Your response time to the server: "
|
||||||
|
pmanager.not.exist: "Plugin not exist!"
|
||||||
|
pmanager.already.enabled: " already enabled!"
|
||||||
|
pmanager.success.enabled: " successfully enabled!"
|
||||||
|
pmanager.already.disabled: " already disabled!"
|
||||||
|
pmanager.success.disabled: " successfully disabled!"
|
||||||
|
list.help: "To list all SimplifyTools commands use the '/help SIMPLIFYTOOLS' command!"
|
||||||
|
cleardropitems.oneMin: "Attention: Dropped items will be cleared in 1 minute!"
|
||||||
|
cleardropitems.tenSec: "Attention: Dropped items will be cleared in 10 seconds!"
|
||||||
|
cleardropitems.cleared: "Dropped items have been cleared (%REMOVECOUNT% items removed)."
|
42
src/main/resources/hu.yml
Normal file
42
src/main/resources/hu.yml
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
version.pre.text: "Verzió: "
|
||||||
|
action.success.reload: "Sikeres újratöltés!"
|
||||||
|
notice.settings.not.applied: "Figyelem: Indítsd újra a szervert, ha a beállítások nem alkalmazódtak."
|
||||||
|
plugin.calculated.tps: "Plugin által kalkulált TPS: "
|
||||||
|
invalid.arguments: "Érvénytelen argumentek!"
|
||||||
|
pmanager.disabled: "A plugin-kezelő le van tiltva a konfigban!"
|
||||||
|
serverpassword.enabled: "Ezen a szerveren szerver jelszó van bekapcsolva!"
|
||||||
|
serverpassword.note: "Figyelem: Ez azt jelenti, hogy mindenki számára ugyanazt a jelszót kell megadni!"
|
||||||
|
serverpassword.login: "Kérlek, lépj be ezzel: /slogin <jelszó>"
|
||||||
|
serverpassword.already.auth: "Már bejelentkeztél."
|
||||||
|
serverpassword.success.auth: "Sikeresen bejelentkeztél!"
|
||||||
|
serverpassword.incorrect: "Rossz jelszó. Próbáld újra."
|
||||||
|
cmd.usage.login: "Használat: /slogin <JELSZÓ>"
|
||||||
|
settings.server: "Szerver "
|
||||||
|
settings.features: "Tulajdonságok "
|
||||||
|
settings.enabled: "Bekapcsolva"
|
||||||
|
settings.disabled: "Kikapcsolva"
|
||||||
|
settings.feature.tab: "Tablista testreszabás: "
|
||||||
|
settings.feature.CustomAdvancementMsg: "Teljesítmény-elérés üzenet testreszabás: "
|
||||||
|
settings.feature.AutoSave: "Automatikus mentés: "
|
||||||
|
settings.feature.pmanager: "Plugin kezelő: "
|
||||||
|
stats.header: "A statisztikáid"
|
||||||
|
stats.connects: "Belépések: "
|
||||||
|
stats.deaths: "Halálok: "
|
||||||
|
stats.MobKills: "Mob ölések: "
|
||||||
|
stats.PlayerKills: "Játékos ölések: "
|
||||||
|
stats.sleeps: "Alvások: "
|
||||||
|
stats.enchants: "Enchantolások: "
|
||||||
|
stats.totaltime: "Összes játékidő: "
|
||||||
|
stats.hour: "ó "
|
||||||
|
stats.minutes: "p "
|
||||||
|
stats.seconds: "mp"
|
||||||
|
cmd.ping: "A válaszidőd a szerverhez: "
|
||||||
|
pmanager.not.exist: "Plugin nem létezik!"
|
||||||
|
pmanager.already.enabled: " már eddig is engedélyezve volt!"
|
||||||
|
pmanager.success.enabled: " sikeresen engedélyezve!"
|
||||||
|
pmanager.already.disabled: " már kivolt kapcsolva eddig is!"
|
||||||
|
pmanager.success.disabled: " sikeresen kikapcsolva!"
|
||||||
|
list.help: "Használd a '/help SIMPLIFYTOOLS' parancsot a plugin parancsainak listázásához!"
|
||||||
|
cleardropitems.oneMin: "Figyelem! Az eldobott tárgyak 1 perc múlva törlésre kerülnek!"
|
||||||
|
cleardropitems.tenSec: "Figyelem! Az eldobott tárgyak 10 másodpercen belül törlésre kerülnek!"
|
||||||
|
cleardropitems.cleared: "Az eldobott tárgyak törlésre kerültek. (%REMOVECOUNT% tárgy lett eltávolítva)."
|
@ -53,8 +53,18 @@ commands:
|
|||||||
description: Plugin settings reload.
|
description: Plugin settings reload.
|
||||||
usage: "/st reload"
|
usage: "/st reload"
|
||||||
permission: st.reload
|
permission: st.reload
|
||||||
|
slogin:
|
||||||
|
description: Server password login.
|
||||||
|
usage: "/slogin <PASSWORD>"
|
||||||
|
permission: st.slogin
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
|
st.slogin:
|
||||||
|
description: The server password login command.
|
||||||
|
default: true
|
||||||
|
st.slogin.skip:
|
||||||
|
description: If has this permission the user dont have to provide server password upon connect.
|
||||||
|
default: op
|
||||||
st.help:
|
st.help:
|
||||||
description: Enables the help command.
|
description: Enables the help command.
|
||||||
default: true
|
default: true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user