Makes ItemCase compile for Minecraft 1.17
This commit is contained in:
parent
a9f1d9e5e7
commit
90b0223d8d
@ -21,6 +21,7 @@ ItemCase uses Maven to handle its dependencies.
|
|||||||
|
|
||||||
Coding and Pull Request Formatting
|
Coding and Pull Request Formatting
|
||||||
----------------------------------
|
----------------------------------
|
||||||
|
|
||||||
* Generally follow the Oracle coding standards.
|
* Generally follow the Oracle coding standards.
|
||||||
* Use spaces not tabs.
|
* Use spaces not tabs.
|
||||||
* No trailing whitespaces.
|
* No trailing whitespaces.
|
||||||
@ -31,6 +32,9 @@ Coding and Pull Request Formatting
|
|||||||
**Please try to follow the above conventions if you want your pull request(s) accepted.**
|
**Please try to follow the above conventions if you want your pull request(s) accepted.**
|
||||||
|
|
||||||
[License]: http://www.gnu.org/licenses/gpl.html
|
[License]: http://www.gnu.org/licenses/gpl.html
|
||||||
|
|
||||||
[GitHub]: http://github.com/BleedObsidian/ItemCase/
|
[GitHub]: http://github.com/BleedObsidian/ItemCase/
|
||||||
|
|
||||||
[Bukkit]: http://dev.bukkit.org/bukkit-plugins/itemcase/
|
[Bukkit]: http://dev.bukkit.org/bukkit-plugins/itemcase/
|
||||||
|
|
||||||
[Javadoc]: http://bleedobsidian.github.io/ItemCase/
|
[Javadoc]: http://bleedobsidian.github.io/ItemCase/
|
96
pom.xml
96
pom.xml
@ -1,36 +1,38 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>com.gmail.bleedobsidian</groupId>
|
<groupId>com.gmail.bleedobsidian</groupId>
|
||||||
<artifactId>ItemCase</artifactId>
|
<artifactId>ItemCase</artifactId>
|
||||||
<name>ItemCase</name>
|
<name>ItemCase</name>
|
||||||
<description>ItemCase is a Bukkit plugin allowing you to showcase items on slabs, that can also be used as shops.</description>
|
<description>ItemCase is a Bukkit plugin allowing you to showcase items on slabs, that can also be used as shops.
|
||||||
|
</description>
|
||||||
<version>2.0.0</version>
|
<version>2.0.0</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>16</maven.compiler.source>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<maven.compiler.target>16</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>spigot-repo</id>
|
<id>sk89q-repo</id>
|
||||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
<url>https://maven.enginehub.org/repo/</url>
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
<id>bstats-repo</id>
|
<id>spigot-repo</id>
|
||||||
<url>http://repo.bstats.org/content/repositories/releases/</url>
|
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
<id>vault-repo</id>
|
<id>vault-repo</id>
|
||||||
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
|
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
<id>sk89q-repo</id>
|
<id>OnARandomBox</id>
|
||||||
<url>http://maven.sk89q.com/repo/</url>
|
<url>https://repo.onarandombox.com/content/groups/public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
@ -38,48 +40,25 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>spigot-api</artifactId>
|
<artifactId>spigot-api</artifactId>
|
||||||
<version>1.12.2-R0.1-SNAPSHOT</version>
|
<version>1.17.1-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.bukkit</groupId>
|
|
||||||
<artifactId>bukkit</artifactId>
|
|
||||||
<version>1.12.2-R0.1-SNAPSHOT</version>
|
|
||||||
<type>jar</type>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.bstats</groupId>
|
|
||||||
<artifactId>bstats-bukkit</artifactId>
|
|
||||||
<version>1.2</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.onarandombox.multiversecore</groupId>
|
<groupId>com.onarandombox.multiversecore</groupId>
|
||||||
<artifactId>Multiverse-Core</artifactId>
|
<artifactId>Multiverse-Core</artifactId>
|
||||||
<version>2.5.0</version>
|
<version>4.3.1</version>
|
||||||
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.milkbowl.vault</groupId>
|
<groupId>net.milkbowl.vault</groupId>
|
||||||
<artifactId>VaultAPI</artifactId>
|
<artifactId>VaultAPI</artifactId>
|
||||||
<version>1.6</version>
|
<version>1.7</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.sk89q.worldguard</groupId>
|
<groupId>com.sk89q.worldguard</groupId>
|
||||||
<artifactId>worldguard</artifactId>
|
<artifactId>worldguard-bukkit</artifactId>
|
||||||
<version>6.2.1</version>
|
<version>7.0.7-SNAPSHOT</version>
|
||||||
</dependency>
|
<scope>provided</scope>
|
||||||
<dependency>
|
|
||||||
<groupId>org.powermock</groupId>
|
|
||||||
<artifactId>powermock-module-junit4</artifactId>
|
|
||||||
<version>1.7.1</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.powermock</groupId>
|
|
||||||
<artifactId>powermock-api-mockito</artifactId>
|
|
||||||
<version>1.7.1</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
@ -110,52 +89,19 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.1</version>
|
<version>3.8.1</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
<version>2.4</version>
|
<version>3.2.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<archive>
|
<archive>
|
||||||
<addMavenDescriptor>false</addMavenDescriptor>
|
<addMavenDescriptor>false</addMavenDescriptor>
|
||||||
</archive>
|
</archive>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>shade</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
<configuration>
|
|
||||||
<finalName>${artifactId}</finalName>
|
|
||||||
<artifactSet>
|
|
||||||
<excludes>
|
|
||||||
<exclude>org.bukkit</exclude>
|
|
||||||
<exclude>net.milkbowl.vault</exclude>
|
|
||||||
<exclude>junit</exclude>
|
|
||||||
<exclude>com.sk89q.worldguard</exclude>
|
|
||||||
</excludes>
|
|
||||||
<includes>
|
|
||||||
<include>org.bstats:*</include>
|
|
||||||
</includes>
|
|
||||||
</artifactSet>
|
|
||||||
<relocations>
|
|
||||||
<relocation>
|
|
||||||
<pattern>org.bstats</pattern>
|
|
||||||
<shadedPattern>com.gmail.bleedobsidian</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
</relocations>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
@ -30,5 +30,5 @@ public interface Command {
|
|||||||
* @param label The label used,
|
* @param label The label used,
|
||||||
* @param args Any arguments.
|
* @param args Any arguments.
|
||||||
*/
|
*/
|
||||||
public void execute(CommandSender sender, String label, String[] args);
|
void execute(CommandSender sender, String label, String[] args);
|
||||||
}
|
}
|
||||||
|
@ -14,17 +14,18 @@
|
|||||||
*/
|
*/
|
||||||
package com.gmail.bleedobsidian.itemcase;
|
package com.gmail.bleedobsidian.itemcase;
|
||||||
|
|
||||||
import com.gmail.bleedobsidian.itemcase.loggers.GenericLogger;
|
|
||||||
import com.gmail.bleedobsidian.itemcase.loggers.ChatLogger;
|
|
||||||
import com.gmail.bleedobsidian.itemcase.commands.CreateCommand;
|
import com.gmail.bleedobsidian.itemcase.commands.CreateCommand;
|
||||||
import com.gmail.bleedobsidian.itemcase.commands.ModifyCommand;
|
|
||||||
import com.gmail.bleedobsidian.itemcase.commands.DestroyCommand;
|
import com.gmail.bleedobsidian.itemcase.commands.DestroyCommand;
|
||||||
|
import com.gmail.bleedobsidian.itemcase.commands.ModifyCommand;
|
||||||
import com.gmail.bleedobsidian.itemcase.commands.OrderCommand;
|
import com.gmail.bleedobsidian.itemcase.commands.OrderCommand;
|
||||||
import com.gmail.bleedobsidian.itemcase.commands.StorageCommand;
|
import com.gmail.bleedobsidian.itemcase.commands.StorageCommand;
|
||||||
|
import com.gmail.bleedobsidian.itemcase.loggers.ChatLogger;
|
||||||
|
import com.gmail.bleedobsidian.itemcase.loggers.GenericLogger;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The central command handler for all ItemCase commands.
|
* The central command handler for all ItemCase commands.
|
||||||
@ -34,11 +35,11 @@ import org.bukkit.entity.Player;
|
|||||||
public final class CommandHandler implements CommandExecutor {
|
public final class CommandHandler implements CommandExecutor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command,
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
|
||||||
String label, String[] args) {
|
@NotNull String label, String[] args) {
|
||||||
|
|
||||||
// Check we have atleast 1 argument (sub-command label).
|
// Check we have atleast 1 argument (sub-command label).
|
||||||
if(args.length <= 0) {
|
if (args.length <= 0) {
|
||||||
|
|
||||||
// Show help message.
|
// Show help message.
|
||||||
this.showHelp(sender, label);
|
this.showHelp(sender, label);
|
||||||
@ -48,7 +49,7 @@ public final class CommandHandler implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Direct sub-command to corresponding command handler.
|
// Direct sub-command to corresponding command handler.
|
||||||
switch(args[0]) {
|
switch (args[0]) {
|
||||||
|
|
||||||
case "create":
|
case "create":
|
||||||
new CreateCommand().execute(sender, label, args);
|
new CreateCommand().execute(sender, label, args);
|
||||||
@ -94,10 +95,9 @@ public final class CommandHandler implements CommandExecutor {
|
|||||||
String command = "/" + label + " [create/order/destroy/modify/storage]";
|
String command = "/" + label + " [create/order/destroy/modify/storage]";
|
||||||
|
|
||||||
// Check if sender is a player or console.
|
// Check if sender is a player or console.
|
||||||
if(sender instanceof Player) {
|
if (sender instanceof Player player) {
|
||||||
|
|
||||||
// Cast sender to player.
|
// Cast sender to player.
|
||||||
Player player = (Player) sender;
|
|
||||||
|
|
||||||
// Get chat logger.
|
// Get chat logger.
|
||||||
ChatLogger logger = ItemCaseCore.instance.getChatLogger();
|
ChatLogger logger = ItemCaseCore.instance.getChatLogger();
|
||||||
|
@ -14,15 +14,16 @@
|
|||||||
*/
|
*/
|
||||||
package com.gmail.bleedobsidian.itemcase;
|
package com.gmail.bleedobsidian.itemcase;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An object with a corresponding configuration file that can be loaded/saved.
|
* An object with a corresponding configuration file that can be loaded/saved.
|
||||||
@ -39,12 +40,12 @@ public class ConfigurationFile {
|
|||||||
/**
|
/**
|
||||||
* The name of this configuration file.
|
* The name of this configuration file.
|
||||||
*/
|
*/
|
||||||
private String name;
|
private final String name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the default file in the jar.
|
* The name of the default file in the jar.
|
||||||
*/
|
*/
|
||||||
private String defaultName;
|
private final String defaultName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If this configuration file can be copied outside of the jar.
|
* If this configuration file can be copied outside of the jar.
|
||||||
@ -91,18 +92,17 @@ public class ConfigurationFile {
|
|||||||
* does not exist, it is copied from the plugins jar.
|
* does not exist, it is copied from the plugins jar.
|
||||||
*
|
*
|
||||||
* @param plugin JavaPlugin.
|
* @param plugin JavaPlugin.
|
||||||
* @throws IOException.
|
|
||||||
*/
|
*/
|
||||||
public void load(JavaPlugin plugin) throws IOException {
|
public void load(JavaPlugin plugin) throws IOException {
|
||||||
|
|
||||||
// If this configuration file can be copied outside of the jar...
|
// If this configuration file can be copied outside of the jar...
|
||||||
if(this.canCopy) {
|
if (this.canCopy) {
|
||||||
|
|
||||||
// Create file reference.
|
// Create file reference.
|
||||||
File fileReference = new File(plugin.getDataFolder(), this.name);
|
File fileReference = new File(plugin.getDataFolder(), this.name);
|
||||||
|
|
||||||
// If the file doesn't exist...
|
// If the file doesn't exist...
|
||||||
if(!fileReference.exists() && this.canCopy) {
|
if (!fileReference.exists() && this.canCopy) {
|
||||||
|
|
||||||
// Copy default config from jar to data folder.
|
// Copy default config from jar to data folder.
|
||||||
this.copyDefault(plugin);
|
this.copyDefault(plugin);
|
||||||
@ -145,7 +145,6 @@ public class ConfigurationFile {
|
|||||||
* jar to the data folder.
|
* jar to the data folder.
|
||||||
*
|
*
|
||||||
* @param plugin JavaPlugin.
|
* @param plugin JavaPlugin.
|
||||||
* @throws IOException.
|
|
||||||
*/
|
*/
|
||||||
private void copyDefault(JavaPlugin plugin) throws IOException {
|
private void copyDefault(JavaPlugin plugin) throws IOException {
|
||||||
|
|
||||||
@ -156,7 +155,7 @@ public class ConfigurationFile {
|
|||||||
InputStream inputStream = plugin.getResource(this.defaultName);
|
InputStream inputStream = plugin.getResource(this.defaultName);
|
||||||
|
|
||||||
// Check if we succeeded.
|
// Check if we succeeded.
|
||||||
if(inputStream == null) {
|
if (inputStream == null) {
|
||||||
|
|
||||||
// Throw exception.
|
// Throw exception.
|
||||||
throw new IOException("Failed to create input stream to default"
|
throw new IOException("Failed to create input stream to default"
|
||||||
@ -175,12 +174,11 @@ public class ConfigurationFile {
|
|||||||
* Save this configuration file in the given plugin's data folder.
|
* Save this configuration file in the given plugin's data folder.
|
||||||
*
|
*
|
||||||
* @param plugin Plugin.
|
* @param plugin Plugin.
|
||||||
* @throws IOException.
|
|
||||||
*/
|
*/
|
||||||
public void save(JavaPlugin plugin) throws IOException {
|
public void save(JavaPlugin plugin) throws IOException {
|
||||||
|
|
||||||
// If this configuration file can not be copied outside of the jar...
|
// If this configuration file can not be copied outside of the jar...
|
||||||
if(!this.canCopy) {
|
if (!this.canCopy) {
|
||||||
|
|
||||||
// Exit.
|
// Exit.
|
||||||
return;
|
return;
|
||||||
|
@ -37,14 +37,14 @@ public final class InventoryUtils {
|
|||||||
int stock = 0;
|
int stock = 0;
|
||||||
|
|
||||||
// For every itemstack.
|
// For every itemstack.
|
||||||
for(ItemStack content : inventory.getContents()) {
|
for (ItemStack content : inventory.getContents()) {
|
||||||
|
|
||||||
// If content is null, skip.
|
// If content is null, skip.
|
||||||
if(content == null)
|
if (content == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// If itemstacks match.
|
// If itemstacks match.
|
||||||
if(content.isSimilar(itemstack)) {
|
if (content.isSimilar(itemstack)) {
|
||||||
|
|
||||||
// Add amount to stock.
|
// Add amount to stock.
|
||||||
stock += content.getAmount();
|
stock += content.getAmount();
|
||||||
|
@ -15,20 +15,21 @@
|
|||||||
|
|
||||||
package com.gmail.bleedobsidian.itemcase;
|
package com.gmail.bleedobsidian.itemcase;
|
||||||
|
|
||||||
import com.gmail.bleedobsidian.itemcase.loggers.ConsoleLogger;
|
|
||||||
import com.gmail.bleedobsidian.itemcase.loggers.GenericLogger;
|
|
||||||
import com.gmail.bleedobsidian.itemcase.loggers.ChatLogger;
|
|
||||||
import com.gmail.bleedobsidian.itemcase.Itemcase.ItemcaseListener;
|
import com.gmail.bleedobsidian.itemcase.Itemcase.ItemcaseListener;
|
||||||
import com.gmail.bleedobsidian.itemcase.configurations.ConfigFile;
|
import com.gmail.bleedobsidian.itemcase.configurations.ConfigFile;
|
||||||
|
import com.gmail.bleedobsidian.itemcase.loggers.ChatLogger;
|
||||||
|
import com.gmail.bleedobsidian.itemcase.loggers.ConsoleLogger;
|
||||||
|
import com.gmail.bleedobsidian.itemcase.loggers.GenericLogger;
|
||||||
import com.gmail.bleedobsidian.itemcase.managers.ItemcaseManager;
|
import com.gmail.bleedobsidian.itemcase.managers.ItemcaseManager;
|
||||||
import com.gmail.bleedobsidian.itemcase.managers.OrderManager;
|
import com.gmail.bleedobsidian.itemcase.managers.OrderManager;
|
||||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
import java.io.IOException;
|
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ItemCase is a Bukkit plugin allowing you to showcase items on slabs, that
|
* ItemCase is a Bukkit plugin allowing you to showcase items on slabs, that
|
||||||
* can also be used as shops.
|
* can also be used as shops.
|
||||||
@ -104,9 +105,6 @@ public final class ItemCaseCore extends JavaPlugin {
|
|||||||
// Set current instance.
|
// Set current instance.
|
||||||
ItemCaseCore.instance = this;
|
ItemCaseCore.instance = this;
|
||||||
|
|
||||||
// Start metrics.
|
|
||||||
PluginMetrics metrics = new PluginMetrics(this);
|
|
||||||
|
|
||||||
// Attempt to load configuration file.
|
// Attempt to load configuration file.
|
||||||
try {
|
try {
|
||||||
|
|
||||||
@ -123,7 +121,7 @@ public final class ItemCaseCore extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to load translator with given locale.
|
// Attempt to load translator with given locale.
|
||||||
if(!this.translator.load(this, this.configFile.getLocale())) {
|
if (!this.translator.load(this, this.configFile.getLocale())) {
|
||||||
|
|
||||||
// Failed to load, stop loading.
|
// Failed to load, stop loading.
|
||||||
return;
|
return;
|
||||||
@ -178,7 +176,7 @@ public final class ItemCaseCore extends JavaPlugin {
|
|||||||
private void loadVault() {
|
private void loadVault() {
|
||||||
|
|
||||||
// Check if this server has Vault installed.
|
// Check if this server has Vault installed.
|
||||||
if(getServer().getPluginManager().getPlugin("Vault") == null) {
|
if (getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||||
|
|
||||||
// Set false.
|
// Set false.
|
||||||
this.hasVault = false;
|
this.hasVault = false;
|
||||||
@ -192,7 +190,7 @@ public final class ItemCaseCore extends JavaPlugin {
|
|||||||
getServer().getServicesManager().getRegistration(Economy.class);
|
getServer().getServicesManager().getRegistration(Economy.class);
|
||||||
|
|
||||||
// If could not find economy service provider.
|
// If could not find economy service provider.
|
||||||
if(rsp == null) {
|
if (rsp == null) {
|
||||||
|
|
||||||
// Set false.
|
// Set false.
|
||||||
this.hasVault = false;
|
this.hasVault = false;
|
||||||
@ -220,7 +218,7 @@ public final class ItemCaseCore extends JavaPlugin {
|
|||||||
Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
|
Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
|
||||||
|
|
||||||
// Check if the server has WorldGuard installed.
|
// Check if the server has WorldGuard installed.
|
||||||
if(plugin == null) {
|
if (plugin == null) {
|
||||||
|
|
||||||
// Set false.
|
// Set false.
|
||||||
this.hasWorldGuard = false;
|
this.hasWorldGuard = false;
|
||||||
@ -240,7 +238,6 @@ public final class ItemCaseCore extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
* @return Main ItemCase configuration file.
|
* @return Main ItemCase configuration file.
|
||||||
*/
|
*/
|
||||||
public ConfigFile getConfigFile() {
|
public ConfigFile getConfigFile() {
|
||||||
|
@ -16,15 +16,13 @@
|
|||||||
package com.gmail.bleedobsidian.itemcase;
|
package com.gmail.bleedobsidian.itemcase;
|
||||||
|
|
||||||
import com.gmail.bleedobsidian.itemcase.managers.ItemcaseManager;
|
import com.gmail.bleedobsidian.itemcase.managers.ItemcaseManager;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.UUID;
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.Tag;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Item;
|
import org.bukkit.entity.Item;
|
||||||
@ -45,6 +43,10 @@ import org.bukkit.metadata.FixedMetadataValue;
|
|||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler of an Itemcase.
|
* Handler of an Itemcase.
|
||||||
*
|
*
|
||||||
@ -60,17 +62,17 @@ public final class Itemcase {
|
|||||||
/**
|
/**
|
||||||
* Types of Itemcase.
|
* Types of Itemcase.
|
||||||
*/
|
*/
|
||||||
public static enum Type {
|
public enum Type {
|
||||||
SHOWCASE,
|
SHOWCASE,
|
||||||
SHOP_BUY,
|
SHOP_BUY,
|
||||||
SHOP_SELL,
|
SHOP_SELL,
|
||||||
SHOP_MULTI
|
SHOP_MULTI
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Storage types.
|
* Storage types.
|
||||||
*/
|
*/
|
||||||
public static enum StorageType {
|
public enum StorageType {
|
||||||
FINITE,
|
FINITE,
|
||||||
INFINITE
|
INFINITE
|
||||||
}
|
}
|
||||||
@ -108,7 +110,7 @@ public final class Itemcase {
|
|||||||
/**
|
/**
|
||||||
* This itemcase's Type.
|
* This itemcase's Type.
|
||||||
*/
|
*/
|
||||||
private Type type = Type.SHOWCASE;
|
private Type type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The storage type of this itemcase.
|
* The storage type of this itemcase.
|
||||||
@ -176,7 +178,7 @@ public final class Itemcase {
|
|||||||
World world = this.location.getWorld();
|
World world = this.location.getWorld();
|
||||||
|
|
||||||
// If task task was previously cancelled or never made.
|
// If task task was previously cancelled or never made.
|
||||||
if(this.task == null || this.task.isCancelled()) {
|
if (this.task == null || this.task.isCancelled()) {
|
||||||
|
|
||||||
// Schedule itemcase task to execute every 200 server
|
// Schedule itemcase task to execute every 200 server
|
||||||
// ticks (10 secs).
|
// ticks (10 secs).
|
||||||
@ -185,14 +187,14 @@ public final class Itemcase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if the chunk is currently loaded.
|
// Check if the chunk is currently loaded.
|
||||||
if(!world.isChunkLoaded(this.chunk)) {
|
if (!world.isChunkLoaded(this.chunk)) {
|
||||||
|
|
||||||
// Not loaded, so don't try to spawn display item.
|
// Not loaded, so don't try to spawn display item.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there was a display item previously.
|
// If there was a display item previously.
|
||||||
if(this.displayItem != null) {
|
if (this.displayItem != null) {
|
||||||
|
|
||||||
// Remove this item.
|
// Remove this item.
|
||||||
this.displayItem.remove();
|
this.displayItem.remove();
|
||||||
@ -207,7 +209,7 @@ public final class Itemcase {
|
|||||||
// Set display name to random UUID to prevent graphical item stacking.
|
// Set display name to random UUID to prevent graphical item stacking.
|
||||||
ItemMeta metadata = itemStack.getItemMeta();
|
ItemMeta metadata = itemStack.getItemMeta();
|
||||||
metadata.setDisplayName("com.gmail.bleedobsidian.itemcase:" +
|
metadata.setDisplayName("com.gmail.bleedobsidian.itemcase:" +
|
||||||
UUID.randomUUID().toString());
|
UUID.randomUUID());
|
||||||
itemStack.setItemMeta(metadata);
|
itemStack.setItemMeta(metadata);
|
||||||
|
|
||||||
// Spawn the item.
|
// Spawn the item.
|
||||||
@ -245,7 +247,7 @@ public final class Itemcase {
|
|||||||
private static boolean isItemcaseDisplayItem(Item item) {
|
private static boolean isItemcaseDisplayItem(Item item) {
|
||||||
|
|
||||||
// If item does not have a display name, it can't be a display item.
|
// If item does not have a display name, it can't be a display item.
|
||||||
if(!item.getItemStack().getItemMeta().hasDisplayName()) {
|
if (!item.getItemStack().getItemMeta().hasDisplayName()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,7 +257,7 @@ public final class Itemcase {
|
|||||||
|
|
||||||
// If display name does not have exactly two parts, it can't be a
|
// If display name does not have exactly two parts, it can't be a
|
||||||
// display item.
|
// display item.
|
||||||
if(displayNameParts.length != 2) {
|
if (displayNameParts.length != 2) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,7 +273,7 @@ public final class Itemcase {
|
|||||||
public void takeStock(int amount) {
|
public void takeStock(int amount) {
|
||||||
|
|
||||||
// If storage is infinite.
|
// If storage is infinite.
|
||||||
if(this.storageType == StorageType.INFINITE) {
|
if (this.storageType == StorageType.INFINITE) {
|
||||||
|
|
||||||
// Exit.
|
// Exit.
|
||||||
return;
|
return;
|
||||||
@ -296,7 +298,7 @@ public final class Itemcase {
|
|||||||
public void addStock(int amount) {
|
public void addStock(int amount) {
|
||||||
|
|
||||||
// If storage is infinite.
|
// If storage is infinite.
|
||||||
if(this.storageType == StorageType.INFINITE) {
|
if (this.storageType == StorageType.INFINITE) {
|
||||||
|
|
||||||
// Exit.
|
// Exit.
|
||||||
return;
|
return;
|
||||||
@ -320,7 +322,7 @@ public final class Itemcase {
|
|||||||
public boolean hasEnough(int amount) {
|
public boolean hasEnough(int amount) {
|
||||||
|
|
||||||
// If storage is infinite.
|
// If storage is infinite.
|
||||||
if(this.storageType == StorageType.INFINITE) {
|
if (this.storageType == StorageType.INFINITE) {
|
||||||
|
|
||||||
// Return true.
|
// Return true.
|
||||||
return true;
|
return true;
|
||||||
@ -399,7 +401,7 @@ public final class Itemcase {
|
|||||||
public void setStorageType(StorageType storageType) {
|
public void setStorageType(StorageType storageType) {
|
||||||
|
|
||||||
// If toggling from finite to infinite.
|
// If toggling from finite to infinite.
|
||||||
if(this.storageType == StorageType.FINITE &&
|
if (this.storageType == StorageType.FINITE &&
|
||||||
storageType == StorageType.INFINITE) {
|
storageType == StorageType.INFINITE) {
|
||||||
|
|
||||||
// Set storage.
|
// Set storage.
|
||||||
@ -408,7 +410,7 @@ public final class Itemcase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set storage type.
|
// Set storage type.
|
||||||
this.storageType= storageType;
|
this.storageType = storageType;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -457,7 +459,7 @@ public final class Itemcase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param buyPrice Sell price.
|
* @param sellPrice Sell price.
|
||||||
*/
|
*/
|
||||||
public void setSellPrice(double sellPrice) {
|
public void setSellPrice(double sellPrice) {
|
||||||
|
|
||||||
@ -483,13 +485,10 @@ public final class Itemcase {
|
|||||||
Material type = this.location.getBlock().getType();
|
Material type = this.location.getBlock().getType();
|
||||||
|
|
||||||
// The relative Y coordinate.
|
// The relative Y coordinate.
|
||||||
double relY = 0;
|
double relY;
|
||||||
|
|
||||||
// If block is a slab.
|
// If block is a slab.
|
||||||
if(type == Material.STEP ||
|
if (Tag.SLABS.isTagged(type)) {
|
||||||
type == Material.STONE_SLAB2 ||
|
|
||||||
type == Material.WOOD_STEP ||
|
|
||||||
type == Material.PURPUR_SLAB) {
|
|
||||||
|
|
||||||
// Set relY.
|
// Set relY.
|
||||||
relY = 0.6;
|
relY = 0.6;
|
||||||
@ -501,14 +500,13 @@ public final class Itemcase {
|
|||||||
|
|
||||||
// Create a location that is in the centre of the block and slightly
|
// Create a location that is in the centre of the block and slightly
|
||||||
// above.
|
// above.
|
||||||
Location displayItemLocation = new Location(
|
|
||||||
|
// Return the default location to spawn the display item.
|
||||||
|
return new Location(
|
||||||
this.location.getWorld(),
|
this.location.getWorld(),
|
||||||
this.location.getBlockX() + 0.5,
|
this.location.getBlockX() + 0.5,
|
||||||
this.location.getBlockY() + relY,
|
this.location.getBlockY() + relY,
|
||||||
this.location.getBlockZ() + 0.5);
|
this.location.getBlockZ() + 0.5);
|
||||||
|
|
||||||
// Return the default location to spawn the display item.
|
|
||||||
return displayItemLocation;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -521,7 +519,7 @@ public final class Itemcase {
|
|||||||
public void onEntityPickupItem(EntityPickupItemEvent event) {
|
public void onEntityPickupItem(EntityPickupItemEvent event) {
|
||||||
|
|
||||||
// If this item entity is a display item.
|
// If this item entity is a display item.
|
||||||
if(Itemcase.isItemcaseDisplayItem(event.getItem())) {
|
if (Itemcase.isItemcaseDisplayItem(event.getItem())) {
|
||||||
|
|
||||||
// Prevent this item from being picked up.
|
// Prevent this item from being picked up.
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
@ -532,7 +530,7 @@ public final class Itemcase {
|
|||||||
public void onItemDespawn(ItemDespawnEvent event) {
|
public void onItemDespawn(ItemDespawnEvent event) {
|
||||||
|
|
||||||
// If this item entity is a display item.
|
// If this item entity is a display item.
|
||||||
if(Itemcase.isItemcaseDisplayItem(event.getEntity())) {
|
if (Itemcase.isItemcaseDisplayItem(event.getEntity())) {
|
||||||
|
|
||||||
// Prevent this item from despawning.
|
// Prevent this item from despawning.
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
@ -547,10 +545,10 @@ public final class Itemcase {
|
|||||||
ItemCaseCore.instance.getItemcaseManager();
|
ItemCaseCore.instance.getItemcaseManager();
|
||||||
|
|
||||||
// For every Itemcase.
|
// For every Itemcase.
|
||||||
for(Itemcase itemcase : itemcaseManager.getItemcases()) {
|
for (Itemcase itemcase : itemcaseManager.getItemcases()) {
|
||||||
|
|
||||||
// Check if this block was an itemcase.
|
// Check if this block was an itemcase.
|
||||||
if(itemcase.location.equals(event.getBlock().getLocation())) {
|
if (itemcase.location.equals(event.getBlock().getLocation())) {
|
||||||
|
|
||||||
// Cancel the event.
|
// Cancel the event.
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
@ -566,26 +564,23 @@ public final class Itemcase {
|
|||||||
ItemCaseCore.instance.getItemcaseManager();
|
ItemCaseCore.instance.getItemcaseManager();
|
||||||
|
|
||||||
// For every Itemcase.
|
// For every Itemcase.
|
||||||
for(Itemcase itemcase : itemcaseManager.getItemcases()) {
|
for (Itemcase itemcase : itemcaseManager.getItemcases()) {
|
||||||
|
|
||||||
// Get block type.
|
// Get block type.
|
||||||
Material type = itemcase.getLocation().getBlock().getType();
|
Material type = itemcase.getLocation().getBlock().getType();
|
||||||
|
|
||||||
// Check if the block placed was on an itemcase.
|
// Check if the block placed was on an itemcase.
|
||||||
if(itemcase.location.equals(event.getBlock().getLocation())) {
|
if (itemcase.location.equals(event.getBlock().getLocation())) {
|
||||||
|
|
||||||
// Cancel the event.
|
// Cancel the event.
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If not a slab.
|
// If not a slab.
|
||||||
if(type != Material.STEP &&
|
if (Tag.SLABS.isTagged(type)) {
|
||||||
type != Material.WOOD_STEP &&
|
|
||||||
type != Material.STONE_SLAB2 &&
|
|
||||||
type != Material.PURPUR_SLAB) {
|
|
||||||
|
|
||||||
// Check if the block placed was 1 above an itemcase.
|
// Check if the block placed was 1 above an itemcase.
|
||||||
if(itemcase.location.clone().add(0, 1, 0)
|
if (itemcase.location.clone().add(0, 1, 0)
|
||||||
.equals(event.getBlock().getLocation())) {
|
.equals(event.getBlock().getLocation())) {
|
||||||
|
|
||||||
// Cancel the event.
|
// Cancel the event.
|
||||||
@ -599,35 +594,35 @@ public final class Itemcase {
|
|||||||
public void onPlayerInteractEvent(PlayerInteractEvent event) {
|
public void onPlayerInteractEvent(PlayerInteractEvent event) {
|
||||||
|
|
||||||
// Check if block was involved.
|
// Check if block was involved.
|
||||||
if(!event.hasBlock()) {
|
if (!event.hasBlock()) {
|
||||||
|
|
||||||
// Exit.
|
// Exit.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if action was correct.
|
// Check if action was correct.
|
||||||
if(event.getAction() != Action.RIGHT_CLICK_BLOCK) {
|
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
|
||||||
|
|
||||||
// Exit.
|
// Exit.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If off-hand, skip.
|
// If off-hand, skip.
|
||||||
if(event.getHand() == EquipmentSlot.OFF_HAND) {
|
if (event.getHand() == EquipmentSlot.OFF_HAND) {
|
||||||
|
|
||||||
// Exit.
|
// Exit.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If player is sneaking.
|
// If player is sneaking.
|
||||||
if(event.getPlayer().isSneaking()) {
|
if (event.getPlayer().isSneaking()) {
|
||||||
|
|
||||||
// Exit.
|
// Exit.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If block is not an ItemCase.
|
// If block is not an ItemCase.
|
||||||
if(!ItemCaseCore.instance.getItemcaseManager().isItemcase(
|
if (!ItemCaseCore.instance.getItemcaseManager().isItemcase(
|
||||||
event.getClickedBlock().getLocation())) {
|
event.getClickedBlock().getLocation())) {
|
||||||
|
|
||||||
// Exit.
|
// Exit.
|
||||||
@ -639,7 +634,7 @@ public final class Itemcase {
|
|||||||
.getItemcase(event.getClickedBlock().getLocation());
|
.getItemcase(event.getClickedBlock().getLocation());
|
||||||
|
|
||||||
// If itemcase is not a shop.
|
// If itemcase is not a shop.
|
||||||
if(itemcase.getType() == Type.SHOWCASE) {
|
if (itemcase.getType() == Type.SHOWCASE) {
|
||||||
|
|
||||||
// Exit.
|
// Exit.
|
||||||
return;
|
return;
|
||||||
@ -660,7 +655,7 @@ public final class Itemcase {
|
|||||||
* is particularly useful when servers use anti-lag plugins that forcibly
|
* is particularly useful when servers use anti-lag plugins that forcibly
|
||||||
* kill entities or a player has somehow caused an item to move.
|
* kill entities or a player has somehow caused an item to move.
|
||||||
*/
|
*/
|
||||||
public final class ItemcaseTask extends BukkitRunnable {
|
public static final class ItemcaseTask extends BukkitRunnable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The itemcase that this task is for.
|
* The itemcase that this task is for.
|
||||||
@ -682,7 +677,7 @@ public final class Itemcase {
|
|||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
// If chunk is not currently loaded.
|
// If chunk is not currently loaded.
|
||||||
if(!this.itemcase.chunk.isLoaded()) {
|
if (!this.itemcase.chunk.isLoaded()) {
|
||||||
|
|
||||||
// Dont bother running this task.
|
// Dont bother running this task.
|
||||||
return;
|
return;
|
||||||
@ -696,7 +691,7 @@ public final class Itemcase {
|
|||||||
ItemCaseCore.instance.getConfigFile().getMaterials();
|
ItemCaseCore.instance.getConfigFile().getMaterials();
|
||||||
|
|
||||||
// Check if this block still exists.
|
// Check if this block still exists.
|
||||||
if(!materials.contains(location.getBlock().getType())) {
|
if (!materials.contains(location.getBlock().getType())) {
|
||||||
|
|
||||||
// Set to default.
|
// Set to default.
|
||||||
location.getBlock().setType(materials.get(0));
|
location.getBlock().setType(materials.get(0));
|
||||||
@ -711,23 +706,22 @@ public final class Itemcase {
|
|||||||
int numberOfItemcaseItems = 0;
|
int numberOfItemcaseItems = 0;
|
||||||
|
|
||||||
// Loop through every entity.
|
// Loop through every entity.
|
||||||
for(Entity entity : entities) {
|
for (Entity entity : entities) {
|
||||||
|
|
||||||
// If the entity is not an item, skip.
|
// If the entity is not an item, skip.
|
||||||
if(!(entity instanceof Item)) {
|
if (!(entity instanceof Item)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the entity is an ItemCase display item.
|
// Check the entity is an ItemCase display item.
|
||||||
if(entity.hasMetadata("ItemCase")) {
|
if (entity.hasMetadata("ItemCase")) {
|
||||||
|
|
||||||
// Get the vector location that belongs to this itemcase
|
// Get the vector location that belongs to this itemcase
|
||||||
// item.
|
// item.
|
||||||
Vector entityVector = (Vector) ((FixedMetadataValue)
|
Vector entityVector = (Vector) entity.getMetadata("ItemCase").get(0).value();
|
||||||
entity.getMetadata("ItemCase").get(0)).value();
|
|
||||||
|
|
||||||
// Check that the entity is an item for this itemcase only.
|
// Check that the entity is an item for this itemcase only.
|
||||||
if(entityVector.getBlockX() !=
|
if (entityVector.getBlockX() !=
|
||||||
this.itemcase.location.getBlockX() ||
|
this.itemcase.location.getBlockX() ||
|
||||||
entityVector.getBlockY() !=
|
entityVector.getBlockY() !=
|
||||||
this.itemcase.location.getBlockY() ||
|
this.itemcase.location.getBlockY() ||
|
||||||
@ -743,7 +737,7 @@ public final class Itemcase {
|
|||||||
|
|
||||||
// If the entity is not the current item we know about, we
|
// If the entity is not the current item we know about, we
|
||||||
// must have a duplicate caused by nms.
|
// must have a duplicate caused by nms.
|
||||||
if(this.itemcase.getDisplayItem().getUniqueId().compareTo(
|
if (this.itemcase.getDisplayItem().getUniqueId().compareTo(
|
||||||
entity.getUniqueId()) != 0) {
|
entity.getUniqueId()) != 0) {
|
||||||
|
|
||||||
// Remove this item.
|
// Remove this item.
|
||||||
@ -756,7 +750,7 @@ public final class Itemcase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the item has no metadata but is some form of display item.
|
// If the item has no metadata but is some form of display item.
|
||||||
} else if(Itemcase.isItemcaseDisplayItem((Item) entity)) {
|
} else if (Itemcase.isItemcaseDisplayItem((Item) entity)) {
|
||||||
|
|
||||||
// Remove this item as it is probably left over from a
|
// Remove this item as it is probably left over from a
|
||||||
// restart hence no metadata.
|
// restart hence no metadata.
|
||||||
@ -765,7 +759,7 @@ public final class Itemcase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If there were no itemcase items nearby.
|
// If there were no itemcase items nearby.
|
||||||
if(numberOfItemcaseItems == 0) {
|
if (numberOfItemcaseItems == 0) {
|
||||||
|
|
||||||
// Spawn a new item as for some reason the item has despawned
|
// Spawn a new item as for some reason the item has despawned
|
||||||
// (usually because of anti-lag plugins.)
|
// (usually because of anti-lag plugins.)
|
||||||
@ -782,7 +776,7 @@ public final class Itemcase {
|
|||||||
this.itemcase.getDisplayItemSpawnLocation();
|
this.itemcase.getDisplayItemSpawnLocation();
|
||||||
|
|
||||||
// Check if the display item has for some reason moved.
|
// Check if the display item has for some reason moved.
|
||||||
if(x != displayItemSpawnLocation.getX() ||
|
if (x != displayItemSpawnLocation.getX() ||
|
||||||
y != displayItemSpawnLocation.getBlockY() ||
|
y != displayItemSpawnLocation.getBlockY() ||
|
||||||
z != displayItemSpawnLocation.getZ()) {
|
z != displayItemSpawnLocation.getZ()) {
|
||||||
|
|
||||||
|
@ -15,10 +15,11 @@
|
|||||||
package com.gmail.bleedobsidian.itemcase;
|
package com.gmail.bleedobsidian.itemcase;
|
||||||
|
|
||||||
import com.gmail.bleedobsidian.itemcase.configurations.LanguageFile;
|
import com.gmail.bleedobsidian.itemcase.configurations.LanguageFile;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class used for communicating in different dialects.
|
* Utility class used for communicating in different dialects.
|
||||||
@ -30,9 +31,9 @@ public final class LanguageTranslator {
|
|||||||
/**
|
/**
|
||||||
* Supported languages.
|
* Supported languages.
|
||||||
*/
|
*/
|
||||||
public static enum Language {
|
public enum Language {
|
||||||
EN
|
EN
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The language file for the chosen language.
|
* The language file for the chosen language.
|
||||||
@ -42,7 +43,7 @@ public final class LanguageTranslator {
|
|||||||
/**
|
/**
|
||||||
* A hash map of placeholders.
|
* A hash map of placeholders.
|
||||||
*/
|
*/
|
||||||
private HashMap<String, String> placeholders = new HashMap<>();
|
private final HashMap<String, String> placeholders = new HashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load corresponding language file.
|
* Load corresponding language file.
|
||||||
@ -88,7 +89,7 @@ public final class LanguageTranslator {
|
|||||||
String translation = this.file.getRawTranslation(key);
|
String translation = this.file.getRawTranslation(key);
|
||||||
|
|
||||||
// For every placeholder.
|
// For every placeholder.
|
||||||
for(Entry<String, String> entry : this.placeholders.entrySet()) {
|
for (Entry<String, String> entry : this.placeholders.entrySet()) {
|
||||||
|
|
||||||
// Replace the placeholder with given value if placeholder is
|
// Replace the placeholder with given value if placeholder is
|
||||||
// present in string.
|
// present in string.
|
||||||
@ -120,7 +121,7 @@ public final class LanguageTranslator {
|
|||||||
public boolean isKey(String string) {
|
public boolean isKey(String string) {
|
||||||
|
|
||||||
// If the file is not loaded yet.
|
// If the file is not loaded yet.
|
||||||
if(!this.file.isLoaded()) {
|
if (!this.file.isLoaded()) {
|
||||||
|
|
||||||
// Return false as we cant do translations yet.
|
// Return false as we cant do translations yet.
|
||||||
return false;
|
return false;
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
/*
|
|
||||||
* ItemCase is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/gpl.html>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.gmail.bleedobsidian.itemcase;
|
|
||||||
|
|
||||||
import org.bstats.bukkit.Metrics;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles bStats plugin metrics and any custom graphs.
|
|
||||||
*
|
|
||||||
* @author Jesse Prescott (BleedObsidian)
|
|
||||||
*/
|
|
||||||
public final class PluginMetrics {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor, starts bStats.
|
|
||||||
*
|
|
||||||
* @param plugin The Bukkit JavaPlugin.
|
|
||||||
*/
|
|
||||||
public PluginMetrics(JavaPlugin plugin) {
|
|
||||||
|
|
||||||
// Start bStats.
|
|
||||||
Metrics metrics = new Metrics(plugin);
|
|
||||||
}
|
|
||||||
}
|
|
@ -15,17 +15,19 @@
|
|||||||
package com.gmail.bleedobsidian.itemcase.commands;
|
package com.gmail.bleedobsidian.itemcase.commands;
|
||||||
|
|
||||||
import com.gmail.bleedobsidian.itemcase.Command;
|
import com.gmail.bleedobsidian.itemcase.Command;
|
||||||
import com.gmail.bleedobsidian.itemcase.loggers.ChatLogger;
|
|
||||||
import com.gmail.bleedobsidian.itemcase.ItemCaseCore;
|
import com.gmail.bleedobsidian.itemcase.ItemCaseCore;
|
||||||
import com.gmail.bleedobsidian.itemcase.LanguageTranslator;
|
import com.gmail.bleedobsidian.itemcase.LanguageTranslator;
|
||||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
import com.gmail.bleedobsidian.itemcase.loggers.ChatLogger;
|
||||||
import java.util.ArrayList;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A command handler for the 'create' command.
|
* A command handler for the 'create' command.
|
||||||
*
|
*
|
||||||
@ -38,7 +40,7 @@ public final class CreateCommand implements Command {
|
|||||||
String[] args) {
|
String[] args) {
|
||||||
|
|
||||||
// If sender is not a player.
|
// If sender is not a player.
|
||||||
if(!(sender instanceof Player)) {
|
if (!(sender instanceof Player player)) {
|
||||||
|
|
||||||
// Send message.
|
// Send message.
|
||||||
ItemCaseCore.instance.getGenericLogger().message(
|
ItemCaseCore.instance.getGenericLogger().message(
|
||||||
@ -49,10 +51,9 @@ public final class CreateCommand implements Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Cast sender to player.
|
// Cast sender to player.
|
||||||
Player player = (Player) sender;
|
|
||||||
|
|
||||||
// Check if player is asking for help.
|
// Check if player is asking for help.
|
||||||
if(this.isAskingForHelp(player, label, args)) {
|
if (this.isAskingForHelp(player, label, args)) {
|
||||||
|
|
||||||
// Exit.
|
// Exit.
|
||||||
return;
|
return;
|
||||||
@ -62,7 +63,7 @@ public final class CreateCommand implements Command {
|
|||||||
ChatLogger chatLogger = ItemCaseCore.instance.getChatLogger();
|
ChatLogger chatLogger = ItemCaseCore.instance.getChatLogger();
|
||||||
|
|
||||||
// Check if player has permission.
|
// Check if player has permission.
|
||||||
if(!player.hasPermission("itemcase.create")) {
|
if (!player.hasPermission("itemcase.create")) {
|
||||||
|
|
||||||
// Send message.
|
// Send message.
|
||||||
chatLogger.message(player, "command.permission");
|
chatLogger.message(player, "command.permission");
|
||||||
@ -76,16 +77,16 @@ public final class CreateCommand implements Command {
|
|||||||
ItemCaseCore.instance.getConfigFile().getMaterials();
|
ItemCaseCore.instance.getConfigFile().getMaterials();
|
||||||
|
|
||||||
// The target location.
|
// The target location.
|
||||||
Location target = null;
|
Location target;
|
||||||
|
|
||||||
// ItemStack to use.
|
// ItemStack to use.
|
||||||
ItemStack itemStack = null;
|
ItemStack itemStack;
|
||||||
|
|
||||||
// Get the players target block.
|
// Get the players target block.
|
||||||
target = player.getTargetBlock(null, 5).getLocation();
|
target = player.getTargetBlock(null, 5).getLocation();
|
||||||
|
|
||||||
// Check if itemcase already exists here.
|
// Check if itemcase already exists here.
|
||||||
if(ItemCaseCore.instance.getItemcaseManager().isItemcase(target)) {
|
if (ItemCaseCore.instance.getItemcaseManager().isItemcase(target)) {
|
||||||
|
|
||||||
// Show message.
|
// Show message.
|
||||||
chatLogger.message(player, "command.create.invalid-location");
|
chatLogger.message(player, "command.create.invalid-location");
|
||||||
@ -95,7 +96,9 @@ public final class CreateCommand implements Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If target block is not on the list of accepted materials.
|
// If target block is not on the list of accepted materials.
|
||||||
if(!materials.contains(target.getBlock().getType())) {
|
if (!materials.contains(target.getBlock().getType())) {
|
||||||
|
chatLogger.message(player, String.valueOf(materials));
|
||||||
|
chatLogger.message(player, String.valueOf(target.getBlock()));
|
||||||
|
|
||||||
// Show message.
|
// Show message.
|
||||||
chatLogger.message(player, "command.create.invalid-type");
|
chatLogger.message(player, "command.create.invalid-type");
|
||||||
@ -104,28 +107,20 @@ public final class CreateCommand implements Command {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this server has WorldGuard.
|
|
||||||
if(ItemCaseCore.instance.hasWorldGuard()) {
|
|
||||||
|
|
||||||
// Get world guard.
|
|
||||||
WorldGuardPlugin worldGuard = ItemCaseCore.instance.getWorldGuard();
|
|
||||||
|
|
||||||
// If player cannot build here.
|
|
||||||
if(!worldGuard.canBuild(player, target)) {
|
|
||||||
|
|
||||||
// Show message.
|
|
||||||
chatLogger.message(player, "command.create.no-build");
|
|
||||||
|
|
||||||
// Exit.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get item in players main hand to use as the Itemcase item.
|
// Get item in players main hand to use as the Itemcase item.
|
||||||
itemStack = player.getInventory().getItemInMainHand();
|
itemStack = player.getInventory().getItemInMainHand();
|
||||||
|
|
||||||
|
//Allow any protection plugins to protect
|
||||||
|
BlockPlaceEvent event = new BlockPlaceEvent(target.getBlock(), target.getBlock().getState(),
|
||||||
|
target.getBlock(), itemStack, player, true, EquipmentSlot.HAND);
|
||||||
|
ItemCaseCore.instance.getServer().getPluginManager().callEvent(event);
|
||||||
|
if (event.isCancelled() || !event.canBuild()) {
|
||||||
|
chatLogger.message(player, "command.create.no-build");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// If the player is not holding anything...
|
// If the player is not holding anything...
|
||||||
if(itemStack == null || itemStack.getType() == Material.AIR) {
|
if (itemStack.getType() == Material.AIR) {
|
||||||
|
|
||||||
// Show message.
|
// Show message.
|
||||||
chatLogger.message(player, "command.create.main-hand");
|
chatLogger.message(player, "command.create.main-hand");
|
||||||
@ -148,7 +143,7 @@ public final class CreateCommand implements Command {
|
|||||||
public boolean isAskingForHelp(Player player, String label, String[] args) {
|
public boolean isAskingForHelp(Player player, String label, String[] args) {
|
||||||
|
|
||||||
// If args length equals 2.
|
// If args length equals 2.
|
||||||
if(args.length != 2) {
|
if (args.length != 2) {
|
||||||
|
|
||||||
// False.
|
// False.
|
||||||
return false;
|
return false;
|
||||||
@ -158,7 +153,7 @@ public final class CreateCommand implements Command {
|
|||||||
String argument = args[1];
|
String argument = args[1];
|
||||||
|
|
||||||
// If not equal to help.
|
// If not equal to help.
|
||||||
if(!argument.equalsIgnoreCase("help")) {
|
if (!argument.equalsIgnoreCase("help")) {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -15,10 +15,10 @@
|
|||||||
package com.gmail.bleedobsidian.itemcase.commands;
|
package com.gmail.bleedobsidian.itemcase.commands;
|
||||||
|
|
||||||
import com.gmail.bleedobsidian.itemcase.Command;
|
import com.gmail.bleedobsidian.itemcase.Command;
|
||||||
import com.gmail.bleedobsidian.itemcase.loggers.ChatLogger;
|
|
||||||
import com.gmail.bleedobsidian.itemcase.ItemCaseCore;
|
import com.gmail.bleedobsidian.itemcase.ItemCaseCore;
|
||||||
import com.gmail.bleedobsidian.itemcase.Itemcase;
|
import com.gmail.bleedobsidian.itemcase.Itemcase;
|
||||||
import com.gmail.bleedobsidian.itemcase.LanguageTranslator;
|
import com.gmail.bleedobsidian.itemcase.LanguageTranslator;
|
||||||
|
import com.gmail.bleedobsidian.itemcase.loggers.ChatLogger;
|
||||||
import com.gmail.bleedobsidian.itemcase.managers.ItemcaseManager;
|
import com.gmail.bleedobsidian.itemcase.managers.ItemcaseManager;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
@ -37,7 +37,7 @@ public final class DestroyCommand implements Command {
|
|||||||
String[] args) {
|
String[] args) {
|
||||||
|
|
||||||
// If sender is not a player.
|
// If sender is not a player.
|
||||||
if(!(sender instanceof Player)) {
|
if (!(sender instanceof Player player)) {
|
||||||
|
|
||||||
// Send message.
|
// Send message.
|
||||||
ItemCaseCore.instance.getGenericLogger().message(
|
ItemCaseCore.instance.getGenericLogger().message(
|
||||||
@ -48,10 +48,9 @@ public final class DestroyCommand implements Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Cast sender to player.
|
// Cast sender to player.
|
||||||
Player player = (Player) sender;
|
|
||||||
|
|
||||||
// Check if player is asking for help.
|
// Check if player is asking for help.
|
||||||
if(this.isAskingForHelp(player, label, args)) {
|
if (this.isAskingForHelp(player, label, args)) {
|
||||||
|
|
||||||
// Exit.
|
// Exit.
|
||||||
return;
|
return;
|
||||||
@ -61,7 +60,7 @@ public final class DestroyCommand implements Command {
|
|||||||
ChatLogger chatLogger = ItemCaseCore.instance.getChatLogger();
|
ChatLogger chatLogger = ItemCaseCore.instance.getChatLogger();
|
||||||
|
|
||||||
// Check if player has permission (Uses create permission).
|
// Check if player has permission (Uses create permission).
|
||||||
if(!player.hasPermission("itemcase.create")) {
|
if (!player.hasPermission("itemcase.create")) {
|
||||||
|
|
||||||
// Send message.
|
// Send message.
|
||||||
chatLogger.message(player, "command.permission");
|
chatLogger.message(player, "command.permission");
|
||||||
@ -71,7 +70,7 @@ public final class DestroyCommand implements Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The target location.
|
// The target location.
|
||||||
Location target = null;
|
Location target;
|
||||||
|
|
||||||
// Get ItemcaseManager.
|
// Get ItemcaseManager.
|
||||||
ItemcaseManager manager = ItemCaseCore.instance.getItemcaseManager();
|
ItemcaseManager manager = ItemCaseCore.instance.getItemcaseManager();
|
||||||
@ -80,7 +79,7 @@ public final class DestroyCommand implements Command {
|
|||||||
target = player.getTargetBlock(null, 5).getLocation();
|
target = player.getTargetBlock(null, 5).getLocation();
|
||||||
|
|
||||||
// Check this target is an itemcase.
|
// Check this target is an itemcase.
|
||||||
if(!manager.isItemcase(target)) {
|
if (!manager.isItemcase(target)) {
|
||||||
|
|
||||||
// Show message.
|
// Show message.
|
||||||
chatLogger.message(player, "command.invalid-location");
|
chatLogger.message(player, "command.invalid-location");
|
||||||
@ -96,10 +95,10 @@ public final class DestroyCommand implements Command {
|
|||||||
OfflinePlayer owner = itemcase.getOwner();
|
OfflinePlayer owner = itemcase.getOwner();
|
||||||
|
|
||||||
// Check if this player owns this itemcase.
|
// Check if this player owns this itemcase.
|
||||||
if(!owner.equals(player)) {
|
if (!owner.equals(player)) {
|
||||||
|
|
||||||
// Check if player is allowed to destroy other peoples itemcases.
|
// Check if player is allowed to destroy other peoples itemcases.
|
||||||
if(!player.hasPermission("itemcase.destroy.other")) {
|
if (!player.hasPermission("itemcase.destroy.other")) {
|
||||||
|
|
||||||
// Show message.
|
// Show message.
|
||||||
chatLogger.message(player, "command.not-owner");
|
chatLogger.message(player, "command.not-owner");
|
||||||
@ -122,7 +121,7 @@ public final class DestroyCommand implements Command {
|
|||||||
public boolean isAskingForHelp(Player player, String label, String[] args) {
|
public boolean isAskingForHelp(Player player, String label, String[] args) {
|
||||||
|
|
||||||
// If args length equals 2.
|
// If args length equals 2.
|
||||||
if(args.length != 2) {
|
if (args.length != 2) {
|
||||||
|
|
||||||
// False.
|
// False.
|
||||||
return false;
|
return false;
|
||||||
@ -132,7 +131,7 @@ public final class DestroyCommand implements Command {
|
|||||||
String argument = args[1];
|
String argument = args[1];
|
||||||
|
|
||||||
// If not equal to help.
|
// If not equal to help.
|
||||||
if(!argument.equalsIgnoreCase("help")) {
|
if (!argument.equalsIgnoreCase("help")) {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -15,12 +15,12 @@
|
|||||||
package com.gmail.bleedobsidian.itemcase.commands;
|
package com.gmail.bleedobsidian.itemcase.commands;
|
||||||
|
|
||||||
import com.gmail.bleedobsidian.itemcase.Command;
|
import com.gmail.bleedobsidian.itemcase.Command;
|
||||||
import com.gmail.bleedobsidian.itemcase.loggers.ChatLogger;
|
|
||||||
import com.gmail.bleedobsidian.itemcase.ItemCaseCore;
|
import com.gmail.bleedobsidian.itemcase.ItemCaseCore;
|
||||||
import com.gmail.bleedobsidian.itemcase.Itemcase;
|
import com.gmail.bleedobsidian.itemcase.Itemcase;
|
||||||
import com.gmail.bleedobsidian.itemcase.Itemcase.StorageType;
|
import com.gmail.bleedobsidian.itemcase.Itemcase.StorageType;
|
||||||
import com.gmail.bleedobsidian.itemcase.Itemcase.Type;
|
import com.gmail.bleedobsidian.itemcase.Itemcase.Type;
|
||||||
import com.gmail.bleedobsidian.itemcase.LanguageTranslator;
|
import com.gmail.bleedobsidian.itemcase.LanguageTranslator;
|
||||||
|
import com.gmail.bleedobsidian.itemcase.loggers.ChatLogger;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
@ -39,7 +39,7 @@ public final class ModifyCommand implements Command {
|
|||||||
String[] args) {
|
String[] args) {
|
||||||
|
|
||||||
// If sender is not a player.
|
// If sender is not a player.
|
||||||
if(!(sender instanceof Player)) {
|
if (!(sender instanceof Player player)) {
|
||||||
|
|
||||||
// Send message.
|
// Send message.
|
||||||
ItemCaseCore.instance.getGenericLogger().message(
|
ItemCaseCore.instance.getGenericLogger().message(
|
||||||
@ -50,17 +50,16 @@ public final class ModifyCommand implements Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Cast sender to player.
|
// Cast sender to player.
|
||||||
Player player = (Player) sender;
|
|
||||||
|
|
||||||
// Check if player is asking for help.
|
// Check if player is asking for help.
|
||||||
if(this.isAskingForHelp(player, label, args)) {
|
if (this.isAskingForHelp(player, label, args)) {
|
||||||
|
|
||||||
// Exit.
|
// Exit.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If incorrect number of args.
|
// If incorrect number of args.
|
||||||
if(args.length != 3) {
|
if (args.length != 3) {
|
||||||
|
|
||||||
// Show help.
|
// Show help.
|
||||||
this.showHelp(player, label);
|
this.showHelp(player, label);
|
||||||
@ -73,7 +72,7 @@ public final class ModifyCommand implements Command {
|
|||||||
ChatLogger chatLogger = ItemCaseCore.instance.getChatLogger();
|
ChatLogger chatLogger = ItemCaseCore.instance.getChatLogger();
|
||||||
|
|
||||||
// Check if player has permission (Uses create permission).
|
// Check if player has permission (Uses create permission).
|
||||||
if(!player.hasPermission("itemcase.create")) {
|
if (!player.hasPermission("itemcase.create")) {
|
||||||
|
|
||||||
// Send message.
|
// Send message.
|
||||||
chatLogger.message(player, "command.permission");
|
chatLogger.message(player, "command.permission");
|
||||||
@ -83,13 +82,13 @@ public final class ModifyCommand implements Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The target location.
|
// The target location.
|
||||||
Location target = null;
|
Location target;
|
||||||
|
|
||||||
// Get the players target block.
|
// Get the players target block.
|
||||||
target = player.getTargetBlock(null, 5).getLocation();
|
target = player.getTargetBlock(null, 5).getLocation();
|
||||||
|
|
||||||
// Check if itemcase exists here.
|
// Check if itemcase exists here.
|
||||||
if(!ItemCaseCore.instance.getItemcaseManager().isItemcase(target)) {
|
if (!ItemCaseCore.instance.getItemcaseManager().isItemcase(target)) {
|
||||||
|
|
||||||
// Show message.
|
// Show message.
|
||||||
chatLogger.message(player, "command.invalid-location");
|
chatLogger.message(player, "command.invalid-location");
|
||||||
@ -106,10 +105,10 @@ public final class ModifyCommand implements Command {
|
|||||||
OfflinePlayer owner = itemcase.getOwner();
|
OfflinePlayer owner = itemcase.getOwner();
|
||||||
|
|
||||||
// Check if this player owns this itemcase.
|
// Check if this player owns this itemcase.
|
||||||
if(!owner.equals(player)) {
|
if (!owner.equals(player)) {
|
||||||
|
|
||||||
// Check if player is allowed to modify other peoples itemcases.
|
// Check if player is allowed to modify other peoples itemcases.
|
||||||
if(!player.hasPermission("itemcase.modify.other")) {
|
if (!player.hasPermission("itemcase.modify.other")) {
|
||||||
|
|
||||||
// Show message.
|
// Show message.
|
||||||
chatLogger.message(player, "command.not-owner");
|
chatLogger.message(player, "command.not-owner");
|
||||||
@ -126,7 +125,7 @@ public final class ModifyCommand implements Command {
|
|||||||
String value = args[2];
|
String value = args[2];
|
||||||
|
|
||||||
// Switch flag.
|
// Switch flag.
|
||||||
switch(flag.toLowerCase()) {
|
switch (flag.toLowerCase()) {
|
||||||
case "type":
|
case "type":
|
||||||
this.typeFlag(label, player, itemcase, value);
|
this.typeFlag(label, player, itemcase, value);
|
||||||
break;
|
break;
|
||||||
@ -163,20 +162,13 @@ public final class ModifyCommand implements Command {
|
|||||||
ChatLogger chatLogger = ItemCaseCore.instance.getChatLogger();
|
ChatLogger chatLogger = ItemCaseCore.instance.getChatLogger();
|
||||||
|
|
||||||
// If the itemcase was a shop.
|
// If the itemcase was a shop.
|
||||||
boolean wasShop = false;
|
boolean wasShop = itemcase.getType() != Type.SHOWCASE;
|
||||||
|
|
||||||
// If the itemcase was a shop.
|
|
||||||
if(itemcase.getType() != Type.SHOWCASE) {
|
|
||||||
|
|
||||||
// Set boolean.
|
|
||||||
wasShop = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the itemcase is now a shop.
|
// If the itemcase is now a shop.
|
||||||
boolean isNowShop = false;
|
boolean isNowShop = false;
|
||||||
|
|
||||||
// Switch value.
|
// Switch value.
|
||||||
switch(value.toLowerCase()) {
|
switch (value.toLowerCase()) {
|
||||||
|
|
||||||
// Showcase.
|
// Showcase.
|
||||||
case "showcase":
|
case "showcase":
|
||||||
@ -191,7 +183,7 @@ public final class ModifyCommand implements Command {
|
|||||||
case "shop_buy":
|
case "shop_buy":
|
||||||
|
|
||||||
// Check if player has permission.
|
// Check if player has permission.
|
||||||
if(!player.hasPermission("itemcase.create.shop.buy")) {
|
if (!player.hasPermission("itemcase.create.shop.buy")) {
|
||||||
|
|
||||||
// Send message.
|
// Send message.
|
||||||
chatLogger.message(player, "command.permission");
|
chatLogger.message(player, "command.permission");
|
||||||
@ -213,7 +205,7 @@ public final class ModifyCommand implements Command {
|
|||||||
case "shop_sell":
|
case "shop_sell":
|
||||||
|
|
||||||
// Check if player has permission.
|
// Check if player has permission.
|
||||||
if(!player.hasPermission("itemcase.create.shop.sell")) {
|
if (!player.hasPermission("itemcase.create.shop.sell")) {
|
||||||
|
|
||||||
// Send message.
|
// Send message.
|
||||||
chatLogger.message(player, "command.permission");
|
chatLogger.message(player, "command.permission");
|
||||||
@ -235,7 +227,7 @@ public final class ModifyCommand implements Command {
|
|||||||
case "shop_multi":
|
case "shop_multi":
|
||||||
|
|
||||||
// Check if player has permission.
|
// Check if player has permission.
|
||||||
if(!player.hasPermission("itemcase.create.shop.buy") ||
|
if (!player.hasPermission("itemcase.create.shop.buy") ||
|
||||||
!player.hasPermission("itemcase.create.shop.sell")) {
|
!player.hasPermission("itemcase.create.shop.sell")) {
|
||||||
|
|
||||||
// Send message.
|
// Send message.
|
||||||
@ -265,7 +257,7 @@ public final class ModifyCommand implements Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If itemcase is now a shop but wasn't before.
|
// If itemcase is now a shop but wasn't before.
|
||||||
if(isNowShop && !wasShop) {
|
if (isNowShop && !wasShop) {
|
||||||
|
|
||||||
// Set storage.
|
// Set storage.
|
||||||
itemcase.setStorage(Bukkit.createInventory(
|
itemcase.setStorage(Bukkit.createInventory(
|
||||||
@ -294,7 +286,7 @@ public final class ModifyCommand implements Command {
|
|||||||
ChatLogger chatLogger = ItemCaseCore.instance.getChatLogger();
|
ChatLogger chatLogger = ItemCaseCore.instance.getChatLogger();
|
||||||
|
|
||||||
// If itemcase is not a shop.
|
// If itemcase is not a shop.
|
||||||
if(itemcase.getType() == Type.SHOWCASE) {
|
if (itemcase.getType() == Type.SHOWCASE) {
|
||||||
|
|
||||||
// Show message.
|
// Show message.
|
||||||
chatLogger.message(player, "command.not-shop");
|
chatLogger.message(player, "command.not-shop");
|
||||||
@ -304,7 +296,7 @@ public final class ModifyCommand implements Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Switch value.
|
// Switch value.
|
||||||
switch(value.toLowerCase()) {
|
switch (value.toLowerCase()) {
|
||||||
|
|
||||||
// Finite.
|
// Finite.
|
||||||
case "finite":
|
case "finite":
|
||||||
@ -319,7 +311,7 @@ public final class ModifyCommand implements Command {
|
|||||||
case "infinite":
|
case "infinite":
|
||||||
|
|
||||||
// Check if player has permission.
|
// Check if player has permission.
|
||||||
if(!player.hasPermission("itemcase.create.shop.infinite")) {
|
if (!player.hasPermission("itemcase.create.shop.infinite")) {
|
||||||
|
|
||||||
// Send message.
|
// Send message.
|
||||||
chatLogger.message(player, "command.permission");
|
chatLogger.message(player, "command.permission");
|
||||||
@ -366,7 +358,7 @@ public final class ModifyCommand implements Command {
|
|||||||
ChatLogger chatLogger = ItemCaseCore.instance.getChatLogger();
|
ChatLogger chatLogger = ItemCaseCore.instance.getChatLogger();
|
||||||
|
|
||||||
// Check if player has permission.
|
// Check if player has permission.
|
||||||
if(!player.hasPermission("itemcase.create.shop.buy")) {
|
if (!player.hasPermission("itemcase.create.shop.buy")) {
|
||||||
|
|
||||||
// Send message.
|
// Send message.
|
||||||
chatLogger.message(player, "command.permission");
|
chatLogger.message(player, "command.permission");
|
||||||
@ -376,7 +368,7 @@ public final class ModifyCommand implements Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If itemcase is not a shop.
|
// If itemcase is not a shop.
|
||||||
if(itemcase.getType() == Type.SHOWCASE) {
|
if (itemcase.getType() == Type.SHOWCASE) {
|
||||||
|
|
||||||
// Show message.
|
// Show message.
|
||||||
chatLogger.message(player, "command.not-shop");
|
chatLogger.message(player, "command.not-shop");
|
||||||
@ -386,7 +378,7 @@ public final class ModifyCommand implements Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If itemcase only sells items.
|
// If itemcase only sells items.
|
||||||
if(itemcase.getType() == Type.SHOP_SELL) {
|
if (itemcase.getType() == Type.SHOP_SELL) {
|
||||||
|
|
||||||
// Show message.
|
// Show message.
|
||||||
chatLogger.message(player, "command.modify.sell-only");
|
chatLogger.message(player, "command.modify.sell-only");
|
||||||
@ -436,7 +428,7 @@ public final class ModifyCommand implements Command {
|
|||||||
ChatLogger chatLogger = ItemCaseCore.instance.getChatLogger();
|
ChatLogger chatLogger = ItemCaseCore.instance.getChatLogger();
|
||||||
|
|
||||||
// Check if player has permission.
|
// Check if player has permission.
|
||||||
if(!player.hasPermission("itemcase.create.shop.sell")) {
|
if (!player.hasPermission("itemcase.create.shop.sell")) {
|
||||||
|
|
||||||
// Send message.
|
// Send message.
|
||||||
chatLogger.message(player, "command.permission");
|
chatLogger.message(player, "command.permission");
|
||||||
@ -446,7 +438,7 @@ public final class ModifyCommand implements Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If itemcase is not a shop.
|
// If itemcase is not a shop.
|
||||||
if(itemcase.getType() == Type.SHOWCASE) {
|
if (itemcase.getType() == Type.SHOWCASE) {
|
||||||
|
|
||||||
// Show message.
|
// Show message.
|
||||||
chatLogger.message(player, "command.not-shop");
|
chatLogger.message(player, "command.not-shop");
|
||||||
@ -456,7 +448,7 @@ public final class ModifyCommand implements Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If itemcase only buys items.
|
// If itemcase only buys items.
|
||||||
if(itemcase.getType() == Type.SHOP_BUY) {
|
if (itemcase.getType() == Type.SHOP_BUY) {
|
||||||
|
|
||||||
// Show message.
|
// Show message.
|
||||||
chatLogger.message(player, "command.modify.buy-only");
|
chatLogger.message(player, "command.modify.buy-only");
|
||||||
@ -497,7 +489,7 @@ public final class ModifyCommand implements Command {
|
|||||||
public boolean isAskingForHelp(Player player, String label, String[] args) {
|
public boolean isAskingForHelp(Player player, String label, String[] args) {
|
||||||
|
|
||||||
// If args length equals 2.
|
// If args length equals 2.
|
||||||
if(args.length != 2) {
|
if (args.length != 2) {
|
||||||
|
|
||||||
// False.
|
// False.
|
||||||
return false;
|
return false;
|
||||||
@ -507,7 +499,7 @@ public final class ModifyCommand implements Command {
|
|||||||
String argument = args[1];
|
String argument = args[1];
|
||||||
|
|
||||||
// If not equal to help.
|
// If not equal to help.
|
||||||
if(!argument.equalsIgnoreCase("help")) {
|
if (!argument.equalsIgnoreCase("help")) {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -521,8 +513,6 @@ public final class ModifyCommand implements Command {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Show help for main command to given sender.
|
* Show help for main command to given sender.
|
||||||
*
|
|
||||||
* @param sender CommandSender.
|
|
||||||
*/
|
*/
|
||||||
private void showHelp(Player player, String label) {
|
private void showHelp(Player player, String label) {
|
||||||
|
|
||||||
|
@ -15,12 +15,12 @@
|
|||||||
package com.gmail.bleedobsidian.itemcase.commands;
|
package com.gmail.bleedobsidian.itemcase.commands;
|
||||||
|
|
||||||
import com.gmail.bleedobsidian.itemcase.Command;
|
import com.gmail.bleedobsidian.itemcase.Command;
|
||||||
import com.gmail.bleedobsidian.itemcase.loggers.ChatLogger;
|
|
||||||
import com.gmail.bleedobsidian.itemcase.ItemCaseCore;
|
import com.gmail.bleedobsidian.itemcase.ItemCaseCore;
|
||||||
import com.gmail.bleedobsidian.itemcase.Itemcase;
|
import com.gmail.bleedobsidian.itemcase.Itemcase;
|
||||||
import com.gmail.bleedobsidian.itemcase.Itemcase.StorageType;
|
import com.gmail.bleedobsidian.itemcase.Itemcase.StorageType;
|
||||||
import com.gmail.bleedobsidian.itemcase.Itemcase.Type;
|
import com.gmail.bleedobsidian.itemcase.Itemcase.Type;
|
||||||
import com.gmail.bleedobsidian.itemcase.LanguageTranslator;
|
import com.gmail.bleedobsidian.itemcase.LanguageTranslator;
|
||||||
|
import com.gmail.bleedobsidian.itemcase.loggers.ChatLogger;
|
||||||
import com.gmail.bleedobsidian.itemcase.managers.OrderManager.ItemcaseOrder;
|
import com.gmail.bleedobsidian.itemcase.managers.OrderManager.ItemcaseOrder;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
@ -42,7 +42,7 @@ public final class OrderCommand implements Command {
|
|||||||
String[] args) {
|
String[] args) {
|
||||||
|
|
||||||
// If sender is not a player.
|
// If sender is not a player.
|
||||||
if(!(sender instanceof Player)) {
|
if (!(sender instanceof Player player)) {
|
||||||
|
|
||||||
// Send message.
|
// Send message.
|
||||||
ItemCaseCore.instance.getGenericLogger().message(
|
ItemCaseCore.instance.getGenericLogger().message(
|
||||||
@ -53,10 +53,9 @@ public final class OrderCommand implements Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Cast sender to player.
|
// Cast sender to player.
|
||||||
Player player = (Player) sender;
|
|
||||||
|
|
||||||
// Check if player is asking for help.
|
// Check if player is asking for help.
|
||||||
if(this.isAskingForHelp(player, label, args)) {
|
if (this.isAskingForHelp(player, label, args)) {
|
||||||
|
|
||||||
// Exit.
|
// Exit.
|
||||||
return;
|
return;
|
||||||
@ -66,7 +65,7 @@ public final class OrderCommand implements Command {
|
|||||||
ChatLogger chatLogger = ItemCaseCore.instance.getChatLogger();
|
ChatLogger chatLogger = ItemCaseCore.instance.getChatLogger();
|
||||||
|
|
||||||
// If not enough arguments.
|
// If not enough arguments.
|
||||||
if(args.length < 2) {
|
if (args.length < 2) {
|
||||||
|
|
||||||
// Show help.
|
// Show help.
|
||||||
this.showHelp(player, label);
|
this.showHelp(player, label);
|
||||||
@ -76,7 +75,7 @@ public final class OrderCommand implements Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if player has active order.
|
// Check if player has active order.
|
||||||
if(!ItemCaseCore.instance.getOrderManager().hasOrder(player)) {
|
if (!ItemCaseCore.instance.getOrderManager().hasOrder(player)) {
|
||||||
|
|
||||||
// Send message
|
// Send message
|
||||||
chatLogger.message(player, "command.order.no-order");
|
chatLogger.message(player, "command.order.no-order");
|
||||||
@ -89,7 +88,7 @@ public final class OrderCommand implements Command {
|
|||||||
String subCommand = args[1];
|
String subCommand = args[1];
|
||||||
|
|
||||||
// Switch sub command.
|
// Switch sub command.
|
||||||
switch(subCommand) {
|
switch (subCommand) {
|
||||||
case "buy":
|
case "buy":
|
||||||
this.executeBuy(player);
|
this.executeBuy(player);
|
||||||
break;
|
break;
|
||||||
@ -147,7 +146,7 @@ public final class OrderCommand implements Command {
|
|||||||
public boolean isAskingForHelp(Player player, String label, String[] args) {
|
public boolean isAskingForHelp(Player player, String label, String[] args) {
|
||||||
|
|
||||||
// If args length equals 2.
|
// If args length equals 2.
|
||||||
if(args.length != 2) {
|
if (args.length != 2) {
|
||||||
|
|
||||||
// False.
|
// False.
|
||||||
return false;
|
return false;
|
||||||
@ -157,7 +156,7 @@ public final class OrderCommand implements Command {
|
|||||||
String argument = args[1];
|
String argument = args[1];
|
||||||
|
|
||||||
// If not equal to help.
|
// If not equal to help.
|
||||||
if(!argument.equalsIgnoreCase("help")) {
|
if (!argument.equalsIgnoreCase("help")) {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -183,7 +182,7 @@ public final class OrderCommand implements Command {
|
|||||||
LanguageTranslator translator = ItemCaseCore.instance.getTranslator();
|
LanguageTranslator translator = ItemCaseCore.instance.getTranslator();
|
||||||
|
|
||||||
// Check if player has permission.
|
// Check if player has permission.
|
||||||
if(!player.hasPermission("itemcase.buy")) {
|
if (!player.hasPermission("itemcase.buy")) {
|
||||||
|
|
||||||
// Send message.
|
// Send message.
|
||||||
chatLogger.message(player, "command.permission");
|
chatLogger.message(player, "command.permission");
|
||||||
@ -200,7 +199,7 @@ public final class OrderCommand implements Command {
|
|||||||
Itemcase itemcase = order.getItemcase();
|
Itemcase itemcase = order.getItemcase();
|
||||||
|
|
||||||
// If itemcase can not be bought from.
|
// If itemcase can not be bought from.
|
||||||
if(itemcase.getType() == Type.SHOP_SELL) {
|
if (itemcase.getType() == Type.SHOP_SELL) {
|
||||||
|
|
||||||
// Send message.
|
// Send message.
|
||||||
chatLogger.message(player, "command.order.no-buy");
|
chatLogger.message(player, "command.order.no-buy");
|
||||||
@ -210,7 +209,7 @@ public final class OrderCommand implements Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if server has vault if items are not free.
|
// Check if server has vault if items are not free.
|
||||||
if(!ItemCaseCore.instance.hasVault() &&
|
if (!ItemCaseCore.instance.hasVault() &&
|
||||||
order.getItemcase().getBuyPrice() > 0) {
|
order.getItemcase().getBuyPrice() > 0) {
|
||||||
|
|
||||||
// Show message.
|
// Show message.
|
||||||
@ -224,10 +223,10 @@ public final class OrderCommand implements Command {
|
|||||||
ItemStack itemstack = itemcase.getItemStack().clone();
|
ItemStack itemstack = itemcase.getItemStack().clone();
|
||||||
|
|
||||||
// If itemcase does not have enough items.
|
// If itemcase does not have enough items.
|
||||||
if(!itemcase.hasEnough(order.getAmount())) {
|
if (!itemcase.hasEnough(order.getAmount())) {
|
||||||
|
|
||||||
// If stock is 0.
|
// If stock is 0.
|
||||||
if(itemcase.getStockLevel() == 0) {
|
if (itemcase.getStockLevel() == 0) {
|
||||||
|
|
||||||
// Send message.
|
// Send message.
|
||||||
chatLogger.message(player, "command.order.no-stock");
|
chatLogger.message(player, "command.order.no-stock");
|
||||||
@ -255,7 +254,7 @@ public final class OrderCommand implements Command {
|
|||||||
Economy economyProvider = ItemCaseCore.instance.getEconomyProvider();
|
Economy economyProvider = ItemCaseCore.instance.getEconomyProvider();
|
||||||
|
|
||||||
// If total is greator than 0, vault must be used.
|
// If total is greator than 0, vault must be used.
|
||||||
if(total == 0) {
|
if (total == 0) {
|
||||||
|
|
||||||
// Give player items.
|
// Give player items.
|
||||||
itemstack.setAmount(order.getAmount());
|
itemstack.setAmount(order.getAmount());
|
||||||
@ -272,10 +271,10 @@ public final class OrderCommand implements Command {
|
|||||||
String money = ChatColor.GOLD + economyProvider.format(total);
|
String money = ChatColor.GOLD + economyProvider.format(total);
|
||||||
|
|
||||||
// If name exists.
|
// If name exists.
|
||||||
if(!economyProvider.currencyNameSingular().equals("")) {
|
if (!economyProvider.currencyNameSingular().equals("")) {
|
||||||
|
|
||||||
// If greator than 1.
|
// If greator than 1.
|
||||||
if(total > 1) {
|
if (total > 1) {
|
||||||
|
|
||||||
// Plural name.
|
// Plural name.
|
||||||
money += " " + economyProvider.currencyNamePlural();
|
money += " " + economyProvider.currencyNamePlural();
|
||||||
@ -293,7 +292,7 @@ public final class OrderCommand implements Command {
|
|||||||
translator.setPlaceholder("%MONEY%", money);
|
translator.setPlaceholder("%MONEY%", money);
|
||||||
|
|
||||||
// If player does not have enough money.
|
// If player does not have enough money.
|
||||||
if(economyProvider.getBalance(player,
|
if (economyProvider.getBalance(player,
|
||||||
player.getWorld().getName()) < total) {
|
player.getWorld().getName()) < total) {
|
||||||
|
|
||||||
// Send message.
|
// Send message.
|
||||||
@ -308,7 +307,7 @@ public final class OrderCommand implements Command {
|
|||||||
new EconomyResponse(0, 0, ResponseType.SUCCESS, null);
|
new EconomyResponse(0, 0, ResponseType.SUCCESS, null);
|
||||||
|
|
||||||
// If itemcase is not infinite.
|
// If itemcase is not infinite.
|
||||||
if(itemcase.getStorageType() == StorageType.FINITE) {
|
if (itemcase.getStorageType() == StorageType.FINITE) {
|
||||||
|
|
||||||
// Deposit money to owner.
|
// Deposit money to owner.
|
||||||
response1 = economyProvider.depositPlayer(
|
response1 = economyProvider.depositPlayer(
|
||||||
@ -321,7 +320,7 @@ public final class OrderCommand implements Command {
|
|||||||
player, player.getWorld().getName(), total);
|
player, player.getWorld().getName(), total);
|
||||||
|
|
||||||
// If successful.
|
// If successful.
|
||||||
if(response1.transactionSuccess() && response2.transactionSuccess()) {
|
if (response1.transactionSuccess() && response2.transactionSuccess()) {
|
||||||
|
|
||||||
// Give player items.
|
// Give player items.
|
||||||
itemstack.setAmount(order.getAmount());
|
itemstack.setAmount(order.getAmount());
|
||||||
@ -337,7 +336,7 @@ public final class OrderCommand implements Command {
|
|||||||
chatLogger.message(player, "command.order.withdrew");
|
chatLogger.message(player, "command.order.withdrew");
|
||||||
|
|
||||||
// If owner is online and itemcase is not infinite.
|
// If owner is online and itemcase is not infinite.
|
||||||
if(itemcase.getStorageType() == StorageType.FINITE &&
|
if (itemcase.getStorageType() == StorageType.FINITE &&
|
||||||
order.getItemcase().getOwner().isOnline()) {
|
order.getItemcase().getOwner().isOnline()) {
|
||||||
|
|
||||||
// Get owner.
|
// Get owner.
|
||||||
@ -347,7 +346,7 @@ public final class OrderCommand implements Command {
|
|||||||
translator.setPlaceholder("%PLAYER%", player.getDisplayName());
|
translator.setPlaceholder("%PLAYER%", player.getDisplayName());
|
||||||
|
|
||||||
// If item has custom display name.
|
// If item has custom display name.
|
||||||
if(itemcase.getItemStack().getItemMeta().hasDisplayName()) {
|
if (itemcase.getItemStack().getItemMeta().hasDisplayName()) {
|
||||||
|
|
||||||
// Set placeholder.
|
// Set placeholder.
|
||||||
translator.setPlaceholder("%ITEM_NAME%",
|
translator.setPlaceholder("%ITEM_NAME%",
|
||||||
@ -382,8 +381,6 @@ public final class OrderCommand implements Command {
|
|||||||
* Execute sell command.
|
* Execute sell command.
|
||||||
*
|
*
|
||||||
* @param player Player.
|
* @param player Player.
|
||||||
* @param label Label.
|
|
||||||
* @param args Arguments.
|
|
||||||
*/
|
*/
|
||||||
private void executeSell(Player player) {
|
private void executeSell(Player player) {
|
||||||
|
|
||||||
@ -394,7 +391,7 @@ public final class OrderCommand implements Command {
|
|||||||
LanguageTranslator translator = ItemCaseCore.instance.getTranslator();
|
LanguageTranslator translator = ItemCaseCore.instance.getTranslator();
|
||||||
|
|
||||||
// Check if player has permission.
|
// Check if player has permission.
|
||||||
if(!player.hasPermission("itemcase.sell")) {
|
if (!player.hasPermission("itemcase.sell")) {
|
||||||
|
|
||||||
// Send message.
|
// Send message.
|
||||||
chatLogger.message(player, "command.permission");
|
chatLogger.message(player, "command.permission");
|
||||||
@ -411,7 +408,7 @@ public final class OrderCommand implements Command {
|
|||||||
Itemcase itemcase = order.getItemcase();
|
Itemcase itemcase = order.getItemcase();
|
||||||
|
|
||||||
// If itemcase can not sell.
|
// If itemcase can not sell.
|
||||||
if(itemcase.getType() == Type.SHOP_BUY) {
|
if (itemcase.getType() == Type.SHOP_BUY) {
|
||||||
|
|
||||||
// Send message.
|
// Send message.
|
||||||
chatLogger.message(player, "command.order.no-sell");
|
chatLogger.message(player, "command.order.no-sell");
|
||||||
@ -421,7 +418,7 @@ public final class OrderCommand implements Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if server has no vault and players get no money for items.
|
// Check if server has no vault and players get no money for items.
|
||||||
if(!ItemCaseCore.instance.hasVault() &&
|
if (!ItemCaseCore.instance.hasVault() &&
|
||||||
order.getItemcase().getSellPrice() > 0) {
|
order.getItemcase().getSellPrice() > 0) {
|
||||||
|
|
||||||
// Show message.
|
// Show message.
|
||||||
@ -435,7 +432,7 @@ public final class OrderCommand implements Command {
|
|||||||
ItemStack itemstack = itemcase.getItemStack().clone();
|
ItemStack itemstack = itemcase.getItemStack().clone();
|
||||||
|
|
||||||
// If player does not have enough items.
|
// If player does not have enough items.
|
||||||
if(!player.getInventory().containsAtLeast(itemstack,
|
if (!player.getInventory().containsAtLeast(itemstack,
|
||||||
order.getAmount())) {
|
order.getAmount())) {
|
||||||
|
|
||||||
// Send message.
|
// Send message.
|
||||||
@ -452,7 +449,7 @@ public final class OrderCommand implements Command {
|
|||||||
Economy economyProvider = ItemCaseCore.instance.getEconomyProvider();
|
Economy economyProvider = ItemCaseCore.instance.getEconomyProvider();
|
||||||
|
|
||||||
// If total is greator than 0, vault must be used.
|
// If total is greator than 0, vault must be used.
|
||||||
if(total == 0) {
|
if (total == 0) {
|
||||||
|
|
||||||
// Remove items from player.
|
// Remove items from player.
|
||||||
itemstack.setAmount(order.getAmount());
|
itemstack.setAmount(order.getAmount());
|
||||||
@ -469,10 +466,10 @@ public final class OrderCommand implements Command {
|
|||||||
String money = ChatColor.GOLD + economyProvider.format(total);
|
String money = ChatColor.GOLD + economyProvider.format(total);
|
||||||
|
|
||||||
// If name exists.
|
// If name exists.
|
||||||
if(!economyProvider.currencyNameSingular().equals("")) {
|
if (!economyProvider.currencyNameSingular().equals("")) {
|
||||||
|
|
||||||
// If greator than 1.
|
// If greator than 1.
|
||||||
if(total > 1) {
|
if (total > 1) {
|
||||||
|
|
||||||
// Plural name.
|
// Plural name.
|
||||||
money += " " + economyProvider.currencyNamePlural();
|
money += " " + economyProvider.currencyNamePlural();
|
||||||
@ -490,7 +487,7 @@ public final class OrderCommand implements Command {
|
|||||||
translator.setPlaceholder("%MONEY%", money);
|
translator.setPlaceholder("%MONEY%", money);
|
||||||
|
|
||||||
// If owner does not have enough money and storage is finite.
|
// If owner does not have enough money and storage is finite.
|
||||||
if(order.getItemcase().getStorageType() == StorageType.FINITE &&
|
if (order.getItemcase().getStorageType() == StorageType.FINITE &&
|
||||||
(economyProvider.getBalance(order.getItemcase().getOwner(),
|
(economyProvider.getBalance(order.getItemcase().getOwner(),
|
||||||
player.getWorld().getName()) < total)) {
|
player.getWorld().getName()) < total)) {
|
||||||
|
|
||||||
@ -506,7 +503,7 @@ public final class OrderCommand implements Command {
|
|||||||
new EconomyResponse(0, 0, ResponseType.SUCCESS, null);
|
new EconomyResponse(0, 0, ResponseType.SUCCESS, null);
|
||||||
|
|
||||||
// If itemcase is not infinite.
|
// If itemcase is not infinite.
|
||||||
if(itemcase.getStorageType() == StorageType.FINITE) {
|
if (itemcase.getStorageType() == StorageType.FINITE) {
|
||||||
|
|
||||||
// Withdraw money from owner.
|
// Withdraw money from owner.
|
||||||
response1 = economyProvider.withdrawPlayer(
|
response1 = economyProvider.withdrawPlayer(
|
||||||
@ -520,7 +517,7 @@ public final class OrderCommand implements Command {
|
|||||||
player.getWorld().getName(), total);
|
player.getWorld().getName(), total);
|
||||||
|
|
||||||
// If successful.
|
// If successful.
|
||||||
if(response1.transactionSuccess() && response2.transactionSuccess()) {
|
if (response1.transactionSuccess() && response2.transactionSuccess()) {
|
||||||
|
|
||||||
// Remove items from player.
|
// Remove items from player.
|
||||||
itemstack.setAmount(order.getAmount());
|
itemstack.setAmount(order.getAmount());
|
||||||
@ -536,7 +533,7 @@ public final class OrderCommand implements Command {
|
|||||||
chatLogger.message(player, "command.order.deposit");
|
chatLogger.message(player, "command.order.deposit");
|
||||||
|
|
||||||
// If owner is online and itemcase is not infinite.
|
// If owner is online and itemcase is not infinite.
|
||||||
if(itemcase.getStorageType() == StorageType.FINITE &&
|
if (itemcase.getStorageType() == StorageType.FINITE &&
|
||||||
order.getItemcase().getOwner().isOnline()) {
|
order.getItemcase().getOwner().isOnline()) {
|
||||||
|
|
||||||
// Get owner.
|
// Get owner.
|
||||||
@ -546,7 +543,7 @@ public final class OrderCommand implements Command {
|
|||||||
translator.setPlaceholder("%PLAYER%", player.getDisplayName());
|
translator.setPlaceholder("%PLAYER%", player.getDisplayName());
|
||||||
|
|
||||||
// If item has custom display name.
|
// If item has custom display name.
|
||||||
if(itemcase.getItemStack().getItemMeta().hasDisplayName()) {
|
if (itemcase.getItemStack().getItemMeta().hasDisplayName()) {
|
||||||
|
|
||||||
// Set placeholder.
|
// Set placeholder.
|
||||||
translator.setPlaceholder("%ITEM_NAME%",
|
translator.setPlaceholder("%ITEM_NAME%",
|
||||||
@ -591,7 +588,7 @@ public final class OrderCommand implements Command {
|
|||||||
ChatLogger chatLogger = ItemCaseCore.instance.getChatLogger();
|
ChatLogger chatLogger = ItemCaseCore.instance.getChatLogger();
|
||||||
|
|
||||||
// Check if player has permission.
|
// Check if player has permission.
|
||||||
if(!player.hasPermission("itemcase.buy") &&
|
if (!player.hasPermission("itemcase.buy") &&
|
||||||
!player.hasPermission("itemcase.sell")) {
|
!player.hasPermission("itemcase.sell")) {
|
||||||
|
|
||||||
// Send message.
|
// Send message.
|
||||||
@ -602,7 +599,7 @@ public final class OrderCommand implements Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check argument length.
|
// Check argument length.
|
||||||
if(args.length != 3) {
|
if (args.length != 3) {
|
||||||
|
|
||||||
// Show help.
|
// Show help.
|
||||||
this.showHelp(player, label);
|
this.showHelp(player, label);
|
||||||
@ -612,7 +609,7 @@ public final class OrderCommand implements Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Define amount.
|
// Define amount.
|
||||||
int amount = 0;
|
int amount;
|
||||||
|
|
||||||
// Attempt to parse amount.
|
// Attempt to parse amount.
|
||||||
try {
|
try {
|
||||||
@ -620,7 +617,7 @@ public final class OrderCommand implements Command {
|
|||||||
// Parse amount.
|
// Parse amount.
|
||||||
amount = Integer.parseInt(args[2]);
|
amount = Integer.parseInt(args[2]);
|
||||||
|
|
||||||
} catch(NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
|
|
||||||
// Show message.
|
// Show message.
|
||||||
chatLogger.message(player, "command.order.invalid-amount");
|
chatLogger.message(player, "command.order.invalid-amount");
|
||||||
|
@ -15,12 +15,12 @@
|
|||||||
package com.gmail.bleedobsidian.itemcase.commands;
|
package com.gmail.bleedobsidian.itemcase.commands;
|
||||||
|
|
||||||
import com.gmail.bleedobsidian.itemcase.Command;
|
import com.gmail.bleedobsidian.itemcase.Command;
|
||||||
import com.gmail.bleedobsidian.itemcase.loggers.ChatLogger;
|
|
||||||
import com.gmail.bleedobsidian.itemcase.ItemCaseCore;
|
import com.gmail.bleedobsidian.itemcase.ItemCaseCore;
|
||||||
import com.gmail.bleedobsidian.itemcase.Itemcase;
|
import com.gmail.bleedobsidian.itemcase.Itemcase;
|
||||||
import com.gmail.bleedobsidian.itemcase.Itemcase.StorageType;
|
import com.gmail.bleedobsidian.itemcase.Itemcase.StorageType;
|
||||||
import com.gmail.bleedobsidian.itemcase.Itemcase.Type;
|
import com.gmail.bleedobsidian.itemcase.Itemcase.Type;
|
||||||
import com.gmail.bleedobsidian.itemcase.LanguageTranslator;
|
import com.gmail.bleedobsidian.itemcase.LanguageTranslator;
|
||||||
|
import com.gmail.bleedobsidian.itemcase.loggers.ChatLogger;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -38,7 +38,7 @@ public final class StorageCommand implements Command {
|
|||||||
String[] args) {
|
String[] args) {
|
||||||
|
|
||||||
// If sender is not a player.
|
// If sender is not a player.
|
||||||
if(!(sender instanceof Player)) {
|
if (!(sender instanceof Player player)) {
|
||||||
|
|
||||||
// Send message.
|
// Send message.
|
||||||
ItemCaseCore.instance.getGenericLogger().message(
|
ItemCaseCore.instance.getGenericLogger().message(
|
||||||
@ -49,10 +49,9 @@ public final class StorageCommand implements Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Cast sender to player.
|
// Cast sender to player.
|
||||||
Player player = (Player) sender;
|
|
||||||
|
|
||||||
// Check if player is asking for help.
|
// Check if player is asking for help.
|
||||||
if(this.isAskingForHelp(player, label, args)) {
|
if (this.isAskingForHelp(player, label, args)) {
|
||||||
|
|
||||||
// Exit.
|
// Exit.
|
||||||
return;
|
return;
|
||||||
@ -62,7 +61,7 @@ public final class StorageCommand implements Command {
|
|||||||
ChatLogger chatLogger = ItemCaseCore.instance.getChatLogger();
|
ChatLogger chatLogger = ItemCaseCore.instance.getChatLogger();
|
||||||
|
|
||||||
// Check if player has permission.
|
// Check if player has permission.
|
||||||
if(!player.hasPermission("itemcase.create")) {
|
if (!player.hasPermission("itemcase.create")) {
|
||||||
|
|
||||||
// Send message.
|
// Send message.
|
||||||
chatLogger.message(player, "command.permission");
|
chatLogger.message(player, "command.permission");
|
||||||
@ -72,13 +71,13 @@ public final class StorageCommand implements Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The target location.
|
// The target location.
|
||||||
Location target = null;
|
Location target;
|
||||||
|
|
||||||
// Get the players target block.
|
// Get the players target block.
|
||||||
target = player.getTargetBlock(null, 5).getLocation();
|
target = player.getTargetBlock(null, 5).getLocation();
|
||||||
|
|
||||||
// Check if itemcase exists here.
|
// Check if itemcase exists here.
|
||||||
if(!ItemCaseCore.instance.getItemcaseManager().isItemcase(target)) {
|
if (!ItemCaseCore.instance.getItemcaseManager().isItemcase(target)) {
|
||||||
|
|
||||||
// Show message.
|
// Show message.
|
||||||
chatLogger.message(player, "command.invalid-location");
|
chatLogger.message(player, "command.invalid-location");
|
||||||
@ -95,10 +94,10 @@ public final class StorageCommand implements Command {
|
|||||||
OfflinePlayer owner = itemcase.getOwner();
|
OfflinePlayer owner = itemcase.getOwner();
|
||||||
|
|
||||||
// Check if this player owns this itemcase.
|
// Check if this player owns this itemcase.
|
||||||
if(!owner.equals(player)) {
|
if (!owner.equals(player)) {
|
||||||
|
|
||||||
// Check if player is allowed to modify other peoples itemcases.
|
// Check if player is allowed to modify other peoples itemcases.
|
||||||
if(!player.hasPermission("itemcase.modify.other")) {
|
if (!player.hasPermission("itemcase.modify.other")) {
|
||||||
|
|
||||||
// Show message.
|
// Show message.
|
||||||
chatLogger.message(player, "command.not-owner");
|
chatLogger.message(player, "command.not-owner");
|
||||||
@ -109,7 +108,7 @@ public final class StorageCommand implements Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if itemcase is a shop.
|
// Check if itemcase is a shop.
|
||||||
if(itemcase.getType() == Type.SHOWCASE) {
|
if (itemcase.getType() == Type.SHOWCASE) {
|
||||||
|
|
||||||
// Show message.
|
// Show message.
|
||||||
chatLogger.message(player, "command.not-shop");
|
chatLogger.message(player, "command.not-shop");
|
||||||
@ -119,7 +118,7 @@ public final class StorageCommand implements Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If itemcase has infinite storage.
|
// If itemcase has infinite storage.
|
||||||
if(itemcase.getStorageType() == StorageType.INFINITE) {
|
if (itemcase.getStorageType() == StorageType.INFINITE) {
|
||||||
|
|
||||||
// Show message.
|
// Show message.
|
||||||
chatLogger.message(player, "command.storage.infinite");
|
chatLogger.message(player, "command.storage.infinite");
|
||||||
@ -138,7 +137,7 @@ public final class StorageCommand implements Command {
|
|||||||
public boolean isAskingForHelp(Player player, String label, String[] args) {
|
public boolean isAskingForHelp(Player player, String label, String[] args) {
|
||||||
|
|
||||||
// If args length equals 2.
|
// If args length equals 2.
|
||||||
if(args.length != 2) {
|
if (args.length != 2) {
|
||||||
|
|
||||||
// False.
|
// False.
|
||||||
return false;
|
return false;
|
||||||
@ -148,7 +147,7 @@ public final class StorageCommand implements Command {
|
|||||||
String argument = args[1];
|
String argument = args[1];
|
||||||
|
|
||||||
// If not equal to help.
|
// If not equal to help.
|
||||||
if(!argument.equalsIgnoreCase("help")) {
|
if (!argument.equalsIgnoreCase("help")) {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -16,9 +16,10 @@ package com.gmail.bleedobsidian.itemcase.configurations;
|
|||||||
|
|
||||||
import com.gmail.bleedobsidian.itemcase.ConfigurationFile;
|
import com.gmail.bleedobsidian.itemcase.ConfigurationFile;
|
||||||
import com.gmail.bleedobsidian.itemcase.LanguageTranslator.Language;
|
import com.gmail.bleedobsidian.itemcase.LanguageTranslator.Language;
|
||||||
import java.util.ArrayList;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main configuration file for ItemCase.
|
* The main configuration file for ItemCase.
|
||||||
*
|
*
|
||||||
@ -62,7 +63,10 @@ public final class ConfigFile extends ConfigurationFile {
|
|||||||
this.file.getStringList("Materials").forEach((id) -> {
|
this.file.getStringList("Materials").forEach((id) -> {
|
||||||
|
|
||||||
// Add material to list.
|
// Add material to list.
|
||||||
materials.add(Material.getMaterial(id));
|
Material material = Material.getMaterial(id);
|
||||||
|
if (material != null) {
|
||||||
|
materials.add(material);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Return list.
|
// Return list.
|
||||||
|
@ -27,7 +27,7 @@ public final class LanguageFile extends ConfigurationFile {
|
|||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param Language The language this file is for.
|
* @param language The language this file is for.
|
||||||
*/
|
*/
|
||||||
public LanguageFile(Language language) {
|
public LanguageFile(Language language) {
|
||||||
|
|
||||||
|
@ -19,6 +19,17 @@ import com.gmail.bleedobsidian.itemcase.ItemCaseCore;
|
|||||||
import com.gmail.bleedobsidian.itemcase.Itemcase;
|
import com.gmail.bleedobsidian.itemcase.Itemcase;
|
||||||
import com.gmail.bleedobsidian.itemcase.Itemcase.StorageType;
|
import com.gmail.bleedobsidian.itemcase.Itemcase.StorageType;
|
||||||
import com.gmail.bleedobsidian.itemcase.Itemcase.Type;
|
import com.gmail.bleedobsidian.itemcase.Itemcase.Type;
|
||||||
|
import com.onarandombox.MultiverseCore.utils.FileUtils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.configuration.MemorySection;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -27,14 +38,6 @@ import java.util.Map;
|
|||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import org.apache.commons.multiverse.io.FileUtils;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.configuration.MemorySection;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A configuration file that holds all Itemcase saves for a specific world.
|
* A configuration file that holds all Itemcase saves for a specific world.
|
||||||
@ -66,7 +69,6 @@ public final class WorldFile extends ConfigurationFile {
|
|||||||
* Saves the given Itemcase to config.
|
* Saves the given Itemcase to config.
|
||||||
*
|
*
|
||||||
* @param itemcase Itemcase.
|
* @param itemcase Itemcase.
|
||||||
* @throws java.io.IOException
|
|
||||||
*/
|
*/
|
||||||
public void saveItemcase(Itemcase itemcase) throws IOException {
|
public void saveItemcase(Itemcase itemcase) throws IOException {
|
||||||
|
|
||||||
@ -90,15 +92,14 @@ public final class WorldFile extends ConfigurationFile {
|
|||||||
this.file.set(key + "itemstack", itemstack);
|
this.file.set(key + "itemstack", itemstack);
|
||||||
|
|
||||||
// If itemcase is a shop.
|
// If itemcase is a shop.
|
||||||
if(itemcase.getType() != Type.SHOWCASE) {
|
if (itemcase.getType() != Type.SHOWCASE) {
|
||||||
|
|
||||||
// Set storage type.
|
// Set storage type.
|
||||||
this.file.set(key + "shop.storage-type",
|
this.file.set(key + "shop.storage-type",
|
||||||
itemcase.getStorageType().name());
|
itemcase.getStorageType().name());
|
||||||
|
|
||||||
// If shop has finite storage.
|
// If shop has finite storage.
|
||||||
if(itemcase.getStorageType() == StorageType.FINITE) {
|
if (itemcase.getStorageType() == StorageType.FINITE) {
|
||||||
|
|
||||||
// Serialize inventory.
|
// Serialize inventory.
|
||||||
Map<String, Object> inventory =
|
Map<String, Object> inventory =
|
||||||
this.serializeInventory(itemcase.getStorage());
|
this.serializeInventory(itemcase.getStorage());
|
||||||
@ -108,7 +109,7 @@ public final class WorldFile extends ConfigurationFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If this itemcase buys.
|
// If this itemcase buys.
|
||||||
if(itemcase.getType() == Type.SHOP_BUY ||
|
if (itemcase.getType() == Type.SHOP_BUY ||
|
||||||
itemcase.getType() == Type.SHOP_MULTI) {
|
itemcase.getType() == Type.SHOP_MULTI) {
|
||||||
|
|
||||||
// Set buy price.
|
// Set buy price.
|
||||||
@ -116,7 +117,7 @@ public final class WorldFile extends ConfigurationFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If this itemcase sells.
|
// If this itemcase sells.
|
||||||
if(itemcase.getType() == Type.SHOP_SELL ||
|
if (itemcase.getType() == Type.SHOP_SELL ||
|
||||||
itemcase.getType() == Type.SHOP_MULTI) {
|
itemcase.getType() == Type.SHOP_MULTI) {
|
||||||
|
|
||||||
// Set sell price.
|
// Set sell price.
|
||||||
@ -136,7 +137,6 @@ public final class WorldFile extends ConfigurationFile {
|
|||||||
* Deletes the given Itemcase from config.
|
* Deletes the given Itemcase from config.
|
||||||
*
|
*
|
||||||
* @param itemcase Itemcase.
|
* @param itemcase Itemcase.
|
||||||
* @throws IOException
|
|
||||||
*/
|
*/
|
||||||
public void deleteItemcase(Itemcase itemcase) throws IOException {
|
public void deleteItemcase(Itemcase itemcase) throws IOException {
|
||||||
|
|
||||||
@ -159,7 +159,6 @@ public final class WorldFile extends ConfigurationFile {
|
|||||||
* Attempts to load all itemcases from the config.
|
* Attempts to load all itemcases from the config.
|
||||||
*
|
*
|
||||||
* @return Array list of loaded itemcases.
|
* @return Array list of loaded itemcases.
|
||||||
* @throws java.io.IOException
|
|
||||||
*/
|
*/
|
||||||
public ArrayList<Itemcase> loadItemcases() throws IOException {
|
public ArrayList<Itemcase> loadItemcases() throws IOException {
|
||||||
|
|
||||||
@ -167,14 +166,14 @@ public final class WorldFile extends ConfigurationFile {
|
|||||||
this.load(ItemCaseCore.instance);
|
this.load(ItemCaseCore.instance);
|
||||||
|
|
||||||
// Create new array list to store loaded itemcases.
|
// Create new array list to store loaded itemcases.
|
||||||
ArrayList<Itemcase> itemcases = new ArrayList<>();
|
ArrayList<Itemcase> itemCases = new ArrayList<>();
|
||||||
|
|
||||||
// Get the list of keys (itemcase locations).
|
// Get the list of keys (itemcase locations).
|
||||||
Set<String> keys =
|
Set<String> keys =
|
||||||
this.file.getConfigurationSection("itemcases").getKeys(false);
|
this.file.getConfigurationSection("itemcases").getKeys(false);
|
||||||
|
|
||||||
// For every key (itemcase).
|
// For every key (itemcase).
|
||||||
for(String key : keys) {
|
for (String key : keys) {
|
||||||
|
|
||||||
// Split key by '/' to obtain individual coordinates.
|
// Split key by '/' to obtain individual coordinates.
|
||||||
String[] coordinates = key.split("/");
|
String[] coordinates = key.split("/");
|
||||||
@ -201,8 +200,7 @@ public final class WorldFile extends ConfigurationFile {
|
|||||||
|
|
||||||
// Get ItemStack.
|
// Get ItemStack.
|
||||||
Map<String, Object> itemstackMap =
|
Map<String, Object> itemstackMap =
|
||||||
this.file.getConfigurationSection(key + "itemstack")
|
this.file.getConfigurationSection(key + "itemstack").getValues(true);
|
||||||
.getValues(true);
|
|
||||||
ItemStack itemstack = ItemStack.deserialize(itemstackMap);
|
ItemStack itemstack = ItemStack.deserialize(itemstackMap);
|
||||||
|
|
||||||
// Create itemcase object.
|
// Create itemcase object.
|
||||||
@ -212,7 +210,7 @@ public final class WorldFile extends ConfigurationFile {
|
|||||||
itemcase.spawnItem();
|
itemcase.spawnItem();
|
||||||
|
|
||||||
// If itemcase is a shop.
|
// If itemcase is a shop.
|
||||||
if(type != Type.SHOWCASE) {
|
if (type != Type.SHOWCASE) {
|
||||||
|
|
||||||
// Get storage type.
|
// Get storage type.
|
||||||
StorageType storageType = StorageType.valueOf(
|
StorageType storageType = StorageType.valueOf(
|
||||||
@ -222,9 +220,9 @@ public final class WorldFile extends ConfigurationFile {
|
|||||||
itemcase.setStorageType(storageType);
|
itemcase.setStorageType(storageType);
|
||||||
|
|
||||||
// If itemcase has finite storage.
|
// If itemcase has finite storage.
|
||||||
if(storageType == StorageType.FINITE) {
|
if (storageType == StorageType.FINITE) {
|
||||||
|
|
||||||
// Deserialse inventory.
|
// De-serialise inventory.
|
||||||
Inventory inventory = this.deserializeInventory(
|
Inventory inventory = this.deserializeInventory(
|
||||||
this.file.getConfigurationSection(
|
this.file.getConfigurationSection(
|
||||||
key + "shop.storage").getValues(false));
|
key + "shop.storage").getValues(false));
|
||||||
@ -234,7 +232,7 @@ public final class WorldFile extends ConfigurationFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If this itemcase buys.
|
// If this itemcase buys.
|
||||||
if(type == Type.SHOP_BUY || type == Type.SHOP_MULTI) {
|
if (type == Type.SHOP_BUY || type == Type.SHOP_MULTI) {
|
||||||
|
|
||||||
// Get buy price.
|
// Get buy price.
|
||||||
double buyPrice =
|
double buyPrice =
|
||||||
@ -245,7 +243,7 @@ public final class WorldFile extends ConfigurationFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If this itemcase sells.
|
// If this itemcase sells.
|
||||||
if(type == Type.SHOP_SELL || type == Type.SHOP_MULTI) {
|
if (type == Type.SHOP_SELL || type == Type.SHOP_MULTI) {
|
||||||
|
|
||||||
// Get sell price.
|
// Get sell price.
|
||||||
double sellPrice =
|
double sellPrice =
|
||||||
@ -257,19 +255,17 @@ public final class WorldFile extends ConfigurationFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add to list.
|
// Add to list.
|
||||||
itemcases.add(itemcase);
|
itemCases.add(itemcase);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return list of loaded itemcases.
|
// Return list of loaded itemcases.
|
||||||
return itemcases;
|
return itemCases;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete directory and config.
|
* Delete directory and config.
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
*/
|
||||||
public void deleteDirectory() throws IOException {
|
public void deleteDirectory() {
|
||||||
|
|
||||||
// Create file reference.
|
// Create file reference.
|
||||||
File fileReference = new File(ItemCaseCore.instance.getDataFolder(),
|
File fileReference = new File(ItemCaseCore.instance.getDataFolder(),
|
||||||
@ -279,7 +275,7 @@ public final class WorldFile extends ConfigurationFile {
|
|||||||
this.file = null;
|
this.file = null;
|
||||||
|
|
||||||
// Delete directory.
|
// Delete directory.
|
||||||
FileUtils.deleteDirectory(fileReference);
|
FileUtils.deleteFolder(fileReference);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -291,16 +287,16 @@ public final class WorldFile extends ConfigurationFile {
|
|||||||
private Map<String, Object> serializeInventory(Inventory inventory) {
|
private Map<String, Object> serializeInventory(Inventory inventory) {
|
||||||
|
|
||||||
// Create map.
|
// Create map.
|
||||||
Map<String, Object> map = new HashMap();
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
|
||||||
// Set size.
|
// Set size.
|
||||||
map.put("size", inventory.getSize());
|
map.put("size", inventory.getSize());
|
||||||
|
|
||||||
// Set name.
|
// Set name.
|
||||||
map.put("name", inventory.getName());
|
map.put("name", ((Entity) inventory).getName());
|
||||||
|
|
||||||
// Loop through all content slots.
|
// Loop through all content slots.
|
||||||
for(int i = 0; i < inventory.getSize(); i++) {
|
for (int i = 0; i < inventory.getSize(); i++) {
|
||||||
|
|
||||||
// Check if content slot has any items.
|
// Check if content slot has any items.
|
||||||
if (inventory.getItem(i) != null) {
|
if (inventory.getItem(i) != null) {
|
||||||
@ -332,10 +328,10 @@ public final class WorldFile extends ConfigurationFile {
|
|||||||
Inventory inventory = Bukkit.createInventory(null, size, name);
|
Inventory inventory = Bukkit.createInventory(null, size, name);
|
||||||
|
|
||||||
// For every map entry.
|
// For every map entry.
|
||||||
for(Entry<String, Object> entry : map.entrySet()) {
|
for (Entry<String, Object> entry : map.entrySet()) {
|
||||||
|
|
||||||
// Check entry is parameter.
|
// Check entry is parameter.
|
||||||
if(entry.getKey().equals("size") ||
|
if (entry.getKey().equals("size") ||
|
||||||
entry.getKey().equals("name")) {
|
entry.getKey().equals("name")) {
|
||||||
|
|
||||||
// Skip.
|
// Skip.
|
||||||
@ -349,8 +345,7 @@ public final class WorldFile extends ConfigurationFile {
|
|||||||
MemorySection section = (MemorySection) entry.getValue();
|
MemorySection section = (MemorySection) entry.getValue();
|
||||||
|
|
||||||
// Deserialize item.
|
// Deserialize item.
|
||||||
ItemStack item = ItemStack.deserialize((Map<String, Object>)
|
ItemStack item = ItemStack.deserialize(section.getValues(true));
|
||||||
section.getValues(true));
|
|
||||||
|
|
||||||
// Set item in slot.
|
// Set item in slot.
|
||||||
inventory.setItem(slot, item);
|
inventory.setItem(slot, item);
|
||||||
|
@ -56,7 +56,7 @@ public final class ChatLogger {
|
|||||||
public void message(Player player, String string) {
|
public void message(Player player, String string) {
|
||||||
|
|
||||||
// If string is a message key.
|
// If string is a message key.
|
||||||
if(this.translator.isKey(string)) {
|
if (this.translator.isKey(string)) {
|
||||||
|
|
||||||
// Translate.
|
// Translate.
|
||||||
string = this.translator.getTranslation(string);
|
string = this.translator.getTranslation(string);
|
||||||
|
@ -16,10 +16,11 @@
|
|||||||
package com.gmail.bleedobsidian.itemcase.loggers;
|
package com.gmail.bleedobsidian.itemcase.loggers;
|
||||||
|
|
||||||
import com.gmail.bleedobsidian.itemcase.LanguageTranslator;
|
import com.gmail.bleedobsidian.itemcase.LanguageTranslator;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.LogRecord;
|
import java.util.logging.LogRecord;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A custom logger used to add color to the console when using warnings and
|
* A custom logger used to add color to the console when using warnings and
|
||||||
@ -67,7 +68,7 @@ public final class ConsoleLogger extends Logger {
|
|||||||
String message = logRecord.getMessage();
|
String message = logRecord.getMessage();
|
||||||
|
|
||||||
// If message is a message key.
|
// If message is a message key.
|
||||||
if(translator.isKey(message)) {
|
if (translator.isKey(message)) {
|
||||||
|
|
||||||
// Translate.
|
// Translate.
|
||||||
message = translator.getTranslation(message);
|
message = translator.getTranslation(message);
|
||||||
|
@ -50,7 +50,7 @@ public final class GenericLogger {
|
|||||||
public void message(CommandSender sender, String string) {
|
public void message(CommandSender sender, String string) {
|
||||||
|
|
||||||
// If string is a message key.
|
// If string is a message key.
|
||||||
if(this.translator.isKey(string)) {
|
if (this.translator.isKey(string)) {
|
||||||
|
|
||||||
// Translate.
|
// Translate.
|
||||||
string = this.translator.getTranslation(string);
|
string = this.translator.getTranslation(string);
|
||||||
|
@ -20,10 +20,6 @@ import com.gmail.bleedobsidian.itemcase.Itemcase.StorageType;
|
|||||||
import com.gmail.bleedobsidian.itemcase.Itemcase.Type;
|
import com.gmail.bleedobsidian.itemcase.Itemcase.Type;
|
||||||
import com.gmail.bleedobsidian.itemcase.configurations.WorldFile;
|
import com.gmail.bleedobsidian.itemcase.configurations.WorldFile;
|
||||||
import com.onarandombox.MultiverseCore.event.MVWorldDeleteEvent;
|
import com.onarandombox.MultiverseCore.event.MVWorldDeleteEvent;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
@ -35,6 +31,11 @@ import org.bukkit.event.inventory.InventoryCloseEvent;
|
|||||||
import org.bukkit.event.world.WorldLoadEvent;
|
import org.bukkit.event.world.WorldLoadEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A manager of all Itemcases in a server. This manager is also responsible
|
* A manager of all Itemcases in a server. This manager is also responsible
|
||||||
* for loading and saving Itemcases to a config.
|
* for loading and saving Itemcases to a config.
|
||||||
@ -59,7 +60,7 @@ public final class ItemcaseManager {
|
|||||||
public void initialize() {
|
public void initialize() {
|
||||||
|
|
||||||
// For every currently loaded world.
|
// For every currently loaded world.
|
||||||
for(World world : Bukkit.getWorlds()) {
|
for (World world : Bukkit.getWorlds()) {
|
||||||
|
|
||||||
// Request itemcases to be loaded.
|
// Request itemcases to be loaded.
|
||||||
this.loadItemcases(world);
|
this.loadItemcases(world);
|
||||||
@ -203,7 +204,7 @@ public final class ItemcaseManager {
|
|||||||
public void unloadItemcases() {
|
public void unloadItemcases() {
|
||||||
|
|
||||||
// For every loaded itemcase.
|
// For every loaded itemcase.
|
||||||
for(Itemcase itemcase : this.itemcases) {
|
for (Itemcase itemcase : this.itemcases) {
|
||||||
|
|
||||||
// Despawn the item.
|
// Despawn the item.
|
||||||
itemcase.despawnItem();
|
itemcase.despawnItem();
|
||||||
@ -232,10 +233,10 @@ public final class ItemcaseManager {
|
|||||||
public boolean isItemcase(Location location) {
|
public boolean isItemcase(Location location) {
|
||||||
|
|
||||||
// For every itemcase.
|
// For every itemcase.
|
||||||
for(Itemcase itemcase : this.itemcases) {
|
for (Itemcase itemcase : this.itemcases) {
|
||||||
|
|
||||||
// Check if location matches.
|
// Check if location matches.
|
||||||
if(itemcase.getLocation().equals(location)) {
|
if (itemcase.getLocation().equals(location)) {
|
||||||
|
|
||||||
// Return true.
|
// Return true.
|
||||||
return true;
|
return true;
|
||||||
@ -255,10 +256,10 @@ public final class ItemcaseManager {
|
|||||||
public Itemcase getItemcase(Location location) {
|
public Itemcase getItemcase(Location location) {
|
||||||
|
|
||||||
// For every itemcase.
|
// For every itemcase.
|
||||||
for(Itemcase itemcase : this.itemcases) {
|
for (Itemcase itemcase : this.itemcases) {
|
||||||
|
|
||||||
// Check if location matches.
|
// Check if location matches.
|
||||||
if(itemcase.getLocation().equals(location)) {
|
if (itemcase.getLocation().equals(location)) {
|
||||||
|
|
||||||
// Return itemcase.
|
// Return itemcase.
|
||||||
return itemcase;
|
return itemcase;
|
||||||
@ -304,14 +305,13 @@ public final class ItemcaseManager {
|
|||||||
WorldFile worldFile = null;
|
WorldFile worldFile = null;
|
||||||
|
|
||||||
// For every entry.
|
// For every entry.
|
||||||
for(Entry<World, WorldFile> entry :
|
for (Entry<World, WorldFile> entry :
|
||||||
ItemcaseManager.this.worldFiles.entrySet()) {
|
ItemcaseManager.this.worldFiles.entrySet()) {
|
||||||
|
|
||||||
// Check if world name matches.
|
// Check if world name matches.
|
||||||
if(entry.getKey().getName() == worldName) {
|
if (entry.getKey().getName().equals(worldName)) {
|
||||||
|
|
||||||
// Attempt to delete config.
|
// Attempt to delete config.
|
||||||
try {
|
|
||||||
|
|
||||||
// Set world file.
|
// Set world file.
|
||||||
worldFile = entry.getValue();
|
worldFile = entry.getValue();
|
||||||
@ -319,13 +319,7 @@ public final class ItemcaseManager {
|
|||||||
// Delete config.
|
// Delete config.
|
||||||
entry.getValue().deleteDirectory();
|
entry.getValue().deleteDirectory();
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
|
|
||||||
// Log error.
|
|
||||||
ItemCaseCore.instance.getConsoleLogger().severe(
|
|
||||||
"Failed to delete itemcase config for world:"
|
|
||||||
+ worldName, e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -333,13 +327,13 @@ public final class ItemcaseManager {
|
|||||||
ItemcaseManager.this.worldFiles.values().remove(worldFile);
|
ItemcaseManager.this.worldFiles.values().remove(worldFile);
|
||||||
|
|
||||||
// List to store itemcases of this world.
|
// List to store itemcases of this world.
|
||||||
ArrayList<Itemcase> itemcases = new ArrayList();
|
ArrayList<Itemcase> itemcases = new ArrayList<>();
|
||||||
|
|
||||||
// For every itemcase.
|
// For every itemcase.
|
||||||
for(Itemcase itemcase : ItemcaseManager.this.itemcases) {
|
for (Itemcase itemcase : ItemcaseManager.this.itemcases) {
|
||||||
|
|
||||||
// Check if itemcase was in deleted world.
|
// Check if itemcase was in deleted world.
|
||||||
if(itemcase.getLocation().getWorld().getName() == worldName) {
|
if (itemcase.getLocation().getWorld().getName().equals(worldName)) {
|
||||||
|
|
||||||
// Despawn item.
|
// Despawn item.
|
||||||
itemcase.despawnItem();
|
itemcase.despawnItem();
|
||||||
@ -357,34 +351,34 @@ public final class ItemcaseManager {
|
|||||||
public void onInventoryCloseEvent(InventoryCloseEvent event) {
|
public void onInventoryCloseEvent(InventoryCloseEvent event) {
|
||||||
|
|
||||||
// Get inventory name.
|
// Get inventory name.
|
||||||
String name = event.getInventory().getName();
|
String name = event.getView().getTitle();
|
||||||
|
|
||||||
// If inventory is Itemcase inventory.
|
// If inventory is Itemcase inventory.
|
||||||
if(!name.equals(Itemcase.INVENTORY_NAME)) {
|
if (!name.equals(Itemcase.INVENTORY_NAME)) {
|
||||||
|
|
||||||
// Exit.
|
// Exit.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For every Itemcase.
|
// For every Itemcase.
|
||||||
for(Itemcase itemcase : ItemcaseManager.this.itemcases) {
|
for (Itemcase itemcase : ItemcaseManager.this.itemcases) {
|
||||||
|
|
||||||
// If itemcase is not a shop it wont have storage.
|
// If itemcase is not a shop it wont have storage.
|
||||||
if(itemcase.getType() == Type.SHOWCASE) {
|
if (itemcase.getType() == Type.SHOWCASE) {
|
||||||
|
|
||||||
// Skip.
|
// Skip.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If itemcase is inifinite, it wont have storage.
|
// If itemcase is inifinite, it wont have storage.
|
||||||
if(itemcase.getStorageType() == StorageType.INFINITE) {
|
if (itemcase.getStorageType() == StorageType.INFINITE) {
|
||||||
|
|
||||||
// Skip.
|
// Skip.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If inventory belongs to this itemcase.
|
// If inventory belongs to this itemcase.
|
||||||
if(itemcase.getStorage().equals(event.getInventory())) {
|
if (itemcase.getStorage().equals(event.getInventory())) {
|
||||||
|
|
||||||
// Get world file.
|
// Get world file.
|
||||||
WorldFile file = ItemcaseManager.this.worldFiles.get(
|
WorldFile file = ItemcaseManager.this.worldFiles.get(
|
||||||
|
@ -14,15 +14,16 @@
|
|||||||
*/
|
*/
|
||||||
package com.gmail.bleedobsidian.itemcase.managers;
|
package com.gmail.bleedobsidian.itemcase.managers;
|
||||||
|
|
||||||
import com.gmail.bleedobsidian.itemcase.loggers.ChatLogger;
|
|
||||||
import com.gmail.bleedobsidian.itemcase.ItemCaseCore;
|
import com.gmail.bleedobsidian.itemcase.ItemCaseCore;
|
||||||
import com.gmail.bleedobsidian.itemcase.Itemcase;
|
import com.gmail.bleedobsidian.itemcase.Itemcase;
|
||||||
import com.gmail.bleedobsidian.itemcase.Itemcase.Type;
|
import com.gmail.bleedobsidian.itemcase.Itemcase.Type;
|
||||||
import com.gmail.bleedobsidian.itemcase.LanguageTranslator;
|
import com.gmail.bleedobsidian.itemcase.LanguageTranslator;
|
||||||
import java.util.HashMap;
|
import com.gmail.bleedobsidian.itemcase.loggers.ChatLogger;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages all active Itemcase orders.
|
* Manages all active Itemcase orders.
|
||||||
*
|
*
|
||||||
@ -33,7 +34,7 @@ public final class OrderManager {
|
|||||||
/**
|
/**
|
||||||
* HashMap of players and their active orders.
|
* HashMap of players and their active orders.
|
||||||
*/
|
*/
|
||||||
private final HashMap<Player, ItemcaseOrder> orders = new HashMap();
|
private final HashMap<Player, ItemcaseOrder> orders = new HashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new order.
|
* Create new order.
|
||||||
@ -60,7 +61,7 @@ public final class OrderManager {
|
|||||||
chatLogger.message(player, "---------- Order ----------");
|
chatLogger.message(player, "---------- Order ----------");
|
||||||
|
|
||||||
// If item has custom display name.
|
// If item has custom display name.
|
||||||
if(itemcase.getItemStack().getItemMeta().hasDisplayName()) {
|
if (itemcase.getItemStack().getItemMeta().hasDisplayName()) {
|
||||||
|
|
||||||
// Set placeholder.
|
// Set placeholder.
|
||||||
translator.setPlaceholder("%ITEM_NAME%",
|
translator.setPlaceholder("%ITEM_NAME%",
|
||||||
@ -84,7 +85,7 @@ public final class OrderManager {
|
|||||||
chatLogger.message(player, "order.amount");
|
chatLogger.message(player, "order.amount");
|
||||||
|
|
||||||
// If shop buys products.
|
// If shop buys products.
|
||||||
if(itemcase.getType() == Type.SHOP_BUY ||
|
if (itemcase.getType() == Type.SHOP_BUY ||
|
||||||
itemcase.getType() == Type.SHOP_MULTI) {
|
itemcase.getType() == Type.SHOP_MULTI) {
|
||||||
|
|
||||||
// Set placeholder.
|
// Set placeholder.
|
||||||
@ -96,7 +97,7 @@ public final class OrderManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If shop sells products.
|
// If shop sells products.
|
||||||
if(itemcase.getType() == Type.SHOP_SELL ||
|
if (itemcase.getType() == Type.SHOP_SELL ||
|
||||||
itemcase.getType() == Type.SHOP_MULTI) {
|
itemcase.getType() == Type.SHOP_MULTI) {
|
||||||
|
|
||||||
// Set placeholder.
|
// Set placeholder.
|
||||||
@ -152,7 +153,7 @@ public final class OrderManager {
|
|||||||
/**
|
/**
|
||||||
* An order for a specific itemcase of some amount.
|
* An order for a specific itemcase of some amount.
|
||||||
*/
|
*/
|
||||||
public final class ItemcaseOrder {
|
public static final class ItemcaseOrder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The itemcase this order is for.
|
* The itemcase this order is for.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#-------------------- ItemCase Configuration File --------------------#
|
#-------------------- ItemCase Configuration File -----------------#
|
||||||
# This file contains all of the ItemCase configuration settings that #
|
# This file contains all the ItemCase configuration settings that #
|
||||||
# can be altered. #
|
# can be altered. #
|
||||||
#---------------------------------------------------------------------#
|
#------------------------------------------------------------------#
|
||||||
|
|
||||||
# Locale:
|
# Locale:
|
||||||
# - EN
|
# - EN
|
||||||
@ -10,7 +10,55 @@ Locale: EN
|
|||||||
# Materials that can be used for ItemCases.
|
# Materials that can be used for ItemCases.
|
||||||
# https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html
|
# https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html
|
||||||
Materials:
|
Materials:
|
||||||
- 'STEP' # Slabs.
|
- 'ACACIA_SLAB'
|
||||||
- 'STONE_SLAB2' # Red Sandstone Slabs.
|
- 'ANDESITE_SLAB'
|
||||||
- 'WOOD_STEP' # Wooden Slabs.
|
- 'BIRCH_SLAB'
|
||||||
- 'PURPUR_SLAB' # Purpur Slabs.
|
- 'BLACKSTONE_SLAB'
|
||||||
|
- 'BRICK_SLAB'
|
||||||
|
- 'COBBLED_DEEPSLATE_SLAB'
|
||||||
|
- 'COBBLESTONE_SLAB'
|
||||||
|
- 'CRIMSON_SLAB'
|
||||||
|
- 'CUT_COPPER_SLAB'
|
||||||
|
- 'CUT_RED_SANDSTONE_SLAB'
|
||||||
|
- 'CUT_SANDSTONE_SLAB'
|
||||||
|
- 'DARK_OAK_SLAB'
|
||||||
|
- 'DARK_PRISMARINE_SLAB'
|
||||||
|
- 'DEEPSLATE_BRICK_SLAB'
|
||||||
|
- 'DEEPSLATE_TILE_SLAB'
|
||||||
|
- 'DIORITE_SLAB'
|
||||||
|
- 'END_STONE_BRICK_SLAB'
|
||||||
|
- 'EXPOSED_CUT_COPPER_SLAB'
|
||||||
|
- 'GRANITE_SLAB'
|
||||||
|
- 'JUNGLE_SLAB'
|
||||||
|
- 'MOSSY_COBBLESTONE_SLAB'
|
||||||
|
- 'MOSSY_STONE_BRICK_SLAB'
|
||||||
|
- 'NETHER_BRICK_SLAB'
|
||||||
|
- 'OAK_SLAB'
|
||||||
|
- 'OXIDIZED_CUT_COPPER_SLAB'
|
||||||
|
- 'PETRIFIED_OAK_SLAB'
|
||||||
|
- 'POLISHED_ANDESITE_SLAB'
|
||||||
|
- 'POLISHED_BLACKSTONE_BRICK_SLAB'
|
||||||
|
- 'POLISHED_BLACKSTONE_SLAB'
|
||||||
|
- 'POLISHED_DEEPSLATE_SLAB'
|
||||||
|
- 'POLISHED_DIORITE_SLAB'
|
||||||
|
- 'POLISHED_GRANITE_SLAB'
|
||||||
|
- 'PRISMARINE_BRICK_SLAB'
|
||||||
|
- 'PRISMARINE_SLAB'
|
||||||
|
- 'PURPUR_SLAB'
|
||||||
|
- 'QUARTZ_SLAB'
|
||||||
|
- 'RED_NETHER_BRICK_SLAB'
|
||||||
|
- 'RED_SANDSTONE_SLAB'
|
||||||
|
- 'SANDSTONE_SLAB'
|
||||||
|
- 'SMOOTH_QUARTZ_SLAB'
|
||||||
|
- 'SMOOTH_RED_SANDSTONE_SLAB'
|
||||||
|
- 'SMOOTH_SANDSTONE_SLAB'
|
||||||
|
- 'SMOOTH_STONE_SLAB'
|
||||||
|
- 'SPRUCE_SLAB'
|
||||||
|
- 'STONE_BRICK_SLAB'
|
||||||
|
- 'STONE_SLAB'
|
||||||
|
- 'WARPED_SLAB'
|
||||||
|
- 'WAXED_CUT_COPPER_SLAB'
|
||||||
|
- 'WAXED_EXPOSED_CUT_COPPER_SLAB'
|
||||||
|
- 'WAXED_OXIDIZED_CUT_COPPER_SLAB'
|
||||||
|
- 'WAXED_WEATHERED_CUT_COPPER_SLAB'
|
||||||
|
- 'WEATHERED_CUT_COPPER_SLAB'
|
@ -2,4 +2,4 @@
|
|||||||
# Server must be stopped while changes are made to this file #
|
# Server must be stopped while changes are made to this file #
|
||||||
# otherwise they will be overwritten. #
|
# otherwise they will be overwritten. #
|
||||||
|
|
||||||
itemcases: {}
|
itemcases: { }
|
@ -1,10 +1,12 @@
|
|||||||
name: ItemCase
|
name: ItemCase
|
||||||
version: 2.0.1
|
version: 3.0.0
|
||||||
description: ItemCase is a Bukkit plugin allowing you to showcase items on slabs, that can also be used as shops.
|
description: ItemCase is a Bukkit plugin allowing you to showcase items on slabs, that can also be used as shops.
|
||||||
load: POSTWORLD
|
load: POSTWORLD
|
||||||
softdepend: [WorldGuard, Vault]
|
softdepend: [ WorldGuard, Vault, Multiverse-Core ]
|
||||||
author: BleedObsidian
|
author: EpicKnarvik97
|
||||||
website: http://dev.bukkit.org/bukkit-plugins/itemcase/
|
authors: [ BleedObsidian, EpicKnarvik97 ]
|
||||||
|
website: https://git.knarcraft.net
|
||||||
|
api-version: 1.17
|
||||||
database: false
|
database: false
|
||||||
prefix: ItemCase
|
prefix: ItemCase
|
||||||
|
|
||||||
@ -12,7 +14,7 @@ main: com.gmail.bleedobsidian.itemcase.ItemCaseCore
|
|||||||
|
|
||||||
commands:
|
commands:
|
||||||
itemcase:
|
itemcase:
|
||||||
aliases: [itemc, ic]
|
aliases: [ itemc, ic ]
|
||||||
description: "Showcase items on slabs, that can also be used as shops."
|
description: "Showcase items on slabs, that can also be used as shops."
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
|
@ -1,245 +0,0 @@
|
|||||||
/*
|
|
||||||
* ItemCase is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/gpl.html>.
|
|
||||||
*/
|
|
||||||
package com.gmail.bleedobsidian.itemcase;
|
|
||||||
|
|
||||||
import com.gmail.bleedobsidian.itemcase.Itemcase.ItemcaseTask;
|
|
||||||
import com.gmail.bleedobsidian.itemcase.Itemcase.Type;
|
|
||||||
import org.bukkit.Chunk;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import static org.mockito.Matchers.any;
|
|
||||||
import static org.mockito.Matchers.anyInt;
|
|
||||||
import static org.mockito.Matchers.anyString;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
import org.powermock.api.mockito.PowerMockito;
|
|
||||||
import static org.powermock.api.mockito.PowerMockito.whenNew;
|
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unit test for {@link com.gmail.bleedobsidian.itemcase.Itemcase}
|
|
||||||
*
|
|
||||||
* @author Jesse Prescott (BleedObsidian).
|
|
||||||
*/
|
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
|
||||||
@PrepareForTest(Itemcase.class)
|
|
||||||
public class ItemcaseTest {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The material of the itemcase
|
|
||||||
*/
|
|
||||||
private Material itemcaseMaterial;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a valid itemcase.
|
|
||||||
*
|
|
||||||
* @return Itemcase.
|
|
||||||
*/
|
|
||||||
private Itemcase createValidItemcase() throws Exception {
|
|
||||||
|
|
||||||
// Itemcase type.
|
|
||||||
Type type = Type.SHOP_MULTI;
|
|
||||||
|
|
||||||
// Mock ItemMeta.
|
|
||||||
ItemMeta meta = PowerMockito.mock(ItemMeta.class);
|
|
||||||
|
|
||||||
// Mock itemstack.
|
|
||||||
ItemStack itemstack = PowerMockito.mock(ItemStack.class);
|
|
||||||
|
|
||||||
// When clone method is called, return mock itemstack.
|
|
||||||
when(itemstack.clone()).thenReturn(itemstack);
|
|
||||||
|
|
||||||
// Return mock item meta.
|
|
||||||
when(itemstack.getItemMeta()).thenReturn(meta);
|
|
||||||
|
|
||||||
// Mock world.
|
|
||||||
World world = PowerMockito.mock(World.class);
|
|
||||||
|
|
||||||
// Mock block.
|
|
||||||
Block block = PowerMockito.mock(Block.class);
|
|
||||||
|
|
||||||
// Return material.
|
|
||||||
when(block.getType()).thenReturn(this.itemcaseMaterial);
|
|
||||||
|
|
||||||
// Mock location.
|
|
||||||
Location location = PowerMockito.mock(Location.class);
|
|
||||||
|
|
||||||
// Return mock world when asked for.
|
|
||||||
when(location.getWorld()).thenReturn(world);
|
|
||||||
|
|
||||||
// Return mock block.
|
|
||||||
when(location.getBlock()).thenReturn(block);
|
|
||||||
|
|
||||||
// Mock chunk.
|
|
||||||
Chunk chunk = PowerMockito.mock(Chunk.class);
|
|
||||||
|
|
||||||
// When asking for the chunk from location, return mock.
|
|
||||||
when(location.getChunk()).thenReturn(chunk);
|
|
||||||
|
|
||||||
// Mock player.
|
|
||||||
OfflinePlayer player = PowerMockito.mock(OfflinePlayer.class);
|
|
||||||
|
|
||||||
// Create new itemcase to test.
|
|
||||||
Itemcase itemcase = new Itemcase(type, itemstack, location, player);
|
|
||||||
|
|
||||||
// Test type is correct.
|
|
||||||
assertEquals(itemcase.getType(), type);
|
|
||||||
|
|
||||||
// Test itemstack is correct.
|
|
||||||
assertEquals(itemcase.getItemStack(), itemstack);
|
|
||||||
|
|
||||||
// Verify itemstack amount was set to 1.
|
|
||||||
verify(itemstack).setAmount(1);
|
|
||||||
|
|
||||||
// Test owner is correct.
|
|
||||||
assertEquals(itemcase.getOwner(), player);
|
|
||||||
|
|
||||||
// Return itemcase.
|
|
||||||
return itemcase;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void constructor_valid_pass() throws Exception {
|
|
||||||
|
|
||||||
// Create itemcase.
|
|
||||||
Itemcase itemcase = this.createValidItemcase();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
|
||||||
public void constructor_nullType_exception() {
|
|
||||||
|
|
||||||
// Mock itemstack.
|
|
||||||
ItemStack itemstack = PowerMockito.mock(ItemStack.class);
|
|
||||||
|
|
||||||
// When clone method is called, return mock itemstack.
|
|
||||||
when(itemstack.clone()).thenReturn(itemstack);
|
|
||||||
|
|
||||||
// Mock location.
|
|
||||||
Location location = PowerMockito.mock(Location.class);
|
|
||||||
|
|
||||||
// Mock chunk.
|
|
||||||
Chunk chunk = PowerMockito.mock(Chunk.class);
|
|
||||||
|
|
||||||
// When asking for the chunk from location, return mock.
|
|
||||||
when(location.getChunk()).thenReturn(chunk);
|
|
||||||
|
|
||||||
// Mock player.
|
|
||||||
OfflinePlayer player = PowerMockito.mock(OfflinePlayer.class);
|
|
||||||
|
|
||||||
// Create object.
|
|
||||||
new Itemcase(null, itemstack, location, player);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
|
||||||
public void constructor_nullItemStack_exception() {
|
|
||||||
|
|
||||||
// Itemcase type.
|
|
||||||
Type type = Type.SHOP_MULTI;
|
|
||||||
|
|
||||||
// Mock location.
|
|
||||||
Location location = PowerMockito.mock(Location.class);
|
|
||||||
|
|
||||||
// Mock chunk.
|
|
||||||
Chunk chunk = PowerMockito.mock(Chunk.class);
|
|
||||||
|
|
||||||
// When asking for the chunk from location, return mock.
|
|
||||||
when(location.getChunk()).thenReturn(chunk);
|
|
||||||
|
|
||||||
// Mock player.
|
|
||||||
OfflinePlayer player = PowerMockito.mock(OfflinePlayer.class);
|
|
||||||
|
|
||||||
// Create itemcase.
|
|
||||||
new Itemcase(type, null, location, player);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
|
||||||
public void constructor_nullLocation_exception() {
|
|
||||||
|
|
||||||
// Itemcase type.
|
|
||||||
Type type = Type.SHOP_MULTI;
|
|
||||||
|
|
||||||
// Mock itemstack.
|
|
||||||
ItemStack itemstack = PowerMockito.mock(ItemStack.class);
|
|
||||||
|
|
||||||
// When clone method is called, return mock itemstack.
|
|
||||||
when(itemstack.clone()).thenReturn(itemstack);
|
|
||||||
|
|
||||||
// Mock player.
|
|
||||||
OfflinePlayer player = PowerMockito.mock(OfflinePlayer.class);
|
|
||||||
|
|
||||||
// Create itemcase.
|
|
||||||
new Itemcase(type, itemstack, null, player);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
|
||||||
public void constructor_nullOwner_exception() {
|
|
||||||
|
|
||||||
// Itemcase type.
|
|
||||||
Type type = Type.SHOP_MULTI;
|
|
||||||
|
|
||||||
// Mock itemstack.
|
|
||||||
ItemStack itemstack = PowerMockito.mock(ItemStack.class);
|
|
||||||
|
|
||||||
// When clone method is called, return mock itemstack.
|
|
||||||
when(itemstack.clone()).thenReturn(itemstack);
|
|
||||||
|
|
||||||
// Mock location.
|
|
||||||
Location location = PowerMockito.mock(Location.class);
|
|
||||||
|
|
||||||
// Mock chunk.
|
|
||||||
Chunk chunk = PowerMockito.mock(Chunk.class);
|
|
||||||
|
|
||||||
// When asking for the chunk from location, return mock.
|
|
||||||
when(location.getChunk()).thenReturn(chunk);
|
|
||||||
|
|
||||||
// Create itemcase.
|
|
||||||
new Itemcase(type, itemstack, location, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void spawnItem_taskStarted_pass() throws Exception {
|
|
||||||
|
|
||||||
// Create valid itemcase.
|
|
||||||
Itemcase itemcase = this.createValidItemcase();
|
|
||||||
|
|
||||||
// Create mock bukkit runnable.
|
|
||||||
ItemcaseTask runnable = PowerMockito.mock(ItemcaseTask.class);
|
|
||||||
|
|
||||||
// When creating a new bukkit runnable (as done so inside of spawnItem
|
|
||||||
// return a mock.
|
|
||||||
whenNew(ItemcaseTask.class).withAnyArguments().thenReturn(runnable);
|
|
||||||
|
|
||||||
// Pretend chunk is loaded.
|
|
||||||
when(itemcase.getLocation().getWorld().isChunkLoaded(
|
|
||||||
any(Chunk.class))).thenReturn(true);
|
|
||||||
|
|
||||||
// Spawn item.
|
|
||||||
itemcase.spawnItem();
|
|
||||||
|
|
||||||
// verify task was started.
|
|
||||||
verify(runnable)
|
|
||||||
.runTaskTimer(any(JavaPlugin.class), anyInt(), anyInt());
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user