Compare commits

...

15 Commits

Author SHA1 Message Date
Christian Koop dc6967e3c7
Release v3.0.0 2024-01-13 22:26:26 +01:00
Christian Koop f97511f474
Upgrade Craftaro Core (+dynamic library loading; +MC 1.20.4 support)
Notable changes:
* Spigot 1.20.3/3 compatibility
* dynamic library/dependency loading
  * Smaller plugin jar size
2024-01-13 22:26:07 +01:00
Christian Koop 8a9a174a9b
Release v3.0.0-b2-SNAPSHOT 2023-10-23 18:20:11 +02:00
Christian Koop 936c63fa45
Merge branch 'master' into development 2023-08-25 15:01:23 +02:00
Christian Koop e364be9b6f
Release v3.0.0-SNAPSHOT 2023-08-25 14:49:47 +02:00
Christian Koop 6a037bcf28
pom.xml: Fixes typo in project description
Mistake copied from the marketplace
2023-08-25 14:39:45 +02:00
Christian Koop a00a64608e
Updates maven plugins used in pom.xml 2023-08-25 12:44:53 +02:00
Christian Koop 4d18b309b4
Updates `plugin.yml` and adds DecentHolograms to softdepends 2023-08-25 12:44:40 +02:00
Christian Koop 3b396faec6
Merge branch 'master' into development 2023-08-25 12:29:16 +02:00
Christian Koop 1f98d2a740
Updates .gitignore 2023-08-25 12:14:41 +02:00
Christian Koop e8bc5fd85a
Create .editorconfig 2023-08-25 12:13:05 +02:00
Christian Koop b5f442bdb9
Heavy code style changes and slight refactoring 2023-08-25 12:12:58 +02:00
Christian Koop f8ee4fd6ad
Fix database implementation to be compatible with latest CraftaroCore 2023-08-16 11:16:34 +02:00
Fernando Pettinelli 49a0a518f4 Version 2.8.0 2023-07-26 21:31:51 -04:00
Fernando Pettinelli 3a652c597d Moved from songoda to craftaro 2023-07-26 21:28:26 -04:00
77 changed files with 2552 additions and 2610 deletions

26
.editorconfig Normal file
View File

@ -0,0 +1,26 @@
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
# max_line_length = 120
tab_width = 4
trim_trailing_whitespace = true
ij_continuation_indent_size = 8
ij_formatter_off_tag = @formatter:off
ij_formatter_on_tag = @formatter:on
ij_formatter_tags_enabled = true
[{*.yaml,*.yml,*.json,*.lang,*.graphqlconfig,*.har,*.jsb2,*.jsb3,*.webmanifest,.babelrc,.eslintrc,.prettierrc,.stylelintrc,bowerrc,jest.config}]
indent_size = 2
tab_width = 2
[{*.markdown,*.md,*.html,*.htm,*.ng,*.sht,*.shtm,*.shtml,*.ts,*.ats,*.js,*.cjs,*.bash,*.sh,*.zsh}]
indent_size = 2
tab_width = 2

92
.gitignore vendored
View File

