mirror of
https://github.com/songoda/UltimateModeration.git
synced 2025-01-31 03:31:27 +01:00
init
This commit is contained in:
parent
db13206689
commit
da9fb516d3
104
.gitignore
vendored
Normal file
104
.gitignore
vendored
Normal file
@ -0,0 +1,104 @@
|
||||
|
||||
\.idea/compiler\.xml
|
||||
|
||||
\.idea/libraries/Maven__bammerbom_ultimatecore_2_1_25\.xml
|
||||
|
||||
\.idea/libraries/Maven__br_net_fabiozumbi12_RedProtect_7_3_0\.xml
|
||||
|
||||
\.idea/libraries/Maven__com_earth2me_essentials_2_0_1\.xml
|
||||
|
||||
\.idea/libraries/Maven__com_gamingmesh_jobs_4_6_0\.xml
|
||||
|
||||
\.idea/libraries/Maven__com_gmail_filoghost_holographicdisplays_holographicdisplays_api_2_3_2\.xml
|
||||
|
||||
\.idea/libraries/Maven__com_gmail_nossr50_mcmmo_1_5_09\.xml
|
||||
|
||||
\.idea/libraries/Maven__com_palmergames_bukkit_towny_0_93_0_0\.xml
|
||||
|
||||
\.idea/libraries/Maven__com_plotsquared_3_5_0\.xml
|
||||
|
||||
\.idea/libraries/Maven__com_sk89q_worldedit_7_0_0\.xml
|
||||
|
||||
\.idea/libraries/Maven__com_sk89q_worldguard_7_0_0\.xml
|
||||
|
||||
\.idea/libraries/Maven__com_songoda_arconix_LATEST\.xml
|
||||
|
||||
\.idea/libraries/Maven__com_songoda_epicspawners_5_4\.xml
|
||||
|
||||
\.idea/libraries/Maven__com_wasteofplastic_askyblock_3_0_6_8\.xml
|
||||
|
||||
\.idea/libraries/Maven__de_diddiz_logblock_1_10_0\.xml
|
||||
|
||||
\.idea/libraries/Maven__me_botsko_prism_2_0_6\.xml
|
||||
|
||||
\.idea/libraries/Maven__me_clip_placeholderapi_2_5_1\.xml
|
||||
|
||||
\.idea/libraries/Maven__me_markeh_factionsframework_1_2_0\.xml
|
||||
|
||||
\.idea/libraries/Maven__me_ryanhamshire_GriefPrevention_16_6\.xml
|
||||
|
||||
\.idea/libraries/Maven__net_coreprotect_2_14_2\.xml
|
||||
|
||||
\.idea/libraries/Maven__net_milkbowl_vault_1_7_1\.xml
|
||||
|
||||
\.idea/libraries/Maven__net_sothatsit_blockstore_1_5_0\.xml
|
||||
|
||||
\.idea/libraries/Maven__org_black_ixx_playerpoints_2_1_4\.xml
|
||||
|
||||
\.idea/libraries/Maven__org_kingdoms_13_0_9\.xml
|
||||
|
||||
\.idea/libraries/Maven__org_spigotmc_spigot_1_13_2\.xml
|
||||
|
||||
\.idea/libraries/Maven__uk_antiperson_stackmob_2_2_6\.xml
|
||||
|
||||
\.idea/libraries/Maven__us_talabrek_ultimateskyblock_2_7_2\.xml
|
||||
|
||||
\.idea/libraries/Maven__xyz_wildseries_wildstacker_b6\.xml
|
||||
|
||||
\.idea/misc\.xml
|
||||
|
||||
\.idea/modules\.xml
|
||||
|
||||
\.idea/uiDesigner\.xml
|
||||
|
||||
\.idea/workspace\.xml
|
||||
|
||||
target/classes/com/songoda/ultimatemoderation/command/AbstractCommand\.class
|
||||
|
||||
target/classes/com/songoda/ultimatemoderation/command/AbstractCommand\$ReturnType\.class
|
||||
|
||||
target/classes/com/songoda/ultimatemoderation/command/CommandManager\.class
|
||||
|
||||
target/classes/com/songoda/ultimatemoderation/command/commands/CommandClearChat\.class
|
||||
|
||||
target/classes/com/songoda/ultimatemoderation/command/commands/CommandRandomPlayer\.class
|
||||
|
||||
target/classes/com/songoda/ultimatemoderation/command/commands/CommandReload\.class
|
||||
|
||||
target/classes/com/songoda/ultimatemoderation/command/commands/CommandSettings\.class
|
||||
|
||||
target/classes/com/songoda/ultimatemoderation/command/commands/CommandToggleChat\.class
|
||||
|
||||
target/classes/com/songoda/ultimatemoderation/command/commands/CommandUltimateModeration\.class
|
||||
|
||||
target/classes/com/songoda/ultimatemoderation/command/TabManager\.class
|
||||
|
||||
target/classes/com/songoda/ultimatemoderation/listeners/ChatListener\.class
|
||||
|
||||
target/classes/com/songoda/ultimatemoderation/Locale\.class
|
||||
|
||||
target/classes/com/songoda/ultimatemoderation/References\.class
|
||||
|
||||
target/classes/com/songoda/ultimatemoderation/UltimateModeration\.class
|
||||
|
||||
target/classes/com/songoda/ultimatemoderation/utils/Methods\.class
|
||||
|
||||
target/classes/com/songoda/ultimatemoderation/utils/SettingsManager\.class
|
||||
|
||||
target/classes/com/songoda/ultimatemoderation/utils/SettingsManager\$Setting\.class
|
||||
|
||||
target/classes/en_US\.lang
|
||||
|
||||
target/classes/plugin\.yml
|
||||
|
||||
UltimateModeration\.iml
|
186
pom.xml
Normal file
186
pom.xml
Normal file
@ -0,0 +1,186 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0">
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>UltimateModeration</artifactId>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<version>maven-version-number</version>
|
||||
<build>
|
||||
<defaultGoal>clean install</defaultGoal>
|
||||
<finalName>UltimateModeration-${project.version}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.google.code.maven-replacer-plugin</groupId>
|
||||
<artifactId>replacer</artifactId>
|
||||
<version>1.5.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>prepare-package</phase>
|
||||
<goals>
|
||||
<goal>replace</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<file>${project.build.directory}/classes/plugin.yml</file>
|
||||
<replacements>
|
||||
<replacement>
|
||||
<token>maven-version-number</token>
|
||||
<value>${project.version}</value>
|
||||
</replacement>
|
||||
</replacements>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>private</id>
|
||||
<url>http://repo.songoda.com/artifactory/private/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.gmail.filoghost.holographicdisplays</groupId>
|
||||
<artifactId>holographicdisplays-api</artifactId>
|
||||
<version>2.3.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.13.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>arconix</artifactId>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org</groupId>
|
||||
<artifactId>kingdoms</artifactId>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.milkbowl</groupId>
|
||||
<artifactId>vault</artifactId>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.ryanhamshire</groupId>
|
||||
<artifactId>GriefPrevention</artifactId>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldedit</artifactId>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldguard</artifactId>
|
||||
<version>7.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com</groupId>
|
||||
<artifactId>plotsquared</artifactId>
|
||||
<version>RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.palmergames.bukkit</groupId>
|
||||
<artifactId>towny</artifactId>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.wasteofplastic</groupId>
|
||||
<artifactId>askyblock</artifactId>
|
||||
<version>3.0.6.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>us.talabrek</groupId>
|
||||
<artifactId>ultimateskyblock</artifactId>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.markeh</groupId>
|
||||
<artifactId>factionsframework</artifactId>
|
||||
<version>1.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>br.net.fabiozumbi12</groupId>
|
||||
<artifactId>RedProtect</artifactId>
|
||||
<version>7.3.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>epicspawners</artifactId>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.gmail.nossr50</groupId>
|
||||
<artifactId>mcmmo</artifactId>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.gamingmesh</groupId>
|
||||
<artifactId>jobs</artifactId>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.botsko</groupId>
|
||||
<artifactId>prism</artifactId>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.diddiz</groupId>
|
||||
<artifactId>logblock</artifactId>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net</groupId>
|
||||
<artifactId>coreprotect</artifactId>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>uk.antiperson</groupId>
|
||||
<artifactId>stackmob</artifactId>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sothatsit</groupId>
|
||||
<artifactId>blockstore</artifactId>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.black_ixx</groupId>
|
||||
<artifactId>playerpoints</artifactId>
|
||||
<version>2.1.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>xyz.wildseries</groupId>
|
||||
<artifactId>wildstacker</artifactId>
|
||||
<version>b6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.5.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.earth2me</groupId>
|
||||
<artifactId>essentials</artifactId>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>bammerbom</groupId>
|
||||
<artifactId>ultimatecore</artifactId>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
375
src/main/java/com/songoda/ultimatemoderation/Locale.java
Normal file
375
src/main/java/com/songoda/ultimatemoderation/Locale.java
Normal file
@ -0,0 +1,375 @@
|
||||
package com.songoda.ultimatemoderation;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Assists in the creation of multiple localizations and languages,
|
||||
* as well as the generation of default .lang files
|
||||
*
|
||||
* @author Parker Hawke - 2008Choco
|
||||
*/
|
||||
public class Locale {
|
||||
|
||||
private static final List<Locale> LOCALES = Lists.newArrayList();
|
||||
private static final Pattern NODE_PATTERN = Pattern.compile("(\\w+(?:\\.{1}\\w+)*)\\s*=\\s*\"(.*)\"");
|
||||
private static final String FILE_EXTENSION = ".lang";
|
||||
private static JavaPlugin plugin;
|
||||
private static File localeFolder;
|
||||
|
||||
private static String defaultLocale;
|
||||
|
||||
private final Map<String, String> nodes = new HashMap<>();
|
||||
|
||||
private final File file;
|
||||
private final String name, region;
|
||||
|
||||
private Locale(String name, String region) {
|
||||
if (plugin == null)
|
||||
throw new IllegalStateException("Cannot generate locales without first initializing the class (Locale#init(JavaPlugin))");
|
||||
|
||||
this.name = name.toLowerCase();
|
||||
this.region = region.toUpperCase();
|
||||
|
||||
String fileName = name + "_" + region + FILE_EXTENSION;
|
||||
this.file = new File(localeFolder, fileName);
|
||||
|
||||
if (this.reloadMessages()) return;
|
||||
|
||||
plugin.getLogger().info("Loaded locale " + fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the locale class to generate information and search for localizations.
|
||||
* This must be called before any other methods in the Locale class can be invoked.
|
||||
* Note that this will also call {@link #searchForLocales()}, so there is no need to
|
||||
* invoke it for yourself after the initialization
|
||||
*
|
||||
* @param plugin the plugin instance
|
||||
*/
|
||||
public static void init(JavaPlugin plugin) {
|
||||
Locale.plugin = plugin;
|
||||
|
||||
if (localeFolder == null) {
|
||||
localeFolder = new File(plugin.getDataFolder(), "locales/");
|
||||
}
|
||||
|
||||
localeFolder.mkdirs();
|
||||
Locale.searchForLocales();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find all .lang file locales under the "locales" folder
|
||||
*/
|
||||
public static void searchForLocales() {
|
||||
if (!localeFolder.exists()) localeFolder.mkdirs();
|
||||
|
||||
for (File file : localeFolder.listFiles()) {
|
||||
String name = file.getName();
|
||||
if (!name.endsWith(".lang")) continue;
|
||||
|
||||
String fileName = name.substring(0, name.lastIndexOf('.'));
|
||||
String[] localeValues = fileName.split("_");
|
||||
|
||||
if (localeValues.length != 2) continue;
|
||||
if (localeExists(localeValues[0] + "_" + localeValues[1])) continue;
|
||||
|
||||
LOCALES.add(new Locale(localeValues[0], localeValues[1]));
|
||||
plugin.getLogger().info("Found and loaded locale \"" + fileName + "\"");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a locale by its entire proper name (i.e. "en_US")
|
||||
*
|
||||
* @param name the full name of the locale
|
||||
* @return locale of the specified name
|
||||
*/
|
||||
public static Locale getLocale(String name) {
|
||||
for (Locale locale : LOCALES)
|
||||
if (locale.getLanguageTag().equalsIgnoreCase(name)) return locale;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a locale from the cache by its name (i.e. "en" from "en_US")
|
||||
*
|
||||
* @param name the name of the language
|
||||
* @return locale of the specified language. Null if not cached
|
||||
*/
|
||||
public static Locale getLocaleByName(String name) {
|
||||
for (Locale locale : LOCALES)
|
||||
if (locale.getName().equalsIgnoreCase(name)) return locale;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a locale from the cache by its region (i.e. "US" from "en_US")
|
||||
*
|
||||
* @param region the name of the region
|
||||
* @return locale of the specified region. Null if not cached
|
||||
*/
|
||||
public static Locale getLocaleByRegion(String region) {
|
||||
for (Locale locale : LOCALES)
|
||||
if (locale.getRegion().equalsIgnoreCase(region)) return locale;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a locale exists and is registered or not
|
||||
*
|
||||
* @param name the whole language tag (i.e. "en_US")
|
||||
* @return true if it exists
|
||||
*/
|
||||
public static boolean localeExists(String name) {
|
||||
for (Locale locale : LOCALES)
|
||||
if (locale.getLanguageTag().equals(name)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an immutable list of all currently loaded locales
|
||||
*
|
||||
* @return list of all locales
|
||||
*/
|
||||
public static List<Locale> getLocales() {
|
||||
return ImmutableList.copyOf(LOCALES);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a default locale file from the project source directory, to the locale folder
|
||||
*
|
||||
* @param in file to save
|
||||
* @param fileName the name of the file to save
|
||||
* @return true if the operation was successful, false otherwise
|
||||
*/
|
||||
public static boolean saveDefaultLocale(InputStream in, String fileName) {
|
||||
if (!localeFolder.exists()) localeFolder.mkdirs();
|
||||
|
||||
if (!fileName.endsWith(FILE_EXTENSION))
|
||||
fileName = (fileName.lastIndexOf(".") == -1 ? fileName : fileName.substring(0, fileName.lastIndexOf('.'))) + FILE_EXTENSION;
|
||||
|
||||
File destinationFile = new File(localeFolder, fileName);
|
||||
if (destinationFile.exists()) {
|
||||
return compareFiles(plugin.getResource(fileName), destinationFile);
|
||||
}
|
||||
|
||||
try (OutputStream outputStream = new FileOutputStream(destinationFile)) {
|
||||
copy(in == null ? plugin.getResource(fileName) : in, outputStream);
|
||||
|
||||
fileName = fileName.substring(0, fileName.lastIndexOf('.'));
|
||||
String[] localeValues = fileName.split("_");
|
||||
|
||||
if (localeValues.length != 2) return false;
|
||||
|
||||
LOCALES.add(new Locale(localeValues[0], localeValues[1]));
|
||||
if (defaultLocale == null) defaultLocale = fileName;
|
||||
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a default locale file from the project source directory, to the locale folder
|
||||
*
|
||||
* @param fileName the name of the file to save
|
||||
* @return true if the operation was successful, false otherwise
|
||||
*/
|
||||
public static boolean saveDefaultLocale(String fileName) {
|
||||
return saveDefaultLocale(null, fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all current locale data
|
||||
*/
|
||||
public static void clearLocaleData() {
|
||||
for (Locale locale : LOCALES)
|
||||
locale.nodes.clear();
|
||||
LOCALES.clear();
|
||||
}
|
||||
|
||||
// Write new changes to existing files, if any at all
|
||||
private static boolean compareFiles(InputStream defaultFile, File existingFile) {
|
||||
// Look for default
|
||||
if (defaultFile == null) {
|
||||
defaultFile = plugin.getResource(defaultLocale != null ? defaultLocale : "en_US");
|
||||
if (defaultFile == null) return false; // No default at all
|
||||
}
|
||||
|
||||
boolean changed = false;
|
||||
|
||||
List<String> defaultLines, existingLines;
|
||||
try (BufferedReader defaultReader = new BufferedReader(new InputStreamReader(defaultFile));
|
||||
BufferedReader existingReader = new BufferedReader(new FileReader(existingFile));
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(existingFile, true))) {
|
||||
defaultLines = defaultReader.lines().collect(Collectors.toList());
|
||||
existingLines = existingReader.lines().map(s -> s.split("\\s*=")[0]).collect(Collectors.toList());
|
||||
|
||||
for (String defaultValue : defaultLines) {
|
||||
if (defaultValue.isEmpty() || defaultValue.startsWith("#")) continue;
|
||||
|
||||
String key = defaultValue.split("\\s*=")[0];
|
||||
|
||||
if (!existingLines.contains(key)) {
|
||||
if (!changed) {
|
||||
writer.newLine();
|
||||
writer.newLine();
|
||||
writer.write("# New messages for " + plugin.getName() + " v" + plugin.getDescription().getVersion());
|
||||
}
|
||||
|
||||
writer.newLine();
|
||||
writer.write(defaultValue);
|
||||
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
private static void copy(InputStream input, OutputStream output) {
|
||||
int n;
|
||||
byte[] buffer = new byte[1024 * 4];
|
||||
|
||||
try {
|
||||
while ((n = input.read(buffer)) != -1) {
|
||||
output.write(buffer, 0, n);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the language that this locale is based on.
|
||||
* (i.e. "en" for English, or "fr" for French)
|
||||
*
|
||||
* @return the name of the language
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the region that this locale is from.
|
||||
* (i.e. "US" for United States or "CA" for Canada)
|
||||
*
|
||||
* @return the name of the region
|
||||
*/
|
||||
public String getRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the entire locale tag (i.e. "en_US")
|
||||
*
|
||||
* @return the language tag
|
||||
*/
|
||||
public String getLanguageTag() {
|
||||
return name + "_" + region;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file that represents this locale
|
||||
*
|
||||
* @return the locale file (.lang)
|
||||
*/
|
||||
public File getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a message set for a specific node
|
||||
*
|
||||
* @param node the node to get
|
||||
* @return the message for the specified node
|
||||
*/
|
||||
public String getMessage(String node) {
|
||||
return ChatColor.translateAlternateColorCodes('&', this.getMessageOrDefault(node, node));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a message set for a specific node and replace its params with a supplied arguments.
|
||||
*
|
||||
* @param node the node to get
|
||||
* @param args the replacement arguments
|
||||
* @return the message for the specified node
|
||||
*/
|
||||
public String getMessage(String node, Object... args) {
|
||||
String message = getMessage(node);
|
||||
for (Object arg : args) {
|
||||
message = message.replaceFirst("\\%.*?\\%", arg.toString());
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a message set for a specific node
|
||||
*
|
||||
* @param node the node to get
|
||||
* @param defaultValue the default value given that a value for the node was not found
|
||||
* @return the message for the specified node. Default if none found
|
||||
*/
|
||||
public String getMessageOrDefault(String node, String defaultValue) {
|
||||
return this.nodes.getOrDefault(node, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the key-value map of nodes to messages
|
||||
*
|
||||
* @return node-message map
|
||||
*/
|
||||
public Map<String, String> getMessageNodeMap() {
|
||||
return ImmutableMap.copyOf(nodes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the previous message cache and load new messages directly from file
|
||||
*
|
||||
* @return reload messages from file
|
||||
*/
|
||||
public boolean reloadMessages() {
|
||||
if (!this.file.exists()) {
|
||||
plugin.getLogger().warning("Could not find file for locale " + this.name);
|
||||
return false;
|
||||
}
|
||||
|
||||
this.nodes.clear(); // Clear previous data (if any)
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
|
||||
String line;
|
||||
for (int lineNumber = 0; (line = reader.readLine()) != null; lineNumber++) {
|
||||
if (line.isEmpty() || line.startsWith("#") /* Comment */) continue;
|
||||
|
||||
Matcher matcher = NODE_PATTERN.matcher(line);
|
||||
if (!matcher.find()) {
|
||||
System.err.println("Invalid locale syntax at (line=" + lineNumber + ")");
|
||||
continue;
|
||||
}
|
||||
|
||||
nodes.put(matcher.group(1), matcher.group(2));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
14
src/main/java/com/songoda/ultimatemoderation/References.java
Normal file
14
src/main/java/com/songoda/ultimatemoderation/References.java
Normal file
@ -0,0 +1,14 @@
|
||||
package com.songoda.ultimatemoderation;
|
||||
|
||||
public class References {
|
||||
|
||||
private String prefix;
|
||||
|
||||
public References() {
|
||||
prefix = UltimateModeration.getInstance().getLocale().getMessage("general.nametag.prefix") + " ";
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return this.prefix;
|
||||
}
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
package com.songoda.ultimatemoderation;
|
||||
|
||||
import com.songoda.ultimatemoderation.command.CommandManager;
|
||||
import com.songoda.ultimatemoderation.listeners.ChatListener;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import com.songoda.ultimatemoderation.utils.SettingsManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class UltimateModeration extends JavaPlugin {
|
||||
private static CommandSender console = Bukkit.getConsoleSender();
|
||||
private static UltimateModeration INSTANCE;
|
||||
private References references;
|
||||
private SettingsManager settingsManager;
|
||||
private CommandManager commandManager;
|
||||
private Locale locale;
|
||||
private ChatListener chatListener;
|
||||
|
||||
public static UltimateModeration getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private boolean checkVersion() {
|
||||
int workingVersion = 13;
|
||||
int currentVersion = Integer.parseInt(Bukkit.getServer().getClass()
|
||||
.getPackage().getName().split("\\.")[3].split("_")[1]);
|
||||
|
||||
if (currentVersion < workingVersion) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> {
|
||||
Bukkit.getConsoleSender().sendMessage("");
|
||||
Bukkit.getConsoleSender().sendMessage(String.format("%sYou installed the 1.%s only version of %s on a 1.%s server. Since you are on the wrong version we disabled the plugin for you. Please install correct version to continue using %s.", ChatColor.RED, workingVersion, this.getDescription().getName(), currentVersion, this.getDescription().getName()));
|
||||
Bukkit.getConsoleSender().sendMessage("");
|
||||
}, 20L);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
INSTANCE = this;
|
||||
|
||||
// Check to make sure the Bukkit version is compatible.
|
||||
if (!checkVersion()) return;
|
||||
|
||||
console.sendMessage(Methods.formatText("&a============================="));
|
||||
console.sendMessage(Methods.formatText("&7UltimateModeration " + this.getDescription().getVersion() + " by &5Songoda <3!"));
|
||||
console.sendMessage(Methods.formatText("&7Action: &aEnabling&7..."));
|
||||
console.sendMessage(Methods.formatText("&a============================="));
|
||||
|
||||
this.settingsManager = new SettingsManager(this);
|
||||
this.setupConfig();
|
||||
|
||||
// Setup language
|
||||
String langMode = SettingsManager.Setting.LANGUGE_MODE.getString();
|
||||
Locale.init(this);
|
||||
Locale.saveDefaultLocale("en_US");
|
||||
this.locale = Locale.getLocale(getConfig().getString("System.Language Mode", langMode));
|
||||
|
||||
this.references = new References();
|
||||
|
||||
this.commandManager = new CommandManager(this);
|
||||
|
||||
this.chatListener = new ChatListener(this);
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(this.chatListener, this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
console.sendMessage(Methods.formatText("&a============================="));
|
||||
console.sendMessage(Methods.formatText("&7UltimateModeration " + this.getDescription().getVersion() + " by &5Songoda <3!"));
|
||||
console.sendMessage(Methods.formatText("&7Action: &cDisabling&7..."));
|
||||
console.sendMessage(Methods.formatText("&a============================="));
|
||||
}
|
||||
|
||||
private void setupConfig() {
|
||||
settingsManager.updateSettings();
|
||||
this.getConfig().options().copyDefaults(true);
|
||||
this.saveConfig();
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
locale.reloadMessages();
|
||||
references = new References();
|
||||
this.setupConfig();
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
public CommandManager getCommandManager() {
|
||||
return commandManager;
|
||||
}
|
||||
|
||||
public SettingsManager getSettingsManager() {
|
||||
return settingsManager;
|
||||
}
|
||||
|
||||
public Locale getLocale() {
|
||||
return locale;
|
||||
}
|
||||
|
||||
public References getReferences() {
|
||||
return references;
|
||||
}
|
||||
|
||||
public ChatListener getChatListener() {
|
||||
return chatListener;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package com.songoda.ultimatemoderation.command;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractCommand {
|
||||
|
||||
private final AbstractCommand parent;
|
||||
private final boolean noConsole;
|
||||
private String command;
|
||||
|
||||
private List<String> subCommand = new ArrayList<>();
|
||||
|
||||
protected AbstractCommand(AbstractCommand parent, boolean noConsole, String... command) {
|
||||
if (parent != null) {
|
||||
this.subCommand = Arrays.asList(command);
|
||||
} else {
|
||||
this.command = Arrays.asList(command).get(0);
|
||||
}
|
||||
this.parent = parent;
|
||||
this.noConsole = noConsole;
|
||||
}
|
||||
|
||||
public AbstractCommand getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
public List<String> getSubCommand() {
|
||||
return subCommand;
|
||||
}
|
||||
|
||||
public void addSubCommand(String command) {
|
||||
subCommand.add(command);
|
||||
}
|
||||
|
||||
protected abstract ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args);
|
||||
|
||||
protected abstract List<String> onTab(UltimateModeration instance, CommandSender sender, String... args);
|
||||
|
||||
public abstract String getPermissionNode();
|
||||
|
||||
public abstract String getSyntax();
|
||||
|
||||
public abstract String getDescription();
|
||||
|
||||
public boolean isNoConsole() {
|
||||
return noConsole;
|
||||
}
|
||||
|
||||
public enum ReturnType {SUCCESS, FAILURE, SYNTAX_ERROR}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
package com.songoda.ultimatemoderation.command;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.command.commands.*;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandManager implements CommandExecutor {
|
||||
|
||||
private UltimateModeration instance;
|
||||
private TabManager tabManager;
|
||||
|
||||
private List<AbstractCommand> commands = new ArrayList<>();
|
||||
|
||||
public CommandManager(UltimateModeration instance) {
|
||||
this.instance = instance;
|
||||
this.tabManager = new TabManager(this);
|
||||
|
||||
instance.getCommand("UltimateModeration").setExecutor(this);
|
||||
instance.getCommand("ClearChat").setExecutor(this);
|
||||
instance.getCommand("ToggleChat").setExecutor(this);
|
||||
instance.getCommand("RandomPlayer").setExecutor(this);
|
||||
|
||||
AbstractCommand commandUltimateModeration = addCommand(new CommandUltimateModeration());
|
||||
addCommand(new CommandClearChat());
|
||||
addCommand(new CommandToggleChat());
|
||||
addCommand(new CommandRandomPlayer());
|
||||
|
||||
addCommand(new CommandSettings(commandUltimateModeration));
|
||||
addCommand(new CommandReload(commandUltimateModeration));
|
||||
|
||||
for (AbstractCommand abstractCommand : commands) {
|
||||
if (abstractCommand.getParent() != null) continue;
|
||||
instance.getCommand(abstractCommand.getCommand()).setTabCompleter(tabManager);
|
||||
}
|
||||
}
|
||||
|
||||
private AbstractCommand addCommand(AbstractCommand abstractCommand) {
|
||||
commands.add(abstractCommand);
|
||||
return abstractCommand;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
|
||||
for (AbstractCommand abstractCommand : commands) {
|
||||
if (abstractCommand.getCommand() == null)
|
||||
continue;
|
||||
if (abstractCommand.getCommand().equalsIgnoreCase(command.getName())) {
|
||||
if (strings.length == 0) {
|
||||
processRequirements(abstractCommand, commandSender, strings);
|
||||
return true;
|
||||
} else {
|
||||
String cmd = strings[0];
|
||||
String cmd2 = strings.length >= 2 ? String.join(" ", strings[0], strings[1]) : null;
|
||||
for (String sub : abstractCommand.getSubCommand()) {
|
||||
if (cmd.equalsIgnoreCase(sub) || (cmd2 != null && cmd2.equalsIgnoreCase(sub))) {
|
||||
processRequirements(abstractCommand, commandSender, strings);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
commandSender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&7The command you entered does not exist or is spelt incorrectly."));
|
||||
return true;
|
||||
}
|
||||
|
||||
private void processRequirements(AbstractCommand command, CommandSender sender, String[] strings) {
|
||||
if (!(sender instanceof Player) && command.isNoConsole()) {
|
||||
sender.sendMessage("You must be a player to use this command.");
|
||||
return;
|
||||
}
|
||||
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
|
||||
AbstractCommand.ReturnType returnType = command.runCommand(instance, sender, strings);
|
||||
if (returnType == AbstractCommand.ReturnType.SYNTAX_ERROR) {
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&cInvalid Syntax!"));
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&7The valid syntax is: &6" + command.getSyntax() + "&7."));
|
||||
}
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("event.general.nopermission"));
|
||||
}
|
||||
|
||||
public List<AbstractCommand> getCommands() {
|
||||
return Collections.unmodifiableList(commands);
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package com.songoda.ultimatemoderation.command;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TabManager implements TabCompleter {
|
||||
|
||||
private final CommandManager commandManager;
|
||||
|
||||
TabManager(CommandManager commandManager) {
|
||||
this.commandManager = commandManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] strings) {
|
||||
for (AbstractCommand abstractCommand : commandManager.getCommands()) {
|
||||
if (abstractCommand.getCommand() != null && abstractCommand.getCommand().equalsIgnoreCase(command.getName().toLowerCase())) {
|
||||
if (strings.length == 1) {
|
||||
List<String> subs = new ArrayList<>();
|
||||
for (AbstractCommand ac : commandManager.getCommands()) {
|
||||
if (ac.getSubCommand() == null) continue;
|
||||
subs.addAll(ac.getSubCommand());
|
||||
}
|
||||
subs.removeIf(s -> !s.toLowerCase().startsWith(strings[0].toLowerCase()));
|
||||
return subs;
|
||||
}
|
||||
} else if (strings.length != 0 && abstractCommand.getParent() != null && abstractCommand.getParent().getCommand().equalsIgnoreCase(command.getName().toLowerCase())) {
|
||||
String cmd = strings[0];
|
||||
String cmd2 = strings.length >= 2 ? String.join(" ", strings[0], strings[1]) : null;
|
||||
for (String cmds : abstractCommand.getSubCommand()) {
|
||||
if (cmd.equalsIgnoreCase(cmds) || (cmd2 != null && cmd2.equalsIgnoreCase(cmds))) {
|
||||
List<String> list = abstractCommand.onTab(UltimateModeration.getInstance(), sender, strings);
|
||||
String str = strings[strings.length - 1];
|
||||
if (list != null && str != null && str.length() >= 1) {
|
||||
try {
|
||||
list.removeIf(s -> !s.toLowerCase().startsWith(str.toLowerCase()));
|
||||
} catch (UnsupportedOperationException ignored) {
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package com.songoda.ultimatemoderation.command.commands;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.command.AbstractCommand;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandClearChat extends AbstractCommand {
|
||||
|
||||
public CommandClearChat() {
|
||||
super(null, true, "ClearChat");
|
||||
addSubCommand("force");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (!player.hasPermission("um.clearchat.bypass") || isForced(args)) {
|
||||
String[] toSend = new String[250];
|
||||
Arrays.fill(toSend, "");
|
||||
player.sendMessage(toSend);
|
||||
}
|
||||
|
||||
player.sendMessage(instance.getReferences().getPrefix() + Methods.formatText(instance.getLocale().getMessage("command.clearchat.cleared", sender.getName())));
|
||||
|
||||
if (player.hasPermission("um.clearchat.bypass") && !isForced(args)) {
|
||||
player.sendMessage(instance.getLocale().getMessage("command.clearchat.immune"));
|
||||
}
|
||||
}
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean isForced(String[] args) {
|
||||
return args.length != 0 && args[0].equals("force");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "um.clearchat";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/clearChat [force]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Allows you to clear the chat.";
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package com.songoda.ultimatemoderation.command.commands;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.command.AbstractCommand;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class CommandRandomPlayer extends AbstractCommand {
|
||||
|
||||
public CommandRandomPlayer() {
|
||||
super(null, true, "RandomPlayer");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
List<Player> players = new ArrayList<>(Bukkit.getOnlinePlayers());
|
||||
Collections.shuffle(players);
|
||||
players.remove(sender);
|
||||
|
||||
if (players.size() == 0) {
|
||||
sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&c You are the only one online!"));
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
((Player)sender).teleport(players.get(0).getLocation());
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "um.randomplayer";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/RandomPlayer";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Allows you to randomly teleport to a player on the server.";
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package com.songoda.ultimatemoderation.command.commands;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.command.AbstractCommand;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandReload extends AbstractCommand {
|
||||
|
||||
public CommandReload(AbstractCommand parent) {
|
||||
super(parent, false, "reload");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
instance.reload();
|
||||
sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&7Configuration and Language files reloaded."));
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "um.admin";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/um reload";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Reload the Configuration and Language files.";
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package com.songoda.ultimatemoderation.command.commands;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.command.AbstractCommand;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandSettings extends AbstractCommand {
|
||||
|
||||
public CommandSettings(AbstractCommand parent) {
|
||||
super(parent, true, "settings");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
Player p = (Player) sender;
|
||||
instance.getSettingsManager().openSettingsManager(p);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "um.admin";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/um settings";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Edit UltimateModeration Settings.";
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package com.songoda.ultimatemoderation.command.commands;
|
||||
|
||||
import com.songoda.ultimatemoderation.Locale;
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.command.AbstractCommand;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandToggleChat extends AbstractCommand {
|
||||
|
||||
/*
|
||||
* Chat is enabled by default ;)
|
||||
*/
|
||||
private boolean toggled = true;
|
||||
|
||||
public CommandToggleChat() {
|
||||
super(null, false, "togglechat");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
toggled = !toggled;
|
||||
String prefix = instance.getReferences().getPrefix();
|
||||
|
||||
Locale locale = instance.getLocale();
|
||||
String strToggledOn = locale.getMessage("command.togglechat.toggledOn");
|
||||
String strToggledOff = locale.getMessage("command.togglechat.toggledOff");
|
||||
String messageToSend = prefix + Methods.formatText(toggled ? strToggledOn : strToggledOff);
|
||||
|
||||
instance.getChatListener().setChatToggled(toggled);
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
|
||||
player.sendMessage(messageToSend);
|
||||
|
||||
if (!player.hasPermission(getPermissionNode() + ".bypass"))
|
||||
continue;
|
||||
|
||||
player.sendMessage(Methods.formatText(locale.getMessage("command.togglechat.bypass")));
|
||||
|
||||
}
|
||||
|
||||
if (!(sender instanceof Player))
|
||||
sender.sendMessage(messageToSend);
|
||||
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "um.togglechat";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/ToggleChat";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Toggle chat for the entire server";
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package com.songoda.ultimatemoderation.command.commands;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.command.AbstractCommand;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandUltimateModeration extends AbstractCommand {
|
||||
|
||||
public CommandUltimateModeration() {
|
||||
super(null, false, "UltimateModeration");
|
||||
addSubCommand("reload");
|
||||
addSubCommand("settings");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&7Version " + instance.getDescription().getVersion() + " Created with <3 by &5&l&oSongoda"));
|
||||
|
||||
for (AbstractCommand command : instance.getCommandManager().getCommands()) {
|
||||
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
|
||||
sender.sendMessage(Methods.formatText("&8 - &a" + command.getSyntax() + "&7 - " + command.getDescription()));
|
||||
}
|
||||
}
|
||||
sender.sendMessage("");
|
||||
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/um";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Displays this page.";
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.songoda.ultimatemoderation.listeners;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
public class ChatListener implements Listener {
|
||||
|
||||
private UltimateModeration instance;
|
||||
private boolean isChatToggled = true; // true means people can talk, false means muted
|
||||
|
||||
public ChatListener(UltimateModeration ultimateModeration) {
|
||||
this.instance = ultimateModeration;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChat(AsyncPlayerChatEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (!isChatToggled && !player.hasPermission("um.togglechat.bypass")) {
|
||||
event.setCancelled(true);
|
||||
player.sendMessage(instance.getReferences().getPrefix() + Methods.formatText(instance.getLocale().getMessage("command.togglechat.muted")));
|
||||
}
|
||||
}
|
||||
|
||||
public void setChatToggled(boolean toggled) {
|
||||
this.isChatToggled = toggled;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package com.songoda.ultimatemoderation.utils;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public class Methods {
|
||||
|
||||
public static ItemStack getGlass() {
|
||||
UltimateModeration instance = UltimateModeration.getInstance();
|
||||
return Methods.getGlass(instance.getConfig().getBoolean("Interfaces.Replace Glass Type 1 With Rainbow Glass"), instance.getConfig().getInt("Interfaces.Glass Type 1"));
|
||||
}
|
||||
|
||||
public static ItemStack getBackgroundGlass(boolean type) {
|
||||
UltimateModeration instance = UltimateModeration.getInstance();
|
||||
if (type)
|
||||
return getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 2"));
|
||||
else
|
||||
return getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 3"));
|
||||
}
|
||||
|
||||
private static ItemStack getGlass(Boolean rainbow, int type) {
|
||||
int randomNum = 1 + (int) (Math.random() * 6);
|
||||
ItemStack glass;
|
||||
if (rainbow) {
|
||||
glass = new ItemStack(Material.LEGACY_STAINED_GLASS_PANE, 1, (short) randomNum);
|
||||
} else {
|
||||
glass = new ItemStack(Material.LEGACY_STAINED_GLASS_PANE, 1, (short) type);
|
||||
}
|
||||
ItemMeta glassmeta = glass.getItemMeta();
|
||||
glassmeta.setDisplayName("§l");
|
||||
glass.setItemMeta(glassmeta);
|
||||
return glass;
|
||||
}
|
||||
|
||||
public static String formatText(String text) {
|
||||
if (text == null || text.equals(""))
|
||||
return "";
|
||||
return formatText(text, false);
|
||||
}
|
||||
|
||||
public static String formatText(String text, boolean cap) {
|
||||
if (text == null || text.equals(""))
|
||||
return "";
|
||||
if (cap)
|
||||
text = text.substring(0, 1).toUpperCase() + text.substring(1);
|
||||
return ChatColor.translateAlternateColorCodes('&', text);
|
||||
}
|
||||
}
|
@ -0,0 +1,203 @@
|
||||
package com.songoda.ultimatemoderation.utils;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
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.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Created by songo on 6/4/2017.
|
||||
*/
|
||||
public class SettingsManager implements Listener {
|
||||
|
||||
private static final Pattern SETTINGS_PATTERN = Pattern.compile("(.{1,28}(?:\\s|$))|(.{0,28})", Pattern.DOTALL);
|
||||
private final UltimateModeration instance;
|
||||
private String pluginName = "EpicHoppers";
|
||||
private Map<Player, String> cat = new HashMap<>();
|
||||
private Map<Player, String> current = new HashMap<>();
|
||||
|
||||
public SettingsManager(UltimateModeration plugin) {
|
||||
this.instance = plugin;
|
||||
Bukkit.getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
ItemStack clickedItem = event.getCurrentItem();
|
||||
|
||||
if (event.getInventory() != event.getWhoClicked().getOpenInventory().getTopInventory()
|
||||
|| clickedItem == null || !clickedItem.hasItemMeta()
|
||||
|| !clickedItem.getItemMeta().hasDisplayName()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getInventory().getTitle().equals(pluginName + " Settings Manager")) {
|
||||
event.setCancelled(true);
|
||||
if (clickedItem.getType().name().contains("STAINED_GLASS")) return;
|
||||
|
||||
String type = ChatColor.stripColor(clickedItem.getItemMeta().getDisplayName());
|
||||
this.cat.put((Player) event.getWhoClicked(), type);
|
||||
this.openEditor((Player) event.getWhoClicked());
|
||||
} else if (event.getInventory().getTitle().equals(pluginName + " Settings Editor")) {
|
||||
event.setCancelled(true);
|
||||
if (clickedItem.getType().name().contains("STAINED_GLASS")) return;
|
||||
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
|
||||
String key = cat.get(player) + "." + ChatColor.stripColor(clickedItem.getItemMeta().getDisplayName());
|
||||
|
||||
if (instance.getConfig().get(key).getClass().getName().equals("java.lang.Boolean")) {
|
||||
this.instance.getConfig().set(key, !instance.getConfig().getBoolean(key));
|
||||
this.finishEditing(player);
|
||||
} else {
|
||||
this.editObject(player, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChat(AsyncPlayerChatEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (!current.containsKey(player)) return;
|
||||
|
||||
String value = current.get(player);
|
||||
FileConfiguration config = instance.getConfig();
|
||||
if (config.isInt(value)) {
|
||||
config.set(value, Integer.parseInt(event.getMessage()));
|
||||
} else if (config.isDouble(value)) {
|
||||
config.set(value, Double.parseDouble(event.getMessage()));
|
||||
} else if (config.isString(value)) {
|
||||
config.set(value, event.getMessage());
|
||||
}
|
||||
|
||||
this.finishEditing(player);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
private void finishEditing(Player player) {
|
||||
this.current.remove(player);
|
||||
this.instance.saveConfig();
|
||||
this.openEditor(player);
|
||||
}
|
||||
|
||||
private void editObject(Player player, String current) {
|
||||
this.current.put(player, ChatColor.stripColor(current));
|
||||
|
||||
player.closeInventory();
|
||||
player.sendMessage("");
|
||||
player.sendMessage(Methods.formatText("&7Please enter a value for &6" + current + "&7."));
|
||||
if (instance.getConfig().isInt(current) || instance.getConfig().isDouble(current)) {
|
||||
player.sendMessage(Methods.formatText("&cUse only numbers."));
|
||||
}
|
||||
player.sendMessage("");
|
||||
}
|
||||
|
||||
public void openSettingsManager(Player player) {
|
||||
Inventory inventory = Bukkit.createInventory(null, 27, pluginName + " Settings Manager");
|
||||
ItemStack glass = Methods.getGlass();
|
||||
for (int i = 0; i < inventory.getSize(); i++) {
|
||||
inventory.setItem(i, glass);
|
||||
}
|
||||
|
||||
int slot = 10;
|
||||
for (String key : instance.getConfig().getDefaultSection().getKeys(false)) {
|
||||
ItemStack item = new ItemStack(Material.WHITE_WOOL, 1, (byte) (slot - 9)); //ToDo: Make this function as it was meant to.
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setLore(Collections.singletonList(Methods.formatText("&6Click To Edit This Category.")));
|
||||
meta.setDisplayName(Methods.formatText("&f&l" + key));
|
||||
item.setItemMeta(meta);
|
||||
inventory.setItem(slot, item);
|
||||
slot++;
|
||||
}
|
||||
|
||||
player.openInventory(inventory);
|
||||
}
|
||||
|
||||
private void openEditor(Player player) {
|
||||
Inventory inventory = Bukkit.createInventory(null, 54, pluginName + " Settings Editor");
|
||||
FileConfiguration config = instance.getConfig();
|
||||
|
||||
int slot = 0;
|
||||
for (String key : config.getConfigurationSection(cat.get(player)).getKeys(true)) {
|
||||
String fKey = cat.get(player) + "." + key;
|
||||
ItemStack item = new ItemStack(Material.DIAMOND_HELMET);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(Methods.formatText("&6" + key));
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
if (config.isBoolean(fKey)) {
|
||||
item.setType(Material.LEVER);
|
||||
lore.add(Methods.formatText(config.getBoolean(fKey) ? "&atrue" : "&cfalse"));
|
||||
} else if (config.isString(fKey)) {
|
||||
item.setType(Material.PAPER);
|
||||
lore.add(Methods.formatText("&9" + config.getString(fKey)));
|
||||
} else if (config.isInt(fKey)) {
|
||||
item.setType(Material.CLOCK);
|
||||
lore.add(Methods.formatText("&5" + config.getInt(fKey)));
|
||||
}
|
||||
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
inventory.setItem(slot, item);
|
||||
slot++;
|
||||
}
|
||||
|
||||
player.openInventory(inventory);
|
||||
}
|
||||
|
||||
public void updateSettings() {
|
||||
FileConfiguration config = instance.getConfig();
|
||||
|
||||
for (Setting setting : Setting.values()) {
|
||||
config.addDefault(setting.setting, setting.option);
|
||||
}
|
||||
}
|
||||
|
||||
public enum Setting {
|
||||
|
||||
GLASS_TYPE_1("Interfaces.Glass Type 1", 7),
|
||||
GLASS_TYPE_2("Interfaces.Glass Type 2", 11),
|
||||
GLASS_TYPE_3("Interfaces.Glass Type 3", 3),
|
||||
|
||||
DOWNLOAD_FILES("System.Download Needed Data Files", true),
|
||||
LANGUGE_MODE("System.Language Mode", "en_US");
|
||||
|
||||
private String setting;
|
||||
private Object option;
|
||||
|
||||
Setting(String setting, Object option) {
|
||||
this.setting = setting;
|
||||
this.option = option;
|
||||
}
|
||||
|
||||
public List<String> getStringList() {
|
||||
return UltimateModeration.getInstance().getConfig().getStringList(setting);
|
||||
}
|
||||
|
||||
public boolean getBoolean() {
|
||||
return UltimateModeration.getInstance().getConfig().getBoolean(setting);
|
||||
}
|
||||
|
||||
public int getInt() {
|
||||
return UltimateModeration.getInstance().getConfig().getInt(setting);
|
||||
}
|
||||
|
||||
public String getString() {
|
||||
return UltimateModeration.getInstance().getConfig().getString(setting);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
11
src/main/resources/en_US.lang
Normal file
11
src/main/resources/en_US.lang
Normal file
@ -0,0 +1,11 @@
|
||||
#General Messages
|
||||
|
||||
general.nametag.prefix = "&7[&6UltimateModeration&7]"
|
||||
|
||||
command.clearchat.cleared = "&6%player% &7cleared the chat!"
|
||||
command.clearchat.immune = "&aYou were immune to the clear chat because of your perms."
|
||||
|
||||
command.togglechat.toggledOn = "&aChat was globally Unmuted..."
|
||||
command.togglechat.toggledOff = "&cChat was globally Muted..."
|
||||
command.togglechat.bypass = "&aYou were immune to the chat toggle because of your perms."
|
||||
command.togglechat.muted = "&cChat is currently disabled, try again later."
|
27
src/main/resources/plugin.yml
Normal file
27
src/main/resources/plugin.yml
Normal file
@ -0,0 +1,27 @@
|
||||
name: UltimateModeration
|
||||
description: UltimateModeration
|
||||
main: com.songoda.ultimatemoderation.UltimateModeration
|
||||
version: 1
|
||||
author: Songoda
|
||||
api-version: 1.13
|
||||
commands:
|
||||
UltimateModeration:
|
||||
description: View information on this plugin.
|
||||
default: true
|
||||
aliases: [um]
|
||||
usage: /um
|
||||
ClearChat:
|
||||
description: Clear the chat
|
||||
default: false
|
||||
aliases: [cc]
|
||||
usage: /cc
|
||||
ToggleChat:
|
||||
description: Toggle chat
|
||||
default: false
|
||||
aliases: [tc]
|
||||
usage: /tc
|
||||
RandomPlayer:
|
||||
description: Random Player
|
||||
default: false
|
||||
aliases: [rp]
|
||||
usage: /rp
|
Loading…
Reference in New Issue
Block a user