mirror of
https://github.com/Zrips/Jobs.git
synced 2025-02-21 06:42:29 +01:00
Move & remove some methods to decrease the file size
This commit is contained in:
parent
6319c69c29
commit
d590153222
@ -1,25 +1,13 @@
|
||||
package com.gamingmesh.jobs.commands;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
@ -38,6 +26,8 @@ import com.gamingmesh.jobs.container.JobProgression;
|
||||
import com.gamingmesh.jobs.container.JobsPlayer;
|
||||
import com.gamingmesh.jobs.container.Title;
|
||||
import com.gamingmesh.jobs.stuff.PageInfo;
|
||||
import com.gamingmesh.jobs.stuff.Sorting;
|
||||
import com.gamingmesh.jobs.stuff.Util;
|
||||
|
||||
public class JobsCommands implements CommandExecutor {
|
||||
public static final String label = "jobs";
|
||||
@ -148,7 +138,7 @@ public class JobsCommands implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
commands = sort(commands);
|
||||
commands = Sorting.sortDESC(commands);
|
||||
|
||||
PageInfo pi = new PageInfo(7, commands.size(), page);
|
||||
|
||||
@ -174,50 +164,6 @@ public class JobsCommands implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static List<String> getClassesFromPackage(String pckgname) throws ClassNotFoundException {
|
||||
List<String> result = new ArrayList<>();
|
||||
try {
|
||||
for (URL jarURL : ((URLClassLoader) Jobs.class.getClassLoader()).getURLs()) {
|
||||
try {
|
||||
result.addAll(getClassesInSamePackageFromJar(pckgname, jarURL.toURI().getPath()));
|
||||
} catch (URISyntaxException e) {
|
||||
}
|
||||
}
|
||||
} catch (NullPointerException x) {
|
||||
throw new ClassNotFoundException(pckgname + " does not appear to be a valid package (Null pointer exception)");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static List<String> getClassesInSamePackageFromJar(String packageName, String jarPath) {
|
||||
JarFile jarFile = null;
|
||||
List<String> listOfCommands = new ArrayList<>();
|
||||
try {
|
||||
jarFile = new JarFile(jarPath);
|
||||
Enumeration<JarEntry> en = jarFile.entries();
|
||||
while (en.hasMoreElements()) {
|
||||
JarEntry entry = en.nextElement();
|
||||
String entryName = entry.getName();
|
||||
packageName = packageName.replace(".", "/");
|
||||
if (entryName != null && entryName.endsWith(".class") && entryName.startsWith(packageName)) {
|
||||
String name = entryName.replace(packageName, "").replace(".class", "").replace("/", "");
|
||||
if (name.contains("$"))
|
||||
name = name.split("\\$")[0];
|
||||
listOfCommands.add(name);
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
} finally {
|
||||
if (jarFile != null)
|
||||
try {
|
||||
jarFile.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
return listOfCommands;
|
||||
}
|
||||
|
||||
public Map<String, Integer> GetCommands(CommandSender sender) {
|
||||
Map<String, Integer> temp = new HashMap<>();
|
||||
for (Entry<String, Integer> cmd : CommandList.entrySet()) {
|
||||
@ -233,7 +179,7 @@ public class JobsCommands implements CommandExecutor {
|
||||
List<String> lm = new ArrayList<>();
|
||||
HashMap<String, Class<?>> classes = new HashMap<>();
|
||||
try {
|
||||
lm = getClassesFromPackage(packagePath);
|
||||
lm = Util.getFilesFromPackage(packagePath);
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -279,22 +225,6 @@ public class JobsCommands implements CommandExecutor {
|
||||
return cmdClass;
|
||||
}
|
||||
|
||||
private static Map<String, Integer> sort(Map<String, Integer> unsortMap) {
|
||||
List<Map.Entry<String, Integer>> list = new LinkedList<>(unsortMap.entrySet());
|
||||
Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
|
||||
@Override
|
||||
public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
|
||||
return (o1.getValue()).compareTo(o2.getValue());
|
||||
}
|
||||
});
|
||||
Map<String, Integer> sortedMap = new LinkedHashMap<>();
|
||||
for (Iterator<Map.Entry<String, Integer>> it = list.iterator(); it.hasNext();) {
|
||||
Map.Entry<String, Integer> entry = it.next();
|
||||
sortedMap.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return sortedMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Job joining permission
|
||||
*/
|
||||
|
@ -762,13 +762,13 @@ public class ConfigManager {
|
||||
name = itemSection.getString("name");
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
if (itemSection.contains("lore") && !itemSection.getStringList("lore").isEmpty())
|
||||
if (itemSection.contains("lore"))
|
||||
for (String eachLine : itemSection.getStringList("lore")) {
|
||||
lore.add(org.bukkit.ChatColor.translateAlternateColorCodes('&', eachLine));
|
||||
}
|
||||
|
||||
HashMap<Enchantment, Integer> enchants = new HashMap<>();
|
||||
if (itemSection.contains("enchants") && !itemSection.getStringList("enchants").isEmpty())
|
||||
if (itemSection.contains("enchants"))
|
||||
for (String eachLine : itemSection.getStringList("enchants")) {
|
||||
|
||||
if (!eachLine.contains("="))
|
||||
|
@ -1,20 +1,14 @@
|
||||
package com.gamingmesh.jobs.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
import com.gamingmesh.jobs.CMILib.ConfigReader;
|
||||
import com.gamingmesh.jobs.stuff.Util;
|
||||
|
||||
public class LanguageManager {
|
||||
|
||||
@ -24,49 +18,9 @@ public class LanguageManager {
|
||||
return languages;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static List<String> getClassesFromPackage(String pckgname, String cleaner) throws ClassNotFoundException {
|
||||
List<String> result = new ArrayList<>();
|
||||
try {
|
||||
for (URL jarURL : ((URLClassLoader) Jobs.class.getClassLoader()).getURLs()) {
|
||||
try {
|
||||
result.addAll(getClassesInSamePackageFromJar(pckgname, jarURL.toURI().getPath(), cleaner));
|
||||
} catch (URISyntaxException e) {
|
||||
}
|
||||
}
|
||||
} catch (NullPointerException x) {
|
||||
throw new ClassNotFoundException(pckgname + " does not appear to be a valid package (Null pointer exception)");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static List<String> getClassesInSamePackageFromJar(String packageName, String jarPath, String cleaner) {
|
||||
JarFile jarFile = null;
|
||||
List<String> listOfCommands = new ArrayList<>();
|
||||
try {
|
||||
jarFile = new JarFile(jarPath);
|
||||
Enumeration<JarEntry> en = jarFile.entries();
|
||||
while (en.hasMoreElements()) {
|
||||
JarEntry entry = en.nextElement();
|
||||
String entryName = entry.getName();
|
||||
packageName = packageName.replace(".", "/");
|
||||
if (entryName != null && entryName.endsWith(".yml") && entryName.startsWith(packageName)) {
|
||||
String name = entryName.replace(packageName, "").replace(".yml", "").replace("/", "");
|
||||
if (name.contains("$"))
|
||||
name = name.split("\\$")[0];
|
||||
if (cleaner != null)
|
||||
name = name.replace(cleaner, "");
|
||||
listOfCommands.add(name);
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
} finally {
|
||||
if (jarFile != null)
|
||||
try {
|
||||
jarFile.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
return listOfCommands;
|
||||
return Util.getFilesFromPackage(pckgname, cleaner, "yml");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -79,7 +33,7 @@ public class LanguageManager {
|
||||
// This should be present to copy over default locale files into locale folder if file doesn't exist. Grabs all files from plugin file.
|
||||
languages = new ArrayList<>();
|
||||
try {
|
||||
languages.addAll(getClassesFromPackage("locale", "messages_"));
|
||||
languages.addAll(Util.getFilesFromPackage("locale", "messages_", "yml"));
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -91,7 +45,7 @@ public class LanguageManager {
|
||||
//Up to here.
|
||||
|
||||
String ls = Jobs.getGCManager().localeString;
|
||||
if (ls.equals(""))
|
||||
if (ls.isEmpty())
|
||||
ls = "en";
|
||||
|
||||
languages.clear();
|
||||
|
@ -194,7 +194,7 @@ public class NameTranslatorManager {
|
||||
|
||||
// This should be present to copy over default files into TranslatableWords folder if file doesn't exist. Grabs all files from plugin file.
|
||||
try {
|
||||
languages.addAll(LanguageManager.getClassesFromPackage("TranslatableWords", "Words_"));
|
||||
languages.addAll(Util.getFilesFromPackage("TranslatableWords", "Words_", "yml"));
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -333,7 +333,7 @@ public class JobsPlayer {
|
||||
* @return true if have
|
||||
*/
|
||||
public boolean havePermission(String perm) {
|
||||
Player player = Bukkit.getPlayer(getPlayerUUID());
|
||||
Player player = Bukkit.getPlayer(getUniqueId());
|
||||
if (player != null)
|
||||
return player.hasPermission(perm);
|
||||
return false;
|
||||
@ -365,7 +365,7 @@ public class JobsPlayer {
|
||||
* @return the getName
|
||||
*/
|
||||
public String getName() {
|
||||
Player player = Bukkit.getPlayer(getPlayerUUID());
|
||||
Player player = Bukkit.getPlayer(getUniqueId());
|
||||
if (player != null)
|
||||
userName = player.getName();
|
||||
return userName;
|
||||
@ -1141,11 +1141,11 @@ public class JobsPlayer {
|
||||
}
|
||||
|
||||
public int getFurnaceCount() {
|
||||
return FurnaceBrewingHandling.getTotalFurnaces(getPlayerUUID());
|
||||
return FurnaceBrewingHandling.getTotalFurnaces(getUniqueId());
|
||||
}
|
||||
|
||||
public int getBrewingStandCount() {
|
||||
return FurnaceBrewingHandling.getTotalBrewingStands(getPlayerUUID());
|
||||
return FurnaceBrewingHandling.getTotalBrewingStands(getUniqueId());
|
||||
}
|
||||
|
||||
public int getMaxBrewingStandsAllowed() {
|
||||
|
@ -1,38 +0,0 @@
|
||||
/**
|
||||
* Jobs Plugin for Bukkit
|
||||
* Copyright (C) 2011 Zak Ford <zak.j.ford@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.gamingmesh.jobs.stuff;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.UUID;
|
||||
|
||||
public class UUIDUtil {
|
||||
public static byte[] toBytes(UUID uuid) {
|
||||
ByteBuffer bb = ByteBuffer.allocate(16);
|
||||
bb.putLong(uuid.getMostSignificantBits());
|
||||
bb.putLong(uuid.getLeastSignificantBits());
|
||||
return bb.array();
|
||||
}
|
||||
|
||||
public static UUID fromBytes(byte[] array) {
|
||||
ByteBuffer bb = ByteBuffer.wrap(array);
|
||||
long most = bb.getLong();
|
||||
long least = bb.getLong();
|
||||
return new UUID(most, least);
|
||||
}
|
||||
}
|
@ -1,10 +1,17 @@
|
||||
package com.gamingmesh.jobs.stuff;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@ -209,4 +216,61 @@ public class Util {
|
||||
return;
|
||||
Util.jobsWorlds.put(jobsWorld.getName().toLowerCase(), jobsWorld);
|
||||
}
|
||||
|
||||
public static List<String> getFilesFromPackage(String pckgname) throws ClassNotFoundException {
|
||||
return getFilesFromPackage(pckgname, null, "class");
|
||||
}
|
||||
|
||||
public static List<String> getFilesFromPackage(String pckgname, String cleaner) throws ClassNotFoundException {
|
||||
return getFilesFromPackage(pckgname, cleaner, "class");
|
||||
}
|
||||
|
||||
public static List<String> getFilesFromPackage(String pckgname, String cleaner, String fileType) throws ClassNotFoundException {
|
||||
List<String> result = new ArrayList<>();
|
||||
try {
|
||||
for (URL jarURL : ((URLClassLoader) Jobs.class.getClassLoader()).getURLs()) {
|
||||
try {
|
||||
result.addAll(getFilesInSamePackageFromJar(pckgname, jarURL.toURI().getPath(), cleaner, fileType));
|
||||
} catch (URISyntaxException e) {
|
||||
}
|
||||
}
|
||||
} catch (NullPointerException x) {
|
||||
throw new ClassNotFoundException(pckgname + " does not appear to be a valid package (Null pointer exception)");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<String> getFilesInSamePackageFromJar(String packageName, String jarPath, String cleaner, String fileType) {
|
||||
JarFile jarFile = null;
|
||||
List<String> listOfCommands = new ArrayList<>();
|
||||
try {
|
||||
jarFile = new JarFile(jarPath);
|
||||
Enumeration<JarEntry> en = jarFile.entries();
|
||||
while (en.hasMoreElements()) {
|
||||
JarEntry entry = en.nextElement();
|
||||
String entryName = entry.getName();
|
||||
|
||||
packageName = packageName.replace(".", "/");
|
||||
|
||||
if (entryName != null && entryName.endsWith("." + fileType) && entryName.startsWith(packageName)) {
|
||||
String name = entryName.replace(packageName, "").replace("." + fileType, "").replace("/", "");
|
||||
if (name.contains("$"))
|
||||
name = name.split("\\$")[0];
|
||||
|
||||
if (cleaner != null)
|
||||
name = name.replace(cleaner, "");
|
||||
|
||||
listOfCommands.add(name);
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
} finally {
|
||||
if (jarFile != null)
|
||||
try {
|
||||
jarFile.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
return listOfCommands;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user