Makes ItemCase compile for Minecraft 1.17

This commit is contained in:
Kristian Knarvik 2021-10-27 17:27:34 +02:00
parent a9f1d9e5e7
commit 90b0223d8d
28 changed files with 1671 additions and 1989 deletions

View File

@ -21,6 +21,7 @@ ItemCase uses Maven to handle its dependencies.
Coding and Pull Request Formatting
----------------------------------
* Generally follow the Oracle coding standards.
* Use spaces not tabs.
* 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.**
[License]: http://www.gnu.org/licenses/gpl.html
[GitHub]: http://github.com/BleedObsidian/ItemCase/
[Bukkit]: http://dev.bukkit.org/bukkit-plugins/itemcase/
[Javadoc]: http://bleedobsidian.github.io/ItemCase/

96
pom.xml
View File

@ -1,36 +1,38 @@
<?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>
<groupId>com.gmail.bleedobsidian</groupId>
<artifactId>ItemCase</artifactId>
<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>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
</properties>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
<id>sk89q-repo</id>
<url>https://maven.enginehub.org/repo/</url>
</repository>
<repository>
<id>bstats-repo</id>
<url>http://repo.bstats.org/content/repositories/releases/</url>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
<repository>
<id>vault-repo</id>
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
</repository>
<repository>
<id>sk89q-repo</id>
<url>http://maven.sk89q.com/repo/</url>
<id>OnARandomBox</id>
<url>https://repo.onarandombox.com/content/groups/public/</url>
</repository>
</repositories>
@ -38,48 +40,25 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.12.2-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>
<version>1.17.1-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.onarandombox.multiversecore</groupId>
<artifactId>Multiverse-Core</artifactId>
<version>2.5.0</version>
<version>4.3.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.6</version>
<version>1.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard</artifactId>
<version>6.2.1</version>
</dependency>
<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>
<artifactId>worldguard-bukkit</artifactId>
<version>7.0.7-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
@ -110,52 +89,19 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<version>3.8.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<version>3.2.0</version>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
</configuration>
</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>
</build>
</project>

View File

@ -30,5 +30,5 @@ public interface Command {
* @param label The label used,
* @param args Any arguments.
*/
public void execute(CommandSender sender, String label, String[] args);
void execute(CommandSender sender, String label, String[] args);
}

View File