@ -1,86 +1,10 @@
target/
icons/
sprites/
audio/
character parts/
tokens/*
credentials.json
.idea/**
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
.idea/**/contentModel.xml
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
.idea/**/gradle.xml
.idea/**/libraries
cmake-build-*/
.idea/**/mongoSettings.xml
*.iws
out/
.idea_modules/
atlassian-ide-plugin.xml
.idea/replstate.xml
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
.idea/httpRequests
.idea/caches/build_file_checksums.ser
*.class
*.log
*.ctxt
.mtj.tmp/
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
hs_err_pid*
## JetBrains IDEs
/.idea/
*.iml
## Maven
/**/target/
dependency-reduced-pom.xml
## Misc.
.DS_Store
.AppleDouble
.LSOverride
Icon
._*
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
.project
.classpath
.settings/
.vscode/
settings.txt
**/*.sql
.gradle/
build/
bin/
*.pom.xml
!gradle-wrapper.jar

57
pom.xml
View File

@ -4,13 +4,13 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.songoda</groupId>
<groupId>com.craftaro</groupId>
<artifactId>UltimateKits</artifactId>
<version>2.7.7</version>
<version>3.0.0</version>
<name>UltimateKits</name>
<description>Creating and displaying your servers kits has never been easier</description>
<url>https://songoda.com/marketplace/product/14</url>
<description>Creating and displaying your server's kits has never been easier</description>
<url>https://craftaro.com/marketplace/product/ultimatekits.14</url>
<properties>
<java.version>1.8</java.version>
@ -19,14 +19,9 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<issueManagement>
<url>https://support.songoda.com/servicedesk/customer/portal/3</url>
<system>Jira Service Desk</system>
</issueManagement>
<scm>
<url>https://github.com/songoda/UltimateKits</url>
<connection>scm:git:git:github.com/songoda/UltimateKits.git</connection>
<url>https://github.com/craftaro/UltimateKits</url>
<connection>scm:git:git:github.com/craftaro/UltimateKits.git</connection>
</scm>
<build>
@ -34,7 +29,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.11.0</version>
<configuration>
<source>${java.version}</source>
@ -47,7 +42,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<version>3.5.0</version>
<executions>
<execution>
@ -60,13 +55,14 @@
<configuration>
<finalName>${project.name}-${project.version}</finalName>
<createDependencyReducedPom>false</createDependencyReducedPom>
<shadedArtifactAttached>false</shadedArtifactAttached>
<useDependencyReducedPomInJar>true</useDependencyReducedPomInJar>
<minimizeJar>true</minimizeJar>
<relocations>
<relocation>
<pattern>com.songoda.core</pattern>
<shadedPattern>com.songoda.epicanchors.core</shadedPattern>
<pattern>com.craftaro.core</pattern>
<shadedPattern>com.craftaro.ultimatestacker.core</shadedPattern>
</relocation>
</relocations>
@ -80,6 +76,25 @@
<exclude>LICENSE.**</exclude>
</excludes>
</filter>
<filter>
<artifact>com.craftaro:CraftaroCore</artifact>
<excludeDefaults>false</excludeDefaults>
<includes>
<include>**/nms/v*/**</include>
</includes>
<excludes>
<exclude>**/third_party/org/apache/**</exclude>
<exclude>**/third_party/net/kyori/**</exclude>
<exclude>**/third_party/com/zaxxer/**</exclude>
<exclude>**/third_party/org/jooq/**</exclude>
<exclude>**/third_party/org/mariadb/**</exclude>
<exclude>**/third_party/com/h2database/**</exclude>
<exclude>**/third_party/org/h2/**</exclude>
<exclude>**/third_party/com/cryptomorin/**</exclude>
<exclude>**/third_party/org/reactivestreams/**</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
@ -102,7 +117,7 @@
</repository>
<repository>
<id>songoda-public</id>
<id>public</id>
<url>https://repo.songoda.com/repository/public/</url>
</repository>
</repositories>
@ -111,14 +126,14 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.18-R0.1-SNAPSHOT</version>
<version>1.20.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore</artifactId>
<version>2.6.21</version>
<groupId>com.craftaro</groupId>
<artifactId>CraftaroCore</artifactId>
<version>3.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>

View File

@ -1,56 +1,54 @@
package com.songoda.ultimatekits;
package com.craftaro.ultimatekits;
import com.songoda.core.SongodaCore;
import com.songoda.core.SongodaPlugin;
import com.songoda.core.commands.CommandManager;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.configuration.Config;
import com.songoda.core.database.DataMigrationManager;
import com.songoda.core.database.DatabaseConnector;
import com.songoda.core.database.MySQLConnector;
import com.songoda.core.database.SQLiteConnector;
import com.songoda.core.gui.GuiManager;
import com.songoda.core.hooks.EconomyManager;
import com.songoda.core.hooks.HologramManager;
import com.songoda.core.utils.TextUtils;
import com.songoda.ultimatekits.category.Category;
import com.songoda.ultimatekits.category.CategoryManager;
import com.songoda.ultimatekits.commands.CommandCategories;
import com.songoda.ultimatekits.commands.CommandCrate;
import com.songoda.ultimatekits.commands.CommandCreatekit;
import com.songoda.ultimatekits.commands.CommandEdit;
import com.songoda.ultimatekits.commands.CommandKey;
import com.songoda.ultimatekits.commands.CommandKit;
import com.songoda.ultimatekits.commands.CommandPreviewKit;
import com.songoda.ultimatekits.commands.CommandReload;
import com.songoda.ultimatekits.commands.CommandRemove;
import com.songoda.ultimatekits.commands.CommandSet;
import com.songoda.ultimatekits.commands.CommandSettings;
import com.songoda.ultimatekits.conversion.Convert;
import com.songoda.ultimatekits.crate.Crate;
import com.songoda.ultimatekits.crate.CrateManager;
import com.songoda.ultimatekits.database.DataManager;
import com.songoda.ultimatekits.database.migrations._1_InitialMigration;
import com.songoda.ultimatekits.database.migrations._2_DuplicateMigration;
import com.songoda.ultimatekits.handlers.DisplayItemHandler;
import com.songoda.ultimatekits.handlers.ParticleHandler;
import com.songoda.ultimatekits.key.Key;
import com.songoda.ultimatekits.key.KeyManager;
import com.songoda.ultimatekits.kit.Kit;
import com.songoda.ultimatekits.kit.KitAnimation;
import com.songoda.ultimatekits.kit.KitBlockData;
import com.songoda.ultimatekits.kit.KitItem;
import com.songoda.ultimatekits.kit.KitManager;
import com.songoda.ultimatekits.kit.KitType;
import com.songoda.ultimatekits.listeners.BlockListeners;
import com.songoda.ultimatekits.listeners.ChatListeners;
import com.songoda.ultimatekits.listeners.ChunkListeners;
import com.songoda.ultimatekits.listeners.EntityListeners;
import com.songoda.ultimatekits.listeners.InteractListeners;
import com.songoda.ultimatekits.listeners.PlayerListeners;
import com.songoda.ultimatekits.settings.Settings;
import com.songoda.ultimatekits.utils.ItemSerializer;
import com.songoda.ultimatekits.utils.Methods;
import com.craftaro.core.SongodaCore;
import com.craftaro.core.SongodaPlugin;
import com.craftaro.core.commands.CommandManager;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.configuration.Config;
import com.craftaro.core.gui.GuiManager;
import com.craftaro.core.hooks.EconomyManager;
import com.craftaro.core.hooks.HologramManager;
import com.craftaro.core.utils.NumberUtils;
import com.craftaro.core.utils.TextUtils;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.ultimatekits.category.Category;
import com.craftaro.ultimatekits.category.CategoryManager;
import com.craftaro.ultimatekits.commands.CommandCategories;
import com.craftaro.ultimatekits.commands.CommandCrate;
import com.craftaro.ultimatekits.commands.CommandCreatekit;
import com.craftaro.ultimatekits.commands.CommandEdit;
import com.craftaro.ultimatekits.commands.CommandKey;
import com.craftaro.ultimatekits.commands.CommandKit;
import com.craftaro.ultimatekits.commands.CommandPreviewKit;
import com.craftaro.ultimatekits.commands.CommandReload;
import com.craftaro.ultimatekits.commands.CommandRemove;
import com.craftaro.ultimatekits.commands.CommandSet;
import com.craftaro.ultimatekits.commands.CommandSettings;
import com.craftaro.ultimatekits.conversion.Convert;
import com.craftaro.ultimatekits.crate.Crate;
import com.craftaro.ultimatekits.crate.CrateManager;
import com.craftaro.ultimatekits.database.DataManager;
import com.craftaro.ultimatekits.database.migrations._1_InitialMigration;
import com.craftaro.ultimatekits.database.migrations._2_DuplicateMigration;
import com.craftaro.ultimatekits.handlers.DisplayItemHandler;
import com.craftaro.ultimatekits.handlers.ParticleHandler;
import com.craftaro.ultimatekits.key.Key;
import com.craftaro.ultimatekits.key.KeyManager;
import com.craftaro.ultimatekits.kit.Kit;
import com.craftaro.ultimatekits.kit.KitAnimation;
import com.craftaro.ultimatekits.kit.KitBlockData;
import com.craftaro.ultimatekits.kit.KitItem;
import com.craftaro.ultimatekits.kit.KitManager;
import com.craftaro.ultimatekits.kit.KitType;
import com.craftaro.ultimatekits.listeners.BlockListeners;
import com.craftaro.ultimatekits.listeners.ChatListeners;
import com.craftaro.ultimatekits.listeners.ChunkListeners;
import com.craftaro.ultimatekits.listeners.EntityListeners;
import com.craftaro.ultimatekits.listeners.InteractListeners;
import com.craftaro.ultimatekits.listeners.PlayerListeners;
import com.craftaro.ultimatekits.settings.Settings;
import com.craftaro.ultimatekits.utils.ItemSerializer;
import com.craftaro.ultimatekits.utils.Methods;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
@ -67,8 +65,6 @@ import java.util.List;
import java.util.stream.Collectors;
public class UltimateKits extends SongodaPlugin {
private static UltimateKits INSTANCE;
private final Config kitConfig = new Config(this, "kit.yml");
private final Config categoryConfig = new Config(this, "category.yml");
private final Config dataFile = new Config(this, "data.yml");
@ -84,24 +80,26 @@ public class UltimateKits extends SongodaPlugin {
private KeyManager keyManager;
private CrateManager crateManager;
private CategoryManager categoryManager;
private DatabaseConnector databaseConnector;
private DataManager dataManager;
private boolean loaded = false;
/**
* @deprecated Use {@link org.bukkit.plugin.java.JavaPlugin#getPlugin(Class)} instead
*/
@Deprecated
public static UltimateKits getInstance() {
return INSTANCE;
return getPlugin(UltimateKits.class);
}
@Override
public void onPluginLoad() {
INSTANCE = this;
}
@Override
public void onPluginEnable() {
SongodaCore.registerPlugin(this, 14, CompatibleMaterial.BEACON);
initDatabase(Arrays.asList(new _1_InitialMigration(), new _2_DuplicateMigration()));
SongodaCore.registerPlugin(this, 14, XMaterial.BEACON);
// Load Economy
EconomyManager.load();
@ -115,13 +113,14 @@ public class UltimateKits extends SongodaPlugin {
// Set economy preference
EconomyManager.getManager().setPreferredHook(Settings.ECONOMY_PLUGIN.getString());
this.dataManager = new DataManager(this);
this.kitManager = new KitManager();
this.keyManager = new KeyManager();
this.crateManager = new CrateManager();
this.categoryManager = new CategoryManager(this);
this.kitConfig.load();
Convert.runKitConversions();
Convert.runKitConversions(this);
this.categoryConfig.load();
@ -148,7 +147,7 @@ public class UltimateKits extends SongodaPlugin {
.addSubCommand(new CommandSet(this))
.addSubCommand(new CommandRemove(this))
.addSubCommand(new CommandCrate());
.addSubCommand(new CommandCrate(this));
// Event registration
@ -159,36 +158,7 @@ public class UltimateKits extends SongodaPlugin {
pluginManager.registerEvents(new ChatListeners(), this);
pluginManager.registerEvents(new EntityListeners(this), this);
pluginManager.registerEvents(new InteractListeners(this, this.guiManager), this);
pluginManager.registerEvents(new PlayerListeners(), this);
try {
if (Settings.MYSQL_ENABLED.getBoolean()) {
String hostname = Settings.MYSQL_HOSTNAME.getString();
int port = Settings.MYSQL_PORT.getInt();
String database = Settings.MYSQL_DATABASE.getString();
String username = Settings.MYSQL_USERNAME.getString();
String password = Settings.MYSQL_PASSWORD.getString();
boolean useSSL = Settings.MYSQL_USE_SSL.getBoolean();
int poolSize = Settings.MYSQL_POOL_SIZE.getInt();
this.databaseConnector = new MySQLConnector(this, hostname, port, database, username, password, useSSL, poolSize);
this.getLogger().info("Data handler connected using MySQL.");
} else {
this.databaseConnector = new SQLiteConnector(this);
this.getLogger().info("Data handler connected using SQLite.");
}
this.dataManager = new DataManager(this.databaseConnector, this);
DataMigrationManager dataMigrationManager = new DataMigrationManager(this.databaseConnector, this.dataManager,
new _1_InitialMigration(),
new _2_DuplicateMigration(this.databaseConnector instanceof SQLiteConnector));
dataMigrationManager.runMigrations();
} catch (Exception ex) {
this.getLogger().severe("Fatal error trying to connect to database. " +
"Please make sure all your connection settings are correct and try again. Plugin has been disabled. (" + ex.getMessage() + ")");
emergencyStop();
return;
}
pluginManager.registerEvents(new PlayerListeners(this), this);
this.displayItemHandler.start();
this.particleHandler.start();
@ -197,34 +167,34 @@ public class UltimateKits extends SongodaPlugin {
@Override
public void onDataLoad() {
// Empty categories from manager
categoryManager.clearCategories();
this.categoryManager.clearCategories();
/*
* Register categories into CategoryManager from Configuration
*/
if (categoryConfig.getConfigurationSection("Categories") != null) {
for (String key : categoryConfig.getConfigurationSection("Categories").getKeys(false)) {
ConfigurationSection section = categoryConfig.getConfigurationSection("Categories." + key);
if (this.categoryConfig.getConfigurationSection("Categories") != null) {
for (String key : this.categoryConfig.getConfigurationSection("Categories").getKeys(false)) {
ConfigurationSection section = this.categoryConfig.getConfigurationSection("Categories." + key);
if (section == null) {
continue;
}
Category category = categoryManager.addCategory(key, section.getString("name"));
Category category = this.categoryManager.addCategory(key, section.getString("name"));
if (section.contains("material")) {
category.setMaterial(CompatibleMaterial.getMaterial(section.getString("material")).getMaterial());
category.setMaterial(CompatibleMaterial.getMaterial(section.getString("material")).get().parseMaterial());
}
}
}
// Empty kits from manager.
kitManager.clearKits();
this.kitManager.clearKits();
/*
* Register kits into KitManager from Configuration
*/
if (kitConfig.getConfigurationSection("Kits") != null) {
for (String kitName : kitConfig.getConfigurationSection("Kits").getKeys(false)) {
ConfigurationSection section = kitConfig.getConfigurationSection("Kits." + kitName);
if (this.kitConfig.getConfigurationSection("Kits") != null) {
for (String kitName : this.kitConfig.getConfigurationSection("Kits").getKeys(false)) {
ConfigurationSection section = this.kitConfig.getConfigurationSection("Kits." + kitName);
if (section == null) {
continue;
}
@ -237,16 +207,16 @@ public class UltimateKits extends SongodaPlugin {
if (itemString.contains("{")) {
item = ItemSerializer.deserializeItemStackFromJson(itemString);
} else {
item = CompatibleMaterial.getMaterial(itemString).getItem();
item = CompatibleMaterial.getMaterial(itemString).get().parseItem();
}
}
kitManager.addKit(new Kit(kitName)
this.kitManager.addKit(new Kit(kitName)
.setTitle(section.getString("title"))
.setDelay(section.getLong("delay"))
.setLink(section.getString("link"))
.setDisplayItem(item)
.setCategory(categoryManager.getCategory(section.getString("category")))
.setCategory(this.categoryManager.getCategory(section.getString("category")))
.setHidden(section.getBoolean("hidden"))
.setPrice(section.getDouble("price"))
.setContents(section.getStringList("items").stream().map(KitItem::new).collect(Collectors.toList()))
@ -258,20 +228,20 @@ public class UltimateKits extends SongodaPlugin {
/*
* Register legacy kit locations into KitManager from Configuration
*/
if (dataFile.contains("BlockData")) {
for (String key : dataFile.getConfigurationSection("BlockData").getKeys(false)) {
if (this.dataFile.contains("BlockData")) {
for (String key : this.dataFile.getConfigurationSection("BlockData").getKeys(false)) {
Location location = Methods.unserializeLocation(key);
Kit kit = kitManager.getKit(dataFile.getString("BlockData." + key + ".kit"));
KitType type = KitType.valueOf(dataFile.getString("BlockData." + key + ".type", "PREVIEW"));
boolean holograms = dataFile.getBoolean("BlockData." + key + ".holograms");
boolean displayItems = dataFile.getBoolean("BlockData." + key + ".displayItems");
boolean particles = dataFile.getBoolean("BlockData." + key + ".particles");
boolean itemOverride = dataFile.getBoolean("BlockData." + key + ".itemOverride");
Kit kit = this.kitManager.getKit(this.dataFile.getString("BlockData." + key + ".kit"));
KitType type = KitType.valueOf(this.dataFile.getString("BlockData." + key + ".type", "PREVIEW"));
boolean holograms = this.dataFile.getBoolean("BlockData." + key + ".holograms");
boolean displayItems = this.dataFile.getBoolean("BlockData." + key + ".displayItems");
boolean particles = this.dataFile.getBoolean("BlockData." + key + ".particles");
boolean itemOverride = this.dataFile.getBoolean("BlockData." + key + ".itemOverride");
if (kit == null) {
dataFile.set("BlockData." + key, null);
this.dataFile.set("BlockData." + key, null);
} else {
updateHologram(kitManager.addKitToLocation(kit, location, type, holograms, particles, displayItems, itemOverride));
updateHologram(this.kitManager.addKitToLocation(kit, location, type, holograms, particles, displayItems, itemOverride));
}
}
}
@ -294,33 +264,33 @@ public class UltimateKits extends SongodaPlugin {
checkCrateDefaults();
// Empty keys from manager
keyManager.clear();
crateManager.clear();
this.keyManager.clear();
this.crateManager.clear();
/*
* Register keys into KitManager from Configuration
*/
if (keyFile.contains("Keys")) {
for (String keyName : keyFile.getConfigurationSection("Keys").getKeys(false)) {
int amt = keyFile.getInt("Keys." + keyName + ".Item Amount");
int kitAmount = keyFile.getInt("Keys." + keyName + ".Amount of kit received");
boolean enchanted = keyFile.getBoolean("Keys." + keyName + ".Enchanted");
if (this.keyFile.contains("Keys")) {
for (String keyName : this.keyFile.getConfigurationSection("Keys").getKeys(false)) {
int amt = this.keyFile.getInt("Keys." + keyName + ".Item Amount");
int kitAmount = this.keyFile.getInt("Keys." + keyName + ".Amount of kit received");
boolean enchanted = this.keyFile.getBoolean("Keys." + keyName + ".Enchanted");
Key key = new Key(keyName, amt, kitAmount, enchanted);
keyManager.addKey(key);
this.keyManager.addKey(key);
}
}
/*
* Register Crates
*/
if (crateFile.contains("Crates")) {
for (String crateName : crateFile.getConfigurationSection("Crates").getKeys(false)) {
int amt = crateFile.getInt("Crates." + crateName + ".Item Amount");
int kitAmount = crateFile.getInt("Crates." + crateName + ".Amount of kit received");
if (this.crateFile.contains("Crates")) {
for (String crateName : this.crateFile.getConfigurationSection("Crates").getKeys(false)) {
int amt = this.crateFile.getInt("Crates." + crateName + ".Item Amount");
int kitAmount = this.crateFile.getInt("Crates." + crateName + ".Amount of kit received");
Crate crate = new Crate(crateName, amt, kitAmount);
crateManager.addCrate(crate);
this.crateManager.addCrate(crate);
}
}
this.loaded = true;
@ -411,7 +381,7 @@ public class UltimateKits extends SongodaPlugin {
}
private List<String> formatHologram(KitBlockData data) {
getDataManager().updateBlockData(data);
getKitDataManager().updateBlockData(data);
List<String> lines = new ArrayList<>();
@ -440,7 +410,7 @@ public class UltimateKits extends SongodaPlugin {
if (kit.getPrice() != 0) {
lines.add(getLocale().getMessage("interface.hologram.buyeco")
.processPlaceholder("price", kit.getPrice() != 0
? Methods.formatEconomy(kit.getPrice())
? NumberUtils.formatNumber(kit.getPrice())
: getLocale().getMessage("general.type.free").getMessage())
.getMessage());
}
@ -471,64 +441,74 @@ public class UltimateKits extends SongodaPlugin {
* Saves registered kits to file
*/
public void saveKits(boolean force) {
if (!loaded && !force) return;
if (!this.loaded && !force) {
return;
}
// If we're changing the order the file needs to be wiped
if (kitManager.hasOrderChanged()) {
kitConfig.clearConfig(true);
kitManager.savedOrderChange();
if (this.kitManager.hasOrderChanged()) {
this.kitConfig.clearConfig(true);
this.kitManager.savedOrderChange();
}
// Hot fix for kit file resets
if (kitConfig.contains("Kits"))
for (String kitName : kitConfig.getConfigurationSection("Kits").getKeys(false)) {
if (kitManager.getKits().stream().noneMatch(kit -> kit.getKey().equals(kitName)))
kitConfig.set("Kits." + kitName, null);
if (this.kitConfig.contains("Kits")) {
for (String kitName : this.kitConfig.getConfigurationSection("Kits").getKeys(false)) {
if (this.kitManager.getKits().stream().noneMatch(kit -> kit.getKey().equals(kitName))) {
this.kitConfig.set("Kits." + kitName, null);
}
}
}
// Hot fix for category file resets
if (categoryConfig.contains("Categories"))
for (String key : categoryConfig.getConfigurationSection("Categories").getKeys(false)) {
if (categoryManager.getCategories().stream().noneMatch(category -> category.getKey().equals(key)))
categoryConfig.set("Categories." + key, null);
if (this.categoryConfig.contains("Categories")) {
for (String key : this.categoryConfig.getConfigurationSection("Categories").getKeys(false)) {
if (this.categoryManager.getCategories().stream().noneMatch(category -> category.getKey().equals(key))) {
this.categoryConfig.set("Categories." + key, null);
}
}
}
/*
* Save kits from KitManager to Configuration
*/
for (Kit kit : kitManager.getKits()) {
kitConfig.set("Kits." + kit.getKey() + ".delay", kit.getDelay());
kitConfig.set("Kits." + kit.getKey() + ".title", kit.getTitle());
kitConfig.set("Kits." + kit.getKey() + ".link", kit.getLink());
kitConfig.set("Kits." + kit.getKey() + ".price", kit.getPrice());
kitConfig.set("Kits." + kit.getKey() + ".hidden", kit.isHidden());
kitConfig.set("Kits." + kit.getKey() + ".animation", kit.getKitAnimation().name());
if (kit.getCategory() != null)
kitConfig.set("Kits." + kit.getKey() + ".category", kit.getCategory().getKey());
if (kit.getDisplayItem() != null)
kitConfig.set("Kits." + kit.getKey() + ".displayItem", ItemSerializer.serializeItemStackToJson(kit.getDisplayItem()));
else
kitConfig.set("Kits." + kit.getKey() + ".displayItem", null);
for (Kit kit : this.kitManager.getKits()) {
this.kitConfig.set("Kits." + kit.getKey() + ".delay", kit.getDelay());
this.kitConfig.set("Kits." + kit.getKey() + ".title", kit.getTitle());
this.kitConfig.set("Kits." + kit.getKey() + ".link", kit.getLink());
this.kitConfig.set("Kits." + kit.getKey() + ".price", kit.getPrice());
this.kitConfig.set("Kits." + kit.getKey() + ".hidden", kit.isHidden());
this.kitConfig.set("Kits." + kit.getKey() + ".animation", kit.getKitAnimation().name());
if (kit.getCategory() != null) {
this.kitConfig.set("Kits." + kit.getKey() + ".category", kit.getCategory().getKey());
}
if (kit.getDisplayItem() != null) {
this.kitConfig.set("Kits." + kit.getKey() + ".displayItem", ItemSerializer.serializeItemStackToJson(kit.getDisplayItem()));
} else {
this.kitConfig.set("Kits." + kit.getKey() + ".displayItem", null);
}
List<KitItem> contents = kit.getContents();
List<String> strContents = new ArrayList<>();
for (KitItem item : contents) strContents.add(item.getSerialized());
for (KitItem item : contents) {
strContents.add(item.getSerialized());
}
kitConfig.set("Kits." + kit.getKey() + ".items", strContents);
this.kitConfig.set("Kits." + kit.getKey() + ".items", strContents);
}
/*
* Save categories from CategoryManager to Configuration
*/
for (Category category : categoryManager.getCategories()) {
categoryConfig.set("Categories." + category.getKey() + ".name", category.getName());
categoryConfig.set("Categories." + category.getKey() + ".material", category.getMaterial().name());
for (Category category : this.categoryManager.getCategories()) {
this.categoryConfig.set("Categories." + category.getKey() + ".name", category.getName());
this.categoryConfig.set("Categories." + category.getKey() + ".material", category.getMaterial().name());
}
// Save to file
kitConfig.saveChanges();
categoryConfig.saveChanges();
this.kitConfig.saveChanges();
this.categoryConfig.saveChanges();
}
/**
@ -599,15 +579,8 @@ public class UltimateKits extends SongodaPlugin {
return this.displayItemHandler;
}
/**
* @deprecated Will be made private or removed completely in the future.
*/
@Deprecated
public DatabaseConnector getDatabaseConnector() {
return this.databaseConnector;
}
public DataManager getDataManager() {
public DataManager getKitDataManager() {
return this.dataManager;
}

View File

@ -1,11 +1,10 @@
package com.songoda.ultimatekits.category;
package com.craftaro.ultimatekits.category;
import org.bukkit.Material;
import java.util.Objects;
public class Category {
private final String key;
private String name;
private Material material = Material.DIAMOND;
@ -16,11 +15,11 @@ public class Category {
}
public String getKey() {
return key;
return this.key;
}
public String getName() {
return name;
return this.name;
}
public void setName(String name) {
@ -28,7 +27,7 @@ public class Category {
}
public Material getMaterial() {
return material;
return this.material;
}
public void setMaterial(Material material) {
@ -37,14 +36,19 @@ public class Category {
@Override
public int hashCode() {
return Objects.hash(key);
return Objects.hash(this.key);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Category category = (Category) o;
return Objects.equals(key, category.key);
return Objects.equals(this.key, category.key);
}
}

View File

@ -1,8 +1,8 @@
package com.songoda.ultimatekits.category;
package com.craftaro.ultimatekits.category;
import com.songoda.core.utils.TextUtils;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.kit.Kit;
import com.craftaro.core.utils.TextUtils;
import com.craftaro.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.kit.Kit;
import org.bukkit.ChatColor;
import java.util.LinkedHashMap;
@ -11,7 +11,6 @@ import java.util.List;
import java.util.Map;
public class CategoryManager {
private final UltimateKits plugin;
private final Map<String, Category> registeredCategories = new LinkedHashMap<>();
@ -21,33 +20,35 @@ public class CategoryManager {
}
public Category getCategory(String key) {
return registeredCategories.get(key);
return this.registeredCategories.get(key);
}
public Category getCategoryByName(String name) {
return registeredCategories.values().stream()
return this.registeredCategories.values().stream()
.filter(c -> ChatColor.stripColor(TextUtils.formatText(c.getName())).equalsIgnoreCase(name))
.findFirst().orElse(null);
}
public Category addCategory(String key, String name) {
Category category = new Category(key, name);
registeredCategories.put(key, category);
this.registeredCategories.put(key, category);
return category;
}
public void removeCategory(Category category) {
registeredCategories.remove(category.getKey());
for (Kit kit : plugin.getKitManager().getKits())
if (kit.getCategory() == category)
this.registeredCategories.remove(category.getKey());
for (Kit kit : this.plugin.getKitManager().getKits()) {
if (kit.getCategory() == category) {
kit.setCategory(null);
}
}
}
public List<Category> getCategories() {
return new LinkedList(registeredCategories.values());
return new LinkedList<>(this.registeredCategories.values());
}
public void clearCategories() {
registeredCategories.clear();
this.registeredCategories.clear();
}
}

View File

@ -1,16 +1,15 @@
package com.songoda.ultimatekits.commands;
package com.craftaro.ultimatekits.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.core.gui.GuiManager;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.gui.CategoryEditorGui;
import com.craftaro.core.commands.AbstractCommand;
import com.craftaro.core.gui.GuiManager;
import com.craftaro.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.gui.CategoryEditorGui;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
public class CommandCategories extends AbstractCommand {
private final UltimateKits plugin;
private final GuiManager guiManager;
@ -22,7 +21,7 @@ public class CommandCategories extends AbstractCommand {
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
guiManager.showGUI((Player) sender, new CategoryEditorGui(plugin, (Player) sender));
this.guiManager.showGUI((Player) sender, new CategoryEditorGui(this.plugin, (Player) sender));
return ReturnType.SUCCESS;
}

View File

@ -1,10 +1,10 @@
package com.songoda.ultimatekits.commands;
package com.craftaro.ultimatekits.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.crate.Crate;
import com.songoda.ultimatekits.kit.Kit;
import com.songoda.ultimatekits.utils.Methods;
import com.craftaro.core.commands.AbstractCommand;
import com.craftaro.core.utils.NumberUtils;
import com.craftaro.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.crate.Crate;
import com.craftaro.ultimatekits.kit.Kit;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
@ -17,39 +17,43 @@ import java.util.List;
import java.util.stream.Collectors;
public class CommandCrate extends AbstractCommand {
private final UltimateKits plugin;
public CommandCrate() {
public CommandCrate(UltimateKits plugin) {
super(CommandType.CONSOLE_OK, "crate");
this.plugin = plugin;
}
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length < 3 || args.length > 4) return ReturnType.SYNTAX_ERROR;
if (args.length < 3 || args.length > 4) {
return ReturnType.SYNTAX_ERROR;
}
OfflinePlayer target = Bukkit.getPlayer(args[0]);
if (!args[0].equalsIgnoreCase("all") && (target == null || !target.isOnline())) {
UltimateKits.getInstance().getLocale().newMessage("&cThat username does not exist, or the user is offline!").sendPrefixedMessage(sender);
this.plugin.getLocale().newMessage("&cThat username does not exist, or the user is offline!").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}
Kit kit = UltimateKits.getInstance().getKitManager().getKit(args[1]);
Kit kit = this.plugin.getKitManager().getKit(args[1]);
if (kit == null) {
UltimateKits.getInstance().getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(sender);
this.plugin.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}
Crate crate = UltimateKits.getInstance().getCrateManager().getCrate(args[2]);
Crate crate = this.plugin.getCrateManager().getCrate(args[2]);
if (crate == null) {
UltimateKits.getInstance().getLocale().getMessage("command.crate.doesntexist").sendPrefixedMessage(sender);
this.plugin.getLocale().getMessage("command.crate.doesntexist").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}
int amount = 1;
if (args.length > 3) {
if (!Methods.isNumeric(args[3])) {
if (!NumberUtils.isInt(args[3])) {
amount = 0;
} else {
amount = Integer.parseInt(args[3]);
@ -57,7 +61,7 @@ public class CommandCrate extends AbstractCommand {
}
if (amount == 0) {
UltimateKits.getInstance().getLocale().newMessage("&a" + args[3] + " &cis not a number.").sendPrefixedMessage(sender);
this.plugin.getLocale().newMessage("&a" + args[3] + " &cis not a number.").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}
@ -67,7 +71,7 @@ public class CommandCrate extends AbstractCommand {
// Give and send msg to all players online
for (Player loopPlayer : Bukkit.getOnlinePlayers()) {
loopPlayer.getInventory().addItem(item);
UltimateKits.getInstance().getLocale().getMessage("event.crate.given")
this.plugin.getLocale().getMessage("event.crate.given")
.processPlaceholder("kit", kit.getName())
.processPlaceholder("crate", crate.getName())
.sendPrefixedMessage(loopPlayer);
@ -75,14 +79,14 @@ public class CommandCrate extends AbstractCommand {
} else {
// Give to player and send msg
target.getPlayer().getInventory().addItem(item);
UltimateKits.getInstance().getLocale().getMessage("event.crate.given")
this.plugin.getLocale().getMessage("event.crate.given")
.processPlaceholder("kit", kit.getName())
.processPlaceholder("crate", crate.getName())
.sendPrefixedMessage(target.getPlayer());
}
// Send msg to admin
UltimateKits.getInstance().getLocale().getMessage("command.crate.given")
this.plugin.getLocale().getMessage("command.crate.given")
.processPlaceholder("kit", kit.getName())
.processPlaceholder("crate", crate.getName())
.processPlaceholder("player", args[0].equalsIgnoreCase("all") ? "all players" : target.getName());
@ -96,16 +100,17 @@ public class CommandCrate extends AbstractCommand {
if (args.length == 1) {
// Players
tab.add("all");
for (Player player : Bukkit.getOnlinePlayers())
for (Player player : Bukkit.getOnlinePlayers()) {
tab.add(player.getName());
}
return tab;
} else if (args.length == 2) {
// Kits
return UltimateKits.getInstance().getKitManager().getKits().stream()
return this.plugin.getKitManager().getKits().stream()
.map(Kit::getName).collect(Collectors.toList());
} else if (args.length == 3) {
// Crates
return UltimateKits.getInstance().getCrateManager().getRegisteredCrates().stream()
return this.plugin.getCrateManager().getRegisteredCrates().stream()
.map(Crate::getName).collect(Collectors.toList());
} else if (args.length == 4) {
return Collections.singletonList("amount");

View File

@ -1,18 +1,18 @@
package com.songoda.ultimatekits.commands;
package com.craftaro.ultimatekits.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.core.gui.GuiManager;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.gui.KitEditorGui;
import com.songoda.ultimatekits.kit.Kit;
import com.craftaro.core.commands.AbstractCommand;
import com.craftaro.core.gui.GuiManager;
import com.craftaro.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.gui.KitEditorGui;
import com.craftaro.ultimatekits.kit.Kit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class CommandCreatekit extends AbstractCommand {
private final UltimateKits plugin;
private final GuiManager guiManager;
@ -29,21 +29,21 @@ public class CommandCreatekit extends AbstractCommand {
return ReturnType.SYNTAX_ERROR;
}
String kitStr = args[0].toLowerCase().trim();
if (plugin.getKitManager().getKit(kitStr) != null) {
plugin.getLocale().getMessage("command.kit.kitalreadyexists").sendPrefixedMessage(player);
if (this.plugin.getKitManager().getKit(kitStr) != null) {
this.plugin.getLocale().getMessage("command.kit.kitalreadyexists").sendPrefixedMessage(player);
return ReturnType.FAILURE;
}
plugin.getLocale().newMessage("&aThat kit doesn't exist. Creating it now.").sendPrefixedMessage(player);
this.plugin.getLocale().newMessage("&aThat kit doesn't exist. Creating it now.").sendPrefixedMessage(player);
Kit kit = new Kit(kitStr);
plugin.getKitManager().addKit(kit);
guiManager.showGUI(player, new KitEditorGui(plugin, player, kit, null));
this.plugin.getKitManager().addKit(kit);
this.guiManager.showGUI(player, new KitEditorGui(this.plugin, player, kit, null));
return ReturnType.SUCCESS;
}
@Override
protected List<String> onTab(CommandSender sender, String... args) {
return Arrays.asList("name");
return Collections.singletonList("name");
}
@Override

View File

@ -1,12 +1,12 @@
package com.songoda.ultimatekits.commands;
package com.craftaro.ultimatekits.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.core.gui.GuiManager;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.gui.BlockEditorGui;
import com.songoda.ultimatekits.gui.KitEditorGui;
import com.songoda.ultimatekits.kit.Kit;
import com.songoda.ultimatekits.kit.KitBlockData;
import com.craftaro.core.commands.AbstractCommand;
import com.craftaro.core.gui.GuiManager;
import com.craftaro.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.gui.BlockEditorGui;
import com.craftaro.ultimatekits.gui.KitEditorGui;
import com.craftaro.ultimatekits.kit.Kit;
import com.craftaro.ultimatekits.kit.KitBlockData;
import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -15,7 +15,6 @@ import java.util.ArrayList;
import java.util.List;
public class CommandEdit extends AbstractCommand {
private final UltimateKits plugin;
private final GuiManager guiManager;
@ -27,25 +26,27 @@ public class CommandEdit extends AbstractCommand {
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length > 1) return ReturnType.SYNTAX_ERROR;
if (args.length > 1) {
return ReturnType.SYNTAX_ERROR;
}
final Player player = (Player) sender;
if (args.length == 0) {
Block block = player.getTargetBlock(null, 200);
KitBlockData kitBlockData = plugin.getKitManager().getKit(block.getLocation());
KitBlockData kitBlockData = this.plugin.getKitManager().getKit(block.getLocation());
if (kitBlockData == null) {
plugin.getLocale().newMessage("command.kit.nokitatblock").sendPrefixedMessage(player);
this.plugin.getLocale().newMessage("command.kit.nokitatblock").sendPrefixedMessage(player);
return ReturnType.FAILURE;
}
guiManager.showGUI(player, new BlockEditorGui(plugin, kitBlockData));
this.guiManager.showGUI(player, new BlockEditorGui(this.plugin, kitBlockData));
} else {
String kitStr = args[0].toLowerCase().trim();
if (plugin.getKitManager().getKit(kitStr) == null) {
plugin.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(player);
if (this.plugin.getKitManager().getKit(kitStr) == null) {
this.plugin.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(player);
return ReturnType.FAILURE;
}
guiManager.showGUI(player, new KitEditorGui(plugin, player, plugin.getKitManager().getKit(kitStr), null));
this.guiManager.showGUI(player, new KitEditorGui(this.plugin, player, this.plugin.getKitManager().getKit(kitStr), null));
}
return ReturnType.SUCCESS;
}
@ -53,11 +54,13 @@ public class CommandEdit extends AbstractCommand {
@Override
protected List<String> onTab(CommandSender sender, String... args) {
List<String> tab = new ArrayList<>();
if (args.length == 1) {
for (Kit kit : plugin.getKitManager().getKits())
for (Kit kit : this.plugin.getKitManager().getKits()) {
tab.add(kit.getKey());
return tab;
}
}
return tab;
}

View File

@ -1,21 +1,20 @@
package com.songoda.ultimatekits.commands;
package com.craftaro.ultimatekits.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.core.utils.PlayerUtils;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.key.Key;
import com.songoda.ultimatekits.kit.Kit;
import com.songoda.ultimatekits.utils.Methods;
import com.craftaro.core.commands.AbstractCommand;
import com.craftaro.core.utils.NumberUtils;
import com.craftaro.core.utils.PlayerUtils;
import com.craftaro.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.key.Key;
import com.craftaro.ultimatekits.kit.Kit;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class CommandKey extends AbstractCommand {
private final UltimateKits plugin;
public CommandKey(UltimateKits plugin) {
@ -28,46 +27,46 @@ public class CommandKey extends AbstractCommand {
if (args.length != 3 && args.length != 4) {
return ReturnType.SYNTAX_ERROR;
}
Kit kit = plugin.getKitManager().getKit(args[0]);
if (kit == null && !args[0].toLowerCase().equals("all")) {
plugin.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(sender);
Kit kit = this.plugin.getKitManager().getKit(args[0]);
if (kit == null && !args[0].equalsIgnoreCase("all")) {
this.plugin.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}
Player playerTo = null;
if (!args[2].trim().equalsIgnoreCase("all") && (playerTo = Bukkit.getPlayer(args[2])) == null) {
plugin.getLocale().newMessage("&cThat username does not exist, or the user is offline!").sendPrefixedMessage(sender);
this.plugin.getLocale().newMessage("&cThat username does not exist, or the user is offline!").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}
int amt = 1;
if (args.length == 4) {
if (!Methods.isNumeric(args[3])) {
if (!NumberUtils.isInt(args[3])) {
amt = 0;
} else {
amt = Integer.parseInt(args[3]);
}
}
if (amt == 0) {
plugin.getLocale().newMessage("&a" + args[3] + " &cis not a number.").sendPrefixedMessage(sender);
this.plugin.getLocale().newMessage("&a" + args[3] + " &cis not a number.").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}
Key key = plugin.getKeyManager().getKey(args[1]);
Key key = this.plugin.getKeyManager().getKey(args[1]);
if (key == null) {
plugin.getLocale().newMessage("&a" + args[1] + " &cis not a key.").sendPrefixedMessage(sender);
this.plugin.getLocale().newMessage("&a" + args[1] + " &cis not a key.").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}
if (playerTo != null) {
PlayerUtils.giveItem(playerTo, key.getKeyItem(kit, amt));
plugin.getLocale().getMessage("event.key.given")
this.plugin.getLocale().getMessage("event.key.given")
.processPlaceholder("kit", kit == null ? "Any" : kit.getName())
.sendPrefixedMessage(playerTo);
return ReturnType.SUCCESS;
}
for (Player pl : plugin.getServer().getOnlinePlayers()) {
for (Player pl : this.plugin.getServer().getOnlinePlayers()) {
PlayerUtils.giveItem(pl, key.getKeyItem(kit, amt));
plugin.getLocale().getMessage("event.key.given")
this.plugin.getLocale().getMessage("event.key.given")
.processPlaceholder("kit", kit == null ? "Any" : kit.getName())
.sendPrefixedMessage(pl);
}
@ -76,25 +75,32 @@ public class CommandKey extends AbstractCommand {
@Override
protected List<String> onTab(CommandSender sender, String... args) {
if (!(sender instanceof Player)) return null;
if (!(sender instanceof Player)) {
return null;
}
List<String> tab = new ArrayList<>();
if (args.length == 1) {
tab.add("all");
for (Kit kit : UltimateKits.getInstance().getKitManager().getKits())
for (Kit kit : this.plugin.getKitManager().getKits()) {
tab.add(kit.getKey());
}
return tab;
} else if (args.length == 2) {
for (Key key : UltimateKits.getInstance().getKeyManager().getKeys())
for (Key key : this.plugin.getKeyManager().getKeys()) {
tab.add(key.getName());
}
return tab;
} else if (args.length == 3) {
tab.add("all");
for (Player player : Bukkit.getOnlinePlayers())
for (Player player : Bukkit.getOnlinePlayers()) {
tab.add(player.getName());
}
return tab;
} else if (args.length == 4) return Arrays.asList("amount");
} else if (args.length == 4) {
return Collections.singletonList("amount");
}
return tab;
}
@ -106,7 +112,7 @@ public class CommandKey extends AbstractCommand {
@Override
public String getSyntax() {
StringBuilder keys = new StringBuilder();
for (Key key : UltimateKits.getInstance().getKeyManager().getKeys()) {
for (Key key : this.plugin.getKeyManager().getKeys()) {
keys.append("/").append(key.getName());
}
return "key <kit/all> <" + keys.substring(1) + "> <player/all> <amount>";

View File

@ -1,11 +1,11 @@
package com.songoda.ultimatekits.commands;
package com.craftaro.ultimatekits.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.core.gui.GuiManager;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.gui.CategorySelectorGui;
import com.songoda.ultimatekits.gui.KitSelectorGui;
import com.songoda.ultimatekits.kit.Kit;
import com.craftaro.core.commands.AbstractCommand;
import com.craftaro.core.gui.GuiManager;
import com.craftaro.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.gui.CategorySelectorGui;
import com.craftaro.ultimatekits.gui.KitSelectorGui;
import com.craftaro.ultimatekits.kit.Kit;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -14,7 +14,6 @@ import java.util.ArrayList;
import java.util.List;
public class CommandKit extends AbstractCommand {
private final UltimateKits plugin;
private final GuiManager guiManager;
@ -26,46 +25,50 @@ public class CommandKit extends AbstractCommand {
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length > 2) return ReturnType.SYNTAX_ERROR;
if (args.length > 2) {
return ReturnType.SYNTAX_ERROR;
}
if (args.length == 0 && sender instanceof Player) {
// /kit - Opens GUI.
if (plugin.getKitManager().getKits().stream().anyMatch(kit -> kit.getCategory() != null))
guiManager.showGUI((Player) sender, new CategorySelectorGui(plugin, (Player) sender));
else
guiManager.showGUI((Player) sender, new KitSelectorGui(plugin, (Player) sender, null));
if (this.plugin.getKitManager().getKits().stream().anyMatch(kit -> kit.getCategory() != null)) {
this.guiManager.showGUI((Player) sender, new CategorySelectorGui(this.plugin, (Player) sender));
} else {
this.guiManager.showGUI((Player) sender, new KitSelectorGui(this.plugin, (Player) sender, null));
}
return ReturnType.SUCCESS;
}
if (plugin.getKitManager().getKit(args[0]) == null) {
plugin.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(sender);
if (this.plugin.getKitManager().getKit(args[0]) == null) {
this.plugin.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}
Kit kit = plugin.getKitManager().getKit(args[0]);
Kit kit = this.plugin.getKitManager().getKit(args[0]);
if (args.length == 1) {
// /kit <kit> - Gives kit to self.
if (!(sender instanceof Player))
if (!(sender instanceof Player)) {
return ReturnType.NEEDS_PLAYER;
}
if (!kit.hasPermissionToClaim((Player) sender)) {
plugin.getLocale().getMessage("command.general.noperms").sendPrefixedMessage(sender);
this.plugin.getLocale().getMessage("command.general.noperms").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}
kit.processGenericUse((Player) sender, false);
return ReturnType.SUCCESS;
} else if (args.length == 2) {
} else {
// /kit <kit> <player> - Gives kit to another player.
if (!sender.hasPermission("ultimatekits.admin")) {
plugin.getLocale().getMessage("command.general.noperms").sendPrefixedMessage(sender);
this.plugin.getLocale().getMessage("command.general.noperms").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}
if (!args[1].equalsIgnoreCase("all") && Bukkit.getPlayer(args[1]) == null) {
plugin.getLocale().newMessage("&cThat username does not exist, or the user is offline!").sendPrefixedMessage(sender);
this.plugin.getLocale().newMessage("&cThat username does not exist, or the user is offline!").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}
@ -74,34 +77,36 @@ public class CommandKit extends AbstractCommand {
if (player != null) {
kit.processGenericUse(player, true);
plugin.getLocale().getMessage("event.claim.givesuccess")
this.plugin.getLocale().getMessage("event.claim.givesuccess")
.processPlaceholder("kit", kit.getName())
.sendPrefixedMessage(sender);
} else {
Bukkit.getOnlinePlayers().forEach(onlinePlayer -> {
kit.processGenericUse(onlinePlayer, true);
plugin.getLocale().getMessage("event.claim.givesuccess")
this.plugin.getLocale().getMessage("event.claim.givesuccess")
.processPlaceholder("kit", kit.getName())
.sendPrefixedMessage(sender);
});
}
plugin.getLocale().newMessage("&7You gave &9" + who + "&7 kit &9" + kit.getName() + "&7.")
this.plugin.getLocale().newMessage("&7You gave &9" + who + "&7 kit &9" + kit.getName() + "&7.")
.sendPrefixedMessage(sender);
return ReturnType.SUCCESS;
}
return ReturnType.SYNTAX_ERROR;
}
@Override
protected List<String> onTab(CommandSender sender, String... args) {
List<String> tab = new ArrayList<>();
if (!(sender instanceof Player)) return tab;
if (!(sender instanceof Player)) {
return tab;
}
if (args.length == 1) {
for (Kit kit : plugin.getKitManager().getKits()) tab.add(kit.getKey());
for (Kit kit : this.plugin.getKitManager().getKits()) {
tab.add(kit.getKey());
}
} else if (args.length == 2) {
tab.add("all");
Bukkit.getOnlinePlayers().forEach(player -> tab.add(player.getName()));

View File

@ -1,9 +1,9 @@
package com.songoda.ultimatekits.commands;
package com.craftaro.ultimatekits.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.core.gui.GuiManager;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.kit.Kit;
import com.craftaro.core.commands.AbstractCommand;
import com.craftaro.core.gui.GuiManager;
import com.craftaro.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.kit.Kit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -11,7 +11,6 @@ import java.util.ArrayList;
import java.util.List;
public class CommandPreviewKit extends AbstractCommand {
private final UltimateKits plugin;
private final GuiManager guiManager;
@ -25,15 +24,15 @@ public class CommandPreviewKit extends AbstractCommand {
protected ReturnType runCommand(CommandSender sender, String... args) {
Player player = (Player) sender;
if (args.length != 1) {
plugin.getLocale().getMessage("command.kit.nokitsupplied").sendPrefixedMessage(player);
this.plugin.getLocale().getMessage("command.kit.nokitsupplied").sendPrefixedMessage(player);
return ReturnType.FAILURE;
}
Kit kit = plugin.getKitManager().getKit(args[0].toLowerCase().trim());
Kit kit = this.plugin.getKitManager().getKit(args[0].toLowerCase().trim());
if (kit == null) {
plugin.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(player);
this.plugin.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(player);
return ReturnType.FAILURE;
}
kit.display(player, guiManager, null);
kit.display(player, this.guiManager, null);
return ReturnType.SUCCESS;
}
@ -45,7 +44,7 @@ public class CommandPreviewKit extends AbstractCommand {
if (args.length == 2) {
List<String> tab = new ArrayList<>();
for (Kit kit : UltimateKits.getInstance().getKitManager().getKits()) {
for (Kit kit : this.plugin.getKitManager().getKits()) {
tab.add(kit.getKey());
}
return tab;

View File

@ -1,14 +1,13 @@
package com.songoda.ultimatekits.commands;
package com.craftaro.ultimatekits.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.ultimatekits.UltimateKits;
import com.craftaro.core.commands.AbstractCommand;
import com.craftaro.ultimatekits.UltimateKits;
import org.bukkit.command.CommandSender;
import java.util.ArrayList;
import java.util.List;
public class CommandReload extends AbstractCommand {
private final UltimateKits plugin;
public CommandReload(UltimateKits plugin) {
@ -18,8 +17,8 @@ public class CommandReload extends AbstractCommand {
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
plugin.reloadConfig();
plugin.getLocale().getMessage("&7Configuration and Language files reloaded.").sendPrefixedMessage(sender);
this.plugin.reloadConfig();
this.plugin.getLocale().getMessage("&7Configuration and Language files reloaded.").sendPrefixedMessage(sender);
return ReturnType.SUCCESS;
}

View File

@ -1,9 +1,9 @@
package com.songoda.ultimatekits.commands;
package com.craftaro.ultimatekits.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.core.hooks.HologramManager;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.kit.Kit;
import com.craftaro.core.commands.AbstractCommand;
import com.craftaro.core.hooks.HologramManager;
import com.craftaro.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.kit.Kit;
import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -12,7 +12,6 @@ import java.util.ArrayList;
import java.util.List;
public class CommandRemove extends AbstractCommand {
private final UltimateKits plugin;
public CommandRemove(UltimateKits plugin) {
@ -24,16 +23,18 @@ public class CommandRemove extends AbstractCommand {
protected ReturnType runCommand(CommandSender sender, String... args) {
Player player = (Player) sender;
Block block = player.getTargetBlock(null, 200);
Kit kit = plugin.getKitManager().removeKitFromLocation(block.getLocation());
if (kit == null) return ReturnType.FAILURE;
if (HologramManager.isEnabled()) {
plugin.getKitManager().getKitLocations().values().stream()
.filter(data -> data.getKit() == kit)
.forEach(data -> plugin.removeHologram(data));
Kit kit = this.plugin.getKitManager().removeKitFromLocation(block.getLocation());
if (kit == null) {
return ReturnType.FAILURE;
}
plugin.getLocale().newMessage("&8Kit &9" + kit.getKey() + " &8unassigned from: &a" + block.getType().toString() + "&8.").sendPrefixedMessage(player);
if (HologramManager.isEnabled()) {
this.plugin.getKitManager().getKitLocations().values().stream()
.filter(data -> data.getKit() == kit)
.forEach(this.plugin::removeHologram);
}
this.plugin.getLocale().newMessage("&8Kit &9" + kit.getKey() + " &8unassigned from: &a" + block.getType() + "&8.").sendPrefixedMessage(player);
return ReturnType.SUCCESS;
}

View File

@ -1,9 +1,9 @@
package com.songoda.ultimatekits.commands;
package com.craftaro.ultimatekits.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.kit.Kit;
import com.songoda.ultimatekits.kit.KitBlockData;
import com.craftaro.core.commands.AbstractCommand;
import com.craftaro.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.kit.Kit;
import com.craftaro.ultimatekits.kit.KitBlockData;
import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -12,7 +12,6 @@ import java.util.ArrayList;
import java.util.List;
public class CommandSet extends AbstractCommand {
private final UltimateKits plugin;
public CommandSet(UltimateKits plugin) {
@ -23,19 +22,19 @@ public class CommandSet extends AbstractCommand {
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length != 1) {
plugin.getLocale().getMessage("command.kit.nokitsupplied").sendPrefixedMessage(sender);
this.plugin.getLocale().getMessage("command.kit.nokitsupplied").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}
Player player = (Player) sender;
Kit kit = plugin.getKitManager().getKit(args[0].toLowerCase());
Kit kit = this.plugin.getKitManager().getKit(args[0].toLowerCase());
if (kit == null) {
plugin.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(sender);
this.plugin.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}
Block b = player.getTargetBlock(null, 200);
KitBlockData data = plugin.getKitManager().addKitToLocation(kit, b.getLocation());
UltimateKits.getInstance().getDataManager().createBlockData(data);
plugin.getLocale().newMessage("&8Kit &a" + kit.getKey() + " &8set to: &a" + b.getType().toString() + "&8.")
KitBlockData data = this.plugin.getKitManager().addKitToLocation(kit, b.getLocation());
this.plugin.getKitDataManager().createBlockData(data);
this.plugin.getLocale().newMessage("&8Kit &a" + kit.getKey() + " &8set to: &a" + b.getType() + "&8.")
.sendPrefixedMessage(sender);
return ReturnType.SUCCESS;
@ -49,7 +48,7 @@ public class CommandSet extends AbstractCommand {
if (args.length == 1) {
List<String> tab = new ArrayList<>();
for (Kit kit : UltimateKits.getInstance().getKitManager().getKits()) {
for (Kit kit : this.plugin.getKitManager().getKits()) {
tab.add(kit.getKey());
}
return tab;

View File

@ -1,9 +1,9 @@
package com.songoda.ultimatekits.commands;
package com.craftaro.ultimatekits.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.core.configuration.editor.PluginConfigGui;
import com.songoda.core.gui.GuiManager;
import com.songoda.ultimatekits.UltimateKits;
import com.craftaro.core.commands.AbstractCommand;
import com.craftaro.core.configuration.editor.PluginConfigGui;
import com.craftaro.core.gui.GuiManager;
import com.craftaro.ultimatekits.UltimateKits;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -11,7 +11,6 @@ import java.util.ArrayList;
import java.util.List;
public class CommandSettings extends AbstractCommand {
private final UltimateKits plugin;
private final GuiManager guiManager;
@ -23,7 +22,7 @@ public class CommandSettings extends AbstractCommand {
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
guiManager.showGUI((Player) sender, new PluginConfigGui(plugin));
this.guiManager.showGUI((Player) sender, new PluginConfigGui(this.plugin));
return ReturnType.SUCCESS;
}

View File

@ -1,12 +1,12 @@
package com.songoda.ultimatekits.conversion;
package com.craftaro.ultimatekits.conversion;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.conversion.hooks.CMIHook;
import com.songoda.ultimatekits.conversion.hooks.DefaultHook;
import com.songoda.ultimatekits.conversion.hooks.EssentialsHook;
import com.songoda.ultimatekits.conversion.hooks.UltimateCoreHook;
import com.songoda.ultimatekits.kit.Kit;
import com.songoda.ultimatekits.kit.KitItem;
import com.craftaro.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.conversion.hooks.CMIHook;
import com.craftaro.ultimatekits.conversion.hooks.DefaultHook;
import com.craftaro.ultimatekits.conversion.hooks.EssentialsHook;
import com.craftaro.ultimatekits.conversion.hooks.UltimateCoreHook;
import com.craftaro.ultimatekits.kit.Kit;
import com.craftaro.ultimatekits.kit.KitItem;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
@ -15,9 +15,8 @@ import java.util.List;
import java.util.Set;
public class Convert {
public static void runKitConversions() {
if (!UltimateKits.getInstance().getKitConfig().contains("Kits")) {
public static void runKitConversions(UltimateKits plugin) {
if (!plugin.getKitConfig().contains("Kits")) {
if (Bukkit.getPluginManager().isPluginEnabled("Essentials")) {
try {
Class.forName("com.earth2me.essentials.metrics.MetricsListener");
@ -42,9 +41,13 @@ public class Convert {
Set<String> kits = hook.getKits();
for (String kit : kits) {
Kit kitObj = UltimateKits.getInstance().getKitManager().addKit(new Kit(kit));
if (kitObj == null) continue;
if (kitObj == null) {
continue;
}
for (ItemStack item : hook.getItems(kit)) {
if (item == null || item.getType() == Material.AIR) continue;
if (item == null || item.getType() == Material.AIR) {
continue;
}
kitObj.getContents().add(new KitItem(item));
}
kitObj.setDelay(hook.getDelay(kit));
@ -56,17 +59,21 @@ public class Convert {
}
private static boolean isInJsonFormat() {
if (!UltimateKits.getInstance().getKitConfig().contains("Kits")) return false;
if (!UltimateKits.getInstance().getKitConfig().contains("Kits")) {
return false;
}
for (String kit : UltimateKits.getInstance().getKitConfig().getConfigurationSection("Kits").getKeys(false)) {
if (UltimateKits.getInstance().getKitConfig().contains("Kits." + kit + ".items")) {
List<String> itemList = UltimateKits.getInstance().getKitConfig().getStringList("Kits." + kit + ".items");
if (itemList.size() > 0) {
if (!itemList.isEmpty()) {
if (itemList.get(0).startsWith("{")) {
return true;
}
}
}
}
return false;
}
}
}

View File

@ -0,0 +1,13 @@
package com.craftaro.ultimatekits.conversion;
import org.bukkit.inventory.ItemStack;
import java.util.Set;
public interface Hook {
Set<String> getKits();
Set<ItemStack> getItems(String kitName);
long getDelay(String kitName);
}

View File

@ -1,46 +1,47 @@
package com.songoda.ultimatekits.conversion.hooks;
package com.craftaro.ultimatekits.conversion.hooks;
import com.Zrips.CMI.CMI;
import com.Zrips.CMI.Modules.Kits.Kit;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.conversion.Hook;
import com.songoda.ultimatekits.kit.type.KitContentCommand;
import com.craftaro.ultimatekits.conversion.Hook;
import com.craftaro.ultimatekits.kit.type.KitContentCommand;
import org.bukkit.Bukkit;
import org.bukkit.inventory.ItemStack;
import java.util.HashSet;
import java.util.Set;
public class CMIHook implements Hook {
private CMI cmi;
private final CMI cmi;
public CMIHook() {
cmi = (CMI) UltimateKits.getInstance().getServer().getPluginManager().getPlugin("CMI");
this.cmi = (CMI) Bukkit.getPluginManager().getPlugin("CMI");
}
public Set<ItemStack> getItems(String kitName) {
Set<ItemStack> stacks = new HashSet<>();
try {
Kit kit = cmi.getKitsManager().getKit(kitName, true);
Kit kit = this.cmi.getKitsManager().getKit(kitName, true);
for (ItemStack item : kit.getItems()) {
if (item != null) stacks.add(item);
if (item != null) {
stacks.add(item);
}
}
for (String command : kit.getCommands()) {
stacks.add(new KitContentCommand(command).getItemForDisplay());
}
} catch (Exception e) {
e.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
}
return stacks;
}
public Set<String> getKits() {
return cmi.getKitsManager().getKitMap().keySet();
return this.cmi.getKitsManager().getKitMap().keySet();
}
public long getDelay(String kitName) {
return cmi.getKitsManager().getKit(kitName, true).getDelay();
return this.cmi.getKitsManager().getKit(kitName, true).getDelay();
}
}

View File

@ -1,8 +1,8 @@
package com.songoda.ultimatekits.conversion.hooks;
package com.craftaro.ultimatekits.conversion.hooks;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.ultimatekits.conversion.Hook;
import com.songoda.ultimatekits.utils.ItemSerializer;
import com.craftaro.core.compatibility.ServerVersion;
import com.craftaro.ultimatekits.conversion.Hook;
import com.craftaro.ultimatekits.utils.ItemSerializer;
import org.bukkit.inventory.ItemStack;
import java.util.HashSet;
@ -13,7 +13,10 @@ public class DefaultHook implements Hook {
Set<ItemStack> items = new HashSet<>();
for (Kits kit : Kits.values()) {
if (!kit.name().equalsIgnoreCase(kitName)) continue;
if (!kit.name().equalsIgnoreCase(kitName)) {
continue;
}
for (String string : kit.items) {
items.add(ItemSerializer.deserializeItemStackFromJson(string));
}
@ -27,7 +30,9 @@ public class DefaultHook implements Hook {
for (Kits kit : Kits.values()) {
if (kit == Kits.BRIANNA_1_12 && ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)
|| kit == Kits.BRIANNA_1_13 && !ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) continue;
|| kit == Kits.BRIANNA_1_13 && !ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
continue;
}
kits.add(kit.name().toLowerCase().replace("_1_12", "").replace("_1_13", ""));
}
@ -36,7 +41,9 @@ public class DefaultHook implements Hook {
public long getDelay(String kitName) {
for (Kits kit : Kits.values()) {
if (!kit.name().equalsIgnoreCase(kitName)) continue;
if (!kit.name().equalsIgnoreCase(kitName)) {
continue;
}
return kit.delay;
}
return 0;
@ -57,8 +64,8 @@ public class DefaultHook implements Hook {
BRIANNA_1_13(0, "{id:\"minecraft:player_head\",Count:1b,tag:{SkullOwner:{Id:\"2626974f-5838-44c6-994d-f6c723d40b79\",Properties:{textures:[{Signature:\"tQRjs3H+5H5A8Id/Hb2a3E+VDQY8sUKQYacc9ZYDsBncagNO6imX6h6qsDmtTDtliTh8ZzHRIAw/6gQeiODJnOm4PAB2vPnUv0VFAP2awbikJeOSuK3WZsvcUN78+hXLFFtvBUt/oGKpsTj5P//2+qH7QLqmrxFD72jGpmyS8Fp6AHuQqzeHn40isvKT2+oTItFb3wQ3H2QgudGxEhOX6Onz0M2xmH61+HF5ajPS+/2hUl5kjRk8uRLc2AJD162dECdYOUJ8/j47Fl9pJXG1dcG6cGMuRlDAim3AqfdJFTW0CI78YEpTTGZcLL+O+/yUMQD9hOQqjP7y63YIOZ9kAZ7DRzu5hQaHLevhUcTwZnkqs+F9eUuQR00y8PoVoSEOMrV4LIWAJFutdziNZX9I7MI9tJ0x96imA18yYC9Skwx7JHurC1wpdtSqS/F7gCeU3+2QiFufxX9ft9BPHSBX7z08nqQkwxYh0O/06OX+H0NJTLwYrK+hoTXT1A5dNrJIHzGuK9/qUaitH4yz0zv5aGd3vVytdKCULFqOTiqur1QYPvF9sI2fhvfcHqUc30yU1di0Ws5SOQzCAFLOypjUH1ezQMOK+Xy3ixB0a8HXI9RL8ewOvKaVepbWS1vomNNWfiCgpudbLW8x6bPvQLmZn8YWPjCAL0WFycnw8lm6JDg=\",Value:\"eyJ0aW1lc3RhbXAiOjE1NzA5MDI0MDg4ODEsInByb2ZpbGVJZCI6IjA2Y2NiMGU0MWM3NjQ0YjE5OGZiYzk5OTBhODcwNjAwIiwicHJvZmlsZU5hbWUiOiJCcmlhbm5hIiwic2lnbmF0dXJlUmVxdWlyZWQiOnRydWUsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS8yN2I3MjM5Yzk2OWNhNzY0NWJmMTQzODc4M2Y1Y2FiZjdlMDhhYTViODY4OGFkODg3NWJhNzNlNTVhNDBlMjIiLCJtZXRhZGF0YSI6eyJtb2RlbCI6InNsaW0ifX19fQ==\"}]},Name:\"Brianna\"},Damage:3}}");
public String[] items;
public int delay;
public final String[] items;
public final int delay;
Kits(int delay, String... items) {
this.items = items;

View File

@ -1,10 +1,10 @@
package com.songoda.ultimatekits.conversion.hooks;
package com.craftaro.ultimatekits.conversion.hooks;
import com.craftaro.ultimatekits.conversion.Hook;
import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.Kit;
import com.earth2me.essentials.MetaItemStack;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.conversion.Hook;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
@ -12,39 +12,38 @@ import java.util.HashSet;
import java.util.Set;
public class EssentialsHook implements Hook {
private Essentials essentials;
private final Essentials essentials;
public EssentialsHook() {
essentials = (Essentials) UltimateKits.getInstance().getServer().getPluginManager().getPlugin("Essentials");
this.essentials = (Essentials) Bukkit.getServer().getPluginManager().getPlugin("Essentials");
}
public Set<ItemStack> getItems(String kitName) {
Set<ItemStack> stacks = new HashSet<>();
try {
Kit kit = new Kit(kitName, essentials);
Kit kit = new Kit(kitName, this.essentials);
for (String nonParse : kit.getItems()) {
String[] parts = nonParse.split(" +");
ItemStack item = essentials.getItemDb().get(parts[0], parts.length > 1 ? Integer.parseInt(parts[1]) : 1);
ItemStack item = this.essentials.getItemDb().get(parts[0], parts.length > 1 ? Integer.parseInt(parts[1]) : 1);
MetaItemStack metaStack = new MetaItemStack(item);
if (parts.length > 2 != nonParse.startsWith("/")) {
try {
metaStack.parseStringMeta(null, true, parts, 2, essentials);
} catch (Exception e) {
e.printStackTrace();
metaStack.parseStringMeta(null, true, parts, 2, this.essentials);
} catch (Exception ex) {
ex.printStackTrace();
}
}
stacks.add(metaStack.getItemStack());
}
} catch (Exception e) {
e.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
}
return stacks;
}
public Set<String> getKits() {
ConfigurationSection cs = essentials.getSettings().getKits();
ConfigurationSection cs = this.essentials.getSettings().getKits();
Set<String> kits = new HashSet<>();
try {
cs.getKeys(false);
@ -56,11 +55,11 @@ public class EssentialsHook implements Hook {
}
public long getDelay(String kitName) {
Object object = essentials.getSettings().getKit(kitName).getOrDefault("delay", 0);
Object object = this.essentials.getSettings().getKit(kitName).getOrDefault("delay", 0);
try {
return Integer.toUnsignedLong((int) object);
} catch (Exception e) {
} catch (Exception ex) {
return (long) object;
}
}
}
}

View File

@ -1,8 +1,8 @@
package com.songoda.ultimatekits.conversion.hooks;
package com.craftaro.ultimatekits.conversion.hooks;
import bammerbom.ultimatecore.bukkit.api.UC;
import bammerbom.ultimatecore.bukkit.api.UKit;
import com.songoda.ultimatekits.conversion.Hook;
import com.craftaro.ultimatekits.conversion.Hook;
import org.bukkit.inventory.ItemStack;
import java.util.HashSet;
@ -10,7 +10,6 @@ import java.util.List;
import java.util.Set;
public class UltimateCoreHook implements Hook {
@Override
public Set<String> getKits() {
Set<String> list = new HashSet<>();
@ -22,14 +21,13 @@ public class UltimateCoreHook implements Hook {
}
@Override
public Set<ItemStack> getItems(String kit) {
UKit uKit = new UKit(kit);
Set<ItemStack> items = new HashSet<>(uKit.getItems());
return items;
public Set<ItemStack> getItems(String kitName) {
UKit uKit = new UKit(kitName);
return new HashSet<>(uKit.getItems());
}
@Override
public long getDelay(String kit) {
public long getDelay(String kitName) {
return 0;
}
}

View File

@ -1,8 +1,8 @@
package com.songoda.ultimatekits.crate;
package com.craftaro.ultimatekits.crate;
import com.songoda.core.utils.TextUtils;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.kit.Kit;
import com.craftaro.core.utils.TextUtils;
import com.craftaro.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.kit.Kit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
@ -13,7 +13,6 @@ import java.util.ArrayList;
import java.util.List;
public class Crate {
// Name of the crate
private String name;
@ -35,51 +34,55 @@ public class Crate {
ItemStack itemStack = new ItemStack(Material.CHEST, amount);
String kitName;
if (kit != null)
if (kit != null) {
kitName = TextUtils.formatText(kit.getName(), true);
else
} else {
kitName = "Any";
}
ItemMeta meta = itemStack.getItemMeta();
meta.setDisplayName(plugin.getLocale().getMessage("interface.crate.title")
.processPlaceholder("kit", kitName)
.processPlaceholder("crate", name)
.processPlaceholder("crate", this.name)
.getMessage());
meta.addEnchant(Enchantment.DURABILITY, 1, true);
List<String> lore = new ArrayList<>();
// Dtools Ultra Crate
lore.add(ChatColor.DARK_PURPLE + kitName + " " + ChatColor.YELLOW + name + " " + ChatColor.WHITE + "Crate");
lore.add(ChatColor.DARK_PURPLE + kitName + " " + ChatColor.YELLOW + this.name + " " + ChatColor.WHITE + "Crate");
String desc1 = plugin.getLocale().getMessage("interface.crate.description1")
.processPlaceholder("kit", kitName)
.processPlaceholder("crate", name)
.processPlaceholder("crate", this.name)
.getMessage();
if (kitName.equals("Any"))
if (kitName.equals("Any")) {
desc1 = desc1.replaceAll("\\[.*?]", "");
else
} else {
desc1 = desc1.replace("[", "").replace("]", "");
}
lore.add(desc1);
if (this.amount == -1)
if (this.amount == -1) {
lore.add(plugin.getLocale().getMessage("interface.crate.description2")
.processPlaceholder("kit", kitName)
.processPlaceholder("crate", name)
.processPlaceholder("crate", this.name)
.getMessage());
else
} else {
lore.add(plugin.getLocale().getMessage("interface.crate.description3")
.processPlaceholder("kit", kitName)
.processPlaceholder("crate", name)
.processPlaceholder("crate", this.name)
.getMessage());
if (kitAmount > 1)
}
if (this.kitAmount > 1) {
lore.add(plugin.getLocale().getMessage("interface.crate.description4")
.processPlaceholder("amt", this.kitAmount)
.processPlaceholder("kit", kitName)
.processPlaceholder("crate", name)
.processPlaceholder("crate", this.name)
.getMessage());
}
meta.setLore(lore);
@ -89,7 +92,7 @@ public class Crate {
}
public String getName() {
return name;
return this.name;
}
public void setName(String name) {
@ -97,7 +100,7 @@ public class Crate {
}
public int getAmount() {
return amount;
return this.amount;
}
public void setAmount(int amount) {
@ -105,7 +108,7 @@ public class Crate {
}
public int getKitAmount() {
return kitAmount;
return this.kitAmount;
}
public void setKitAmount(int kitAmount) {

View File

@ -1,4 +1,4 @@
package com.songoda.ultimatekits.crate;
package com.craftaro.ultimatekits.crate;
import org.bukkit.ChatColor;
import org.bukkit.Material;
@ -9,32 +9,34 @@ import java.util.HashSet;
import java.util.Set;
public class CrateManager {
private final Set<Crate> registeredCrates = new HashSet<>();
public boolean addCrate(Crate crate) {
return crate != null && registeredCrates.add(crate);
return crate != null && this.registeredCrates.add(crate);
}
public Crate getCrate(String name) {
for (Crate crate : registeredCrates)
if (crate.getName().equalsIgnoreCase(name))
for (Crate crate : this.registeredCrates) {
if (crate.getName().equalsIgnoreCase(name)) {
return crate;
}
}
return null;
}
public Crate getCrate(ItemStack item) {
if (item == null || !item.hasItemMeta() || !item.getItemMeta().hasLore() || item.getType() != Material.CHEST)
if (item == null || !item.hasItemMeta() || !item.getItemMeta().hasLore() || item.getType() != Material.CHEST) {
return null;
}
return getCrate(ChatColor.stripColor(item.getItemMeta().getLore().get(0)).split(" ")[1]);
}
public Set<Crate> getRegisteredCrates() {
return Collections.unmodifiableSet(registeredCrates);
return Collections.unmodifiableSet(this.registeredCrates);
}
public void clear() {
registeredCrates.clear();
this.registeredCrates.clear();
}
}
}

View File

@ -1,15 +1,12 @@
package com.songoda.ultimatekits.database;
package com.craftaro.ultimatekits.database;
import com.songoda.core.database.DataManagerAbstract;
import com.songoda.core.database.DatabaseConnector;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.kit.Kit;
import com.songoda.ultimatekits.kit.KitBlockData;
import com.songoda.ultimatekits.kit.KitType;
import com.craftaro.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.kit.Kit;
import com.craftaro.ultimatekits.kit.KitBlockData;
import com.craftaro.ultimatekits.kit.KitType;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.plugin.Plugin;
import java.sql.Connection;
import java.sql.PreparedStatement;
@ -19,20 +16,23 @@ import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;
public class DataManager extends DataManagerAbstract {
public class DataManager {
private final UltimateKits plugin;
public DataManager(DatabaseConnector databaseConnector, Plugin plugin) {
super(databaseConnector, plugin);
public DataManager(UltimateKits plugin) {
this.plugin = plugin;
}
public void bulkUpdateBlockData(Map<Location, KitBlockData> blockData) {
try (Connection connection = this.databaseConnector.getConnection()) {
String updateData = "UPDATE " + this.getTablePrefix() + "blockdata SET type = ?, kit = ?, holograms = ?, " +
try (Connection connection = this.plugin.getDataManager().getDatabaseConnector().getConnection()) {
String updateData = "UPDATE " + this.plugin.getDataManager().getTablePrefix() + "blockdata SET type = ?, kit = ?, holograms = ?, " +
"displayItems = ?, particles = ?, itemOverride = ? " +
"WHERE world = ? AND x = ? AND y = ? AND z = ?";
PreparedStatement statement = connection.prepareStatement(updateData);
for (KitBlockData data : blockData.values()) {
if (data == null || data.getWorld() == null) continue;
if (data == null || data.getWorld() == null) {
continue;
}
statement.setString(1, data.getType().toString());
statement.setString(2, data.getKit().getKey());
statement.setBoolean(3, data.showHologram());
@ -53,10 +53,13 @@ public class DataManager extends DataManagerAbstract {
}
public void updateBlockData(KitBlockData blockData) {
if (blockData.getWorld() == null) return;
this.runAsync(() -> {
try (Connection connection = this.databaseConnector.getConnection()) {
String updateData = "UPDATE " + this.getTablePrefix() + "blockdata SET type = ?, kit = ?, holograms = ?, " +
if (blockData.getWorld() == null) {
return;
}
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
try (Connection connection = this.plugin.getDataManager().getDatabaseConnector().getConnection()) {
String updateData = "UPDATE " + this.plugin.getDataManager().getTablePrefix() + "blockdata SET type = ?, kit = ?, holograms = ?, " +
"displayItems = ?, particles = ?, itemOverride = ? " +
"WHERE world = ? AND x = ? AND y = ? AND z = ?";
PreparedStatement statement = connection.prepareStatement(updateData);
@ -78,10 +81,12 @@ public class DataManager extends DataManagerAbstract {
}
public void createBlockData(KitBlockData blockData) {
if (blockData.getWorld() == null) return;
this.runAsync(() -> {
try (Connection connection = this.databaseConnector.getConnection()) {
String createData = "INSERT INTO " + this.getTablePrefix() + "blockdata (" +
if (blockData.getWorld() == null) {
return;
}
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
try (Connection connection = this.plugin.getDataManager().getDatabaseConnector().getConnection()) {
String createData = "INSERT INTO " + this.plugin.getDataManager().getTablePrefix() + "blockdata (" +
"type, kit, holograms, displayItems, particles, itemOverride, world, x, y, z)" +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
PreparedStatement statement = connection.prepareStatement(createData);
@ -103,9 +108,9 @@ public class DataManager extends DataManagerAbstract {
}
public void deleteBlockData(KitBlockData blockData) {
this.runAsync(() -> {
try (Connection connection = this.databaseConnector.getConnection()) {
String deleteData = "DELETE FROM " + this.getTablePrefix() + "blockdata WHERE world = ? " +
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
try (Connection connection = this.plugin.getDataManager().getDatabaseConnector().getConnection()) {
String deleteData = "DELETE FROM " + this.plugin.getDataManager().getTablePrefix() + "blockdata WHERE world = ? " +
"AND x = ? AND y = ? AND z = ?";
PreparedStatement statement = connection.prepareStatement(deleteData);
statement.setString(1, blockData.getWorld().getName());
@ -120,20 +125,24 @@ public class DataManager extends DataManagerAbstract {
}
public void getBlockData(Consumer<Map<Location, KitBlockData>> callback) {
this.runAsync(() -> {
try (Connection connection = this.databaseConnector.getConnection()) {
String selectData = "SELECT * FROM " + this.getTablePrefix() + "blockdata";
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
try (Connection connection = this.plugin.getDataManager().getDatabaseConnector().getConnection()) {
String selectData = "SELECT * FROM " + this.plugin.getDataManager().getTablePrefix() + "blockdata";
Map<Location, KitBlockData> blockData = new HashMap<>();
Statement statement = connection.createStatement();
ResultSet result = statement.executeQuery(selectData);
while (result.next()) {
World world = Bukkit.getWorld(result.getString("world"));
if (world == null) continue;
if (world == null) {
continue;
}
Kit kit = UltimateKits.getInstance().getKitManager().getKit(result.getString("kit"));
KitType type = KitType.getKitType(result.getString("type"));
if (kit == null || type == null) continue;
if (kit == null || type == null) {
continue;
}
boolean holograms = result.getBoolean("holograms");
boolean displayItems = result.getBoolean("displayItems");
@ -147,7 +156,7 @@ public class DataManager extends DataManagerAbstract {
blockData.put(location, new KitBlockData(kit, location, type, holograms, particles, displayItems, itemOverride));
}
this.sync(() -> callback.accept(blockData));
Bukkit.getScheduler().runTask(this.plugin, () -> callback.accept(blockData));
} catch (Exception ex) {
ex.printStackTrace();
}

View File

@ -1,23 +1,18 @@
package com.songoda.ultimatekits.database.migrations;
package com.craftaro.ultimatekits.database.migrations;
import com.songoda.core.database.DataMigration;
import com.craftaro.core.database.DataMigration;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
public class _1_InitialMigration extends DataMigration {
public _1_InitialMigration() {
super(1);
}
@Override
public void migrate(Connection connection, String tablePrefix) throws SQLException {
// String autoIncrement = UltimateKits.getInstance().getDatabaseConnector() instanceof
// MySQLConnector ? " AUTO_INCREMENT" : "";
// Create plugin settings table
try (Statement statement = connection.createStatement()) {
statement.execute("CREATE TABLE " + tablePrefix + "blockdata (" +
"type TEXT NOT NULL," +
@ -33,4 +28,4 @@ public class _1_InitialMigration extends DataMigration {
")");
}
}
}
}

View File

@ -1,6 +1,7 @@
package com.songoda.ultimatekits.database.migrations;
package com.craftaro.ultimatekits.database.migrations;
import com.songoda.core.database.DataMigration;
import com.craftaro.core.database.DataMigration;
import com.craftaro.core.database.SQLiteConnector;
import java.sql.Connection;
import java.sql.PreparedStatement;
@ -10,19 +11,16 @@ import java.sql.Statement;
import java.util.HashMap;
public class _2_DuplicateMigration extends DataMigration {
private final boolean sqlite;
public _2_DuplicateMigration(boolean sqlite) {
public _2_DuplicateMigration() {
super(2);
this.sqlite = sqlite;
}
@Override
public void migrate(Connection connection, String tablePrefix) throws SQLException {
// Fix duplicate data caused by old sqlite data duplication bug
boolean sqlite = connection instanceof SQLiteConnector;
if (sqlite) {
HashMap<String, TempKitData> data = new HashMap();
HashMap<String, TempKitData> data = new HashMap<>();
// grab a copy of the unique data values
try (Statement statement = connection.createStatement()) {
ResultSet allData = statement.executeQuery("SELECT * FROM " + tablePrefix + "blockdata");
@ -46,7 +44,9 @@ public class _2_DuplicateMigration extends DataMigration {
}
allData.close();
}
if (data.isEmpty()) return;
if (data.isEmpty()) {
return;
}
connection.setAutoCommit(false);
// first delete old data
try (Statement statement = connection.createStatement()) {

View File

@ -1,136 +1,135 @@
package com.songoda.ultimatekits.gui;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.compatibility.CompatibleSound;
import com.songoda.core.gui.Gui;
import com.songoda.core.gui.GuiUtils;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.kit.Kit;
import com.songoda.ultimatekits.kit.KitItem;
import com.songoda.ultimatekits.settings.Settings;
import com.songoda.ultimatekits.utils.ArmorType;
import org.apache.commons.lang.WordUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayDeque;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
public class AnimatedKitGui extends Gui {
static final Random rand = new Random();
private final UltimateKits plugin;
private final Player player;
private final ItemStack give;
private final ArrayDeque<KitItem> items = new ArrayDeque();
private boolean finish = false;
private boolean done = false;
private int tick = 0, updateTick = 0;
private int ticksPerUpdate = 3;
private int task;
public AnimatedKitGui(UltimateKits plugin, Player player, Kit kit, ItemStack give) {
this.plugin = plugin;
this.player = player;
this.give = give;
setRows(3);
setAllowClose(false);
setTitle(kit.getName());
setDefaultItem(GuiUtils.getBorderItem(CompatibleMaterial.GRAY_STAINED_GLASS_PANE));
// ideally, we'd populate the items in such a way that the end item isn't far from the center when the animation is complete
// would be something to do if people have large kit loot tables.
List<KitItem> kitItems = kit.getContents();
if (kitItems.isEmpty()) {
throw new RuntimeException("Cannot give an empty kit!");
}
Collections.shuffle(kitItems);
this.items.addAll(kitItems);
while (this.items.size() < 10) {
items.addAll(kitItems);
}
setItem(4, GuiUtils.getBorderItem(CompatibleMaterial.TRIPWIRE_HOOK));
setItem(22, GuiUtils.getBorderItem(CompatibleMaterial.TRIPWIRE_HOOK));
tick();
setOnOpen(event -> {
task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> tick(), 1L, 1L);
});
}
private void tick() {
if (++tick < ticksPerUpdate) {
return;
}
tick = 0;
int updatesPerSlow = 6;
if (++updateTick >= updatesPerSlow) {
updateTick = 0;
int ticksPerUpdateSlow = Settings.ROULETTE_LENGTH_MULTIPLIER.getInt();
if (++ticksPerUpdate >= ticksPerUpdateSlow) {
finish = true;
}
}
// now update the display
// rainbow disco!
for (int col = 0; col < 9; ++col) {
if (col == 4) continue;
setItem(0, col, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneColor(rand.nextInt(16))));
setItem(2, col, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneColor(rand.nextInt(16))));
}
// item slider
if (!done) {
CompatibleSound.UI_BUTTON_CLICK.play(player, 5F, 5F);
items.addFirst(items.getLast());
items.removeLast();
Iterator<KitItem> itemIter = items.iterator();
for (int i = 9; i < 18; i++) {
setItem(0, i, itemIter.next().getItem());
}
}
// should we try to wrap it up?
if (finish) {
ItemStack item = getItem(13);
KitItem kitItem = items.stream().filter(i -> i.getItem().isSimilar(item)).findFirst().orElse(null);
if (item == null) {
done = true; // idk.
} else if (item.isSimilar(give)) {
if (!done) {
done = true;
if (!Settings.AUTO_EQUIP_ARMOR_ROULETTE.getBoolean() || !ArmorType.equip(player, give)) {
ItemStack processedItem = kitItem.getContent().process(player);
if (processedItem != null) {
Map<Integer, ItemStack> overfilled = player.getInventory().addItem(give);
for (ItemStack item2 : overfilled.values()) {
player.getWorld().dropItemNaturally(player.getLocation(), item2);
}
}
}
CompatibleSound.ENTITY_PLAYER_LEVELUP.play(player, 10f, 10f);
plugin.getLocale().getMessage("event.create.won")
.processPlaceholder("item", WordUtils.capitalize(give.getType().name().toLowerCase().replace("_", " ")))
.sendPrefixedMessage(player);
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, this::finish, 50);
setAllowClose(true);
}
}
}
}
private void finish() {
Bukkit.getScheduler().cancelTask(task);
exit();
}
}
package com.craftaro.ultimatekits.gui;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.gui.Gui;
import com.craftaro.core.gui.GuiUtils;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.third_party.com.cryptomorin.xseries.XSound;
import com.craftaro.third_party.org.apache.commons.text.WordUtils;
import com.craftaro.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.kit.Kit;
import com.craftaro.ultimatekits.kit.KitItem;
import com.craftaro.ultimatekits.settings.Settings;
import com.craftaro.ultimatekits.utils.ArmorType;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayDeque;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
public class AnimatedKitGui extends Gui {
static final Random rand = new Random();
private final UltimateKits plugin;
private final Player player;
private final ItemStack give;
private final ArrayDeque<KitItem> items = new ArrayDeque<>();
private boolean finish = false;
private boolean done = false;
private int tick = 0, updateTick = 0;
private int ticksPerUpdate = 3;
private int task;
public AnimatedKitGui(UltimateKits plugin, Player player, Kit kit, ItemStack give) {
this.plugin = plugin;
this.player = player;
this.give = give;
setRows(3);
setAllowClose(false);
setTitle(kit.getName());
setDefaultItem(GuiUtils.getBorderItem(XMaterial.GRAY_STAINED_GLASS_PANE));
// ideally, we'd populate the items in such a way that the end item isn't far from the center when the animation is complete
// would be something to do if people have large kit loot tables.
List<KitItem> kitItems = kit.getContents();
if (kitItems.isEmpty()) {
throw new RuntimeException("Cannot give an empty kit!");
}
Collections.shuffle(kitItems);
this.items.addAll(kitItems);
while (this.items.size() < 10) {
this.items.addAll(kitItems);
}
setItem(4, GuiUtils.getBorderItem(XMaterial.TRIPWIRE_HOOK));
setItem(22, GuiUtils.getBorderItem(XMaterial.TRIPWIRE_HOOK));
tick();
setOnOpen(event -> this.task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, this::tick, 1L, 1L));
}
private void tick() {
if (++this.tick < this.ticksPerUpdate) {
return;
}
this.tick = 0;
int updatesPerSlow = 6;
if (++this.updateTick >= updatesPerSlow) {
this.updateTick = 0;
int ticksPerUpdateSlow = Settings.ROULETTE_LENGTH_MULTIPLIER.getInt();
if (++this.ticksPerUpdate >= ticksPerUpdateSlow) {
this.finish = true;
}
}
// now update the display
// rainbow disco!
for (int col = 0; col < 9; ++col) {
if (col == 4) {
continue;
}
setItem(0, col, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneForColor(rand.nextInt(16))));
setItem(2, col, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneForColor(rand.nextInt(16))));
}
// item slider
if (!this.done) {
XSound.UI_BUTTON_CLICK.play(this.player, 5F, 5F);
this.items.addFirst(this.items.getLast());
this.items.removeLast();
Iterator<KitItem> itemIter = this.items.iterator();
for (int i = 9; i < 18; i++) {
setItem(0, i, itemIter.next().getItem());
}
}
// should we try to wrap it up?
if (this.finish) {
ItemStack item = getItem(13);
KitItem kitItem = this.items.stream().filter(i -> i.getItem().isSimilar(item)).findFirst().orElse(null);
if (item == null) {
this.done = true; // idk.
} else if (item.isSimilar(this.give)) {
if (!this.done) {
this.done = true;
if (!Settings.AUTO_EQUIP_ARMOR_ROULETTE.getBoolean() || !ArmorType.equip(this.player, this.give)) {
ItemStack processedItem = kitItem.getContent().process(this.player);
if (processedItem != null) {
Map<Integer, ItemStack> overfilled = this.player.getInventory().addItem(this.give);
for (ItemStack item2 : overfilled.values()) {
this.player.getWorld().dropItemNaturally(this.player.getLocation(), item2);
}
}
}
XSound.ENTITY_PLAYER_LEVELUP.play(this.player, 10f, 10f);
this.plugin.getLocale().getMessage("event.create.won")
.processPlaceholder("item", WordUtils.capitalize(this.give.getType().name().toLowerCase().replace("_", " ")))
.sendPrefixedMessage(this.player);
Bukkit.getScheduler().scheduleSyncDelayedTask(this.plugin, this::finish, 50);
setAllowClose(true);
}
}
}
}
private void finish() {
Bukkit.getScheduler().cancelTask(this.task);
exit();
}
}

View File

@ -1,13 +1,13 @@
package com.songoda.ultimatekits.gui;
package com.craftaro.ultimatekits.gui;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.gui.Gui;
import com.songoda.core.gui.GuiUtils;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.kit.KitBlockData;
import com.songoda.ultimatekits.kit.KitType;
import com.songoda.ultimatekits.settings.Settings;
import com.songoda.ultimatekits.utils.Methods;
import com.craftaro.core.gui.Gui;
import com.craftaro.core.gui.GuiUtils;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.kit.KitBlockData;
import com.craftaro.ultimatekits.kit.KitType;
import com.craftaro.ultimatekits.settings.Settings;
import com.craftaro.ultimatekits.utils.Methods;
import org.bukkit.ChatColor;
import org.bukkit.event.inventory.ClickType;
@ -15,7 +15,6 @@ import java.util.Arrays;
import java.util.List;
public class BlockEditorGui extends Gui {
private final KitBlockData kitBlockData;
public BlockEditorGui(UltimateKits plugin, KitBlockData kitBlockData) {
@ -29,15 +28,15 @@ public class BlockEditorGui extends Gui {
Methods.fillGlass(this);
// exit button
setButton(0, 8, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(CompatibleMaterial.OAK_DOOR),
plugin.getLocale().getMessage("interface.button.exit").getMessage()),
setButton(0, 8, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(XMaterial.OAK_DOOR),
plugin.getLocale().getMessage("interface.button.exit").getMessage()),
ClickType.LEFT,
event -> event.player.closeInventory());
// kit type
setButton(1, 2, GuiUtils.createButtonItem(CompatibleMaterial.COMPARATOR,
plugin.getLocale().getMessage("interface.kitblock.switchtype").getMessage(),
kitTypeLore(plugin)),
setButton(1, 2, GuiUtils.createButtonItem(XMaterial.COMPARATOR,
plugin.getLocale().getMessage("interface.kitblock.switchtype").getMessage(),
kitTypeLore(plugin)),
ClickType.LEFT,
event -> {
plugin.removeHologram(kitBlockData);
@ -57,19 +56,19 @@ public class BlockEditorGui extends Gui {
});
// decor options
setButton(1, 4, GuiUtils.createButtonItem(CompatibleMaterial.POPPY,
plugin.getLocale().getMessage("interface.kitblock.decor").getMessage(),
plugin.getLocale().getMessage("interface.kitblock.decorlore").getMessage().split("\\|")),
setButton(1, 4, GuiUtils.createButtonItem(XMaterial.POPPY,
plugin.getLocale().getMessage("interface.kitblock.decor").getMessage(),
plugin.getLocale().getMessage("interface.kitblock.decorlore").getMessage().split("\\|")),
ClickType.LEFT,
event -> event.manager.showGUI(event.player, new KitDecorOptionsGui(plugin, kitBlockData, this)));
// edit
setButton(1, 6, GuiUtils.createButtonItem(CompatibleMaterial.DIAMOND_PICKAXE,
plugin.getLocale().getMessage("interface.kitblock.edit").getMessage(),
plugin.getLocale().getMessage("interface.kitblock.editlore").getMessage().split("\\|")),
setButton(1, 6, GuiUtils.createButtonItem(XMaterial.DIAMOND_PICKAXE,
plugin.getLocale().getMessage("interface.kitblock.edit").getMessage(),
plugin.getLocale().getMessage("interface.kitblock.editlore").getMessage().split("\\|")),
ClickType.LEFT,
event -> {
guiManager.showGUI(event.player, new KitEditorGui(UltimateKits.getInstance(), event.player, kitBlockData.getKit(), this));
this.guiManager.showGUI(event.player, new KitEditorGui(UltimateKits.getInstance(), event.player, kitBlockData.getKit(), this));
});
}
@ -78,9 +77,8 @@ public class BlockEditorGui extends Gui {
String[] type = plugin.getLocale().getMessage("interface.kitblock.switchtypelore").getMessage().split("\\|");
return Arrays.asList(
type[0],
(kitBlockData.getType() == KitType.PREVIEW ? ChatColor.GOLD : ChatColor.GRAY) + (type.length > 1 ? type[1] : "Preview"),
(kitBlockData.getType() == KitType.CRATE ? ChatColor.GOLD : ChatColor.GRAY) + (type.length > 2 ? type[2] : "Crate"),
(kitBlockData.getType() == KitType.CLAIM ? ChatColor.GOLD : ChatColor.GRAY) + (type.length > 3 ? type[3] : "Claim"));
(this.kitBlockData.getType() == KitType.PREVIEW ? ChatColor.GOLD : ChatColor.GRAY) + (type.length > 1 ? type[1] : "Preview"),
(this.kitBlockData.getType() == KitType.CRATE ? ChatColor.GOLD : ChatColor.GRAY) + (type.length > 2 ? type[2] : "Crate"),
(this.kitBlockData.getType() == KitType.CLAIM ? ChatColor.GOLD : ChatColor.GRAY) + (type.length > 3 ? type[3] : "Claim"));
}
}

View File

@ -1,15 +1,15 @@
package com.songoda.ultimatekits.gui;
package com.craftaro.ultimatekits.gui;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.gui.Gui;
import com.songoda.core.gui.GuiUtils;
import com.songoda.core.input.ChatPrompt;
import com.songoda.core.utils.TextUtils;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.category.Category;
import com.songoda.ultimatekits.category.CategoryManager;
import com.songoda.ultimatekits.settings.Settings;
import com.songoda.ultimatekits.utils.Methods;
import com.craftaro.core.gui.Gui;
import com.craftaro.core.gui.GuiUtils;
import com.craftaro.core.input.ChatPrompt;
import com.craftaro.core.utils.TextUtils;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.category.Category;
import com.craftaro.ultimatekits.category.CategoryManager;
import com.craftaro.ultimatekits.settings.Settings;
import com.craftaro.ultimatekits.utils.Methods;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
@ -17,7 +17,6 @@ import org.bukkit.event.inventory.ClickType;
import java.util.List;
public class CategoryEditorGui extends Gui {
private final UltimateKits plugin;
private final Player player;
private final CategoryManager categoryManager;
@ -34,9 +33,9 @@ public class CategoryEditorGui extends Gui {
Methods.fillGlass(this);
mirrorFill(1, 1, false, true, getDefaultItem());
setButton(4, GuiUtils.createButtonItem(CompatibleMaterial.GREEN_DYE, "Create Category"),
setButton(4, GuiUtils.createButtonItem(XMaterial.GREEN_DYE, "Create Category"),
(event) -> {
if (categoryManager.getCategories().size() >= 7) {
if (this.categoryManager.getCategories().size() >= 7) {
plugin.getLocale().newMessage("&cYou already have the maximum amount of categories...").sendPrefixedMessage(player);
} else {
ChatPrompt.showPrompt(event.manager.getPlugin(), event.player, "Enter a category name:", response -> {
@ -44,12 +43,12 @@ public class CategoryEditorGui extends Gui {
String key = msg.toUpperCase().replace(" ", "_");
if (categoryManager.getCategory(key) != null) {
if (this.categoryManager.getCategory(key) != null) {
plugin.getLocale().newMessage("&cA category with that name already exists...").sendPrefixedMessage(player);
return;
}
categoryManager.addCategory(key, msg);
this.categoryManager.addCategory(key, msg);
plugin.getLocale().newMessage("&aCategory added successfully!").sendPrefixedMessage(player);
Bukkit.getScheduler().runTask(plugin, player::closeInventory);
@ -61,19 +60,19 @@ public class CategoryEditorGui extends Gui {
});
// exit button
setButton(0, 8, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(CompatibleMaterial.OAK_DOOR),
plugin.getLocale().getMessage("interface.button.exit").getMessage()),
setButton(0, 8, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(XMaterial.OAK_DOOR),
plugin.getLocale().getMessage("interface.button.exit").getMessage()),
ClickType.LEFT,
event -> exit());
paint();
}
private void paint() {
List<Category> categories = categoryManager.getCategories();
List<Category> categories = this.categoryManager.getCategories();
for (int i = 0; i < categories.size(); i++) {
Category category = categories.get(i);
setButton(i + 10,
GuiUtils.createButtonItem(CompatibleMaterial.getMaterial(category.getMaterial()),
GuiUtils.createButtonItem(XMaterial.matchXMaterial(category.getMaterial()),
TextUtils.formatText(category.getName()),
TextUtils.formatText("&6Left click to change name"),
"",
@ -83,17 +82,17 @@ public class CategoryEditorGui extends Gui {
TextUtils.formatText("&cRight click to remove."),
TextUtils.formatText("&c(Kits will not be removed)")),
(event) -> {
if (event.clickType == ClickType.LEFT)
if (event.clickType == ClickType.LEFT) {
ChatPrompt.showPrompt(event.manager.getPlugin(), event.player, "Enter a name:", response -> {
category.setName(response.getMessage().trim());
event.manager.showGUI(event.player, new CategoryEditorGui(plugin, event.player));
event.manager.showGUI(event.player, new CategoryEditorGui(this.plugin, event.player));
});
else if (event.clickType == ClickType.MIDDLE) {
category.setMaterial(player.getItemInHand().getType());
event.manager.showGUI(event.player, new CategoryEditorGui(plugin, event.player));
} else if (event.clickType == ClickType.MIDDLE) {
category.setMaterial(this.player.getItemInHand().getType());
event.manager.showGUI(event.player, new CategoryEditorGui(this.plugin, event.player));
} else if (event.clickType == ClickType.RIGHT) {
categoryManager.removeCategory(category);
event.manager.showGUI(event.player, new CategoryEditorGui(plugin, event.player));
this.categoryManager.removeCategory(category);
event.manager.showGUI(event.player, new CategoryEditorGui(this.plugin, event.player));
}
});
}

View File

@ -1,13 +1,14 @@
package com.songoda.ultimatekits.gui;
package com.craftaro.ultimatekits.gui;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.gui.Gui;
import com.songoda.core.gui.GuiUtils;
import com.songoda.core.utils.TextUtils;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.category.Category;
import com.songoda.ultimatekits.kit.Kit;
import com.songoda.ultimatekits.settings.Settings;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.gui.Gui;
import com.craftaro.core.gui.GuiUtils;
import com.craftaro.core.utils.TextUtils;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.category.Category;
import com.craftaro.ultimatekits.kit.Kit;
import com.craftaro.ultimatekits.settings.Settings;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@ -18,7 +19,6 @@ import java.util.Random;
import java.util.Set;
public class CategorySelectorGui extends Gui {
private int timer;
private static final Random rand = new Random();
@ -27,9 +27,11 @@ public class CategorySelectorGui extends Gui {
Set<Category> categories = new LinkedHashSet<>();
for (Kit kit : plugin.getKitManager().getKits())
if (kit.hasPermissionToPreview(player) && kit.getCategory() != null)
for (Kit kit : plugin.getKitManager().getKits()) {
if (kit.hasPermissionToPreview(player) && kit.getCategory() != null) {
categories.add(kit.getCategory());
}
}
setTitle(plugin.getLocale().getMessage("interface.categoryselector.title").getMessage());
@ -37,13 +39,13 @@ public class CategorySelectorGui extends Gui {
int nrows = (int) Math.ceil(categories.size() / (double) showPerRow);
setRows(glassless ? nrows : nrows + 2);
setItem(0, 4, GuiUtils.createButtonItem(CompatibleMaterial.BOOK,
setItem(0, 4, GuiUtils.createButtonItem(XMaterial.BOOK,
plugin.getLocale().getMessage("interface.categoryselector.details")
.processPlaceholder("player", player.getName()).getMessage().split("\\|")));
if (!glassless) {
setButton(rows - 1, 4, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(CompatibleMaterial.OAK_DOOR),
UltimateKits.getInstance().getLocale().getMessage("interface.button.exit").getMessage()),
setButton(this.rows - 1, 4, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(XMaterial.OAK_DOOR),
UltimateKits.getInstance().getLocale().getMessage("interface.button.exit").getMessage()),
event -> exit());
}
@ -54,11 +56,13 @@ public class CategorySelectorGui extends Gui {
if (!glassless) {
if (Settings.RAINBOW.getBoolean()) {
animateGlass();
timer = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
if (inventory.getViewers().isEmpty()) return;
this.timer = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
if (this.inventory.getViewers().isEmpty()) {
return;
}
animateGlass();
}, 20L, 20L);
setOnClose(event -> Bukkit.getScheduler().cancelTask(timer));
setOnClose(event -> Bukkit.getScheduler().cancelTask(this.timer));
} else {
ItemStack glass1 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_1.getMaterial());
ItemStack glass3 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_3.getMaterial());
@ -72,12 +76,12 @@ public class CategorySelectorGui extends Gui {
int i = 10;
for (Category category : categories) {
setButton(i, GuiUtils.createButtonItem(CompatibleMaterial.getMaterial(category.getMaterial()),
TextUtils.formatText(category.getName()),
"",
plugin.getLocale().getMessage("interface.categoryselector.view").getMessage()),
setButton(i, GuiUtils.createButtonItem(XMaterial.matchXMaterial(category.getMaterial()),
TextUtils.formatText(category.getName()),
"",
plugin.getLocale().getMessage("interface.categoryselector.view").getMessage()),
event -> {
guiManager.showGUI(player, new KitSelectorGui(plugin, player, category));
this.guiManager.showGUI(player, new KitSelectorGui(plugin, player, category));
});
i++;
}
@ -87,14 +91,16 @@ public class CategorySelectorGui extends Gui {
private void animateGlass() {
for (int col = 1; col < 8; ++col) {
ItemStack it;
if ((it = getItem(0, col)) == null || it.getType() == Material.AIR || it.getType().name().contains("PANE"))
setItem(0, col, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneColor(rand.nextInt(16))));
if ((it = getItem(rows - 1, col)) == null || it.getType() == Material.AIR || it.getType().name().contains("PANE"))
setItem(rows - 1, col, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneColor(rand.nextInt(16))));
if ((it = getItem(0, col)) == null || it.getType() == Material.AIR || it.getType().name().contains("PANE")) {
setItem(0, col, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneForColor(rand.nextInt(16))));
}
if ((it = getItem(this.rows - 1, col)) == null || it.getType() == Material.AIR || it.getType().name().contains("PANE")) {
setItem(this.rows - 1, col, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneForColor(rand.nextInt(16))));
}
}
for (int row = 1; row + 1 < rows; ++row) {
setItem(row, 0, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneColor(rand.nextInt(16))));
setItem(row, 8, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneColor(rand.nextInt(16))));
for (int row = 1; row + 1 < this.rows; ++row) {
setItem(row, 0, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneForColor(rand.nextInt(16))));
setItem(row, 8, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneForColor(rand.nextInt(16))));
}
}
}

View File

@ -1,25 +1,26 @@
package com.songoda.ultimatekits.gui;
package com.craftaro.ultimatekits.gui;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.gui.Gui;
import com.songoda.core.gui.GuiUtils;
import com.songoda.core.utils.TextUtils;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.kit.Kit;
import com.songoda.ultimatekits.settings.Settings;
import com.songoda.ultimatekits.utils.Methods;
import com.craftaro.core.gui.Gui;
import com.craftaro.core.gui.GuiUtils;
import com.craftaro.core.utils.NumberUtils;
import com.craftaro.core.utils.TextUtils;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.kit.Kit;
import com.craftaro.ultimatekits.settings.Settings;
import com.craftaro.ultimatekits.utils.Methods;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
public class ConfirmBuyGui extends Gui {
public ConfirmBuyGui(UltimateKits plugin, Player player, Kit kit, Gui back) {
super(back);
setRows(3);
double cost = kit.getPrice();
if (kit.hasPermissionToClaim(player))
if (kit.hasPermissionToClaim(player)) {
cost = 0;
}
setTitle(plugin.getLocale().getMessage("interface.yesno.title")
.processPlaceholder("price", cost)
@ -29,26 +30,24 @@ public class ConfirmBuyGui extends Gui {
Methods.fillGlass(this);
// Kit information
setItem(0, 4, GuiUtils.createButtonItem(kit.getDisplayItem() != null ? kit.getDisplayItem() : CompatibleMaterial.DIAMOND_HELMET.getItem(),
setItem(0, 4, GuiUtils.createButtonItem(kit.getDisplayItem() != null ? kit.getDisplayItem() : XMaterial.DIAMOND_HELMET.parseItem(),
ChatColor.RED + TextUtils.formatText(kit.getKey().toLowerCase(), true),
ChatColor.GREEN + Settings.CURRENCY_SYMBOL.getString() + Methods.formatEconomy(cost)));
ChatColor.GREEN + Settings.CURRENCY_SYMBOL.getString() + NumberUtils.formatNumber(cost)));
// confirm button
setButton(1, 2, GuiUtils.createButtonItem(Settings.BUY_ICON.getMaterial(CompatibleMaterial.EMERALD),
plugin.getLocale().getMessage("interface.yesno.yes").getMessage()),
setButton(1, 2, GuiUtils.createButtonItem(Settings.BUY_ICON.getMaterial(XMaterial.EMERALD),
plugin.getLocale().getMessage("interface.yesno.yes").getMessage()),
event -> {
kit.processPurchaseUse(event.player);
exit();
});
// cancel button
setButton(1, 6, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(CompatibleMaterial.OAK_DOOR),
plugin.getLocale().getMessage("interface.yesno.no").getMessage()),
setButton(1, 6, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(XMaterial.OAK_DOOR),
plugin.getLocale().getMessage("interface.yesno.no").getMessage()),
event -> {
plugin.getLocale().getMessage("event.purchase.cancelled").sendPrefixedMessage(event.player);
event.player.closeInventory();
});
}
}

View File

@ -1,18 +1,17 @@
package com.songoda.ultimatekits.gui;
package com.craftaro.ultimatekits.gui;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.gui.Gui;
import com.songoda.core.gui.GuiUtils;
import com.songoda.core.utils.ItemUtils;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.kit.Kit;
import com.songoda.ultimatekits.kit.KitBlockData;
import com.songoda.ultimatekits.settings.Settings;
import com.songoda.ultimatekits.utils.Methods;
import com.craftaro.core.gui.Gui;
import com.craftaro.core.gui.GuiUtils;
import com.craftaro.core.utils.ItemUtils;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.kit.Kit;
import com.craftaro.ultimatekits.kit.KitBlockData;
import com.craftaro.ultimatekits.settings.Settings;
import com.craftaro.ultimatekits.utils.Methods;
import org.bukkit.event.inventory.ClickType;
public class KitDecorOptionsGui extends Gui {
public KitDecorOptionsGui(UltimateKits plugin, KitBlockData kitBlockData, Gui parent) {
super(parent);
setRows(3);
@ -26,14 +25,14 @@ public class KitDecorOptionsGui extends Gui {
Methods.fillGlass(this);
// exit button
setButton(0, 8, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(CompatibleMaterial.OAK_DOOR),
plugin.getLocale().getMessage("interface.button.exit").getMessage()),
setButton(0, 8, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(XMaterial.OAK_DOOR),
plugin.getLocale().getMessage("interface.button.exit").getMessage()),
ClickType.LEFT,
event -> exit());
// back button
setButton(0, 0, GuiUtils.createButtonItem(ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"),
plugin.getLocale().getMessage("interface.button.back").getMessage()),
plugin.getLocale().getMessage("interface.button.back").getMessage()),
ClickType.LEFT,
event -> event.player.closeInventory());
@ -41,9 +40,9 @@ public class KitDecorOptionsGui extends Gui {
final String disableLore = plugin.getLocale().getMessage("interface.kitdecor.settingoff").getMessage();
// Hologram
setButton(1, 1, GuiUtils.createButtonItem(CompatibleMaterial.NAME_TAG,
plugin.getLocale().getMessage("interface.kitdecor.hologram").getMessage(),
kitBlockData.showHologram() ? enableLore : disableLore),
setButton(1, 1, GuiUtils.createButtonItem(XMaterial.NAME_TAG,
plugin.getLocale().getMessage("interface.kitdecor.hologram").getMessage(),
kitBlockData.showHologram() ? enableLore : disableLore),
event -> {
kitBlockData.setShowHologram(!kitBlockData.showHologram());
plugin.updateHologram(kitBlockData);
@ -51,18 +50,18 @@ public class KitDecorOptionsGui extends Gui {
});
// Particle effects
setButton(1, 3, GuiUtils.createButtonItem(CompatibleMaterial.POTION,
plugin.getLocale().getMessage("interface.kitdecor.particle").getMessage(),
kitBlockData.hasParticles() ? enableLore : disableLore),
setButton(1, 3, GuiUtils.createButtonItem(XMaterial.POTION,
plugin.getLocale().getMessage("interface.kitdecor.particle").getMessage(),
kitBlockData.hasParticles() ? enableLore : disableLore),
event -> {
kitBlockData.setHasParticles(!kitBlockData.hasParticles());
updateItemLore(event.slot, kitBlockData.hasParticles() ? enableLore : disableLore);
});
// Item Display
setButton(1, 5, GuiUtils.createButtonItem(CompatibleMaterial.DIAMOND,
plugin.getLocale().getMessage("interface.kitdecor.display").getMessage(),
kitBlockData.isDisplayingItems() ? enableLore : disableLore),
setButton(1, 5, GuiUtils.createButtonItem(XMaterial.DIAMOND,
plugin.getLocale().getMessage("interface.kitdecor.display").getMessage(),
kitBlockData.isDisplayingItems() ? enableLore : disableLore),
event -> {
plugin.removeHologram(kitBlockData);
kitBlockData.setDisplayingItems(!kitBlockData.isDisplayingItems());
@ -71,16 +70,14 @@ public class KitDecorOptionsGui extends Gui {
});
// Item Display Override
setButton(1, 7, GuiUtils.createButtonItem(kit.getDisplayItem() != null ? kit.getDisplayItem() : CompatibleMaterial.BEACON.getItem(),
plugin.getLocale().getMessage("interface.kitdecor.displayone").getMessage(),
plugin.getLocale().getMessage("interface.kitdecor.displayonelore")
.processPlaceholder("enabled", kitBlockData.isItemOverride() ? enableLore : disableLore)
.getMessage().split("\\|")),
setButton(1, 7, GuiUtils.createButtonItem(kit.getDisplayItem() != null ? kit.getDisplayItem() : XMaterial.BEACON.parseItem(),
plugin.getLocale().getMessage("interface.kitdecor.displayone").getMessage(),
plugin.getLocale().getMessage("interface.kitdecor.displayonelore")
.processPlaceholder("enabled", kitBlockData.isItemOverride() ? enableLore : disableLore)
.getMessage().split("\\|")),
event -> {
kitBlockData.setItemOverride(!kitBlockData.isItemOverride());
updateItemLore(event.slot, kitBlockData.isItemOverride() ? enableLore : disableLore);
});
}
}

View File

@ -0,0 +1,495 @@
package com.craftaro.ultimatekits.gui;
import com.craftaro.core.gui.AnvilGui;
import com.craftaro.core.gui.DoubleGui;
import com.craftaro.core.gui.Gui;
import com.craftaro.core.gui.GuiUtils;
import com.craftaro.core.input.ChatPrompt;
import com.craftaro.core.utils.ItemUtils;
import com.craftaro.core.utils.TextUtils;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.third_party.com.cryptomorin.xseries.XSound;
import com.craftaro.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.kit.Kit;
import com.craftaro.ultimatekits.kit.KitAnimation;
import com.craftaro.ultimatekits.kit.KitItem;
import com.craftaro.ultimatekits.settings.Settings;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
public class KitEditorGui extends DoubleGui {
private final UltimateKits plugin;
private final Kit kit;
private final Player player;
private final Gui back;
private boolean isInFunction = false;
private boolean isInInventory = false;
private ItemStack[] stash;
public KitEditorGui(UltimateKits plugin, Player player, Kit kit, Gui back) {
super(6);
this.plugin = plugin;
this.kit = kit;
this.player = player;
this.back = back;
setDefaultItem(null);
setTitle(plugin.getLocale().getMessage("interface.kiteditor.title")
.processPlaceholder("name", kit.getName())
.getMessage());
setOnClose((event) -> {
restoreItemsInstance();
saveKit(player, this.inventory, false);
XSound.ENTITY_VILLAGER_YES.play(player);
});
ItemStack glass1 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_1.getMaterial());
ItemStack glass2 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_2.getMaterial());
ItemStack glass3 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_3.getMaterial());
mirrorFill(0, 0, true, true, glass2);
mirrorFill(0, 1, true, true, glass2);
mirrorFill(1, 0, true, true, glass2);
mirrorFill(0, 2, true, true, glass3);
mirrorFill(0, 3, false, true, glass1);
// exit button
setButton(0, 8, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(XMaterial.OAK_DOOR),
plugin.getLocale().getMessage("interface.button.exit").getMessage()),
ClickType.LEFT,
event -> player.closeInventory());
// back button
if (this.parent != null) {
setButton(0, 0, GuiUtils.createButtonItem(ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"),
plugin.getLocale().getMessage("interface.button.back").getMessage()),
ClickType.LEFT,
event -> {
player.closeInventory();
this.guiManager.showGUI(player, back);
});
}
// info icon
setItem(0, 4, GuiUtils.createButtonItem(XMaterial.CHEST,
plugin.getLocale().getMessage("interface.kiteditor.info")
.processPlaceholder("kit", kit.getKey())
.processPlaceholder("perm", "ultimatekits.claim." + kit.getKey().toLowerCase())
.getMessage().split("\\|"))
);
saveItemsInstance();
paint();
Bukkit.getScheduler().runTaskLater(plugin, this::setInvItems, 3L);
}
private void paint() {
for (int i = 10; i < 44; i++) {
if (i == 17 || i == 36) {
continue;
}
setItem(i, null);
}
int num = 10;
for (ItemStack itemStack : this.kit.getReadableContents(this.player, false, true, true)) {
if (num == 17 || num == 36) {
num++;
}
KitItem item = new KitItem(itemStack);
ItemStack is = getCompiledMeta(item);
if (!this.isInFunction) {
setButton(num, is, null);
} else {
setButton(num, is,
(event) -> {
switch (event.clickType) {
case SHIFT_LEFT:
replaceItem(Action.CHANCE_UP, this.player, event.clickedItem, event.slot);
break;
case SHIFT_RIGHT:
replaceItem(Action.CHANCE_DOWN, this.player, event.clickedItem, event.slot);
break;
case LEFT:
replaceItem(Action.DISPLAY_ITEM, this.player, event.clickedItem, event.slot);
break;
case MIDDLE:
replaceItem(Action.DISPLAY_NAME, this.player, event.clickedItem, event.slot);
break;
case RIGHT:
replaceItem(Action.DISPLAY_LORE, this.player, event.clickedItem, event.slot);
break;
}
});
}
num++;
}
updateInvButton();
}
private void updateInvButton() {
ItemStack item;
if (!this.isInFunction) {
setUnlockedRange(1, 1, 1, 7);
setUnlockedRange(2, 0, 3, 8);
setUnlockedRange(4, 1, 4, 7);
item = GuiUtils.createButtonItem(XMaterial.PAPER,
this.plugin.getLocale().getMessage("interface.kiteditor.itemediting").getMessage(),
this.plugin.getLocale().getMessage("interface.kiteditor.itemeditinglore").getMessage().split("\\|"));
} else {
this.unlockedCells.clear();
item = GuiUtils.createButtonItem(XMaterial.PAPER,
this.plugin.getLocale().getMessage("interface.kiteditor.itemmoving").getMessage(),
this.plugin.getLocale().getMessage("interface.kiteditor.itemmovinglore").getMessage().split("\\|"));
}
setButton(48, item,
(event) -> {
this.isInFunction = !this.isInFunction;
saveKit(this.player, this.inventory, true);
paint();
});
ItemStack item2;
item2 = this.isInInventory ? GuiUtils.createButtonItem(XMaterial.ITEM_FRAME,
this.plugin.getLocale().getMessage("interface.kiteditor.switchtokitfunctions").getMessage(),
this.plugin.getLocale().getMessage("interface.kiteditor.switchtokitfunctionslore").getMessage().split("\\|"))
: GuiUtils.createButtonItem(XMaterial.ITEM_FRAME,
this.plugin.getLocale().getMessage("interface.kiteditor.switchtoinventory").getMessage(),
this.plugin.getLocale().getMessage("interface.kiteditor.switchtoinventorylore").getMessage().split("\\|"));
setButton(50, item2,
event -> {
if (!this.isInInventory) {
restoreItemsInstance();
setPlayerActionForRange(0, 0, 3, 8, null);
setAcceptsItems(true);
} else {
saveItemsInstance();
setInvItems();
setAcceptsItems(false);
}
updateInvButton();
});
}
private void saveItemsInstance() {
setPlayerUnlockedRange(0, 0, 3, 8, false);
this.stash = this.player.getInventory().getContents().clone();
this.player.getInventory().clear();
this.isInInventory = false;
}
private void restoreItemsInstance() {
if (!this.isInInventory) {
this.player.getInventory().clear();
}
setPlayerUnlockedRange(0, 0, 3, 8);
if (this.stash != null) {
this.player.getInventory().setContents(this.stash);
}
this.player.updateInventory();
this.isInInventory = true;
}
private void setInvItems() {
setPlayerButton(0, GuiUtils.createButtonItem(XMaterial.REDSTONE_TORCH,
this.plugin.getLocale().getMessage("interface.kiteditor.generaloptions").getMessage(),
this.plugin.getLocale().getMessage("interface.kiteditor.generaloptionslore").getMessage().split("\\|")),
(event) -> {
this.player.closeInventory();
this.guiManager.showGUI(this.player, new KitGeneralOptionsGui(this.plugin, this.player, this.kit, this.back));
});
setPlayerButton(1, GuiUtils.createButtonItem(XMaterial.EMERALD,
this.plugin.getLocale().getMessage("interface.kiteditor.sellingoptions").getMessage(),
this.plugin.getLocale().getMessage("interface.kiteditor.sellingoptionslore").getMessage().split("\\|")),
(event) -> {
this.player.closeInventory();
this.guiManager.showGUI(this.player, new KitSellingOptionsGui(this.plugin, this.player, this.kit, this.back));
});
setPlayerButton(3, GuiUtils.createButtonItem(XMaterial.ITEM_FRAME,
this.plugin.getLocale().getMessage("interface.kiteditor.guioptions").getMessage(),
this.plugin.getLocale().getMessage("interface.kiteditor.guioptionslore").getMessage().split("\\|")),
(event) -> {
this.player.closeInventory();
this.guiManager.showGUI(this.player, new KitGuiOptionsGui(this.plugin, this.player, this.kit, this.back));
});
setPlayerButton(4, GuiUtils.createButtonItem(XMaterial.PAPER,
this.plugin.getLocale().getMessage("interface.kiteditor.addcommand").getMessage(),
this.plugin.getLocale().getMessage("interface.kiteditor.addcommandlore").getMessage().split("\\|")),
(event) -> {
event.gui.exit();
ChatPrompt.showPrompt(event.manager.getPlugin(), event.player, "Enter a command for this kit:", response -> {
String msg = response.getMessage().trim();
ItemStack parseStack = new ItemStack(Material.PAPER, 1);
ItemMeta meta = parseStack.getItemMeta();
ArrayList<String> lore = new ArrayList<>();
int index = 0;
while (index < msg.length()) {
lore.add(ChatColor.GREEN + (index == 0 ? "/" : "") + msg.substring(index, Math.min(index + 30, msg.length())));
index += 30;
}
meta.setLore(lore);
meta.setDisplayName(this.plugin.getLocale().getMessage("general.type.command").getMessage());
parseStack.setItemMeta(meta);
this.plugin.getLocale().newMessage(this.plugin.getLocale().getMessage("interface.kiteditor.addcommandok")
.processPlaceholder("command", msg).getMessage())
.sendPrefixedMessage(this.player);
this.inventory.addItem(parseStack);
Bukkit.getScheduler().runTask(this.plugin, event.player::closeInventory);
}).setOnClose(() -> {
event.manager.showGUI(event.player, this);
})
.setOnCancel(() -> {
event.player.sendMessage(ChatColor.RED + "Edit canceled");
event.manager.showGUI(event.player, this);
});
});
setPlayerButton(5, GuiUtils.createButtonItem(XMaterial.SUNFLOWER,
this.plugin.getLocale().getMessage("interface.kiteditor.addeconomy").getMessage(),
this.plugin.getLocale().getMessage("interface.kiteditor.addeconomylore").getMessage().split("\\|")),
(event) -> {
AnvilGui gui = new AnvilGui(this.player, this);
gui.setTitle(this.plugin.getLocale().getMessage("interface.kiteditor.addeconomyprompt").getMessage());
gui.setAction(aevent -> {
String msg = gui.getInputText().trim();
ItemStack parseStack = new ItemStack(Material.PAPER, 1);
ItemMeta meta = parseStack.getItemMeta();
ArrayList<String> lore = new ArrayList<>();
int index = 0;
while (index < msg.length()) {
lore.add(ChatColor.GREEN + "$" + msg.substring(index, Math.min(index + 30, msg.length())));
index += 30;
}
meta.setLore(lore);
meta.setDisplayName(this.plugin.getLocale().getMessage("general.type.money").getMessage());
parseStack.setItemMeta(meta);
this.plugin.getLocale().getMessage("interface.kiteditor.addeconomyok").processPlaceholder("amount", msg.trim())
.sendPrefixedMessage(this.player);
this.inventory.addItem(parseStack);
this.player.closeInventory();
});
this.guiManager.showGUI(event.player, gui);
});
setPlayerButton(7, GuiUtils.createButtonItem(XMaterial.SHEEP_SPAWN_EGG,
this.plugin.getLocale().getMessage("interface.kiteditor.clone").getMessage(),
this.plugin.getLocale().getMessage("interface.kiteditor.clonelore")
.getMessage().split("\\|")),
(event) -> {
AnvilGui gui = new AnvilGui(this.player, this);
gui.setTitle("Enter a new kit name");
gui.setAction(evnt -> {
String kitStr = gui.getInputText().toLowerCase().trim();
if (this.plugin.getKitManager().getKit(kitStr) != null) {
this.plugin.getLocale().getMessage("command.kit.kitalreadyexists").sendPrefixedMessage(this.player);
this.player.closeInventory();
} else {
Kit newKit = this.kit.clone(kitStr);
this.plugin.getKitManager().addKit(newKit);
restoreItemsInstance();
saveKit(this.player, this.inventory, false);
XSound.ENTITY_VILLAGER_YES.play(this.player);
Bukkit.getScheduler().runTaskLater(this.plugin, () ->
this.guiManager.showGUI(this.player, new KitEditorGui(this.plugin, this.player, newKit, null)), 5L);
}
});
this.guiManager.showGUI(this.player, gui);
});
setPlayerButton(8, GuiUtils.createButtonItem(XMaterial.CHEST,
this.plugin.getLocale().getMessage("interface.kiteditor.animation").getMessage(),
this.plugin.getLocale().getMessage("interface.kiteditor.animationlore")
.processPlaceholder("animation", this.kit.getKitAnimation().name())
.getMessage().split("\\|")),
(event) -> {
if (this.kit.getKitAnimation() == KitAnimation.NONE) {
this.kit.setKitAnimation(KitAnimation.ROULETTE);
} else {
this.kit.setKitAnimation(KitAnimation.NONE);
}
setInvItems();
});
}
public void saveKit(Player player, Inventory i, boolean muteSave) {
ItemStack[] items = i.getContents();
for (int num = 0; num < items.length; ++num) {
if (num < 10 || num == 17 || num == 36) {
items[num] = null;
}
}
items = Arrays.copyOf(items, items.length - 10);
this.kit.saveKit(Arrays.asList(items));
if (!muteSave) {
this.plugin.getLocale().getMessage("interface.kiteditor.saved")
.processPlaceholder("kit", this.kit.getName())
.sendPrefixedMessage(player);
}
}
public void replaceItem(Action action, Player player, ItemStack itemStack, int slot) {
if (itemStack.getItemMeta().hasLore()) {
ItemMeta meta = itemStack.getItemMeta();
List<String> newLore = new ArrayList<>();
for (String line : meta.getLore()) {
if (line.contains("Moveable")) {
continue;
}
if (line.equals(TextUtils.formatText("&8----"))) {
break;
}
newLore.add(line);
}
meta.setLore(newLore);
itemStack.setItemMeta(meta);
}
KitItem item = new KitItem(itemStack);
switch (action) {
case CHANCE_UP:
case CHANCE_DOWN:
if (action == Action.CHANCE_UP) {
item.setChance(item.getChance() >= 100 ? 5 : (item.getChance() + 5));
} else {
item.setChance(item.getChance() <= 0 ? 100 : (item.getChance() - 5));
}
setItem(slot, getCompiledMeta(item));
saveKit(player, this.inventory, true);
paint();
break;
case DISPLAY_ITEM: {
AnvilGui gui = new AnvilGui(player, this);
gui.setTitle("Enter a Material");
gui.setAction(event -> {
Optional<XMaterial> compatibleMaterial = XMaterial.matchXMaterial(gui.getInputText().trim());
if (!compatibleMaterial.isPresent()) {
player.sendMessage("'" + gui.getInputText().trim() + "' is not a valid material.");
} else {
Material material = compatibleMaterial.get().parseMaterial();
KitItem newItem = new KitItem(itemStack);
newItem.setDisplayItem(material);
setItem(slot, newItem.getMoveableItem());
player.closeInventory();
saveKit(player, this.inventory, true);
paint();
}
});
this.guiManager.showGUI(player, gui);
}
break;
case DISPLAY_NAME: {
AnvilGui gui = new AnvilGui(player, this);
gui.setTitle("Enter a name");
gui.setAction(event -> {
KitItem newItem = new KitItem(itemStack);
newItem.setDisplayName(gui.getInputText());
setItem(slot, getCompiledMeta(newItem));
player.closeInventory();
saveKit(player, this.inventory, true);
paint();
});
this.guiManager.showGUI(player, gui);
}
break;
case DISPLAY_LORE: {
AnvilGui gui = new AnvilGui(player, this);
gui.setTitle("Enter lore");
gui.setAction(event -> {
KitItem newItem = new KitItem(itemStack);
newItem.setDisplayLore(gui.getInputText());
setItem(slot, getCompiledMeta(newItem));
player.closeInventory();
saveKit(player, this.inventory, true);
paint();
});
this.guiManager.showGUI(player, gui);
}
break;
default:
paint();
break;
}
}
private ItemStack getCompiledMeta(KitItem item) {
ItemStack is = item.getMoveableItem();
ItemMeta meta;
if (is.hasItemMeta()) {
meta = is.getItemMeta();
} else {
meta = Bukkit.getItemFactory().getItemMeta(is.getType());
}
List<String> itemLore;
if (meta.hasLore()) {
itemLore = meta.getLore();
} else {
itemLore = new ArrayList<>();
}
itemLore.add(TextUtils.formatText("&8----"));
itemLore.add(ChatColor.GRAY + this.plugin.getLocale().getMessage("general.type.chance").getMessage().replaceFirst("^" + ChatColor.RESET, "")
+ ": " + ChatColor.GOLD + item.getChance() + "%"); //TODO use a placeholder message in locales
if (this.isInFunction) {
itemLore.addAll(Arrays.asList(this.plugin.getLocale().getMessage("interface.kiteditor.itemfunctionlore")
.processPlaceholder("item", item.getDisplayItem() == null ? "" : item.getDisplayItem().name())
.processPlaceholder("name", item.getDisplayName())
.processPlaceholder("lore", item.getDisplayLore())
.getMessage().split("\\|")));
}
meta.setLore(itemLore);
is.setItemMeta(meta);
return is;
}
public enum Action {NONE, CHANCE_UP, CHANCE_DOWN, DISPLAY_ITEM, DISPLAY_NAME, DISPLAY_LORE}
}

View File

@ -1,20 +1,19 @@
package com.songoda.ultimatekits.gui;
package com.craftaro.ultimatekits.gui;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.gui.AnvilGui;
import com.songoda.core.gui.Gui;
import com.songoda.core.gui.GuiUtils;
import com.songoda.core.utils.ItemUtils;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.category.Category;
import com.songoda.ultimatekits.kit.Kit;
import com.songoda.ultimatekits.settings.Settings;
import com.songoda.ultimatekits.utils.Methods;
import com.craftaro.core.gui.AnvilGui;
import com.craftaro.core.gui.Gui;
import com.craftaro.core.gui.GuiUtils;
import com.craftaro.core.utils.ItemUtils;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.category.Category;
import com.craftaro.ultimatekits.kit.Kit;
import com.craftaro.ultimatekits.settings.Settings;
import com.craftaro.ultimatekits.utils.Methods;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
public class KitGeneralOptionsGui extends Gui {
public KitGeneralOptionsGui(UltimateKits plugin, Player player, Kit kit, Gui back) {
super(3);
setTitle(plugin.getLocale().getMessage("interface.kitoptions.title")
@ -25,22 +24,22 @@ public class KitGeneralOptionsGui extends Gui {
Methods.fillGlass(this);
// exit button
setButton(0, 8, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(CompatibleMaterial.OAK_DOOR),
plugin.getLocale().getMessage("interface.button.exit").getMessage()),
setButton(0, 8, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(XMaterial.OAK_DOOR),
plugin.getLocale().getMessage("interface.button.exit").getMessage()),
ClickType.LEFT,
event -> exit());
// back button
setButton(0, 0, GuiUtils.createButtonItem(ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"),
plugin.getLocale().getMessage("interface.button.back").getMessage()),
plugin.getLocale().getMessage("interface.button.back").getMessage()),
ClickType.LEFT,
event -> guiManager.showGUI(player, new KitEditorGui(plugin, player, kit, back)));
event -> this.guiManager.showGUI(player, new KitEditorGui(plugin, player, kit, back)));
// edit delay
setButton(1, 2, GuiUtils.createButtonItem(CompatibleMaterial.CLOCK,
plugin.getLocale().getMessage("interface.kitoptions.delay").getMessage(),
plugin.getLocale().getMessage("interface.kitoptions.delaylore")
.processPlaceholder("delay", kit.getDelay()).getMessage().split("\\|")),
setButton(1, 2, GuiUtils.createButtonItem(XMaterial.CLOCK,
plugin.getLocale().getMessage("interface.kitoptions.delay").getMessage(),
plugin.getLocale().getMessage("interface.kitoptions.delaylore")
.processPlaceholder("delay", kit.getDelay()).getMessage().split("\\|")),
event -> {
AnvilGui gui = new AnvilGui(event.player, this);
gui.setTitle(plugin.getLocale().getMessage("interface.kitoptions.delayprompt").getMessage());
@ -57,14 +56,14 @@ public class KitGeneralOptionsGui extends Gui {
plugin.getLocale().getMessage("interface.kitoptions.delaynonumber").processPlaceholder("input", msg).sendPrefixedMessage(player);
plugin.saveKits(false);
});
guiManager.showGUI(event.player, gui);
this.guiManager.showGUI(event.player, gui);
});
// edit category
setButton(1, 4, GuiUtils.createButtonItem(CompatibleMaterial.BOOK,
plugin.getLocale().getMessage("interface.kitoptions.category").getMessage(),
plugin.getLocale().getMessage("interface.kitoptions.categorylore")
.processPlaceholder("category", kit.getCategory() == null ? "none" : kit.getCategory().getName()).getMessage().split("\\|")),
setButton(1, 4, GuiUtils.createButtonItem(XMaterial.BOOK,
plugin.getLocale().getMessage("interface.kitoptions.category").getMessage(),
plugin.getLocale().getMessage("interface.kitoptions.categorylore")
.processPlaceholder("category", kit.getCategory() == null ? "none" : kit.getCategory().getName()).getMessage().split("\\|")),
event -> {
if (event.clickType == ClickType.LEFT) {
AnvilGui gui = new AnvilGui(event.player, this);
@ -82,7 +81,7 @@ public class KitGeneralOptionsGui extends Gui {
plugin.getLocale().getMessage("interface.kitoptions.notacategory").processPlaceholder("input", msg).sendPrefixedMessage(player);
plugin.saveKits(false);
});
guiManager.showGUI(event.player, gui);
this.guiManager.showGUI(event.player, gui);
} else if (event.clickType == ClickType.RIGHT) {
kit.setCategory(null);
updateItemLore(event.slot, plugin.getLocale().getMessage("interface.kitoptions.categorylore")
@ -91,9 +90,9 @@ public class KitGeneralOptionsGui extends Gui {
});
// delete
setButton(1, 6, GuiUtils.createButtonItem(CompatibleMaterial.TNT,
plugin.getLocale().getMessage("interface.kitoptions.destroy").getMessage(),
plugin.getLocale().getMessage("interface.kitoptions.destroylore").getMessage().split("\\|")),
setButton(1, 6, GuiUtils.createButtonItem(XMaterial.TNT,
plugin.getLocale().getMessage("interface.kitoptions.destroy").getMessage(),
plugin.getLocale().getMessage("interface.kitoptions.destroylore").getMessage().split("\\|")),
event -> {
AnvilGui gui = new AnvilGui(event.player);
gui.setTitle(plugin.getLocale().getMessage("interface.kitoptions.destroyprompt").processPlaceholder("kit", kit.getKey()).getMessage());
@ -109,9 +108,7 @@ public class KitGeneralOptionsGui extends Gui {
aevent.player.closeInventory();
plugin.saveKits(false);
});
guiManager.showGUI(event.player, gui);
this.guiManager.showGUI(event.player, gui);
});
}
}

View File

@ -0,0 +1,123 @@
package com.craftaro.ultimatekits.gui;
import com.craftaro.core.gui.AnvilGui;
import com.craftaro.core.gui.Gui;
import com.craftaro.core.gui.GuiUtils;
import com.craftaro.core.utils.ItemUtils;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.kit.Kit;
import com.craftaro.ultimatekits.settings.Settings;
import com.craftaro.ultimatekits.utils.Methods;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
public class KitGuiOptionsGui extends Gui {
private final UltimateKits plugin;
private final Kit kit;
private final Player player;
public KitGuiOptionsGui(UltimateKits plugin, Player player, Kit kit, Gui back) {
super(3);
this.plugin = plugin;
this.kit = kit;
this.player = player;
setTitle(plugin.getLocale().getMessage("interface.kitblock.title")
.processPlaceholder("kit", kit.getName())
.getMessage());
setAcceptsItems(true); // display item takes an item
// fill glass borders
Methods.fillGlass(this);
// exit button
setButton(0, 8, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(XMaterial.OAK_DOOR),
plugin.getLocale().getMessage("interface.button.exit").getMessage()),
ClickType.LEFT,
event -> exit());
// back button
setButton(0, 0, GuiUtils.createButtonItem(ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"),
plugin.getLocale().getMessage("interface.button.back").getMessage()),
ClickType.LEFT,
event -> this.guiManager.showGUI(player, new KitEditorGui(plugin, player, kit, back)));
paint();
}
private void paint() {
// set hologram title
setButton(1, 2, GuiUtils.createButtonItem(XMaterial.NAME_TAG,
this.plugin.getLocale().getMessage("interface.kitguioptions.holo").getMessage(),
this.plugin.getLocale().getMessage("interface.kitguioptions.hololore")
.processPlaceholder("onoff",
this.kit.getTitle() != null ? this.plugin.getLocale().getMessage("interface.kitguioptions.holoon").processPlaceholder("title", this.kit.getTitle()).getMessage()
: this.plugin.getLocale().getMessage("interface.kitguioptions.holooff").getMessage()
).getMessage().split("\\|")),
ClickType.LEFT,
event -> {
AnvilGui gui = new AnvilGui(event.player, this);
gui.setTitle(this.plugin.getLocale().getMessage("interface.kitguioptions.holoprompt").getMessage());
gui.setAction(evnt -> {
final String msg = gui.getInputText().trim();
this.kit.setTitle(msg);
this.plugin.getLocale().getMessage("interface.kitguioptions.holoset")
.processPlaceholder("title", msg)
.processPlaceholder("kit", this.kit.getName())
.sendPrefixedMessage(this.player);
this.plugin.updateHologram(this.kit);
evnt.player.closeInventory();
paint();
this.plugin.saveKits(false);
});
this.guiManager.showGUI(event.player, gui);
});
setAction(1, 2, ClickType.RIGHT, event -> {
this.kit.setTitle(null);
this.plugin.updateHologram(this.kit);
paint();
this.plugin.saveKits(false);
});
setButton(1, 4, GuiUtils.createButtonItem(this.kit.getDisplayItem() != null ? this.kit.getDisplayItem() : XMaterial.BEACON.parseItem(),
this.plugin.getLocale().getMessage("interface.kitguioptions.item").getMessage(),
this.plugin.getLocale().getMessage("interface.kitguioptions.itemlore")
.processPlaceholder("onoff",
this.kit.getDisplayItem() != null ? this.plugin.getLocale().getMessage("interface.kitguioptions.itemon")
.processPlaceholder("item", this.kit.getDisplayItem().toString()).getMessage()
: this.plugin.getLocale().getMessage("interface.kitguioptions.itemoff").getMessage()
).getMessage().split("\\|")),
ClickType.LEFT,
event -> {
ItemStack is = this.player.getItemInHand();
if (is.getType() == Material.AIR) {
this.plugin.getLocale().getMessage("interface.kitguioptions.itemnoitem").sendPrefixedMessage(this.player);
} else {
this.kit.setDisplayItem(is);
this.plugin.getLocale().getMessage("interface.kitguioptions.itemset").processPlaceholder("item", this.kit.getName()).sendPrefixedMessage(this.player);
paint();
}
this.plugin.saveKits(false);
});
setAction(1, 4, ClickType.RIGHT, event -> {
this.kit.setDisplayItem(null);
this.plugin.getLocale().getMessage("interface.kitguioptions.itemremoved").processPlaceholder("kit", this.kit.getName()).sendPrefixedMessage(this.player);
paint();
});
setButton(1, 6, GuiUtils.createButtonItem(XMaterial.COAL,
this.plugin.getLocale().getMessage("interface.kitguioptions.hide").getMessage(),
this.plugin.getLocale().getMessage("interface.kitguioptions.hidelore")
.processPlaceholder("onoff", this.plugin.getLocale().getMessage(
this.kit.isHidden() ? "interface.kitguioptions.hideon" : "interface.kitguioptions.hideoff").getMessage()
).getMessage().split("\\|")),
ClickType.LEFT,
event -> {
this.kit.setHidden(!this.kit.isHidden());
paint();
this.plugin.saveKits(false);
});
}
}

View File

@ -0,0 +1,227 @@
package com.craftaro.ultimatekits.gui;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.gui.Gui;
import com.craftaro.core.gui.GuiUtils;
import com.craftaro.core.utils.ItemUtils;
import com.craftaro.core.utils.TextUtils;
import com.craftaro.core.utils.TimeUtils;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.category.Category;
import com.craftaro.ultimatekits.kit.Kit;
import com.craftaro.ultimatekits.settings.Settings;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
public class KitSelectorGui extends Gui {
private final Player player;
private final UltimateKits plugin;
private int timer;
private final Category category;
private List<String> kitList;
private boolean kitsmode = false;
private final boolean glassless;
private final int showPerPage;
public KitSelectorGui(UltimateKits plugin, Player player, Category category) {
this.player = player;
this.plugin = plugin;
this.category = category;
this.glassless = Settings.DO_NOT_USE_GLASS_BORDERS.getBoolean();
setTitle(plugin.getLocale().getMessage("interface.selector.title").getMessage());
loadKits();
int showPerRow = this.glassless ? 9 : 7;
int nrows = (int) Math.ceil(this.kitList.size() / (double) showPerRow);
setRows(this.glassless ? nrows : nrows + 2);
this.showPerPage = showPerRow * (this.glassless ? (nrows == 6 ? 6 : 5) : 4);
setPages(this.kitList.size() / this.showPerPage);
setItem(0, 4, GuiUtils.createButtonItem(XMaterial.BOOK,
plugin.getLocale().getMessage("interface.selector.details")
.processPlaceholder("player", player.getName()).getMessage().split("\\|")));
if (this.pages > 1) {
this.setNextPage(this.rows - 1, 5, GuiUtils.createButtonItem(ItemUtils.getCustomHead("1b6f1a25b6bc199946472aedb370522584ff6f4e83221e5946bd2e41b5ca13b"),
plugin.getLocale().getMessage("interface.button.next").getMessage()));
this.setPrevPage(this.rows - 1, 3, GuiUtils.createButtonItem(ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"),
plugin.getLocale().getMessage("interface.button.last").getMessage()));
this.setOnPage(pager -> showPage());
}
if (!this.glassless) {
setButton(this.rows - 1, 4, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(XMaterial.OAK_DOOR),
UltimateKits.getInstance().getLocale().getMessage("interface.button.exit").getMessage()),
event -> exit());
}
ItemStack glass2 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_2.getMaterial());
setDefaultItem(AIR);
mirrorFill(0, 0, true, true, glass2);
if (!this.glassless) {
if (Settings.RAINBOW.getBoolean()) {
animateGlass();
this.timer = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
if (this.inventory.getViewers().isEmpty()) {
return;
}
animateGlass();
}, 20L, 20L);
setOnClose(event -> Bukkit.getScheduler().cancelTask(this.timer));
} else {
ItemStack glass1 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_1.getMaterial());
ItemStack glass3 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_3.getMaterial());
mirrorFill(0, 0, true, true, glass2);
mirrorFill(1, 0, true, true, glass2);
mirrorFill(0, 1, true, true, glass2);
mirrorFill(0, 2, true, true, glass3);
mirrorFill(0, 3, false, true, glass1);
}
}
if (category != null) {
setButton(0, 0, GuiUtils.createButtonItem(ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"),
plugin.getLocale().getMessage("interface.button.back").getMessage()),
event -> this.guiManager.showGUI(player, new CategorySelectorGui(plugin, player)));
}
showPage();
}
private void loadKits() {
this.kitList = this.plugin.getKitManager().getKits().stream()
.filter(kit -> !kit.isHidden() && kit.hasPermissionToPreview(this.player)
&& (this.category == null || kit.getCategory() == this.category))
.map(Kit::getKey)
.collect(Collectors.toList());
}
private static final Random rand = new Random();
private void animateGlass() {
for (int col = 1; col < 8; ++col) {
ItemStack it;
if ((it = getItem(0, col)) == null || it.getType() == Material.AIR || it.getType().name().contains("PANE")) {
setItem(0, col, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneForColor(rand.nextInt(16))));
}
if ((it = getItem(this.rows - 1, col)) == null || it.getType() == Material.AIR || it.getType().name().contains("PANE")) {
setItem(this.rows - 1, col, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneForColor(rand.nextInt(16))));
}
}
for (int row = 1; row + 1 < this.rows; ++row) {
setItem(row, 0, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneForColor(rand.nextInt(16))));
setItem(row, 8, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneForColor(rand.nextInt(16))));
}
}
private void showPage() {
int index = (this.page - 1) * this.showPerPage;
for (int row = this.glassless ? 0 : 1; row < (!this.glassless || this.pages != 1 ? this.rows - 1 : this.rows); ++row) {
for (int col = this.glassless ? 0 : 1; col < (this.glassless ? 9 : 8); ++col) {
if (index >= this.kitList.size()) {
setItem(row, col, null);
clearActions(row, col);
continue;
}
final String kitItem = this.kitList.get(index++);
final Kit kit = this.plugin.getKitManager().getKit(kitItem);
String kitTitle = kit.getTitle() != null
? ChatColor.translateAlternateColorCodes('&', kit.getTitle())
: this.plugin.getLocale().getMessage("interface.selector.kit")
.processPlaceholder("kit", TextUtils.formatText(kitItem, true)).getMessage();
setButton(row, col, GuiUtils.createButtonItem(
kit.getDisplayItem() != null ? kit.getDisplayItem() : XMaterial.ENCHANTED_BOOK.parseItem(), kitTitle,
getKitLore(kit)),
event -> {
if (event.clickType == ClickType.MIDDLE && this.player.hasPermission("ultimatekits.admin")) {
this.kitsmode = !this.kitsmode;
showPage();
} else if (this.kitsmode) {
if (event.clickType == ClickType.RIGHT) {
this.plugin.getKitManager().moveKit(kit, true);
} else if (event.clickType == ClickType.LEFT) {
this.plugin.getKitManager().moveKit(kit, false);
}
loadKits();
this.plugin.saveKits(false);
showPage();
} else if (event.clickType == ClickType.LEFT) {
kit.display(this.player, this.guiManager, this);
} else if (event.clickType == ClickType.RIGHT) {
kit.buy(event.player, event.manager);
}
});
}
}
}
private List<String> getKitLore(Kit kit) {
ArrayList<String> lore = new ArrayList<>();
if (kit.getPrice() != 0) {
lore.add(this.plugin.getLocale().getMessage("interface.selector.aboutkitprice")
.processPlaceholder("price", String.valueOf(kit.getPrice()))
.getMessage());
} else if (kit.getLink() != null) {
lore.add(this.plugin.getLocale().getMessage("general.type.link").getMessage());
}
if (!this.kitsmode) {
if (!this.plugin.getLocale().getMessage("interface.selector.aboutkit").getMessage().trim().equals("")) {
String[] parts = this.plugin.getLocale().getMessage("interface.selector.aboutkit").getMessage().split("\\|");
lore.add("");
for (String line : parts) {
lore.add(ChatColor.translateAlternateColorCodes('&', line));
}
}
if (kit.hasPermissionToClaim(this.player)) {
if (kit.getNextUse(this.player) == -1) {
lore.add(this.plugin.getLocale().getMessage("event.claim.once").getMessage());
} else if (kit.getNextUse(this.player) > 0) {
if (!this.plugin.getLocale().getMessage("event.claim.wait").getMessage().trim().equals("")) {
lore.add(this.plugin.getLocale().getMessage("event.claim.wait")
.processPlaceholder("time", TimeUtils.makeReadable(kit.getNextUse(this.player)))
.getMessage());
}
} else if (!this.plugin.getLocale().getMessage("event.claim.ready").getMessage().trim().equals("")) {
lore.add(this.plugin.getLocale().getMessage("event.claim.ready").getMessage());
}
} else {
lore.add(this.plugin.getLocale().getMessage("event.claim.noaccess").getMessage());
}
lore.add("");
lore.add(this.plugin.getLocale().getMessage("interface.selector.leftpreview").getMessage());
if (kit.hasPermissionToClaim(this.player)) {
lore.add(this.plugin.getLocale().getMessage("interface.selector.rightclaim").getMessage());
} else if (kit.getPrice() != 0 || kit.getLink() != null) {
lore.add(this.plugin.getLocale().getMessage("interface.selector.rightbuy").getMessage());
}
if (this.player.hasPermission("ultimatekits.admin")) {
lore.add("");
lore.add(this.plugin.getLocale().getMessage("interface.selector.adminlore").getMessage());
}
} else {
lore.addAll(Arrays.asList(this.plugin.getLocale().getMessage("interface.selector.editlore").getMessage().split("\\|")));
}
return lore;
}
}

View File

@ -0,0 +1,127 @@
package com.craftaro.ultimatekits.gui;
import com.craftaro.core.gui.AnvilGui;
import com.craftaro.core.gui.Gui;
import com.craftaro.core.gui.GuiUtils;
import com.craftaro.core.hooks.EconomyManager;
import com.craftaro.core.utils.ItemUtils;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.kit.Kit;
import com.craftaro.ultimatekits.settings.Settings;
import com.craftaro.ultimatekits.utils.Methods;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
public class KitSellingOptionsGui extends Gui {
private final UltimateKits plugin;
private final Player player;
private final Kit kit;
public KitSellingOptionsGui(UltimateKits plugin, Player player, Kit kit, Gui back) {
super(3);
this.plugin = plugin;
this.player = player;
this.kit = kit;
setTitle(plugin.getLocale().getMessage("interface.kitblock.title")
.processPlaceholder("kit", kit.getName())
.getMessage());
// fill glass borders
Methods.fillGlass(this);
// exit button
setButton(0, 8, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(XMaterial.OAK_DOOR),
plugin.getLocale().getMessage("interface.button.exit").getMessage()),
ClickType.LEFT,
event -> exit());
// back button
setButton(0, 0, GuiUtils.createButtonItem(ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"),
plugin.getLocale().getMessage("interface.button.back").getMessage()),
ClickType.LEFT,
event -> this.guiManager.showGUI(player, new KitEditorGui(plugin, player, kit, back)));
paint();
}
private void paint() {
// remove sale
setButton(1, 2, GuiUtils.createButtonItem(XMaterial.BARRIER,
this.plugin.getLocale().getMessage("interface.kitsell.nosell").getMessage(),
this.plugin.getLocale().getMessage("interface.kitsell.noselllore")
.processPlaceholder("onoff", this.plugin.getLocale().getMessage(
this.kit.getPrice() != 0 || this.kit.getLink() != null ? "interface.kitsell.nosellon" : "interface.kitsell.noselloff").getMessage()
).getMessage().split("\\|")),
event -> {
this.kit.setPrice(0);
this.kit.setLink(null);
paint();
});
// kit link
setButton(1, 4, GuiUtils.createButtonItem(XMaterial.PAPER,
this.plugin.getLocale().getMessage("interface.kitsell.link").getMessage(),
this.plugin.getLocale().getMessage("interface.kitsell.linklore")
.processPlaceholder("onoff",
this.kit.getLink() != null ? this.plugin.getLocale().getMessage("interface.kitsell.linkon").processPlaceholder("kit", this.kit.getLink()).getMessage()
: this.plugin.getLocale().getMessage("interface.kitsell.linkoff").getMessage()
).getMessage().split("\\|")),
event -> {
AnvilGui gui = new AnvilGui(event.player, this);
gui.setTitle(this.plugin.getLocale().getMessage("interface.kitsell.linkprompt").getMessage());
gui.setAction(aevent -> {
final String msg = gui.getInputText().trim();
if (this.kit.getPrice() != 0) {
this.kit.setPrice(0);
this.plugin.getLocale().getMessage("interface.kitsell.linknoeco").sendPrefixedMessage(this.player);
}
this.kit.setLink(msg);
this.plugin.updateHologram(this.kit);
aevent.player.closeInventory();
paint();
this.plugin.saveKits(false);
});
this.guiManager.showGUI(event.player, gui);
});
// kit price
setButton(1, 6, GuiUtils.createButtonItem(XMaterial.SUNFLOWER,
this.plugin.getLocale().getMessage("interface.kitsell.price").getMessage(),
this.plugin.getLocale().getMessage("interface.kitsell.pricelore")
.processPlaceholder("onoff",
this.kit.getPrice() != 0 ? this.plugin.getLocale().getMessage("interface.kitsell.priceon")
.processPlaceholder("price", this.kit.getPrice()).getMessage()
: this.plugin.getLocale().getMessage("interface.kitsell.priceoff").getMessage()
).getMessage().split("\\|")),
event -> {
if (!EconomyManager.isEnabled()) {
this.plugin.getLocale().getMessage("interface.kitsell.pricenoeco").sendPrefixedMessage(event.player);
return;
}
AnvilGui gui = new AnvilGui(event.player, this);
gui.setTitle(this.plugin.getLocale().getMessage("interface.kitsell.priceprompt").getMessage());
gui.setAction(aevent -> {
final String msg = gui.getInputText().trim();
double d = 0;
try {
d = Double.parseDouble(msg);
} catch (NumberFormatException e) {
}
if (d <= 0) {
this.plugin.getLocale().getMessage("interface.kitsell.pricenonumber").processPlaceholder("input", msg).sendPrefixedMessage(this.player);
} else {
if (this.kit.getLink() != null) {
this.kit.setLink(null);
this.plugin.getLocale().getMessage("interface.kitsell.pricenolink").sendPrefixedMessage(this.player);
}
this.kit.setPrice(d);
this.plugin.updateHologram(this.kit);
aevent.player.closeInventory();
paint();
this.plugin.saveKits(false);
}
});
this.guiManager.showGUI(event.player, gui);
});
}
}

View File

@ -1,26 +1,27 @@
package com.songoda.ultimatekits.gui;
package com.craftaro.ultimatekits.gui;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.gui.Gui;
import com.songoda.core.gui.GuiUtils;
import com.songoda.core.utils.ItemUtils;
import com.songoda.core.utils.TextUtils;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.kit.Kit;
import com.songoda.ultimatekits.settings.Settings;
import com.songoda.ultimatekits.utils.Methods;
import com.craftaro.core.gui.Gui;
import com.craftaro.core.gui.GuiUtils;
import com.craftaro.core.utils.NumberUtils;
import com.craftaro.core.utils.TextUtils;
import com.craftaro.third_party.com.cryptomorin.xseries.SkullUtils;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.kit.Kit;
import com.craftaro.ultimatekits.settings.Settings;
import com.craftaro.ultimatekits.utils.Methods;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class PreviewKitGui extends Gui {
private final Kit kit;
private final Player player;
private final UltimateKits plugin;
@ -81,21 +82,24 @@ public class PreviewKitGui extends Gui {
Methods.fillGlass(this);
// exit button is only visible with a glass border
setButton(0, 8, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(CompatibleMaterial.OAK_DOOR),
plugin.getLocale().getMessage("interface.button.exit").getMessage()),
setButton(0, 8, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(XMaterial.OAK_DOOR),
plugin.getLocale().getMessage("interface.button.exit").getMessage()),
event -> exit());
if (back != null) {
setButton(0, 0, GuiUtils.createButtonItem(ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"),
plugin.getLocale().getMessage("interface.button.back").getMessage()),
ItemStack buttonItem = XMaterial.PLAYER_HEAD.parseItem();
SkullMeta meta = SkullUtils.applySkin(buttonItem.getItemMeta(), "3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
buttonItem.setItemMeta(meta);
setButton(0, 0, GuiUtils.createButtonItem(buttonItem, plugin.getLocale().getMessage("interface.button.back").getMessage()),
event -> event.player.closeInventory());
}
}
// purchase button
if (buyable) {
setButton(rows - 1, 4, GuiUtils.createButtonItem(Settings.BUY_ICON.getMaterial(CompatibleMaterial.EMERALD),
plugin.getLocale().getMessage("interface.button.buynow").getMessage(),
getBuyLore()),
setButton(this.rows - 1, 4, GuiUtils.createButtonItem(Settings.BUY_ICON.getMaterial(XMaterial.EMERALD),
plugin.getLocale().getMessage("interface.button.buynow").getMessage(),
getBuyLore()),
event -> {
exit();
kit.buy(event.player, event.manager);
@ -105,7 +109,7 @@ public class PreviewKitGui extends Gui {
// display the kit items here
Iterator<ItemStack> items = list.iterator();
int startRow = useGlassBorder ? 1 : 0;
int endRow = useGlassBorder ? rows - 2 : rows - 1;
int endRow = useGlassBorder ? this.rows - 2 : this.rows - 1;
int startCol = useGlassBorder ? 1 : 0;
int endCol = useGlassBorder ? 7 : 8;
for (int row = startRow; row <= endRow; ++row) {
@ -143,7 +147,7 @@ public class PreviewKitGui extends Gui {
List<String> newLore = new ArrayList<>();
if (meta != null && meta.hasLore()) {
for (String str : meta.getLore()) {
newLore.add(str.replace("{PLAYER}", player.getName()).replace("<PLAYER>", player.getName()));
newLore.add(str.replace("{PLAYER}", this.player.getName()).replace("<PLAYER>", this.player.getName()));
}
meta.setLore(newLore);
}
@ -157,7 +161,7 @@ public class PreviewKitGui extends Gui {
List<String> newLore = new ArrayList<>();
if (meta != null && meta.hasLore()) {
for (String str : meta.getLore()) {
newLore.add(str.replace("{PLAYER}", player.getName()).replace("<PLAYER>", player.getName()));
newLore.add(str.replace("{PLAYER}", this.player.getName()).replace("<PLAYER>", this.player.getName()));
}
}
meta.setLore(newLore);
@ -168,21 +172,21 @@ public class PreviewKitGui extends Gui {
private List<String> getBuyLore() {
ArrayList<String> lore = new ArrayList<>();
if (kit.hasPermissionToClaim(player)) {
lore.add(plugin.getLocale().getMessage("interface.button.clickeco")
if (this.kit.hasPermissionToClaim(this.player)) {
lore.add(this.plugin.getLocale().getMessage("interface.button.clickeco")
.processPlaceholder("price", "0").getMessage());
if (player.isOp()) {
if (this.player.isOp()) {
lore.add("");
lore.add(ChatColor.GRAY + "This is free because");
lore.add(ChatColor.GRAY + "you have perms for it.");
lore.add(ChatColor.GRAY + "Everyone else buys");
lore.add(ChatColor.GRAY + "this for " + ChatColor.GREEN + "$" + Methods.formatEconomy(kit.getPrice()) + ChatColor.GRAY + ".");
lore.add(ChatColor.GRAY + "this for " + ChatColor.GREEN + "$" + NumberUtils.formatNumber(this.kit.getPrice()) + ChatColor.GRAY + ".");
}
} else {
lore.add(plugin.getLocale().getMessage("interface.button.clickeco")
.processPlaceholder("price", Methods.formatEconomy(kit.getPrice())).getMessage());
lore.add(this.plugin.getLocale().getMessage("interface.button.clickeco")
.processPlaceholder("price", NumberUtils.formatNumber(this.kit.getPrice())).getMessage());
}
if (kit.getDelay() != 0 && player.isOp()) {
if (this.kit.getDelay() != 0 && this.player.isOp()) {
lore.add("");
lore.add(ChatColor.GRAY + "You do not have a delay");
lore.add(ChatColor.GRAY + "because you have perms");
@ -190,5 +194,4 @@ public class PreviewKitGui extends Gui {
}
return lore;
}
}

View File

@ -1,9 +1,9 @@
package com.songoda.ultimatekits.handlers;
package com.craftaro.ultimatekits.handlers;
import com.songoda.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.kit.Kit;
import com.songoda.ultimatekits.kit.KitBlockData;
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.craftaro.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.kit.Kit;
import com.craftaro.ultimatekits.kit.KitBlockData;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
@ -17,11 +17,7 @@ import org.bukkit.util.Vector;
import java.util.Collections;
import java.util.List;
/**
* Created by songoda on 2/24/2017.
*/
public class DisplayItemHandler {
private final UltimateKits plugin;
public DisplayItemHandler(UltimateKits plugin) {
@ -29,12 +25,13 @@ public class DisplayItemHandler {
}
public void start() {
Bukkit.getServer().getScheduler().runTaskTimer(plugin, this::displayItems, 30L, 30L);
Bukkit.getServer().getScheduler().runTaskTimer(this.plugin, this::displayItems, 30L, 30L);
}
private void displayItems() {
for (KitBlockData kitBlockData : plugin.getKitManager().getKitLocations().values())
for (KitBlockData kitBlockData : this.plugin.getKitManager().getKitLocations().values()) {
displayItem(kitBlockData);
}
}
public void displayItem(KitBlockData kitBlockData) {
@ -42,15 +39,22 @@ public class DisplayItemHandler {
location.add(0.5, 0, 0.5);
Kit kit = kitBlockData.getKit();
if (kit == null) return;
if (kit == null) {
return;
}
List<ItemStack> list = kit.getReadableContents(null, false, false, false);
if (list == null) return;
if (list.isEmpty()) return;
if (!location.getWorld().isChunkLoaded((int) location.getX() >> 4, (int) location.getZ() >> 4))
if (list == null) {
return;
}
if (list.isEmpty()) {
return;
}
if (!location.getWorld().isChunkLoaded((int) location.getX() >> 4, (int) location.getZ() >> 4)) {
return;
}
for (Entity e : location.getChunk().getEntities()) {
if (e.getType() != EntityType.DROPPED_ITEM
@ -60,19 +64,24 @@ public class DisplayItemHandler {
}
Item i = (Item) e;
if (!kitBlockData.isDisplayingItems()) e.remove();
if (!kitBlockData.isDisplayingItems()) {
e.remove();
}
NBTItem nbtItem = new NBTItem(i.getItemStack());
int inum = nbtItem.hasKey("num") ? nbtItem.getInteger("num") + 1 : 0;
int inum = nbtItem.hasTag("num") ? nbtItem.getInteger("num") + 1 : 0;
int size = list.size();
if (inum > size || inum <= 0) inum = 1;
if (inum > size || inum <= 0) {
inum = 1;
}
ItemStack is = list.get(inum - 1);
if (kitBlockData.isItemOverride()) {
if (kit.getDisplayItem() != null)
if (kit.getDisplayItem() != null) {
is = kit.getDisplayItem();
}
}
is.setAmount(1);
ItemMeta meta = is.getItemMeta();
@ -85,7 +94,9 @@ public class DisplayItemHandler {
i.setPickupDelay(9999);
return;
}
if (!kitBlockData.isDisplayingItems()) return;
if (!kitBlockData.isDisplayingItems()) {
return;
}
ItemStack is = list.get(0);
is.setAmount(1);
@ -96,15 +107,15 @@ public class DisplayItemHandler {
NBTItem nbtItem = new NBTItem(is);
nbtItem.setInteger("num", 0);
Bukkit.getScheduler().runTask(plugin, () -> {
Bukkit.getScheduler().runTask(this.plugin, () -> {
Item item = location.getWorld().dropItem(location.add(0, 1, 0), nbtItem.getItem());
Vector vec = new Vector(0, 0, 0);
item.setVelocity(vec);
item.setPickupDelay(9999);
item.setCustomName(null);
item.setMetadata("US_EXEMPT", new FixedMetadataValue(UltimateKits.getInstance(), true));
item.setMetadata("displayItem", new FixedMetadataValue(UltimateKits.getInstance(), true));
item.setMetadata("betterdrops_ignore", new FixedMetadataValue(UltimateKits.getInstance(), true));
item.setMetadata("US_EXEMPT", new FixedMetadataValue(this.plugin, true));
item.setMetadata("displayItem", new FixedMetadataValue(this.plugin, true));
item.setMetadata("betterdrops_ignore", new FixedMetadataValue(this.plugin, true));
});
}
}

View File

@ -1,20 +1,16 @@
package com.songoda.ultimatekits.handlers;
package com.craftaro.ultimatekits.handlers;
import com.songoda.core.compatibility.CompatibleParticleHandler;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.kit.KitBlockData;
import com.songoda.ultimatekits.settings.Settings;
import com.craftaro.core.compatibility.CompatibleParticleHandler;
import com.craftaro.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.kit.KitBlockData;
import com.craftaro.ultimatekits.settings.Settings;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import java.util.ArrayList;
import java.util.Map;
/**
* Created by songoda on 2/24/2017.
*/
public class ParticleHandler {
private final UltimateKits plugin;
private int amt;
private CompatibleParticleHandler.ParticleType type;
@ -24,25 +20,26 @@ public class ParticleHandler {
}
public void start() {
amt = Settings.PARTICLE_AMOUNT.getInt() / 2;
this.amt = Settings.PARTICLE_AMOUNT.getInt() / 2;
String typeName = Settings.PARTICLE_TYPE.getString();
type = CompatibleParticleHandler.ParticleType.getParticle(typeName);
if (type == null) {
type = CompatibleParticleHandler.ParticleType.SPELL_WITCH;
this.type = CompatibleParticleHandler.ParticleType.getParticle(typeName);
if (this.type == null) {
this.type = CompatibleParticleHandler.ParticleType.SPELL_WITCH;
}
Bukkit.getServer().getScheduler().runTaskTimerAsynchronously(UltimateKits.getInstance(), this::applyParticles, 0, 5L);
}
private void applyParticles() {
Map<Location, KitBlockData> kitBlocks = plugin.getKitManager().getKitLocations();
Map<Location, KitBlockData> kitBlocks = this.plugin.getKitManager().getKitLocations();
for (KitBlockData kitBlockData : new ArrayList<>(kitBlocks.values())) {
if (kitBlockData.getLocation().getWorld() == null || !kitBlockData.hasParticles()) continue;
if (kitBlockData.getLocation().getWorld() == null || !kitBlockData.hasParticles()) {
continue;
}
Location location = kitBlockData.getLocation();
location.add(.5, 0, .5);
CompatibleParticleHandler.spawnParticles(type, location, amt, 0.25, 0.25, 0.25, 0.5);
CompatibleParticleHandler.spawnParticles(this.type, location, this.amt, 0.25, 0.25, 0.25, 0.5);
}
}
}

View File

@ -1,11 +1,11 @@
package com.songoda.ultimatekits.key;
package com.craftaro.ultimatekits.key;
import com.songoda.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.songoda.core.utils.ItemUtils;
import com.songoda.core.utils.TextUtils;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.kit.Kit;
import com.songoda.ultimatekits.settings.Settings;
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.craftaro.core.utils.ItemUtils;
import com.craftaro.core.utils.TextUtils;
import com.craftaro.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.kit.Kit;
import com.craftaro.ultimatekits.settings.Settings;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@ -13,11 +13,10 @@ import java.util.ArrayList;
import java.util.List;
public class Key {
// The name of the key.
private final String name;
// The amount of items this key will give you. -1 is all;
// The number of items this key will give you; -1 is all
private final int amount;
// Should the key be enchanted?
@ -35,7 +34,7 @@ public class Key {
public ItemStack getKeyItem(Kit kit, int amount) {
UltimateKits plugin = UltimateKits.getInstance();
ItemStack item = Settings.KEY_MATERIAL.getMaterial().getItem();
ItemStack item = Settings.KEY_MATERIAL.getMaterial().parseItem();
item.setAmount(amount);
String kitName = kit != null ? TextUtils.formatText(kit.getName(), true)
@ -45,53 +44,57 @@ public class Key {
meta.setDisplayName(plugin.getLocale().getMessage("interface.key.title")
.processPlaceholder("kit", kitName).getMessage());
if (enchanted)
if (this.enchanted) {
ItemUtils.addGlow(item);
}
List<String> lore = new ArrayList<>();
lore.add(plugin.getLocale().getMessage("interface.key.name")
.processPlaceholder("name", name).getMessage());
.processPlaceholder("name", this.name).getMessage());
String desc1 = plugin.getLocale().getMessage("interface.key.description1")
.processPlaceholder("kit", kitName).getMessage();
if (kit == null)
if (kit == null) {
desc1 = desc1.replaceAll("\\[.*?\\]", "");
else
} else {
desc1 = desc1.replace("[", "").replace("]", "");
}
lore.add(desc1);
if (this.amount == -1)
if (this.amount == -1) {
lore.add(plugin.getLocale().getMessage("interface.key.description2").getMessage());
else
} else {
lore.add(plugin.getLocale().getMessage("interface.key.description3").getMessage());
if (kitAmount > 1)
}
if (this.kitAmount > 1) {
lore.add(plugin.getLocale().getMessage("interface.key.description4")
.processPlaceholder("amt", this.kitAmount).getMessage());
}
meta.setLore(lore);
item.setItemMeta(meta);
NBTItem nbtItem = new NBTItem(item);
nbtItem.setString("key", name);
nbtItem.setString("key", this.name);
nbtItem.setString("kit", kit == null ? "ANY" : kit.getName());
return nbtItem.getItem();
}
public String getName() {
return name;
return this.name;
}
public int getAmount() {
return amount;
return this.amount;
}
public int getKitAmount() {
return kitAmount;
return this.kitAmount;
}
public boolean isEnchanted() {
return enchanted;
return this.enchanted;
}
}

View File

@ -0,0 +1,39 @@
package com.craftaro.ultimatekits.key;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
public final class KeyManager {
private final Set<Key> registeredKeys = new HashSet<>();
public boolean addKey(Key key) {
if (key == null) {
return false;
}
return this.registeredKeys.add(key);
}
public void removeKey(Key key) {
this.registeredKeys.remove(key);
}
public Key getKey(String name) {
for (Key key : this.registeredKeys) {
if (key.getName().equalsIgnoreCase(name)) {
return key;
}
}
return null;
}
public Set<Key> getKeys() {
return Collections.unmodifiableSet(this.registeredKeys);
}
public void clear() {
this.registeredKeys.clear();
}
}

View File

@ -1,26 +1,26 @@
package com.songoda.ultimatekits.kit;
package com.craftaro.ultimatekits.kit;
import com.songoda.core.compatibility.CompatibleHand;
import com.songoda.core.compatibility.CompatibleSound;
import com.songoda.core.configuration.Config;
import com.songoda.core.gui.Gui;
import com.songoda.core.gui.GuiManager;
import com.songoda.core.hooks.EconomyManager;
import com.songoda.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.songoda.core.utils.ItemUtils;
import com.songoda.core.utils.TextUtils;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.category.Category;
import com.songoda.ultimatekits.crate.Crate;
import com.songoda.ultimatekits.gui.AnimatedKitGui;
import com.songoda.ultimatekits.gui.ConfirmBuyGui;
import com.songoda.ultimatekits.gui.PreviewKitGui;
import com.songoda.ultimatekits.key.Key;
import com.songoda.ultimatekits.kit.type.KitContentCommand;
import com.songoda.ultimatekits.kit.type.KitContentEconomy;
import com.songoda.ultimatekits.settings.Settings;
import com.songoda.ultimatekits.utils.ArmorType;
import com.songoda.ultimatekits.utils.Methods;
import com.craftaro.core.compatibility.CompatibleHand;
import com.craftaro.core.configuration.Config;
import com.craftaro.core.gui.Gui;
import com.craftaro.core.gui.GuiManager;
import com.craftaro.core.hooks.EconomyManager;
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.craftaro.core.utils.ItemUtils;
import com.craftaro.core.utils.TextUtils;
import com.craftaro.core.utils.TimeUtils;
import com.craftaro.third_party.com.cryptomorin.xseries.XSound;
import com.craftaro.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.category.Category;
import com.craftaro.ultimatekits.crate.Crate;
import com.craftaro.ultimatekits.gui.AnimatedKitGui;
import com.craftaro.ultimatekits.gui.ConfirmBuyGui;
import com.craftaro.ultimatekits.gui.PreviewKitGui;
import com.craftaro.ultimatekits.key.Key;
import com.craftaro.ultimatekits.kit.type.KitContentCommand;
import com.craftaro.ultimatekits.kit.type.KitContentEconomy;
import com.craftaro.ultimatekits.settings.Settings;
import com.craftaro.ultimatekits.utils.ArmorType;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
@ -53,8 +53,9 @@ public class Kit implements Cloneable {
private KitAnimation kitAnimation = KitAnimation.NONE;
public Kit(String key) {
if (plugin == null)
if (plugin == null) {
plugin = UltimateKits.getInstance();
}
this.key = key;
this.name = TextUtils.formatText(key, true);
}
@ -71,12 +72,12 @@ public class Kit implements Cloneable {
return;
}
if (link != null) {
if (this.link != null) {
player.sendMessage("");
plugin.getLocale().newMessage("&a" + link).sendPrefixedMessage(player);
plugin.getLocale().newMessage("&a" + this.link).sendPrefixedMessage(player);
player.sendMessage("");
player.closeInventory();
} else if (price != 0) {
} else if (this.price != 0) {
manager.showGUI(player, new ConfirmBuyGui(plugin, player, this, null));
} else {
UltimateKits.getInstance().getLocale().getMessage("command.general.noperms")
@ -95,8 +96,9 @@ public class Kit implements Cloneable {
}
// Since roulette only gives one item, we don't need to check if the user has room for the whole kit.
if (kitAnimation == KitAnimation.ROULETTE && space >= 1)
if (this.kitAnimation == KitAnimation.ROULETTE && space >= 1) {
return true;
}
return space >= itemAmount;
}
@ -105,8 +107,9 @@ public class Kit implements Cloneable {
ItemStack item = player.getItemInHand();
NBTItem nbtItem = new NBTItem(item);
if (!nbtItem.hasKey("key") || !nbtItem.hasKey("kit"))
if (!nbtItem.hasKey("key") || !nbtItem.hasKey("kit")) {
return;
}
String keyName = nbtItem.getString("key");
String kitName = nbtItem.getString("kit");
@ -114,17 +117,18 @@ public class Kit implements Cloneable {
boolean any = kitName.equals("ANY");
Key key = plugin.getKeyManager().getKey(keyName);
if (key == null && !any)
if (key == null && !any) {
return;
}
if (!any && !kitName.equals(name)) {
if (!any && !kitName.equals(this.name)) {
plugin.getLocale().getMessage("event.crate.wrongkey").sendPrefixedMessage(player);
return;
}
if (giveKit(player, key)) {
plugin.getLocale().getMessage("event.key.success")
.processPlaceholder("kit", name).sendPrefixedMessage(player);
.processPlaceholder("kit", this.name).sendPrefixedMessage(player);
if (player.getInventory().getItemInHand().getAmount() != 1) {
item.setAmount(item.getAmount() - 1);
player.setItemInHand(item);
@ -137,31 +141,34 @@ public class Kit implements Cloneable {
public void processCrateUse(Player player, ItemStack item, CompatibleHand hand) {
Crate crate = plugin.getCrateManager().getCrate(item);
if (crate == null || !giveKit(player, crate))
if (crate == null || !giveKit(player, crate)) {
return;
}
ItemUtils.takeActiveItem(player, hand);
plugin.getLocale().getMessage("event.crate.success")
.processPlaceholder("crate", name).sendPrefixedMessage(player);
.processPlaceholder("crate", this.name).sendPrefixedMessage(player);
}
public void processPurchaseUse(Player player) {
if (!EconomyManager.isEnabled()) return;
if (!EconomyManager.isEnabled()) {
return;
}
if (!player.hasPermission("ultimatekits.buy." + key)) {
if (!player.hasPermission("ultimatekits.buy." + this.key)) {
UltimateKits.getInstance().getLocale().getMessage("command.general.noperms")
.sendPrefixedMessage(player);
return;
} else if (!EconomyManager.hasBalance(player, price)) {
} else if (!EconomyManager.hasBalance(player, this.price)) {
plugin.getLocale().getMessage("event.claim.cannotafford")
.processPlaceholder("kit", name).sendPrefixedMessage(player);
.processPlaceholder("kit", this.name).sendPrefixedMessage(player);
return;
}
if (this.delay > 0) {
if (getNextUse(player) != 0) {
plugin.getLocale().getMessage("event.claim.delay")
.processPlaceholder("time", Methods.makeReadable(this.getNextUse(player)))
.processPlaceholder("time", TimeUtils.makeReadable(this.getNextUse(player)))
.sendPrefixedMessage(player);
return;
}
@ -170,12 +177,13 @@ public class Kit implements Cloneable {
return;
}
if (giveKit(player)) {
EconomyManager.withdrawBalance(player, price);
if (delay != 0)
EconomyManager.withdrawBalance(player, this.price);
if (this.delay != 0) {
updateDelay(player); //updates delay on buy
}
plugin.getLocale().getMessage("event.claim.purchasesuccess")
.processPlaceholder("kit", name).sendPrefixedMessage(player);
.processPlaceholder("kit", this.name).sendPrefixedMessage(player);
}
}
@ -185,13 +193,14 @@ public class Kit implements Cloneable {
} else if (getNextUse(player) <= 0 || forced) {
if (giveKit(player)) {
updateDelay(player);
if (kitAnimation == KitAnimation.NONE)
if (this.kitAnimation == KitAnimation.NONE) {
plugin.getLocale().getMessage("event.claim.givesuccess")
.processPlaceholder("kit", name).sendPrefixedMessage(player);
.processPlaceholder("kit", this.name).sendPrefixedMessage(player);
}
}
} else {
plugin.getLocale().getMessage("event.claim.delay")
.processPlaceholder("time", Methods.makeReadable(getNextUse(player)))
.processPlaceholder("time", TimeUtils.makeReadable(getNextUse(player)))
.sendPrefixedMessage(player);
}
}
@ -203,13 +212,13 @@ public class Kit implements Cloneable {
.sendPrefixedMessage(player);
return;
}
if (key == null) {
if (this.key == null) {
plugin.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(player);
return;
}
plugin.getLocale().getMessage("event.preview.kit")
.processPlaceholder("kit", name).sendPrefixedMessage(player);
.processPlaceholder("kit", this.name).sendPrefixedMessage(player);
manager.showGUI(player, new PreviewKitGui(plugin, player, this, back));
}
@ -222,8 +231,12 @@ public class Kit implements Cloneable {
ItemMeta meta = is.getItemMeta();
List<String> newLore = new ArrayList<>();
for (String line : meta.getLore()) {
if (line.contains("Moveable")) continue;
if (line.equals(TextUtils.formatText("&8----"))) break;
if (line.contains("Moveable")) {
continue;
}
if (line.equals(TextUtils.formatText("&8----"))) {
break;
}
newLore.add(line);
}
meta.setLore(newLore);
@ -248,7 +261,7 @@ public class Kit implements Cloneable {
}
}
}
contents = list;
this.contents = list;
plugin.saveKits(false);
}
@ -258,8 +271,12 @@ public class Kit implements Cloneable {
for (KitItem item : getContents()) {
if ((!item.getSerialized().startsWith("/") && !item.getSerialized().startsWith(Settings.CURRENCY_SYMBOL.getString())) || commands) { //ToDO: I doubt this is correct.
ItemStack stack = moveable ? item.getMoveableItem() : item.getItem();
if (preview) stack = item.getItemForDisplay();
if (stack == null) continue;
if (preview) {
stack = item.getItemForDisplay();
}
if (stack == null) {
continue;
}
ItemStack fin = stack;
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI") && stack.getItemMeta().getLore() != null) {
@ -279,7 +296,7 @@ public class Kit implements Cloneable {
}
public boolean giveKit(Player player) {
return giveKit(player, contents.size(), -1);
return giveKit(player, this.contents.size(), -1);
}
private boolean giveKit(Player player, Key key) {
@ -291,7 +308,7 @@ public class Kit implements Cloneable {
if (amount == -1) {
// FIXME: I don't understand how Crates, Keys, etc. actually are supposed to work.
// I think the give-algorithms are generally wrongly implemented and confusing naming is making it hard to understand.
amount = contents.size();
amount = this.contents.size();
}
return giveKit(player, amount, key.getKitAmount());
}
@ -301,7 +318,7 @@ public class Kit implements Cloneable {
if (amount == -1) {
// FIXME: I don't understand how Crates, Keys, etc. actually are supposed to work.
// I think the give-algorithms are generally wrongly implemented and confusing naming is making it hard to understand.
amount = contents.size();
amount = this.contents.size();
}
return giveKit(player, amount, crate.getKitAmount());
}
@ -310,8 +327,9 @@ public class Kit implements Cloneable {
List<KitItem> innerContents = new ArrayList<>(getContents());
// Amount of items from the kit to give to the player.
if (kitAnimation == KitAnimation.ROULETTE)
if (this.kitAnimation == KitAnimation.ROULETTE) {
itemAmount = 1; //TODO how about kitAmount > 1? generateRandomItem() will only give 1 random item instead of kitAmount
}
int itemGiveAmount = kitAmount > 0 ? itemAmount * kitAmount : itemAmount;
if (Settings.NO_REDEEM_WHEN_FULL.getBoolean() && !hasRoom(player, itemGiveAmount)) {
@ -319,24 +337,28 @@ public class Kit implements Cloneable {
return false;
}
if (Settings.SOUNDS_ENABLED.getBoolean() && kitAnimation == KitAnimation.NONE)
CompatibleSound.ENTITY_PLAYER_LEVELUP.play(player, 0.6F, 15.0F);
if (Settings.SOUNDS_ENABLED.getBoolean() && this.kitAnimation == KitAnimation.NONE) {
XSound.ENTITY_PLAYER_LEVELUP.play(player, 0.6F, 15.0F);
}
return generateRandomItem(innerContents, itemGiveAmount, 0, player);
}
private boolean generateRandomItem(List<KitItem> innerContents, int itemGiveAmount, int itemGivenAmount, Player player) {
if (innerContents.size() != itemGiveAmount || kitAnimation != KitAnimation.NONE)
if (innerContents.size() != itemGiveAmount || this.kitAnimation != KitAnimation.NONE) {
Collections.shuffle(innerContents);
}
for (KitItem item : new ArrayList<>(innerContents)) {
if (itemGiveAmount <= 0 && itemGivenAmount != 0) break;
if (itemGiveAmount <= 0 && itemGivenAmount != 0) {
break;
}
double ch = item.getChance() == 0 ? 100 : item.getChance();
double rand = Math.random() * 100;
itemGiveAmount--;
if (rand < ch || ch == 100) {
itemGivenAmount++;
if (kitAnimation != KitAnimation.NONE) {
if (this.kitAnimation != KitAnimation.NONE) {
// TODO: this is a very bad way to solve this problem.
// Giving the player kit rewards really should be done outside of the Kit class.
plugin.getGuiManager().showGUI(player, new AnimatedKitGui(plugin, player, this, item.getItem()));
@ -344,12 +366,15 @@ public class Kit implements Cloneable {
} else {
ItemStack parseStack = item.getContent().process(player);
if (item.getContent() instanceof KitContentEconomy
|| item.getContent() instanceof KitContentCommand)
|| item.getContent() instanceof KitContentCommand) {
continue;
}
innerContents.remove(item);
if (Settings.AUTO_EQUIP_ARMOR.getBoolean() && ArmorType.equip(player, parseStack)) continue;
if (Settings.AUTO_EQUIP_ARMOR.getBoolean() && ArmorType.equip(player, parseStack)) {
continue;
}
Map<Integer, ItemStack> overfilled = player.getInventory().addItem(parseStack);
for (ItemStack item2 : overfilled.values()) {
@ -359,24 +384,27 @@ public class Kit implements Cloneable {
}
}
if ((itemGiveAmount > 0 || itemGivenAmount == 0) && !innerContents.isEmpty())
if ((itemGiveAmount > 0 || itemGivenAmount == 0) && !innerContents.isEmpty()) {
return generateRandomItem(innerContents, itemGiveAmount, itemGivenAmount, player);
}
player.updateInventory();
return true;
}
public void updateDelay(Player player) {
plugin.getDataFile().set("Kits." + key + ".delays." + player.getUniqueId().toString(), System.currentTimeMillis());
plugin.getDataFile().set("Kits." + this.key + ".delays." + player.getUniqueId(), System.currentTimeMillis());
}
public Long getNextUse(Player player) {
String configSectionPlayer = "Kits." + key + ".delays." + player.getUniqueId().toString();
String configSectionPlayer = "Kits." + this.key + ".delays." + player.getUniqueId();
Config config = plugin.getDataFile();
if (!config.contains(configSectionPlayer)) {
return 0L;
} else if (this.delay == -1) return -1L;
} else if (this.delay == -1) {
return -1L;
}
long last = config.getLong(configSectionPlayer);
long delay = this.delay * 1000;
@ -385,19 +413,19 @@ public class Kit implements Cloneable {
}
public boolean hasPermissionToClaim(Player player) {
return player.hasPermission("ultimatekits.claim." + key.toLowerCase());
return player.hasPermission("ultimatekits.claim." + this.key.toLowerCase());
}
public boolean hasPermissionToPreview(Player player) {
return player.hasPermission("ultimatekits.preview." + key.toLowerCase());
return player.hasPermission("ultimatekits.preview." + this.key.toLowerCase());
}
public boolean hasPermissionToBuy(Player player) {
return player.hasPermission("ultimatekits.buy." + key.toLowerCase());
return player.hasPermission("ultimatekits.buy." + this.key.toLowerCase());
}
public double getPrice() {
return price;
return this.price;
}
public Kit setPrice(double price) {
@ -406,7 +434,7 @@ public class Kit implements Cloneable {
}
public String getLink() {
return link;
return this.link;
}
public Kit setLink(String link) {
@ -415,7 +443,7 @@ public class Kit implements Cloneable {
}
public String getTitle() {
return title;
return this.title;
}
public Kit setTitle(String title) {
@ -424,7 +452,7 @@ public class Kit implements Cloneable {
}
public long getDelay() {
return delay;
return this.delay;
}
public Kit setDelay(long delay) {
@ -433,7 +461,7 @@ public class Kit implements Cloneable {
}
public Category getCategory() {
return category;
return this.category;
}
public Kit setCategory(Category category) {
@ -451,15 +479,15 @@ public class Kit implements Cloneable {
}
public String getKey() {
return key;
return this.key;
}
public String getName() {
return name;
return this.name;
}
public ItemStack getDisplayItem() {
return displayItem;
return this.displayItem;
}
public Kit setDisplayItem(ItemStack item) {
@ -468,7 +496,7 @@ public class Kit implements Cloneable {
}
public boolean isHidden() {
return hidden;
return this.hidden;
}
public Kit setHidden(boolean hidden) {
@ -477,7 +505,7 @@ public class Kit implements Cloneable {
}
public KitAnimation getKitAnimation() {
return kitAnimation;
return this.kitAnimation;
}
public Kit setKitAnimation(KitAnimation kitAnimation) {
@ -491,8 +519,9 @@ public class Kit implements Cloneable {
List<KitItem> contents = new ArrayList<>();
for (KitItem item : newKit.contents)
for (KitItem item : newKit.contents) {
contents.add(item.clone());
}
newKit.setContents(contents);
@ -507,16 +536,19 @@ public class Kit implements Cloneable {
@Override
public int hashCode() {
return 31 * (key != null ? key.hashCode() : 0);
return 31 * (this.key != null ? this.key.hashCode() : 0);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Kit)) return false;
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof Kit)) {
return false;
}
Kit kit = (Kit) o;
return Objects.equals(key, kit.key);
Kit kit = (Kit) obj;
return Objects.equals(this.key, kit.key);
}
}

View File

@ -1,4 +1,4 @@
package com.songoda.ultimatekits.kit;
package com.craftaro.ultimatekits.kit;
public enum KitAnimation {
NONE, ROULETTE

View File

@ -1,13 +1,12 @@
package com.songoda.ultimatekits.kit;
package com.craftaro.ultimatekits.kit;
import com.songoda.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.UltimateKits;
import org.bukkit.Location;
import org.bukkit.World;
import java.util.UUID;
public class KitBlockData {
// This is the unique identifier for this block data.
// It is reset on every plugin load.
// Used for holograms.
@ -40,39 +39,39 @@ public class KitBlockData {
UltimateKits.getInstance().getDisplayItemHandler().displayItem(this);
UltimateKits.getInstance().removeHologram(this);
UltimateKits.getInstance().getDataManager().updateBlockData(this);
UltimateKits.getInstance().getKitDataManager().updateBlockData(this);
}
public Kit getKit() {
return kit;
return this.kit;
}
public Location getLocation() {
return location.clone();
return this.location.clone();
}
public boolean isInLoadedChunk() {
return location != null && location.getWorld() != null && location.getWorld().isChunkLoaded(((int) location.getX()) >> 4, ((int) location.getZ()) >> 4);
return this.location != null && this.location.getWorld() != null && this.location.getWorld().isChunkLoaded(((int) this.location.getX()) >> 4, ((int) this.location.getZ()) >> 4);
}
public int getX() {
return location.getBlockX();
return this.location.getBlockX();
}
public int getY() {
return location.getBlockY();
return this.location.getBlockY();
}
public int getZ() {
return location.getBlockZ();
return this.location.getBlockZ();
}
public World getWorld() {
return location.getWorld();
return this.location.getWorld();
}
public boolean showHologram() {
return hologram;
return this.hologram;
}
public void setShowHologram(boolean hologram) {
@ -80,7 +79,7 @@ public class KitBlockData {
}
public boolean hasParticles() {
return particles;
return this.particles;
}
public void setHasParticles(boolean particles) {
@ -88,7 +87,7 @@ public class KitBlockData {
}
public boolean isDisplayingItems() {
return items;
return this.items;
}
public void setDisplayingItems(boolean items) {
@ -96,7 +95,7 @@ public class KitBlockData {
}
public boolean isItemOverride() {
return itemOverride;
return this.itemOverride;
}
public void setItemOverride(boolean itemOverride) {
@ -104,7 +103,7 @@ public class KitBlockData {
}
public KitType getType() {
return type;
return this.type;
}
public void setType(KitType type) {
@ -112,6 +111,6 @@ public class KitBlockData {
}
public String getHologramId() {
return "UltimateKits-" + uniqueId;
return "UltimateKits-" + this.uniqueId;
}
}
}

View File

@ -1,14 +1,14 @@
package com.songoda.ultimatekits.kit;
package com.craftaro.ultimatekits.kit;
import com.songoda.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.songoda.core.utils.TextUtils;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.kit.type.KitContent;
import com.songoda.ultimatekits.kit.type.KitContentCommand;
import com.songoda.ultimatekits.kit.type.KitContentEconomy;
import com.songoda.ultimatekits.kit.type.KitContentItem;
import com.songoda.ultimatekits.settings.Settings;
import com.songoda.ultimatekits.utils.ItemSerializer;
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.craftaro.core.utils.TextUtils;
import com.craftaro.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.kit.type.KitContent;
import com.craftaro.ultimatekits.kit.type.KitContentCommand;
import com.craftaro.ultimatekits.kit.type.KitContentEconomy;
import com.craftaro.ultimatekits.kit.type.KitContentItem;
import com.craftaro.ultimatekits.settings.Settings;
import com.craftaro.ultimatekits.utils.ItemSerializer;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
@ -20,7 +20,6 @@ import java.util.Collections;
import java.util.List;
public class KitItem implements Cloneable {
private KitContent content;
private KitItemType type;
private String displayName, displayLore = null;
@ -59,41 +58,51 @@ public class KitItem implements Cloneable {
}
private void translateTags(ItemStack item) {
if (item == null) return;
if (item == null) {
return;
}
NBTItem nbtItem = new NBTItem(item);
if (nbtItem.hasKey("chance"))
chance = nbtItem.getDouble("chance");
if (nbtItem.hasKey("display-item"))
displayItem = Material.valueOf(nbtItem.getString("display-item"));
if (nbtItem.hasKey("display-name"))
displayName = nbtItem.getString("display-name");
if (nbtItem.hasKey("display-lore"))
displayLore = nbtItem.getString("display-lore");
if (nbtItem.hasKey("chance")) {
this.chance = nbtItem.getDouble("chance");
}
if (nbtItem.hasKey("display-item")) {
this.displayItem = Material.valueOf(nbtItem.getString("display-item"));
}
if (nbtItem.hasKey("display-name")) {
this.displayName = nbtItem.getString("display-name");
}
if (nbtItem.hasKey("display-lore")) {
this.displayLore = nbtItem.getString("display-lore");
}
}
private String translateLine(String line) {
String[] lineSplit = line.trim().split(";", 2);
String[] kitOptions = lineSplit[0].replace(String.valueOf(ChatColor.COLOR_CHAR), "").split("~");
for (String s : kitOptions) {
if (s.equals("")) continue;
if (s.isEmpty()) {
continue;
}
String[] sSplit = s.split(":", 2);
if (sSplit.length != 2) return line;
if (sSplit.length != 2) {
return line;
}
String option = sSplit[0].toLowerCase();
String value = sSplit[1].trim();
switch (option) {
case "chance":
//chance = Integer.parseInt(value);
chance = Double.parseDouble(value);
this.chance = Double.parseDouble(value);
break;
case "display-item":
displayItem = Material.valueOf(value);
this.displayItem = Material.valueOf(value);
break;
case "display-lore":
displayLore = value;
this.displayLore = value;
break;
case "display-name":
displayName = value;
this.displayName = value;
break;
}
}
@ -102,42 +111,51 @@ public class KitItem implements Cloneable {
private ItemStack compileOptions(ItemStack item) {
NBTItem nbtItem = new NBTItem(item);
if (chance != 0)
nbtItem.setDouble("chance", chance);
if (displayItem != null)
nbtItem.setString("display-item", displayItem.name());
if (displayName != null)
nbtItem.setString("display-name", displayName);
if (displayLore != null)
nbtItem.setString("display-lore", displayLore);
if (this.chance != 0) {
nbtItem.setDouble("chance", this.chance);
}
if (this.displayItem != null) {
nbtItem.setString("display-item", this.displayItem.name());
}
if (this.displayName != null) {
nbtItem.setString("display-name", this.displayName);
}
if (this.displayLore != null) {
nbtItem.setString("display-lore", this.displayLore);
}
return nbtItem.getItem();
}
private String compileOptionsText() {
String line = "";
if (chance != 0)
line += "chance:" + chance;
if (displayItem != null)
line += "~display-item:" + displayItem;
if (displayName != null)
line += "~display-name:" + displayName;
if (displayLore != null)
line += "~display-lore:" + displayLore;
if (this.chance != 0) {
line += "chance:" + this.chance;
}
if (this.displayItem != null) {
line += "~display-item:" + this.displayItem;
}
if (this.displayName != null) {
line += "~display-name:" + this.displayName;
}
if (this.displayLore != null) {
line += "~display-lore:" + this.displayLore;
}
return line.trim();
}
public KitContent getContent() {
return content;
return this.content;
}
public String getSerialized() {
if (chance == 0 && displayItem == null && displayName == null && displayLore == null)
if (this.chance == 0 && this.displayItem == null && this.displayName == null && this.displayLore == null) {
return this.content.getSerialized();
}
return compileOptionsText() + ";" + this.content.getSerialized();
}
public double getChance() {
return chance == 0 ? 100 : chance;
return this.chance == 0 ? 100 : this.chance;
}
public void setChance(double chance) {
@ -145,7 +163,7 @@ public class KitItem implements Cloneable {
}
public Material getDisplayItem() {
return displayItem;
return this.displayItem;
}
public void setDisplayItem(Material displayItem) {
@ -153,7 +171,7 @@ public class KitItem implements Cloneable {
}
public String getDisplayName() {
return displayName;
return this.displayName;
}
public void setDisplayName(String displayName) {
@ -161,7 +179,7 @@ public class KitItem implements Cloneable {
}
public String getDisplayLore() {
return displayLore;
return this.displayLore;
}
public void setDisplayLore(String displayLore) {
@ -169,48 +187,56 @@ public class KitItem implements Cloneable {
}
public ItemStack getItem() {
return content.getItemForDisplay();
return this.content.getItemForDisplay();
}
public ItemStack getMoveableItem() {
if (content == null) return null;
ItemStack item = content.getItemForDisplay().clone();
if (this.content == null) {
return null;
}
ItemStack item = this.content.getItemForDisplay().clone();
ItemMeta meta = item.getItemMeta();
List<String> lore = meta.hasLore() && meta.getLore().get(0).equals(TextUtils.formatText("&8&oMoveable"))
? new ArrayList<>() : new ArrayList<>(Collections.singletonList(TextUtils.formatText("&8&oMoveable")));
if (meta.hasLore())
if (meta.hasLore()) {
lore.addAll(meta.getLore());
}
meta.setLore(lore);
item.setItemMeta(meta);
return compileOptions(item);
}
public ItemStack getItemForDisplay() {
if (content == null) return null;
ItemStack item = content.getItemForDisplay();
if (this.content == null) {
return null;
}
ItemStack item = this.content.getItemForDisplay();
ItemMeta meta = item.getItemMeta();
if (displayItem != null) {
item.setType(displayItem);
if (this.displayItem != null) {
item.setType(this.displayItem);
meta = item.getItemMeta();
}
if (meta != null) {
if (displayName != null) {
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', displayName));
if (this.displayName != null) {
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', this.displayName));
}
if (displayLore != null) {
meta.setLore(Collections.singletonList(ChatColor.translateAlternateColorCodes('&', displayLore)));
if (this.displayLore != null) {
meta.setLore(Collections.singletonList(ChatColor.translateAlternateColorCodes('&', this.displayLore)));
}
if (UltimateKits.getInstance().getConfig().getBoolean("Main.Display Chance In Preview")) {
ArrayDeque<String> lore;
if (meta.hasLore())
if (meta.hasLore()) {
lore = new ArrayDeque<>(meta.getLore());
else
} else {
lore = new ArrayDeque<>();
}
if (!lore.isEmpty()) lore.addFirst("");
lore.addFirst(ChatColor.GRAY.toString() + UltimateKits.getInstance().getLocale().getMessage("general.type.chance").getMessage() + ": " + ChatColor.GOLD + (chance == 0 ? 100 : chance) + "%");
if (!lore.isEmpty()) {
lore.addFirst("");
}
lore.addFirst(ChatColor.GRAY + UltimateKits.getInstance().getLocale().getMessage("general.type.chance").getMessage() + ": " + ChatColor.GOLD + (this.chance == 0 ? 100 : this.chance) + "%");
meta.setLore(new ArrayList<>(lore));
}
@ -220,7 +246,7 @@ public class KitItem implements Cloneable {
}
public KitItemType getType() {
return type;
return this.type;
}
public KitItem clone() throws CloneNotSupportedException {
@ -230,12 +256,11 @@ public class KitItem implements Cloneable {
@Override
public String toString() {
return "KitItem:{"
+ "Item:\"" + content.getSerialized() + "\","
+ "Chance:" + chance + "\","
+ "Display Item:" + displayItem + "\","
+ "Display Name:" + displayName + "\","
+ "Display Lore:" + displayLore
+ "Item:\"" + this.content.getSerialized() + "\","
+ "Chance:" + this.chance + "\","
+ "Display Item:" + this.displayItem + "\","
+ "Display Name:" + this.displayName + "\","
+ "Display Lore:" + this.displayLore
+ "}";
}
}

View File

@ -1,7 +1,5 @@
package com.songoda.ultimatekits.kit;
package com.craftaro.ultimatekits.kit;
public enum KitItemType {
ITEM, ECONOMY, COMMAND
}

View File

@ -1,6 +1,6 @@
package com.songoda.ultimatekits.kit;
package com.craftaro.ultimatekits.kit;
import com.songoda.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.UltimateKits;
import org.bukkit.Location;
import java.util.ArrayList;
@ -11,75 +11,79 @@ import java.util.List;
import java.util.Map;
public final class KitManager {
private final Map<Location, KitBlockData> kitsAtLocations = new HashMap<>();
private final List<Kit> registeredKits = new LinkedList<>();
private boolean hasOrderChanged = false;
public Kit addKit(Kit kit) {
if (kit == null) return null;
registeredKits.add(kit);
if (kit == null) {
return null;
}
this.registeredKits.add(kit);
return kit;
}
public void removeKit(Kit kit) {
registeredKits.remove(kit);
this.registeredKits.remove(kit);
removeLocationsFromKit(kit);
}
public void removeLocationsFromKit(Kit kit) {
for (Map.Entry<Location, KitBlockData> entry : new ArrayList<>(kitsAtLocations.entrySet())) {
for (Map.Entry<Location, KitBlockData> entry : new ArrayList<>(this.kitsAtLocations.entrySet())) {
if (entry.getValue().getKit() == kit) {
entry.getValue().reset();
kitsAtLocations.remove(entry.getKey());
this.kitsAtLocations.remove(entry.getKey());
}
}
}
public KitBlockData addKitToLocation(Kit kit, Location location) {
KitBlockData data = new KitBlockData(kit, location);
kitsAtLocations.put(roundLocation(location), data);
this.kitsAtLocations.put(roundLocation(location), data);
return data;
}
public KitBlockData addKitToLocation(Kit kit, Location location, KitType type, boolean hologram, boolean particles, boolean items, boolean itemOverride) {
KitBlockData data = new KitBlockData(kit, location, type, hologram, particles, items, itemOverride);
kitsAtLocations.put(roundLocation(location), data);
this.kitsAtLocations.put(roundLocation(location), data);
return data;
}
public Kit removeKitFromLocation(Location location) {
KitBlockData kit = getKit(roundLocation(location));
if (kit == null) return null;
if (kit == null) {
return null;
}
kit.reset();
KitBlockData removed = kitsAtLocations.remove(roundLocation(location));
UltimateKits.getInstance().getDataManager().deleteBlockData(removed);
KitBlockData removed = this.kitsAtLocations.remove(roundLocation(location));
UltimateKits.getInstance().getKitDataManager().deleteBlockData(removed);
return (removed != null ? removed.getKit() : null);
}
public Kit getKit(String name) {
return registeredKits.stream().filter(kit -> kit.getKey().equalsIgnoreCase(name.trim()))
return this.registeredKits.stream().filter(kit -> kit.getKey().equalsIgnoreCase(name.trim()))
.findFirst().orElse(null);
}
public KitBlockData getKit(Location location) {
return kitsAtLocations.get(roundLocation(location));
return this.kitsAtLocations.get(roundLocation(location));
}
public List<Kit> getKits() {
return Collections.unmodifiableList(registeredKits);
return Collections.unmodifiableList(this.registeredKits);
}
public Map<Location, KitBlockData> getKitLocations() {
return Collections.unmodifiableMap(kitsAtLocations);
return Collections.unmodifiableMap(this.kitsAtLocations);
}
public void setKitLocations(Map<Location, KitBlockData> kits) {
kitsAtLocations.clear();
kitsAtLocations.putAll(kits);
this.kitsAtLocations.clear();
this.kitsAtLocations.putAll(kits);
}
public void clearKits() {
@ -96,28 +100,34 @@ public final class KitManager {
}
public void moveKit(Kit kit, boolean up) {
if (kit == null) return;
if (kit == null) {
return;
}
int i = 0;
for (Kit kit2 : registeredKits) {
if (kit == kit2)
for (Kit kit2 : this.registeredKits) {
if (kit == kit2) {
break;
}
i++;
}
int action = i - 1;
if (up) action = i + 1;
if (up) {
action = i + 1;
}
if (action >= 0 && action < registeredKits.size())
Collections.swap(registeredKits, i, action);
hasOrderChanged = true;
if (action >= 0 && action < this.registeredKits.size()) {
Collections.swap(this.registeredKits, i, action);
}
this.hasOrderChanged = true;
}
public boolean hasOrderChanged() {
return hasOrderChanged;
return this.hasOrderChanged;
}
public void savedOrderChange() {
hasOrderChanged = false;
this.hasOrderChanged = false;
}
}

View File

@ -0,0 +1,18 @@
package com.craftaro.ultimatekits.kit;
public enum KitType {
PREVIEW, CRATE, CLAIM;
public static KitType getKitType(String search) {
if (search == null) {
return null;
}
for (KitType t : values()) {
if (t.name().equalsIgnoreCase(search)) {
return t;
}
}
return null;
}
}

View File

@ -1,14 +1,12 @@
package com.songoda.ultimatekits.kit.type;
package com.craftaro.ultimatekits.kit.type;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public interface KitContent {
String getSerialized();
ItemStack getItemForDisplay();
ItemStack process(Player player);
}

View File

@ -1,6 +1,6 @@
package com.songoda.ultimatekits.kit.type;
package com.craftaro.ultimatekits.kit.type;
import com.songoda.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.UltimateKits;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
@ -11,7 +11,6 @@ import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
public class KitContentCommand implements KitContent {
private final String command; // Stored like "eco give <player> 100"
public KitContentCommand(String command) {
@ -19,12 +18,12 @@ public class KitContentCommand implements KitContent {
}
public String getCommand() {
return command;
return this.command;
}
@Override
public String getSerialized() {
return "/" + command;
return "/" + this.command;
}
@Override
@ -33,8 +32,8 @@ public class KitContentCommand implements KitContent {
ItemMeta meta = stack.getItemMeta();
ArrayList<String> lore = new ArrayList<>();
int index = 0;
while (index < command.length()) {
lore.add(ChatColor.GREEN + (index == 0 ? "/" : "") + ChatColor.GREEN + command.substring(index, Math.min(index + 30, command.length())));
while (index < this.command.length()) {
lore.add(ChatColor.GREEN + (index == 0 ? "/" : "") + ChatColor.GREEN + this.command.substring(index, Math.min(index + 30, this.command.length())));
index += 30;
}
meta.setLore(lore);
@ -45,7 +44,7 @@ public class KitContentCommand implements KitContent {
@Override
public ItemStack process(Player player) {
String parsed = command;
String parsed = this.command;
parsed = parsed.replace("{player}", player.getName());
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), parsed);
return null;

View File

@ -1,8 +1,8 @@
package com.songoda.ultimatekits.kit.type;
package com.craftaro.ultimatekits.kit.type;
import com.songoda.core.hooks.EconomyManager;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.utils.Methods;
import com.craftaro.core.hooks.EconomyManager;
import com.craftaro.core.utils.NumberUtils;
import com.craftaro.ultimatekits.UltimateKits;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@ -12,7 +12,6 @@ import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
public class KitContentEconomy implements KitContent {
private final double amount;
public KitContentEconomy(double amount) {
@ -20,12 +19,12 @@ public class KitContentEconomy implements KitContent {
}
public double getAmount() {
return amount;
return this.amount;
}
@Override
public String getSerialized() {
return UltimateKits.getInstance().getConfig().getString("Main.Currency Symbol") + amount;
return UltimateKits.getInstance().getConfig().getString("Main.Currency Symbol") + this.amount;
}
@Override
@ -36,8 +35,8 @@ public class KitContentEconomy implements KitContent {
ArrayList<String> lore = new ArrayList<>();
int index = 0;
while (index < String.valueOf(amount).length()) {
lore.add(ChatColor.GREEN + (index == 0 ? UltimateKits.getInstance().getConfig().getString("Main.Currency Symbol") : "") + ChatColor.GREEN + String.valueOf(amount).substring(index, Math.min(index + 30, String.valueOf(amount).length())));
while (index < String.valueOf(this.amount).length()) {
lore.add(ChatColor.GREEN + (index == 0 ? UltimateKits.getInstance().getConfig().getString("Main.Currency Symbol") : "") + ChatColor.GREEN + String.valueOf(this.amount).substring(index, Math.min(index + 30, String.valueOf(this.amount).length())));
index += 30;
}
meta.setLore(lore);
@ -49,9 +48,9 @@ public class KitContentEconomy implements KitContent {
@Override
public ItemStack process(Player player) {
try {
EconomyManager.deposit(player, amount);
EconomyManager.deposit(player, this.amount);
UltimateKits.getInstance().getLocale().getMessage("event.claim.eco")
.processPlaceholder("amt", Methods.formatEconomy(amount))
.processPlaceholder("amt", NumberUtils.formatNumber(this.amount))
.sendPrefixedMessage(player);
} catch (NumberFormatException ex) {
ex.printStackTrace();

View File

@ -1,7 +1,6 @@
package com.songoda.ultimatekits.kit.type;
package com.craftaro.ultimatekits.kit.type;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.utils.ItemSerializer;
import com.craftaro.ultimatekits.utils.ItemSerializer;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@ -10,7 +9,6 @@ import java.util.ArrayList;
import java.util.List;
public class KitContentItem implements KitContent {
private final ItemStack itemStack;
private String serialized = null;
@ -20,24 +18,27 @@ public class KitContentItem implements KitContent {
}
public ItemStack getItemStack() {
return itemStack;
return this.itemStack;
}
@Override
public String getSerialized() {
if (serialized != null) return serialized;
serialized = ItemSerializer.serializeItemStackToJson(itemStack);
return serialized;
if (this.serialized != null) {
return this.serialized;
}
this.serialized = ItemSerializer.serializeItemStackToJson(this.itemStack);
return this.serialized;
}
@Override
public ItemStack getItemForDisplay() {
return itemStack.clone();
return this.itemStack.clone();
}
@Override
public ItemStack process(Player player) {
ItemStack parseStack = itemStack;
ItemStack parseStack = this.itemStack;
if (parseStack.hasItemMeta() && parseStack.getItemMeta().hasLore()) {
ItemMeta meta = parseStack.getItemMeta();

View File

@ -1,9 +1,9 @@
package com.songoda.ultimatekits.listeners;
package com.craftaro.ultimatekits.listeners;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.key.Key;
import com.songoda.ultimatekits.kit.Kit;
import com.songoda.ultimatekits.kit.KitBlockData;
import com.craftaro.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.key.Key;
import com.craftaro.ultimatekits.kit.Kit;
import com.craftaro.ultimatekits.kit.KitBlockData;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
@ -14,11 +14,7 @@ import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.ItemStack;
/**
* Created by songoda on 2/24/2017.
*/
public class BlockListeners implements Listener {
private final UltimateKits plugin;
public BlockListeners(UltimateKits plugin) {
@ -28,30 +24,33 @@ public class BlockListeners implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
Block block = event.getBlock();
KitBlockData kitBlockData = plugin.getKitManager().getKit(block.getLocation());
if (kitBlockData == null) return;
KitBlockData kitBlockData = this.plugin.getKitManager().getKit(block.getLocation());
if (kitBlockData == null) {
return;
}
Kit kit = kitBlockData.getKit();
plugin.removeHologram(kitBlockData);
this.plugin.removeHologram(kitBlockData);
plugin.getKitManager().removeKitFromLocation(block.getLocation());
this.plugin.getKitManager().removeKitFromLocation(block.getLocation());
plugin.getLocale().newMessage("&8Kit &9" + kit.getKey() + " &8unassigned from: &a" + block.getType() + "&8.")
this.plugin.getLocale().newMessage("&8Kit &9" + kit.getKey() + " &8unassigned from: &a" + block.getType() + "&8.")
.sendPrefixedMessage(event.getPlayer());
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent e) {
Block block = e.getBlockAgainst();
KitBlockData kitBlockData = plugin.getKitManager().getKit(block.getLocation());
KitBlockData kitBlockData = this.plugin.getKitManager().getKit(block.getLocation());
if (kitBlockData != null) {
e.setCancelled(true);
}
ItemStack item = e.getItemInHand();
if (item.getType() == Material.TRIPWIRE_HOOK && item.hasItemMeta() && item.getItemMeta().hasDisplayName()) {
Key key = plugin.getKeyManager().getKey(ChatColor.stripColor(item.getItemMeta().getLore().get(0)).replace(" Key", ""));
if (key != null)
Key key = this.plugin.getKeyManager().getKey(ChatColor.stripColor(item.getItemMeta().getLore().get(0)).replace(" Key", ""));
if (key != null) {
e.setCancelled(true);
}
}
}
}

View File

@ -1,18 +1,14 @@
package com.songoda.ultimatekits.listeners;
package com.craftaro.ultimatekits.listeners;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
/**
* Created by songoda on 2/24/2017.
*/
public class ChatListeners implements Listener {
@EventHandler
public void onCommandPreprocess(AsyncPlayerChatEvent event) {
if (event.getMessage().equalsIgnoreCase("/kit") || event.getMessage().equalsIgnoreCase("/kit")) {
event.setCancelled(true);
}
}
}
}

View File

@ -1,16 +1,12 @@
package com.songoda.ultimatekits.listeners;
package com.craftaro.ultimatekits.listeners;
import com.songoda.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.UltimateKits;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.world.ChunkLoadEvent;
/**
* Created by songoda on 2/24/2017.
*/
public class ChunkListeners implements Listener {
private final UltimateKits plugin;
public ChunkListeners(UltimateKits plugin) {
@ -19,10 +15,10 @@ public class ChunkListeners implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onChunkLoad(ChunkLoadEvent event) {
plugin.getKitManager().getKitLocations().values().stream()
this.plugin.getKitManager().getKitLocations().values().stream()
.filter(l -> l.getLocation().getWorld() == event.getWorld()
&& l.getLocation().getBlockX() >> 4 == event.getChunk().getX()
&& l.getLocation().getBlockZ() >> 4 == event.getChunk().getZ())
.forEach(plugin::updateHologram);
.forEach(this.plugin::updateHologram);
}
}

View File

@ -1,6 +1,6 @@
package com.songoda.ultimatekits.listeners;
package com.craftaro.ultimatekits.listeners;
import com.songoda.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.UltimateKits;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
@ -12,7 +12,6 @@ import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
public class EntityListeners implements Listener {
private final UltimateKits plugin;
public EntityListeners(UltimateKits plugin) {
@ -21,12 +20,12 @@ public class EntityListeners implements Listener {
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerEntityInteract(EntityDamageEvent event) {
if (event.getEntity().getType() != EntityType.ARMOR_STAND || plugin.getConfig().getString("data.hologramHandler") == null) {
if (event.getEntity().getType() != EntityType.ARMOR_STAND || this.plugin.getConfig().getString("data.hologramHandler") == null) {
return;
}
ConfigurationSection section = plugin.getConfig().getConfigurationSection("data.hologramHandler");
ConfigurationSection section = this.plugin.getConfig().getConfigurationSection("data.hologramHandler");
for (String loc : section.getKeys(false)) {
String str[] = loc.split(":");
String[] str = loc.split(":");
World world = Bukkit.getServer().getWorld(str[1].substring(0, str[1].length() - 1));
double x = Double.parseDouble(str[2].substring(0, str[2].length() - 1)) + .5;
double z = Double.parseDouble(str[4]) + .5;
@ -38,12 +37,13 @@ public class EntityListeners implements Listener {
@EventHandler
public void onPlayerEntityInteract(PlayerInteractAtEntityEvent event) {
if (event.getRightClicked().getType() != EntityType.ARMOR_STAND || plugin.getConfig().getString("data.hologramHandler") == null) {
if (event.getRightClicked().getType() != EntityType.ARMOR_STAND || this.plugin.getConfig().getString("data.hologramHandler") == null) {
return;
}
ConfigurationSection section = plugin.getConfig().getConfigurationSection("data.hologramHandler");
ConfigurationSection section = this.plugin.getConfig().getConfigurationSection("data.hologramHandler");
for (String loc : section.getKeys(false)) {
String str[] = loc.split(":");
String[] str = loc.split(":");
World w = Bukkit.getServer().getWorld(str[1].substring(0, str[1].length() - 1));
double x = Double.parseDouble(str[2].substring(0, str[2].length() - 1)) + .5;
double z = Double.parseDouble(str[4]) + .5;

View File

@ -1,15 +1,16 @@
package com.songoda.ultimatekits.listeners;
package com.craftaro.ultimatekits.listeners;
import com.songoda.core.compatibility.CompatibleHand;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.core.gui.GuiManager;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.gui.BlockEditorGui;
import com.songoda.ultimatekits.kit.Kit;
import com.songoda.ultimatekits.kit.KitBlockData;
import com.songoda.ultimatekits.kit.KitType;
import com.songoda.ultimatekits.utils.Methods;
import com.craftaro.core.compatibility.CompatibleHand;
import com.craftaro.core.compatibility.ServerVersion;
import com.craftaro.core.gui.GuiManager;
import com.craftaro.core.utils.TimeUtils;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.gui.BlockEditorGui;
import com.craftaro.ultimatekits.kit.Kit;
import com.craftaro.ultimatekits.kit.KitBlockData;
import com.craftaro.ultimatekits.kit.KitType;
import com.craftaro.ultimatekits.settings.Settings;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
@ -19,12 +20,9 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import com.songoda.ultimatekits.settings.Settings;
public class InteractListeners implements Listener {
private final UltimateKits plugin;
private final GuiManager guiManager;
@ -35,16 +33,21 @@ public class InteractListeners implements Listener {
@EventHandler
public void onBlockInteract(PlayerInteractEvent event) {
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9))
if (event.getHand() == EquipmentSlot.OFF_HAND) return;
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9)) {
if (event.getHand() == EquipmentSlot.OFF_HAND) {
return;
}
}
Block block = event.getClickedBlock();
if (block == null) {
return;
}
if (event.getClickedBlock() == null) return;
KitBlockData kitBlockData = plugin.getKitManager().getKit(block.getLocation());
if (kitBlockData == null) return;
KitBlockData kitBlockData = this.plugin.getKitManager().getKit(block.getLocation());
if (kitBlockData == null) {
return;
}
Kit kit = kitBlockData.getKit();
@ -52,10 +55,8 @@ public class InteractListeners implements Listener {
Material itemInHand = player.getItemInHand().getType();
Material keyMaterial = Settings.KEY_MATERIAL.getMaterial().getItem().getType();
Material keyMaterial = Settings.KEY_MATERIAL.getMaterial().parseMaterial();
if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
if (player.isSneaking()) {
return;
}
@ -63,32 +64,29 @@ public class InteractListeners implements Listener {
event.setCancelled(true);
if (kitBlockData.getType() == KitType.PREVIEW) {
kit.display(player, guiManager, null);
} else if(kitBlockData.getType() == KitType.CRATE) {
kit.display(player, this.guiManager, null);
} else if (kitBlockData.getType() == KitType.CRATE) {
if (itemInHand == keyMaterial) {
kit.processKeyUse(player);
} else {
plugin.getLocale().getMessage("event.crate.needkey").sendPrefixedMessage(player);
this.plugin.getLocale().getMessage("event.crate.needkey").sendPrefixedMessage(player);
return;
}
} else if (kitBlockData.getType() == KitType.CLAIM) {
if (!kit.hasPermissionToClaim(player)) {
plugin.getLocale().getMessage("command.general.noperms").sendPrefixedMessage(player);
this.plugin.getLocale().getMessage("command.general.noperms").sendPrefixedMessage(player);
return;
}
if (kit.getNextUse(player) > 0) {
long time = kit.getNextUse(player);
plugin.getLocale().getMessage("event.crate.notyet").processPlaceholder("time", Methods.makeReadable(time)).sendPrefixedMessage(player);
this.plugin.getLocale().getMessage("event.crate.notyet").processPlaceholder("time", TimeUtils.makeReadable(time)).sendPrefixedMessage(player);
return;
}
if (kit.getLink() != null || kit.getPrice() != 0) {
kit.buy(player, guiManager);
kit.buy(player, this.guiManager);
} else {
kit.processGenericUse(player, false);
}
@ -98,15 +96,14 @@ public class InteractListeners implements Listener {
}
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
event.setCancelled(true);
if (player.isSneaking() && player.hasPermission("ultimatekits.admin")) {
guiManager.showGUI(player, new BlockEditorGui(plugin, kitBlockData));
this.guiManager.showGUI(player, new BlockEditorGui(this.plugin, kitBlockData));
return;
}
kit.display(player, guiManager, null);
kit.display(player, this.guiManager, null);
}
}
@ -118,18 +115,23 @@ public class InteractListeners implements Listener {
// Filter physical actions (pressure plates, buttons)
if (event.getAction() == Action.PHYSICAL
|| event.getItem() == null
|| event.getItem().getType() == CompatibleMaterial.AIR.getMaterial()
|| CompatibleMaterial.getMaterial(event.getItem()) != CompatibleMaterial.CHEST)
|| XMaterial.AIR.isSimilar(event.getItem())
|| !XMaterial.CHEST.isSimilar(event.getItem())) {
return;
}
ItemStack item = event.getItem();
Player player = event.getPlayer();
if (!item.hasItemMeta() || !item.getItemMeta().hasLore() || item.getItemMeta().getLore().size() == 0) return;
if (!item.hasItemMeta() || !item.getItemMeta().hasLore() || item.getItemMeta().getLore().isEmpty()) {
return;
}
Kit kit = UltimateKits.getInstance().getKitManager().getKit(ChatColor.stripColor(item.getItemMeta().getLore().get(0).split(" ")[0]));
Kit kit = this.plugin.getKitManager().getKit(ChatColor.stripColor(item.getItemMeta().getLore().get(0).split(" ")[0]));
if (kit == null) return;
if (kit == null) {
return;
}
event.setCancelled(true);
@ -138,6 +140,8 @@ public class InteractListeners implements Listener {
// Open the crate
kit.processCrateUse(player, item, CompatibleHand.getHand(event));
} else // There are only left click actions left
kit.display(player, guiManager, null);
{
kit.display(player, this.guiManager, null);
}
}
}
}

View File

@ -0,0 +1,32 @@
package com.craftaro.ultimatekits.listeners;
import com.craftaro.ultimatekits.UltimateKits;
import com.craftaro.ultimatekits.settings.Settings;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
public class PlayerListeners implements Listener {
private final UltimateKits plugin;
public PlayerListeners(UltimateKits plugin) {
this.plugin = plugin;
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
if (player.hasPlayedBefore()) {
return;
}
if (this.plugin.getKitManager().getKit(Settings.STARTER_KIT.getString()) == null
|| Settings.STARTER_KIT.getString() == null
|| Settings.STARTER_KIT.getString().equalsIgnoreCase("none")) {
return;
}
this.plugin.getKitManager().getKit(Settings.STARTER_KIT.getString()).giveKit(player);
}
}

View File

@ -1,16 +1,15 @@
package com.songoda.ultimatekits.settings;
package com.craftaro.ultimatekits.settings;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.configuration.Config;
import com.songoda.core.configuration.ConfigSetting;
import com.songoda.core.hooks.EconomyManager;
import com.songoda.ultimatekits.UltimateKits;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.configuration.Config;
import com.craftaro.core.configuration.ConfigSetting;
import com.craftaro.core.hooks.EconomyManager;
import com.craftaro.ultimatekits.UltimateKits;
import java.util.Arrays;
import java.util.stream.Collectors;
public class Settings {
static final Config config = UltimateKits.getInstance().getCoreConfig();
public static final ConfigSetting DONT_PREVIEW_COMMANDS = new ConfigSetting(config, "Main.Dont Preview Commands In Kits", false);
@ -74,13 +73,13 @@ public class Settings {
// convert glass pane settings
int color;
if ((color = GLASS_TYPE_1.getInt(-1)) != -1) {
config.set(GLASS_TYPE_1.getKey(), CompatibleMaterial.getGlassPaneColor(color).name());
config.set(GLASS_TYPE_1.getKey(), CompatibleMaterial.getGlassPaneForColor(color).name());
}
if ((color = GLASS_TYPE_2.getInt(-1)) != -1) {
config.set(GLASS_TYPE_2.getKey(), CompatibleMaterial.getGlassPaneColor(color).name());
config.set(GLASS_TYPE_2.getKey(), CompatibleMaterial.getGlassPaneForColor(color).name());
}
if ((color = GLASS_TYPE_3.getInt(-1)) != -1) {
config.set(GLASS_TYPE_3.getKey(), CompatibleMaterial.getGlassPaneColor(color).name());
config.set(GLASS_TYPE_3.getKey(), CompatibleMaterial.getGlassPaneForColor(color).name());
}
// convert economy settings

View File

@ -1,11 +1,10 @@
package com.songoda.ultimatekits.utils;
package com.craftaro.ultimatekits.utils;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public enum ArmorType {
LEATHER_BOOTS("Boots"),
LEATHER_CHESTPLATE("Chestplate"),
LEATHER_HELMET("Helmet"),
@ -41,7 +40,7 @@ public enum ArmorType {
ELYTRA("Chestplate"),
SHIELD("OffHand");
String slot;
final String slot;
ArmorType(String slot) {
this.slot = slot;
@ -49,51 +48,51 @@ public enum ArmorType {
}
public boolean isHelmet() {
return slot.equalsIgnoreCase("Helmet");
return this.slot.equalsIgnoreCase("Helmet");
}
public boolean isChestplate() {
return slot.equalsIgnoreCase("Chestplate");
return this.slot.equalsIgnoreCase("Chestplate");
}
public boolean isLeggings() {
return slot.equalsIgnoreCase("Leggings");
return this.slot.equalsIgnoreCase("Leggings");
}
public boolean isBoots() {
return slot.equalsIgnoreCase("Boots");
return this.slot.equalsIgnoreCase("Boots");
}
public boolean isOffHand() {
return slot.equalsIgnoreCase("OffHand");
return this.slot.equalsIgnoreCase("OffHand");
}
public static boolean equip(Player player, ItemStack item) {
try {
ArmorType type = ArmorType.valueOf(item.getType().toString());
boolean equipped = false;
if ((type.isHelmet() && player.getInventory().getHelmet() == null)
boolean equipped = (type.isHelmet() && player.getInventory().getHelmet() == null)
|| (type.isChestplate() && player.getInventory().getChestplate() == null)
|| (type.isLeggings() && player.getInventory().getLeggings() == null)
|| (type.isBoots() && player.getInventory().getBoots() == null)
|| (type.isOffHand() && player.getInventory().getItemInOffHand().getType() == Material.AIR))
equipped = true;
|| (type.isOffHand() && player.getInventory().getItemInOffHand().getType() == Material.AIR);
if (type.isHelmet() && player.getInventory().getHelmet() == null)
if (type.isHelmet() && player.getInventory().getHelmet() == null) {
player.getInventory().setHelmet(item);
if (type.isChestplate() && player.getInventory().getChestplate() == null)
}
if (type.isChestplate() && player.getInventory().getChestplate() == null) {
player.getInventory().setChestplate(item);
if (type.isLeggings() && player.getInventory().getLeggings() == null)
}
if (type.isLeggings() && player.getInventory().getLeggings() == null) {
player.getInventory().setLeggings(item);
if (type.isBoots() && player.getInventory().getBoots() == null)
}
if (type.isBoots() && player.getInventory().getBoots() == null) {
player.getInventory().setBoots(item);
if (type.isOffHand() && player.getInventory().getItemInOffHand().getType() == Material.AIR)
}
if (type.isOffHand() && player.getInventory().getItemInOffHand().getType() == Material.AIR) {
player.getInventory().setItemInOffHand(item);
}
return equipped;
} catch (IllegalArgumentException e) {
return false;
}

View File

@ -1,8 +1,8 @@
package com.songoda.ultimatekits.utils;
package com.craftaro.ultimatekits.utils;
import com.songoda.core.compatibility.ClassMapping;
import com.songoda.core.compatibility.MethodMapping;
import com.songoda.core.compatibility.ServerVersion;
import com.craftaro.core.compatibility.ClassMapping;
import com.craftaro.core.compatibility.MethodMapping;
import com.craftaro.core.compatibility.ServerVersion;
import org.bukkit.inventory.ItemStack;
import java.lang.reflect.Constructor;
@ -51,7 +51,6 @@ public class ItemSerializer {
* Deserializes a JSON String
*
* @param jsonString the JSON String to parse
*
* @return the deserialized ItemStack
*/
public static ItemStack deserializeItemStackFromJson(String jsonString) {
@ -79,7 +78,6 @@ public class ItemSerializer {
* Serializes an item stack
*
* @param itemStack the ItemStack to parse
*
* @return condensed JSON String
*/
public static String serializeItemStackToJson(ItemStack itemStack) {

View File

@ -0,0 +1,74 @@
package com.craftaro.ultimatekits.utils;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.gui.Gui;
import com.craftaro.core.gui.GuiUtils;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.ultimatekits.settings.Settings;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.inventory.ItemStack;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
public class Methods {
private static final Random rand = new Random();
private static final Map<String, Location> serializeCache = new HashMap<>();
/**
* Deserializes a location from the string.
*
* @param str The string to parse.
* @return The location that was serialized in the string.
*/
public static Location unserializeLocation(String str) {
if (str == null || str.isEmpty()) {
return null;
}
if (serializeCache.containsKey(str)) {
return serializeCache.get(str).clone();
}
String cacheKey = str;
str = str.replace("y:", ":").replace("z:", ":").replace("w:", "").replace("x:", ":").replace("/", ".");
List<String> args = Arrays.asList(str.split("\\s*:\\s*"));
World world = Bukkit.getWorld(args.get(0));
double x = Double.parseDouble(args.get(1));
double y = Double.parseDouble(args.get(2));
double z = Double.parseDouble(args.get(3));
Location location = new Location(world, x, y, z, 0, 0);
serializeCache.put(cacheKey, location.clone());
return location;
}
public static void fillGlass(Gui gui) {
// fill center with glass
if (Settings.RAINBOW.getBoolean()) {
for (int row = 0; row < gui.getRows(); ++row) {
for (int col = row == 1 ? 2 : 3; col < (row == 1 ? 7 : 6); ++col) {
gui.setItem(row, col, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneForColor(rand.nextInt(16))));
}
}
} else {
gui.setDefaultItem(GuiUtils.getBorderItem(Settings.GLASS_TYPE_1.getMaterial(XMaterial.GRAY_STAINED_GLASS_PANE)));
}
// decorate the edges
ItemStack glass2 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_2.getMaterial(XMaterial.BLUE_STAINED_GLASS_PANE));
ItemStack glass3 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_3.getMaterial(XMaterial.LIGHT_BLUE_STAINED_GLASS_PANE));
// edges will be type 3
gui.mirrorFill(0, 2, true, true, glass3);
gui.mirrorFill(1, 1, false, true, glass3);
// decorate corners with type 2
gui.mirrorFill(0, 0, true, true, glass2);
gui.mirrorFill(1, 0, true, true, glass2);
gui.mirrorFill(0, 1, true, true, glass2);
}
}

View File

@ -1,14 +0,0 @@
package com.songoda.ultimatekits.conversion;
import org.bukkit.inventory.ItemStack;
import java.util.Set;
public interface Hook {
Set<String> getKits();
Set<ItemStack> getItems(String kit);
long getDelay(String kit);
}

View File

@ -1,474 +0,0 @@
package com.songoda.ultimatekits.gui;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.compatibility.CompatibleSound;
import com.songoda.core.gui.AnvilGui;
import com.songoda.core.gui.DoubleGui;
import com.songoda.core.gui.Gui;
import com.songoda.core.gui.GuiUtils;
import com.songoda.core.input.ChatPrompt;
import com.songoda.core.utils.ItemUtils;
import com.songoda.core.utils.TextUtils;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.kit.Kit;
import com.songoda.ultimatekits.kit.KitAnimation;
import com.songoda.ultimatekits.kit.KitItem;
import com.songoda.ultimatekits.settings.Settings;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class KitEditorGui extends DoubleGui {
private final UltimateKits plugin;
private final Kit kit;
private final Player player;
private final Gui back;
private boolean isInFunction = false;
private boolean isInInventory = false;
private ItemStack[] stash;
public KitEditorGui(UltimateKits plugin, Player player, Kit kit, Gui back) {
super(6);
this.plugin = plugin;
this.kit = kit;
this.player = player;
this.back = back;
setDefaultItem(null);
setTitle(plugin.getLocale().getMessage("interface.kiteditor.title")
.processPlaceholder("name", kit.getName())
.getMessage());
setOnClose((event) -> {
restoreItemsInstance();
saveKit(player, inventory, false);
CompatibleSound.ENTITY_VILLAGER_YES.play(player);
});
ItemStack glass1 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_1.getMaterial());
ItemStack glass2 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_2.getMaterial());
ItemStack glass3 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_3.getMaterial());
mirrorFill(0, 0, true, true, glass2);
mirrorFill(0, 1, true, true, glass2);
mirrorFill(1, 0, true, true, glass2);
mirrorFill(0, 2, true, true, glass3);
mirrorFill(0, 3, false, true, glass1);
// exit button
setButton(0, 8, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(CompatibleMaterial.OAK_DOOR),
plugin.getLocale().getMessage("interface.button.exit").getMessage()),
ClickType.LEFT,
event -> player.closeInventory());
// back button
if (parent != null)
setButton(0, 0, GuiUtils.createButtonItem(ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"),
plugin.getLocale().getMessage("interface.button.back").getMessage()),
ClickType.LEFT,
event -> {
player.closeInventory();
guiManager.showGUI(player, back);
});
// info icon
setItem(0, 4, GuiUtils.createButtonItem(CompatibleMaterial.CHEST,
plugin.getLocale().getMessage("interface.kiteditor.info")
.processPlaceholder("kit", kit.getKey())
.processPlaceholder("perm", "ultimatekits.claim." + kit.getKey().toLowerCase())
.getMessage().split("\\|"))
);
saveItemsInstance();
paint();
Bukkit.getScheduler().runTaskLater(plugin, this::setInvItems, 3L);
}
private void paint() {
for (int i = 10; i < 44; i++) {
if (i == 17 || i == 36)
continue;
setItem(i, null);
}
int num = 10;
for (ItemStack itemStack : kit.getReadableContents(player, false, true, true)) {
if (num == 17 || num == 36)
num++;
KitItem item = new KitItem(itemStack);
ItemStack is = getCompiledMeta(item);
if (!isInFunction)
setButton(num, is, null);
else {
setButton(num, is,
(event) -> {
switch (event.clickType) {
case SHIFT_LEFT:
replaceItem(Action.CHANCE_UP, player, event.clickedItem, event.slot);
break;
case SHIFT_RIGHT:
replaceItem(Action.CHANCE_DOWN, player, event.clickedItem, event.slot);
break;
case LEFT:
replaceItem(Action.DISPLAY_ITEM, player, event.clickedItem, event.slot);
break;
case MIDDLE:
replaceItem(Action.DISPLAY_NAME, player, event.clickedItem, event.slot);
break;
case RIGHT:
replaceItem(Action.DISPLAY_LORE, player, event.clickedItem, event.slot);
break;
}
});
}
num++;
}
updateInvButton();
}
private void updateInvButton() {
ItemStack item;
if (!isInFunction) {
setUnlockedRange(1, 1, 1, 7);
setUnlockedRange(2, 0, 3, 8);
setUnlockedRange(4, 1, 4, 7);
item = GuiUtils.createButtonItem(CompatibleMaterial.PAPER,
plugin.getLocale().getMessage("interface.kiteditor.itemediting").getMessage(),
plugin.getLocale().getMessage("interface.kiteditor.itemeditinglore").getMessage().split("\\|"));
} else {
unlockedCells.clear();
item = GuiUtils.createButtonItem(CompatibleMaterial.PAPER,
plugin.getLocale().getMessage("interface.kiteditor.itemmoving").getMessage(),
plugin.getLocale().getMessage("interface.kiteditor.itemmovinglore").getMessage().split("\\|"));
}
setButton(48, item,
(event) -> {
isInFunction = !isInFunction;
saveKit(player, inventory, true);
paint();
});
ItemStack item2;
item2 = isInInventory ? GuiUtils.createButtonItem(CompatibleMaterial.ITEM_FRAME,
plugin.getLocale().getMessage("interface.kiteditor.switchtokitfunctions").getMessage(),
plugin.getLocale().getMessage("interface.kiteditor.switchtokitfunctionslore").getMessage().split("\\|"))
: GuiUtils.createButtonItem(CompatibleMaterial.ITEM_FRAME,
plugin.getLocale().getMessage("interface.kiteditor.switchtoinventory").getMessage(),
plugin.getLocale().getMessage("interface.kiteditor.switchtoinventorylore").getMessage().split("\\|"));
setButton(50, item2,
event -> {
if (!isInInventory) {
restoreItemsInstance();
setPlayerActionForRange(0, 0, 3, 8, null);
setAcceptsItems(true);
} else {
saveItemsInstance();
setInvItems();
setAcceptsItems(false);
}
updateInvButton();
});
}
private void saveItemsInstance() {
setPlayerUnlockedRange(0, 0, 3, 8, false);
stash = player.getInventory().getContents().clone();
player.getInventory().clear();
isInInventory = false;
}
private void restoreItemsInstance() {
if (!isInInventory)
player.getInventory().clear();
setPlayerUnlockedRange(0, 0, 3, 8);
if (stash != null)
player.getInventory().setContents(stash);
player.updateInventory();
isInInventory = true;
}
private void setInvItems() {
setPlayerButton(0, GuiUtils.createButtonItem(CompatibleMaterial.REDSTONE_TORCH,
plugin.getLocale().getMessage("interface.kiteditor.generaloptions").getMessage(),
plugin.getLocale().getMessage("interface.kiteditor.generaloptionslore").getMessage().split("\\|")),
(event) -> {
player.closeInventory();
guiManager.showGUI(player, new KitGeneralOptionsGui(plugin, player, kit, back));
});
setPlayerButton(1, GuiUtils.createButtonItem(CompatibleMaterial.EMERALD,
plugin.getLocale().getMessage("interface.kiteditor.sellingoptions").getMessage(),
plugin.getLocale().getMessage("interface.kiteditor.sellingoptionslore").getMessage().split("\\|")),
(event) -> {
player.closeInventory();
guiManager.showGUI(player, new KitSellingOptionsGui(plugin, player, kit, back));
});
setPlayerButton(3, GuiUtils.createButtonItem(CompatibleMaterial.ITEM_FRAME,
plugin.getLocale().getMessage("interface.kiteditor.guioptions").getMessage(),
plugin.getLocale().getMessage("interface.kiteditor.guioptionslore").getMessage().split("\\|")),
(event) -> {
player.closeInventory();
guiManager.showGUI(player, new KitGuiOptionsGui(plugin, player, kit, back));
});
setPlayerButton(4, GuiUtils.createButtonItem(CompatibleMaterial.PAPER,
plugin.getLocale().getMessage("interface.kiteditor.addcommand").getMessage(),
plugin.getLocale().getMessage("interface.kiteditor.addcommandlore").getMessage().split("\\|")),
(event) -> {
event.gui.exit();
ChatPrompt.showPrompt(event.manager.getPlugin(), event.player, "Enter a command for this kit:", response -> {
String msg = response.getMessage().trim();
ItemStack parseStack = new ItemStack(Material.PAPER, 1);
ItemMeta meta = parseStack.getItemMeta();
ArrayList<String> lore = new ArrayList<>();
int index = 0;
while (index < msg.length()) {
lore.add(ChatColor.GREEN + (index == 0 ? "/" : "") + msg.substring(index, Math.min(index + 30, msg.length())));
index += 30;
}
meta.setLore(lore);
meta.setDisplayName(plugin.getLocale().getMessage("general.type.command").getMessage());
parseStack.setItemMeta(meta);
plugin.getLocale().newMessage(plugin.getLocale().getMessage("interface.kiteditor.addcommandok")
.processPlaceholder("command", msg).getMessage())
.sendPrefixedMessage(player);
inventory.addItem(parseStack);
Bukkit.getScheduler().runTask(plugin, event.player::closeInventory);
}).setOnClose(() -> {
event.manager.showGUI(event.player, this);
})
.setOnCancel(() -> {
event.player.sendMessage(ChatColor.RED + "Edit canceled");
event.manager.showGUI(event.player, this);
});
});
setPlayerButton(5, GuiUtils.createButtonItem(CompatibleMaterial.SUNFLOWER,
plugin.getLocale().getMessage("interface.kiteditor.addeconomy").getMessage(),
plugin.getLocale().getMessage("interface.kiteditor.addeconomylore").getMessage().split("\\|")),
(event) -> {
AnvilGui gui = new AnvilGui(player, this);
gui.setTitle(plugin.getLocale().getMessage("interface.kiteditor.addeconomyprompt").getMessage());
gui.setAction(aevent -> {
String msg = gui.getInputText().trim();
ItemStack parseStack = new ItemStack(Material.PAPER, 1);
ItemMeta meta = parseStack.getItemMeta();
ArrayList<String> lore = new ArrayList<>();
int index = 0;
while (index < msg.length()) {
lore.add(ChatColor.GREEN + "$" + msg.substring(index, Math.min(index + 30, msg.length())));
index += 30;
}
meta.setLore(lore);
meta.setDisplayName(plugin.getLocale().getMessage("general.type.money").getMessage());
parseStack.setItemMeta(meta);
plugin.getLocale().getMessage("interface.kiteditor.addeconomyok").processPlaceholder("amount", msg.trim())
.sendPrefixedMessage(player);
this.inventory.addItem(parseStack);
player.closeInventory();
});
guiManager.showGUI(event.player, gui);
});
setPlayerButton(7, GuiUtils.createButtonItem(CompatibleMaterial.SHEEP_SPAWN_EGG,
plugin.getLocale().getMessage("interface.kiteditor.clone").getMessage(),
plugin.getLocale().getMessage("interface.kiteditor.clonelore")
.getMessage().split("\\|")),
(event) -> {
AnvilGui gui = new AnvilGui(player, this);
gui.setTitle("Enter a new kit name");
gui.setAction(evnt -> {
String kitStr = gui.getInputText().toLowerCase().trim();
if (plugin.getKitManager().getKit(kitStr) != null) {
plugin.getLocale().getMessage("command.kit.kitalreadyexists").sendPrefixedMessage(player);
player.closeInventory();
} else {
Kit newKit = kit.clone(kitStr);
plugin.getKitManager().addKit(newKit);
player.closeInventory();
Bukkit.getScheduler().runTaskLater(plugin, () ->
guiManager.showGUI(player, new KitEditorGui(plugin, player, newKit, null)), 2L);
}
});
guiManager.showGUI(player, gui);
});
setPlayerButton(8, GuiUtils.createButtonItem(CompatibleMaterial.CHEST,
plugin.getLocale().getMessage("interface.kiteditor.animation").getMessage(),
plugin.getLocale().getMessage("interface.kiteditor.animationlore")
.processPlaceholder("animation", kit.getKitAnimation().name())
.getMessage().split("\\|")),
(event) -> {
if (kit.getKitAnimation() == KitAnimation.NONE) {
kit.setKitAnimation(KitAnimation.ROULETTE);
} else {
kit.setKitAnimation(KitAnimation.NONE);
}
setInvItems();
});
}
public void saveKit(Player player, Inventory i, boolean muteSave) {
ItemStack[] items = i.getContents();
for (int num = 0; num < items.length; ++num) {
if (num < 10 || num == 17 || num == 36) {
items[num] = null;
}
}
items = Arrays.copyOf(items, items.length - 10);
kit.saveKit(Arrays.asList(items));
if (!muteSave)
plugin.getLocale().getMessage("interface.kiteditor.saved")
.processPlaceholder("kit", kit.getName())
.sendPrefixedMessage(player);
}
public void replaceItem(Action action, Player player, ItemStack itemStack, int slot) {
if (itemStack.getItemMeta().hasLore()) {
ItemMeta meta = itemStack.getItemMeta();
List<String> newLore = new ArrayList<>();
for (String line : meta.getLore()) {
if (line.contains("Moveable")) continue;
if (line.equals(TextUtils.formatText("&8----"))) break;
newLore.add(line);
}
meta.setLore(newLore);
itemStack.setItemMeta(meta);
}
KitItem item = new KitItem(itemStack);
switch (action) {
case CHANCE_UP:
case CHANCE_DOWN:
if (action == Action.CHANCE_UP)
item.setChance(item.getChance() >= 100 ? 5 : (item.getChance() + 5));
else
item.setChance(item.getChance() <= 0 ? 100 : (item.getChance() - 5));
setItem(slot, getCompiledMeta(item));
saveKit(player, inventory, true);
paint();
break;
case DISPLAY_ITEM: {
AnvilGui gui = new AnvilGui(player, this);
gui.setTitle("Enter a Material");
gui.setAction(event -> {
CompatibleMaterial compatibleMaterial = CompatibleMaterial.getMaterial(gui.getInputText().trim());
if (compatibleMaterial == null) {
player.sendMessage("'" + gui.getInputText().trim() + "' is not a valid material.");
} else {
Material material = compatibleMaterial.getMaterial();
KitItem newItem = new KitItem(itemStack);
newItem.setDisplayItem(material);
setItem(slot, newItem.getMoveableItem());
player.closeInventory();
saveKit(player, inventory, true);
paint();
}
});
guiManager.showGUI(player, gui);
}
break;
case DISPLAY_NAME: {
AnvilGui gui = new AnvilGui(player, this);
gui.setTitle("Enter a name");
gui.setAction(event -> {
KitItem newItem = new KitItem(itemStack);
newItem.setDisplayName(gui.getInputText());
setItem(slot, getCompiledMeta(newItem));
player.closeInventory();
saveKit(player, inventory, true);
paint();
});
guiManager.showGUI(player, gui);
}
break;
case DISPLAY_LORE: {
AnvilGui gui = new AnvilGui(player, this);
gui.setTitle("Enter lore");
gui.setAction(event -> {
KitItem newItem = new KitItem(itemStack);
newItem.setDisplayLore(gui.getInputText());
setItem(slot, getCompiledMeta(newItem));
player.closeInventory();
saveKit(player, inventory, true);
paint();
});
guiManager.showGUI(player, gui);
}
break;
default:
paint();
break;
}
}
private ItemStack getCompiledMeta(KitItem item) {
ItemStack is = item.getMoveableItem();
ItemMeta meta;
if (is.hasItemMeta()) meta = is.getItemMeta();
else meta = Bukkit.getItemFactory().getItemMeta(is.getType());
List<String> itemLore;
if (meta.hasLore()) itemLore = meta.getLore();
else itemLore = new ArrayList<>();
itemLore.add(TextUtils.formatText("&8----"));
itemLore.add(ChatColor.GRAY.toString() + plugin.getLocale().getMessage("general.type.chance").getMessage().replaceFirst("^" + ChatColor.RESET.toString(), "")
+ ": " + ChatColor.GOLD.toString() + item.getChance() + "%"); //TODO use a placeholder message in locales
if (isInFunction) {
itemLore.addAll(Arrays.asList(plugin.getLocale().getMessage("interface.kiteditor.itemfunctionlore")
.processPlaceholder("item", item.getDisplayItem() == null ? "" : item.getDisplayItem().name())
.processPlaceholder("name", item.getDisplayName())
.processPlaceholder("lore", item.getDisplayLore())
.getMessage().split("\\|")));
}
meta.setLore(itemLore);
is.setItemMeta(meta);
return is;
}
public enum Action {NONE, CHANCE_UP, CHANCE_DOWN, DISPLAY_ITEM, DISPLAY_NAME, DISPLAY_LORE}
}

View File

@ -1,124 +0,0 @@
package com.songoda.ultimatekits.gui;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.gui.AnvilGui;
import com.songoda.core.gui.Gui;
import com.songoda.core.gui.GuiUtils;
import com.songoda.core.utils.ItemUtils;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.kit.Kit;
import com.songoda.ultimatekits.settings.Settings;
import com.songoda.ultimatekits.utils.Methods;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
public class KitGuiOptionsGui extends Gui {
private final UltimateKits plugin;
private final Kit kit;
private final Player player;
public KitGuiOptionsGui(UltimateKits plugin, Player player, Kit kit, Gui back) {
super(3);
this.plugin = plugin;
this.kit = kit;
this.player = player;
setTitle(plugin.getLocale().getMessage("interface.kitblock.title")
.processPlaceholder("kit", kit.getName())
.getMessage());
setAcceptsItems(true); // display item takes an item
// fill glass borders
Methods.fillGlass(this);
// exit button
setButton(0, 8, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(CompatibleMaterial.OAK_DOOR),
plugin.getLocale().getMessage("interface.button.exit").getMessage()),
ClickType.LEFT,
event -> exit());
// back button
setButton(0, 0, GuiUtils.createButtonItem(ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"),
plugin.getLocale().getMessage("interface.button.back").getMessage()),
ClickType.LEFT,
event -> guiManager.showGUI(player, new KitEditorGui(plugin, player, kit, back)));
paint();
}
private void paint() {
// set hologram title
setButton(1, 2, GuiUtils.createButtonItem(CompatibleMaterial.NAME_TAG,
plugin.getLocale().getMessage("interface.kitguioptions.holo").getMessage(),
plugin.getLocale().getMessage("interface.kitguioptions.hololore")
.processPlaceholder("onoff",
kit.getTitle() != null ? plugin.getLocale().getMessage("interface.kitguioptions.holoon").processPlaceholder("title", kit.getTitle()).getMessage()
: plugin.getLocale().getMessage("interface.kitguioptions.holooff").getMessage()
).getMessage().split("\\|")),
ClickType.LEFT,
event -> {
AnvilGui gui = new AnvilGui(event.player, this);
gui.setTitle(plugin.getLocale().getMessage("interface.kitguioptions.holoprompt").getMessage());
gui.setAction(evnt -> {
final String msg = gui.getInputText().trim();
kit.setTitle(msg);
plugin.getLocale().getMessage("interface.kitguioptions.holoset")
.processPlaceholder("title", msg)
.processPlaceholder("kit", kit.getName())
.sendPrefixedMessage(player);
plugin.updateHologram(kit);
evnt.player.closeInventory();
paint();
plugin.saveKits(false);
});
guiManager.showGUI(event.player, gui);
});
setAction(1, 2, ClickType.RIGHT, event -> {
kit.setTitle(null);
plugin.updateHologram(kit);
paint();
plugin.saveKits(false);
});
setButton(1, 4, GuiUtils.createButtonItem(kit.getDisplayItem() != null ? kit.getDisplayItem() : CompatibleMaterial.BEACON.getItem(),
plugin.getLocale().getMessage("interface.kitguioptions.item").getMessage(),
plugin.getLocale().getMessage("interface.kitguioptions.itemlore")
.processPlaceholder("onoff",
kit.getDisplayItem() != null ? plugin.getLocale().getMessage("interface.kitguioptions.itemon")
.processPlaceholder("item", kit.getDisplayItem().toString()).getMessage()
: plugin.getLocale().getMessage("interface.kitguioptions.itemoff").getMessage()
).getMessage().split("\\|")),
ClickType.LEFT,
event -> {
ItemStack is = player.getItemInHand();
if (is.getType() == Material.AIR) {
plugin.getLocale().getMessage("interface.kitguioptions.itemnoitem").sendPrefixedMessage(player);
} else {
kit.setDisplayItem(is);
plugin.getLocale().getMessage("interface.kitguioptions.itemset").processPlaceholder("item", kit.getName()).sendPrefixedMessage(player);
paint();
}
plugin.saveKits(false);
});
setAction(1, 4, ClickType.RIGHT, event -> {
kit.setDisplayItem((ItemStack) null);
plugin.getLocale().getMessage("interface.kitguioptions.itemremoved").processPlaceholder("kit", kit.getName()).sendPrefixedMessage(player);
paint();
});
setButton(1, 6, GuiUtils.createButtonItem(CompatibleMaterial.COAL,
plugin.getLocale().getMessage("interface.kitguioptions.hide").getMessage(),
plugin.getLocale().getMessage("interface.kitguioptions.hidelore")
.processPlaceholder("onoff", plugin.getLocale().getMessage(
kit.isHidden() ? "interface.kitguioptions.hideon" : "interface.kitguioptions.hideoff").getMessage()
).getMessage().split("\\|")),
ClickType.LEFT,
event -> {
kit.setHidden(!kit.isHidden());
paint();
plugin.saveKits(false);
});
}
}

View File

@ -1,220 +0,0 @@
package com.songoda.ultimatekits.gui;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.gui.Gui;
import com.songoda.core.gui.GuiUtils;
import com.songoda.core.utils.ItemUtils;
import com.songoda.core.utils.TextUtils;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.category.Category;
import com.songoda.ultimatekits.kit.Kit;
import com.songoda.ultimatekits.settings.Settings;
import com.songoda.ultimatekits.utils.Methods;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
public class KitSelectorGui extends Gui {
private final Player player;
private final UltimateKits plugin;
private int timer;
private final Category category;
private List<String> kitList;
private boolean kitsmode = false;
private final boolean glassless;
private final int showPerPage;
public KitSelectorGui(UltimateKits plugin, Player player, Category category) {
this.player = player;
this.plugin = plugin;
this.category = category;
glassless = Settings.DO_NOT_USE_GLASS_BORDERS.getBoolean();
setTitle(plugin.getLocale().getMessage("interface.selector.title").getMessage());
loadKits();
int showPerRow = glassless ? 9 : 7;
int nrows = (int) Math.ceil(kitList.size() / (double) showPerRow);
setRows(glassless ? nrows : nrows + 2);
showPerPage = showPerRow * (glassless ? (nrows == 6 ? 6 : 5) : 4);
setPages(kitList.size() / showPerPage);
setItem(0, 4, GuiUtils.createButtonItem(CompatibleMaterial.BOOK,
plugin.getLocale().getMessage("interface.selector.details")
.processPlaceholder("player", player.getName()).getMessage().split("\\|")));
if (pages > 1) {
this.setNextPage(rows - 1, 5, GuiUtils.createButtonItem(ItemUtils.getCustomHead("1b6f1a25b6bc199946472aedb370522584ff6f4e83221e5946bd2e41b5ca13b"),
plugin.getLocale().getMessage("interface.button.next").getMessage()));
this.setPrevPage(rows - 1, 3, GuiUtils.createButtonItem(ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"),
plugin.getLocale().getMessage("interface.button.last").getMessage()));
this.setOnPage(pager -> showPage());
}
if (!glassless) {
setButton(rows - 1, 4, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(CompatibleMaterial.OAK_DOOR),
UltimateKits.getInstance().getLocale().getMessage("interface.button.exit").getMessage()),
event -> exit());
}
ItemStack glass2 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_2.getMaterial());
setDefaultItem(AIR);
mirrorFill(0, 0, true, true, glass2);
if (!glassless) {
if (Settings.RAINBOW.getBoolean()) {
animateGlass();
timer = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
if (inventory.getViewers().isEmpty()) return;
animateGlass();
}, 20L, 20L);
setOnClose(event -> Bukkit.getScheduler().cancelTask(timer));
} else {
ItemStack glass1 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_1.getMaterial());
ItemStack glass3 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_3.getMaterial());
mirrorFill(0, 0, true, true, glass2);
mirrorFill(1, 0, true, true, glass2);
mirrorFill(0, 1, true, true, glass2);
mirrorFill(0, 2, true, true, glass3);
mirrorFill(0, 3, false, true, glass1);
}
}
if (category != null)
setButton(0, 0, GuiUtils.createButtonItem(ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"),
plugin.getLocale().getMessage("interface.button.back").getMessage()),
event -> guiManager.showGUI(player, new CategorySelectorGui(plugin, player)));
showPage();
}
private void loadKits() {
kitList = plugin.getKitManager().getKits().stream()
.filter(kit -> !kit.isHidden() && kit.hasPermissionToPreview(player)
&& (category == null || kit.getCategory() == category))
.map(Kit::getKey)
.collect(Collectors.toList());
}
private static final Random rand = new Random();
private void animateGlass() {
for (int col = 1; col < 8; ++col) {
ItemStack it;
if ((it = getItem(0, col)) == null || it.getType() == Material.AIR || it.getType().name().contains("PANE"))
setItem(0, col, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneColor(rand.nextInt(16))));
if ((it = getItem(rows - 1, col)) == null || it.getType() == Material.AIR || it.getType().name().contains("PANE"))
setItem(rows - 1, col, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneColor(rand.nextInt(16))));
}
for (int row = 1; row + 1 < rows; ++row) {
setItem(row, 0, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneColor(rand.nextInt(16))));
setItem(row, 8, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneColor(rand.nextInt(16))));
}
}
private void showPage() {
int index = (page - 1) * showPerPage;
for (int row = glassless ? 0 : 1; row < (!glassless || pages != 1 ? rows - 1 : rows); ++row) {
for (int col = glassless ? 0 : 1; col < (glassless ? 9 : 8); ++col) {
if (index >= kitList.size()) {
setItem(row, col, null);
clearActions(row, col);
continue;
}
final String kitItem = kitList.get(index++);
final Kit kit = plugin.getKitManager().getKit(kitItem);
String kitTitle = kit.getTitle() != null
? ChatColor.translateAlternateColorCodes('&', kit.getTitle())
: plugin.getLocale().getMessage("interface.selector.kit")
.processPlaceholder("kit", TextUtils.formatText(kitItem, true)).getMessage();
setButton(row, col, GuiUtils.createButtonItem(
kit.getDisplayItem() != null ? kit.getDisplayItem() : CompatibleMaterial.ENCHANTED_BOOK.getItem(), kitTitle,
getKitLore(kit)),
event -> {
if (event.clickType == ClickType.MIDDLE && player.hasPermission("ultimatekits.admin")) {
kitsmode = !kitsmode;
showPage();
} else if (kitsmode) {
if (event.clickType == ClickType.RIGHT) {
plugin.getKitManager().moveKit(kit, true);
} else if (event.clickType == ClickType.LEFT) {
plugin.getKitManager().moveKit(kit, false);
}
loadKits();
plugin.saveKits(false);
showPage();
} else if (event.clickType == ClickType.LEFT) {
kit.display(player, guiManager, this);
} else if (event.clickType == ClickType.RIGHT) {
kit.buy(event.player, event.manager);
}
});
}
}
}
private List<String> getKitLore(Kit kit) {
ArrayList<String> lore = new ArrayList<>();
if (kit.getPrice() != 0)
lore.add(plugin.getLocale().getMessage("interface.selector.aboutkitprice")
.processPlaceholder("price", String.valueOf(kit.getPrice()))
.getMessage());
else if (kit.getLink() != null)
lore.add(plugin.getLocale().getMessage("general.type.link").getMessage());
if (!kitsmode) {
if (!plugin.getLocale().getMessage("interface.selector.aboutkit").getMessage().trim().equals("")) {
String[] parts = plugin.getLocale().getMessage("interface.selector.aboutkit").getMessage().split("\\|");
lore.add("");
for (String line : parts)
lore.add(ChatColor.translateAlternateColorCodes('&', line));
}
if (kit.hasPermissionToClaim(player)) {
if (kit.getNextUse(player) == -1) {
lore.add(plugin.getLocale().getMessage("event.claim.once").getMessage());
} else if (kit.getNextUse(player) > 0) {
if (!plugin.getLocale().getMessage("event.claim.wait").getMessage().trim().equals("")) {
lore.add(plugin.getLocale().getMessage("event.claim.wait")
.processPlaceholder("time", Methods.makeReadable(kit.getNextUse(player)))
.getMessage());
}
} else if (!plugin.getLocale().getMessage("event.claim.ready").getMessage().trim().equals("")) {
lore.add(plugin.getLocale().getMessage("event.claim.ready").getMessage());
}
} else
lore.add(plugin.getLocale().getMessage("event.claim.noaccess").getMessage());
lore.add("");
lore.add(plugin.getLocale().getMessage("interface.selector.leftpreview").getMessage());
if (kit.hasPermissionToClaim(player)) {
lore.add(plugin.getLocale().getMessage("interface.selector.rightclaim").getMessage());
} else if (kit.getPrice() != 0 || kit.getLink() != null) {
lore.add(plugin.getLocale().getMessage("interface.selector.rightbuy").getMessage());
}
if (player.hasPermission("ultimatekits.admin")) {
lore.add("");
lore.add(plugin.getLocale().getMessage("interface.selector.adminlore").getMessage());
}
} else {
lore.addAll(Arrays.asList(plugin.getLocale().getMessage("interface.selector.editlore").getMessage().split("\\|")));
}
return lore;
}
}

View File

@ -1,128 +0,0 @@
package com.songoda.ultimatekits.gui;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.gui.AnvilGui;
import com.songoda.core.gui.Gui;
import com.songoda.core.gui.GuiUtils;
import com.songoda.core.hooks.EconomyManager;
import com.songoda.core.utils.ItemUtils;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.kit.Kit;
import com.songoda.ultimatekits.settings.Settings;
import com.songoda.ultimatekits.utils.Methods;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
public class KitSellingOptionsGui extends Gui {
private final UltimateKits plugin;
private final Player player;
private final Kit kit;
public KitSellingOptionsGui(UltimateKits plugin, Player player, Kit kit, Gui back) {
super(3);
this.plugin = plugin;
this.player = player;
this.kit = kit;
setTitle(plugin.getLocale().getMessage("interface.kitblock.title")
.processPlaceholder("kit", kit.getName())
.getMessage());
// fill glass borders
Methods.fillGlass(this);
// exit button
setButton(0, 8, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(CompatibleMaterial.OAK_DOOR),
plugin.getLocale().getMessage("interface.button.exit").getMessage()),
ClickType.LEFT,
event -> exit());
// back button
setButton(0, 0, GuiUtils.createButtonItem(ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"),
plugin.getLocale().getMessage("interface.button.back").getMessage()),
ClickType.LEFT,
event -> guiManager.showGUI(player, new KitEditorGui(plugin, player, kit, back)));
paint();
}
private void paint() {
// remove sale
setButton(1, 2, GuiUtils.createButtonItem(CompatibleMaterial.BARRIER,
plugin.getLocale().getMessage("interface.kitsell.nosell").getMessage(),
plugin.getLocale().getMessage("interface.kitsell.noselllore")
.processPlaceholder("onoff", plugin.getLocale().getMessage(
kit.getPrice() != 0 || kit.getLink() != null ? "interface.kitsell.nosellon" : "interface.kitsell.noselloff").getMessage()
).getMessage().split("\\|")),
event -> {
kit.setPrice(0);
kit.setLink(null);
paint();
});
// kit link
setButton(1, 4, GuiUtils.createButtonItem(CompatibleMaterial.PAPER,
plugin.getLocale().getMessage("interface.kitsell.link").getMessage(),
plugin.getLocale().getMessage("interface.kitsell.linklore")
.processPlaceholder("onoff",
kit.getLink() != null ? plugin.getLocale().getMessage("interface.kitsell.linkon").processPlaceholder("kit", kit.getLink()).getMessage()
: plugin.getLocale().getMessage("interface.kitsell.linkoff").getMessage()
).getMessage().split("\\|")),
event -> {
AnvilGui gui = new AnvilGui(event.player, this);
gui.setTitle(plugin.getLocale().getMessage("interface.kitsell.linkprompt").getMessage());
gui.setAction(aevent -> {
final String msg = gui.getInputText().trim();
if (kit.getPrice() != 0) {
kit.setPrice(0);
plugin.getLocale().getMessage("interface.kitsell.linknoeco").sendPrefixedMessage(player);
}
kit.setLink(msg);
plugin.updateHologram(kit);
aevent.player.closeInventory();
paint();
plugin.saveKits(false);
});
guiManager.showGUI(event.player, gui);
});
// kit price
setButton(1, 6, GuiUtils.createButtonItem(CompatibleMaterial.SUNFLOWER,
plugin.getLocale().getMessage("interface.kitsell.price").getMessage(),
plugin.getLocale().getMessage("interface.kitsell.pricelore")
.processPlaceholder("onoff",
kit.getPrice() != 0 ? plugin.getLocale().getMessage("interface.kitsell.priceon")
.processPlaceholder("price", kit.getPrice()).getMessage()
: plugin.getLocale().getMessage("interface.kitsell.priceoff").getMessage()
).getMessage().split("\\|")),
event -> {
if (!EconomyManager.isEnabled()) {
plugin.getLocale().getMessage("interface.kitsell.pricenoeco").sendPrefixedMessage(event.player);
return;
}
AnvilGui gui = new AnvilGui(event.player, this);
gui.setTitle(plugin.getLocale().getMessage("interface.kitsell.priceprompt").getMessage());
gui.setAction(aevent -> {
final String msg = gui.getInputText().trim();
double d = 0;
try {
d = Double.parseDouble(msg);
} catch (NumberFormatException e) {
}
if (d <= 0) {
plugin.getLocale().getMessage("interface.kitsell.pricenonumber").processPlaceholder("input", msg).sendPrefixedMessage(player);
} else {
if (kit.getLink() != null) {
kit.setLink(null);
plugin.getLocale().getMessage("interface.kitsell.pricenolink").sendPrefixedMessage(player);
}
kit.setPrice(d);
plugin.updateHologram(kit);
aevent.player.closeInventory();
paint();
plugin.saveKits(false);
}
});
guiManager.showGUI(event.player, gui);
});
}
}

View File

@ -1,34 +0,0 @@
package com.songoda.ultimatekits.key;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
public final class KeyManager {
private final Set<Key> registeredKeys = new HashSet<>();
public boolean addKey(Key key) {
if (key == null) return false;
return registeredKeys.add(key);
}
public void removeKey(Key key) {
registeredKeys.remove(key);
}
public Key getKey(String name) {
for (Key key : registeredKeys)
if (key.getName().equalsIgnoreCase(name)) return key;
return null;
}
public Set<Key> getKeys() {
return Collections.unmodifiableSet(registeredKeys);
}
public void clear() {
registeredKeys.clear();
}
}

View File

@ -1,17 +0,0 @@
package com.songoda.ultimatekits.kit;
public enum KitType {
PREVIEW, CRATE, CLAIM;
public static KitType getKitType(String search) {
if (search != null) {
for (KitType t : values()) {
if (t.name().equalsIgnoreCase(search)) {
return t;
}
}
}
return null;
}
}

View File

@ -1,30 +0,0 @@
package com.songoda.ultimatekits.listeners;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.settings.Settings;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
public class PlayerListeners implements Listener {
private final UltimateKits plugin;
public PlayerListeners() {
plugin = UltimateKits.getInstance();
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
if (player.hasPlayedBefore()) return;
if (plugin.getKitManager().getKit(Settings.STARTER_KIT.getString()) == null
|| Settings.STARTER_KIT.getString() == null
|| Settings.STARTER_KIT.getString().equalsIgnoreCase("none")) return;
plugin.getKitManager().getKit(Settings.STARTER_KIT.getString()).giveKit(player);
}
}

View File

@ -1,206 +0,0 @@
package com.songoda.ultimatekits.utils;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.gui.Gui;
import com.songoda.core.gui.GuiUtils;
import com.songoda.ultimatekits.settings.Settings;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.TimeUnit;
/**
* Created by songoda on 2/24/2017.
*/
public class Methods {
private static final Random rand = new Random();
public static boolean canGiveKit(Player player) {
if (player.hasPermission("ultimatekits.cangive")) return true;
if (player.hasPermission("essentials.kit.others")) return true;
return false;
}
/**
* Serializes the location of the block specified.
*
* @param block The block whose location is to be saved.
* @return The serialized data.
*/
public static String serializeLocation(Block block) {
if (block == null)
return "";
return serializeLocation(block.getLocation());
}
/**
* Serializes the location specified.
*
* @param location The location that is to be saved.
* @return The serialized data.
*/
public static String serializeLocation(Location location) {
if (location == null || location.getWorld() == null)
return null;
String w = location.getWorld().getName();
double x = location.getX();
double y = location.getY();
double z = location.getZ();
String str = w + ":" + x + ":" + y + ":" + z;
str = str.replace(".0", "").replace("/", "");
return str;
}
private static Map<String, Location> serializeCache = new HashMap<>();
/**
* Deserializes a location from the string.
*
* @param str The string to parse.
* @return The location that was serialized in the string.
*/
public static Location unserializeLocation(String str) {
if (str == null || str.equals(""))
return null;
if (serializeCache.containsKey(str)) {
return serializeCache.get(str).clone();
}
String cacheKey = str;
str = str.replace("y:", ":").replace("z:", ":").replace("w:", "").replace("x:", ":").replace("/", ".");
List<String> args = Arrays.asList(str.split("\\s*:\\s*"));
World world = Bukkit.getWorld(args.get(0));
double x = Double.parseDouble(args.get(1));
double y = Double.parseDouble(args.get(2));
double z = Double.parseDouble(args.get(3));
Location location = new Location(world, x, y, z, 0, 0);
serializeCache.put(cacheKey, location.clone());
return location;
}
public static String makeReadable(Long time) {
if (time == null)
return "1s";
StringBuilder sb = new StringBuilder();
long days = TimeUnit.MILLISECONDS.toDays(time);
long hours = TimeUnit.MILLISECONDS.toHours(time) - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(time));
long minutes = TimeUnit.MILLISECONDS.toMinutes(time) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(time));
long seconds = TimeUnit.MILLISECONDS.toSeconds(time) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time));
if (days != 0L)
sb.append(" ").append(days).append("d");
if (hours != 0L)
sb.append(" ").append(hours).append("h");
if (minutes != 0L)
sb.append(" ").append(minutes).append("m");
if (seconds != 0L)
sb.append(" ").append(seconds).append("s");
if (sb.length() == 0)
sb.append("1s");
return sb.toString().trim();
}
public static long parseTime(String input) {
long result = 0;
StringBuilder number = new StringBuilder();
for (int i = 0; i < input.length(); i++) {
char c = input.charAt(i);
if (Character.isDigit(c)) {
number.append(c);
} else if (Character.isLetter(c) && (number.length() > 0)) {
result += convert(Integer.parseInt(number.toString()), c);
number = new StringBuilder();
}
}
return result;
}
private static long convert(long value, char unit) {
switch (unit) {
case 'd':
return value * 1000 * 60 * 60 * 24;
case 'h':
return value * 1000 * 60 * 60;
case 'm':
return value * 1000 * 60;
case 's':
return value * 1000;
}
return 0;
}
/**
* Formats the specified double into the Economy format specified in the Arconix config.
*
* @param amt The double to format.
* @return The economy formatted double.
*/
public static String formatEconomy(double amt) {
DecimalFormat formatter = new DecimalFormat("#,###.00");
return formatter.format(amt);
}
public static boolean isInt(String number) {
if (number == null || number.equals(""))
return false;
try {
Integer.parseInt(number);
} catch (NumberFormatException e) {
return false;
}
return true;
}
/**
* Determines if the provided string is a valid number (int, double, float, or otherwise).
*
* @param s The string to check.
* @return <code>true</code> if the string is numeric, otherwise <code>false</code>
*/
public static boolean isNumeric(String s) {
if (s == null || s.equals(""))
return false;
return s.matches("[-+]?\\d*\\.?\\d+");
}
public static void fillGlass(Gui gui) {
// fill center with glass
if (Settings.RAINBOW.getBoolean()) {
for (int row = 0; row < gui.getRows(); ++row) {
for (int col = row == 1 ? 2 : 3; col < (row == 1 ? 7 : 6); ++col) {
gui.setItem(row, col, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneColor(rand.nextInt(16))));
}
}
} else {
gui.setDefaultItem(GuiUtils.getBorderItem(Settings.GLASS_TYPE_1.getMaterial(CompatibleMaterial.GRAY_STAINED_GLASS_PANE)));
}
// decorate the edges
ItemStack glass2 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_2.getMaterial(CompatibleMaterial.BLUE_STAINED_GLASS_PANE));
ItemStack glass3 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_3.getMaterial(CompatibleMaterial.LIGHT_BLUE_STAINED_GLASS_PANE));
// edges will be type 3
gui.mirrorFill(0, 2, true, true, glass3);
gui.mirrorFill( 1, 1, false, true, glass3);
// decorate corners with type 2
gui.mirrorFill( 0, 0, true, true, glass2);
gui.mirrorFill( 1, 0, true, true, glass2);
gui.mirrorFill(0, 1, true, true, glass2);
}
}

View File

@ -8,4 +8,4 @@ Glass-Type: 'This is the id of the glass used for the background in the inventor
Rainbow-Glass: 'If this is enabled the glass background will be randomized colors.'
Only-Show-Kits-With-Perms: 'If this is set to true kit in the /kit gui will only show up if the user has perms for them.'
Dont-Preview-Commands: 'When enabled this will prevent commands from being previewed in UltimateKits'
Kits-Free-With-Perms: 'If this is enabled players will be able to get a kit free through kit preview if they have perms for the kit in essentials/ultimatecore'
Kits-Free-With-Perms: 'If this is enabled players will be able to get a kit free through kit preview if they have perms for the kit in essentials/ultimatecore'

View File

@ -1,5 +1,4 @@
# General Messages
general:
nametag:
prefix: '&8[&9UltimateKits&8]'
@ -11,6 +10,7 @@ general:
link: '&9Link'
free: Free
any: Any
# Interface Messages
interface:
selector:
@ -165,6 +165,7 @@ interface:
switchtokitfunctionslore: '&7Click to switch back|&7to the kit functions.'
itemfunctionlore: '&7Display Item: &6%item%|&7Display Name: &6%name%|&7Display Lore: &6%lore%||&7Left-Click: &6To set a display item.|&7Middle-Click: &6To set a display name.|&7Right-Click: &6To set display lore.|&7Shift-Click: &6To set chance.||&7Display options only show up on display.|&7This can be useful if you want to explain|&7What an item does without putting it in the|&7permanent lore.||&6Leave function mode to move items.'
saved: '&8Changes to &a%kit% &8saved successfully.'
# Command Messages
command:
general:
@ -178,6 +179,7 @@ command:
crate:
given: '&9Gave &7%player% &9crate &7%crate% &9for kit &7%kit%.'
doesntexist: '&cThis crate is not loaded.'
# Event Messages
event:
preview:

View File

@ -3,9 +3,10 @@ description: ${project.description}
version: ${project.version}
api-version: 1.13
main: com.songoda.ultimatekits.UltimateKits
main: com.craftaro.ultimatekits.UltimateKits
softdepend:
- CMI
- DecentHolograms
- Essentials
- Holograms
- HolographicDisplays
@ -16,26 +17,24 @@ softdepend:
- UltimateCore
- Vault
author: Songoda
author: Craftaro
website: ${project.url}
commands:
kitadmin:
description: View information on this plugin.
default: true
usage: /<command> [reload]
usage: /<command>
aliases:
- kp
- uk
- ultimatekits
kit:
description: Preview a kit
default: true
usage: /<commands>
aliases:
- kits
previewkit:
description: Preview a kit
default: true
@ -45,9 +44,9 @@ commands:
- preview
permissions:
ultimatekits.use:
UltimateKits.use:
description: allows the user to preview kit
default: true
ultimatekits.admin:
UltimateKits.admin:
description: Gives access to admin commands.