🔥 Removed unused code, added cleaner Java AWT detection
This commit is contained in:
parent
e4f245349c
commit
920f384a56
5 changed files with 100 additions and 46 deletions
9
pom.xml
9
pom.xml
|
@ -159,6 +159,15 @@
|
||||||
<resource>
|
<resource>
|
||||||
<directory>src/main/resources</directory>
|
<directory>src/main/resources</directory>
|
||||||
<filtering>true</filtering>
|
<filtering>true</filtering>
|
||||||
|
<includes>
|
||||||
|
<include>plugin.yml</include>
|
||||||
|
</includes>
|
||||||
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<excludes>
|
||||||
|
<exclude>plugin.yml</exclude>
|
||||||
|
</excludes>
|
||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
</build>
|
</build>
|
||||||
|
|
|
@ -26,7 +26,6 @@ package com.bergerkiller.bukkit.common.map;
|
||||||
import com.bergerkiller.bukkit.common.map.color.MCSDBubbleFormat;
|
import com.bergerkiller.bukkit.common.map.color.MCSDBubbleFormat;
|
||||||
import com.bergerkiller.bukkit.common.map.color.MCSDGenBukkit;
|
import com.bergerkiller.bukkit.common.map.color.MCSDGenBukkit;
|
||||||
import com.bergerkiller.bukkit.common.map.color.MapColorSpaceData;
|
import com.bergerkiller.bukkit.common.map.color.MapColorSpaceData;
|
||||||
import tech.sbdevelopment.mapreflectionapi.MapReflectionAPI;
|
|
||||||
import tech.sbdevelopment.mapreflectionapi.utils.ReflectionUtil;
|
import tech.sbdevelopment.mapreflectionapi.utils.ReflectionUtil;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
@ -47,16 +46,6 @@ public class MapColorPalette {
|
||||||
public static final byte COLOR_TRANSPARENT = 0;
|
public static final byte COLOR_TRANSPARENT = 0;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// We NEED java awt or all will just fail to work anyway.
|
|
||||||
try {
|
|
||||||
Class.forName("java.awt.Color");
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
MapReflectionAPI.getInstance().getLogger().severe("The Java AWT runtime library is not available");
|
|
||||||
MapReflectionAPI.getInstance().getLogger().severe("This is usually because a headless JVM is used for the server");
|
|
||||||
MapReflectionAPI.getInstance().getLogger().severe("Please install and configure a non-headless JVM to have Map Displays work");
|
|
||||||
throw new UnsupportedOperationException("Map Displays require a non-headless JVM (Uses AWT)");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now we know java.awt exists we can initialize this one
|
// Now we know java.awt exists we can initialize this one
|
||||||
COLOR_MAP_DATA = new MapColorSpaceData();
|
COLOR_MAP_DATA = new MapColorSpaceData();
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
package tech.sbdevelopment.mapreflectionapi;
|
package tech.sbdevelopment.mapreflectionapi;
|
||||||
|
|
||||||
|
import com.bergerkiller.bukkit.common.map.MapColorPalette;
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
import org.bstats.bukkit.Metrics;
|
import org.bstats.bukkit.Metrics;
|
||||||
import org.bstats.charts.SingleLineChart;
|
import org.bstats.charts.SingleLineChart;
|
||||||
|
@ -34,6 +35,7 @@ import tech.sbdevelopment.mapreflectionapi.cmd.MapManagerCMD;
|
||||||
import tech.sbdevelopment.mapreflectionapi.listeners.MapListener;
|
import tech.sbdevelopment.mapreflectionapi.listeners.MapListener;
|
||||||
import tech.sbdevelopment.mapreflectionapi.listeners.PacketListener;
|
import tech.sbdevelopment.mapreflectionapi.listeners.PacketListener;
|
||||||
import tech.sbdevelopment.mapreflectionapi.managers.Configuration;
|
import tech.sbdevelopment.mapreflectionapi.managers.Configuration;
|
||||||
|
import tech.sbdevelopment.mapreflectionapi.utils.MainUtil;
|
||||||
import tech.sbdevelopment.mapreflectionapi.utils.ReflectionUtil;
|
import tech.sbdevelopment.mapreflectionapi.utils.ReflectionUtil;
|
||||||
import tech.sbdevelopment.mapreflectionapi.utils.UpdateManager;
|
import tech.sbdevelopment.mapreflectionapi.utils.UpdateManager;
|
||||||
|
|
||||||
|
@ -77,11 +79,15 @@ public class MapReflectionAPI extends JavaPlugin {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Bukkit.getPluginManager().isPluginEnabled("BKCommonLib")) {
|
getLogger().info("Loading Java AWT runtime library support...");
|
||||||
getLogger().severe("MapReflectionAPI requires BKCommonLib to function!");
|
if (MainUtil.isHeadlessJDK()) {
|
||||||
|
getLogger().severe("MapReflectionAPI requires the Java AWT runtime library, but is not available!");
|
||||||
|
getLogger().severe("This is usually because a headless JVM is used for the server.");
|
||||||
|
getLogger().severe("Please install and configure a non-headless JVM to make this plugin work.");
|
||||||
Bukkit.getPluginManager().disablePlugin(this);
|
Bukkit.getPluginManager().disablePlugin(this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
MapColorPalette.getColor(0, 0, 0); //Initializes the class
|
||||||
|
|
||||||
if (!Bukkit.getPluginManager().isPluginEnabled("ProtocolLib")) {
|
if (!Bukkit.getPluginManager().isPluginEnabled("ProtocolLib")) {
|
||||||
getLogger().severe("MapReflectionAPI requires ProtocolLib to function!");
|
getLogger().severe("MapReflectionAPI requires ProtocolLib to function!");
|
||||||
|
@ -126,6 +132,7 @@ public class MapReflectionAPI extends JavaPlugin {
|
||||||
metrics.addCustomChart(new SingleLineChart("managed_maps", () -> mapManager.getManagedMapsCount()));
|
metrics.addCustomChart(new SingleLineChart("managed_maps", () -> mapManager.getManagedMapsCount()));
|
||||||
|
|
||||||
if (Configuration.getInstance().isUpdaterCheck()) {
|
if (Configuration.getInstance().isUpdaterCheck()) {
|
||||||
|
try {
|
||||||
UpdateManager updateManager = new UpdateManager(this, UpdateManager.CheckType.SPIGOT);
|
UpdateManager updateManager = new UpdateManager(this, UpdateManager.CheckType.SPIGOT);
|
||||||
|
|
||||||
updateManager.handleResponse((versionResponse, version) -> {
|
updateManager.handleResponse((versionResponse, version) -> {
|
||||||
|
@ -161,6 +168,9 @@ public class MapReflectionAPI extends JavaPlugin {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}).check();
|
}).check();
|
||||||
|
} catch (IllegalStateException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getLogger().info("MapReflectionAPI is enabled!");
|
getLogger().info("MapReflectionAPI is enabled!");
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* This file is part of MapReflectionAPI.
|
||||||
|
* Copyright (c) 2022 inventivetalent / SBDevelopment - All Rights Reserved
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package tech.sbdevelopment.mapreflectionapi.utils;
|
||||||
|
|
||||||
|
public class MainUtil {
|
||||||
|
private MainUtil() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets whether this is a headless JDK that doesn't contain the Java AWT library
|
||||||
|
*
|
||||||
|
* @return True if java.awt is not available
|
||||||
|
*/
|
||||||
|
public static boolean isHeadlessJDK() {
|
||||||
|
try {
|
||||||
|
Class.forName("java.awt.Color");
|
||||||
|
return false;
|
||||||
|
} catch (ClassNotFoundException ex) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -74,6 +74,9 @@ public class UpdateManager {
|
||||||
* @param plugin The plugin instance
|
* @param plugin The plugin instance
|
||||||
*/
|
*/
|
||||||
public UpdateManager(Plugin plugin, CheckType type) {
|
public UpdateManager(Plugin plugin, CheckType type) {
|
||||||
|
if ("%%__RESOURCE__%%".equals("%%__" + "RES" + "OU" + "RCE" + "__%%"))
|
||||||
|
throw new IllegalStateException("Resource ID not set!");
|
||||||
|
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.currentVersion = new Version(plugin.getDescription().getVersion());
|
this.currentVersion = new Version(plugin.getDescription().getVersion());
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
|
Loading…
Add table
Reference in a new issue