@ -14,17 +14,18 @@
*/
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.ModifyCommand;
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.StorageCommand;
import com.gmail.bleedobsidian.itemcase.loggers.ChatLogger;
import com.gmail.bleedobsidian.itemcase.loggers.GenericLogger;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
/**
* The central command handler for all ItemCase commands.
@ -34,11 +35,11 @@ import org.bukkit.entity.Player;
public final class CommandHandler implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command,
String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
// Check we have atleast 1 argument (sub-command label).
if(args.length <= 0) {
if (args.length <= 0) {
// Show help message.
this.showHelp(sender, label);
@ -48,7 +49,7 @@ public final class CommandHandler implements CommandExecutor {
}
// Direct sub-command to corresponding command handler.
switch(args[0]) {
switch (args[0]) {
case "create":
new CreateCommand().execute(sender, label, args);
@ -94,10 +95,9 @@ public final class CommandHandler implements CommandExecutor {
String command = "/" + label + " [create/order/destroy/modify/storage]";
// Check if sender is a player or console.
if(sender instanceof Player) {
if (sender instanceof Player player) {
// Cast sender to player.
Player player = (Player) sender;
// Get chat logger.
ChatLogger logger = ItemCaseCore.instance.getChatLogger();

View File

@ -14,15 +14,16 @@
*/
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.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Files;
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.
@ -39,12 +40,12 @@ public class ConfigurationFile {
/**
* The name of this configuration file.
*/
private String name;
private final String name;
/**
* 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.
@ -91,18 +92,17 @@ public class ConfigurationFile {
* does not exist, it is copied from the plugins jar.
*
* @param plugin JavaPlugin.
* @throws IOException.
*/
public void load(JavaPlugin plugin) throws IOException {
// If this configuration file can be copied outside of the jar...
if(this.canCopy) {
if (this.canCopy) {
// Create file reference.
File fileReference = new File(plugin.getDataFolder(), this.name);
// If the file doesn't exist...
if(!fileReference.exists() && this.canCopy) {
if (!fileReference.exists() && this.canCopy) {
// Copy default config from jar to data folder.
this.copyDefault(plugin);
@ -145,7 +145,6 @@ public class ConfigurationFile {
* jar to the data folder.
*
* @param plugin JavaPlugin.
* @throws IOException.
*/
private void copyDefault(JavaPlugin plugin) throws IOException {
@ -156,7 +155,7 @@ public class ConfigurationFile {
InputStream inputStream = plugin.getResource(this.defaultName);
// Check if we succeeded.
if(inputStream == null) {
if (inputStream == null) {
// Throw exception.
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.
*
* @param plugin Plugin.
* @throws IOException.
*/
public void save(JavaPlugin plugin) throws IOException {
// If this configuration file can not be copied outside of the jar...
if(!this.canCopy) {
if (!this.canCopy) {
// Exit.
return;

View File

@ -37,14 +37,14 @@ public final class InventoryUtils {
int stock = 0;
// For every itemstack.
for(ItemStack content : inventory.getContents()) {
for (ItemStack content : inventory.getContents()) {
// If content is null, skip.
if(content == null)
if (content == null)
continue;
// If itemstacks match.
if(content.isSimilar(itemstack)) {
if (content.isSimilar(itemstack)) {
// Add amount to stock.
stock += content.getAmount();

View File

@ -15,20 +15,21 @@
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.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.OrderManager;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import java.io.IOException;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.IOException;
/**
* ItemCase is a Bukkit plugin allowing you to showcase items on slabs, that
* can also be used as shops.
@ -104,9 +105,6 @@ public final class ItemCaseCore extends JavaPlugin {
// Set current instance.
ItemCaseCore.instance = this;
// Start metrics.
PluginMetrics metrics = new PluginMetrics(this);
// Attempt to load configuration file.
try {
@ -123,7 +121,7 @@ public final class ItemCaseCore extends JavaPlugin {
}
// 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.
return;
@ -178,7 +176,7 @@ public final class ItemCaseCore extends JavaPlugin {
private void loadVault() {
// Check if this server has Vault installed.
if(getServer().getPluginManager().getPlugin("Vault") == null) {
if (getServer().getPluginManager().getPlugin("Vault") == null) {
// Set false.
this.hasVault = false;
@ -192,7 +190,7 @@ public final class ItemCaseCore extends JavaPlugin {
getServer().getServicesManager().getRegistration(Economy.class);
// If could not find economy service provider.
if(rsp == null) {
if (rsp == null) {
// Set false.
this.hasVault = false;
@ -220,7 +218,7 @@ public final class ItemCaseCore extends JavaPlugin {
Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
// Check if the server has WorldGuard installed.
if(plugin == null) {
if (plugin == null) {
// Set false.
this.hasWorldGuard = false;
@ -240,7 +238,6 @@ public final class ItemCaseCore extends JavaPlugin {
}
/**
* @return Main ItemCase configuration file.
*/
public ConfigFile getConfigFile() {

View File

@ -16,15 +16,13 @@
package com.gmail.bleedobsidian.itemcase;
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.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.Tag;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
@ -45,6 +43,10 @@ import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.Collection;
import java.util.UUID;
/**
* Handler of an Itemcase.
*
@ -60,17 +62,17 @@ public final class Itemcase {
/**
* Types of Itemcase.
*/
public static enum Type {
public enum Type {
SHOWCASE,
SHOP_BUY,
SHOP_SELL,
SHOP_MULTI
};
}
/**
* Storage types.
*/
public static enum StorageType {
public enum StorageType {
FINITE,
INFINITE
}
@ -108,7 +110,7 @@ public final class Itemcase {
/**
* This itemcase's Type.
*/
private Type type = Type.SHOWCASE;
private Type type;
/**
* The storage type of this itemcase.
@ -176,7 +178,7 @@ public final class Itemcase {
World world = this.location.getWorld();
// 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
// ticks (10 secs).
@ -185,14 +187,14 @@ public final class Itemcase {
}
// 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.
return;
}
// If there was a display item previously.
if(this.displayItem != null) {
if (this.displayItem != null) {
// Remove this item.
this.displayItem.remove();
@ -207,7 +209,7 @@ public final class Itemcase {
// Set display name to random UUID to prevent graphical item stacking.
ItemMeta metadata = itemStack.getItemMeta();
metadata.setDisplayName("com.gmail.bleedobsidian.itemcase:" +
UUID.randomUUID().toString());
UUID.randomUUID());
itemStack.setItemMeta(metadata);
// Spawn the item.
@ -245,7 +247,7 @@ public final class Itemcase {
private static boolean isItemcaseDisplayItem(Item 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;
}
@ -255,7 +257,7 @@ public final class Itemcase {
// If display name does not have exactly two parts, it can't be a
// display item.
if(displayNameParts.length != 2) {
if (displayNameParts.length != 2) {
return false;
}
@ -271,7 +273,7 @@ public final class Itemcase {
public void takeStock(int amount) {
// If storage is infinite.
if(this.storageType == StorageType.INFINITE) {
if (this.storageType == StorageType.INFINITE) {
// Exit.
return;
@ -296,7 +298,7 @@ public final class Itemcase {
public void addStock(int amount) {
// If storage is infinite.
if(this.storageType == StorageType.INFINITE) {
if (this.storageType == StorageType.INFINITE) {
// Exit.
return;
@ -320,7 +322,7 @@ public final class Itemcase {
public boolean hasEnough(int amount) {
// If storage is infinite.
if(this.storageType == StorageType.INFINITE) {
if (this.storageType == StorageType.INFINITE) {
// Return true.
return true;
@ -399,7 +401,7 @@ public final class Itemcase {
public void setStorageType(StorageType storageType) {
// If toggling from finite to infinite.
if(this.storageType == StorageType.FINITE &&
if (this.storageType == StorageType.FINITE &&
storageType == StorageType.INFINITE) {
// Set storage.
@ -408,7 +410,7 @@ public final class Itemcase {
}
// 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) {
@ -483,13 +485,10 @@ public final class Itemcase {
Material type = this.location.getBlock().getType();
// The relative Y coordinate.
double relY = 0;
double relY;
// If block is a slab.
if(type == Material.STEP ||
type == Material.STONE_SLAB2 ||
type == Material.WOOD_STEP ||
type == Material.PURPUR_SLAB) {
if (Tag.SLABS.isTagged(type)) {
// Set relY.
relY = 0.6;
@ -501,14 +500,13 @@ public final class Itemcase {
// Create a location that is in the centre of the block and slightly
// above.
Location displayItemLocation = new Location(
// Return the default location to spawn the display item.
return new Location(
this.location.getWorld(),
this.location.getBlockX() + 0.5,
this.location.getBlockY() + relY,
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) {
// 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.
event.setCancelled(true);
@ -532,7 +530,7 @@ public final class Itemcase {
public void onItemDespawn(ItemDespawnEvent event) {
// If this item entity is a display item.
if(Itemcase.isItemcaseDisplayItem(event.getEntity())) {
if (Itemcase.isItemcaseDisplayItem(event.getEntity())) {
// Prevent this item from despawning.
event.setCancelled(true);
@ -547,10 +545,10 @@ public final class Itemcase {
ItemCaseCore.instance.getItemcaseManager();
// For every Itemcase.
for(Itemcase itemcase : itemcaseManager.getItemcases()) {
for (Itemcase itemcase : itemcaseManager.getItemcases()) {
// Check if this block was an itemcase.
if(itemcase.location.equals(event.getBlock().getLocation())) {
if (itemcase.location.equals(event.getBlock().getLocation())) {
// Cancel the event.
event.setCancelled(true);
@ -566,26 +564,23 @@ public final class Itemcase {
ItemCaseCore.instance.getItemcaseManager();
// For every Itemcase.
for(Itemcase itemcase : itemcaseManager.getItemcases()) {
for (Itemcase itemcase : itemcaseManager.getItemcases()) {
// Get block type.
Material type = itemcase.getLocation().getBlock().getType();
// 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.
event.setCancelled(true);
}
// If not a slab.
if(type != Material.STEP &&
type != Material.WOOD_STEP &&
type != Material.STONE_SLAB2 &&
type != Material.PURPUR_SLAB) {
if (Tag.SLABS.isTagged(type)) {
// 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())) {
// Cancel the event.
@ -599,35 +594,35 @@ public final class Itemcase {
public void onPlayerInteractEvent(PlayerInteractEvent event) {
// Check if block was involved.
if(!event.hasBlock()) {
if (!event.hasBlock()) {
// Exit.
return;
}
// Check if action was correct.
if(event.getAction() != Action.RIGHT_CLICK_BLOCK) {
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
// Exit.
return;
}
// If off-hand, skip.
if(event.getHand() == EquipmentSlot.OFF_HAND) {
if (event.getHand() == EquipmentSlot.OFF_HAND) {
// Exit.
return;
}
// If player is sneaking.
if(event.getPlayer().isSneaking()) {
if (event.getPlayer().isSneaking()) {
// Exit.
return;
}
// If block is not an ItemCase.
if(!ItemCaseCore.instance.getItemcaseManager().isItemcase(
if (!ItemCaseCore.instance.getItemcaseManager().isItemcase(
event.getClickedBlock().getLocation())) {
// Exit.
@ -639,7 +634,7 @@ public final class Itemcase {
.getItemcase(event.getClickedBlock().getLocation());
// If itemcase is not a shop.
if(itemcase.getType() == Type.SHOWCASE) {
if (itemcase.getType() == Type.SHOWCASE) {
// Exit.
return;
@ -660,7 +655,7 @@ public final class Itemcase {
* is particularly useful when servers use anti-lag plugins that forcibly
* 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.
@ -682,7 +677,7 @@ public final class Itemcase {
public void run() {
// If chunk is not currently loaded.
if(!this.itemcase.chunk.isLoaded()) {
if (!this.itemcase.chunk.isLoaded()) {
// Dont bother running this task.
return;
@ -696,7 +691,7 @@ public final class Itemcase {
ItemCaseCore.instance.getConfigFile().getMaterials();
// Check if this block still exists.
if(!materials.contains(location.getBlock().getType())) {
if (!materials.contains(location.getBlock().getType())) {
// Set to default.
location.getBlock().setType(materials.get(0));
@ -711,23 +706,22 @@ public final class Itemcase {
int numberOfItemcaseItems = 0;
// Loop through every entity.
for(Entity entity : entities) {
for (Entity entity : entities) {
// If the entity is not an item, skip.
if(!(entity instanceof Item)) {
if (!(entity instanceof Item)) {
continue;
}
// 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
// item.
Vector entityVector = (Vector) ((FixedMetadataValue)
entity.getMetadata("ItemCase").get(0)).value();
Vector entityVector = (Vector) entity.getMetadata("ItemCase").get(0).value();
// Check that the entity is an item for this itemcase only.
if(entityVector.getBlockX() !=
if (entityVector.getBlockX() !=
this.itemcase.location.getBlockX() ||
entityVector.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
// must have a duplicate caused by nms.
if(this.itemcase.getDisplayItem().getUniqueId().compareTo(
if (this.itemcase.getDisplayItem().getUniqueId().compareTo(
entity.getUniqueId()) != 0) {
// Remove this item.
@ -756,7 +750,7 @@ public final class Itemcase {
}
// 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
// restart hence no metadata.
@ -765,7 +759,7 @@ public final class Itemcase {
}
// 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
// (usually because of anti-lag plugins.)
@ -782,7 +776,7 @@ public final class Itemcase {
this.itemcase.getDisplayItemSpawnLocation();
// Check if the display item has for some reason moved.
if(x != displayItemSpawnLocation.getX() ||
if (x != displayItemSpawnLocation.getX() ||
y != displayItemSpawnLocation.getBlockY() ||
z != displayItemSpawnLocation.getZ()) {

View File

@ -15,10 +15,11 @@
package com.gmail.bleedobsidian.itemcase;
import com.gmail.bleedobsidian.itemcase.configurations.LanguageFile;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map.Entry;
import org.bukkit.plugin.java.JavaPlugin;
/**
* Utility class used for communicating in different dialects.
@ -30,9 +31,9 @@ public final class LanguageTranslator {
/**
* Supported languages.
*/
public static enum Language {
public enum Language {
EN
};
}
/**
* The language file for the chosen language.
@ -42,7 +43,7 @@ public final class LanguageTranslator {
/**
* A hash map of placeholders.
*/
private HashMap<String, String> placeholders = new HashMap<>();
private final HashMap<String, String> placeholders = new HashMap<>();
/**
* Load corresponding language file.
@ -88,7 +89,7 @@ public final class LanguageTranslator {
String translation = this.file.getRawTranslation(key);
// 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
// present in string.
@ -120,7 +121,7 @@ public final class LanguageTranslator {
public boolean isKey(String string) {
// 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;

View File

@ -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);
}
}

View File

@ -15,17 +15,19 @@
package com.gmail.bleedobsidian.itemcase.commands;
import com.gmail.bleedobsidian.itemcase.Command;
import com.gmail.bleedobsidian.itemcase.loggers.ChatLogger;
import com.gmail.bleedobsidian.itemcase.ItemCaseCore;
import com.gmail.bleedobsidian.itemcase.LanguageTranslator;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import java.util.ArrayList;
import com.gmail.bleedobsidian.itemcase.loggers.ChatLogger;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
/**
* A command handler for the 'create' command.
*
@ -38,7 +40,7 @@ public final class CreateCommand implements Command {
String[] args) {
// If sender is not a player.
if(!(sender instanceof Player)) {
if (!(sender instanceof Player player)) {
// Send message.
ItemCaseCore.instance.getGenericLogger().message(
@ -49,10 +51,9 @@ public final class CreateCommand implements Command {
}
// Cast sender to player.
Player player = (Player) sender;
// Check if player is asking for help.
if(this.isAskingForHelp(player, label, args)) {
if (this.isAskingForHelp(player, label, args)) {
// Exit.
return;
@ -62,7 +63,7 @@ public final class CreateCommand implements Command {
ChatLogger chatLogger = ItemCaseCore.instance.getChatLogger();
// Check if player has permission.
if(!player.hasPermission("itemcase.create")) {
if (!player.hasPermission("itemcase.create")) {
// Send message.
chatLogger.message(player, "command.permission");
@ -76,16 +77,16 @@ public final class CreateCommand implements Command {
ItemCaseCore.instance.getConfigFile().getMaterials();
// The target location.
Location target = null;
Location target;
// ItemStack to use.
ItemStack itemStack = null;
ItemStack itemStack;
// Get the players target block.
target = player.getTargetBlock(null, 5).getLocation();
// Check if itemcase already exists here.
if(ItemCaseCore.instance.getItemcaseManager().isItemcase(target)) {
if (ItemCaseCore.instance.getItemcaseManager().isItemcase(target)) {
// Show message.
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(!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.
chatLogger.message(player, "command.create.invalid-type");
@ -104,28 +107,20 @@ public final class CreateCommand implements Command {
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.
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(itemStack == null || itemStack.getType() == Material.AIR) {
if (itemStack.getType() == Material.AIR) {
// Show message.
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) {
// If args length equals 2.
if(args.length != 2) {
if (args.length != 2) {
// False.
return false;
@ -158,7 +153,7 @@ public final class CreateCommand implements Command {
String argument = args[1];
// If not equal to help.
if(!argument.equalsIgnoreCase("help")) {
if (!argument.equalsIgnoreCase("help")) {
return false;
}

View File

@ -15,10 +15,10 @@
package com.gmail.bleedobsidian.itemcase.commands;
import com.gmail.bleedobsidian.itemcase.Command;
import com.gmail.bleedobsidian.itemcase.loggers.ChatLogger;
import com.gmail.bleedobsidian.itemcase.ItemCaseCore;
import com.gmail.bleedobsidian.itemcase.Itemcase;
import com.gmail.bleedobsidian.itemcase.LanguageTranslator;
import com.gmail.bleedobsidian.itemcase.loggers.ChatLogger;
import com.gmail.bleedobsidian.itemcase.managers.ItemcaseManager;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
@ -37,7 +37,7 @@ public final class DestroyCommand implements Command {
String[] args) {
// If sender is not a player.
if(!(sender instanceof Player)) {
if (!(sender instanceof Player player)) {
// Send message.
ItemCaseCore.instance.getGenericLogger().message(
@ -48,10 +48,9 @@ public final class DestroyCommand implements Command {
}
// Cast sender to player.
Player player = (Player) sender;
// Check if player is asking for help.
if(this.isAskingForHelp(player, label, args)) {
if (this.isAskingForHelp(player, label, args)) {
// Exit.
return;
@ -61,7 +60,7 @@ public final class DestroyCommand implements Command {
ChatLogger chatLogger = ItemCaseCore.instance.getChatLogger();
// Check if player has permission (Uses create permission).
if(!player.hasPermission("itemcase.create")) {
if (!player.hasPermission("itemcase.create")) {
// Send message.
chatLogger.message(player, "command.permission");
@ -71,7 +70,7 @@ public final class DestroyCommand implements Command {
}
// The target location.
Location target = null;
Location target;
// Get ItemcaseManager.
ItemcaseManager manager = ItemCaseCore.instance.getItemcaseManager();
@ -80,7 +79,7 @@ public final class DestroyCommand implements Command {
target = player.getTargetBlock(null, 5).getLocation();
// Check this target is an itemcase.
if(!manager.isItemcase(target)) {
if (!manager.isItemcase(target)) {
// Show message.
chatLogger.message(player, "command.invalid-location");
@ -96,10 +95,10 @@ public final class DestroyCommand implements Command {
OfflinePlayer owner = itemcase.getOwner();
// 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.
if(!player.hasPermission("itemcase.destroy.other")) {
if (!player.hasPermission("itemcase.destroy.other")) {
// Show message.
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) {
// If args length equals 2.
if(args.length != 2) {
if (args.length != 2) {
// False.
return false;
@ -132,7 +131,7 @@ public final class DestroyCommand implements Command {
String argument = args[1];
// If not equal to help.
if(!argument.equalsIgnoreCase("help")) {
if (!argument.equalsIgnoreCase("help")) {
return false;
}

View File

@ -15,12 +15,12 @@
package com.gmail.bleedobsidian.itemcase.commands;
import com.gmail.bleedobsidian.itemcase.Command;
import com.gmail.bleedobsidian.itemcase.loggers.ChatLogger;
import com.gmail.bleedobsidian.itemcase.ItemCaseCore;
import com.gmail.bleedobsidian.itemcase.Itemcase;
import com.gmail.bleedobsidian.itemcase.Itemcase.StorageType;
import com.gmail.bleedobsidian.itemcase.Itemcase.Type;
import com.gmail.bleedobsidian.itemcase.LanguageTranslator;
import com.gmail.bleedobsidian.itemcase.loggers.ChatLogger;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
@ -39,7 +39,7 @@ public final class ModifyCommand implements Command {
String[] args) {
// If sender is not a player.
if(!(sender instanceof Player)) {
if (!(sender instanceof Player player)) {
// Send message.
ItemCaseCore.instance.getGenericLogger().message(
@ -50,17 +50,16 @@ public final class ModifyCommand implements Command {
}
// Cast sender to player.
Player player = (Player) sender;
// Check if player is asking for help.
if(this.isAskingForHelp(player, label, args)) {
if (this.isAskingForHelp(player, label, args)) {
// Exit.
return;
}
// If incorrect number of args.
if(args.length != 3) {
if (args.length != 3) {
// Show help.
this.showHelp(player, label);
@ -73,7 +72,7 @@ public final class ModifyCommand implements Command {
ChatLogger chatLogger = ItemCaseCore.instance.getChatLogger();
// Check if player has permission (Uses create permission).
if(!player.hasPermission("itemcase.create")) {
if (!player.hasPermission("itemcase.create")) {
// Send message.
chatLogger.message(player, "command.permission");
@ -83,13 +82,13 @@ public final class ModifyCommand implements Command {
}
// The target location.
Location target = null;
Location target;
// Get the players target block.
target = player.getTargetBlock(null, 5).getLocation();
// Check if itemcase exists here.
if(!ItemCaseCore.instance.getItemcaseManager().isItemcase(target)) {
if (!ItemCaseCore.instance.getItemcaseManager().isItemcase(target)) {
// Show message.
chatLogger.message(player, "command.invalid-location");
@ -106,10 +105,10 @@ public final class ModifyCommand implements Command {
OfflinePlayer owner = itemcase.getOwner();
// 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.
if(!player.hasPermission("itemcase.modify.other")) {
if (!player.hasPermission("itemcase.modify.other")) {
// Show message.
chatLogger.message(player, "command.not-owner");
@ -126,7 +125,7 @@ public final class ModifyCommand implements Command {
String value = args[2];
// Switch flag.
switch(flag.toLowerCase()) {
switch (flag.toLowerCase()) {
case "type":
this.typeFlag(label, player, itemcase, value);
break;
@ -163,20 +162,13 @@ public final class ModifyCommand implements Command {
ChatLogger chatLogger = ItemCaseCore.instance.getChatLogger();
// If the itemcase was a shop.
boolean wasShop = false;
// If the itemcase was a shop.
if(itemcase.getType() != Type.SHOWCASE) {
// Set boolean.
wasShop = true;
}
boolean wasShop = itemcase.getType() != Type.SHOWCASE;
// If the itemcase is now a shop.
boolean isNowShop = false;
// Switch value.
switch(value.toLowerCase()) {
switch (value.toLowerCase()) {
// Showcase.
case "showcase":
@ -191,7 +183,7 @@ public final class ModifyCommand implements Command {
case "shop_buy":
// Check if player has permission.
if(!player.hasPermission("itemcase.create.shop.buy")) {
if (!player.hasPermission("itemcase.create.shop.buy")) {
// Send message.
chatLogger.message(player, "command.permission");
@ -213,7 +205,7 @@ public final class ModifyCommand implements Command {
case "shop_sell":
// Check if player has permission.
if(!player.hasPermission("itemcase.create.shop.sell")) {
if (!player.hasPermission("itemcase.create.shop.sell")) {
// Send message.
chatLogger.message(player, "command.permission");
@ -235,7 +227,7 @@ public final class ModifyCommand implements Command {
case "shop_multi":
// 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")) {
// Send message.
@ -265,7 +257,7 @@ public final class ModifyCommand implements Command {
}
// If itemcase is now a shop but wasn't before.
if(isNowShop && !wasShop) {
if (isNowShop && !wasShop) {
// Set storage.
itemcase.setStorage(Bukkit.createInventory(
@ -294,7 +286,7 @@ public final class ModifyCommand implements Command {
ChatLogger chatLogger = ItemCaseCore.instance.getChatLogger();
// If itemcase is not a shop.
if(itemcase.getType() == Type.SHOWCASE) {
if (itemcase.getType() == Type.SHOWCASE) {
// Show message.
chatLogger.message(player, "command.not-shop");
@ -304,7 +296,7 @@ public final class ModifyCommand implements Command {
}
// Switch value.
switch(value.toLowerCase()) {
switch (value.toLowerCase()) {
// Finite.
case "finite":
@ -319,7 +311,7 @@ public final class ModifyCommand implements Command {
case "infinite":
// Check if player has permission.
if(!player.hasPermission("itemcase.create.shop.infinite")) {
if (!player.hasPermission("itemcase.create.shop.infinite")) {
// Send message.
chatLogger.message(player, "command.permission");
@ -366,7 +358,7 @@ public final class ModifyCommand implements Command {
ChatLogger chatLogger = ItemCaseCore.instance.getChatLogger();
// Check if player has permission.
if(!player.hasPermission("itemcase.create.shop.buy")) {
if (!player.hasPermission("itemcase.create.shop.buy")) {
// Send message.
chatLogger.message(player, "command.permission");
@ -376,7 +368,7 @@ public final class ModifyCommand implements Command {
}
// If itemcase is not a shop.
if(itemcase.getType() == Type.SHOWCASE) {
if (itemcase.getType() == Type.SHOWCASE) {
// Show message.
chatLogger.message(player, "command.not-shop");
@ -386,7 +378,7 @@ public final class ModifyCommand implements Command {
}
// If itemcase only sells items.
if(itemcase.getType() == Type.SHOP_SELL) {
if (itemcase.getType() == Type.SHOP_SELL) {
// Show message.
chatLogger.message(player, "command.modify.sell-only");
@ -436,7 +428,7 @@ public final class ModifyCommand implements Command {
ChatLogger chatLogger = ItemCaseCore.instance.getChatLogger();
// Check if player has permission.
if(!player.hasPermission("itemcase.create.shop.sell")) {
if (!player.hasPermission("itemcase.create.shop.sell")) {
// Send message.
chatLogger.message(player, "command.permission");
@ -446,7 +438,7 @@ public final class ModifyCommand implements Command {
}
// If itemcase is not a shop.
if(itemcase.getType() == Type.SHOWCASE) {
if (itemcase.getType() == Type.SHOWCASE) {
// Show message.
chatLogger.message(player, "command.not-shop");
@ -456,7 +448,7 @@ public final class ModifyCommand implements Command {
}
// If itemcase only buys items.
if(itemcase.getType() == Type.SHOP_BUY) {
if (itemcase.getType() == Type.SHOP_BUY) {
// Show message.
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) {
// If args length equals 2.
if(args.length != 2) {
if (args.length != 2) {
// False.
return false;
@ -507,7 +499,7 @@ public final class ModifyCommand implements Command {
String argument = args[1];
// If not equal to help.
if(!argument.equalsIgnoreCase("help")) {
if (!argument.equalsIgnoreCase("help")) {
return false;
}
@ -521,8 +513,6 @@ public final class ModifyCommand implements Command {
/**
* Show help for main command to given sender.
*
* @param sender CommandSender.
*/
private void showHelp(Player player, String label) {

View File

@ -15,12 +15,12 @@
package com.gmail.bleedobsidian.itemcase.commands;
import com.gmail.bleedobsidian.itemcase.Command;
import com.gmail.bleedobsidian.itemcase.loggers.ChatLogger;
import com.gmail.bleedobsidian.itemcase.ItemCaseCore;
import com.gmail.bleedobsidian.itemcase.Itemcase;
import com.gmail.bleedobsidian.itemcase.Itemcase.StorageType;
import com.gmail.bleedobsidian.itemcase.Itemcase.Type;
import com.gmail.bleedobsidian.itemcase.LanguageTranslator;
import com.gmail.bleedobsidian.itemcase.loggers.ChatLogger;
import com.gmail.bleedobsidian.itemcase.managers.OrderManager.ItemcaseOrder;
import net.md_5.bungee.api.ChatColor;
import net.milkbowl.vault.economy.Economy;
@ -42,7 +42,7 @@ public final class OrderCommand implements Command {
String[] args) {
// If sender is not a player.
if(!(sender instanceof Player)) {
if (!(sender instanceof Player player)) {
// Send message.
ItemCaseCore.instance.getGenericLogger().message(
@ -53,10 +53,9 @@ public final class OrderCommand implements Command {
}
// Cast sender to player.
Player player = (Player) sender;
// Check if player is asking for help.
if(this.isAskingForHelp(player, label, args)) {
if (this.isAskingForHelp(player, label, args)) {
// Exit.
return;
@ -66,7 +65,7 @@ public final class OrderCommand implements Command {
ChatLogger chatLogger = ItemCaseCore.instance.getChatLogger();
// If not enough arguments.
if(args.length < 2) {
if (args.length < 2) {
// Show help.
this.showHelp(player, label);
@ -76,7 +75,7 @@ public final class OrderCommand implements Command {
}
// Check if player has active order.
if(!ItemCaseCore.instance.getOrderManager().hasOrder(player)) {
if (!ItemCaseCore.instance.getOrderManager().hasOrder(player)) {
// Send message
chatLogger.message(player, "command.order.no-order");
@ -89,7 +88,7 @@ public final class OrderCommand implements Command {
String subCommand = args[1];
// Switch sub command.
switch(subCommand) {
switch (subCommand) {
case "buy":
this.executeBuy(player);
break;
@ -147,7 +146,7 @@ public final class OrderCommand implements Command {
public boolean isAskingForHelp(Player player, String label, String[] args) {
// If args length equals 2.
if(args.length != 2) {
if (args.length != 2) {
// False.
return false;
@ -157,7 +156,7 @@ public final class OrderCommand implements Command {
String argument = args[1];
// If not equal to help.
if(!argument.equalsIgnoreCase("help")) {
if (!argument.equalsIgnoreCase("help")) {
return false;
}
@ -183,7 +182,7 @@ public final class OrderCommand implements Command {
LanguageTranslator translator = ItemCaseCore.instance.getTranslator();
// Check if player has permission.
if(!player.hasPermission("itemcase.buy")) {
if (!player.hasPermission("itemcase.buy")) {
// Send message.
chatLogger.message(player, "command.permission");
@ -200,7 +199,7 @@ public final class OrderCommand implements Command {
Itemcase itemcase = order.getItemcase();
// If itemcase can not be bought from.
if(itemcase.getType() == Type.SHOP_SELL) {
if (itemcase.getType() == Type.SHOP_SELL) {
// Send message.
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.
if(!ItemCaseCore.instance.hasVault() &&
if (!ItemCaseCore.instance.hasVault() &&
order.getItemcase().getBuyPrice() > 0) {
// Show message.
@ -224,10 +223,10 @@ public final class OrderCommand implements Command {
ItemStack itemstack = itemcase.getItemStack().clone();
// If itemcase does not have enough items.
if(!itemcase.hasEnough(order.getAmount())) {
if (!itemcase.hasEnough(order.getAmount())) {
// If stock is 0.
if(itemcase.getStockLevel() == 0) {
if (itemcase.getStockLevel() == 0) {
// Send message.
chatLogger.message(player, "command.order.no-stock");
@ -255,7 +254,7 @@ public final class OrderCommand implements Command {
Economy economyProvider = ItemCaseCore.instance.getEconomyProvider();
// If total is greator than 0, vault must be used.
if(total == 0) {
if (total == 0) {
// Give player items.
itemstack.setAmount(order.getAmount());
@ -272,10 +271,10 @@ public final class OrderCommand implements Command {
String money = ChatColor.GOLD + economyProvider.format(total);
// If name exists.
if(!economyProvider.currencyNameSingular().equals("")) {
if (!economyProvider.currencyNameSingular().equals("")) {
// If greator than 1.
if(total > 1) {
if (total > 1) {
// Plural name.
money += " " + economyProvider.currencyNamePlural();
@ -293,7 +292,7 @@ public final class OrderCommand implements Command {
translator.setPlaceholder("%MONEY%", money);
// If player does not have enough money.
if(economyProvider.getBalance(player,
if (economyProvider.getBalance(player,
player.getWorld().getName()) < total) {
// Send message.
@ -308,7 +307,7 @@ public final class OrderCommand implements Command {
new EconomyResponse(0, 0, ResponseType.SUCCESS, null);
// If itemcase is not infinite.
if(itemcase.getStorageType() == StorageType.FINITE) {
if (itemcase.getStorageType() == StorageType.FINITE) {
// Deposit money to owner.
response1 = economyProvider.depositPlayer(
@ -321,7 +320,7 @@ public final class OrderCommand implements Command {
player, player.getWorld().getName(), total);
// If successful.
if(response1.transactionSuccess() && response2.transactionSuccess()) {
if (response1.transactionSuccess() && response2.transactionSuccess()) {
// Give player items.
itemstack.setAmount(order.getAmount());
@ -337,7 +336,7 @@ public final class OrderCommand implements Command {
chatLogger.message(player, "command.order.withdrew");
// If owner is online and itemcase is not infinite.
if(itemcase.getStorageType() == StorageType.FINITE &&
if (itemcase.getStorageType() == StorageType.FINITE &&
order.getItemcase().getOwner().isOnline()) {
// Get owner.
@ -347,7 +346,7 @@ public final class OrderCommand implements Command {
translator.setPlaceholder("%PLAYER%", player.getDisplayName());
// If item has custom display name.
if(itemcase.getItemStack().getItemMeta().hasDisplayName()) {
if (itemcase.getItemStack().getItemMeta().hasDisplayName()) {
// Set placeholder.
translator.setPlaceholder("%ITEM_NAME%",
@ -382,8 +381,6 @@ public final class OrderCommand implements Command {
* Execute sell command.
*
* @param player Player.
* @param label Label.
* @param args Arguments.
*/
private void executeSell(Player player) {
@ -394,7 +391,7 @@ public final class OrderCommand implements Command {
LanguageTranslator translator = ItemCaseCore.instance.getTranslator();
// Check if player has permission.
if(!player.hasPermission("itemcase.sell")) {
if (!player.hasPermission("itemcase.sell")) {
// Send message.
chatLogger.message(player, "command.permission");
@ -411,7 +408,7 @@ public final class OrderCommand implements Command {
Itemcase itemcase = order.getItemcase();
// If itemcase can not sell.
if(itemcase.getType() == Type.SHOP_BUY) {
if (itemcase.getType() == Type.SHOP_BUY) {
// Send message.
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.
if(!ItemCaseCore.instance.hasVault() &&
if (!ItemCaseCore.instance.hasVault() &&
order.getItemcase().getSellPrice() > 0) {
// Show message.
@ -435,7 +432,7 @@ public final class OrderCommand implements Command {
ItemStack itemstack = itemcase.getItemStack().clone();
// If player does not have enough items.
if(!player.getInventory().containsAtLeast(itemstack,
if (!player.getInventory().containsAtLeast(itemstack,
order.getAmount())) {
// Send message.
@ -452,7 +449,7 @@ public final class OrderCommand implements Command {
Economy economyProvider = ItemCaseCore.instance.getEconomyProvider();
// If total is greator than 0, vault must be used.
if(total == 0) {
if (total == 0) {
// Remove items from player.
itemstack.setAmount(order.getAmount());
@ -469,10 +466,10 @@ public final class OrderCommand implements Command {
String money = ChatColor.GOLD + economyProvider.format(total);
// If name exists.
if(!economyProvider.currencyNameSingular().equals("")) {
if (!economyProvider.currencyNameSingular().equals("")) {
// If greator than 1.
if(total > 1) {
if (total > 1) {
// Plural name.
money += " " + economyProvider.currencyNamePlural();
@ -490,7 +487,7 @@ public final class OrderCommand implements Command {
translator.setPlaceholder("%MONEY%", money);
// 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(),
player.getWorld().getName()) < total)) {
@ -506,7 +503,7 @@ public final class OrderCommand implements Command {
new EconomyResponse(0, 0, ResponseType.SUCCESS, null);
// If itemcase is not infinite.
if(itemcase.getStorageType() == StorageType.FINITE) {
if (itemcase.getStorageType() == StorageType.FINITE) {
// Withdraw money from owner.
response1 = economyProvider.withdrawPlayer(
@ -520,7 +517,7 @@ public final class OrderCommand implements Command {
player.getWorld().getName(), total);
// If successful.
if(response1.transactionSuccess() && response2.transactionSuccess()) {
if (response1.transactionSuccess() && response2.transactionSuccess()) {
// Remove items from player.
itemstack.setAmount(order.getAmount());
@ -536,7 +533,7 @@ public final class OrderCommand implements Command {
chatLogger.message(player, "command.order.deposit");
// If owner is online and itemcase is not infinite.
if(itemcase.getStorageType() == StorageType.FINITE &&
if (itemcase.getStorageType() == StorageType.FINITE &&
order.getItemcase().getOwner().isOnline()) {
// Get owner.
@ -546,7 +543,7 @@ public final class OrderCommand implements Command {
translator.setPlaceholder("%PLAYER%", player.getDisplayName());
// If item has custom display name.
if(itemcase.getItemStack().getItemMeta().hasDisplayName()) {
if (itemcase.getItemStack().getItemMeta().hasDisplayName()) {
// Set placeholder.
translator.setPlaceholder("%ITEM_NAME%",
@ -591,7 +588,7 @@ public final class OrderCommand implements Command {
ChatLogger chatLogger = ItemCaseCore.instance.getChatLogger();
// Check if player has permission.
if(!player.hasPermission("itemcase.buy") &&
if (!player.hasPermission("itemcase.buy") &&
!player.hasPermission("itemcase.sell")) {
// Send message.
@ -602,7 +599,7 @@ public final class OrderCommand implements Command {
}
// Check argument length.
if(args.length != 3) {
if (args.length != 3) {
// Show help.
this.showHelp(player, label);
@ -612,7 +609,7 @@ public final class OrderCommand implements Command {
}
// Define amount.
int amount = 0;
int amount;
// Attempt to parse amount.
try {
@ -620,7 +617,7 @@ public final class OrderCommand implements Command {
// Parse amount.
amount = Integer.parseInt(args[2]);
} catch(NumberFormatException e) {
} catch (NumberFormatException e) {
// Show message.
chatLogger.message(player, "command.order.invalid-amount");

View File

@ -15,12 +15,12 @@
package com.gmail.bleedobsidian.itemcase.commands;
import com.gmail.bleedobsidian.itemcase.Command;
import com.gmail.bleedobsidian.itemcase.loggers.ChatLogger;
import com.gmail.bleedobsidian.itemcase.ItemCaseCore;
import com.gmail.bleedobsidian.itemcase.Itemcase;
import com.gmail.bleedobsidian.itemcase.Itemcase.StorageType;
import com.gmail.bleedobsidian.itemcase.Itemcase.Type;
import com.gmail.bleedobsidian.itemcase.LanguageTranslator;
import com.gmail.bleedobsidian.itemcase.loggers.ChatLogger;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
@ -38,7 +38,7 @@ public final class StorageCommand implements Command {
String[] args) {
// If sender is not a player.
if(!(sender instanceof Player)) {
if (!(sender instanceof Player player)) {
// Send message.
ItemCaseCore.instance.getGenericLogger().message(
@ -49,10 +49,9 @@ public final class StorageCommand implements Command {
}
// Cast sender to player.
Player player = (Player) sender;
// Check if player is asking for help.
if(this.isAskingForHelp(player, label, args)) {
if (this.isAskingForHelp(player, label, args)) {
// Exit.
return;
@ -62,7 +61,7 @@ public final class StorageCommand implements Command {
ChatLogger chatLogger = ItemCaseCore.instance.getChatLogger();
// Check if player has permission.
if(!player.hasPermission("itemcase.create")) {
if (!player.hasPermission("itemcase.create")) {
// Send message.
chatLogger.message(player, "command.permission");
@ -72,13 +71,13 @@ public final class StorageCommand implements Command {
}
// The target location.
Location target = null;
Location target;
// Get the players target block.
target = player.getTargetBlock(null, 5).getLocation();
// Check if itemcase exists here.
if(!ItemCaseCore.instance.getItemcaseManager().isItemcase(target)) {
if (!ItemCaseCore.instance.getItemcaseManager().isItemcase(target)) {
// Show message.
chatLogger.message(player, "command.invalid-location");
@ -95,10 +94,10 @@ public final class StorageCommand implements Command {
OfflinePlayer owner = itemcase.getOwner();
// 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.
if(!player.hasPermission("itemcase.modify.other")) {
if (!player.hasPermission("itemcase.modify.other")) {
// Show message.
chatLogger.message(player, "command.not-owner");
@ -109,7 +108,7 @@ public final class StorageCommand implements Command {
}
// Check if itemcase is a shop.
if(itemcase.getType() == Type.SHOWCASE) {
if (itemcase.getType() == Type.SHOWCASE) {
// Show message.
chatLogger.message(player, "command.not-shop");
@ -119,7 +118,7 @@ public final class StorageCommand implements Command {
}
// If itemcase has infinite storage.
if(itemcase.getStorageType() == StorageType.INFINITE) {
if (itemcase.getStorageType() == StorageType.INFINITE) {
// Show message.
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) {
// If args length equals 2.
if(args.length != 2) {
if (args.length != 2) {
// False.
return false;
@ -148,7 +147,7 @@ public final class StorageCommand implements Command {
String argument = args[1];
// If not equal to help.
if(!argument.equalsIgnoreCase("help")) {
if (!argument.equalsIgnoreCase("help")) {
return false;
}

View File

@ -16,9 +16,10 @@ package com.gmail.bleedobsidian.itemcase.configurations;
import com.gmail.bleedobsidian.itemcase.ConfigurationFile;
import com.gmail.bleedobsidian.itemcase.LanguageTranslator.Language;
import java.util.ArrayList;
import org.bukkit.Material;
import java.util.ArrayList;
/**
* The main configuration file for ItemCase.
*
@ -62,7 +63,10 @@ public final class ConfigFile extends ConfigurationFile {
this.file.getStringList("Materials").forEach((id) -> {
// Add material to list.
materials.add(Material.getMaterial(id));
Material material = Material.getMaterial(id);
if (material != null) {
materials.add(material);
}
});
// Return list.

View File

@ -27,7 +27,7 @@ public final class LanguageFile extends ConfigurationFile {
/**
* Constructor.
*
* @param Language The language this file is for.
* @param language The language this file is for.
*/
public LanguageFile(Language language) {

View File

@ -19,6 +19,17 @@ import com.gmail.bleedobsidian.itemcase.ItemCaseCore;
import com.gmail.bleedobsidian.itemcase.Itemcase;
import com.gmail.bleedobsidian.itemcase.Itemcase.StorageType;
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.IOException;
import java.util.ArrayList;
@ -27,14 +38,6 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
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.
@ -66,7 +69,6 @@ public final class WorldFile extends ConfigurationFile {
* Saves the given Itemcase to config.
*
* @param itemcase Itemcase.
* @throws java.io.IOException
*/
public void saveItemcase(Itemcase itemcase) throws IOException {
@ -90,15 +92,14 @@ public final class WorldFile extends ConfigurationFile {
this.file.set(key + "itemstack", itemstack);
// If itemcase is a shop.
if(itemcase.getType() != Type.SHOWCASE) {
if (itemcase.getType() != Type.SHOWCASE) {
// Set storage type.
this.file.set(key + "shop.storage-type",
itemcase.getStorageType().name());
// If shop has finite storage.
if(itemcase.getStorageType() == StorageType.FINITE) {
if (itemcase.getStorageType() == StorageType.FINITE) {
// Serialize inventory.
Map<String, Object> inventory =
this.serializeInventory(itemcase.getStorage());
@ -108,7 +109,7 @@ public final class WorldFile extends ConfigurationFile {
}
// If this itemcase buys.
if(itemcase.getType() == Type.SHOP_BUY ||
if (itemcase.getType() == Type.SHOP_BUY ||
itemcase.getType() == Type.SHOP_MULTI) {
// Set buy price.
@ -116,7 +117,7 @@ public final class WorldFile extends ConfigurationFile {
}
// If this itemcase sells.
if(itemcase.getType() == Type.SHOP_SELL ||
if (itemcase.getType() == Type.SHOP_SELL ||
itemcase.getType() == Type.SHOP_MULTI) {
// Set sell price.
@ -136,7 +137,6 @@ public final class WorldFile extends ConfigurationFile {
* Deletes the given Itemcase from config.
*
* @param 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.
*
* @return Array list of loaded itemcases.
* @throws java.io.IOException
*/
public ArrayList<Itemcase> loadItemcases() throws IOException {
@ -167,14 +166,14 @@ public final class WorldFile extends ConfigurationFile {
this.load(ItemCaseCore.instance);
// 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).
Set<String> keys =
this.file.getConfigurationSection("itemcases").getKeys(false);
// For every key (itemcase).
for(String key : keys) {
for (String key : keys) {
// Split key by '/' to obtain individual coordinates.
String[] coordinates = key.split("/");
@ -201,8 +200,7 @@ public final class WorldFile extends ConfigurationFile {
// Get ItemStack.
Map<String, Object> itemstackMap =
this.file.getConfigurationSection(key + "itemstack")
.getValues(true);
this.file.getConfigurationSection(key + "itemstack").getValues(true);
ItemStack itemstack = ItemStack.deserialize(itemstackMap);
// Create itemcase object.
@ -212,7 +210,7 @@ public final class WorldFile extends ConfigurationFile {
itemcase.spawnItem();
// If itemcase is a shop.
if(type != Type.SHOWCASE) {
if (type != Type.SHOWCASE) {
// Get storage type.
StorageType storageType = StorageType.valueOf(
@ -222,9 +220,9 @@ public final class WorldFile extends ConfigurationFile {
itemcase.setStorageType(storageType);
// If itemcase has finite storage.
if(storageType == StorageType.FINITE) {
if (storageType == StorageType.FINITE) {
// Deserialse inventory.
// De-serialise inventory.
Inventory inventory = this.deserializeInventory(
this.file.getConfigurationSection(
key + "shop.storage").getValues(false));
@ -234,7 +232,7 @@ public final class WorldFile extends ConfigurationFile {
}
// 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.
double buyPrice =
@ -245,7 +243,7 @@ public final class WorldFile extends ConfigurationFile {
}
// 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.
double sellPrice =
@ -257,19 +255,17 @@ public final class WorldFile extends ConfigurationFile {
}
// Add to list.
itemcases.add(itemcase);
itemCases.add(itemcase);
}
// Return list of loaded itemcases.
return itemcases;
return itemCases;
}
/**
* Delete directory and config.
*
* @throws IOException
*/
public void deleteDirectory() throws IOException {
public void deleteDirectory() {
// Create file reference.
File fileReference = new File(ItemCaseCore.instance.getDataFolder(),
@ -279,7 +275,7 @@ public final class WorldFile extends ConfigurationFile {
this.file = null;
// 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) {
// Create map.
Map<String, Object> map = new HashMap();
Map<String, Object> map = new HashMap<>();
// Set size.
map.put("size", inventory.getSize());
// Set name.
map.put("name", inventory.getName());
map.put("name", ((Entity) inventory).getName());
// 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.
if (inventory.getItem(i) != null) {
@ -332,10 +328,10 @@ public final class WorldFile extends ConfigurationFile {
Inventory inventory = Bukkit.createInventory(null, size, name);
// For every map entry.
for(Entry<String, Object> entry : map.entrySet()) {
for (Entry<String, Object> entry : map.entrySet()) {
// Check entry is parameter.
if(entry.getKey().equals("size") ||
if (entry.getKey().equals("size") ||
entry.getKey().equals("name")) {
// Skip.
@ -349,8 +345,7 @@ public final class WorldFile extends ConfigurationFile {
MemorySection section = (MemorySection) entry.getValue();
// Deserialize item.
ItemStack item = ItemStack.deserialize((Map<String, Object>)
section.getValues(true));
ItemStack item = ItemStack.deserialize(section.getValues(true));
// Set item in slot.
inventory.setItem(slot, item);

View File

@ -56,7 +56,7 @@ public final class ChatLogger {
public void message(Player player, String string) {
// If string is a message key.
if(this.translator.isKey(string)) {
if (this.translator.isKey(string)) {
// Translate.
string = this.translator.getTranslation(string);

View File

@ -16,10 +16,11 @@
package com.gmail.bleedobsidian.itemcase.loggers;
import com.gmail.bleedobsidian.itemcase.LanguageTranslator;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.logging.Level;
import java.util.logging.LogRecord;
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
@ -67,7 +68,7 @@ public final class ConsoleLogger extends Logger {
String message = logRecord.getMessage();
// If message is a message key.
if(translator.isKey(message)) {
if (translator.isKey(message)) {
// Translate.
message = translator.getTranslation(message);

View File

@ -50,7 +50,7 @@ public final class GenericLogger {
public void message(CommandSender sender, String string) {
// If string is a message key.
if(this.translator.isKey(string)) {
if (this.translator.isKey(string)) {
// Translate.
string = this.translator.getTranslation(string);

View File

@ -20,10 +20,6 @@ import com.gmail.bleedobsidian.itemcase.Itemcase.StorageType;
import com.gmail.bleedobsidian.itemcase.Itemcase.Type;
import com.gmail.bleedobsidian.itemcase.configurations.WorldFile;
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.Location;
import org.bukkit.OfflinePlayer;
@ -35,6 +31,11 @@ import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.world.WorldLoadEvent;
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
* for loading and saving Itemcases to a config.
@ -59,7 +60,7 @@ public final class ItemcaseManager {
public void initialize() {
// For every currently loaded world.
for(World world : Bukkit.getWorlds()) {
for (World world : Bukkit.getWorlds()) {
// Request itemcases to be loaded.
this.loadItemcases(world);
@ -203,7 +204,7 @@ public final class ItemcaseManager {
public void unloadItemcases() {
// For every loaded itemcase.
for(Itemcase itemcase : this.itemcases) {
for (Itemcase itemcase : this.itemcases) {
// Despawn the item.
itemcase.despawnItem();
@ -232,10 +233,10 @@ public final class ItemcaseManager {
public boolean isItemcase(Location location) {
// For every itemcase.
for(Itemcase itemcase : this.itemcases) {
for (Itemcase itemcase : this.itemcases) {
// Check if location matches.
if(itemcase.getLocation().equals(location)) {
if (itemcase.getLocation().equals(location)) {
// Return true.
return true;
@ -255,10 +256,10 @@ public final class ItemcaseManager {
public Itemcase getItemcase(Location location) {
// For every itemcase.
for(Itemcase itemcase : this.itemcases) {
for (Itemcase itemcase : this.itemcases) {
// Check if location matches.
if(itemcase.getLocation().equals(location)) {
if (itemcase.getLocation().equals(location)) {
// Return itemcase.
return itemcase;
@ -304,14 +305,13 @@ public final class ItemcaseManager {
WorldFile worldFile = null;
// For every entry.
for(Entry<World, WorldFile> entry :
for (Entry<World, WorldFile> entry :
ItemcaseManager.this.worldFiles.entrySet()) {
// Check if world name matches.
if(entry.getKey().getName() == worldName) {
if (entry.getKey().getName().equals(worldName)) {
// Attempt to delete config.
try {
// Set world file.
worldFile = entry.getValue();
@ -319,13 +319,7 @@ public final class ItemcaseManager {
// Delete config.
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);
// List to store itemcases of this world.
ArrayList<Itemcase> itemcases = new ArrayList();
ArrayList<Itemcase> itemcases = new ArrayList<>();
// For every itemcase.
for(Itemcase itemcase : ItemcaseManager.this.itemcases) {
for (Itemcase itemcase : ItemcaseManager.this.itemcases) {
// Check if itemcase was in deleted world.
if(itemcase.getLocation().getWorld().getName() == worldName) {
if (itemcase.getLocation().getWorld().getName().equals(worldName)) {
// Despawn item.
itemcase.despawnItem();
@ -357,34 +351,34 @@ public final class ItemcaseManager {
public void onInventoryCloseEvent(InventoryCloseEvent event) {
// Get inventory name.
String name = event.getInventory().getName();
String name = event.getView().getTitle();
// If inventory is Itemcase inventory.
if(!name.equals(Itemcase.INVENTORY_NAME)) {
if (!name.equals(Itemcase.INVENTORY_NAME)) {
// Exit.
return;
}
// 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.getType() == Type.SHOWCASE) {
if (itemcase.getType() == Type.SHOWCASE) {
// Skip.
continue;
}
// If itemcase is inifinite, it wont have storage.
if(itemcase.getStorageType() == StorageType.INFINITE) {
if (itemcase.getStorageType() == StorageType.INFINITE) {
// Skip.
continue;
}
// If inventory belongs to this itemcase.
if(itemcase.getStorage().equals(event.getInventory())) {
if (itemcase.getStorage().equals(event.getInventory())) {
// Get world file.
WorldFile file = ItemcaseManager.this.worldFiles.get(

View File

@ -14,15 +14,16 @@
*/
package com.gmail.bleedobsidian.itemcase.managers;
import com.gmail.bleedobsidian.itemcase.loggers.ChatLogger;
import com.gmail.bleedobsidian.itemcase.ItemCaseCore;
import com.gmail.bleedobsidian.itemcase.Itemcase;
import com.gmail.bleedobsidian.itemcase.Itemcase.Type;
import com.gmail.bleedobsidian.itemcase.LanguageTranslator;
import java.util.HashMap;
import com.gmail.bleedobsidian.itemcase.loggers.ChatLogger;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import java.util.HashMap;
/**
* Manages all active Itemcase orders.
*
@ -33,7 +34,7 @@ public final class OrderManager {
/**
* 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.
@ -60,7 +61,7 @@ public final class OrderManager {
chatLogger.message(player, "---------- Order ----------");
// If item has custom display name.
if(itemcase.getItemStack().getItemMeta().hasDisplayName()) {
if (itemcase.getItemStack().getItemMeta().hasDisplayName()) {
// Set placeholder.
translator.setPlaceholder("%ITEM_NAME%",
@ -84,7 +85,7 @@ public final class OrderManager {
chatLogger.message(player, "order.amount");
// If shop buys products.
if(itemcase.getType() == Type.SHOP_BUY ||
if (itemcase.getType() == Type.SHOP_BUY ||
itemcase.getType() == Type.SHOP_MULTI) {
// Set placeholder.
@ -96,7 +97,7 @@ public final class OrderManager {
}
// If shop sells products.
if(itemcase.getType() == Type.SHOP_SELL ||
if (itemcase.getType() == Type.SHOP_SELL ||
itemcase.getType() == Type.SHOP_MULTI) {
// Set placeholder.
@ -152,7 +153,7 @@ public final class OrderManager {
/**
* An order for a specific itemcase of some amount.
*/
public final class ItemcaseOrder {
public static final class ItemcaseOrder {
/**
* The itemcase this order is for.

View File

@ -1,7 +1,7 @@
#-------------------- ItemCase Configuration File --------------------#
# This file contains all of the ItemCase configuration settings that #
#-------------------- ItemCase Configuration File -----------------#
# This file contains all the ItemCase configuration settings that #
# can be altered. #
#---------------------------------------------------------------------#
#------------------------------------------------------------------#
# Locale:
# - EN
@ -10,7 +10,55 @@ Locale: EN
# Materials that can be used for ItemCases.
# https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html
Materials:
- 'STEP' # Slabs.
- 'STONE_SLAB2' # Red Sandstone Slabs.
- 'WOOD_STEP' # Wooden Slabs.
- 'PURPUR_SLAB' # Purpur Slabs.
- 'ACACIA_SLAB'
- 'ANDESITE_SLAB'
- 'BIRCH_SLAB'
- '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'

View File

@ -2,4 +2,4 @@
# Server must be stopped while changes are made to this file #
# otherwise they will be overwritten. #
itemcases: {}
itemcases: { }

View File

@ -1,10 +1,12 @@
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.
load: POSTWORLD
softdepend: [WorldGuard, Vault]
author: BleedObsidian
website: http://dev.bukkit.org/bukkit-plugins/itemcase/
softdepend: [ WorldGuard, Vault, Multiverse-Core ]
author: EpicKnarvik97
authors: [ BleedObsidian, EpicKnarvik97 ]
website: https://git.knarcraft.net
api-version: 1.17
database: false
prefix: ItemCase
@ -12,7 +14,7 @@ main: com.gmail.bleedobsidian.itemcase.ItemCaseCore
commands:
itemcase:
aliases: [itemc, ic]
aliases: [ itemc, ic ]
description: "Showcase items on slabs, that can also be used as shops."
permissions:

View File

@ -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());
}
}