Added sealing command

This commit is contained in:
Sn0wStorm 2020-04-08 11:34:18 +02:00
parent ce4e665fda
commit 0e5893472b
8 changed files with 54 additions and 12 deletions

View File

@ -62,6 +62,7 @@ Help_Player: '&6/brew <Spieler> <%Trunkenheit> [Qualität]&9 Setzt Trunkenheit (
Help_Reload: '&6/brew reload &9Config neuladen'
Help_Configname: '&6/brew ItemName &9Zeigt Name für die Config vom Item in der Hand'
Help_UnLabel: '&6/brew UnLabel &9Entfernt die genaue Beschriftung des Trankes'
Help_Seal: '&6/brew Seal &9Tränke für den Verkauf versiegeln'
Help_Wakeup: '&6/brew Wakeup List <Seite>&9 Listet alle Aufwachpunkte auf'
Help_WakeupAdd: '&6/brew Wakeup Add &9Setzt einen Aufwachpunkt and deiner Position'
Help_WakeupCheck: '&6/brew Wakeup Check &9Teleportiert zu allen Aufwachpunkten'

View File

@ -64,6 +64,7 @@ Help_Reload: '&6/brew reload &9Reload config'
Help_Configname: '&6/brew ItemName &9Display name of item in hand for the config'
Help_Static: '&6/brew static &9Make Brew static -> No further ageing or distilling'
Help_UnLabel: '&6/brew unlabel &9Removes the detailled label of a potion'
Help_Seal: '&6/brew seal &9Seal Brews for selling in shops'
Help_Wakeup: '&6/brew wakeup list <Page>&9 Lists all wakeup points'
Help_WakeupAdd: '&6/brew wakeup add &9Adds a wakeup point at your current position'
Help_WakeupCheck: '&6/brew wakeup check &9Teleports to all wakeup points'

View File

@ -37,6 +37,7 @@ permissions:
brewery.mod: true
brewery.cmd.info: true
brewery.cmd.infoOther: true
brewery.cmd.seal: true
brewery.cmd.player: true
brewery.cmd.create: true
brewery.cmd.copy: true
@ -60,6 +61,8 @@ permissions:
description: Information about your own drunkeness
brewery.cmd.infoOther:
description: Information about the drunkeness of another Player
brewery.cmd.seal:
description: Open the Brew Sealer by command
brewery.cmd.player:
description: Set Player-values
brewery.cmd.wakeup:

View File

@ -9,16 +9,18 @@ import org.bukkit.block.Container;
import org.bukkit.block.data.Directional;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.RecipeChoice;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.*;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.NotNull;
import java.util.Iterator;
/**
* The Sealing Inventory that is being checked for Brews and seals them after a second.
* <p>Class doesn't load in mc <= 1.12 (Can't find RecipeChoice, BlockData and NamespacedKey)
*/
public class BSealer implements InventoryHolder {
public static final NamespacedKey TAG_KEY = new NamespacedKey(P.p, "SealingTable");
public static boolean recipeRegistered = false;
@ -27,8 +29,8 @@ public class BSealer implements InventoryHolder {
private final Inventory inventory;
private final Player player;
private short[] slotTime = new short[9];
ItemStack[] contents = null;
BukkitTask task;
private ItemStack[] contents = null;
private BukkitTask task;
public BSealer(Player player) {
this.player = player;
@ -91,7 +93,7 @@ public class BSealer implements InventoryHolder {
Brew brew = Brew.get(contents[i]);
if (brew != null && !brew.isStripped()) {
brew.seal(contents[i]);
if (playerValid) {
if (playerValid && P.use1_9) {
player.playSound(player.getLocation(), Sound.ITEM_BOTTLE_FILL_DRAGONBREATH, 1, 1.5f + (float) (Math.random() * 0.2));
}
}
@ -152,6 +154,14 @@ public class BSealer implements InventoryHolder {
public static void unregisterRecipe() {
recipeRegistered = false;
P.p.getServer().removeRecipe(new NamespacedKey(P.p, "SealingTable"));
//P.p.getServer().removeRecipe(new NamespacedKey(P.p, "SealingTable")); 1.15 Method
Iterator<Recipe> recipeIterator = P.p.getServer().recipeIterator();
while (recipeIterator.hasNext()) {
Recipe next = recipeIterator.next();
if (next instanceof ShapedRecipe && ((ShapedRecipe) next).getKey().equals(TAG_KEY)) {
recipeIterator.remove();
return;
}
}
}
}

View File

@ -121,7 +121,7 @@ public class P extends JavaPlugin {
if (use1_9) {
p.getServer().getPluginManager().registerEvents(new CauldronListener(), p);
}
if (BConfig.hasChestShop) {
if (BConfig.hasChestShop && use1_13) {
p.getServer().getPluginManager().registerEvents(new ChestShopListener(), p);
}

View File

@ -81,6 +81,14 @@ public class CommandListener implements CommandExecutor {
}
}
} else if (cmd.equalsIgnoreCase("seal") || cmd.startsWith("seal") || cmd.startsWith("Seal")) {
if (sender.hasPermission("brewery.cmd.seal")) {
cmdSeal(sender);
} else {
p.msg(sender, p.languageReader.get("Error_NoPermissions"));
}
} else if (cmd.equalsIgnoreCase("copy") || cmd.equalsIgnoreCase("cp")) {
if (sender.hasPermission("brewery.cmd.copy")) {
@ -174,6 +182,10 @@ public class CommandListener implements CommandExecutor {
cmds.add (p.languageReader.get("Help_Info"));
}
if (P.use1_13 && sender.hasPermission("brewery.cmd.seal")) {
cmds.add (p.languageReader.get("Help_Seal"));
}
if (sender.hasPermission("brewery.cmd.unlabel")) {
cmds.add (p.languageReader.get("Help_UnLabel"));
}
@ -366,6 +378,20 @@ public class CommandListener implements CommandExecutor {
}
public void cmdSeal(CommandSender sender) {
if (!P.use1_13) {
P.p.msg(sender, "Sealing requires minecraft 1.13 or higher");
return;
}
if (!(sender instanceof Player)) {
p.msg(sender, p.languageReader.get("Error_PlayerCommand"));
return;
}
Player player = (Player) sender;
player.openInventory(new BSealer(player).getInventory());
}
@Deprecated
public void cmdCopy(CommandSender sender, int count) {

View File

@ -193,6 +193,7 @@ public class InventoryListener implements Listener {
// Handle the Brew Sealer Inventory
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onInventoryClickBSealer(InventoryClickEvent event) {
if (!P.use1_13) return;
InventoryHolder holder = event.getInventory().getHolder();
if (!(holder instanceof BSealer)) {
return;
@ -296,6 +297,7 @@ public class InventoryListener implements Listener {
@EventHandler
public void onInventoryClose(InventoryCloseEvent event) {
if (!P.use1_13) return;
if (event.getInventory().getHolder() instanceof BSealer) {
((BSealer) event.getInventory().getHolder()).closeInv();
}

View File

@ -6,7 +6,6 @@ import com.dre.brewery.filedata.UpdateChecker;
import com.dre.brewery.utility.LegacyUtil;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.Nameable;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -42,7 +41,7 @@ public class PlayerListener implements Listener {
}
if (BSealer.isBSealer(clickedBlock)) {
if (P.use1_14 && BSealer.isBSealer(clickedBlock)) {
event.setCancelled(true);
if (BConfig.enableSealingTable) {
BSealer sealer = new BSealer(player);