Skip to content

Commit ff73b40

Browse files
committed
Several changes
Removed permission argument from CosmeticType constructors Fix christmas tree bug Move Hikari support to separate module to run on Java 11 Add auto-update Run update checker even if UltraCosmetics fails to enable Provide reason for load fail when using /uc
1 parent 1a93373 commit ff73b40

25 files changed

Lines changed: 461 additions & 249 deletions

.github/workflows/gradle.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ jobs:
2222
run: java -jar BuildTools.jar --rev 1.12.2
2323
- name: Build MC 1.16.5
2424
run: java -jar BuildTools.jar --rev 1.16.5
25+
- name: Set up JDK 11 for Hikari
26+
uses: actions/setup-java@v2
27+
with:
28+
distribution: temurin
29+
java-version: 11
2530
- name: Set up JDK 16
2631
uses: actions/setup-java@v2
2732
with:

build.gradle

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ allprojects {
44
apply plugin: 'idea'
55

66
group = 'be.isach'
7-
version = '2.6.3-DEV-b2'
7+
version = '2.6.3-DEV-b3'
88

99
compileJava.options.encoding = 'UTF-8'
1010

@@ -52,7 +52,10 @@ dependencies {
5252
if (p.name.equals("core")) {
5353
shaded(project(path: ':core', configuration: 'shadow'))
5454
return;
55-
}
55+
} else if (p.name.equals("hikari")) {
56+
shaded(project(path: ':hikari', configuration: 'shadow'))
57+
return;
58+
}
5659
shaded(p) {
5760
transitive false
5861
}
@@ -106,9 +109,9 @@ subprojects { subproj ->
106109
url 'https://jitpack.io'
107110
}
108111

109-
// Mojang Authlib
112+
// Mojang Authlib
110113
maven {
111-
url 'https://libraries.minecraft.net'
114+
url 'https://libraries.minecraft.net'
112115
}
113116
}
114117
def version = 8

