Browse Source

1.5.2

tags/1.5.2
Nazar Kalinowski 9 months ago
parent
commit
09a7b78624
9 changed files with 70 additions and 95 deletions
  1. +1
    -0
      .gitignore
  2. +5
    -0
      CHANGELOG
  3. +2
    -2
      pom.xml
  4. +61
    -57
      src/main/java/dev/gwm/spongeplugin/cosmetics/Cosmetics.java
  5. +0
    -24
      src/main/java/dev/gwm/spongeplugin/cosmetics/command/SaveCommand.java
  6. +0
    -7
      src/main/java/dev/gwm/spongeplugin/cosmetics/util/CosmeticsCommandUtils.java
  7. +1
    -1
      src/main/java/dev/gwm/spongeplugin/cosmetics/util/CosmeticsUtils.java
  8. +0
    -2
      src/main/resources/assets/cosmetics/translations/en_us.conf
  9. +0
    -2
      src/main/resources/assets/cosmetics/translations/ru_ru.conf

+ 1
- 0
.gitignore View File

@@ -1,3 +1,4 @@
.idea/
target/
/dependency-reduced-pom.xml
cosmetics.iml

+ 5
- 0
CHANGELOG View File

@@ -1,3 +1,8 @@
VERSION 1.5.2
* Update to GWMLibrary 2.5.3
* Remove '/cosmetics save' command
* Code refactoring

VERSION 1.5.1
* Update to GWMLibrary 2.5.2
* Rename `utils` package to `util`


+ 2
- 2
pom.xml View File

@@ -6,7 +6,7 @@

<groupId>dev.gwm.spongeplugin</groupId>
<artifactId>cosmetics</artifactId>
<version>1.5.1</version>
<version>1.5.2</version>
<name>Cosmetics</name>
<packaging>jar</packaging>

@@ -33,7 +33,7 @@
<dependency>
<groupId>dev.gwm.spongeplugin</groupId>
<artifactId>library</artifactId>
<version>2.5.2</version>
<version>2.5.3</version>
<scope>provided</scope>
</dependency>
<dependency>


+ 61
- 57
src/main/java/dev/gwm/spongeplugin/cosmetics/Cosmetics.java View File

