Use munge-maven-plugin to reduce final jar size
All the code changes for the Standalone edition are now done at compile time and no longer on runtime, this also reduces the final jar size as some classes of the PluginLib are not needed in Standalone mode
This commit is contained in:
parent
373f6020e4
commit
531fa82f73
|
@ -57,7 +57,7 @@ git clone https://github.com/GeorgH93/Minepacks.git
|
|||
cd Minepacks
|
||||
mvn package
|
||||
```
|
||||
The final file will be in the target folder
|
||||
The final file will be in the `target` folder
|
||||
|
||||
### Standalone version:
|
||||
This version works without the PCGF-PluginLib, however some API features are not available.
|
||||
|
@ -66,7 +66,7 @@ git clone https://github.com/GeorgH93/Minepacks.git
|
|||
cd Minepacks
|
||||
mvn package -P Standalone
|
||||
```
|
||||
The final file will be in the target folder
|
||||
The final file will be in the `target/munged` folder
|
||||
|
||||
## API:
|
||||
Minepacks V2 comes with an API that allows you to interact with this plugin.
|
||||
|
|
18
pom.xml
18
pom.xml
|
@ -85,6 +85,7 @@
|
|||
<build>
|
||||
<defaultGoal>clean package</defaultGoal>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<testSourceDirectory>test/src</testSourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>resources</directory>
|
||||
|
@ -202,6 +203,23 @@
|
|||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- Replace all the PCGF-PluginLib code with alternatives -->
|
||||
<plugin>
|
||||
<groupId>org.sonatype.plugins</groupId>
|
||||
<artifactId>munge-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>munge</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>munge</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<symbols>STANDALONE</symbols>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
|
|
|
@ -20,7 +20,6 @@ package at.pcgamingfreaks.Minepacks.Bukkit.Command;
|
|||
import at.pcgamingfreaks.Bukkit.Message.Message;
|
||||
import at.pcgamingfreaks.Minepacks.Bukkit.API.MinepacksCommand;
|
||||
import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
|
||||
import at.pcgamingfreaks.PluginLib.Bukkit.PluginLib;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -46,7 +45,10 @@ public class UpdateCommand extends MinepacksCommand
|
|||
public void execute(@NotNull final CommandSender sender, @NotNull String mainCommandAlias, @NotNull String alias, @NotNull String[] args)
|
||||
{
|
||||
messageCheckingForUpdates.send(sender);
|
||||
if(!Minepacks.getInstance().isRunningInStandaloneMode()) ((PluginLib) PluginLib.getInstance()).update(null); // Make the PluginLib check for updates too
|
||||
/*if[STANDALONE]
|
||||
else[STANDALONE]*/
|
||||
((at.pcgamingfreaks.PluginLib.Bukkit.PluginLib) at.pcgamingfreaks.PluginLib.Bukkit.PluginLib.getInstance()).update(null); // Make the PluginLib check for updates too
|
||||
/*end[STANDALONE]*/
|
||||
((Minepacks) plugin).update(result -> {
|
||||
switch(result)
|
||||
{
|
||||
|
|
|
@ -19,7 +19,6 @@ package at.pcgamingfreaks.Minepacks.Bukkit.Command;
|
|||
|
||||
import at.pcgamingfreaks.Minepacks.Bukkit.API.MinepacksCommand;
|
||||
import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
|
||||
import at.pcgamingfreaks.PluginLib.Bukkit.PluginLib;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -38,9 +37,10 @@ public class VersionCommand extends MinepacksCommand
|
|||
{
|
||||
sender.sendMessage("##### Start Minepacks version info #####");
|
||||
sender.sendMessage("Marriage Master: " + plugin.getDescription().getVersion());
|
||||
String pluginLibVersion = "Standalone";
|
||||
if(!Minepacks.getInstance().isRunningInStandaloneMode()) pluginLibVersion = PluginLib.getInstance().getVersion().toString();
|
||||
sender.sendMessage("PCGF PluginLib: " + pluginLibVersion);
|
||||
/*if[STANDALONE]
|
||||
else[STANDALONE]*/
|
||||
sender.sendMessage("PCGF PluginLib: " + at.pcgamingfreaks.PluginLib.Bukkit.PluginLib.getInstance().getVersion());
|
||||
/*end[STANDALONE]*/
|
||||
sender.sendMessage("Server: " + plugin.getServer().getVersion());
|
||||
sender.sendMessage("##### End Minepacks version info #####");
|
||||
}
|
||||
|
|
|
@ -24,8 +24,6 @@ import at.pcgamingfreaks.Minepacks.Bukkit.Backpack;
|
|||
import at.pcgamingfreaks.Minepacks.Bukkit.Database.UnCacheStrategies.OnDisconnect;
|
||||
import at.pcgamingfreaks.Minepacks.Bukkit.Database.UnCacheStrategies.UnCacheStrategie;
|
||||
import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
|
||||
import at.pcgamingfreaks.PluginLib.Bukkit.PluginLib;
|
||||
import at.pcgamingfreaks.PluginLib.Database.DatabaseConnectionPool;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -84,32 +82,25 @@ public abstract class Database implements Listener
|
|||
unCacheStrategie.close();
|
||||
}
|
||||
|
||||
public static DatabaseConnectionPool getSharedDatabaseConnectionPool(Minepacks plugin)
|
||||
{
|
||||
if(plugin.isRunningInStandaloneMode())
|
||||
{
|
||||
plugin.getLogger().warning(ConsoleColor.RED + "The shared database connection option is not available in standalone mode!" + ConsoleColor.RESET);
|
||||
return null;
|
||||
}
|
||||
DatabaseConnectionPool pool = PluginLib.getInstance().getDatabaseConnectionPool();
|
||||
if(pool == null)
|
||||
{
|
||||
plugin.getLogger().warning(ConsoleColor.RED + "The shared connection pool is not initialized correctly!" + ConsoleColor.RESET);
|
||||
return null;
|
||||
}
|
||||
return pool;
|
||||
}
|
||||
|
||||
public static Database getDatabase(Minepacks plugin)
|
||||
{
|
||||
String dbType = plugin.getConfiguration().getDatabaseType().toLowerCase();
|
||||
ConnectionProvider connectionProvider = null;
|
||||
if(dbType.equals("shared") || dbType.equals("external") || dbType.equals("global"))
|
||||
{
|
||||
DatabaseConnectionPool pool = getSharedDatabaseConnectionPool(plugin);
|
||||
if(pool == null) return null;
|
||||
/*if[STANDALONE]
|
||||
plugin.getLogger().warning(ConsoleColor.RED + "The shared database connection option is not available in standalone mode!" + ConsoleColor.RESET);
|
||||
return null;
|
||||
else[STANDALONE]*/
|
||||
at.pcgamingfreaks.PluginLib.Database.DatabaseConnectionPool pool = at.pcgamingfreaks.PluginLib.Bukkit.PluginLib.getInstance().getDatabaseConnectionPool();
|
||||
if(pool == null)
|
||||
{
|
||||
plugin.getLogger().warning(ConsoleColor.RED + "The shared connection pool is not initialized correctly!" + ConsoleColor.RESET);
|
||||
return null;
|
||||
}
|
||||
dbType = pool.getDatabaseType().toLowerCase();
|
||||
connectionProvider = pool.getConnectionProvider();
|
||||
/*end[STANDALONE]*/
|
||||
}
|
||||
Database database;
|
||||
switch(dbType)
|
||||
|
|
|
@ -20,7 +20,6 @@ package at.pcgamingfreaks.Minepacks.Bukkit.Database.Migration;
|
|||
import at.pcgamingfreaks.ConsoleColor;
|
||||
import at.pcgamingfreaks.Minepacks.Bukkit.Database.*;
|
||||
import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
|
||||
import at.pcgamingfreaks.PluginLib.Database.DatabaseConnectionPool;
|
||||
import at.pcgamingfreaks.Reflection;
|
||||
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
@ -109,10 +108,19 @@ public class MigrationManager
|
|||
boolean global = false;
|
||||
if(targetDatabaseType.toLowerCase().equals("external") ||targetDatabaseType.toLowerCase().equals("global") || targetDatabaseType.toLowerCase().equals("shared"))
|
||||
{
|
||||
DatabaseConnectionPool pool = Database.getSharedDatabaseConnectionPool(plugin);
|
||||
if(pool == null) return null;
|
||||
/*if[STANDALONE]
|
||||
plugin.getLogger().warning(ConsoleColor.RED + "The shared database connection option is not available in standalone mode!" + ConsoleColor.RESET);
|
||||
return null;
|
||||
else[STANDALONE]*/
|
||||
at.pcgamingfreaks.PluginLib.Database.DatabaseConnectionPool pool = at.pcgamingfreaks.PluginLib.Bukkit.PluginLib.getInstance().getDatabaseConnectionPool();
|
||||
if(pool == null)
|
||||
{
|
||||
plugin.getLogger().warning(ConsoleColor.RED + "The shared connection pool is not initialized correctly!" + ConsoleColor.RESET);
|
||||
return null;
|
||||
}
|
||||
targetDatabaseType = pool.getDatabaseType().toLowerCase();
|
||||
global = true;
|
||||
/*end[STANDALONE]*/
|
||||
}
|
||||
switch(targetDatabaseType.toLowerCase())
|
||||
{
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
/*
|
||||
* Copyright (C) 2018 GeorgH93
|
||||
* Copyright (C) 2019 GeorgH93
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
|
@ -23,7 +23,6 @@ import at.pcgamingfreaks.Minepacks.Bukkit.Database.MySQL;
|
|||
import at.pcgamingfreaks.Minepacks.Bukkit.Database.SQL;
|
||||
import at.pcgamingfreaks.Minepacks.Bukkit.Database.SQLite;
|
||||
import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
|
||||
import at.pcgamingfreaks.PluginLib.Bukkit.PluginLib;
|
||||
import at.pcgamingfreaks.Reflection;
|
||||
|
||||
import org.intellij.lang.annotations.Language;
|
||||
|
@ -50,10 +49,14 @@ public abstract class ToSQLMigration extends Migration
|
|||
protected final SQL newDb;
|
||||
protected final boolean uuid;
|
||||
|
||||
protected ToSQLMigration(@NotNull Minepacks plugin, @NotNull Database oldDb, @NotNull String dbType, boolean global) throws Exception
|
||||
protected ToSQLMigration(@NotNull Minepacks plugin, @NotNull Database oldDb, @NotNull String dbType, boolean global)
|
||||
{
|
||||
super(plugin, oldDb);
|
||||
ConnectionProvider connectionProvider = (global) ? PluginLib.getInstance().getDatabaseConnectionPool().getConnectionProvider() : null;
|
||||
/*if[STANDALONE]
|
||||
ConnectionProvider connectionProvider = null;
|
||||
else[STANDALONE]*/
|
||||
ConnectionProvider connectionProvider = (global) ? at.pcgamingfreaks.PluginLib.Bukkit.PluginLib.getInstance().getDatabaseConnectionPool().getConnectionProvider() : null;
|
||||
/*end[STANDALONE]*/
|
||||
switch(dbType)
|
||||
{
|
||||
case "mysql": newDb = new MySQL(plugin, connectionProvider); break;
|
||||
|
|
|
@ -18,13 +18,10 @@
|
|||
package at.pcgamingfreaks.Minepacks.Bukkit.Listener;
|
||||
|
||||
import at.pcgamingfreaks.Bukkit.ItemNameResolver;
|
||||
import at.pcgamingfreaks.Bukkit.Language;
|
||||
import at.pcgamingfreaks.Bukkit.MCVersion;
|
||||
import at.pcgamingfreaks.Bukkit.Message.Message;
|
||||
import at.pcgamingfreaks.Bukkit.MinecraftMaterial;
|
||||
import at.pcgamingfreaks.Minepacks.Bukkit.API.Backpack;
|
||||
import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
|
||||
import at.pcgamingfreaks.YamlFileUpdateMethod;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -34,7 +31,6 @@ import org.bukkit.event.inventory.InventoryClickEvent;
|
|||
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||
import org.bukkit.event.inventory.InventoryMoveItemEvent;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
||||
|
@ -59,25 +55,25 @@ public class ItemFilter extends MinepacksListener
|
|||
|
||||
messageNotAllowedInBackpack = plugin.getLanguage().getMessage("Ingame.NotAllowedInBackpack").replaceAll("\\{ItemName}", "%s");
|
||||
|
||||
if(plugin.isRunningInStandaloneMode())
|
||||
/*if[STANDALONE]
|
||||
itemNameResolver = new ItemNameResolver();
|
||||
if (at.pcgamingfreaks.Bukkit.MCVersion.isOlderThan(at.pcgamingfreaks.Bukkit.MCVersion.MC_1_13))
|
||||
{
|
||||
itemNameResolver = new ItemNameResolver();
|
||||
if (MCVersion.isOlderThan(MCVersion.MC_1_13)) {
|
||||
Language itemNameLanguage = new Language(plugin, 1, 1, File.separator + "lang", "items_", "legacy_items_");
|
||||
itemNameLanguage.setFileDescription("item name language");
|
||||
itemNameLanguage.load(plugin.getConfiguration().getLanguage(), YamlFileUpdateMethod.OVERWRITE);
|
||||
itemNameResolver.loadLegacy(itemNameLanguage, plugin.getLogger());
|
||||
} else {
|
||||
Language itemNameLanguage = new Language(plugin, 2, File.separator + "lang", "items_");
|
||||
itemNameLanguage.setFileDescription("item name language");
|
||||
itemNameLanguage.load(plugin.getConfiguration().getLanguage(), YamlFileUpdateMethod.OVERWRITE);
|
||||
itemNameResolver.load(itemNameLanguage, plugin.getLogger());
|
||||
}
|
||||
at.pcgamingfreaks.Bukkit.Language itemNameLanguage = new at.pcgamingfreaks.Bukkit.Language(plugin, 1, 1, java.io.File.separator + "lang", "items_", "legacy_items_");
|
||||
itemNameLanguage.setFileDescription("item name language");
|
||||
itemNameLanguage.load(plugin.getConfiguration().getLanguage(), at.pcgamingfreaks.YamlFileUpdateMethod.OVERWRITE);
|
||||
itemNameResolver.loadLegacy(itemNameLanguage, plugin.getLogger());
|
||||
}
|
||||
else
|
||||
{
|
||||
itemNameResolver = at.pcgamingfreaks.PluginLib.Bukkit.ItemNameResolver.getInstance();
|
||||
at.pcgamingfreaks.Bukkit.Language itemNameLanguage = new at.pcgamingfreaks.Bukkit.Language(plugin, 2, java.io.File.separator + "lang", "items_");
|
||||
itemNameLanguage.setFileDescription("item name language");
|
||||
itemNameLanguage.load(plugin.getConfiguration().getLanguage(), at.pcgamingfreaks.YamlFileUpdateMethod.OVERWRITE);
|
||||
itemNameResolver.load(itemNameLanguage, plugin.getLogger());
|
||||
}
|
||||
else[STANDALONE]*/
|
||||
itemNameResolver = at.pcgamingfreaks.PluginLib.Bukkit.ItemNameResolver.getInstance();
|
||||
/*end[STANDALONE]*/
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
|
|
|
@ -35,7 +35,6 @@ import at.pcgamingfreaks.Minepacks.Bukkit.Listener.BackpackEventListener;
|
|||
import at.pcgamingfreaks.Minepacks.Bukkit.Listener.DisableShulkerboxes;
|
||||
import at.pcgamingfreaks.Minepacks.Bukkit.Listener.DropOnDeath;
|
||||
import at.pcgamingfreaks.Minepacks.Bukkit.Listener.ItemFilter;
|
||||
import at.pcgamingfreaks.PluginLib.Bukkit.PluginLib;
|
||||
import at.pcgamingfreaks.StringUtils;
|
||||
import at.pcgamingfreaks.Updater.UpdateProviders.BukkitUpdateProvider;
|
||||
import at.pcgamingfreaks.Updater.UpdateProviders.JenkinsUpdateProvider;
|
||||
|
@ -60,7 +59,6 @@ public class Minepacks extends JavaPlugin implements MinepacksPlugin
|
|||
private static final int BUKKIT_PROJECT_ID = 83445;
|
||||
private static final String JENKINS_URL = "https://ci.pcgamingfreaks.at", JENKINS_JOB = "Minepacks V2", MIN_PCGF_PLUGIN_LIB_VERSION = "1.0.11-SNAPSHOT";
|
||||
private static Minepacks instance = null;
|
||||
private static boolean standalone = false;
|
||||
|
||||
private Config config;
|
||||
private Language lang;
|
||||
|
@ -68,6 +66,7 @@ public class Minepacks extends JavaPlugin implements MinepacksPlugin
|
|||
|
||||
public Message messageNoPermission, messageInvalidBackpack, messageWorldDisabled, messageNotFromConsole, messageNotANumber;
|
||||
|
||||
private boolean standalone = false;
|
||||
private int maxSize;
|
||||
private Collection<String> worldBlacklist;
|
||||
private WorldBlacklistMode worldBlacklistMode;
|
||||
|
@ -91,24 +90,22 @@ public class Minepacks extends JavaPlugin implements MinepacksPlugin
|
|||
public void onEnable()
|
||||
{
|
||||
// Check if running as standalone edition
|
||||
if(getDescription().getVersion().contains("Standalone"))
|
||||
/*if[STANDALONE]
|
||||
standalone = true;
|
||||
if(getServer().getPluginManager().isPluginEnabled("PCGF_PluginLib"))
|
||||
{
|
||||
standalone = true;
|
||||
if(getServer().getPluginManager().isPluginEnabled("PCGF_PluginLib"))
|
||||
{
|
||||
getLogger().info("You do have the PCGF_PluginLib installed. You may consider switching to the default version of the plugin to reduce memory load and unlock additional features.");
|
||||
}
|
||||
getLogger().info("You do have the PCGF_PluginLib installed. You may consider switching to the default version of the plugin to reduce memory load and unlock additional features.");
|
||||
}
|
||||
else
|
||||
else[STANDALONE]*/
|
||||
// Not standalone so we should check the version of the PluginLib
|
||||
if(at.pcgamingfreaks.PluginLib.Bukkit.PluginLib.getInstance().getVersion().olderThan(new Version(MIN_PCGF_PLUGIN_LIB_VERSION)))
|
||||
{
|
||||
// Not standalone so we should check the version of the PluginLib
|
||||
if(PluginLib.getInstance().getVersion().olderThan(new Version(MIN_PCGF_PLUGIN_LIB_VERSION)))
|
||||
{
|
||||
getLogger().warning("You are using an outdated version of the PCGF PluginLib! Please update it!");
|
||||
setEnabled(false);
|
||||
return;
|
||||
}
|
||||
getLogger().warning("You are using an outdated version of the PCGF PluginLib! Please update it!");
|
||||
setEnabled(false);
|
||||
return;
|
||||
}
|
||||
standalone = false;
|
||||
/*end[STANDALONE]*/
|
||||
|
||||
|
||||
//region Check compatibility with used minecraft version
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
The munge-maven-plugin requiers a test source folder.
|
||||
There currently are no tests so this file is here instead.
|
Loading…
Reference in New Issue