core/build.gradle

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@ dependencies {
2020
compileOnly 'com.mojang:authlib:2.3.31'
2121
// used by the update checker
2222
compileOnly 'com.googlecode.json-simple:json-simple:1.1.1'
23-
// hikari requires slf4j, this attaches it to log4j
24-
implementation ('org.apache.logging.log4j:log4j-slf4j18-impl:2.17.2') {
25-
exclude group: 'org.apache.logging.log4j', module: 'log4j-api'
26-
exclude group: 'org.apache.logging.log4j', module: 'log4j-core'
27-
}
28-
// versions above 4.0.3 are compiled with Java 11 so we can't use them
29-
implementation 'com.zaxxer:HikariCP:4.0.3'
3023
// NMS modules can't actually use XSeries but it doesn't compile without 'api'.
3124
// IDEs do not like it when 'core' references XSeries directly
3225
// but subprojects must reference XSeries as shaded.
@@ -41,11 +34,6 @@ shadowJar {
4134
// XParticle is big and not required so don't shade it.
4235
// It's not removed by minimize() because it's on the API path I guess?
4336
exclude 'com/cryptomorin/xseries/particles/*'
44-
// I'd like to relocate everything but slf4j breaks when relocated.
45-
// I think it has something to do with META-INF/services/org.slf4j.spi.SLF4JServiceProvider
46-
//relocate ('org.slf4j', path + '.slf4j')
47-
//relocate ('org.apache.logging.slf4j', path + '.log4j-slf4j')
48-
relocate ('com.zaxxer.hikari', path + '.hikari')
4937
relocate ('com.cryptomorin.xseries', path + '.xseries')
5038
relocate ('org.bstats', path + '.metrics')
5139
}

core/src/main/java/be/isach/ultracosmetics/CosmeticManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public void setupCosmeticsConfigs() {
106106
setupCategory(config, ParticleEffectType.values());
107107

108108
try {
109-
config.save(ultraCosmetics.getFile());
109+
config.save(ultraCosmetics.getConfigFile());
110110
} catch (IOException e) {
111111
e.printStackTrace();
112112
}
@@ -123,7 +123,7 @@ public void setupCosmeticsConfigs() {
123123
}
124124

125125
try {
126-
config.save(ultraCosmetics.getFile());
126+
config.save(ultraCosmetics.getConfigFile());
127127
// for any default descriptions saved
128128
MessageManager.save();
129129
} catch (IOException e) {

core/src/main/java/be/isach/ultracosmetics/UltraCosmetics.java

Lines changed: 57 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ public class UltraCosmetics extends JavaPlugin {
122122

123123
private boolean legacyMessagePrinted = false;
124124
private boolean enableFinished = false;
125+
126+
/**
127+
* Stores the reason plugin load failed, if any.
128+
*/
129+
private String failReason = null;
125130

126131
/**
127132
* Called when plugin is loaded.
@@ -135,7 +140,8 @@ public void onLoad() {
135140

136141
UltraCosmeticsData.init(this);
137142

138-
if (!UltraCosmeticsData.get().checkServerVersion()) {
143+
failReason = UltraCosmeticsData.get().checkServerVersion();
144+
if (failReason != null) {
139145
return;
140146
}
141147

@@ -167,41 +173,51 @@ public void onLoad() {
167173
*/
168174
@Override
169175
public void onEnable() {
170-
// if loading failed...
176+
// Enable command manager as early as possible
177+
// so we can print helpful error messages about
178+
// why the plugin didn't start correctly.
179+
commandManager = new CommandManager(this);
180+
// Set up config.
181+
if (!setUpConfig()) {
182+
getSmartLogger().write(LogLevel.ERROR, "Failed to load config.yml, shutting down to protect data.");
183+
failReason = "Failed to load config.yml, please run it through a YAML checker";
184+
return;
185+
}
186+
187+
// Start update checker ASAP so if there's a problem that can be
188+
// resolved by updating, the user knows there's an update.
189+
// (We can't start it before the config loader because we need config settings.)
190+
if (SettingsManager.getConfig().getBoolean("Check-For-Updates")) {
191+
getSmartLogger().write("Checking for update...");
192+
updateChecker = new UpdateManager(this);
193+
updateChecker.runTaskAsynchronously(this);
194+
}
195+
196+
// if early loading failed...
171197
if (UltraCosmeticsData.get().getServerVersion() == null) {
172198
getSmartLogger().write(LogLevel.ERROR, "Plugin load has failed, please check earlier in the log for details.");
173-
Bukkit.getPluginManager().disablePlugin(this);
174199
return;
175200
}
176201
// Create UltraPlayer Manager.
177202
this.playerManager = new UltraPlayerManager(this);
178203

179-
this.armorStandManager = new ArmorStandManager(this);
180-
181204
// Beginning of boot log. basic informations.
182205
getSmartLogger().write("-------------------------------------------------------------------");
183206
getSmartLogger().write("UltraCosmetics v" + getDescription().getVersion() + " is loading... (server: " + UltraCosmeticsData.get().getServerVersion().getName() + ")");
184207
getSmartLogger().write("Thanks for downloading it!");
185208
getSmartLogger().write("Plugin by iSach.");
186209
getSmartLogger().write("Link: http://bit.ly/UltraCosmetics");
187210

188-
// Set up config.
189-
if (!setUpConfig()) {
190-
getSmartLogger().write(LogLevel.ERROR, "Failed to load config.yml, shutting down to protect data.");
191-
getServer().getPluginManager().disablePlugin(this);
192-
return;
193-
}
194-
195211
// Initialize NMS Module
196212
if (!UltraCosmeticsData.get().initModule()) {
197-
getServer().getPluginManager().disablePlugin(this);
213+
failReason = "Failed to load NMS module";
198214
return;
199215
}
200216

201217
// Init Message manager.
202218
if (!MessageManager.success()) {
203219
getSmartLogger().write(LogLevel.ERROR, "Failed to load messages.yml, shutting down to protect data.");
204-
getServer().getPluginManager().disablePlugin(this);
220+
failReason = "Failed to load messages.yml, please run it through a YAML checker";
205221
return;
206222
}
207223

@@ -211,8 +227,7 @@ public void onEnable() {
211227
// Register Listeners.
212228
registerListeners();
213229

214-
// Register the command
215-
commandManager = new CommandManager(this);
230+
// Register the command pt. 2
216231
commandManager.registerCommands(this);
217232

218233
UltraCosmeticsData.get().initConfigFields();
@@ -246,11 +261,15 @@ public void onEnable() {
246261
getSmartLogger().write("Connecting to MySQL database...");
247262

248263
// Start MySQL.
249-
this.mySqlConnectionManager = new MySqlConnectionManager(this);
250-
mySqlConnectionManager.start();
251-
252-
getSmartLogger().write("Connected to MySQL database.");
253-
} else {
264+
mySqlConnectionManager = new MySqlConnectionManager(this);
265+
if (mySqlConnectionManager.success()) {
266+
mySqlConnectionManager.start();
267+
getSmartLogger().write("Connected to MySQL database.");
268+
}
269+
}
270+
// This might seem redundant, but MySQLConnectionManager
271+
// forcefully switches to file storage if it fails to connect.
272+
if (UltraCosmeticsData.get().usingFileStorage()) {
254273
// Initialize UltraPlayers and give chest (if needed).
255274
// Only actually does anything when the plugin is reloaded or loaded REALLY late.
256275
// MySQL manager handles this when active.
@@ -265,6 +284,7 @@ public void onEnable() {
265284
if (!config.getStringList("Enabled-Worlds").contains("*")) {
266285
new InvalidWorldChecker(this).runTaskTimerAsynchronously(this, 0, 5);
267286
}
287+
armorStandManager = new ArmorStandManager(this);
268288

269289
// Start up bStats
270290
new Metrics(this, 2629);
@@ -277,11 +297,6 @@ public void onEnable() {
277297
e.printStackTrace();
278298
}
279299

280-
if (SettingsManager.getConfig().getBoolean("Check-For-Updates")) {
281-
updateChecker = new UpdateManager(this);
282-
updateChecker.runTaskAsynchronously(this);
283-
}
284-
285300
PermissionPrinter.printPermissions(this);
286301

287302
// Ended well :v
@@ -301,7 +316,7 @@ public void onDisable() {
301316
return;
302317
}
303318

304-
if (mySqlConnectionManager != null) {
319+
if (mySqlConnectionManager != null && mySqlConnectionManager.success()) {
305320
mySqlConnectionManager.shutdown();
306321
}
307322

@@ -525,6 +540,7 @@ else if (max < 15)
525540
List<String> airMaterials = new ArrayList<>();
526541
Arrays.asList(XMaterial.AIR, XMaterial.CAVE_AIR, XMaterial.VOID_AIR, XMaterial.LIGHT).forEach(k -> airMaterials.add(k.name()));
527542
config.addDefault("Air-Materials", airMaterials, "Materials that are treated as air. Changing these is not recommended.");
543+
config.addDefault("Auto-Update", false, "Whether UltraCosmetics should automatically download and install new versions.", "Requires Check-For-Updates to be enabled.");
528544

529545
upgradeIdsToMaterials();
530546

@@ -554,10 +570,17 @@ public CommandManager getCommandManager() {
554570
}
555571

556572
/**
557-
* @return Overwrites getFile to return our own File.
573+
* Increase visibility of getFile() for Updater
558574
*/
559575
@Override
560576
public File getFile() {
577+
return super.getFile();
578+
}
579+
580+
/**
581+
* @return Config file
582+
*/
583+
public File getConfigFile() {
561584
return file;
562585
}
563586

@@ -719,6 +742,8 @@ private void upgradeIdsToMaterials() {
719742
upgradeKeyToMaterial("TreasureChests.Designs.Nether.third-blocks", "87:0", XMaterial.NETHERRACK);
720743
upgradeKeyToMaterial("TreasureChests.Designs.Nether.below-chests", "112:0", XMaterial.NETHER_BRICKS);
721744
upgradeKeyToMaterial("TreasureChests.Designs.Nether.barriers", "113:0", XMaterial.NETHER_BRICK_FENCE);
745+
746+
upgradeKeyToMaterial("Fill-Blank-Slots-With-Item.Item", "160:15", XMaterial.BLACK_STAINED_GLASS_PANE);
722747
}
723748

724749
private void upgradeKeyToMaterial(String key, String oldValue, XMaterial newValue) {
@@ -736,6 +761,10 @@ private void upgradeKeyToMaterial(String key, String oldValue, XMaterial newValu
736761
}
737762
}
738763

764+
public String getFailReason() {
765+
return failReason;
766+
}
767+
739768
// has to be outside AFlagManager because AFlagManager cannot load if WorldGuard is not present
740769
public enum CosmeticRegionState {
741770
BLOCKED_ALL,

core/src/main/java/be/isach/ultracosmetics/UltraCosmeticsData.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,19 @@ boolean initModule() {
131131
return false;
132132
}
133133

134-
boolean checkServerVersion() {
134+
/**
135+
* Checks to make sure UC is OK to run on this MC version
136+
* @return the reason the check failed, or null if it succeeded.
137+
*/
138+
String checkServerVersion() {
135139
String versionString = Bukkit.getServer().getClass().getPackage().getName();
136140
String mcVersion;
137141
try {
138142
mcVersion = versionString.split("\\.")[3];
139143
} catch (ArrayIndexOutOfBoundsException e) {
140144
ultraCosmetics.getSmartLogger().write(LogLevel.ERROR, "Unable to determine server version. Please report this error.");
141145
ultraCosmetics.getSmartLogger().write(LogLevel.ERROR, "Version string: " + versionString);
142-
return false;
146+
return "Unable to determine server version";
143147
}
144148

145149
ServerVersion serverVersion;
@@ -158,13 +162,12 @@ boolean checkServerVersion() {
158162
ultraCosmetics.getSmartLogger().write(LogLevel.ERROR, "ULTRACOSMETICS CAN ONLY RUN ON " + sj.toString() + ", OR " + ServerVersion.latest().getName() + "!");
159163
ultraCosmetics.getSmartLogger().write(LogLevel.ERROR, "");
160164
ultraCosmetics.getSmartLogger().write(LogLevel.ERROR, "----------------------------");
161-
// plugin can't be disabled at load time since it hasn't been enabled yet?
162-
return false;
165+
return "Unsupported MC version";
163166
}
164167

165168
setServerVersion(serverVersion);
166169

167-
return true;
170+
return null;
168171
}
169172

170173
boolean checkMappingsVersion(ServerVersion version) {
@@ -253,4 +256,8 @@ public UltraCosmetics getPlugin() {
253256
public boolean areCosmeticsProfilesEnabled() {
254257
return cosmeticsProfilesEnabled;
255258
}
259+
260+
public void setFileStorage(boolean fileStorage) {
261+
this.fileStorage = fileStorage;
262+
}
256263
}

core/src/main/java/be/isach/ultracosmetics/command/CommandManager.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ public class CommandManager implements CommandExecutor {
2424
/**
2525
* List of the registered commands.
2626
*/
27-
private List<SubCommand> commands = new ArrayList<>();
27+
private final List<SubCommand> commands = new ArrayList<>();
28+
private final UltraCosmetics ultraCosmetics;
2829

2930
public CommandManager(UltraCosmetics ultraCosmetics) {
3031
PluginCommand cmd = ultraCosmetics.getCommand("ultracosmetics");
3132
cmd.setExecutor(this);
3233
cmd.setTabCompleter(new UCTabCompleter(ultraCosmetics));
34+
this.ultraCosmetics = ultraCosmetics;
3335
}
3436

3537
/**
@@ -72,6 +74,11 @@ private int getMaxPages() {
7274

7375
@Override
7476
public boolean onCommand(CommandSender sender, Command command, String label, String[] arguments) {
77+
if (ultraCosmetics.getFailReason() != null) {
78+
sender.sendMessage(ChatColor.RED + "Plugin is currently disabled because: " + ultraCosmetics.getFailReason());
79+
return true;
80+
}
81+
7582
if (arguments.length == 0) {
7683
showHelp(sender, 1);
7784
return true;

core/src/main/java/be/isach/ultracosmetics/command/subcommands/SubCommandMigrate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected void onExeNotPlayer(CommandSender sender, String[] args) {
3939
error(sender, "This command can only be used from the console.");
4040
return;
4141
}
42-
if (UltraCosmeticsData.get().usingFileStorage() || !ultraCosmetics.getMySqlConnectionManager().success()) {
42+
if (UltraCosmeticsData.get().usingFileStorage()) {
4343
error(sender, "SQL must be enabled and connected to migrate either direction.");
4444
return;
4545
}

core/src/main/java/be/isach/ultracosmetics/cosmetics/gadgets/GadgetChristmasTree.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private void drawSnow() {
5656

5757
@Override
5858
protected boolean checkRequirements(PlayerInteractEvent event) {
59-
if (event.getAction() != Action.RIGHT_CLICK_BLOCK || event.getAction() != Action.LEFT_CLICK_BLOCK) {
59+
if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.LEFT_CLICK_BLOCK) {
6060
getPlayer().sendMessage(MessageManager.getMessage("Gadgets.ChristmasTree.Click-On-Block"));
6161
return false;
6262
}

core/src/main/java/be/isach/ultracosmetics/cosmetics/type/CosmeticEntType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public abstract class CosmeticEntType<T extends Cosmetic<?>> extends CosmeticTyp
1919

2020
private final EntityType entityType;
2121

22-
public CosmeticEntType(Category category, String configName, String permission, String description, XMaterial material, EntityType entityType, Class<? extends T> clazz) {
22+
public CosmeticEntType(Category category, String configName, String description, XMaterial material, EntityType entityType, Class<? extends T> clazz) {
2323
super(category, configName, description, material, clazz);
2424
this.entityType = entityType;
2525
}

0 commit comments

Comments
 (0)