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,8 +35,8 @@ 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) {
@ -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,7 +92,6 @@ 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 {
@ -145,7 +145,6 @@ public class ConfigurationFile {
* jar to the data folder.
*
* @param plugin JavaPlugin.
* @throws IOException.
*/
private void copyDefault(JavaPlugin plugin) throws IOException {
@ -175,7 +174,6 @@ 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 {

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 {
@ -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.
@ -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.
@ -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;
}
/**
@ -579,10 +577,7 @@ public final class Itemcase {
}
// 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)
@ -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.
@ -723,8 +718,7 @@ public final class 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() !=

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.

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,7 +51,6 @@ 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)) {
@ -76,10 +77,10 @@ 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();
@ -96,6 +97,8 @@ public final class CreateCommand implements Command {
// If target block is not on the list of accepted materials.
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");

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,7 +48,6 @@ 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)) {
@ -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();

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,7 +50,6 @@ 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)) {
@ -83,7 +82,7 @@ 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();
@ -163,14 +162,7 @@ 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;
@ -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,7 +53,6 @@ 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)) {
@ -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) {
@ -612,7 +609,7 @@ public final class OrderCommand implements Command {
}
// Define amount.
int amount = 0;
int amount;
// Attempt to parse amount.
try {

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,7 +49,6 @@ 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)) {
@ -72,7 +71,7 @@ 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();

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 {
@ -98,7 +100,6 @@ public final class WorldFile extends ConfigurationFile {
// If shop has finite storage.
if (itemcase.getStorageType() == StorageType.FINITE) {
// Serialize inventory.
Map<String, Object> inventory =
this.serializeInventory(itemcase.getStorage());
@ -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,7 +166,7 @@ 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 =
@ -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.
@ -224,7 +222,7 @@ public final class WorldFile extends ConfigurationFile {
// If itemcase has finite storage.
if (storageType == StorageType.FINITE) {
// Deserialse inventory.
// De-serialise inventory.
Inventory inventory = this.deserializeInventory(
this.file.getConfigurationSection(
key + "shop.storage").getValues(false));
@ -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,13 +287,13 @@ 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++) {
@ -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

@ -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

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.
@ -308,10 +309,9 @@ public final class ItemcaseManager {
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) {
// 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,7 +351,7 @@ 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)) {

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.
@ -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

@ -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

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