diff --git a/build.gradle b/build.gradle
index d8eee18..53ace68 100644
--- a/build.gradle
+++ b/build.gradle
@@ -27,6 +27,7 @@ buildscript {
classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT'
classpath "org.spongepowered:SpongeGradle:0.11.5"
classpath "gradle.plugin.net.minecrell:licenser:0.4.1"
+ classpath "net.kyori:blossom:1.+"
}
}
@@ -42,11 +43,22 @@ applyPlugin('com.github.johnrengelman.shadow')
applyPlugin('net.minecrell.licenser')
applyPlugin('org.spongepowered.mixin')
applyPlugin('org.spongepowered.gradle.plugin')
+applyPlugin('net.kyori.blossom')
group = "${getProjectProperty('m_group')}" as Object
version = "${getProjectProperty('minecraft_version')}-${getProjectProperty('m_major')}.${getProjectProperty('m_minor')}-${getProjectProperty('m_api')}-${getProjectProperty('m_suffix')}" as Object
description = "${getProjectProperty('m_description')}"
+blossom {
+ replaceToken("@version@", "${getProjectProperty('m_major')}.${getProjectProperty('m_minor')}")
+ replaceToken("@description@", description)
+ replaceToken("@id@", m_id)
+ replaceToken("@name@", m_name)
+ replaceToken("@organization@", m_organization)
+ replaceToken("@authors@", m_authors)
+ replaceToken("@url@", m_url)
+}
+
if (System.getenv().BUILD_NUMBER != null) {
version += "+${System.getenv().BUILD_NUMBER}"
}
diff --git a/gradle.properties b/gradle.properties
index 21b5691..e6e9837 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -18,17 +18,14 @@ m_description=Core plugin for all of my Nyx plugins.
## Version
m_major=1
-m_minor=1
-m_api=S7.3.0
+m_minor=5
+m_api=S7.4
m_suffix=STABLE
## Dependencies
-spongeapi=7.3.0
-##spongeforge=7.1.6
-##spongeforgeServerFolder=run/spongeforge
-
+spongeapi=7.4.+
minecraft_version=1.12.2
forge_rundir=run/forge
-forgeVersion=1.12.2-14.23.5.2854
+forgeVersion=1.12.2-14.23.5.2860
mappings_channel=snapshot
mappings_version=20180814-1.12
\ No newline at end of file
diff --git a/src/main/java/io/github/poqdavid/nyx/nyxcore/NyxCore.java b/src/main/java/io/github/poqdavid/nyx/nyxcore/NyxCore.java
index e14a873..7a28add 100644
--- a/src/main/java/io/github/poqdavid/nyx/nyxcore/NyxCore.java
+++ b/src/main/java/io/github/poqdavid/nyx/nyxcore/NyxCore.java
@@ -22,10 +22,12 @@
import com.google.inject.Inject;
import io.github.poqdavid.nyx.nyxcore.Permissions.BackpackPermission;
+import io.github.poqdavid.nyx.nyxcore.Permissions.MarketPermission;
import io.github.poqdavid.nyx.nyxcore.Permissions.ToolsPermission;
import io.github.poqdavid.nyx.nyxcore.Utils.CText;
import io.github.poqdavid.nyx.nyxcore.Utils.NCLogger;
-import io.github.poqdavid.nyx.nyxcore.Utils.Setting.NyxTools.Settings;
+import io.github.poqdavid.nyx.nyxcore.Utils.Setting.NyxMarket.NMSettings;
+import io.github.poqdavid.nyx.nyxcore.Utils.Setting.NyxTools.NTSettings;
import org.bstats.sponge.Metrics;
import org.slf4j.Logger;
import org.spongepowered.api.Game;
@@ -48,7 +50,7 @@
import java.nio.file.Paths;
import java.util.Optional;
-@Plugin(id = PluginData.id, name = PluginData.name, version = PluginData.version, description = PluginData.description, url = PluginData.url, authors = {PluginData.author1})
+@Plugin(id = "nyxcore", name = "@name@", version = "@version@", description = "@description@", url = "https://github.com/poqdavid/NyxCore", authors = {"@authors@"})
public class NyxCore {
public static NyxCore nyxcore;
@@ -58,13 +60,16 @@ public class NyxCore {
private final Path backpackDir;
private final Path toolsDir;
private final Path backpacksDir;
+ private final Path effectDir;
+ private final Path marketDir;
private final PluginContainer pluginContainer;
private final Metrics metrics;
public NCLogger logger;
public PermissionService permService;
public PermissionDescription.Builder permDescBuilder;
public Path recordsDir;
- public Settings nytSettings;
+ public NTSettings nytSettings;
+ public NMSettings nmSettings;
@Inject
private Game game;
private CommandManager cmdManager;
@@ -72,19 +77,23 @@ public class NyxCore {
@Inject
public NyxCore(Metrics.Factory metricsFactory, @ConfigDir(sharedRoot = true) Path path, Logger logger, PluginContainer container) {
nyxcore = this;
- this.dataDir = Sponge.getGame().getSavesDirectory().resolve(PluginData.id);
this.pluginContainer = container;
+
+ this.dataDir = Sponge.getGame().getSavesDirectory().resolve(this.getPluginContainer().getId());
+
this.logger = new NCLogger();
- this.nytSettings = new Settings();
- this.configDirPath = path.resolve(PluginData.shortName);
+ this.nytSettings = new NTSettings();
+ this.nmSettings = new NMSettings();
+ this.configDirPath = path.resolve("Nyx");
this.configFullPath = Paths.get(this.getConfigPath().toString(), "config.json");
this.backpackDir = Paths.get(this.getConfigPath().toString(), "NyxBackpack");
this.toolsDir = Paths.get(this.getConfigPath().toString(), "NyxTools");
this.backpacksDir = Paths.get(this.backpackDir.toString(), "backpacks");
-
+ this.effectDir = Paths.get(this.getConfigPath().toString(), "NyxEffect");
+ this.marketDir = Paths.get(this.getConfigPath().toString(), "NyxMarket");
this.logger.info(" ");
- this.logger.info(CText.get(CText.Colors.MAGENTA, 0, "NyxCore") + CText.get(CText.Colors.YELLOW, 0, " v" + PluginData.version));
+ this.logger.info(CText.get(CText.Colors.MAGENTA, 0, "@name@") + CText.get(CText.Colors.YELLOW, 0, " v" + this.getVersion()));
this.logger.info("Starting...");
this.logger.info(" ");
@@ -117,6 +126,16 @@ public Path getBackpacksPath() {
return this.backpacksDir;
}
+ @Nonnull
+ public Path getEffectPath() {
+ return this.effectDir;
+ }
+
+ @Nonnull
+ public Path getMarketPath() {
+ return this.marketDir;
+ }
+
@Nonnull
public PluginContainer getPluginContainer() {
return this.pluginContainer;
@@ -124,14 +143,23 @@ public PluginContainer getPluginContainer() {
@Nonnull
public String getVersion() {
- return PluginData.version;
+ if (this.getPluginContainer().getVersion().isPresent()) {
+ return this.getPluginContainer().getVersion().get();
+ } else {
+ return "@version@";
+ }
}
@Nonnull
- public Settings getToolsSettings() {
+ public NTSettings getToolsSettings() {
return this.nytSettings;
}
+ @Nonnull
+ public NMSettings getMarketSettings() {
+ return this.nmSettings;
+ }
+
@Nonnull
public NCLogger getLogger(String name) {
if (name == null || name.isEmpty()) {
@@ -154,7 +182,7 @@ public void setGame(Game game) {
@Listener
public void onGamePreInit(@Nullable final GamePreInitializationEvent event) {
this.logger.info(" ");
- this.logger.info(CText.get(CText.Colors.MAGENTA, 0, "NyxCore") + CText.get(CText.Colors.YELLOW, 0, " v" + PluginData.version));
+ this.logger.info(CText.get(CText.Colors.MAGENTA, 0, "@name@") + CText.get(CText.Colors.YELLOW, 0, " v" + this.getVersion()));
this.logger.info("Initializing...");
this.logger.info(" ");
nyxcore = this;
@@ -415,6 +443,93 @@ public void onGameInit(@Nullable final GameInitializationEvent event) {
.assign(PermissionDescription.ROLE_STAFF, true)
.assign(PermissionDescription.ROLE_ADMIN, true)
.register();
+
+ //Market
+ this.permDescBuilder
+ .id(MarketPermission.COMMAND_HELP)
+ .description(Text.of("Allows the use of help command"))
+ .assign(PermissionDescription.ROLE_USER, true)
+ .assign(PermissionDescription.ROLE_STAFF, true)
+ .assign(PermissionDescription.ROLE_ADMIN, true)
+ .register();
+ this.permDescBuilder
+ .id(MarketPermission.COMMAND_MAIN)
+ .description(Text.of("Allows the use of /sm, /NyxMarket"))
+ .assign(PermissionDescription.ROLE_USER, true)
+ .assign(PermissionDescription.ROLE_STAFF, true)
+ .assign(PermissionDescription.ROLE_ADMIN, true)
+ .register();
+ this.permDescBuilder
+ .id(MarketPermission.COMMAND_SELL)
+ .description(Text.of("Allows the use of /market sell"))
+ .assign(PermissionDescription.ROLE_USER, true)
+ .assign(PermissionDescription.ROLE_STAFF, true)
+ .assign(PermissionDescription.ROLE_ADMIN, true)
+ .register();
+ this.permDescBuilder
+ .id(MarketPermission.COMMAND_BUY)
+ .description(Text.of("Allows the use of /market buy"))
+ .assign(PermissionDescription.ROLE_USER, true)
+ .assign(PermissionDescription.ROLE_STAFF, true)
+ .assign(PermissionDescription.ROLE_ADMIN, true)
+ .register();
+ this.permDescBuilder
+ .id(MarketPermission.COMMAND_HISTORY)
+ .description(Text.of("Allows the use of /market history"))
+ .assign(PermissionDescription.ROLE_USER, false)
+ .assign(PermissionDescription.ROLE_STAFF, true)
+ .assign(PermissionDescription.ROLE_ADMIN, true)
+ .register();
+ this.permDescBuilder
+ .id(MarketPermission.COMMAND_MAIL)
+ .description(Text.of("Allows the use of /market mail"))
+ .assign(PermissionDescription.ROLE_USER, true)
+ .assign(PermissionDescription.ROLE_STAFF, true)
+ .assign(PermissionDescription.ROLE_ADMIN, true)
+ .register();
+ this.permDescBuilder
+ .id(MarketPermission.COMMAND_PRICECHECK)
+ .description(Text.of("Allows the use of /market price"))
+ .assign(PermissionDescription.ROLE_USER, true)
+ .assign(PermissionDescription.ROLE_STAFF, true)
+ .assign(PermissionDescription.ROLE_ADMIN, true)
+ .register();
+ this.permDescBuilder
+ .id(MarketPermission.COMMAND_PRICELIMIT)
+ .description(Text.of("Allows the use of /market pricelimit"))
+ .assign(PermissionDescription.ROLE_USER, false)
+ .assign(PermissionDescription.ROLE_STAFF, false)
+ .assign(PermissionDescription.ROLE_ADMIN, true)
+ .register();
+ this.permDescBuilder
+ .id(MarketPermission.COMMAND_RELOAD)
+ .description(Text.of("Allows the use of /market reload"))
+ .assign(PermissionDescription.ROLE_USER, false)
+ .assign(PermissionDescription.ROLE_STAFF, false)
+ .assign(PermissionDescription.ROLE_ADMIN, true)
+ .register();
+ this.permDescBuilder
+ .id(MarketPermission.COMMAND_SEND)
+ .description(Text.of("Allows the use of /market send"))
+ .assign(PermissionDescription.ROLE_USER, true)
+ .assign(PermissionDescription.ROLE_STAFF, true)
+ .assign(PermissionDescription.ROLE_ADMIN, true)
+ .register();
+
+ this.permDescBuilder
+ .id(MarketPermission.ADMIN_CANCEL)
+ .description(Text.of("Allows the the admin to cancel market items"))
+ .assign(PermissionDescription.ROLE_USER, false)
+ .assign(PermissionDescription.ROLE_STAFF, false)
+ .assign(PermissionDescription.ROLE_ADMIN, true)
+ .register();
+ this.permDescBuilder
+ .id(MarketPermission.COMMAND_SETTING)
+ .description(Text.of("Allows the the admin to change settings"))
+ .assign(PermissionDescription.ROLE_USER, false)
+ .assign(PermissionDescription.ROLE_STAFF, false)
+ .assign(PermissionDescription.ROLE_ADMIN, true)
+ .register();
}
this.logger.info("Plugin Initialized successfully!");
diff --git a/src/main/java/io/github/poqdavid/nyx/nyxcore/Permissions/EffectPermission.java b/src/main/java/io/github/poqdavid/nyx/nyxcore/Permissions/EffectPermission.java
new file mode 100644
index 0000000..1b22e93
--- /dev/null
+++ b/src/main/java/io/github/poqdavid/nyx/nyxcore/Permissions/EffectPermission.java
@@ -0,0 +1,41 @@
+/*
+ * This file is part of NyxCore.
+ *
+ * NyxCore 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.
+ *
+ * NyxCore 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with NyxCore. If not, see .
+ *
+ * Copyright (c) POQDavid
+ * Copyright (c) contributors
+ */
+
+package io.github.poqdavid.nyx.nyxcore.Permissions;
+
+public class EffectPermission {
+ public static final String COMMAND_HELP = "NyxCore.Effect.Command.Help";
+ public static final String COMMAND_MAIN = "NyxCore.Effect.Command.Main";
+
+ public static final String COMMAND_CHECK = "NyxCore.Effect.Command.Check";
+ public static final String COMMAND_CHECKOTHERS = "NyxCore.Effect.Command.CheckOthers";
+
+ public static final String COMMAND_DISABLEOTHERS = "NyxCore.Effect.Command.DisableOthers";
+
+ public static final String COMMAND_EFFECT = "NyxCore.Effect.Command.Effect";
+ public static final String COMMAND_EFFECT_OTHER = "NyxCore.Effect.Command.EffectOther";
+
+ public static final String COMMAND_TASK = "NyxCore.Effect.Command.Task";
+ public static final String COMMAND_LIST = "NyxCore.Effect.Command.List";
+
+ public static final String COMMAND_TASK_OTHER = "NyxCore.Effect.Command.TaskOther";
+
+ public static final String EFFECTS = "NyxCore.Effect.Effects";
+}
diff --git a/src/main/java/io/github/poqdavid/nyx/nyxcore/Permissions/MarketPermission.java b/src/main/java/io/github/poqdavid/nyx/nyxcore/Permissions/MarketPermission.java
new file mode 100644
index 0000000..8bc3761
--- /dev/null
+++ b/src/main/java/io/github/poqdavid/nyx/nyxcore/Permissions/MarketPermission.java
@@ -0,0 +1,37 @@
+/*
+ * This file is part of NyxCore.
+ *
+ * NyxCore 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.
+ *
+ * NyxCore 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with NyxCore. If not, see .
+ *
+ * Copyright (c) POQDavid
+ * Copyright (c) contributors
+ */
+
+package io.github.poqdavid.nyx.nyxcore.Permissions;
+
+public class MarketPermission {
+ //Commands
+ public static final String COMMAND_HELP = "NyxCore.Market.Command.Help";
+ public static final String COMMAND_MAIN = "NyxCore.Market.Command.Main";
+ public static final String COMMAND_SELL = "NyxCore.Market.Command.Sell";
+ public static final String COMMAND_BUY = "NyxCore.Market.Command.Buy";
+ public static final String COMMAND_HISTORY = "NyxCore.Market.Command.History";
+ public static final String COMMAND_MAIL = "NyxCore.Market.Command.Mail";
+ public static final String COMMAND_PRICECHECK = "NyxCore.Market.Command.PriceCheck";
+ public static final String COMMAND_PRICELIMIT = "NyxCore.Market.Command.PriceLimit";
+ public static final String COMMAND_RELOAD = "NyxCore.Market.Command.Reload";
+ public static final String COMMAND_SEND = "NyxCore.Market.Command.Send";
+ public static final String COMMAND_SETTING = "NyxCore.Market.Command.Setting";
+ public static final String ADMIN_CANCEL = "NyxCore.Market.ADMIN_CANCEL";
+}
diff --git a/src/main/java/io/github/poqdavid/nyx/nyxcore/Permissions/ToolsPermission.java b/src/main/java/io/github/poqdavid/nyx/nyxcore/Permissions/ToolsPermission.java
index a9ab950..3c2f0d6 100644
--- a/src/main/java/io/github/poqdavid/nyx/nyxcore/Permissions/ToolsPermission.java
+++ b/src/main/java/io/github/poqdavid/nyx/nyxcore/Permissions/ToolsPermission.java
@@ -48,30 +48,4 @@ public class ToolsPermission {
public static final String COMMAND_ENCHANTINGTABLE_POWER_13 = "NyxCore.Tools.Command.EnchantingtablePower.13";
public static final String COMMAND_ENCHANTINGTABLE_POWER_14 = "NyxCore.Tools.Command.EnchantingtablePower.14";
public static final String COMMAND_ENCHANTINGTABLE_POWER_15 = "NyxCore.Tools.Command.EnchantingtablePower.15";
-
- public static final String OLD_COMMAND_ANVIL = "VirtualTool.command.anvil";
- public static final String OLD_COMMAND_HELP = "VirtualTool.command.help";
- public static final String OLD_COMMAND_MAIN = "VirtualTool.command.main";
- public static final String OLD_COMMAND_ENDERCHEST = "VirtualTool.command.enderchest";
- public static final String OLD_COMMAND_ENCHANTINGTABLE = "VirtualTool.command.enchantingtable";
- public static final String OLD_COMMAND_WORKBENCH = "VirtualTool.command.workbench";
-
-
- //Enchantment powers
- public static final String OLD_COMMAND_ENCHANTINGTABLE_POWER_0 = "VirtualTool.command.enchantingtablepower.0";
- public static final String OLD_COMMAND_ENCHANTINGTABLE_POWER_1 = "VirtualTool.command.enchantingtablepower.1";
- public static final String OLD_COMMAND_ENCHANTINGTABLE_POWER_2 = "VirtualTool.command.enchantingtablepower.2";
- public static final String OLD_COMMAND_ENCHANTINGTABLE_POWER_3 = "VirtualTool.command.enchantingtablepower.3";
- public static final String OLD_COMMAND_ENCHANTINGTABLE_POWER_4 = "VirtualTool.command.enchantingtablepower.4";
- public static final String OLD_COMMAND_ENCHANTINGTABLE_POWER_5 = "VirtualTool.command.enchantingtablepower.5";
- public static final String OLD_COMMAND_ENCHANTINGTABLE_POWER_6 = "VirtualTool.command.enchantingtablepower.6";
- public static final String OLD_COMMAND_ENCHANTINGTABLE_POWER_7 = "VirtualTool.command.enchantingtablepower.7";
- public static final String OLD_COMMAND_ENCHANTINGTABLE_POWER_8 = "VirtualTool.command.enchantingtablepower.8";
- public static final String OLD_COMMAND_ENCHANTINGTABLE_POWER_9 = "VirtualTool.command.enchantingtablepower.9";
- public static final String OLD_COMMAND_ENCHANTINGTABLE_POWER_10 = "VirtualTool.command.enchantingtablepower.10";
- public static final String OLD_COMMAND_ENCHANTINGTABLE_POWER_11 = "VirtualTool.command.enchantingtablepower.11";
- public static final String OLD_COMMAND_ENCHANTINGTABLE_POWER_12 = "VirtualTool.command.enchantingtablepower.12";
- public static final String OLD_COMMAND_ENCHANTINGTABLE_POWER_13 = "VirtualTool.command.enchantingtablepower.13";
- public static final String OLD_COMMAND_ENCHANTINGTABLE_POWER_14 = "VirtualTool.command.enchantingtablepower.14";
- public static final String OLD_COMMAND_ENCHANTINGTABLE_POWER_15 = "VirtualTool.command.enchantingtablepower.15";
}
diff --git a/src/main/java/io/github/poqdavid/nyx/nyxcore/PluginData.java b/src/main/java/io/github/poqdavid/nyx/nyxcore/PluginData.java
deleted file mode 100644
index c568c1c..0000000
--- a/src/main/java/io/github/poqdavid/nyx/nyxcore/PluginData.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * This file is part of NyxCore.
- *
- * NyxCore 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.
- *
- * NyxCore 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
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with NyxCore. If not, see .
- *
- * Copyright (c) POQDavid
- * Copyright (c) contributors
- */
-
-package io.github.poqdavid.nyx.nyxcore;
-
-public class PluginData {
- public static final String id = "nyxcore";
- public static final String name = "NyxCore";
- public static final String shortName = "Nyx";
- public static final String version = "1.1";
- public static final String description = "Core plugin for all of my Nyx plugins.";
- public static final String organization = "POQDavid";
- public static final String author1 = "POQDavid";
- public static final String url = "https://github.com/poqdavid/NyxCore";
-}
diff --git a/src/main/java/io/github/poqdavid/nyx/nyxcore/Utils/Tools.java b/src/main/java/io/github/poqdavid/nyx/nyxcore/Utils/CoreTools.java
similarity index 62%
rename from src/main/java/io/github/poqdavid/nyx/nyxcore/Utils/Tools.java
rename to src/main/java/io/github/poqdavid/nyx/nyxcore/Utils/CoreTools.java
index ead0b33..33d41d2 100644
--- a/src/main/java/io/github/poqdavid/nyx/nyxcore/Utils/Tools.java
+++ b/src/main/java/io/github/poqdavid/nyx/nyxcore/Utils/CoreTools.java
@@ -20,31 +20,49 @@
package io.github.poqdavid.nyx.nyxcore.Utils;
+import com.flowpowered.math.imaginary.Quaterniond;
+import com.flowpowered.math.vector.Vector3d;
+import com.google.common.base.Charsets;
+import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import io.github.poqdavid.nyx.nyxcore.NyxCore;
-import io.github.poqdavid.nyx.nyxcore.Utils.Setting.NyxTools.Settings;
+import io.github.poqdavid.nyx.nyxcore.Utils.Setting.NyxMarket.NMSettings;
+import io.github.poqdavid.nyx.nyxcore.Utils.Setting.NyxTools.NTSettings;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
+import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
import org.spongepowered.api.Server;
+import org.spongepowered.api.Sponge;
+import org.spongepowered.api.block.BlockState;
+import org.spongepowered.api.block.BlockTypes;
import org.spongepowered.api.command.CommandException;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.data.DataContainer;
+import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.data.persistence.DataFormats;
+import org.spongepowered.api.data.persistence.DataTranslators;
+import org.spongepowered.api.effect.particle.ParticleType;
+import org.spongepowered.api.effect.particle.ParticleTypes;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.entity.living.player.User;
import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.item.inventory.ItemStack;
+import org.spongepowered.api.item.inventory.ItemStackSnapshot;
import org.spongepowered.api.item.inventory.property.SlotPos;
+import org.spongepowered.api.text.Text;
+import org.spongepowered.api.world.Location;
+import org.spongepowered.api.world.World;
import java.io.*;
+import java.lang.reflect.Type;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Base64;
import java.util.Optional;
-public class Tools {
+public class CoreTools {
public static boolean WriteFile(File file, String content) {
FileWriter filew = null;
@@ -214,7 +232,7 @@ public static void MakeNewBP(Player player) {
final File file = filePath.toFile();
if (!file.exists()) {
- if (!Tools.WriteFile(file, "{}")) {
+ if (!CoreTools.WriteFile(file, "{}")) {
NyxCore.getInstance().getLogger(null).error("Failed to create backpack file on player join for " + player.getName());
}
}
@@ -346,7 +364,7 @@ public static void backpackUnlockAll() {
}
}
- public static void saveToJson(Path file, Settings jsonob) {
+ public static void saveToJson(Path file, NTSettings jsonob) {
Gson gson = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
if (jsonob == null) {
@@ -356,7 +374,17 @@ public static void saveToJson(Path file, Settings jsonob) {
}
}
- public static Settings loadFromJson(Path file, Settings defob) {
+ public static void saveToJson(Path file, NMSettings jsonob) {
+ Gson gson = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
+
+ if (jsonob == null) {
+ WriteFile(file.toFile(), "{}");
+ } else {
+ WriteFile(file.toFile(), gson.toJson(jsonob, jsonob.getClass()));
+ }
+ }
+
+ public static NTSettings loadFromJson(Path file, NTSettings defob) {
if (!Files.exists(file)) {
try {
@@ -367,7 +395,7 @@ public static Settings loadFromJson(Path file, Settings defob) {
}
Gson gson = new Gson();
- Settings out = null;
+ NTSettings out = null;
BufferedReader br = null;
try {
@@ -387,4 +415,168 @@ public static Settings loadFromJson(Path file, Settings defob) {
return out;
}
+
+ public static NMSettings loadFromJson(Path file, NMSettings defob) {
+
+ if (!Files.exists(file)) {
+ try {
+ saveToJson(file, defob);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ Gson gson = new Gson();
+ NMSettings out = null;
+ BufferedReader br = null;
+
+ try {
+ br = new BufferedReader(new FileReader(file.toString()));
+ out = gson.fromJson(br, defob.getClass());
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } finally {
+ if (br != null) {
+ try {
+ br.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ return out;
+ }
+
+ public static String serializeToJSON(BlockState items) {
+
+
+ GsonBuilder gsonBuilder = new GsonBuilder();
+
+ gsonBuilder.setPrettyPrinting();
+
+ //gsonBuilder.registerTypeAdapter(ParticleDataList.class, new InterfaceAdapter());
+
+ Gson gson = gsonBuilder.create();
+ Type type = new TypeToken() {
+ }.getType();
+ return gson.toJson(items, type);
+ }
+
+ public static String serialize(DataContainer container) throws IOException {
+ try (StringWriter writer = new StringWriter()) {
+ HoconConfigurationLoader loader = HoconConfigurationLoader.builder().setSink(() -> new BufferedWriter(writer)).build();
+ loader.save(DataTranslators.CONFIGURATION_NODE.translate(container));
+ return Base64.getEncoder().encodeToString(writer.toString().getBytes(Charsets.UTF_8));
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ return null;
+ }
+ }
+
+ public static DataContainer deSerialize(String json) {
+ try (StringReader reader = new StringReader(new String(Base64.getDecoder().decode(json), Charsets.UTF_8))) {
+ return DataTranslators.CONFIGURATION_NODE.translate(HoconConfigurationLoader.builder().setSource(() -> new BufferedReader(reader)).build().load()).getContainer();
+ } catch (IOException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ public static ParticleType GetParticleType(String id) {
+ ParticleType pt = ParticleTypes.FIRE_SMOKE;
+ Optional optpt = Sponge.getRegistry().getType(ParticleType.class, id);
+
+ if (optpt.isPresent()) {
+ pt = optpt.get();
+ }
+
+ return pt;
+ }
+
+ public static BlockState GetBlock(String id) {
+ return Sponge.getRegistry().getType(BlockState.class, id).orElse(BlockTypes.AIR.getDefaultState());
+ }
+
+
+ public static String getDirection(Player player) {
+ String playerDirection;
+ double yaw = player.getRotation().getY();
+ //World w = player.getWorld();
+ int x = player.getLocation().getBlockX();
+ int y = player.getLocation().getBlockY();
+ int z = player.getLocation().getBlockZ();
+
+ if (yaw < 0) {
+ yaw = yaw + 360;
+ }
+
+ if ((yaw >= 315) && (yaw <= 360)) {
+ playerDirection = "south";
+ } else if ((yaw >= 0) && (yaw <= 45)) {
+ playerDirection = "south";
+ } else if ((yaw >= 45) && (yaw <= 135)) {
+ playerDirection = "west";
+ } else if ((yaw >= 135) && (yaw <= 180)) {
+ playerDirection = "north";
+ } else if ((yaw >= 180) && (yaw <= 225)) {
+ playerDirection = "north";
+ } else if ((yaw >= 225) && (yaw <= 315)) {
+ playerDirection = "east";
+ } else {
+ playerDirection = "east";
+ }
+
+ return playerDirection;
+ }
+
+ public static Vector3d getBL(Player player) {
+
+ double x = player.getLocation().getX();
+ double y = player.getLocation().getY();
+ double z = player.getLocation().getZ();
+ final String playerDirection = CoreTools.getDirection(player);
+
+ if (playerDirection == "north") {
+ z = z + 1;
+ } else if (playerDirection == "east") {
+ x = x - 1;
+ } else if (playerDirection == "south") {
+ z = z - 1;
+ } else if (playerDirection == "west") {
+ x = x + 1;
+ }
+
+
+ return new Vector3d(x, y, z);
+ }
+
+ public static Location GetLocation(Player player, Quaterniond Qu, Vector3d distance) {
+ final Vector3d dir = Qu.getDirection();
+ final Vector3d diff = dir.add(distance);
+ return player.getLocation().add(diff);
+ }
+
+ public static Location GetLocation(Player player, Vector3d distance) {
+ final Vector3d rotation = player.getRotation();
+ return GetLocation(player, Quaterniond.fromAxesAnglesDeg(rotation.getX(), -rotation.getY(), rotation.getZ()), distance);
+ }
+
+ public static Vector3d rotateAroundAxisY(Vector3d v, double cos, double sin) {
+ double x = v.getX() * cos + v.getZ() * sin;
+ double z = v.getX() * -sin + v.getZ() * cos;
+ return new Vector3d(x, v.getY(), z);
+ }
+
+ public static ItemStack Base64ToItemStack(byte[] base64) {
+ return ItemStack.builder().fromContainer(Base64ToContainer(base64)).build();
+ }
+
+ public static Text getItemName(ItemStack itemStack) {
+ return itemStack.get(Keys.DISPLAY_NAME).orElse(Text.of(itemStack.getTranslation().get()));
+ }
+
+ public static Text getItemName(ItemStackSnapshot itemStack) {
+ return itemStack.get(Keys.DISPLAY_NAME).orElse(Text.of(itemStack.getTranslation().get()));
+ }
}
diff --git a/src/main/java/io/github/poqdavid/nyx/nyxcore/Utils/Invs.java b/src/main/java/io/github/poqdavid/nyx/nyxcore/Utils/Invs.java
index aaffb03..ab1045d 100644
--- a/src/main/java/io/github/poqdavid/nyx/nyxcore/Utils/Invs.java
+++ b/src/main/java/io/github/poqdavid/nyx/nyxcore/Utils/Invs.java
@@ -67,7 +67,7 @@ public CommandResult Open(CommandSource src, Inventory inv, InventoryArchetype i
public CommandResult Open(CommandSource src, CommandContext args, String invArch) {
if (Objects.equals(invArch, "enderchest")) {
- final Player player = Tools.getPlayer(src);
+ final Player player = CoreTools.getPlayer(src);
return this.Open(src, args, player.getEnderChestInventory());
}
return CommandResult.empty();
@@ -80,7 +80,7 @@ public CommandResult Open(CommandSource src, CommandContext args, InventoryArche
}
public CommandResult Open(CommandSource src, CommandContext args, org.spongepowered.api.item.inventory.Inventory i) {
- final Player player = Tools.getPlayer(src);
+ final Player player = CoreTools.getPlayer(src);
if (src.getCommandSource().isPresent() && src.getCommandSource().get() instanceof Player) {
player.openInventory(i);
return CommandResult.success();
@@ -89,7 +89,7 @@ public CommandResult Open(CommandSource src, CommandContext args, org.spongepowe
}
public CommandResult Open(CommandSource src, org.spongepowered.api.item.inventory.Inventory i) {
- final Player player = Tools.getPlayer(src);
+ final Player player = CoreTools.getPlayer(src);
if (src.getCommandSource().isPresent() && src.getCommandSource().get() instanceof Player) {
player.openInventory(i);
return CommandResult.success();
@@ -98,7 +98,7 @@ public CommandResult Open(CommandSource src, org.spongepowered.api.item.inventor
}
public CommandResult Open(CommandSource src, Container openCon, String inventoryTypeIn, String title) {
- final Player player = Tools.getPlayer(src);
+ final Player player = CoreTools.getPlayer(src);
final EntityPlayerMP MPlayer = (EntityPlayerMP) player;
MPlayer.getNextWindowId();
MPlayer.connection.sendPacket(new SPacketOpenWindow(MPlayer.currentWindowId, inventoryTypeIn, new TextComponentString(title)));
diff --git a/src/main/java/io/github/poqdavid/nyx/nyxcore/Utils/Setting/NyxMarket/NMSettings.java b/src/main/java/io/github/poqdavid/nyx/nyxcore/Utils/Setting/NyxMarket/NMSettings.java
new file mode 100644
index 0000000..5cb08af
--- /dev/null
+++ b/src/main/java/io/github/poqdavid/nyx/nyxcore/Utils/Setting/NyxMarket/NMSettings.java
@@ -0,0 +1,110 @@
+/*
+ * This file is part of NyxCore.
+ *
+ * NyxCore 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.
+ *
+ * NyxCore 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with NyxCore. If not, see .
+ *
+ * Copyright (c) POQDavid
+ * Copyright (c) contributors
+ */
+
+package io.github.poqdavid.nyx.nyxcore.Utils.Setting.NyxMarket;
+
+import com.google.gson.annotations.Expose;
+import com.google.gson.annotations.SerializedName;
+import io.github.poqdavid.nyx.nyxcore.NyxCore;
+import io.github.poqdavid.nyx.nyxcore.Utils.CoreTools;
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+
+import java.io.Serializable;
+import java.nio.file.Path;
+
+public class NMSettings implements Serializable {
+
+ private final static long serialVersionUID = 3330320144420690910L;
+ @SerializedName("ItemExpiryTime")
+ @Expose
+ private Integer itemExpiryTime;
+
+ /**
+ * No args constructor for use in serialization
+ */
+ public NMSettings() {
+ this.setItemExpiryTime(5760);
+ }
+
+ /**
+ * @param itemExpiryTime
+ */
+ public NMSettings(Integer itemExpiryTime) {
+ super();
+ this.itemExpiryTime = itemExpiryTime;
+ }
+
+ public NMSettings(Path file) {
+ this.Load(file);
+ }
+
+ public void Load(Path file) {
+ try {
+ NMSettings sets = CoreTools.loadFromJson(file, new NMSettings());
+ NyxCore.getInstance().getLogger(null).info("Loading file: " + file.toString());
+ this.setItemExpiryTime(sets.getItemExpiryTime());
+ } catch (Exception e) {
+ this.Save(file);
+ NyxCore.getInstance().getLogger(null).error(e.getMessage(), e);
+ }
+ }
+
+ public void Save(Path file) {
+ CoreTools.saveToJson(file, this);
+ }
+
+ public Integer getItemExpiryTime() {
+ return itemExpiryTime;
+ }
+
+ public void setItemExpiryTime(Integer itemExpiryTime) {
+ this.itemExpiryTime = itemExpiryTime;
+ }
+
+ public NMSettings withItemExpiryTime(Integer itemExpiryTime) {
+ this.itemExpiryTime = itemExpiryTime;
+ return this;
+ }
+
+ @Override
+ public String toString() {
+ return new ToStringBuilder(this).append("itemExpiryTime", itemExpiryTime).toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return new HashCodeBuilder().append(itemExpiryTime).toHashCode();
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (other == this) {
+ return true;
+ }
+ if ((other instanceof NMSettings) == false) {
+ return false;
+ }
+ NMSettings rhs = ((NMSettings) other);
+ return new EqualsBuilder().append(itemExpiryTime, rhs.itemExpiryTime).isEquals();
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/io/github/poqdavid/nyx/nyxcore/Utils/Setting/NyxTools/Settings.java b/src/main/java/io/github/poqdavid/nyx/nyxcore/Utils/Setting/NyxTools/NTSettings.java
similarity index 89%
rename from src/main/java/io/github/poqdavid/nyx/nyxcore/Utils/Setting/NyxTools/Settings.java
rename to src/main/java/io/github/poqdavid/nyx/nyxcore/Utils/Setting/NyxTools/NTSettings.java
index b3736ef..230a800 100644
--- a/src/main/java/io/github/poqdavid/nyx/nyxcore/Utils/Setting/NyxTools/Settings.java
+++ b/src/main/java/io/github/poqdavid/nyx/nyxcore/Utils/Setting/NyxTools/NTSettings.java
@@ -23,7 +23,7 @@
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import io.github.poqdavid.nyx.nyxcore.NyxCore;
-import io.github.poqdavid.nyx.nyxcore.Utils.Tools;
+import io.github.poqdavid.nyx.nyxcore.Utils.CoreTools;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
@@ -32,7 +32,7 @@
import java.io.Serializable;
import java.nio.file.Path;
-public class Settings implements Serializable {
+public class NTSettings implements Serializable {
private final static long serialVersionUID = 4280887333225310204L;
@SerializedName("commands")
@@ -43,23 +43,23 @@ public class Settings implements Serializable {
/**
* No args constructor for use in serialization
*/
- public Settings() {
+ public NTSettings() {
this.setCommands(new Commands(true, true, true, true));
}
- public Settings(Commands commands) {
+ public NTSettings(Commands commands) {
super();
this.commands = commands;
}
- public Settings(Path file) {
+ public NTSettings(Path file) {
this.Load(file);
}
public void Load(Path file) {
try {
- Settings sets = Tools.loadFromJson(file, new Settings());
+ NTSettings sets = CoreTools.loadFromJson(file, new NTSettings());
NyxCore.getInstance().getLogger(null).info("Loading file: " + file.toString());
this.setCommands(sets.getCommands());
} catch (Exception e) {
@@ -69,7 +69,7 @@ public void Load(Path file) {
}
public void Save(Path file) {
- Tools.saveToJson(file, this);
+ CoreTools.saveToJson(file, this);
}
public Commands getCommands() {
@@ -80,7 +80,7 @@ public void setCommands(Commands commands) {
this.commands = commands;
}
- public Settings withCommands(Commands commands) {
+ public NTSettings withCommands(Commands commands) {
this.commands = commands;
return this;
}
@@ -100,10 +100,10 @@ public boolean equals(Object other) {
if (other == this) {
return true;
}
- if (!(other instanceof Settings)) {
+ if (!(other instanceof NTSettings)) {
return false;
}
- Settings rhs = ((Settings) other);
+ NTSettings rhs = ((NTSettings) other);
return new EqualsBuilder().append(commands, rhs.commands).isEquals();
}