mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
Fix file saving and channel redundancy
This commit is contained in:
1 parent
0a76cad4f7
commit
9c4187124a
2 files changed
+40
-41
No files matched your search
@@ -17,30 +17,30 @@ import java.util.Map;
|
||||
public class ChannelOptions {
|
||||
|
||||
@Setting private String key = "channel";
|
||||
@Setting private String color = "#FFFFFF";
|
||||
@Setting private String color;
|
||||
@Setting private Map<String, Context> contexts = new HashMap<>(); // TODO: set defaults
|
||||
@Setting private Map<String, String> formats = new HashMap<>(); // TODO: set defaults
|
||||
@Setting private String defaultFormatName = "default";
|
||||
@Setting private String defaultFormatName;
|
||||
@Setting private boolean isDefault = false; // primitive because missing = false
|
||||
@Setting private Boolean ignorable = true; // boxed because missing = use defaults
|
||||
@Setting private Boolean crossServer = true;
|
||||
@Setting private Boolean honorsRecipientList = false;
|
||||
@Setting private Boolean permissionGroupMatching = false;
|
||||
@Setting private List<String> groupOverrides = new ArrayList<>();
|
||||
@Setting private Boolean ignorable; // boxed because missing = use defaults
|
||||
@Setting private Boolean crossServer;
|
||||
@Setting private Boolean honorsRecipientList;
|
||||
@Setting private Boolean permissionGroupMatching;
|
||||
@Setting private List<String> groupOverrides;
|
||||
@Setting private String name = "";
|
||||
@Setting private String messagePrefix = "";
|
||||
@Setting private List<String> aliases = new ArrayList<>();
|
||||
@Setting private Boolean shouldCancelChatEvent = false;
|
||||
@Setting private Boolean primaryGroupOnly = false;
|
||||
@Setting private String switchMessage = "<gray>You are now in <color><channel> <gray>chat!";
|
||||
@Setting private String switchOtherMessage = "<gray><player> <reset><gray>is now in <color><channel> <gray>chat!";
|
||||
@Setting private String switchFailureMessage = "<red>You cannot use channel <channel>!";
|
||||
@Setting private String toggleOnMessage = "<gray>You can now see <color><channel> <gray>chat!";
|
||||
@Setting private String toggleOffMessage = "<gray>You can no longer see <color><channel> <gray>chat!";
|
||||
@Setting private String toggleOtherOnMessage = "<gray><player> <reset><gray>can now see <color><channel> <gray>chat!";
|
||||
@Setting private String toggleOtherOffMessage = "<gray><player> <reset><gray>can no longer see <color><channel> <gray>chat!";
|
||||
@Setting private String cannotUseMessage = "You cannot use that channel!";
|
||||
@Setting private String cannotIgnoreMessage = "<red>You cannot ignore that channel!";
|
||||
@Setting private Boolean shouldCancelChatEvent;
|
||||
@Setting private Boolean primaryGroupOnly;
|
||||
@Setting private String switchMessage;
|
||||
@Setting private String switchOtherMessage;
|
||||
@Setting private String switchFailureMessage;
|
||||
@Setting private String toggleOnMessage;
|
||||
@Setting private String toggleOffMessage;
|
||||
@Setting private String toggleOtherOnMessage;
|
||||
@Setting private String toggleOtherOffMessage;
|
||||
@Setting private String cannotUseMessage;
|
||||
@Setting private String cannotIgnoreMessage;
|
||||
|
||||
private SharedChannelOptions defaultOptions() {
|
||||
return CarbonChatProvider.carbonChat().channelSettings().defaultChannelOptions();
|
||||
|
||||
@@ -235,67 +235,77 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
|
||||
private void loadCarbonSettings() {
|
||||
try {
|
||||
final CommentedConfigurationNode node =
|
||||
final HoconConfigurationLoader loader =
|
||||
this.loadConfigFile("config.conf", false);
|
||||
final CommentedConfigurationNode node = loader.load();
|
||||
|
||||
this.carbonSettings = CarbonSettings.loadFrom(node);
|
||||
} catch (final ObjectMappingException exception) {
|
||||
loader.save(node);
|
||||
} catch (final ObjectMappingException | IOException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void loadLanguage() {
|
||||
try {
|
||||
final CommentedConfigurationNode node =
|
||||
final HoconConfigurationLoader loader =
|
||||
this.loadConfigFile("language.conf", false);
|
||||
final CommentedConfigurationNode node = loader.load();
|
||||
|
||||
this.translations = CarbonTranslations.loadFrom(node);
|
||||
} catch (final ObjectMappingException exception) {
|
||||
loader.save(node);
|
||||
} catch (final ObjectMappingException | IOException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void loadModerationSettings() {
|
||||
try {
|
||||
final CommentedConfigurationNode node =
|
||||
final HoconConfigurationLoader loader =
|
||||
this.loadConfigFile("moderation.conf", false);
|
||||
final CommentedConfigurationNode node = loader.load();
|
||||
|
||||
this.moderationSettings = ModerationSettings.loadFrom(node);
|
||||
} catch (final ObjectMappingException exception) {
|
||||
loader.save(node);
|
||||
} catch (final ObjectMappingException | IOException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void loadCommandSettings() {
|
||||
try {
|
||||
final CommentedConfigurationNode node =
|
||||
final HoconConfigurationLoader loader =
|
||||
this.loadConfigFile("carbonCommands.conf", true);
|
||||
final CommentedConfigurationNode node = loader.load();
|
||||
|
||||
this.commandSettings = CommandSettingsRegistry.loadFrom(node);
|
||||
} catch (final ObjectMappingException exception) {
|
||||
loader.save(node);
|
||||
} catch (final ObjectMappingException | IOException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void loadChannelSettings() {
|
||||
try {
|
||||
final CommentedConfigurationNode node =
|
||||
final HoconConfigurationLoader loader =
|
||||
this.loadConfigFile("channels.conf", false);
|
||||
final CommentedConfigurationNode node = loader.load();
|
||||
|
||||
this.channelSettings = ChannelSettings.loadFrom(node);
|
||||
} catch (final ObjectMappingException exception) {
|
||||
loader.save(node);
|
||||
} catch (final ObjectMappingException | IOException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private CommentedConfigurationNode loadConfigFile(final String fileName, final boolean saveResource) {
|
||||
private HoconConfigurationLoader loadConfigFile(final String fileName, final boolean saveResource) {
|
||||
final File configFile = new File(this.getDataFolder(), fileName);
|
||||
|
||||
if (!(configFile.exists()) && saveResource) {
|
||||
this.saveResource(fileName, false);
|
||||
}
|
||||
|
||||
final HoconConfigurationLoader configLoader = HoconConfigurationLoader.builder()
|
||||
return HoconConfigurationLoader.builder()
|
||||
.setDefaultOptions(opts -> {
|
||||
return opts.withShouldCopyDefaults(true).withSerializers(builder -> {
|
||||
builder.register(Key.class, KeySerializer.INSTANCE)
|
||||
@@ -304,17 +314,6 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
})
|
||||
.setFile(configFile)
|
||||
.build();
|
||||
|
||||
try {
|
||||
final CommentedConfigurationNode configNode = configLoader.load();
|
||||
configLoader.save(configNode);
|
||||
|
||||
return configNode;
|
||||
} catch (final IOException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void registerContexts() {
|
||||
|
||||
Reference in new issue
Block a user