mirror of
https://github.com/songoda/SongodaCore.git
synced 2025-02-17 03:51:27 +01:00
General code cleanup.
This commit is contained in:
parent
9b523726ce
commit
1f1ea4d96b
@ -1,24 +1,13 @@
|
||||
package com.songoda.core;
|
||||
|
||||
import com.songoda.core.core.PluginInfo;
|
||||
import com.songoda.core.core.LocaleModule;
|
||||
import com.songoda.core.core.PluginInfoModule;
|
||||
import com.songoda.core.core.SongodaCoreCommand;
|
||||
import com.songoda.core.core.SongodaCoreDiagCommand;
|
||||
import com.songoda.core.commands.CommandManager;
|
||||
import com.songoda.core.compatibility.ClientVersion;
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.songoda.core.database.DataManagerAbstract;
|
||||
import com.songoda.core.core.LocaleModule;
|
||||
import com.songoda.core.core.PluginInfo;
|
||||
import com.songoda.core.core.PluginInfoModule;
|
||||
import com.songoda.core.core.SongodaCoreCommand;
|
||||
import com.songoda.core.core.SongodaCoreDiagCommand;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -36,22 +25,38 @@ import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class SongodaCore {
|
||||
|
||||
private final static String prefix = "[SongodaCore]";
|
||||
|
||||
/**
|
||||
* Whenever we make a major change to the core GUI, updater,
|
||||
* Whenever we make a major change to the core GUI, updater,
|
||||
* or other function used by the core, increment this number
|
||||
*/
|
||||
private final static int coreRevision = 6;
|
||||
|
||||
|
||||
/**
|
||||
* This has been added as of Rev 6 <br>
|
||||
* This value is automatically filled in by gitlab-ci
|
||||
*/
|
||||
private final static String coreVersion = "2.4.4";
|
||||
|
||||
|
||||
/**
|
||||
* This is specific to the website api
|
||||
*/
|
||||
@ -67,7 +72,7 @@ public class SongodaCore {
|
||||
|
||||
public static boolean hasShading() {
|
||||
// sneaky hack to check the package name since maven tries to re-shade all references to the package string
|
||||
return !SongodaCore.class.getPackage().getName().equals(new String(new char[]{'c','o','m','.','s','o','n','g','o','d','a','.','c','o','r','e'}));
|
||||
return !SongodaCore.class.getPackage().getName().equals(new String(new char[]{'c', 'o', 'm', '.', 's', 'o', 'n', 'g', 'o', 'd', 'a', '.', 'c', 'o', 'r', 'e'}));
|
||||
}
|
||||
|
||||
public static void registerPlugin(JavaPlugin plugin, int pluginID, CompatibleMaterial icon) {
|
||||
@ -79,10 +84,10 @@ public class SongodaCore {
|
||||
}
|
||||
|
||||
public static void registerPlugin(JavaPlugin plugin, int pluginID, String icon, String coreVersion) {
|
||||
if(INSTANCE == null) {
|
||||
if (INSTANCE == null) {
|
||||
// First: are there any other instances of SongodaCore active?
|
||||
for (Class<?> clazz : Bukkit.getServicesManager().getKnownServices()) {
|
||||
if(clazz.getSimpleName().equals("SongodaCore")) {
|
||||
if (clazz.getSimpleName().equals("SongodaCore")) {
|
||||
try {
|
||||
// test to see if we're up to date
|
||||
int otherVersion;
|
||||
@ -91,12 +96,12 @@ public class SongodaCore {
|
||||
} catch (Exception ignore) {
|
||||
otherVersion = -1;
|
||||
}
|
||||
if(otherVersion >= getCoreVersion()) {
|
||||
if (otherVersion >= getCoreVersion()) {
|
||||
// use the active service
|
||||
// assuming that the other is greater than R6 if we get here ;)
|
||||
clazz.getMethod("registerPlugin", JavaPlugin.class, int.class, String.class, String.class).invoke(null, plugin, pluginID, icon, coreVersion);
|
||||
|
||||
if(hasShading()) {
|
||||
if (hasShading()) {
|
||||
(INSTANCE = new SongodaCore()).piggybackedPlugin = plugin;
|
||||
INSTANCE.shadingListener = new ShadedEventListener();
|
||||
Bukkit.getPluginManager().registerEvents(INSTANCE.shadingListener, plugin);
|
||||
@ -116,17 +121,17 @@ public class SongodaCore {
|
||||
INSTANCE.register(plugin, pluginID, icon, coreVersion);
|
||||
Bukkit.getServicesManager().register(SongodaCore.class, INSTANCE, plugin, ServicePriority.Normal);
|
||||
// we need (JavaPlugin plugin, int pluginID, String icon) for our object
|
||||
if(!otherPlugins.isEmpty()) {
|
||||
if (!otherPlugins.isEmpty()) {
|
||||
Object testSubject = otherPlugins.get(0);
|
||||
Class otherPluginInfo = testSubject.getClass();
|
||||
Method otherPluginInfo_getJavaPlugin = otherPluginInfo.getMethod("getJavaPlugin");
|
||||
Method otherPluginInfo_getSongodaId = otherPluginInfo.getMethod("getSongodaId");
|
||||
Method otherPluginInfo_getCoreIcon = otherPluginInfo.getMethod("getCoreIcon");
|
||||
Method otherPluginInfo_getCoreLibraryVersion = otherVersion >= 6 ? otherPluginInfo.getMethod("getCoreLibraryVersion") : null;
|
||||
for(Object other : otherPlugins) {
|
||||
for (Object other : otherPlugins) {
|
||||
INSTANCE.register(
|
||||
(JavaPlugin) otherPluginInfo_getJavaPlugin.invoke(other),
|
||||
(int) otherPluginInfo_getSongodaId.invoke(other),
|
||||
(JavaPlugin) otherPluginInfo_getJavaPlugin.invoke(other),
|
||||
(int) otherPluginInfo_getSongodaId.invoke(other),
|
||||
(String) otherPluginInfo_getCoreIcon.invoke(other),
|
||||
otherPluginInfo_getCoreLibraryVersion != null ? (String) otherPluginInfo_getCoreLibraryVersion.invoke(other) : "?");
|
||||
}
|
||||
@ -163,10 +168,16 @@ public class SongodaCore {
|
||||
Bukkit.getPluginManager().registerEvents(loginListener, piggybackedPlugin);
|
||||
Bukkit.getPluginManager().registerEvents(shadingListener, piggybackedPlugin);
|
||||
// we aggressevely want to own this command
|
||||
tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(piggybackedPlugin, ()->{CommandManager.registerCommandDynamically(piggybackedPlugin, "songoda", commandManager, commandManager);}, 10 * 60 * 1));
|
||||
tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(piggybackedPlugin, ()->{CommandManager.registerCommandDynamically(piggybackedPlugin, "songoda", commandManager, commandManager);}, 20 * 60 * 1));
|
||||
tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(piggybackedPlugin, ()->{CommandManager.registerCommandDynamically(piggybackedPlugin, "songoda", commandManager, commandManager);}, 20 * 60 * 2));
|
||||
tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(piggybackedPlugin, ()->registerAllPlugins(), 20 * 60 * 2));
|
||||
tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(piggybackedPlugin, () -> {
|
||||
CommandManager.registerCommandDynamically(piggybackedPlugin, "songoda", commandManager, commandManager);
|
||||
}, 10 * 60 * 1));
|
||||
tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(piggybackedPlugin, () -> {
|
||||
CommandManager.registerCommandDynamically(piggybackedPlugin, "songoda", commandManager, commandManager);
|
||||
}, 20 * 60 * 1));
|
||||
tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(piggybackedPlugin, () -> {
|
||||
CommandManager.registerCommandDynamically(piggybackedPlugin, "songoda", commandManager, commandManager);
|
||||
}, 20 * 60 * 2));
|
||||
tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(piggybackedPlugin, () -> registerAllPlugins(), 20 * 60 * 2));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -184,6 +195,7 @@ public class SongodaCore {
|
||||
commandManager = null;
|
||||
loginListener = null;
|
||||
}
|
||||
|
||||
private ArrayList<BukkitTask> tasks = new ArrayList();
|
||||
|
||||
/**
|
||||
@ -369,7 +381,7 @@ public class SongodaCore {
|
||||
void onEnable(PluginEnableEvent event) {
|
||||
// technically shouldn't have online players here, but idk
|
||||
if (!via && (via = event.getPlugin().getName().equals("ViaVersion"))) {
|
||||
Bukkit.getOnlinePlayers().forEach(p -> ClientVersion.onLoginVia(p));
|
||||
Bukkit.getOnlinePlayers().forEach(p -> ClientVersion.onLoginVia(p));
|
||||
} else if (!proto && (proto = event.getPlugin().getName().equals("ProtocolSupport"))) {
|
||||
Bukkit.getOnlinePlayers().forEach(p -> ClientVersion.onLoginProtocol(p));
|
||||
}
|
||||
@ -385,7 +397,7 @@ public class SongodaCore {
|
||||
// don't spam players with update checks
|
||||
long now = System.currentTimeMillis();
|
||||
Long last = lastCheck.get(player.getUniqueId());
|
||||
if(last != null && now - 10000 < last) return;
|
||||
if (last != null && now - 10000 < last) return;
|
||||
lastCheck.put(player.getUniqueId(), now);
|
||||
// is this player good to revieve update notices?
|
||||
if (!event.getPlayer().isOp() && !player.hasPermission("songoda.updatecheck")) return;
|
||||
|
@ -3,14 +3,15 @@ package com.songoda.core;
|
||||
import com.songoda.core.configuration.Config;
|
||||
import com.songoda.core.locale.Locale;
|
||||
import com.songoda.core.utils.Metrics;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* REMINDER: When converting plugins to use this, REMOVE METRICS <br>
|
||||
* Must not have two instances of Metrics enabled!
|
||||
@ -41,7 +42,7 @@ public abstract class SongodaPlugin extends JavaPlugin {
|
||||
|
||||
/**
|
||||
* Any other plugin configuration files used by the plugin.
|
||||
*
|
||||
*
|
||||
* @return a list of Configs that are used in addition to the main config.
|
||||
*/
|
||||
public abstract List<Config> getExtraConfig();
|
||||
@ -73,16 +74,16 @@ public abstract class SongodaPlugin extends JavaPlugin {
|
||||
} catch (Throwable t) {
|
||||
Bukkit.getLogger().log(Level.SEVERE,
|
||||
"Unexpected error while loading " + getDescription().getName()
|
||||
+ " v" + getDescription().getVersion()
|
||||
+ " c" + SongodaCore.getCoreLibraryVersion()
|
||||
+ ": Disabling plugin!", t);
|
||||
+ " v" + getDescription().getVersion()
|
||||
+ " c" + SongodaCore.getCoreLibraryVersion()
|
||||
+ ": Disabling plugin!", t);
|
||||
emergencyStop = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onEnable() {
|
||||
if(emergencyStop) {
|
||||
if (emergencyStop) {
|
||||
setEnabled(false);
|
||||
return;
|
||||
}
|
||||
@ -100,7 +101,7 @@ public abstract class SongodaPlugin extends JavaPlugin {
|
||||
onPluginEnable();
|
||||
// Load Data.
|
||||
Bukkit.getScheduler().runTaskLater(this, this::onDataLoad, dataLoadDelay);
|
||||
if(emergencyStop) {
|
||||
if (emergencyStop) {
|
||||
console.sendMessage(ChatColor.RED + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
|
||||
console.sendMessage(" ");
|
||||
return;
|
||||
@ -110,9 +111,9 @@ public abstract class SongodaPlugin extends JavaPlugin {
|
||||
} catch (Throwable t) {
|
||||
Bukkit.getLogger().log(Level.SEVERE,
|
||||
"Unexpected error while loading " + getDescription().getName()
|
||||
+ " v" + getDescription().getVersion()
|
||||
+ " c" + SongodaCore.getCoreLibraryVersion()
|
||||
+ ": Disabling plugin!", t);
|
||||
+ " v" + getDescription().getVersion()
|
||||
+ " c" + SongodaCore.getCoreLibraryVersion()
|
||||
+ ": Disabling plugin!", t);
|
||||
emergencyStop();
|
||||
console.sendMessage(ChatColor.RED + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
|
||||
console.sendMessage(" ");
|
||||
@ -156,8 +157,8 @@ public abstract class SongodaPlugin extends JavaPlugin {
|
||||
* Set the plugin's locale to a specific language
|
||||
*
|
||||
* @param localeName locale to use, eg "en_US"
|
||||
* @param reload optionally reload the loaded locale if the locale didn't
|
||||
* change
|
||||
* @param reload optionally reload the loaded locale if the locale didn't
|
||||
* change
|
||||
* @return true if the locale exists and was loaded successfully
|
||||
*/
|
||||
public boolean setLocale(String localeName, boolean reload) {
|
||||
|
@ -179,7 +179,7 @@ public class ChatMessage {
|
||||
|
||||
Object packet;
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_16)) {
|
||||
packet = mc_PacketPlayOutChat_new.newInstance(mc_IChatBaseComponent_ChatSerializer_a.invoke(null, gson.toJson(textList)), mc_chatMessageType_Chat.get(null), ((Player)sender).getUniqueId());
|
||||
packet = mc_PacketPlayOutChat_new.newInstance(mc_IChatBaseComponent_ChatSerializer_a.invoke(null, gson.toJson(textList)), mc_chatMessageType_Chat.get(null), ((Player) sender).getUniqueId());
|
||||
} else {
|
||||
packet = mc_PacketPlayOutChat_new.newInstance(mc_IChatBaseComponent_ChatSerializer_a.invoke(null, gson.toJson(textList)));
|
||||
}
|
||||
|
@ -66,6 +66,7 @@ public abstract class AbstractCommand {
|
||||
}
|
||||
|
||||
public static enum ReturnType {SUCCESS, NEEDS_PLAYER, FAILURE, SYNTAX_ERROR}
|
||||
|
||||
public static enum CommandType {PLAYER_ONLY, CONSOLE_OK}
|
||||
}
|
||||
|
||||
|
@ -2,17 +2,6 @@ package com.songoda.core.commands;
|
||||
|
||||
import com.songoda.core.compatibility.ServerProject;
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
@ -25,6 +14,18 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CommandManager implements CommandExecutor, TabCompleter {
|
||||
|
||||
private final JavaPlugin plugin;
|
||||
@ -76,8 +77,8 @@ public class CommandManager implements CommandExecutor, TabCompleter {
|
||||
.forEach(c -> {
|
||||
all.add(c.parent);
|
||||
c.children.values().stream()
|
||||
.filter(s -> !all.contains(s))
|
||||
.forEach(s -> all.add(s));
|
||||
.filter(s -> !all.contains(s))
|
||||
.forEach(s -> all.add(s));
|
||||
});
|
||||
return all;
|
||||
}
|
||||
|
@ -1,14 +1,6 @@
|
||||
package com.songoda.core.commands;
|
||||
|
||||
import com.songoda.core.compatibility.EntityNamespace;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -18,6 +10,15 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class SelectorArguments {
|
||||
|
||||
static Pattern selectorPattern = Pattern.compile("^(@[apers])(\\[(.*?)\\])?$");
|
||||
@ -26,8 +27,8 @@ public class SelectorArguments {
|
||||
/**
|
||||
* Parse a command selector using Minecraft's selector format. <br>
|
||||
* Currently only supports distance and entity type
|
||||
*
|
||||
* @param sender CommandBlock or Player running the command
|
||||
*
|
||||
* @param sender CommandBlock or Player running the command
|
||||
* @param argument argument with the selector to parse
|
||||
* @return SelectorArguments Object for grabbing the list of entities, or null if the selector is invalid
|
||||
*/
|
||||
@ -149,7 +150,7 @@ public class SelectorArguments {
|
||||
return rangeMax == Double.POSITIVE_INFINITY
|
||||
? location.getWorld().getEntitiesByClasses(Player.class)
|
||||
: location.getWorld().getNearbyEntities(location, rangeMax * 2, rangeMax * 2, rangeMax * 2).stream()
|
||||
.filter(e -> e instanceof Player).collect(Collectors.toSet());
|
||||
.filter(e -> e instanceof Player).collect(Collectors.toSet());
|
||||
case ALL_ENTITIES:
|
||||
return rangeMax == Double.POSITIVE_INFINITY
|
||||
? location.getWorld().getEntities()
|
||||
@ -159,7 +160,7 @@ public class SelectorArguments {
|
||||
}
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
|
||||
protected List<Entity> filter(Location location, Collection<Entity> list) {
|
||||
Stream<Entity> stream = list.stream()
|
||||
.filter(p -> rangeMin == 0 || p.getLocation().distance(location) > rangeMin)
|
||||
|
@ -1,11 +1,12 @@
|
||||
package com.songoda.core.compatibility;
|
||||
|
||||
import com.songoda.core.SongodaCore;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Handy reference for checking a connected client's Minecraft version<br>
|
||||
* NOTE: this is automatically initialized through SongodaCore
|
||||
@ -16,7 +17,7 @@ public class ClientVersion {
|
||||
|
||||
/**
|
||||
* Check to see what client version this player is connected to the server
|
||||
* with. Note that if a player is connecting with a newer client than the server,
|
||||
* with. Note that if a player is connecting with a newer client than the server,
|
||||
* this value will simply be the server version.
|
||||
*
|
||||
* @param player Player to check
|
||||
@ -34,8 +35,8 @@ public class ClientVersion {
|
||||
*/
|
||||
@Deprecated
|
||||
public static void onLoginProtocol(Player p) {
|
||||
Bukkit.getScheduler().runTaskLater(SongodaCore.getHijackedPlugin(), ()-> {
|
||||
if(p.isOnline()) {
|
||||
Bukkit.getScheduler().runTaskLater(SongodaCore.getHijackedPlugin(), () -> {
|
||||
if (p.isOnline()) {
|
||||
final int version = protocolsupport.api.ProtocolSupportAPI.getProtocolVersion(p).getId();
|
||||
players.put(p.getUniqueId(), protocolToVersion(version));
|
||||
}
|
||||
@ -47,8 +48,8 @@ public class ClientVersion {
|
||||
*/
|
||||
@Deprecated
|
||||
public static void onLoginVia(Player p) {
|
||||
Bukkit.getScheduler().runTaskLater(SongodaCore.getHijackedPlugin(), ()-> {
|
||||
if(p.isOnline()) {
|
||||
Bukkit.getScheduler().runTaskLater(SongodaCore.getHijackedPlugin(), () -> {
|
||||
if (p.isOnline()) {
|
||||
final int version = us.myles.ViaVersion.api.Via.getAPI().getPlayerVersion(p.getUniqueId());
|
||||
players.put(p.getUniqueId(), protocolToVersion(version));
|
||||
}
|
||||
|
@ -8,7 +8,15 @@ import org.bukkit.block.Biome;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Arrays;
|
||||
import java.util.Deque;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Biomes that are compatible with server versions 1.7+
|
||||
|
@ -5,7 +5,11 @@ import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Items that are compatible with server versions 1.7+
|
||||
@ -1356,7 +1360,7 @@ public enum CompatibleMaterial {
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) { // Flattening
|
||||
return CompatibleMaterial.getMaterialFromNewBlock(block);
|
||||
} else { // Pre-Flattening
|
||||
if(block != null) {
|
||||
if (block != null) {
|
||||
if (block.getData() != 0) {
|
||||
for (CompatibleMaterial cm : CompatibleMaterial.values()) {
|
||||
if (cm.isValidItem() && !cm.usesCompatibility() && cm.getMaterial() != null && cm.getMaterial().equals(block.getType())) {
|
||||
@ -1375,7 +1379,7 @@ public enum CompatibleMaterial {
|
||||
/**
|
||||
* Lookup a Material by Material and data, corrected for legacy
|
||||
*
|
||||
* @param mat material to check
|
||||
* @param mat material to check
|
||||
* @param data data of the block
|
||||
* @return LegacyMaterial or null if none found
|
||||
*/
|
||||
@ -1383,7 +1387,7 @@ public enum CompatibleMaterial {
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) { // Flattening
|
||||
return CompatibleMaterial.getMaterial(mat);
|
||||
} else { // Pre-Flattening
|
||||
if(mat != null){
|
||||
if (mat != null) {
|
||||
if (data != 0) {
|
||||
for (CompatibleMaterial cm : CompatibleMaterial.values()) {
|
||||
if (cm.getMaterial() != null
|
||||
|
@ -7,15 +7,15 @@ import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Sounds that are compatible with server versions 1.7+ <br>
|
||||
* TODO: This needs work.
|
||||
* TODO: This needs work.
|
||||
* Finished 1.8, finished 1.9 blocks, resume with 1.9 entities<br>
|
||||
* Between 1.8 and 1.9, all sounds were renamed, and between 1.12 and 1.13, some
|
||||
* sounds were renamed. New sounds have been added by different versions, as
|
||||
* well. The intent of this class is to provide either the correct sound or a
|
||||
* near equivalent for the current server.
|
||||
*
|
||||
* @since 2019-08-25
|
||||
* @author jascotty2
|
||||
* @since 2019-08-25
|
||||
*/
|
||||
public enum CompatibleSound {
|
||||
|
||||
@ -200,7 +200,7 @@ public enum CompatibleSound {
|
||||
PARTICLE_SOUL_ESCAPE(ServerVersion.V1_16, v(null, true)),
|
||||
|
||||
/* 1.15 */
|
||||
// TODO: add similar sounds for older versions
|
||||
// TODO: add similar sounds for older versions
|
||||
BLOCK_BEEHIVE_DRIP(ServerVersion.V1_15, v(null, true)),
|
||||
BLOCK_BEEHIVE_ENTER(ServerVersion.V1_15, v(null, true)),
|
||||
BLOCK_BEEHIVE_EXIT(ServerVersion.V1_15, v(null, true)),
|
||||
@ -406,7 +406,7 @@ public enum CompatibleSound {
|
||||
BLOCK_WET_GRASS_HIT,
|
||||
BLOCK_WET_GRASS_PLACE,
|
||||
BLOCK_WET_GRASS_STEP,
|
||||
BLOCK_WOODEN_BUTTON_CLICK_OFF(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_WOOD_BUTTON_CLICK_ON"), v("WOOD_CLICK")),
|
||||
BLOCK_WOODEN_BUTTON_CLICK_OFF(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_WOOD_BUTTON_CLICK_ON"), v("WOOD_CLICK")),
|
||||
BLOCK_WOODEN_BUTTON_CLICK_ON(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_WOOD_BUTTON_CLICK_ON"), v("WOOD_CLICK")),
|
||||
BLOCK_WOODEN_DOOR_CLOSE("DOOR_CLOSE"),
|
||||
BLOCK_WOODEN_DOOR_OPEN("DOOR_OPEN"),
|
||||
@ -920,7 +920,7 @@ public enum CompatibleSound {
|
||||
ENTITY_ZOMBIE_BREAK_WOODEN_DOOR(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_ZOMBIE_BREAK_DOOR_WOOD", true), v("ZOMBIE_WOODBREAK")),
|
||||
ENTITY_ZOMBIE_CONVERTED_TO_DROWNED,
|
||||
ENTITY_ZOMBIE_DEATH("ZOMBIE_DEATH"),
|
||||
ENTITY_ZOMBIE_DESTROY_EGG ,
|
||||
ENTITY_ZOMBIE_DESTROY_EGG,
|
||||
ENTITY_ZOMBIE_HORSE_AMBIENT("HORSE_ZOMBIE_IDLE"),
|
||||
ENTITY_ZOMBIE_HORSE_DEATH("HORSE_ZOMBIE_DEATH"),
|
||||
ENTITY_ZOMBIE_HORSE_HURT("HORSE_ZOMBIE_HIT"),
|
||||
@ -1028,7 +1028,7 @@ public enum CompatibleSound {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(DEBUG && find == null) {
|
||||
if (DEBUG && find == null) {
|
||||
System.out.println("Sound for " + name() + " Not found!");
|
||||
}
|
||||
sound = find;
|
||||
@ -1127,7 +1127,7 @@ public enum CompatibleSound {
|
||||
*
|
||||
* @param sendTo player to send the sound to
|
||||
* @param volume the volume of the sound
|
||||
* @param pitch the pitch of the sound
|
||||
* @param pitch the pitch of the sound
|
||||
*/
|
||||
public void play(Player sendTo, float volume, float pitch) {
|
||||
sendTo.playSound(sendTo.getLocation(), getSound(), volume, pitch);
|
||||
@ -1136,10 +1136,10 @@ public enum CompatibleSound {
|
||||
/**
|
||||
* Send a sound to a specific player
|
||||
*
|
||||
* @param sendTo player to send the sound to
|
||||
* @param sendTo player to send the sound to
|
||||
* @param location where the sound should come from
|
||||
* @param volume the volume of the sound
|
||||
* @param pitch the pitch of the sound
|
||||
* @param volume the volume of the sound
|
||||
* @param pitch the pitch of the sound
|
||||
*/
|
||||
public void play(Player sendTo, Location location, float volume, float pitch) {
|
||||
sendTo.playSound(sendTo.getLocation(), getSound(), volume, pitch);
|
||||
@ -1148,10 +1148,10 @@ public enum CompatibleSound {
|
||||
/**
|
||||
* Play a sound in a world
|
||||
*
|
||||
* @param sendTo world to send the sound to
|
||||
* @param sendTo world to send the sound to
|
||||
* @param location where the sound should come from
|
||||
* @param volume the volume of the sound
|
||||
* @param pitch the pitch of the sound
|
||||
* @param volume the volume of the sound
|
||||
* @param pitch the pitch of the sound
|
||||
*/
|
||||
public void play(World sendTo, Location location, float volume, float pitch) {
|
||||
sendTo.playSound(location, getSound(), volume, pitch);
|
||||
|
@ -1,8 +1,9 @@
|
||||
package com.songoda.core.compatibility;
|
||||
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
public class EntityNamespace {
|
||||
|
||||
|
@ -1,14 +1,16 @@
|
||||
package com.songoda.core.compatibility;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Near-Materials for older servers 1.7+
|
||||
* @since 2019-08-23
|
||||
*
|
||||
* @author jascotty2
|
||||
* @since 2019-08-23
|
||||
*/
|
||||
public enum LegacyMaterialAnalouge {
|
||||
|
||||
@ -117,14 +119,14 @@ public enum LegacyMaterialAnalouge {
|
||||
ZOGLIN_SPAWN_EGG(ServerVersion.V1_15, "STONE"),
|
||||
ZOMBIFIED_PIGLIN_SPAWN_EGG(ServerVersion.V1_15, "STONE"),
|
||||
|
||||
/* 1.15 */
|
||||
BEE_SPAWN_EGG(ServerVersion.V1_15, "PARROT_SPAWN_EGG", ServerVersion.V1_12, "MONSTER_EGG", (byte) 65),
|
||||
BEE_NEST(ServerVersion.V1_15, "BIRCH_LOG", "LOG", (byte) 2),
|
||||
BEEHIVE(ServerVersion.V1_15, "SLIME_BLOCK", ServerVersion.V1_8, "WOOL", (byte) 4),
|
||||
HONEY_BLOCK(ServerVersion.V1_15, "SLIME_BLOCK", ServerVersion.V1_8, "WOOL", (byte) 4),
|
||||
HONEY_BOTTLE(ServerVersion.V1_15, "DRAGON_BREATH", ServerVersion.V1_9, "POTION", (byte) 0),
|
||||
HONEYCOMB(ServerVersion.V1_15, "SUNFLOWER", "DOUBLE_PLANT", (byte) 0),
|
||||
HONEYCOMB_BLOCK(ServerVersion.V1_15, "SLIME_BLOCK", ServerVersion.V1_8, "WOOL", (byte) 4),
|
||||
/* 1.15 */
|
||||
BEE_SPAWN_EGG(ServerVersion.V1_15, "PARROT_SPAWN_EGG", ServerVersion.V1_12, "MONSTER_EGG", (byte) 65),
|
||||
BEE_NEST(ServerVersion.V1_15, "BIRCH_LOG", "LOG", (byte) 2),
|
||||
BEEHIVE(ServerVersion.V1_15, "SLIME_BLOCK", ServerVersion.V1_8, "WOOL", (byte) 4),
|
||||
HONEY_BLOCK(ServerVersion.V1_15, "SLIME_BLOCK", ServerVersion.V1_8, "WOOL", (byte) 4),
|
||||
HONEY_BOTTLE(ServerVersion.V1_15, "DRAGON_BREATH", ServerVersion.V1_9, "POTION", (byte) 0),
|
||||
HONEYCOMB(ServerVersion.V1_15, "SUNFLOWER", "DOUBLE_PLANT", (byte) 0),
|
||||
HONEYCOMB_BLOCK(ServerVersion.V1_15, "SLIME_BLOCK", ServerVersion.V1_8, "WOOL", (byte) 4),
|
||||
|
||||
ACACIA_BOAT(ServerVersion.V1_9, "BOAT"),
|
||||
ACACIA_BUTTON(ServerVersion.V1_13, "WOOD_BUTTON"),
|
||||
@ -643,24 +645,23 @@ public enum LegacyMaterialAnalouge {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param versionLessThan AKA, what server version was this material added to minecraft?
|
||||
* @param modernAnalouge post-1.13 material name, if applicable
|
||||
* @param legacyMaterial pre-1.13 material name
|
||||
* @param legacyData data for defining specific legacy items
|
||||
* @param modernAnalouge post-1.13 material name, if applicable
|
||||
* @param legacyMaterial pre-1.13 material name
|
||||
* @param legacyData data for defining specific legacy items
|
||||
*/
|
||||
private LegacyMaterialAnalouge(ServerVersion versionLessThan, String modernAnalouge, String legacyMaterial, Byte legacyData, ServerVersion legacyMinimum, String compatMaterial, Byte compatData) {
|
||||
this.versionLessThan = versionLessThan;
|
||||
this.modernMaterial = modernAnalouge;
|
||||
this.legacyMaterial = legacyMaterial;
|
||||
this.legacyData = legacyData;
|
||||
|
||||
|
||||
this.legacyMinimumVersion = legacyMinimum;
|
||||
this.compatibleMaterial = compatMaterial;
|
||||
this.compatibleData = compatData;
|
||||
|
||||
if (ServerVersion.isServerVersionBelow(versionLessThan)) {
|
||||
if(legacyMinimumVersion != null && ServerVersion.isServerVersionBelow(legacyMinimumVersion)) {
|
||||
if (legacyMinimumVersion != null && ServerVersion.isServerVersionBelow(legacyMinimumVersion)) {
|
||||
// fallback material not available, so use its fallback
|
||||
material = Material.getMaterial(compatibleMaterial);
|
||||
data = compatibleData;
|
||||
|
@ -1,15 +1,16 @@
|
||||
package com.songoda.core.compatibility;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.bukkit.Material;
|
||||
|
||||
/**
|
||||
* Starting in Minecraft 1.13, separate materials for blocks and items were
|
||||
* phased out. This provides a translation for those values.
|
||||
*
|
||||
* @since 2019-09-12
|
||||
* @author jascotty2
|
||||
* @since 2019-09-12
|
||||
*/
|
||||
public enum LegacyMaterialBlockType {
|
||||
|
||||
@ -18,7 +19,7 @@ public enum LegacyMaterialBlockType {
|
||||
BIRCH_DOOR("BIRCH_DOOR", true),
|
||||
FURNACE("FURNACE", "BURNING_FURNACE"),
|
||||
CAKE("CAKE_BLOCK"),
|
||||
CARROTS("CARROT"), // totally makes sense, lol
|
||||
CARROTS("CARROT"), // totally makes sense, lol
|
||||
CAULDRON("CAULDRON_BLOCK"),
|
||||
COMPARATOR("REDSTONE_COMPARATOR_OFF", "REDSTONE_COMPARATOR_ON"),
|
||||
DARK_OAK_DOOR("DARK_OAK_DOOR", true),
|
||||
@ -30,18 +31,18 @@ public enum LegacyMaterialBlockType {
|
||||
FLOWER_POT("FLOWER_POT"),
|
||||
IRON_DOOR("IRON_DOOR_BLOCK", true),
|
||||
JUNGLE_DOOR("JUNGLE_DOOR", true),
|
||||
LAVA("STATIONARY_LAVA"),
|
||||
LAVA("STATIONARY_LAVA"),
|
||||
NETHER_WART("NETHER_WARTS"),
|
||||
/*
|
||||
< PURPUR_DOUBLE_SLAB
|
||||
*/
|
||||
POTATOES("POTATO"),
|
||||
POTATOES("POTATO"),
|
||||
REDSTONE_LAMP("REDSTONE_LAMP_OFF", "REDSTONE_LAMP_ON"),
|
||||
REDSTONE_ORE("REDSTONE_ORE", "GLOWING_REDSTONE_ORE"),
|
||||
REDSTONE_TORCH("REDSTONE_TORCH_ON", "REDSTONE_TORCH_OFF"),
|
||||
SPRUCE_DOOR("SPRUCE_DOOR"),
|
||||
SUGAR_CANE("SUGAR_CANE_BLOCK"),
|
||||
WATER("STATIONARY_WATER"),
|
||||
WATER("STATIONARY_WATER"),
|
||||
WHEAT("CROPS");
|
||||
final String blockMaterialName;
|
||||
final String alternateBlockMaterialName;
|
||||
@ -54,7 +55,7 @@ public enum LegacyMaterialBlockType {
|
||||
for (LegacyMaterialBlockType t : values()) {
|
||||
lookupTable.put(t.name(), t);
|
||||
reverseLookupTable.put(t.blockMaterialName, t);
|
||||
if(t.alternateBlockMaterialName != null) {
|
||||
if (t.alternateBlockMaterialName != null) {
|
||||
reverseLookupTable.put(t.alternateBlockMaterialName, t);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,10 @@
|
||||
package com.songoda.core.compatibility;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
@ -7,15 +12,12 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Particle effects for servers 1.8 and below
|
||||
* @since 2019-08-23
|
||||
*
|
||||
* @author jascotty2
|
||||
* @since 2019-08-23
|
||||
*/
|
||||
public class LegacyParticleEffects {
|
||||
|
||||
@ -157,19 +159,18 @@ public class LegacyParticleEffects {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param l exact location to spawn the particle
|
||||
* @param e particle effect type
|
||||
* @param xx for notes, this is a value 0-1 for the color ([0-24]/24), for
|
||||
* redstone this is the red value 0-1 ([0-255]/255).
|
||||
* Otherwise this is the distance for particles to fly on the x-axis.
|
||||
* @param yy for redstone this is the green value 0-1 ([0-255]/255)
|
||||
* Otherwise this is the distance for particles to fly on the y-axis.
|
||||
* @param zz for redstone this is the blue value 0-1 ([0-255]/255)
|
||||
* Otherwise this is the distance for particles to fly on the z-axis.
|
||||
* @param effectSpeed particle effect speed
|
||||
* @param l exact location to spawn the particle
|
||||
* @param e particle effect type
|
||||
* @param xx for notes, this is a value 0-1 for the color ([0-24]/24), for
|
||||
* redstone this is the red value 0-1 ([0-255]/255).
|
||||
* Otherwise this is the distance for particles to fly on the x-axis.
|
||||
* @param yy for redstone this is the green value 0-1 ([0-255]/255)
|
||||
* Otherwise this is the distance for particles to fly on the y-axis.
|
||||
* @param zz for redstone this is the blue value 0-1 ([0-255]/255)
|
||||
* Otherwise this is the distance for particles to fly on the z-axis.
|
||||
* @param effectSpeed particle effect speed
|
||||
* @param amountOfParticles extra particles to spawn (client-side)
|
||||
* @param localOnly list of players to send the packets to, or null for all players
|
||||
* @param localOnly list of players to send the packets to, or null for all players
|
||||
*/
|
||||
public static void createParticle(Location l, Type e, float xx, float yy, float zz, float effectSpeed, int amountOfParticles, List<Player> localOnly) {
|
||||
if (!enabled || e == null || effectSpeed < 0 || amountOfParticles < 0
|
||||
|
@ -1,8 +1,9 @@
|
||||
package com.songoda.core.compatibility;
|
||||
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
public class LegacyPotionEffects {
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.songoda.core.configuration;
|
||||
|
||||
import com.songoda.core.configuration.ConfigFormattingRules.CommentStyle;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
@ -11,8 +12,8 @@ import java.util.stream.Collectors;
|
||||
/**
|
||||
* A comment for a configuration key
|
||||
*
|
||||
* @since 2019-08-28
|
||||
* @author jascotty2
|
||||
* @since 2019-08-28
|
||||
*/
|
||||
public class Comment {
|
||||
|
||||
@ -57,7 +58,7 @@ public class Comment {
|
||||
public String toString() {
|
||||
return lines.isEmpty() ? "" : lines.stream().collect(Collectors.joining("\n"));
|
||||
}
|
||||
|
||||
|
||||
public static Comment loadComment(List<String> lines) {
|
||||
CommentStyle style = ConfigFormattingRules.parseStyle(lines);
|
||||
int linePad = (style.drawBorder ? 1 : 0) + (style.drawSpace ? 1 : 0);
|
||||
|
@ -1,19 +1,20 @@
|
||||
package com.songoda.core.configuration;
|
||||
|
||||
import com.songoda.core.utils.TextUtils;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConstructor;
|
||||
import org.bukkit.configuration.file.YamlRepresenter;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.error.YAMLException;
|
||||
import org.yaml.snakeyaml.representer.Representer;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
@ -29,24 +30,12 @@ import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConstructor;
|
||||
import org.bukkit.configuration.file.YamlRepresenter;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.error.YAMLException;
|
||||
import org.yaml.snakeyaml.representer.Representer;
|
||||
|
||||
/**
|
||||
* Configuration settings for a plugin
|
||||
*
|
||||
* @since 2019-08-28
|
||||
* @author jascotty2
|
||||
* @since 2019-08-28
|
||||
*/
|
||||
public class Config extends ConfigSection {
|
||||
|
||||
@ -189,7 +178,7 @@ public class Config extends ConfigSection {
|
||||
|
||||
/**
|
||||
* Should comments from the config file be loaded when loading?
|
||||
*
|
||||
*
|
||||
* @param loadComments set to false if you do not want to preserve node comments
|
||||
*/
|
||||
public void setLoadComments(boolean loadComments) {
|
||||
@ -203,7 +192,7 @@ public class Config extends ConfigSection {
|
||||
/**
|
||||
* Should the configuration automatically save whenever it's been changed? <br>
|
||||
* All saves are done asynchronously, so this should not impact server performance.
|
||||
*
|
||||
*
|
||||
* @param autosave set to true if autosaving is enabled.
|
||||
* @return this class
|
||||
*/
|
||||
@ -220,7 +209,7 @@ public class Config extends ConfigSection {
|
||||
/**
|
||||
* If autosave is enabled, this is the delay between a change and when the save is started. <br>
|
||||
* If the configuration is changed within this period, the timer is not reset.
|
||||
*
|
||||
*
|
||||
* @param autosaveInterval time in seconds
|
||||
* @return this class
|
||||
*/
|
||||
@ -259,7 +248,7 @@ public class Config extends ConfigSection {
|
||||
|
||||
/**
|
||||
* Default comment applied to config nodes
|
||||
*
|
||||
*
|
||||
* @return this config
|
||||
*/
|
||||
@NotNull
|
||||
@ -278,7 +267,7 @@ public class Config extends ConfigSection {
|
||||
|
||||
/**
|
||||
* Default comment applied to section nodes
|
||||
*
|
||||
*
|
||||
* @return this config
|
||||
*/
|
||||
@NotNull
|
||||
@ -296,7 +285,7 @@ public class Config extends ConfigSection {
|
||||
|
||||
/**
|
||||
* Extra lines to put between root nodes
|
||||
*
|
||||
*
|
||||
* @return this config
|
||||
*/
|
||||
@NotNull
|
||||
@ -316,7 +305,7 @@ public class Config extends ConfigSection {
|
||||
/**
|
||||
* Extra lines to put in front of comments. <br>
|
||||
* This is separate from rootNodeSpacing, if applicable.
|
||||
*
|
||||
*
|
||||
* @return this config
|
||||
*/
|
||||
@NotNull
|
||||
@ -400,7 +389,7 @@ public class Config extends ConfigSection {
|
||||
try (BufferedInputStream stream = new BufferedInputStream(new FileInputStream(file))) {
|
||||
Charset charset = TextUtils.detectCharset(stream, StandardCharsets.UTF_8);
|
||||
// upgrade charset if file was saved in a more complex format
|
||||
if(charset == StandardCharsets.UTF_16BE || charset == StandardCharsets.UTF_16LE) {
|
||||
if (charset == StandardCharsets.UTF_16BE || charset == StandardCharsets.UTF_16LE) {
|
||||
defaultCharset = StandardCharsets.UTF_16;
|
||||
}
|
||||
this.load(new InputStreamReader(stream, charset));
|
||||
@ -415,12 +404,12 @@ public class Config extends ConfigSection {
|
||||
|
||||
public void load(@NotNull Reader reader) throws IOException, InvalidConfigurationException {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
|
||||
try (BufferedReader input = reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader)) {
|
||||
String line;
|
||||
boolean firstLine = true;
|
||||
while ((line = input.readLine()) != null) {
|
||||
if(firstLine) {
|
||||
if (firstLine) {
|
||||
line = line.replaceAll("[\uFEFF\uFFFE\u200B]", ""); // clear BOM markers
|
||||
firstLine = false;
|
||||
}
|
||||
@ -440,7 +429,7 @@ public class Config extends ConfigSection {
|
||||
throw new InvalidConfigurationException("Top level is not a Map.");
|
||||
}
|
||||
if (input != null) {
|
||||
if(loadComments) {
|
||||
if (loadComments) {
|
||||
this.parseComments(contents, input);
|
||||
}
|
||||
this.convertMapsToSections(input, this);
|
||||
@ -530,8 +519,8 @@ public class Config extends ConfigSection {
|
||||
public void deleteNonDefaultSettings() {
|
||||
// Delete old config values (thread-safe)
|
||||
List<String> defaultKeys = Arrays.asList(defaults.keySet().toArray(new String[0]));
|
||||
for(String key : values.keySet().toArray(new String[0])) {
|
||||
if(!defaultKeys.contains(key)) {
|
||||
for (String key : values.keySet().toArray(new String[0])) {
|
||||
if (!defaultKeys.contains(key)) {
|
||||
values.remove(key);
|
||||
}
|
||||
}
|
||||
@ -557,7 +546,7 @@ public class Config extends ConfigSection {
|
||||
if (changed || hasNewDefaults()) {
|
||||
saved = save();
|
||||
}
|
||||
if(saveTask != null) {
|
||||
if (saveTask != null) {
|
||||
//Close Threads
|
||||
saveTask.cancel();
|
||||
autosaveTimer.cancel();
|
||||
@ -576,7 +565,7 @@ public class Config extends ConfigSection {
|
||||
}
|
||||
|
||||
public boolean save() {
|
||||
if(saveTask != null) {
|
||||
if (saveTask != null) {
|
||||
//Close Threads
|
||||
saveTask.cancel();
|
||||
autosaveTimer.cancel();
|
||||
|
@ -1,10 +1,6 @@
|
||||
package com.songoda.core.configuration;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
@ -12,6 +8,11 @@ import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ConfigFileConfigurationAdapter extends FileConfiguration {
|
||||
|
||||
final Config config;
|
||||
|
@ -42,9 +42,9 @@ public class ConfigFormattingRules {
|
||||
final char spaceCharTop, spaceCharBottom;
|
||||
|
||||
private CommentStyle(boolean drawBorder, boolean drawSpace,
|
||||
String spacePrefixTop, char spaceCharTop, String spaceSuffixTop,
|
||||
String commentPrefix, String commentSuffix,
|
||||
String spacePrefixBottom, char spaceCharBottom, String spaceSuffixBottom) {
|
||||
String spacePrefixTop, char spaceCharTop, String spaceSuffixTop,
|
||||
String commentPrefix, String commentSuffix,
|
||||
String spacePrefixBottom, char spaceCharBottom, String spaceSuffixBottom) {
|
||||
this.drawBorder = drawBorder;
|
||||
this.drawSpace = drawSpace;
|
||||
this.commentPrefix = commentPrefix;
|
||||
@ -68,23 +68,23 @@ public class ConfigFormattingRules {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static CommentStyle parseStyle(List<String> lines) {
|
||||
if(lines == null || lines.size() <= 2) {
|
||||
if (lines == null || lines.size() <= 2) {
|
||||
return CommentStyle.SIMPLE;
|
||||
} else if(lines.size() > 2 && lines.get(0).trim().equals("#") && lines.get(lines.size() - 1).trim().equals("#")) {
|
||||
} else if (lines.size() > 2 && lines.get(0).trim().equals("#") && lines.get(lines.size() - 1).trim().equals("#")) {
|
||||
return CommentStyle.SPACED;
|
||||
}
|
||||
boolean hasBorders = lines.size() > 2 && lines.get(0).trim().matches("^##+$") && lines.get(lines.size() - 1).trim().matches("^##+$");
|
||||
if(!hasBorders) {
|
||||
if (!hasBorders) {
|
||||
// default return
|
||||
return CommentStyle.SIMPLE;
|
||||
}
|
||||
// now need to figure out if this is blocked or not
|
||||
if(lines.size() > 4 && lines.get(1).trim().matches(("^#"
|
||||
if (lines.size() > 4 && lines.get(1).trim().matches(("^#"
|
||||
+ CommentStyle.BLOCKSPACED.spacePrefixTop + CommentStyle.BLOCKSPACED.spaceCharTop + "+"
|
||||
+ CommentStyle.BLOCKSPACED.spaceSuffixTop + "#$").replace("|", "\\|"))
|
||||
&& lines.get(1).trim().matches(("^#"
|
||||
&& lines.get(1).trim().matches(("^#"
|
||||
+ CommentStyle.BLOCKSPACED.spacePrefixTop + CommentStyle.BLOCKSPACED.spaceCharTop + "+"
|
||||
+ CommentStyle.BLOCKSPACED.spaceSuffixTop + "#$").replace("|", "\\|"))) {
|
||||
return CommentStyle.BLOCKSPACED;
|
||||
|
@ -1,10 +1,11 @@
|
||||
package com.songoda.core.configuration;
|
||||
|
||||
import java.util.List;
|
||||
import org.bukkit.configuration.file.FileConfigurationOptions;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ConfigOptionsAdapter extends FileConfigurationOptions {
|
||||
|
||||
final ConfigSection config;
|
||||
|
@ -1,6 +1,11 @@
|
||||
package com.songoda.core.configuration;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import org.bukkit.configuration.MemoryConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@ -12,16 +17,12 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import org.bukkit.configuration.MemoryConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Configuration for a specific node
|
||||
*
|
||||
* @since 2019-08-28
|
||||
* @author jascotty2
|
||||
* @since 2019-08-28
|
||||
*/
|
||||
public class ConfigSection extends MemoryConfiguration {
|
||||
|
||||
@ -80,7 +81,7 @@ public class ConfigSection extends MemoryConfiguration {
|
||||
/**
|
||||
* Sets the character used to separate configuration nodes. <br>
|
||||
* IMPORTANT: Do not change this after loading or adding ConfigurationSections!
|
||||
*
|
||||
*
|
||||
* @param pathChar character to use
|
||||
*/
|
||||
public void setPathSeparator(char pathChar) {
|
||||
@ -110,8 +111,8 @@ public class ConfigSection extends MemoryConfiguration {
|
||||
/**
|
||||
* Create the path required for this node to exist. <br />
|
||||
* <b>DO NOT USE THIS IN A SYNCHRONIZED LOCK</b>
|
||||
*
|
||||
* @param path full path of the node required. Eg, for foo.bar.node, this will create sections for foo and foo.bar
|
||||
*
|
||||
* @param path full path of the node required. Eg, for foo.bar.node, this will create sections for foo and foo.bar
|
||||
* @param useDefault set to true if this is a default value
|
||||
*/
|
||||
protected void createNodePath(@NotNull String path, boolean useDefault) {
|
||||
@ -143,7 +144,7 @@ public class ConfigSection extends MemoryConfiguration {
|
||||
}
|
||||
return section;
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public ConfigSection createDefaultSection(@NotNull String path, String... comment) {
|
||||
createNodePath(path, true);
|
||||
@ -154,7 +155,7 @@ public class ConfigSection extends MemoryConfiguration {
|
||||
}
|
||||
return section;
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public ConfigSection createDefaultSection(@NotNull String path, ConfigFormattingRules.CommentStyle commentStyle, String... comment) {
|
||||
createNodePath(path, true);
|
||||
@ -200,6 +201,7 @@ public class ConfigSection extends MemoryConfiguration {
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConfigSection setDefaultComment(@NotNull String path, ConfigFormattingRules.CommentStyle commentStyle, String... lines) {
|
||||
return setDefaultComment(path, commentStyle, lines.length == 0 ? (List) null : Arrays.asList(lines));
|
||||
@ -316,31 +318,39 @@ public class ConfigSection extends MemoryConfiguration {
|
||||
result.putAll((Map<String, Object>) root.defaults.entrySet().stream()
|
||||
.filter(k -> k.getKey().startsWith(fullPath))
|
||||
.collect(Collectors.toMap(
|
||||
e -> !e.getKey().endsWith(String.valueOf(root.pathChar)) ? e.getKey().substring(pathIndex + 1) : e.getKey().substring(pathIndex + 1, e.getKey().length() - 1),
|
||||
e -> !e.getKey().endsWith(String.valueOf(root.pathChar)) ? e.getKey().substring(pathIndex + 1) : e.getKey().substring(pathIndex + 1, e.getKey().length() - 1),
|
||||
e -> e.getValue(),
|
||||
(v1, v2) -> { throw new IllegalStateException(); }, // never going to be merging keys
|
||||
(v1, v2) -> {
|
||||
throw new IllegalStateException();
|
||||
}, // never going to be merging keys
|
||||
LinkedHashMap::new)));
|
||||
result.putAll((Map<String, Object>) root.values.entrySet().stream()
|
||||
.filter(k -> k.getKey().startsWith(fullPath))
|
||||
.collect(Collectors.toMap(
|
||||
e -> !e.getKey().endsWith(String.valueOf(root.pathChar)) ? e.getKey().substring(pathIndex + 1) : e.getKey().substring(pathIndex + 1, e.getKey().length() - 1),
|
||||
e -> !e.getKey().endsWith(String.valueOf(root.pathChar)) ? e.getKey().substring(pathIndex + 1) : e.getKey().substring(pathIndex + 1, e.getKey().length() - 1),
|
||||
e -> e.getValue(),
|
||||
(v1, v2) -> { throw new IllegalStateException(); }, // never going to be merging keys
|
||||
(v1, v2) -> {
|
||||
throw new IllegalStateException();
|
||||
}, // never going to be merging keys
|
||||
LinkedHashMap::new)));
|
||||
} else {
|
||||
result.putAll((Map<String, Object>) root.defaults.entrySet().stream()
|
||||
result.putAll((Map<String, Object>) root.defaults.entrySet().stream()
|
||||
.filter(k -> k.getKey().startsWith(fullPath) && k.getKey().lastIndexOf(root.pathChar) == pathIndex)
|
||||
.collect(Collectors.toMap(
|
||||
e -> !e.getKey().endsWith(String.valueOf(root.pathChar)) ? e.getKey().substring(pathIndex + 1) : e.getKey().substring(pathIndex + 1, e.getKey().length() - 1),
|
||||
e -> !e.getKey().endsWith(String.valueOf(root.pathChar)) ? e.getKey().substring(pathIndex + 1) : e.getKey().substring(pathIndex + 1, e.getKey().length() - 1),
|
||||
e -> e.getValue(),
|
||||
(v1, v2) -> { throw new IllegalStateException(); }, // never going to be merging keys
|
||||
(v1, v2) -> {
|
||||
throw new IllegalStateException();
|
||||
}, // never going to be merging keys
|
||||
LinkedHashMap::new)));
|
||||
result.putAll((Map<String, Object>) root.values.entrySet().stream()
|
||||
.filter(k -> k.getKey().startsWith(fullPath) && k.getKey().lastIndexOf(root.pathChar) == pathIndex)
|
||||
.collect(Collectors.toMap(
|
||||
e -> !e.getKey().endsWith(String.valueOf(root.pathChar)) ? e.getKey().substring(pathIndex + 1) : e.getKey().substring(pathIndex + 1, e.getKey().length() - 1),
|
||||
e -> !e.getKey().endsWith(String.valueOf(root.pathChar)) ? e.getKey().substring(pathIndex + 1) : e.getKey().substring(pathIndex + 1, e.getKey().length() - 1),
|
||||
e -> e.getValue(),
|
||||
(v1, v2) -> { throw new IllegalStateException(); }, // never going to be merging keys
|
||||
(v1, v2) -> {
|
||||
throw new IllegalStateException();
|
||||
}, // never going to be merging keys
|
||||
LinkedHashMap::new)));
|
||||
}
|
||||
return result;
|
||||
@ -442,7 +452,7 @@ public class ConfigSection extends MemoryConfiguration {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConfigSection set(@NotNull String path, @Nullable Object value, String ... comment) {
|
||||
public ConfigSection set(@NotNull String path, @Nullable Object value, String... comment) {
|
||||
set(path, value);
|
||||
return setComment(path, null, comment);
|
||||
}
|
||||
@ -454,7 +464,7 @@ public class ConfigSection extends MemoryConfiguration {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConfigSection set(@NotNull String path, @Nullable Object value, @Nullable ConfigFormattingRules.CommentStyle commentStyle, String ... comment) {
|
||||
public ConfigSection set(@NotNull String path, @Nullable Object value, @Nullable ConfigFormattingRules.CommentStyle commentStyle, String... comment) {
|
||||
set(path, value);
|
||||
return setComment(path, commentStyle, comment);
|
||||
}
|
||||
@ -472,7 +482,7 @@ public class ConfigSection extends MemoryConfiguration {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConfigSection setDefault(@NotNull String path, @Nullable Object value, String ... comment) {
|
||||
public ConfigSection setDefault(@NotNull String path, @Nullable Object value, String... comment) {
|
||||
addDefault(path, value);
|
||||
return setDefaultComment(path, comment);
|
||||
}
|
||||
@ -484,7 +494,7 @@ public class ConfigSection extends MemoryConfiguration {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConfigSection setDefault(@NotNull String path, @Nullable Object value, ConfigFormattingRules.CommentStyle commentStyle, String ... comment) {
|
||||
public ConfigSection setDefault(@NotNull String path, @Nullable Object value, ConfigFormattingRules.CommentStyle commentStyle, String... comment) {
|
||||
addDefault(path, value);
|
||||
return setDefaultComment(path, commentStyle, comment);
|
||||
}
|
||||
@ -500,7 +510,7 @@ public class ConfigSection extends MemoryConfiguration {
|
||||
public ConfigSection createSection(@NotNull String path) {
|
||||
createNodePath(path, false);
|
||||
ConfigSection section = new ConfigSection(root, this, path, false);
|
||||
synchronized(root.lock) {
|
||||
synchronized (root.lock) {
|
||||
root.values.put(fullPath + path, section);
|
||||
}
|
||||
root.changed = true;
|
||||
@ -619,7 +629,7 @@ public class ConfigSection extends MemoryConfiguration {
|
||||
@Override
|
||||
public long getLong(@NotNull String path) {
|
||||
Object result = get(path);
|
||||
return result instanceof Number ? ((Number) result).longValue(): 0;
|
||||
return result instanceof Number ? ((Number) result).longValue() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,10 +1,11 @@
|
||||
package com.songoda.core.configuration;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import java.util.List;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ConfigSetting {
|
||||
|
||||
final Config config;
|
||||
@ -15,13 +16,13 @@ public class ConfigSetting {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public ConfigSetting(@NotNull Config config, @NotNull String key, @NotNull Object defaultValue, String ... comment) {
|
||||
public ConfigSetting(@NotNull Config config, @NotNull String key, @NotNull Object defaultValue, String... comment) {
|
||||
this.config = config;
|
||||
this.key = key;
|
||||
config.setDefault(key, defaultValue, comment);
|
||||
}
|
||||
|
||||
public ConfigSetting(@NotNull Config config, @NotNull String key, @NotNull Object defaultValue, ConfigFormattingRules.CommentStyle commentStyle, String ... comment) {
|
||||
public ConfigSetting(@NotNull Config config, @NotNull String key, @NotNull Object defaultValue, ConfigFormattingRules.CommentStyle commentStyle, String... comment) {
|
||||
this.config = config;
|
||||
this.key = key;
|
||||
config.setDefault(key, defaultValue, commentStyle, comment);
|
||||
|
@ -1,5 +1,12 @@
|
||||
package com.songoda.core.configuration;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
@ -9,19 +16,13 @@ import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.function.Function;
|
||||
import java.util.logging.Level;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Used to easily store a set of one data value
|
||||
*
|
||||
* @param <T> DataObject class that is used to store the data
|
||||
* @since 2019-09-06
|
||||
* @author jascotty2
|
||||
* @since 2019-09-06
|
||||
*/
|
||||
public class SimpleDataStore<T extends DataStoreObject> {
|
||||
|
||||
|
@ -7,13 +7,6 @@ import com.songoda.core.gui.GuiUtils;
|
||||
import com.songoda.core.gui.SimplePagedGui;
|
||||
import com.songoda.core.input.ChatPrompt;
|
||||
import com.songoda.core.utils.ItemUtils;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.MemoryConfiguration;
|
||||
@ -24,11 +17,19 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Edit a configuration file for a specific plugin
|
||||
*
|
||||
* @since 2019-08-31
|
||||
* @author jascotty2
|
||||
* @since 2019-08-31
|
||||
*/
|
||||
public class ConfigEditorGui extends SimplePagedGui {
|
||||
|
||||
@ -72,7 +73,7 @@ public class ConfigEditorGui extends SimplePagedGui {
|
||||
this.setUseHeader(true);
|
||||
headerBackItem = footerBackItem = GuiUtils.getBorderItem(CompatibleMaterial.GRAY_STAINED_GLASS_PANE.getItem());
|
||||
final String path = node.getCurrentPath();
|
||||
this.setItem(4, configItem(CompatibleMaterial.FILLED_MAP, !path.isEmpty() ? path : file , config, !path.isEmpty() ? path : null, ChatColor.BLACK.toString()));
|
||||
this.setItem(4, configItem(CompatibleMaterial.FILLED_MAP, !path.isEmpty() ? path : file, config, !path.isEmpty() ? path : null, ChatColor.BLACK.toString()));
|
||||
this.setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.OAK_DOOR, "Exit"), (event) -> event.player.closeInventory());
|
||||
|
||||
// compile list of settings
|
||||
@ -94,7 +95,7 @@ public class ConfigEditorGui extends SimplePagedGui {
|
||||
// now display individual settings
|
||||
for (final String settingKey : settings) {
|
||||
final Object val = node.get(settingKey);
|
||||
if(val == null) continue;
|
||||
if (val == null) continue;
|
||||
else if (val instanceof Boolean) {
|
||||
// toggle switch
|
||||
setButton(index, configItem(CompatibleMaterial.LEVER, ChatColor.YELLOW + settingKey, node, settingKey, String.valueOf((Boolean) val), "Click to toggle this setting"),
|
||||
@ -112,7 +113,10 @@ public class ConfigEditorGui extends SimplePagedGui {
|
||||
event.player.sendMessage(ChatColor.RED + "Error: \"" + response.getMessage().trim() + "\" is not a number!");
|
||||
}
|
||||
}).setOnClose(() -> event.manager.showGUI(event.player, this))
|
||||
.setOnCancel(() -> {event.player.sendMessage(ChatColor.RED + "Edit canceled"); event.manager.showGUI(event.player, this);});
|
||||
.setOnCancel(() -> {
|
||||
event.player.sendMessage(ChatColor.RED + "Edit canceled");
|
||||
event.manager.showGUI(event.player, this);
|
||||
});
|
||||
});
|
||||
} else if (isMaterial(val)) {
|
||||
// changing a block
|
||||
@ -124,7 +128,7 @@ public class ConfigEditorGui extends SimplePagedGui {
|
||||
paged.setHeaderBackItem(headerBackItem).setFooterBackItem(footerBackItem).setDefaultItem(blankItem);
|
||||
paged.setItem(4, configItem(CompatibleMaterial.FILLED_MAP, settingKey, node, settingKey, "Choose an item to change this value to"));
|
||||
int i = 9;
|
||||
for(CompatibleMaterial mat : CompatibleMaterial.getAllValidItemMaterials()) {
|
||||
for (CompatibleMaterial mat : CompatibleMaterial.getAllValidItemMaterials()) {
|
||||
paged.setButton(i++, GuiUtils.createButtonItem(mat, mat.name()), ClickType.LEFT, (matEvent) -> {
|
||||
setMaterial(event.slot, settingKey, matEvent.clickedItem);
|
||||
matEvent.player.closeInventory();
|
||||
@ -132,7 +136,7 @@ public class ConfigEditorGui extends SimplePagedGui {
|
||||
}
|
||||
event.manager.showGUI(event.player, paged);
|
||||
});
|
||||
|
||||
|
||||
} else if (val instanceof String) {
|
||||
// changing a "string" value (or change to a feather for writing quill)
|
||||
setButton(index, configItem(CompatibleMaterial.STRING, ChatColor.YELLOW + settingKey, node, settingKey, val.toString(), "Click to edit this setting"),
|
||||
@ -142,13 +146,16 @@ public class ConfigEditorGui extends SimplePagedGui {
|
||||
node.set(settingKey, response.getMessage().trim());
|
||||
updateValue(event.slot, settingKey);
|
||||
}).setOnClose(() -> event.manager.showGUI(event.player, this))
|
||||
.setOnCancel(() -> {event.player.sendMessage(ChatColor.RED + "Edit canceled"); event.manager.showGUI(event.player, this);});
|
||||
.setOnCancel(() -> {
|
||||
event.player.sendMessage(ChatColor.RED + "Edit canceled");
|
||||
event.manager.showGUI(event.player, this);
|
||||
});
|
||||
});
|
||||
} else if (val instanceof List) {
|
||||
setButton(index, configItem(CompatibleMaterial.WRITABLE_BOOK, ChatColor.YELLOW + settingKey, node, settingKey, String.format("(%d values)", ((List) val).size()), "Click to edit this setting"),
|
||||
(event) -> {
|
||||
event.manager.showGUI(event.player, (new ConfigEditorListEditorGui(this, settingKey, (List) val)).setOnClose((gui) -> {
|
||||
if(((ConfigEditorListEditorGui) gui.gui).saveChanges) {
|
||||
if (((ConfigEditorListEditorGui) gui.gui).saveChanges) {
|
||||
setList(event.slot, settingKey, ((ConfigEditorListEditorGui) gui.gui).values);
|
||||
}
|
||||
}));
|
||||
@ -168,7 +175,7 @@ public class ConfigEditorGui extends SimplePagedGui {
|
||||
|
||||
protected void updateValue(int clickCell, String path) {
|
||||
ItemStack item = inventory.getItem(clickCell);
|
||||
if(item == null || item == AIR) return;
|
||||
if (item == null || item == AIR) return;
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
Object val = node.get(path);
|
||||
if (meta != null && val != null) {
|
||||
@ -194,7 +201,7 @@ public class ConfigEditorGui extends SimplePagedGui {
|
||||
void toggle(int clickCell, String path) {
|
||||
boolean val = !node.getBoolean(path);
|
||||
node.set(path, val);
|
||||
if(val) {
|
||||
if (val) {
|
||||
setItem(clickCell, ItemUtils.addGlow(inventory.getItem(clickCell)));
|
||||
} else {
|
||||
setItem(clickCell, ItemUtils.removeGlow(inventory.getItem(clickCell)));
|
||||
@ -259,9 +266,9 @@ public class ConfigEditorGui extends SimplePagedGui {
|
||||
private boolean isNumber(Object value) {
|
||||
return value != null && (
|
||||
value instanceof Long
|
||||
|| value instanceof Integer
|
||||
|| value instanceof Float
|
||||
|| value instanceof Double);
|
||||
|| value instanceof Integer
|
||||
|| value instanceof Float
|
||||
|| value instanceof Double);
|
||||
}
|
||||
|
||||
private boolean isMaterial(Object value) {
|
||||
@ -285,7 +292,7 @@ public class ConfigEditorGui extends SimplePagedGui {
|
||||
}
|
||||
|
||||
protected ItemStack configItem(CompatibleMaterial type, String name, ConfigurationSection node, String path, String value, String def) {
|
||||
if(value == null) value = "";
|
||||
if (value == null) value = "";
|
||||
String[] info = null;
|
||||
if (configSection_getCommentString != null) {
|
||||
try {
|
||||
|
@ -4,16 +4,17 @@ import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.gui.GuiUtils;
|
||||
import com.songoda.core.gui.SimplePagedGui;
|
||||
import com.songoda.core.input.ChatPrompt;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Edit a string list
|
||||
*
|
||||
* @since 2019-08-31
|
||||
* @author jascotty2
|
||||
* @since 2019-08-31
|
||||
*/
|
||||
public class ConfigEditorListEditorGui extends SimplePagedGui {
|
||||
|
||||
@ -38,14 +39,19 @@ public class ConfigEditorListEditorGui extends SimplePagedGui {
|
||||
saveChanges = true;
|
||||
event.player.closeInventory();
|
||||
});
|
||||
this.setButton(1, GuiUtils.createButtonItem(CompatibleMaterial.CHEST, ChatColor.BLUE + "Add Item"),
|
||||
this.setButton(1, GuiUtils.createButtonItem(CompatibleMaterial.CHEST, ChatColor.BLUE + "Add Item"),
|
||||
(event) -> {
|
||||
event.gui.exit();
|
||||
ChatPrompt.showPrompt(event.manager.getPlugin(), event.player, "Enter a new value to add:", response -> {
|
||||
values.add(response.getMessage().trim());
|
||||
redraw();
|
||||
}).setOnClose(() -> {event.manager.showGUI(event.player, this); })
|
||||
.setOnCancel(() -> {event.player.sendMessage(ChatColor.RED + "Edit canceled"); event.manager.showGUI(event.player, this);});
|
||||
}).setOnClose(() -> {
|
||||
event.manager.showGUI(event.player, this);
|
||||
})
|
||||
.setOnCancel(() -> {
|
||||
event.player.sendMessage(ChatColor.RED + "Edit canceled");
|
||||
event.manager.showGUI(event.player, this);
|
||||
});
|
||||
});
|
||||
|
||||
redraw();
|
||||
@ -54,9 +60,9 @@ public class ConfigEditorListEditorGui extends SimplePagedGui {
|
||||
void redraw() {
|
||||
page = 1;
|
||||
// clear old display
|
||||
if(inventory != null) {
|
||||
for(Integer i : cellItems.keySet().toArray(new Integer[0])) {
|
||||
if(i > 8) {
|
||||
if (inventory != null) {
|
||||
for (Integer i : cellItems.keySet().toArray(new Integer[0])) {
|
||||
if (i > 8) {
|
||||
cellItems.remove(i);
|
||||
conditionalButtons.remove(i);
|
||||
}
|
||||
|
@ -6,21 +6,22 @@ import com.songoda.core.configuration.Config;
|
||||
import com.songoda.core.gui.Gui;
|
||||
import com.songoda.core.gui.GuiUtils;
|
||||
import com.songoda.core.gui.SimplePagedGui;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.MemoryConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.MemoryConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
/**
|
||||
* Edit all configuration files for a specific plugin
|
||||
*
|
||||
* @since 2019-08-31
|
||||
* @author jascotty2
|
||||
* @since 2019-08-31
|
||||
*/
|
||||
public class PluginConfigGui extends SimplePagedGui {
|
||||
|
||||
|
@ -1,20 +1,21 @@
|
||||
package com.songoda.core.core;
|
||||
|
||||
import com.songoda.core.locale.Locale;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class LocaleModule implements PluginInfoModule {
|
||||
|
||||
@Override
|
||||
public void run(PluginInfo plugin) {
|
||||
if(plugin.getJavaPlugin() == null || plugin.getSongodaId() <= 0) return;
|
||||
if (plugin.getJavaPlugin() == null || plugin.getSongodaId() <= 0) return;
|
||||
JSONObject json = plugin.getJson();
|
||||
try {
|
||||
JSONArray files = (JSONArray) json.get("neededFiles");
|
||||
|
@ -3,10 +3,11 @@ package com.songoda.core.core;
|
||||
import com.songoda.core.SongodaCore;
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.core.gui.GuiManager;
|
||||
import java.util.List;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SongodaCoreCommand extends AbstractCommand {
|
||||
|
||||
protected GuiManager guiManager;
|
||||
@ -17,8 +18,8 @@ public class SongodaCoreCommand extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if(sender instanceof Player) {
|
||||
if(guiManager == null || guiManager.isClosed()) {
|
||||
if (sender instanceof Player) {
|
||||
if (guiManager == null || guiManager.isClosed()) {
|
||||
guiManager = new GuiManager(SongodaCore.getHijackedPlugin());
|
||||
}
|
||||
guiManager.showGUI((Player) sender, new SongodaCoreOverviewGUI());
|
||||
@ -27,7 +28,7 @@ public class SongodaCoreCommand extends AbstractCommand {
|
||||
}
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "songoda.admin";
|
||||
|
@ -48,8 +48,8 @@ public class SongodaCoreDiagCommand extends AbstractCommand {
|
||||
sender.sendMessage("NMS: " + ServerProject.getServerVersion() + " " + ServerVersion.getServerVersionString());
|
||||
sender.sendMessage("Operating System: " + System.getProperty("os.name"));
|
||||
sender.sendMessage("Allocated Memory: " + format.format(Runtime.getRuntime().maxMemory() / (1024 * 1024)) + "Mb");
|
||||
sender.sendMessage("Online Players: " + Bukkit.getOnlinePlayers().size());
|
||||
if(tpsField != null) {
|
||||
sender.sendMessage("Online Players: " + Bukkit.getOnlinePlayers().size());
|
||||
if (tpsField != null) {
|
||||
try {
|
||||
double[] tps = ((double[]) tpsField.get(serverInstance));
|
||||
|
||||
|
@ -5,10 +5,11 @@ import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.configuration.editor.PluginConfigGui;
|
||||
import com.songoda.core.gui.Gui;
|
||||
import com.songoda.core.gui.GuiUtils;
|
||||
import java.util.List;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
final class SongodaCoreOverviewGUI extends Gui {
|
||||
|
||||
protected SongodaCoreOverviewGUI() {
|
||||
@ -33,7 +34,7 @@ final class SongodaCoreOverviewGUI extends Gui {
|
||||
"",
|
||||
ChatColor.GOLD + "Click for the marketplace page link.",
|
||||
ChatColor.GOLD + "Right Click to edit plugin settings."
|
||||
),
|
||||
),
|
||||
ClickType.LEFT, (event) -> event.player.sendMessage(plugin.getMarketplaceLink()));
|
||||
setAction(i, ClickType.RIGHT, (event) -> event.manager.showGUI(event.player, new PluginConfigGui(plugin.getJavaPlugin(), event.gui)));
|
||||
highlightItem(i);
|
||||
@ -44,7 +45,7 @@ final class SongodaCoreOverviewGUI extends Gui {
|
||||
"",
|
||||
ChatColor.GOLD + "Click for the marketplace page link.",
|
||||
ChatColor.GOLD + "Right Click to edit plugin settings."
|
||||
),
|
||||
),
|
||||
ClickType.LEFT, (event) -> event.player.sendMessage(plugin.getMarketplaceLink()));
|
||||
setAction(i, ClickType.RIGHT, (event) -> event.manager.showGUI(event.player, new PluginConfigGui(plugin.getJavaPlugin(), event.gui)));
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ public class MySQLConnector implements DatabaseConnector {
|
||||
this.plugin = plugin;
|
||||
|
||||
System.out.println("connecting to " + hostname + " : " + port);
|
||||
|
||||
|
||||
HikariConfig config = new HikariConfig();
|
||||
config.setJdbcUrl("jdbc:mysql://" + hostname + ":" + port + "/" + database + "?useSSL=" + useSSL);
|
||||
config.setUsername(username);
|
||||
|
@ -2,11 +2,9 @@ package com.songoda.core.gui;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.gui.methods.Clickable;
|
||||
import com.songoda.core.nms.NmsManager;
|
||||
import com.songoda.core.nms.anvil.AnvilCore;
|
||||
import com.songoda.core.nms.anvil.CustomAnvil;
|
||||
import com.songoda.core.nms.NmsManager;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
@ -14,11 +12,14 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Anvil GUI for text prompts
|
||||
*
|
||||
* @since 2019-09-15
|
||||
* @author jascotty2
|
||||
* @since 2019-09-15
|
||||
*/
|
||||
public class AnvilGui extends Gui {
|
||||
|
||||
@ -66,7 +67,7 @@ public class AnvilGui extends Gui {
|
||||
return this;
|
||||
}
|
||||
|
||||
public AnvilGui setOutputPrompt(String ... str) {
|
||||
public AnvilGui setOutputPrompt(String... str) {
|
||||
endPrompt = Arrays.asList(str);
|
||||
return this;
|
||||
}
|
||||
@ -78,7 +79,7 @@ public class AnvilGui extends Gui {
|
||||
|
||||
void updateOutputPrompt() {
|
||||
final ItemStack in;
|
||||
if(endPrompt != null && (in = cellItems.get(0)) != null) {
|
||||
if (endPrompt != null && (in = cellItems.get(0)) != null) {
|
||||
setItem(2, GuiUtils.createButtonItem(in, endPrompt));
|
||||
}
|
||||
}
|
||||
|
@ -10,5 +10,5 @@ public enum BackgroundType {
|
||||
private BackgroundType() {
|
||||
this.key = "minecraft:textures/gui/advancements/backgrounds/" + name().toLowerCase() + ".png";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -4,8 +4,6 @@ import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.configuration.DataStoreObject;
|
||||
import com.songoda.core.configuration.SimpleDataStore;
|
||||
import com.songoda.core.gui.methods.Clickable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -13,11 +11,14 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Represents a GUI screen that can be user-configured
|
||||
*
|
||||
* @since 2019-09-06
|
||||
* @author jascotty2
|
||||
* @since 2019-09-06
|
||||
*/
|
||||
public class CustomizableGui extends Gui {
|
||||
|
||||
|
@ -3,7 +3,11 @@ package com.songoda.core.gui;
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.gui.events.GuiClickEvent;
|
||||
import com.songoda.core.gui.events.GuiDropItemEvent;
|
||||
import com.songoda.core.gui.methods.*;
|
||||
import com.songoda.core.gui.methods.Clickable;
|
||||
import com.songoda.core.gui.methods.Closable;
|
||||
import com.songoda.core.gui.methods.Droppable;
|
||||
import com.songoda.core.gui.methods.Openable;
|
||||
import com.songoda.core.gui.methods.Pagable;
|
||||
import com.songoda.core.utils.ItemUtils;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -8,20 +8,13 @@ import com.songoda.core.gui.events.GuiCloseEvent;
|
||||
import com.songoda.core.gui.events.GuiDropItemEvent;
|
||||
import com.songoda.core.gui.events.GuiOpenEvent;
|
||||
import com.songoda.core.gui.events.GuiPageEvent;
|
||||
import com.songoda.core.gui.methods.Pagable;
|
||||
import com.songoda.core.gui.methods.Clickable;
|
||||
import com.songoda.core.gui.methods.Droppable;
|
||||
import com.songoda.core.gui.methods.Closable;
|
||||
import com.songoda.core.gui.methods.Droppable;
|
||||
import com.songoda.core.gui.methods.Openable;
|
||||
import com.songoda.core.gui.methods.Pagable;
|
||||
import com.songoda.core.utils.ItemUtils;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Hopper;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
@ -31,11 +24,17 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* TODO: animated buttons
|
||||
*
|
||||
* @since 2019-08-25
|
||||
* @author jascotty2
|
||||
* @since 2019-08-25
|
||||
*/
|
||||
public class Gui {
|
||||
|
||||
@ -158,18 +157,18 @@ public class Gui {
|
||||
.collect(Collectors.toList())
|
||||
.forEach(Player::closeInventory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the GUI as if the player closed it normally
|
||||
*/
|
||||
public void close() {
|
||||
|
||||
/**
|
||||
* Close the GUI as if the player closed it normally
|
||||
*/
|
||||
public void close() {
|
||||
allowClose = true;
|
||||
inventory.getViewers().stream()
|
||||
.filter(e -> e instanceof Player)
|
||||
.map(e -> (Player) e)
|
||||
.collect(Collectors.toList())
|
||||
.forEach(Player::closeInventory);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public GuiType getType() {
|
||||
@ -682,7 +681,7 @@ public class Gui {
|
||||
public void setPage(int page) {
|
||||
int lastPage = this.page;
|
||||
this.page = Math.max(1, Math.min(pages, page));
|
||||
if(pager != null && this.page != lastPage) {
|
||||
if (pager != null && this.page != lastPage) {
|
||||
pager.onPageChange(new GuiPageEvent(this, guiManager, lastPage, page));
|
||||
// page markers
|
||||
updatePageNavigation();
|
||||
@ -692,7 +691,7 @@ public class Gui {
|
||||
public void changePage(int direction) {
|
||||
int lastPage = page;
|
||||
this.page = Math.max(1, Math.min(pages, page + direction));
|
||||
if(pager != null && this.page != lastPage) {
|
||||
if (pager != null && this.page != lastPage) {
|
||||
pager.onPageChange(new GuiPageEvent(this, guiManager, lastPage, page));
|
||||
// page markers
|
||||
updatePageNavigation();
|
||||
@ -735,7 +734,7 @@ public class Gui {
|
||||
}
|
||||
|
||||
protected void updatePageNavigation() {
|
||||
if(prevPage != null) {
|
||||
if (prevPage != null) {
|
||||
if (page > 1) {
|
||||
this.setButton(prevPageIndex, prevPage, ClickType.LEFT, (event) -> this.prevPage());
|
||||
} else {
|
||||
@ -743,7 +742,7 @@ public class Gui {
|
||||
this.clearActions(prevPageIndex);
|
||||
}
|
||||
}
|
||||
if(nextPage != null) {
|
||||
if (nextPage != null) {
|
||||
if (pages > 1 && page != pages) {
|
||||
this.setButton(nextPageIndex, nextPage, ClickType.LEFT, (event) -> this.nextPage());
|
||||
} else {
|
||||
@ -804,7 +803,7 @@ public class Gui {
|
||||
}
|
||||
|
||||
protected static String trimTitle(String title) {
|
||||
if(title == null) {
|
||||
if (title == null) {
|
||||
return "";
|
||||
} else if (ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_8) && title.length() > 32) {
|
||||
return title.charAt(30) == '\u00A7' ? title.substring(0, 30) : title.substring(0, 31);
|
||||
|
@ -7,9 +7,9 @@ import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
/**
|
||||
* Internal class for marking an inventory as a GUI inventory
|
||||
*
|
||||
* @since 2019-08-25
|
||||
*
|
||||
* @author jascotty2
|
||||
* @since 2019-08-25
|
||||
*/
|
||||
class GuiHolder implements InventoryHolder {
|
||||
|
||||
|
@ -1,13 +1,8 @@
|
||||
package com.songoda.core.gui;
|
||||
|
||||
import com.songoda.core.compatibility.ClientVersion;
|
||||
import com.songoda.core.compatibility.CompatibleSound;
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -26,11 +21,16 @@ import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Manages events for GUI screens
|
||||
*
|
||||
* @since 2019-08-25
|
||||
* @author jascotty2
|
||||
* @since 2019-08-25
|
||||
*/
|
||||
public class GuiManager {
|
||||
|
||||
@ -72,15 +72,15 @@ public class GuiManager {
|
||||
* Create and display a GUI interface for a player
|
||||
*
|
||||
* @param player player to open the interface for
|
||||
* @param gui GUI to use
|
||||
* @param gui GUI to use
|
||||
*/
|
||||
public void showGUI(Player player, Gui gui) {
|
||||
if (shutdown) {
|
||||
if(plugin.isEnabled()) {
|
||||
if (plugin.isEnabled()) {
|
||||
// recover if reloaded without calling init manually
|
||||
init();
|
||||
} else {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
} else if (!initialized) {
|
||||
init();
|
||||
@ -107,7 +107,7 @@ public class GuiManager {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
player.openInventory(inv);
|
||||
gui.onOpen(this, player);
|
||||
synchronized(lock) {
|
||||
synchronized (lock) {
|
||||
openInventories.put(player, gui);
|
||||
}
|
||||
});
|
||||
@ -143,7 +143,7 @@ public class GuiManager {
|
||||
* Close all active GUIs
|
||||
*/
|
||||
public void closeAll() {
|
||||
synchronized(lock) {
|
||||
synchronized (lock) {
|
||||
openInventories.entrySet().stream()
|
||||
.filter(e -> e.getKey().getOpenInventory().getTopInventory().getHolder() instanceof GuiHolder)
|
||||
.collect(Collectors.toList()) // to prevent concurrency exceptions
|
||||
@ -169,10 +169,10 @@ public class GuiManager {
|
||||
Inventory openInv = event.getInventory();
|
||||
Gui gui;
|
||||
if (openInv.getHolder() != null && openInv.getHolder() instanceof GuiHolder
|
||||
&& ((GuiHolder) openInv.getHolder()).manager.uuid.equals(manager.uuid)) {
|
||||
&& ((GuiHolder) openInv.getHolder()).manager.uuid.equals(manager.uuid)) {
|
||||
gui = ((GuiHolder) openInv.getHolder()).getGUI();
|
||||
|
||||
if(event.getRawSlots().stream().filter(slot -> gui.inventory.getSize() > slot).anyMatch(slot -> !gui.unlockedCells.getOrDefault(slot, false))){
|
||||
if (event.getRawSlots().stream().filter(slot -> gui.inventory.getSize() > slot).anyMatch(slot -> !gui.unlockedCells.getOrDefault(slot, false))) {
|
||||
event.setCancelled(true);
|
||||
event.setResult(Result.DENY);
|
||||
}
|
||||
@ -196,12 +196,12 @@ public class GuiManager {
|
||||
if (event.getClick() == ClickType.DOUBLE_CLICK) {
|
||||
// always cancel this event if there are matching gui elements, since it tends to do bad things
|
||||
ItemStack clicked = event.getCursor();
|
||||
if(clicked != null && clicked.getType() != Material.AIR) {
|
||||
if (clicked != null && clicked.getType() != Material.AIR) {
|
||||
int cell = 0;
|
||||
for(ItemStack it : gui.inventory.getContents()) {
|
||||
if(!gui.unlockedCells.getOrDefault(cell++, false) && clicked.isSimilar(it)) {
|
||||
for (ItemStack it : gui.inventory.getContents()) {
|
||||
if (!gui.unlockedCells.getOrDefault(cell++, false) && clicked.isSimilar(it)) {
|
||||
event.setCancelled(true);
|
||||
if(gui instanceof AnvilGui) {
|
||||
if (gui instanceof AnvilGui) {
|
||||
((AnvilGui) gui).anvil.update();
|
||||
}
|
||||
break;
|
||||
@ -228,7 +228,7 @@ public class GuiManager {
|
||||
player.playSound(player.getLocation(), gui.getDefaultSound().getSound(), 1F, 1F);
|
||||
} else if (!gui.acceptsItems || event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
|
||||
event.setCancelled(true);
|
||||
if(gui instanceof AnvilGui) {
|
||||
if (gui instanceof AnvilGui) {
|
||||
((AnvilGui) gui).anvil.update();
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,18 @@
|
||||
package com.songoda.core.gui;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @since 2019-08-25
|
||||
* @author jascotty2
|
||||
* @since 2019-08-25
|
||||
*/
|
||||
public class GuiUtils {
|
||||
|
||||
|
@ -6,8 +6,6 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -17,6 +15,9 @@ import org.bukkit.advancement.AdvancementProgress;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Instance of a popup message that can be sent to a player <br>
|
||||
* Popup toast messages only work on Minecraft 1.12+ <br>
|
||||
@ -83,22 +84,22 @@ class PopupMessage {
|
||||
return gson.toJson(json);
|
||||
}
|
||||
|
||||
protected void grant(final Player pl) {
|
||||
final Advancement adv = getAdvancement();
|
||||
final AdvancementProgress progress = pl.getAdvancementProgress(adv);
|
||||
protected void grant(final Player pl) {
|
||||
final Advancement adv = getAdvancement();
|
||||
final AdvancementProgress progress = pl.getAdvancementProgress(adv);
|
||||
|
||||
if (!progress.isDone())
|
||||
progress.getRemainingCriteria().forEach((crit) -> progress.awardCriteria(crit));
|
||||
}
|
||||
if (!progress.isDone())
|
||||
progress.getRemainingCriteria().forEach((crit) -> progress.awardCriteria(crit));
|
||||
}
|
||||
|
||||
protected void revoke(final Player pl) {
|
||||
final Advancement adv = getAdvancement();
|
||||
final AdvancementProgress prog = pl.getAdvancementProgress(adv);
|
||||
protected void revoke(final Player pl) {
|
||||
final Advancement adv = getAdvancement();
|
||||
final AdvancementProgress prog = pl.getAdvancementProgress(adv);
|
||||
|
||||
if (prog.isDone())
|
||||
prog.getAwardedCriteria().forEach((crit) -> prog.revokeCriteria(crit));
|
||||
}
|
||||
|
||||
if (prog.isDone())
|
||||
prog.getAwardedCriteria().forEach((crit) -> prog.revokeCriteria(crit));
|
||||
}
|
||||
|
||||
protected void add() {
|
||||
if (!registeredMessages.contains(id)) {
|
||||
registeredMessages.add(id);
|
||||
|
@ -1,11 +1,8 @@
|
||||
package com.songoda.core.gui;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import static com.songoda.core.gui.Gui.trimTitle;
|
||||
import com.songoda.core.gui.events.GuiClickEvent;
|
||||
import com.songoda.core.gui.methods.Clickable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
@ -13,11 +10,14 @@ import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Paged GUI for when you aren't going to be making too many pages
|
||||
*
|
||||
* @since 2019-08-31
|
||||
* @author jascotty2
|
||||
* @since 2019-08-31
|
||||
*/
|
||||
public class SimplePagedGui extends Gui {
|
||||
|
||||
@ -190,7 +190,7 @@ public class SimplePagedGui extends Gui {
|
||||
showPage();
|
||||
|
||||
// did we need to change the display window size?
|
||||
if(toUpdate != null) {
|
||||
if (toUpdate != null) {
|
||||
// whoopsie!
|
||||
exit();
|
||||
toUpdate.forEach(player -> guiManager.showGUI(player, this));
|
||||
|
@ -25,5 +25,5 @@ public class GuiClickEvent extends GuiEvent {
|
||||
this.clickType = event.getClick();
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -18,5 +18,5 @@ public class GuiDropItemEvent extends GuiEvent {
|
||||
this.clickType = event.getClick();
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,6 @@ package com.songoda.core.gui.methods;
|
||||
import com.songoda.core.gui.events.GuiOpenEvent;
|
||||
|
||||
public interface Openable {
|
||||
|
||||
|
||||
void onOpen(GuiOpenEvent event);
|
||||
}
|
||||
|
@ -54,6 +54,7 @@ public class EconomyManager {
|
||||
|
||||
/**
|
||||
* Format the given amount to a human-readable string in this currency
|
||||
*
|
||||
* @param amt amount to display
|
||||
* @return a currency string as formatted by the economy plugin
|
||||
*/
|
||||
|
@ -2,9 +2,10 @@ package com.songoda.core.hooks;
|
||||
|
||||
import com.songoda.core.hooks.holograms.Holograms;
|
||||
import org.bukkit.Location;
|
||||
import java.util.List;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A convenience class for static access to a Holograms HookManager
|
||||
*/
|
||||
@ -14,9 +15,9 @@ public class HologramManager {
|
||||
|
||||
/**
|
||||
* Load all supported economy plugins.<br/>
|
||||
* Note: This method should be called in your plugin's onEnable() section
|
||||
*
|
||||
* @param plugin plugin that will be using the holograms
|
||||
* Note: This method should be called in your plugin's onEnable() section
|
||||
*
|
||||
* @param plugin plugin that will be using the holograms
|
||||
*/
|
||||
public static void load(Plugin plugin) {
|
||||
manager.load(plugin);
|
||||
|
@ -1,12 +1,13 @@
|
||||
package com.songoda.core.hooks;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class HookManager<T extends Hook> {
|
||||
|
||||
@ -28,7 +29,8 @@ public class HookManager<T extends Hook> {
|
||||
|
||||
/**
|
||||
* Load all supported plugins.
|
||||
* @param hookingPlugin plugin to pass to the hook handler
|
||||
*
|
||||
* @param hookingPlugin plugin to pass to the hook handler
|
||||
*/
|
||||
public void load(Plugin hookingPlugin) {
|
||||
if (!loaded) {
|
||||
@ -53,8 +55,8 @@ public class HookManager<T extends Hook> {
|
||||
|
||||
/**
|
||||
* Set the default hook to a different plugin, if that plugin exists. <br>
|
||||
* If the plugin is not loaded or supported,
|
||||
* the previously defined default will be used.
|
||||
* If the plugin is not loaded or supported,
|
||||
* the previously defined default will be used.
|
||||
*
|
||||
* @param name name of the plugin to use
|
||||
* @return true if the default was set to this plugin
|
||||
@ -70,7 +72,7 @@ public class HookManager<T extends Hook> {
|
||||
|
||||
/**
|
||||
* Set the default hook to a different plugin, if that plugin exists. <br />
|
||||
* If the plugin is not loaded or supported,
|
||||
* If the plugin is not loaded or supported,
|
||||
* the previously defined default will be used.
|
||||
*
|
||||
* @param plugin plugin to use
|
||||
|
@ -2,14 +2,15 @@ package com.songoda.core.hooks;
|
||||
|
||||
import com.songoda.core.hooks.jobs.JobsHandler;
|
||||
import com.songoda.core.hooks.jobs.JobsPlayerHandler;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class JobsHook {
|
||||
|
||||
static boolean canHook;
|
||||
|
@ -1,11 +1,12 @@
|
||||
package com.songoda.core.hooks;
|
||||
|
||||
import com.songoda.core.hooks.mcmmo.McMMOHandler;
|
||||
import java.util.Collection;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class McMMOHook {
|
||||
|
||||
static boolean canHook = false;
|
||||
|
@ -2,20 +2,21 @@ package com.songoda.core.hooks;
|
||||
|
||||
import com.songoda.core.hooks.worldguard.WorldGuardFlagHandler;
|
||||
import com.songoda.core.hooks.worldguard.WorldGuardRegionHandler;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class WorldGuardHook {
|
||||
|
||||
static boolean canHook = false;
|
||||
|
||||
static {
|
||||
try {
|
||||
try {
|
||||
// if this class exists, we're good to use WG classes
|
||||
Class.forName("com.sk89q.worldguard.protection.flags.Flag");
|
||||
canHook = true;
|
||||
@ -26,12 +27,12 @@ public class WorldGuardHook {
|
||||
/**
|
||||
* Attempt to register a worldGuard flag (ALLOW/DENY) <br />
|
||||
* Note: This must be called before WorldGuard loads, or it will fail.
|
||||
*
|
||||
* @param flag name of the flag to set
|
||||
*
|
||||
* @param flag name of the flag to set
|
||||
* @param state default value of the flag
|
||||
*/
|
||||
public static void addHook(@NotNull String flag, boolean state) {
|
||||
if(canHook) {
|
||||
if (canHook) {
|
||||
WorldGuardFlagHandler.addHook(flag, state);
|
||||
}
|
||||
}
|
||||
@ -49,7 +50,7 @@ public class WorldGuardHook {
|
||||
/**
|
||||
* Checks this location to see what this flag is set to
|
||||
*
|
||||
* @param l location to check
|
||||
* @param l location to check
|
||||
* @param flag ALLOW/DENY flag to check
|
||||
* @return flag state, or null if undefined
|
||||
*/
|
||||
@ -61,7 +62,7 @@ public class WorldGuardHook {
|
||||
/**
|
||||
* Query all regions that are in or intersect this chunk
|
||||
*
|
||||
* @param c chunk to check for regions in
|
||||
* @param c chunk to check for regions in
|
||||
* @param flag ALLOW/DENY flag to check
|
||||
* @return flag state, or null if undefined
|
||||
*/
|
||||
@ -72,7 +73,7 @@ public class WorldGuardHook {
|
||||
|
||||
/**
|
||||
* Check to see if the pvp flag is set and is set to ALLOW
|
||||
*
|
||||
*
|
||||
* @param loc Location to check
|
||||
* @return false if the pvp flag is not set for this region, or is set to DENY
|
||||
*/
|
||||
@ -102,7 +103,7 @@ public class WorldGuardHook {
|
||||
|
||||
/**
|
||||
* Check to see if the other-explosion flag is set and is set to ALLOW
|
||||
*
|
||||
*
|
||||
* @param loc Location to check
|
||||
* @return false if the other-explosion flag is not set for this region, or is set to DENY
|
||||
*/
|
||||
@ -112,7 +113,7 @@ public class WorldGuardHook {
|
||||
|
||||
/**
|
||||
* Check to see if the mob-spawning flag is set and is set to ALLOW
|
||||
*
|
||||
*
|
||||
* @param loc Location to check
|
||||
* @return false if the mob-spawning flag is not set for this region, or is set to DENY
|
||||
*/
|
||||
|
@ -1,9 +1,10 @@
|
||||
package com.songoda.core.hooks.economies;
|
||||
|
||||
import com.songoda.core.hooks.Hook;
|
||||
import java.text.DecimalFormat;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
public abstract class Economy implements Hook {
|
||||
|
||||
/**
|
||||
@ -18,7 +19,7 @@ public abstract class Economy implements Hook {
|
||||
* Check to see if a player has at least some balance available
|
||||
*
|
||||
* @param player player to check
|
||||
* @param cost minimum amount this player should have
|
||||
* @param cost minimum amount this player should have
|
||||
* @return true if this player can have this amount withdrawn
|
||||
*/
|
||||
public abstract boolean hasBalance(OfflinePlayer player, double cost);
|
||||
@ -27,7 +28,7 @@ public abstract class Economy implements Hook {
|
||||
* Try to withdraw an amount from a player's balance
|
||||
*
|
||||
* @param player player to check
|
||||
* @param cost amount to remove from this player
|
||||
* @param cost amount to remove from this player
|
||||
* @return true if the total amount was withdrawn successfully
|
||||
*/
|
||||
public abstract boolean withdrawBalance(OfflinePlayer player, double cost);
|
||||
@ -43,6 +44,7 @@ public abstract class Economy implements Hook {
|
||||
|
||||
/**
|
||||
* Format the given amount to a human-readable string in this currency
|
||||
*
|
||||
* @param amt amount to display
|
||||
* @return a currency string as formatted by the economy plugin
|
||||
*/
|
||||
|
@ -11,7 +11,7 @@ public class VaultEconomy extends Economy {
|
||||
public VaultEconomy() {
|
||||
// this returns null if we have Vault with no compatible eco plugin
|
||||
RegisteredServiceProvider<net.milkbowl.vault.economy.Economy> v = Bukkit.getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||
if(v != null) {
|
||||
if (v != null) {
|
||||
this.vault = v.getProvider();
|
||||
} else {
|
||||
// whoopsie!
|
||||
@ -29,7 +29,7 @@ public class VaultEconomy extends Economy {
|
||||
return "Vault";
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public String formatEconomy(double amt) {
|
||||
return vault != null ? vault.format(amt) : super.formatEconomy(amt);
|
||||
}
|
||||
|
@ -3,6 +3,10 @@ package com.songoda.core.hooks.holograms;
|
||||
import com.Zrips.CMI.CMI;
|
||||
import com.Zrips.CMI.Modules.Holograms.CMIHologram;
|
||||
import com.Zrips.CMI.Modules.Holograms.HologramManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@ -10,9 +14,6 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class CMIHolograms extends Holograms {
|
||||
|
||||
|
@ -28,7 +28,7 @@ public abstract class Holograms implements Hook {
|
||||
|
||||
/**
|
||||
* Center and offset this location
|
||||
*
|
||||
*
|
||||
* @param location location to offset
|
||||
* @return copy-safe location with the applied offset.
|
||||
*/
|
||||
|
@ -4,12 +4,13 @@ import com.sainttx.holograms.api.Hologram;
|
||||
import com.sainttx.holograms.api.HologramPlugin;
|
||||
import com.sainttx.holograms.api.line.HologramLine;
|
||||
import com.sainttx.holograms.api.line.TextLine;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
public class HologramsHolograms extends Holograms {
|
||||
|
||||
HologramPlugin hologramPlugin;
|
||||
@ -54,7 +55,7 @@ public class HologramsHolograms extends Holograms {
|
||||
|
||||
@Override
|
||||
public void removeAllHolograms() {
|
||||
for(String id : ourHolograms) {
|
||||
for (String id : ourHolograms) {
|
||||
Hologram hologram = hologramPlugin.getHologramManager().getHologram(id);
|
||||
if (hologram != null) {
|
||||
hologram.despawn();
|
||||
@ -72,14 +73,14 @@ public class HologramsHolograms extends Holograms {
|
||||
hologram.spawn();
|
||||
// only update if there is a change to the text
|
||||
boolean isChanged = lines.size() != hologram.getLines().size();
|
||||
if(!isChanged) {
|
||||
if (!isChanged) {
|
||||
// double-check the lines
|
||||
for(int i = 0; !isChanged && i < lines.size(); ++i) {
|
||||
for (int i = 0; !isChanged && i < lines.size(); ++i) {
|
||||
isChanged = !hologram.getLine(i).getRaw().equals(lines.get(i));
|
||||
}
|
||||
}
|
||||
if(isChanged) {
|
||||
for(HologramLine line : hologram.getLines().toArray(new HologramLine[0])) {
|
||||
if (isChanged) {
|
||||
for (HologramLine line : hologram.getLines().toArray(new HologramLine[0])) {
|
||||
hologram.removeLine(line);
|
||||
}
|
||||
for (String line : lines) {
|
||||
@ -105,7 +106,7 @@ public class HologramsHolograms extends Holograms {
|
||||
|
||||
hologramPlugin.getHologramManager().addActiveHologram(hologram);
|
||||
|
||||
if(!ourHolograms.contains(id))
|
||||
if (!ourHolograms.contains(id))
|
||||
ourHolograms.add(id);
|
||||
}
|
||||
|
||||
|
@ -53,13 +53,13 @@ public class HolographicDisplaysHolograms extends Holograms {
|
||||
|| hologram.getZ() != location.getZ()) continue;
|
||||
// only update if there is a change to the text
|
||||
boolean isChanged = lines.size() != hologram.size();
|
||||
if(!isChanged) {
|
||||
if (!isChanged) {
|
||||
// double-check the lines
|
||||
for(int i = 0; !isChanged && i < lines.size(); ++i) {
|
||||
for (int i = 0; !isChanged && i < lines.size(); ++i) {
|
||||
isChanged = !hologram.getLine(i).toString().equals("CraftTextLine [text=" + lines.get(i) + "]");
|
||||
}
|
||||
}
|
||||
if(isChanged) {
|
||||
if (isChanged) {
|
||||
hologram.clearLines();
|
||||
for (String line : lines) {
|
||||
hologram.appendTextLine(line);
|
||||
@ -71,7 +71,7 @@ public class HolographicDisplaysHolograms extends Holograms {
|
||||
}
|
||||
|
||||
private void createAt(Location location, List<String> lines) {
|
||||
Hologram hologram = HologramsAPI.createHologram(plugin, location);
|
||||
Hologram hologram = HologramsAPI.createHologram(plugin, location);
|
||||
for (String line : lines) {
|
||||
hologram.appendTextLine(line);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.songoda.core.hooks.jobs;
|
||||
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -12,9 +12,6 @@ import com.gamingmesh.jobs.container.CurrencyType;
|
||||
import com.gamingmesh.jobs.container.Job;
|
||||
import com.gamingmesh.jobs.container.JobProgression;
|
||||
import com.gamingmesh.jobs.container.JobsPlayer;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Entity;
|
||||
@ -22,6 +19,10 @@ import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class JobsPlayerHandler {
|
||||
|
||||
protected final JobsPlayer jPlayer;
|
||||
|
@ -13,16 +13,17 @@ import com.gmail.nossr50.util.random.RandomChanceUtil;
|
||||
import com.gmail.nossr50.util.skills.RankUtils;
|
||||
import com.gmail.nossr50.util.skills.SkillActivationType;
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class McMMOHandler {
|
||||
|
||||
|
@ -7,8 +7,6 @@ import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class UltimateStacker extends Stacker {
|
||||
|
||||
private final com.songoda.ultimatestacker.UltimateStacker plugin;
|
||||
|
@ -11,6 +11,10 @@ import com.sk89q.worldguard.protection.flags.StateFlag.State;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
@ -19,13 +23,10 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Stream;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
|
||||
/**
|
||||
* Hooks for adding a custom WorldGuard flag
|
||||
*
|
||||
* <p>
|
||||
* Note: Hooks must be added before WG loads!
|
||||
*/
|
||||
public class WorldGuardFlagHandler {
|
||||
@ -75,7 +76,7 @@ public class WorldGuardFlagHandler {
|
||||
* Attempt to register a worldGuard flag (ALLOW/DENY) <br />
|
||||
* Note: This must be called before WorldGuard loads, or it will fail.
|
||||
*
|
||||
* @param flag name of the flag to set
|
||||
* @param flag name of the flag to set
|
||||
* @param state default value of the flag
|
||||
*/
|
||||
public static void addHook(String flag, boolean state) {
|
||||
@ -139,7 +140,7 @@ public class WorldGuardFlagHandler {
|
||||
|
||||
if (legacy_v62) { // SimpleFlagRegistry is NOT in 6.0 or 6.1
|
||||
// register this flag in the registry
|
||||
if(legacy_simpleFlagRegistryClazz == null) {
|
||||
if (legacy_simpleFlagRegistryClazz == null) {
|
||||
legacy_worldGuardPlugin_flagRegistry = getPrivateField(worldGuardPlugin.getClass(), worldGuardPlugin, "flagRegistry");
|
||||
legacy_simpleFlagRegistryClazz = Class.forName("com.sk89q.worldguard.protection.flags.registry.SimpleFlagRegistry");
|
||||
legacy_simpleFlagRegistry_get = legacy_simpleFlagRegistryClazz.getDeclaredMethod("get", String.class);
|
||||
@ -212,7 +213,7 @@ public class WorldGuardFlagHandler {
|
||||
/**
|
||||
* Checks this location to see what this flag is set to
|
||||
*
|
||||
* @param loc location to check
|
||||
* @param loc location to check
|
||||
* @param flag ALLOW/DENY flag to check
|
||||
* @return flag state, or null if undefined
|
||||
*/
|
||||
@ -240,7 +241,7 @@ public class WorldGuardFlagHandler {
|
||||
/**
|
||||
* Query all regions that are in or intersect this chunk
|
||||
*
|
||||
* @param c chunk to check for regions in
|
||||
* @param c chunk to check for regions in
|
||||
* @param flag ALLOW/DENY flag to check
|
||||
* @return flag state, or null if undefined
|
||||
*/
|
||||
|
@ -7,15 +7,16 @@ import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class WorldGuardRegionHandler {
|
||||
|
||||
|
@ -1,9 +1,5 @@
|
||||
package com.songoda.core.input;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -14,6 +10,11 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class ChatPrompt implements Listener {
|
||||
|
||||
private static final List<UUID> registered = new ArrayList<>();
|
||||
@ -87,6 +88,7 @@ public class ChatPrompt implements Listener {
|
||||
}
|
||||
HandlerList.unregisterAll(listener);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false)
|
||||
public void onCancel(PlayerCommandPreprocessEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
@ -94,7 +96,7 @@ public class ChatPrompt implements Listener {
|
||||
|
||||
ChatPrompt.unregister(player);
|
||||
|
||||
if(event.getMessage().toLowerCase().startsWith("/cancel"))
|
||||
if (event.getMessage().toLowerCase().startsWith("/cancel"))
|
||||
event.setCancelled(true);
|
||||
|
||||
if (onCancel != null) {
|
||||
|
@ -3,17 +3,11 @@ package com.songoda.core.locale;
|
||||
import com.songoda.core.configuration.Config;
|
||||
import com.songoda.core.configuration.ConfigSection;
|
||||
import com.songoda.core.utils.TextUtils;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
@ -25,9 +19,6 @@ import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
/**
|
||||
* Assists in the utilization of localization files. <br>
|
||||
@ -50,8 +41,8 @@ public class Locale {
|
||||
* Instantiate the Locale class for future use
|
||||
*
|
||||
* @param plugin Owning Plugin
|
||||
* @param file Location of the locale file
|
||||
* @param name The locale name for the language
|
||||
* @param file Location of the locale file
|
||||
* @param name The locale name for the language
|
||||
*/
|
||||
public Locale(Plugin plugin, File file, String name) {
|
||||
this.plugin = plugin;
|
||||
@ -60,10 +51,10 @@ public class Locale {
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a default-included lang file from the plugin's jar file
|
||||
* Load a default-included lang file from the plugin's jar file
|
||||
*
|
||||
* @param plugin plugin to load from
|
||||
* @param name name of the default locale, eg "en_US"
|
||||
* @param name name of the default locale, eg "en_US"
|
||||
* @return returns the loaded Locale, or null if there was an error
|
||||
*/
|
||||
public static Locale loadDefaultLocale(JavaPlugin plugin, String name) {
|
||||
@ -75,7 +66,7 @@ public class Locale {
|
||||
* Load a locale from this plugin's locale directory
|
||||
*
|
||||
* @param plugin plugin to load from
|
||||
* @param name name of the locale, eg "en_US"
|
||||
* @param name name of the locale, eg "en_US"
|
||||
* @return returns the loaded Locale, or null if there was an error
|
||||
*/
|
||||
public static Locale loadLocale(JavaPlugin plugin, String name) {
|
||||
@ -88,7 +79,7 @@ public class Locale {
|
||||
if (!l.reloadMessages()) return null;
|
||||
plugin.getLogger().info("Loaded locale \"" + name + "\"");
|
||||
return l;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all locales from this plugin's locale directory
|
||||
@ -99,7 +90,7 @@ public class Locale {
|
||||
public static List<Locale> loadAllLocales(JavaPlugin plugin) {
|
||||
File localeFolder = new File(plugin.getDataFolder(), "locales/");
|
||||
List<Locale> all = new ArrayList();
|
||||
for (File localeFile : localeFolder.listFiles()) {
|
||||
for (File localeFile : localeFolder.listFiles()) {
|
||||
String fileName = localeFile.getName();
|
||||
if (!fileName.endsWith(FILE_EXTENSION)) continue;
|
||||
fileName = fileName.substring(0, fileName.lastIndexOf('.'));
|
||||
@ -123,7 +114,7 @@ public class Locale {
|
||||
List<String> all = new ArrayList();
|
||||
for (File localeFile : localeFolder.listFiles()) {
|
||||
String fileName = localeFile.getName();
|
||||
if (!fileName.endsWith(FILE_EXTENSION)) continue;
|
||||
if (!fileName.endsWith(FILE_EXTENSION)) continue;
|
||||
fileName = fileName.substring(0, fileName.lastIndexOf('.'));
|
||||
if (fileName.split("_").length != 2) {
|
||||
continue;
|
||||
@ -136,8 +127,8 @@ public class Locale {
|
||||
/**
|
||||
* Save a locale file from the Plugin's Resources to the locale folder
|
||||
*
|
||||
* @param plugin plugin owning the locale file
|
||||
* @param locale the specific locale file to save
|
||||
* @param plugin plugin owning the locale file
|
||||
* @param locale the specific locale file to save
|
||||
* @param fileName where to save the file
|
||||
* @return true if the operation was successful, false otherwise
|
||||
*/
|
||||
@ -148,8 +139,8 @@ public class Locale {
|
||||
/**
|
||||
* Save a locale file from an InputStream to the locale folder
|
||||
*
|
||||
* @param plugin plugin owning the locale file
|
||||
* @param in file to save
|
||||
* @param plugin plugin owning the locale file
|
||||
* @param in file to save
|
||||
* @param fileName the name of the file to save
|
||||
* @return true if the operation was successful, false otherwise
|
||||
*/
|
||||
@ -158,7 +149,7 @@ public class Locale {
|
||||
}
|
||||
|
||||
private static boolean saveLocale(Plugin plugin, InputStream in, String fileName, boolean builtin) {
|
||||
if(in == null) return false;
|
||||
if (in == null) return false;
|
||||
File localeFolder = new File(plugin.getDataFolder(), "locales/");
|
||||
if (!localeFolder.exists()) localeFolder.mkdirs();
|
||||
|
||||
@ -186,15 +177,15 @@ public class Locale {
|
||||
private static boolean updateFiles(Plugin plugin, InputStream defaultFile, File existingFile, boolean builtin) {
|
||||
|
||||
try (BufferedInputStream defaultIn = new BufferedInputStream(defaultFile);
|
||||
BufferedInputStream existingIn = new BufferedInputStream(new FileInputStream(existingFile))) {
|
||||
BufferedInputStream existingIn = new BufferedInputStream(new FileInputStream(existingFile))) {
|
||||
|
||||
Charset defaultCharset = TextUtils.detectCharset(defaultIn, StandardCharsets.UTF_8);
|
||||
Charset existingCharset = TextUtils.detectCharset(existingIn, StandardCharsets.UTF_8);
|
||||
|
||||
try (BufferedReader defaultReaderOriginal = new BufferedReader(new InputStreamReader(defaultIn, defaultCharset));
|
||||
BufferedReader existingReaderOriginal = new BufferedReader(new InputStreamReader(existingIn, existingCharset));
|
||||
BufferedReader defaultReader = translatePropertyToYAML(defaultReaderOriginal, defaultCharset);
|
||||
BufferedReader existingReader = translatePropertyToYAML(existingReaderOriginal, existingCharset);) {
|
||||
BufferedReader existingReaderOriginal = new BufferedReader(new InputStreamReader(existingIn, existingCharset));
|
||||
BufferedReader defaultReader = translatePropertyToYAML(defaultReaderOriginal, defaultCharset);
|
||||
BufferedReader existingReader = translatePropertyToYAML(existingReaderOriginal, existingCharset);) {
|
||||
|
||||
Config existingLang = new Config(existingFile);
|
||||
existingLang.load(existingReader);
|
||||
@ -267,15 +258,15 @@ public class Locale {
|
||||
|
||||
// guess what encoding this file is in
|
||||
Charset charset = TextUtils.detectCharset(file, null);
|
||||
if(charset == null) {
|
||||
if (charset == null) {
|
||||
plugin.getLogger().warning("Could not determine charset for locale \"" + this.name + "\"");
|
||||
charset = StandardCharsets.UTF_8;
|
||||
}
|
||||
|
||||
// load in the file!
|
||||
try (FileInputStream stream = new FileInputStream(file);
|
||||
BufferedReader source = new BufferedReader(new InputStreamReader((InputStream) stream, charset));
|
||||
BufferedReader reader = translatePropertyToYAML(source, charset);) {
|
||||
BufferedReader source = new BufferedReader(new InputStreamReader((InputStream) stream, charset));
|
||||
BufferedReader reader = translatePropertyToYAML(source, charset);) {
|
||||
Config lang = new Config(file);
|
||||
lang.load(reader);
|
||||
translateMsgRoot(lang, file, charset);
|
||||
@ -302,7 +293,7 @@ public class Locale {
|
||||
// remove BOM markers, if any
|
||||
line1 = line;
|
||||
line = line.replaceAll("[\uFEFF\uFFFE\u200B]", "");
|
||||
if(line1.length() != line.length()) {
|
||||
if (line1.length() != line.length()) {
|
||||
output.append(line1.substring(0, line1.length() - line.length()));
|
||||
}
|
||||
}
|
||||
@ -335,7 +326,7 @@ public class Locale {
|
||||
.collect(Collectors.toList());
|
||||
if (!msgs.isEmpty()) {
|
||||
try (FileInputStream stream = new FileInputStream(file);
|
||||
BufferedReader source = new BufferedReader(new InputStreamReader((InputStream) stream, charset))) {
|
||||
BufferedReader source = new BufferedReader(new InputStreamReader((InputStream) stream, charset))) {
|
||||
String line;
|
||||
for (int lineNumber = 0; (line = source.readLine()) != null; lineNumber++) {
|
||||
if (lineNumber == 0) {
|
||||
@ -361,21 +352,21 @@ public class Locale {
|
||||
.collect(Collectors.toList());
|
||||
if (!msgs.isEmpty()) {
|
||||
String source[] = file.split("\n");
|
||||
String line;
|
||||
for (int lineNumber = 0; lineNumber < source.length; lineNumber++) {
|
||||
line = source[lineNumber];
|
||||
if (lineNumber == 0) {
|
||||
// remove BOM markers, if any
|
||||
line = line.replaceAll("[\uFEFF\uFFFE\u200B]", "");
|
||||
}
|
||||
Matcher matcher;
|
||||
if (!(line = line.trim()).isEmpty() && !line.startsWith("#")
|
||||
&& (matcher = OLD_NODE_PATTERN.matcher(line)).find()) {
|
||||
if (msgs.contains(matcher.group(1))) {
|
||||
lang.set(matcher.group(1) + ".message", matcher.group(2));
|
||||
}
|
||||
String line;
|
||||
for (int lineNumber = 0; lineNumber < source.length; lineNumber++) {
|
||||
line = source[lineNumber];
|
||||
if (lineNumber == 0) {
|
||||
// remove BOM markers, if any
|
||||
line = line.replaceAll("[\uFEFF\uFFFE\u200B]", "");
|
||||
}
|
||||
Matcher matcher;
|
||||
if (!(line = line.trim()).isEmpty() && !line.startsWith("#")
|
||||
&& (matcher = OLD_NODE_PATTERN.matcher(line)).find()) {
|
||||
if (msgs.contains(matcher.group(1))) {
|
||||
lang.set(matcher.group(1) + ".message", matcher.group(2));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -406,7 +397,7 @@ public class Locale {
|
||||
* @return the message for the specified node
|
||||
*/
|
||||
public Message getMessage(String node) {
|
||||
if(this.nodes.containsKey(node + ".message")) {
|
||||
if (this.nodes.containsKey(node + ".message")) {
|
||||
node += ".message";
|
||||
}
|
||||
return this.getMessageOrDefault(node, node);
|
||||
@ -420,7 +411,7 @@ public class Locale {
|
||||
* @return the message for the specified node. Default if none found
|
||||
*/
|
||||
public Message getMessageOrDefault(String node, String defaultValue) {
|
||||
if(this.nodes.containsKey(node + ".message")) {
|
||||
if (this.nodes.containsKey(node + ".message")) {
|
||||
node += ".message";
|
||||
}
|
||||
return supplyPrefix(new Message(this.nodes.getOrDefault(node, defaultValue)));
|
||||
|
@ -2,15 +2,15 @@ package com.songoda.core.locale;
|
||||
|
||||
import com.songoda.core.chat.ChatMessage;
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import com.songoda.core.utils.TextUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
/**
|
||||
* The Message object. This holds the message to be sent
|
||||
* as well as the plugins prefix so that they can both be
|
||||
@ -19,15 +19,17 @@ import org.bukkit.entity.Player;
|
||||
public class Message {
|
||||
|
||||
private static boolean canActionBar = false;
|
||||
|
||||
static {
|
||||
try {
|
||||
Class.forName("net.md_5.bungee.api.ChatMessageType");
|
||||
Class.forName("net.md_5.bungee.api.ChatMessageType");
|
||||
Class.forName("net.md_5.bungee.api.chat.TextComponent");
|
||||
Player.Spigot.class.getDeclaredMethod("sendMessage", net.md_5.bungee.api.ChatMessageType.class, net.md_5.bungee.api.chat.TextComponent.class);
|
||||
canActionBar = true;
|
||||
} catch (Exception ex) {
|
||||
canActionBar = true;
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
}
|
||||
|
||||
private ChatMessage prefix = null;
|
||||
private ChatMessage message;
|
||||
|
||||
@ -119,7 +121,7 @@ public class Message {
|
||||
* @return the prefixed message
|
||||
*/
|
||||
public String getPrefixedMessage() {
|
||||
return TextUtils.formatText((prefix == null ? "" : this.prefix.toText()) + " " + this.message.toText());
|
||||
return TextUtils.formatText((prefix == null ? "" : this.prefix.toText()) + " " + this.message.toText());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -159,7 +161,7 @@ public class Message {
|
||||
*/
|
||||
public Message processPlaceholder(String placeholder, Object replacement) {
|
||||
final String place = Matcher.quoteReplacement(placeholder);
|
||||
this.message = message.replaceAll("%" + place + "%|\\{" + place +"\\}", replacement == null ? "" : Matcher.quoteReplacement(replacement.toString()));
|
||||
this.message = message.replaceAll("%" + place + "%|\\{" + place + "\\}", replacement == null ? "" : Matcher.quoteReplacement(replacement.toString()));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,11 @@ package com.songoda.core.utils;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
||||
@ -313,7 +317,7 @@ public class BlockUtils {
|
||||
* @param location location of the container
|
||||
*/
|
||||
public static void updateAdjacentComparators(Location location) {
|
||||
if(location == null || location.getWorld() == null) return;
|
||||
if (location == null || location.getWorld() == null) return;
|
||||
try {
|
||||
// Cache reflection.
|
||||
if (clazzCraftWorld == null) {
|
||||
|
@ -1,153 +1,152 @@
|
||||
package com.songoda.core.utils;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.Ageable;
|
||||
import org.bukkit.block.data.AnaloguePowerable;
|
||||
import org.bukkit.block.data.Bisected;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.AnaloguePowerable;
|
||||
import org.bukkit.block.data.Powerable;
|
||||
import org.bukkit.block.data.type.Door;
|
||||
import org.bukkit.block.data.type.Gate;
|
||||
import org.bukkit.block.data.type.Switch;
|
||||
import org.bukkit.block.data.type.TrapDoor;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class BlockUtilsModern {
|
||||
|
||||
protected static void _updatePressurePlateModern(Block plate, int power) {
|
||||
BlockData blockData = plate.getBlockData();
|
||||
boolean update = false;
|
||||
if (blockData instanceof AnaloguePowerable) {
|
||||
AnaloguePowerable a = (AnaloguePowerable) blockData;
|
||||
int toPower = Math.min(a.getMaximumPower(), power);
|
||||
if ((update = toPower != a.getPower())) {
|
||||
a.setPower(toPower);
|
||||
plate.setBlockData(a);
|
||||
}
|
||||
} else if (blockData instanceof Powerable) {
|
||||
Powerable p = (Powerable) blockData;
|
||||
if ((update = p.isPowered() != (power != 0))) {
|
||||
p.setPowered(power != 0);
|
||||
plate.setBlockData(p);
|
||||
}
|
||||
}
|
||||
if (update) {
|
||||
_updateRedstoneNeighbours(plate);
|
||||
}
|
||||
}
|
||||
protected static void _updatePressurePlateModern(Block plate, int power) {
|
||||
BlockData blockData = plate.getBlockData();
|
||||
boolean update = false;
|
||||
if (blockData instanceof AnaloguePowerable) {
|
||||
AnaloguePowerable a = (AnaloguePowerable) blockData;
|
||||
int toPower = Math.min(a.getMaximumPower(), power);
|
||||
if ((update = toPower != a.getPower())) {
|
||||
a.setPower(toPower);
|
||||
plate.setBlockData(a);
|
||||
}
|
||||
} else if (blockData instanceof Powerable) {
|
||||
Powerable p = (Powerable) blockData;
|
||||
if ((update = p.isPowered() != (power != 0))) {
|
||||
p.setPowered(power != 0);
|
||||
plate.setBlockData(p);
|
||||
}
|
||||
}
|
||||
if (update) {
|
||||
_updateRedstoneNeighbours(plate);
|
||||
}
|
||||
}
|
||||
|
||||
protected static void _toggleLeverModern(Block lever) {
|
||||
BlockData blockData = lever.getBlockData();
|
||||
if (blockData instanceof Switch) {
|
||||
Switch s = (Switch) blockData;
|
||||
s.setPowered(!s.isPowered());
|
||||
lever.setBlockData(s);
|
||||
_updateRedstoneNeighbours(lever);
|
||||
}
|
||||
}
|
||||
protected static void _toggleLeverModern(Block lever) {
|
||||
BlockData blockData = lever.getBlockData();
|
||||
if (blockData instanceof Switch) {
|
||||
Switch s = (Switch) blockData;
|
||||
s.setPowered(!s.isPowered());
|
||||
lever.setBlockData(s);
|
||||
_updateRedstoneNeighbours(lever);
|
||||
}
|
||||
}
|
||||
|
||||
protected static void _pressButtonModern(Block button) {
|
||||
BlockData blockData = button.getBlockData();
|
||||
if (blockData instanceof Switch) {
|
||||
Switch s = (Switch) blockData;
|
||||
s.setPowered(true);
|
||||
button.setBlockData(s);
|
||||
_updateRedstoneNeighbours(button);
|
||||
}
|
||||
}
|
||||
protected static void _pressButtonModern(Block button) {
|
||||
BlockData blockData = button.getBlockData();
|
||||
if (blockData instanceof Switch) {
|
||||
Switch s = (Switch) blockData;
|
||||
s.setPowered(true);
|
||||
button.setBlockData(s);
|
||||
_updateRedstoneNeighbours(button);
|
||||
}
|
||||
}
|
||||
|
||||
static void _releaseButtonModern(Block button) {
|
||||
BlockData blockData = button.getBlockData();
|
||||
if (blockData instanceof Switch) {
|
||||
Switch s = (Switch) blockData;
|
||||
s.setPowered(false);
|
||||
button.setBlockData(s);
|
||||
_updateRedstoneNeighbours(button);
|
||||
}
|
||||
}
|
||||
static void _releaseButtonModern(Block button) {
|
||||
BlockData blockData = button.getBlockData();
|
||||
if (blockData instanceof Switch) {
|
||||
Switch s = (Switch) blockData;
|
||||
s.setPowered(false);
|
||||
button.setBlockData(s);
|
||||
_updateRedstoneNeighbours(button);
|
||||
}
|
||||
}
|
||||
|
||||
private static Class<?> clazzCraftWorld, clazzCraftBlock,
|
||||
clazzLeverBlock, clazzButtonBlock, clazzPressurePlateBlock;
|
||||
private static Method craftWorld_getHandle, craftBlock_getNMSBlock, craftBlock_getPostition, craftBlockData_getState,
|
||||
nmsLever_updateNeighbours, nmsButton_updateNeighbours, nmsPlate_updateNeighbours;
|
||||
private static Class<?> clazzCraftWorld, clazzCraftBlock,
|
||||
clazzLeverBlock, clazzButtonBlock, clazzPressurePlateBlock;
|
||||
private static Method craftWorld_getHandle, craftBlock_getNMSBlock, craftBlock_getPostition, craftBlockData_getState,
|
||||
nmsLever_updateNeighbours, nmsButton_updateNeighbours, nmsPlate_updateNeighbours;
|
||||
|
||||
static {
|
||||
try {
|
||||
// Cache reflection.
|
||||
static {
|
||||
try {
|
||||
// Cache reflection.
|
||||
|
||||
String ver = Bukkit.getServer().getClass().getPackage().getName().substring(23);
|
||||
clazzCraftWorld = Class.forName("org.bukkit.craftbukkit." + ver + ".CraftWorld");
|
||||
clazzCraftBlock = Class.forName("org.bukkit.craftbukkit." + ver + ".block.CraftBlock");
|
||||
//clazzBlockPosition = Class.forName("net.minecraft.server." + ver + ".BlockPosition");
|
||||
String ver = Bukkit.getServer().getClass().getPackage().getName().substring(23);
|
||||
clazzCraftWorld = Class.forName("org.bukkit.craftbukkit." + ver + ".CraftWorld");
|
||||
clazzCraftBlock = Class.forName("org.bukkit.craftbukkit." + ver + ".block.CraftBlock");
|
||||
//clazzBlockPosition = Class.forName("net.minecraft.server." + ver + ".BlockPosition");
|
||||
|
||||
craftWorld_getHandle = clazzCraftWorld.getMethod("getHandle");
|
||||
craftBlock_getNMSBlock = clazzCraftBlock.getDeclaredMethod("getNMSBlock");
|
||||
craftBlock_getNMSBlock.setAccessible(true);
|
||||
craftBlock_getPostition = clazzCraftBlock.getDeclaredMethod("getPosition");
|
||||
craftWorld_getHandle = clazzCraftWorld.getMethod("getHandle");
|
||||
craftBlock_getNMSBlock = clazzCraftBlock.getDeclaredMethod("getNMSBlock");
|
||||
craftBlock_getNMSBlock.setAccessible(true);
|
||||
craftBlock_getPostition = clazzCraftBlock.getDeclaredMethod("getPosition");
|
||||
|
||||
Class<?> clazzCraftBlockData = Class.forName("org.bukkit.craftbukkit." + ver + ".block.data.CraftBlockData");
|
||||
craftBlockData_getState = clazzCraftBlockData.getDeclaredMethod("getState");
|
||||
Class<?> clazzCraftBlockData = Class.forName("org.bukkit.craftbukkit." + ver + ".block.data.CraftBlockData");
|
||||
craftBlockData_getState = clazzCraftBlockData.getDeclaredMethod("getState");
|
||||
|
||||
Class<?> clazzWorld = Class.forName("net.minecraft.server." + ver + ".World");
|
||||
Class<?> clazzBlockState = Class.forName("net.minecraft.server." + ver + ".IBlockData");
|
||||
Class<?> clazzBlockPos = Class.forName("net.minecraft.server." + ver + ".BlockPosition");
|
||||
clazzLeverBlock = Class.forName("net.minecraft.server." + ver + ".BlockLever");
|
||||
clazzButtonBlock = Class.forName("net.minecraft.server." + ver + ".BlockButtonAbstract");
|
||||
clazzPressurePlateBlock = Class.forName("net.minecraft.server." + ver + ".BlockPressurePlateAbstract");
|
||||
Class<?> clazzWorld = Class.forName("net.minecraft.server." + ver + ".World");
|
||||
Class<?> clazzBlockState = Class.forName("net.minecraft.server." + ver + ".IBlockData");
|
||||
Class<?> clazzBlockPos = Class.forName("net.minecraft.server." + ver + ".BlockPosition");
|
||||
clazzLeverBlock = Class.forName("net.minecraft.server." + ver + ".BlockLever");
|
||||
clazzButtonBlock = Class.forName("net.minecraft.server." + ver + ".BlockButtonAbstract");
|
||||
clazzPressurePlateBlock = Class.forName("net.minecraft.server." + ver + ".BlockPressurePlateAbstract");
|
||||
|
||||
// nmsLever_updateNeighbours, nmsButton_updateNeighbours, nmsPlate_updateNeighbours
|
||||
nmsLever_updateNeighbours = clazzLeverBlock.getDeclaredMethod(ServerVersion.isServerVersionAbove(ServerVersion.V1_13)
|
||||
// nmsLever_updateNeighbours, nmsButton_updateNeighbours, nmsPlate_updateNeighbours
|
||||
nmsLever_updateNeighbours = clazzLeverBlock.getDeclaredMethod(ServerVersion.isServerVersionAbove(ServerVersion.V1_13)
|
||||
? "e" : "b", clazzBlockState, clazzWorld, clazzBlockPos);
|
||||
nmsLever_updateNeighbours.setAccessible(true);
|
||||
nmsLever_updateNeighbours.setAccessible(true);
|
||||
|
||||
nmsButton_updateNeighbours = clazzButtonBlock.getDeclaredMethod(ServerVersion.isServerVersionAbove(ServerVersion.V1_13)
|
||||
nmsButton_updateNeighbours = clazzButtonBlock.getDeclaredMethod(ServerVersion.isServerVersionAbove(ServerVersion.V1_13)
|
||||
? "f" : "c", clazzBlockState, clazzWorld, clazzBlockPos);
|
||||
nmsButton_updateNeighbours.setAccessible(true);
|
||||
nmsButton_updateNeighbours.setAccessible(true);
|
||||
|
||||
nmsPlate_updateNeighbours = clazzPressurePlateBlock.getDeclaredMethod("a", clazzWorld, clazzBlockPos);
|
||||
nmsPlate_updateNeighbours.setAccessible(true);
|
||||
} catch (Throwable ex) {
|
||||
Logger.getLogger(BlockUtilsModern.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
nmsPlate_updateNeighbours = clazzPressurePlateBlock.getDeclaredMethod("a", clazzWorld, clazzBlockPos);
|
||||
nmsPlate_updateNeighbours.setAccessible(true);
|
||||
} catch (Throwable ex) {
|
||||
Logger.getLogger(BlockUtilsModern.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
static void _updateRedstoneNeighbours(Block block) {
|
||||
try {
|
||||
// spigot made some changes to how data updates work in 1.13+
|
||||
// updating the data value of a redstone power source
|
||||
// does NOT update attatched block power,
|
||||
// even if you update the block state. (Still broken last I checked in 1.15.2)
|
||||
// so now we're going to manually call the updateNeighbours block method
|
||||
static void _updateRedstoneNeighbours(Block block) {
|
||||
try {
|
||||
// spigot made some changes to how data updates work in 1.13+
|
||||
// updating the data value of a redstone power source
|
||||
// does NOT update attatched block power,
|
||||
// even if you update the block state. (Still broken last I checked in 1.15.2)
|
||||
// so now we're going to manually call the updateNeighbours block method
|
||||
|
||||
// invoke and cast objects.
|
||||
Object cworld = clazzCraftWorld.cast(block.getWorld());
|
||||
Object mworld = craftWorld_getHandle.invoke(cworld);
|
||||
Object cblock = clazzCraftBlock.cast(block);
|
||||
Object mblock = craftBlock_getNMSBlock.invoke(cblock);
|
||||
Object mpos = craftBlock_getPostition.invoke(cblock);
|
||||
// invoke and cast objects.
|
||||
Object cworld = clazzCraftWorld.cast(block.getWorld());
|
||||
Object mworld = craftWorld_getHandle.invoke(cworld);
|
||||
Object cblock = clazzCraftBlock.cast(block);
|
||||
Object mblock = craftBlock_getNMSBlock.invoke(cblock);
|
||||
Object mpos = craftBlock_getPostition.invoke(cblock);
|
||||
|
||||
//System.out.println(mblock.getClass());
|
||||
// now for testing stuff
|
||||
if (clazzLeverBlock.isAssignableFrom(mblock.getClass())) {
|
||||
final Object mstate = craftBlockData_getState.invoke(block.getBlockData());
|
||||
nmsLever_updateNeighbours.invoke(mblock, mstate, mworld, mpos);
|
||||
} else if (clazzButtonBlock.isAssignableFrom(mblock.getClass())) {
|
||||
final Object mstate = craftBlockData_getState.invoke(block.getBlockData());
|
||||
nmsButton_updateNeighbours.invoke(mblock, mstate, mworld, mpos);
|
||||
} else if (clazzPressurePlateBlock.isAssignableFrom(mblock.getClass())) {
|
||||
nmsPlate_updateNeighbours.invoke(mblock, mworld, mpos);
|
||||
} else {
|
||||
System.out.println("Unknown redstone: " + mblock.getClass().getName());
|
||||
}
|
||||
//System.out.println(mblock.getClass());
|
||||
// now for testing stuff
|
||||
if (clazzLeverBlock.isAssignableFrom(mblock.getClass())) {
|
||||
final Object mstate = craftBlockData_getState.invoke(block.getBlockData());
|
||||
nmsLever_updateNeighbours.invoke(mblock, mstate, mworld, mpos);
|
||||
} else if (clazzButtonBlock.isAssignableFrom(mblock.getClass())) {
|
||||
final Object mstate = craftBlockData_getState.invoke(block.getBlockData());
|
||||
nmsButton_updateNeighbours.invoke(mblock, mstate, mworld, mpos);
|
||||
} else if (clazzPressurePlateBlock.isAssignableFrom(mblock.getClass())) {
|
||||
nmsPlate_updateNeighbours.invoke(mblock, mworld, mpos);
|
||||
} else {
|
||||
System.out.println("Unknown redstone: " + mblock.getClass().getName());
|
||||
}
|
||||
//
|
||||
// if(mblock instanceof net.minecraft.server.v1_15_R1.BlockLever) {
|
||||
// Method updateNeighbours = net.minecraft.server.v1_15_R1.BlockLever.class.getDeclaredMethod("e", net.minecraft.server.v1_15_R1.IBlockData.class, net.minecraft.server.v1_15_R1.World.class, net.minecraft.server.v1_15_R1.BlockPosition.class);
|
||||
@ -176,10 +175,10 @@ public class BlockUtilsModern {
|
||||
// mworld,
|
||||
// mpos);
|
||||
// }
|
||||
} catch (Throwable ex) {
|
||||
Logger.getLogger(BlockUtilsModern.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
Logger.getLogger(BlockUtilsModern.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
protected static void _toggleDoorStatesModern(boolean allowDoorToOpen, Block... doors) {
|
||||
for (Block door : doors) {
|
||||
@ -286,7 +285,7 @@ public class BlockUtilsModern {
|
||||
|
||||
protected static boolean _isCropFullyGrown(Block block) {
|
||||
BlockData data = block.getBlockData();
|
||||
if(data instanceof Ageable) {
|
||||
if (data instanceof Ageable) {
|
||||
return ((Ageable) data).getAge() == ((Ageable) data).getMaximumAge();
|
||||
}
|
||||
return false;
|
||||
@ -294,7 +293,7 @@ public class BlockUtilsModern {
|
||||
|
||||
protected static int _getMaxGrowthStage(Block block) {
|
||||
BlockData data = block.getBlockData();
|
||||
if(data instanceof Ageable) {
|
||||
if (data instanceof Ageable) {
|
||||
return ((Ageable) data).getMaximumAge();
|
||||
}
|
||||
return -1;
|
||||
@ -302,7 +301,7 @@ public class BlockUtilsModern {
|
||||
|
||||
protected static int _getMaxGrowthStage(Material material) {
|
||||
BlockData data = material.createBlockData();
|
||||
if(data instanceof Ageable) {
|
||||
if (data instanceof Ageable) {
|
||||
return ((Ageable) data).getMaximumAge();
|
||||
}
|
||||
return -1;
|
||||
|
@ -1,12 +1,11 @@
|
||||
package com.songoda.core.utils;
|
||||
|
||||
import com.songoda.core.chat.ColorCode;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import com.songoda.core.chat.ColorCode;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class ColorUtils {
|
||||
|
||||
private static Map<ColorCode, ColorSet<Integer, Integer, Integer>> colorMap = new HashMap<>();
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -8,7 +8,7 @@ public class LocationUtils {
|
||||
return location1.getBlockX() == location2.getBlockX() && location1.getBlockY() == location2.getBlockY() && location1.getBlockZ() == location2.getBlockZ();
|
||||
}
|
||||
|
||||
public static boolean isInArea(Location l, Location pos1, Location pos2){
|
||||
public static boolean isInArea(Location l, Location pos1, Location pos2) {
|
||||
double x1 = Math.min(pos1.getX(), pos2.getX());
|
||||
double y1 = Math.min(pos1.getY(), pos2.getY());
|
||||
double z1 = Math.min(pos1.getZ(), pos2.getZ());
|
||||
|
@ -10,12 +10,24 @@ import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.logging.Level;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
@ -75,7 +87,7 @@ public class Metrics {
|
||||
* @param plugin The plugin which stats should be submitted.
|
||||
*/
|
||||
public static void start(Plugin plugin) {
|
||||
Metrics m = new Metrics(plugin);
|
||||
Metrics m = new Metrics(plugin);
|
||||
if (m.enabled) {
|
||||
boolean found = false;
|
||||
// Search for all other bStats Metrics classes to see if we are the first one
|
||||
@ -84,7 +96,8 @@ public class Metrics {
|
||||
service.getField("B_STATS_VERSION"); // Our identifier :)
|
||||
found = true; // We aren't the first
|
||||
break;
|
||||
} catch (NoSuchFieldException ignored) { }
|
||||
} catch (NoSuchFieldException ignored) {
|
||||
}
|
||||
}
|
||||
// Register this specific instance as a service
|
||||
Bukkit.getServicesManager().register(Metrics.class, m, plugin, ServicePriority.Normal);
|
||||
@ -93,7 +106,7 @@ public class Metrics {
|
||||
m.startSubmitting();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Metrics(Plugin plugin) {
|
||||
if (plugin == null) {
|
||||
@ -129,7 +142,8 @@ public class Metrics {
|
||||
).copyDefaults(true);
|
||||
try {
|
||||
config.save(configFile);
|
||||
} catch (IOException ignored) { }
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
// Load the data
|
||||
@ -271,9 +285,11 @@ public class Metrics {
|
||||
for (RegisteredServiceProvider<?> provider : Bukkit.getServicesManager().getRegistrations(service)) {
|
||||
try {
|
||||
pluginData.add(provider.getService().getMethod("getPluginData").invoke(provider.getProvider()));
|
||||
} catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { }
|
||||
} catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) {
|
||||
}
|
||||
}
|
||||
} catch (NoSuchFieldException ignored) { }
|
||||
} catch (NoSuchFieldException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
data.put("plugins", pluginData);
|
||||
@ -299,7 +315,7 @@ public class Metrics {
|
||||
* Sends the data to the bStats server.
|
||||
*
|
||||
* @param plugin Any plugin. It's just used to get a logger instance.
|
||||
* @param data The data to send.
|
||||
* @param data The data to send.
|
||||
* @throws Exception If the request failed.
|
||||
*/
|
||||
private static void sendData(Plugin plugin, JSONObject data) throws Exception {
|
||||
@ -418,7 +434,7 @@ public class Metrics {
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public SimplePie(String chartId, Callable<String> callable) {
|
||||
@ -449,7 +465,7 @@ public class Metrics {
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public AdvancedPie(String chartId, Callable<Map<String, Integer>> callable) {
|
||||
@ -493,7 +509,7 @@ public class Metrics {
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public DrilldownPie(String chartId, Callable<Map<String, Map<String, Integer>>> callable) {
|
||||
@ -542,7 +558,7 @@ public class Metrics {
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public SingleLineChart(String chartId, Callable<Integer> callable) {
|
||||
@ -574,7 +590,7 @@ public class Metrics {
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public MultiLineChart(String chartId, Callable<Map<String, Integer>> callable) {
|
||||
@ -619,7 +635,7 @@ public class Metrics {
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public SimpleBarChart(String chartId, Callable<Map<String, Integer>> callable) {
|
||||
@ -657,7 +673,7 @@ public class Metrics {
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public AdvancedBarChart(String chartId, Callable<Map<String, int[]>> callable) {
|
||||
|
@ -30,7 +30,7 @@ public class NMSUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static Method getPrivateMethod(Class<?> c, String methodName, Class<?> ... parameters) throws Exception {
|
||||
public static Method getPrivateMethod(Class<?> c, String methodName, Class<?>... parameters) throws Exception {
|
||||
Method m = c.getDeclaredMethod(methodName, parameters);
|
||||
m.setAccessible(true);
|
||||
return m;
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.songoda.core.utils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@ -10,6 +8,14 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PlayerUtils {
|
||||
|
||||
static Random random = new Random();
|
||||
@ -17,9 +23,9 @@ public class PlayerUtils {
|
||||
/**
|
||||
* Get a list of all of the players that this player can "see"
|
||||
*
|
||||
* @param sender user to check against, or null for all players
|
||||
* @param sender user to check against, or null for all players
|
||||
* @param startingWith optional query to test: only players whose game names
|
||||
* start with this
|
||||
* start with this
|
||||
* @return list of player names that are "visible" to the player
|
||||
*/
|
||||
public static List<String> getVisiblePlayerNames(CommandSender sender, String startingWith) {
|
||||
@ -36,9 +42,9 @@ public class PlayerUtils {
|
||||
/**
|
||||
* Get a list of all of the players that this player can "see"
|
||||
*
|
||||
* @param sender user to check against, or null for all players
|
||||
* @param sender user to check against, or null for all players
|
||||
* @param startingWith optional query to test: only players whose game names
|
||||
* start with this
|
||||
* start with this
|
||||
* @return list of player names that are "visible" to the player
|
||||
*/
|
||||
public static List<String> getVisiblePlayerDisplayNames(CommandSender sender, String startingWith) {
|
||||
@ -55,9 +61,9 @@ public class PlayerUtils {
|
||||
/**
|
||||
* Get a list of all of the players that this player can "see"
|
||||
*
|
||||
* @param sender user to check against, or null for all players
|
||||
* @param sender user to check against, or null for all players
|
||||
* @param startingWith optional query to test: only players whose game names
|
||||
* start with this
|
||||
* start with this
|
||||
* @return list of players that are "visible" to the player
|
||||
*/
|
||||
public static List<Player> getVisiblePlayers(CommandSender sender, String startingWith) {
|
||||
@ -73,8 +79,8 @@ public class PlayerUtils {
|
||||
|
||||
/**
|
||||
* Get a list of all online player names that start with a string.
|
||||
*
|
||||
* @param us Ourselves / who is requesting the list. Will not return this player.
|
||||
*
|
||||
* @param us Ourselves / who is requesting the list. Will not return this player.
|
||||
* @param startsWith All names returned must start with this input string
|
||||
* @return List of matching player IGN
|
||||
*/
|
||||
@ -88,8 +94,8 @@ public class PlayerUtils {
|
||||
|
||||
/**
|
||||
* Get a list of all online player names that start with a string.
|
||||
*
|
||||
* @param us Ourselves / who is requesting the list. Will not return this player.
|
||||
*
|
||||
* @param us Ourselves / who is requesting the list. Will not return this player.
|
||||
* @param startsWith All names returned must start with this input string
|
||||
* @return List of matching player display names
|
||||
*/
|
||||
|
@ -66,7 +66,7 @@ public class ReflectionUtils {
|
||||
// does not work in JRE 8+
|
||||
private static Method j7getStackTraceElementMethod;
|
||||
private static Method j7getStackTraceDepthMethod;
|
||||
|
||||
|
||||
// does not work in JRE != 8
|
||||
private static Method j8getJavaLangAccess;
|
||||
private static Method j8getStackTraceElementMethod;
|
||||
@ -201,7 +201,7 @@ public class ReflectionUtils {
|
||||
int packageDelim = classPath.lastIndexOf('.');
|
||||
return getClassNamesFromPackage(getJarFile(classInPackage), classPath.substring(0, packageDelim), ITERATION.NONE);
|
||||
}
|
||||
|
||||
|
||||
public static List<String> getClassNamesFromPackage(String packageName) throws IOException, URISyntaxException, ClassNotFoundException {
|
||||
return getClassNamesFromPackage(packageName, ITERATION.NONE);
|
||||
}
|
||||
@ -296,7 +296,7 @@ public class ReflectionUtils {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// hits here if running in IDE
|
||||
// hits here if running in IDE
|
||||
|
||||
// loop through files in classpath
|
||||
URI uri = new URI(packageURL.toString());
|
||||
|
@ -3,7 +3,7 @@ package com.songoda.core.utils;
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
||||
public class RotationUtils {
|
||||
|
||||
|
||||
public static float faceToYaw(BlockFace face) {
|
||||
switch (face) {
|
||||
case NORTH:
|
||||
@ -36,5 +36,5 @@ public class RotationUtils {
|
||||
// idk
|
||||
return BlockFace.SOUTH;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.songoda.core.utils;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@ -12,8 +14,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class TextUtils {
|
||||
|
||||
public static String formatText(String text) {
|
||||
@ -37,7 +37,7 @@ public class TextUtils {
|
||||
* Convert a string to an invisible colored string that's lore-safe <br />
|
||||
* (Safe to use as lore) <br />
|
||||
* Note: Do not use semi-colons in this string, or they will be lost when decoding!
|
||||
*
|
||||
*
|
||||
* @param s string to convert
|
||||
* @return encoded string
|
||||
*/
|
||||
@ -45,7 +45,8 @@ public class TextUtils {
|
||||
if (s == null || s.equals(""))
|
||||
return "";
|
||||
StringBuilder hidden = new StringBuilder();
|
||||
for (char c : s.toCharArray()) hidden.append(ChatColor.COLOR_CHAR).append(';').append(ChatColor.COLOR_CHAR).append(c);
|
||||
for (char c : s.toCharArray())
|
||||
hidden.append(ChatColor.COLOR_CHAR).append(';').append(ChatColor.COLOR_CHAR).append(c);
|
||||
return hidden.toString();
|
||||
}
|
||||
|
||||
@ -53,7 +54,7 @@ public class TextUtils {
|
||||
* Convert a string to an invisible colored string <br />
|
||||
* (Not safe to use as lore) <br />
|
||||
* Note: Do not use semi-colons in this string, or they will be lost when decoding!
|
||||
*
|
||||
*
|
||||
* @param s string to convert
|
||||
* @return encoded string
|
||||
*/
|
||||
@ -67,7 +68,7 @@ public class TextUtils {
|
||||
|
||||
/**
|
||||
* Removes color markers used to encode strings as invisible text
|
||||
*
|
||||
*
|
||||
* @param s encoded string
|
||||
* @return string with color markers removed
|
||||
*/
|
||||
@ -87,8 +88,8 @@ public class TextUtils {
|
||||
//supportedCharsets.add(StandardCharsets.UTF_16BE); // FE FF
|
||||
//supportedCharsets.add(StandardCharsets.UTF_16);
|
||||
try {
|
||||
supportedCharsets.add(Charset.forName("windows-1253"));
|
||||
supportedCharsets.add(Charset.forName("ISO-8859-7"));
|
||||
supportedCharsets.add(Charset.forName("windows-1253"));
|
||||
supportedCharsets.add(Charset.forName("ISO-8859-7"));
|
||||
} catch (Exception e) {
|
||||
} // UnsupportedCharsetException technically can be thrown, but can also be ignored
|
||||
supportedCharsets.add(StandardCharsets.US_ASCII);
|
||||
|
@ -5,5 +5,6 @@ import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
public interface AnvilCore {
|
||||
public CustomAnvil createAnvil(Player player);
|
||||
|
||||
public CustomAnvil createAnvil(Player player, InventoryHolder holder);
|
||||
}
|
||||
|
@ -7,8 +7,8 @@ import org.bukkit.inventory.ItemStack;
|
||||
/**
|
||||
* NMS interface for creating an anvil view for a single player
|
||||
*
|
||||
* @since 2019-09-13
|
||||
* @author jascotty2
|
||||
* @since 2019-09-13
|
||||
*/
|
||||
public interface CustomAnvil {
|
||||
|
||||
|
@ -2,9 +2,6 @@ package com.songoda.core.nms.v1_10_R1.anvil;
|
||||
|
||||
import com.songoda.core.nms.anvil.CustomAnvil;
|
||||
import com.songoda.core.nms.anvil.methods.AnvilTextChange;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import net.minecraft.server.v1_10_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_10_R1.ChatMessage;
|
||||
import net.minecraft.server.v1_10_R1.ContainerAnvil;
|
||||
@ -18,6 +15,10 @@ import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class AnvilView extends ContainerAnvil implements CustomAnvil {
|
||||
|
||||
private final EntityPlayer entity;
|
||||
|
@ -5,7 +5,12 @@ import com.songoda.core.nms.nbt.NBTObject;
|
||||
import net.minecraft.server.v1_10_R1.NBTCompressedStreamTools;
|
||||
import net.minecraft.server.v1_10_R1.NBTTagCompound;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class NBTCompoundImpl implements NBTCompound {
|
||||
|
@ -1,7 +1,10 @@
|
||||
package com.songoda.core.nms.v1_10_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import net.minecraft.server.v1_10_R1.*;
|
||||
import net.minecraft.server.v1_10_R1.Entity;
|
||||
import net.minecraft.server.v1_10_R1.EntityTypes;
|
||||
import net.minecraft.server.v1_10_R1.ItemMonsterEgg;
|
||||
import net.minecraft.server.v1_10_R1.NBTTagCompound;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_10_R1.CraftWorld;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
@ -19,21 +22,21 @@ public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity {
|
||||
public org.bukkit.entity.Entity spawn(Location location) {
|
||||
String entityType = getNBTObject("entity_type").asString();
|
||||
|
||||
Entity spawned = ItemMonsterEgg.spawnCreature( // Changed since 1.14
|
||||
((CraftWorld) location.getWorld()).getHandle(),
|
||||
entityType, // Parameter simplified in 1.10
|
||||
location.getBlockX(), location.getBlockY(), location.getBlockZ(),
|
||||
CreatureSpawnEvent.SpawnReason.DEFAULT
|
||||
);
|
||||
Entity spawned = ItemMonsterEgg.spawnCreature( // Changed since 1.14
|
||||
((CraftWorld) location.getWorld()).getHandle(),
|
||||
entityType, // Parameter simplified in 1.10
|
||||
location.getBlockX(), location.getBlockY(), location.getBlockZ(),
|
||||
CreatureSpawnEvent.SpawnReason.DEFAULT
|
||||
);
|
||||
|
||||
if (spawned != null) {
|
||||
spawned.f(compound); // This changed from 1.16.1
|
||||
org.bukkit.entity.Entity entity = spawned.getBukkitEntity();
|
||||
spawned.setLocation(location.getX(), location.getY(), location.getZ(),
|
||||
location.getPitch(), location.getYaw());
|
||||
nmsEntity = spawned;
|
||||
return entity;
|
||||
}
|
||||
if (spawned != null) {
|
||||
spawned.f(compound); // This changed from 1.16.1
|
||||
org.bukkit.entity.Entity entity = spawned.getBukkitEntity();
|
||||
spawned.setLocation(location.getX(), location.getY(), location.getZ(),
|
||||
location.getPitch(), location.getYaw());
|
||||
nmsEntity = spawned;
|
||||
return entity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package com.songoda.core.nms.v1_10_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.server.v1_10_R1.NBTTagCompound;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
@ -2,9 +2,6 @@ package com.songoda.core.nms.v1_11_R1.anvil;
|
||||
|
||||
import com.songoda.core.nms.anvil.CustomAnvil;
|
||||
import com.songoda.core.nms.anvil.methods.AnvilTextChange;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import net.minecraft.server.v1_11_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_11_R1.ChatMessage;
|
||||
import net.minecraft.server.v1_11_R1.ContainerAnvil;
|
||||
@ -18,6 +15,10 @@ import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class AnvilView extends ContainerAnvil implements CustomAnvil {
|
||||
|
||||
private final EntityPlayer entity;
|
||||
|
@ -5,7 +5,12 @@ import com.songoda.core.nms.nbt.NBTObject;
|
||||
import net.minecraft.server.v1_11_R1.NBTCompressedStreamTools;
|
||||
import net.minecraft.server.v1_11_R1.NBTTagCompound;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class NBTCompoundImpl implements NBTCompound {
|
||||
|
@ -1,7 +1,11 @@
|
||||
package com.songoda.core.nms.v1_11_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import net.minecraft.server.v1_11_R1.*;
|
||||
import net.minecraft.server.v1_11_R1.Entity;
|
||||
import net.minecraft.server.v1_11_R1.EntityTypes;
|
||||
import net.minecraft.server.v1_11_R1.ItemMonsterEgg;
|
||||
import net.minecraft.server.v1_11_R1.MinecraftKey;
|
||||
import net.minecraft.server.v1_11_R1.NBTTagCompound;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_11_R1.CraftWorld;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
@ -19,21 +23,21 @@ public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity {
|
||||
public org.bukkit.entity.Entity spawn(Location location) {
|
||||
String entityType = getNBTObject("entity_type").asString();
|
||||
|
||||
Entity spawned = ItemMonsterEgg.spawnCreature( // Changed since 1.14
|
||||
((CraftWorld) location.getWorld()).getHandle(),
|
||||
new MinecraftKey(entityType),
|
||||
location.getBlockX(), location.getBlockY(), location.getBlockZ(),
|
||||
CreatureSpawnEvent.SpawnReason.DEFAULT
|
||||
);
|
||||
Entity spawned = ItemMonsterEgg.spawnCreature( // Changed since 1.14
|
||||
((CraftWorld) location.getWorld()).getHandle(),
|
||||
new MinecraftKey(entityType),
|
||||
location.getBlockX(), location.getBlockY(), location.getBlockZ(),
|
||||
CreatureSpawnEvent.SpawnReason.DEFAULT
|
||||
);
|
||||
|
||||
if (spawned != null) {
|
||||
spawned.f(compound); // This changed from 1.16.1
|
||||
org.bukkit.entity.Entity entity = spawned.getBukkitEntity();
|
||||
spawned.setLocation(location.getX(), location.getY(), location.getZ(),
|
||||
location.getPitch(), location.getYaw());
|
||||
nmsEntity = spawned;
|
||||
return entity;
|
||||
}
|
||||
if (spawned != null) {
|
||||
spawned.f(compound); // This changed from 1.16.1
|
||||
org.bukkit.entity.Entity entity = spawned.getBukkitEntity();
|
||||
spawned.setLocation(location.getX(), location.getY(), location.getZ(),
|
||||
location.getPitch(), location.getYaw());
|
||||
nmsEntity = spawned;
|
||||
return entity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package com.songoda.core.nms.v1_11_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.server.v1_11_R1.NBTTagCompound;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
@ -2,9 +2,6 @@ package com.songoda.core.nms.v1_12_R1.anvil;
|
||||
|
||||
import com.songoda.core.nms.anvil.CustomAnvil;
|
||||
import com.songoda.core.nms.anvil.methods.AnvilTextChange;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import net.minecraft.server.v1_12_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_12_R1.ChatMessage;
|
||||
import net.minecraft.server.v1_12_R1.ContainerAnvil;
|
||||
@ -18,6 +15,10 @@ import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class AnvilView extends ContainerAnvil implements CustomAnvil {
|
||||
|
||||
private final EntityPlayer entity;
|
||||
|
@ -5,7 +5,12 @@ import com.songoda.core.nms.nbt.NBTObject;
|
||||
import net.minecraft.server.v1_12_R1.NBTCompressedStreamTools;
|
||||
import net.minecraft.server.v1_12_R1.NBTTagCompound;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class NBTCompoundImpl implements NBTCompound {
|
||||
|
@ -1,10 +1,13 @@
|
||||
package com.songoda.core.nms.v1_12_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import net.minecraft.server.v1_12_R1.*;
|
||||
import net.minecraft.server.v1_12_R1.Entity;
|
||||
import net.minecraft.server.v1_12_R1.EntityTypes;
|
||||
import net.minecraft.server.v1_12_R1.ItemMonsterEgg;
|
||||
import net.minecraft.server.v1_12_R1.MinecraftKey;
|
||||
import net.minecraft.server.v1_12_R1.NBTTagCompound;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity {
|
||||
@ -20,21 +23,21 @@ public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity {
|
||||
public org.bukkit.entity.Entity spawn(Location location) {
|
||||
String entityType = getNBTObject("entity_type").asString();
|
||||
|
||||
Entity spawned = ItemMonsterEgg.spawnCreature( // Changed since 1.14
|
||||
((CraftWorld) location.getWorld()).getHandle(),
|
||||
new MinecraftKey(entityType),
|
||||
location.getBlockX(), location.getBlockY(), location.getBlockZ(),
|
||||
CreatureSpawnEvent.SpawnReason.DEFAULT
|
||||
);
|
||||
Entity spawned = ItemMonsterEgg.spawnCreature( // Changed since 1.14
|
||||
((CraftWorld) location.getWorld()).getHandle(),
|
||||
new MinecraftKey(entityType),
|
||||
location.getBlockX(), location.getBlockY(), location.getBlockZ(),
|
||||
CreatureSpawnEvent.SpawnReason.DEFAULT
|
||||
);
|
||||
|
||||
if (spawned != null) {
|
||||
spawned.f(compound); // This changed from 1.16.1
|
||||
org.bukkit.entity.Entity entity = spawned.getBukkitEntity();
|
||||
spawned.setLocation(location.getX(), location.getY(), location.getZ(),
|
||||
location.getPitch(), location.getYaw());
|
||||
nmsEntity = spawned;
|
||||
return entity;
|
||||
}
|
||||
if (spawned != null) {
|
||||
spawned.f(compound); // This changed from 1.16.1
|
||||
org.bukkit.entity.Entity entity = spawned.getBukkitEntity();
|
||||
spawned.setLocation(location.getX(), location.getY(), location.getZ(),
|
||||
location.getPitch(), location.getYaw());
|
||||
nmsEntity = spawned;
|
||||
return entity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package com.songoda.core.nms.v1_12_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.server.v1_12_R1.NBTTagCompound;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
@ -2,7 +2,13 @@ package com.songoda.core.nms.v1_13_R1.anvil;
|
||||
|
||||
import com.songoda.core.nms.anvil.CustomAnvil;
|
||||
import com.songoda.core.nms.anvil.methods.AnvilTextChange;
|
||||
import net.minecraft.server.v1_13_R1.*;
|
||||
import net.minecraft.server.v1_13_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_13_R1.ChatMessage;
|
||||
import net.minecraft.server.v1_13_R1.ContainerAnvil;
|
||||
import net.minecraft.server.v1_13_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_13_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_13_R1.IInventory;
|
||||
import net.minecraft.server.v1_13_R1.PacketPlayOutOpenWindow;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_13_R1.inventory.CraftInventoryView;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
@ -20,7 +26,7 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
|
||||
private String title = "Repairing";
|
||||
private int cost = -1;
|
||||
private boolean canUse = true;
|
||||
private AnvilTextChange textChange = null;
|
||||
private AnvilTextChange textChange = null;
|
||||
|
||||
// used for setting custom inventory
|
||||
static Field mc_ContainerAnvil_repairInventory; // subcontainer with only the result
|
||||
|
@ -5,7 +5,12 @@ import com.songoda.core.nms.nbt.NBTObject;
|
||||
import net.minecraft.server.v1_13_R1.NBTCompressedStreamTools;
|
||||
import net.minecraft.server.v1_13_R1.NBTTagCompound;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class NBTCompoundImpl implements NBTCompound {
|
||||
|
@ -1,7 +1,11 @@
|
||||
package com.songoda.core.nms.v1_13_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import net.minecraft.server.v1_13_R1.*;
|
||||
import net.minecraft.server.v1_13_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_13_R1.Entity;
|
||||
import net.minecraft.server.v1_13_R1.EntityTypes;
|
||||
import net.minecraft.server.v1_13_R1.MinecraftKey;
|
||||
import net.minecraft.server.v1_13_R1.NBTTagCompound;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_13_R1.CraftWorld;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
@ -2,7 +2,6 @@ package com.songoda.core.nms.v1_13_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.server.v1_13_R1.NBTTagCompound;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_13_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
@ -2,9 +2,6 @@ package com.songoda.core.nms.v1_13_R2.anvil;
|
||||
|
||||
import com.songoda.core.nms.anvil.CustomAnvil;
|
||||
import com.songoda.core.nms.anvil.methods.AnvilTextChange;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import net.minecraft.server.v1_13_R2.BlockPosition;
|
||||
import net.minecraft.server.v1_13_R2.ChatMessage;
|
||||
import net.minecraft.server.v1_13_R2.ContainerAnvil;
|
||||
@ -18,6 +15,10 @@ import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class AnvilView extends ContainerAnvil implements CustomAnvil {
|
||||
|
||||
private final EntityPlayer entity;
|
||||
@ -25,7 +26,7 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
|
||||
private String title = "Repairing";
|
||||
private int cost = -1;
|
||||
private boolean canUse = true;
|
||||
private AnvilTextChange textChange = null;
|
||||
private AnvilTextChange textChange = null;
|
||||
|
||||
// used for setting custom inventory
|
||||
static Field mc_ContainerAnvil_repairInventory; // subcontainer with only the result
|
||||
|
@ -5,7 +5,12 @@ import com.songoda.core.nms.nbt.NBTObject;
|
||||
import net.minecraft.server.v1_13_R2.NBTCompressedStreamTools;
|
||||
import net.minecraft.server.v1_13_R2.NBTTagCompound;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class NBTCompoundImpl implements NBTCompound {
|
||||
|
@ -1,7 +1,12 @@
|
||||
package com.songoda.core.nms.v1_13_R2.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import net.minecraft.server.v1_13_R2.*;
|
||||
import net.minecraft.server.v1_13_R2.BlockPosition;
|
||||
import net.minecraft.server.v1_13_R2.Entity;
|
||||
import net.minecraft.server.v1_13_R2.EntityTypes;
|
||||
import net.minecraft.server.v1_13_R2.IRegistry;
|
||||
import net.minecraft.server.v1_13_R2.MinecraftKey;
|
||||
import net.minecraft.server.v1_13_R2.NBTTagCompound;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_13_R2.CraftWorld;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
@ -2,7 +2,6 @@ package com.songoda.core.nms.v1_13_R2.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.server.v1_13_R2.NBTTagCompound;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
@ -2,27 +2,18 @@ package com.songoda.core.nms.v1_14_R1.anvil;
|
||||
|
||||
import com.songoda.core.nms.anvil.CustomAnvil;
|
||||
import com.songoda.core.nms.anvil.methods.AnvilTextChange;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_14_R1.ChatMessage;
|
||||
import net.minecraft.server.v1_14_R1.Container;
|
||||
import net.minecraft.server.v1_14_R1.ContainerAccess;
|
||||
import net.minecraft.server.v1_14_R1.ContainerAnvil;
|
||||
import net.minecraft.server.v1_14_R1.ContainerProperty;
|
||||
import net.minecraft.server.v1_14_R1.Containers;
|
||||
import net.minecraft.server.v1_14_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_14_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_14_R1.IInventory;
|
||||
import net.minecraft.server.v1_14_R1.PacketPlayOutOpenWindow;
|
||||
import net.minecraft.server.v1_14_R1.*;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventoryView;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class AnvilView extends ContainerAnvil implements CustomAnvil {
|
||||
|
||||
private final EntityPlayer entity;
|
||||
@ -30,7 +21,7 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
|
||||
private String customTitle = "Repairing";
|
||||
private int cost = -1;
|
||||
private boolean canUse = true;
|
||||
private AnvilTextChange textChange = null;
|
||||
private AnvilTextChange textChange = null;
|
||||
|
||||
// used for setting custom inventory
|
||||
static Field mc_ContainerAnvil_repairInventory; // subcontainer with only the result
|
||||
@ -89,7 +80,7 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
|
||||
this.setTitle(new ChatMessage(customTitle != null ? customTitle : ""));
|
||||
this.checkReachable = false;
|
||||
this.entity = entity;
|
||||
if(holder != null) {
|
||||
if (holder != null) {
|
||||
this.inventory = getBukkitView(entity, holder).getTopInventory();
|
||||
} else {
|
||||
this.inventory = getBukkitView().getTopInventory();
|
||||
@ -100,7 +91,7 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
|
||||
try {
|
||||
AnvilInventoryCustom craftInventory = new AnvilInventoryCustom(holder,
|
||||
new Location(entity.world.getWorld(), 0, 0, 0),
|
||||
(IInventory) mc_ContainerAnvil_repairInventory.get(this),
|
||||
(IInventory) mc_ContainerAnvil_repairInventory.get(this),
|
||||
(IInventory) mc_ContainerAnvil_resultInventory.get(this), this);
|
||||
CraftInventoryView view = new CraftInventoryView(player.getBukkitEntity(), craftInventory, this);
|
||||
mc_ContainerAnvil_bukkitEntity.set(this, view);
|
||||
|
@ -5,7 +5,12 @@ import com.songoda.core.nms.nbt.NBTObject;
|
||||
import net.minecraft.server.v1_14_R1.NBTCompressedStreamTools;
|
||||
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class NBTCompoundImpl implements NBTCompound {
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user