Prevent players from creating itemcases where ones already exist.

This commit is contained in:
Jesse Prescott 2018-05-31 14:52:21 +01:00
parent c8dca8dd3b
commit 75c0742b6d
3 changed files with 37 additions and 1 deletions

View File

@ -73,6 +73,16 @@ public final class CreateCommand implements Command {
// Get the players target block.
target = player.getTargetBlock(null, 3).getLocation();
// Check if itemcase already exists here.
if(ItemCaseCore.instance.getItemcaseManager().isItemcase(target)) {
// Show message.
chatLogger.message(player, "command.create.invalid-location");
// Exit.
return;
}
// If target block is not on the list of accepted materials.
if(!materials.contains(target.getBlock().getType())) {

View File

@ -24,7 +24,6 @@ import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@ -161,6 +160,29 @@ public final class ItemcaseManager {
new ItemcaseManagerListener(), ItemCaseCore.instance);
}
/**
* If the given location is an itemcase or not.
*
* @param location Location.
* @return Boolean.
*/
public boolean isItemcase(Location location) {
// For every itemcase.
for(Itemcase itemcase : this.itemcases) {
// Check if location matches.
if(itemcase.getLocation().equals(location)) {
// Return true.
return true;
}
}
// Otherwise return false.
return false;
}
/**
* @return A list of all active Itemcase instances.
*/

View File

@ -42,6 +42,10 @@ command:
# invalid block type.
invalid-type: "This block cannot be used for an ItemCase."
# Shown to the player when they try to make an itemcase where one
# already exists.
invalid-location: "An ItemCase already exists here."
# Shown to the player when they use the create command but they are not
# holding any item in their main hand.
main-hand: "You must be holding something in your main hand."