@@ -1,6 +1,5 @@
package dev.gwm.spongeplugin.cosmetics;
import com.google.inject.Inject;
import dev.gwm.spongeplugin.cosmetics.superobject.effect.*;
import dev.gwm.spongeplugin.cosmetics.superobject.effect.base.CosmeticEffect;
import dev.gwm.spongeplugin.cosmetics.util.CosmeticsCommandUtils;
@@ -13,27 +12,27 @@ import dev.gwm.spongeplugin.library.util.*;
import dev.gwm.spongeplugin.library.util.service.SuperObjectService;
import ninja.leaping.configurate.ConfigurationNode;
import org.slf4j.Logger;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.Game;
import org.spongepowered.api.asset.AssetManager;
import org.spongepowered.api.config.ConfigDir;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.event.cause.EventContext;
import org.spongepowered.api.event.game.GameReloadEvent;
import org.spongepowered.api.event.game.state.GameConstructionEvent;
import org.spongepowered.api.event.game.state.GamePreInitializationEvent;
import org.spongepowered.api.event.game.state.GameStoppingServerEvent;
import org.spongepowered.api.plugin.Dependency;
import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.plugin.PluginContainer;
import javax.inject.Inject;
import java.io.File;
import java.nio.file.Files;
import java.util.concurrent.atomic.AtomicInteger;
@Plugin(id = "cosmetics",
name = "Cosmetics",
version = "1.5.1",
version = "1.5.2",
description = "Fancy cosmetic effects",
authors = {"GWM"/* My contacts:
* E-Mail(nazark@tutanota.com),
@@ -44,7 +43,7 @@ import java.util.concurrent.atomic.AtomicInteger;
})
public class Cosmetics extends SpongePlugin {
public static final Version VERSION = new Version(1, 5, 1);
public static final Version VERSION = new Version(1, 5, 2);
private static Cosmetics instance = null;
@@ -55,60 +54,66 @@ public class Cosmetics extends SpongePlugin {
return instance;
}
private Cause cause;
private final Game game;
private final Cause cause;
@Inject
@ConfigDir(sharedRoot = false)
private File configDirectory;
private File effectsDirectory;
private final Logger logger;
private final PluginContainer container;
@Inject
private Logger logger;
private final File configDirectory;
@Inject
private PluginContainer container;
private final File effectsDirectory;
private Config config;
private Config languageConfig;
private final Config config;
private final Config languageConfig;
private Language language;
private final Language language;
private boolean logLoadedEffects = true;
@Listener
public void onConstruct(GameConstructionEvent event) {
instance = this;
@Inject
public Cosmetics(Game game,
Logger logger,
PluginContainer container,
@ConfigDir(sharedRoot = false) File configDirectory) {
Cosmetics.instance = this;
this.game = game;
cause = Cause.of(EventContext.empty(), container);
this.logger = logger;
this.container = container;
this.configDirectory = configDirectory;
effectsDirectory = new File(configDirectory, "effects");
if (!configDirectory.exists()) {
logger.info("Config directory does not exist! Trying to create it...");
try {
configDirectory.mkdirs();
logger.info("Config directory successfully created!");
} catch (Exception e) {
logger.warn("Failed to create config directory!", e);
}
}
if (!effectsDirectory.exists()) {
logger.info("Cosmetic Effects directory does not exist! Trying to create it...");
try {
effectsDirectory.mkdirs();
logger.info("Cosmetic Effects directory successfully created!");
} catch (Exception e) {
logger.warn("Failed to create Cosmetic Effects config directory!", e);
}
}
config = new Config.Builder(this, new File(configDirectory, "config.conf")).
loadDefaults("config.conf").
build();
languageConfig = new Config.Builder(this, new File(configDirectory, "language.conf")).
loadDefaults(getDefaultTranslationPath()).
build();
language = new Language(this);
logger.info("Construction completed!");
}
@Listener
public void onPreInitialization(GamePreInitializationEvent event) {
effectsDirectory = new File(configDirectory, "effects");
if (!configDirectory.exists()) {
logger.info("Config directory does not exist! Trying to create it...");
try {
configDirectory.mkdirs();
logger.info("Config directory successfully created!");
} catch (Exception e) {
logger.warn("Failed to create config directory!", e);
}
}
if (!effectsDirectory.exists()) {
logger.info("Cosmetic Effects directory does not exist! Trying to create it...");
try {
effectsDirectory.mkdirs();
logger.info("Cosmetic Effects directory successfully created!");
} catch (Exception e) {
logger.warn("Failed to create Cosmetic Effects config directory!", e);
}
}
cause = Cause.of(EventContext.empty(), container);
AssetManager assetManager = Sponge.getAssetManager();
config = new Config(this, new File(configDirectory, "config.conf"),
assetManager.getAsset(this, "config.conf"), true, false);
languageConfig = new Config(this, new File(configDirectory, "language.conf"),
getDefaultTranslation(assetManager), true, false);
loadConfigValues();
language = new Language(this);
CosmeticsCommandUtils.registerCommands(this);
logger.info("PreInitialization completed!");
}
@@ -138,7 +143,7 @@ public class Cosmetics extends SpongePlugin {
@Listener
public void onSuperObjectsRegistration(SuperObjectsRegistrationEvent event) {
loadCpes();
loadCosmeticEffects();
}
@Listener
@@ -149,18 +154,15 @@ public class Cosmetics extends SpongePlugin {
@Listener
public void onStopping(GameStoppingServerEvent event) {
save();
logger.info("Stopping completed!");
}
public void reload() {
cause = Cause.of(EventContext.empty(), container);
config.reload();
languageConfig.reload();
loadConfigValues();
language = new Language(this);
unloadCosmeticEffects();
loadCpes();
loadCosmeticEffects();
logger.info("Plugin has been reloaded.");
}
@@ -173,7 +175,7 @@ public class Cosmetics extends SpongePlugin {
}
}
private void loadCpes() {
private void loadCosmeticEffects() {
try {
AtomicInteger loaded = new AtomicInteger();
AtomicInteger skipped = new AtomicInteger();
@@ -208,7 +210,7 @@ public class Cosmetics extends SpongePlugin {
}
private void unloadCosmeticEffects() {
Sponge.getServiceManager().provide(SuperObjectService.class).get().
game.getServiceManager().provide(SuperObjectService.class).get().
shutdownCreatedSuperObjects(superObject -> superObject instanceof CosmeticEffect);
}
@@ -222,15 +224,16 @@ public class Cosmetics extends SpongePlugin {
return cause;
}
public Logger getLogger() {
return logger;
}
@Override
public PluginContainer getContainer() {
return container;
}
public Logger getLogger() {
return logger;
}
@Override
public File getConfigDirectory() {
return configDirectory;
}
@@ -244,6 +247,7 @@ public class Cosmetics extends SpongePlugin {
return config;
}
@Override
public Config getLanguageConfig() {
return languageConfig;
}


+ 0
- 24
src/main/java/dev/gwm/spongeplugin/cosmetics/command/SaveCommand.java View File

@@ -1,24 +0,0 @@
package dev.gwm.spongeplugin.cosmetics.command;

import dev.gwm.spongeplugin.cosmetics.Cosmetics;
import dev.gwm.spongeplugin.library.util.Language;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.command.args.CommandContext;
import org.spongepowered.api.command.spec.CommandExecutor;

public class SaveCommand implements CommandExecutor {

private final Language language;

public SaveCommand(Language language) {
this.language = language;
}

@Override
public CommandResult execute(CommandSource source, CommandContext args) {
Cosmetics.getInstance().save();
source.sendMessages(language.getTranslation("SUCCESSFULLY_SAVED", source));
return CommandResult.success();
}
}

+ 0
- 7
src/main/java/dev/gwm/spongeplugin/cosmetics/util/CosmeticsCommandUtils.java View File

@@ -3,7 +3,6 @@ package dev.gwm.spongeplugin.cosmetics.util;
import dev.gwm.spongeplugin.cosmetics.Cosmetics;
import dev.gwm.spongeplugin.cosmetics.command.HelpCommand;
import dev.gwm.spongeplugin.cosmetics.command.ReloadCommand;
import dev.gwm.spongeplugin.cosmetics.command.SaveCommand;
import dev.gwm.spongeplugin.library.util.Language;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.spec.CommandSpec;
@@ -25,17 +24,11 @@ public final class CosmeticsCommandUtils {
description(Text.of("Reload the plugin")).
executor(new ReloadCommand(language)).
build();
CommandSpec saveCommand = CommandSpec.builder().
permission("cosmetics.command.save").
description(Text.of("Save the plugin's configs")).
executor(new SaveCommand(language)).
build();
CommandSpec spec = CommandSpec.builder().
permission("cosmetics.command.base").
description(Text.of("The basic command")).
child(helpCommand, "help").
child(reloadCommand, "reload").
child(saveCommand, "save").
build();
Sponge.getCommandManager().register(Cosmetics.getInstance(), spec,
"cosmetics", "cosmetic");


+ 1
- 1
src/main/java/dev/gwm/spongeplugin/cosmetics/util/CosmeticsUtils.java View File

@@ -22,7 +22,7 @@ public class CosmeticsUtils {

public static boolean loadCosmeticEffect(File file, boolean force) {
try {
Config cosmeticEffectConfig = new Config(Cosmetics.getInstance(), file);
Config cosmeticEffectConfig = new Config.Builder(Cosmetics.getInstance(), file).build();
ConfigurationNode loadNode = cosmeticEffectConfig.getNode("LOAD");
if (force || loadNode.getBoolean(true)) {
CosmeticEffect cosmeticEffect = Sponge.getServiceManager().provide(SuperObjectService.class).get().


+ 0
- 2
src/main/resources/assets/cosmetics/translations/en_us.conf View File

@@ -8,7 +8,5 @@ HELP_MESSAGE: [
${VERSION},
"&a/cosmetics help &c- &bshow this message",
"&a/cosmetics reload &c- &breload the plugin",
"&a/cosmetics save &c- &bsave the plugin's configs",
]
SUCCESSFULLY_RELOADED: "&aSuccessfully reloaded Cosmetics&0!"
SUCCESSFULLY_SAVED: "&aAll configs successfully saved&0!"

+ 0
- 2
src/main/resources/assets/cosmetics/translations/ru_ru.conf View File

@@ -8,7 +8,5 @@ HELP_MESSAGE: [
${VERSION},
"&a/cosmetics help &c- &bпоказать список команд",
"&a/cosmetics reload &c- &bперезагрузить плагин",
"&a/cosmetics save &c- &bсохранить конфиги",
]
SUCCESSFULLY_RELOADED: "&aCosmetics успешно пезагружен&0!"
SUCCESSFULLY_SAVED: "&aВсе конфиги сохранены&0!"

Loading…
Cancel
Save