mirror of
https://github.com/exituser/Brewery.git
synced 2026-09-17 07:49:03 +00:00
/br -> /brew, added Persistence
This commit is contained in:
+2
-1
@@ -6,7 +6,7 @@ softdepend: [LWC, LogBlock, WorldGuard, GriefPrevention]
|
|||||||
commands:
|
commands:
|
||||||
brewery:
|
brewery:
|
||||||
description: Command for Administration
|
description: Command for Administration
|
||||||
aliases: [brew,br]
|
aliases: [brew]
|
||||||
permissions:
|
permissions:
|
||||||
# -- Groups --
|
# -- Groups --
|
||||||
# User
|
# User
|
||||||
@@ -39,6 +39,7 @@ permissions:
|
|||||||
brewery.cmd.player: true
|
brewery.cmd.player: true
|
||||||
brewery.cmd.copy: true
|
brewery.cmd.copy: true
|
||||||
brewery.cmd.delete: true
|
brewery.cmd.delete: true
|
||||||
|
brewery.cmd.persist: true
|
||||||
brewery.cmd.reload: true
|
brewery.cmd.reload: true
|
||||||
# *
|
# *
|
||||||
brewery.*:
|
brewery.*:
|
||||||
|
|||||||
@@ -77,39 +77,34 @@ public class BPlayer {
|
|||||||
return org.bukkit.Bukkit.getPlayerExact(name);
|
return org.bukkit.Bukkit.getPlayerExact(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns true if drinking was successful
|
// Drink a brew and apply effects, etc.
|
||||||
public static boolean drink(int uid, Player player) {
|
public static void drink(Brew brew, Player player) {
|
||||||
Brew brew = Brew.get(uid);
|
int brewAlc = brew.calcAlcohol();
|
||||||
if (brew != null) {
|
if (brewAlc == 0) {
|
||||||
int brewAlc = brew.calcAlcohol();
|
//no alcohol so we dont need to add a BPlayer
|
||||||
if (brewAlc == 0) {
|
addBrewEffects(brew, player);
|
||||||
//no alcohol so we dont need to add a BPlayer
|
return;
|
||||||
addBrewEffects(brew, player);
|
}
|
||||||
return true;
|
BPlayer bPlayer = get(player.getName());
|
||||||
}
|
if (bPlayer == null) {
|
||||||
BPlayer bPlayer = get(player.getName());
|
bPlayer = new BPlayer();
|
||||||
if (bPlayer == null) {
|
players.put(player.getName(), bPlayer);
|
||||||
bPlayer = new BPlayer();
|
}
|
||||||
players.put(player.getName(), bPlayer);
|
bPlayer.drunkeness += brewAlc;
|
||||||
}
|
if (brew.getQuality() > 0) {
|
||||||
bPlayer.drunkeness += brewAlc;
|
bPlayer.quality += brew.getQuality() * brewAlc;
|
||||||
if (brew.getQuality() > 0) {
|
} else {
|
||||||
bPlayer.quality += brew.getQuality() * brewAlc;
|
bPlayer.quality += brewAlc;
|
||||||
} else {
|
}
|
||||||
bPlayer.quality += brewAlc;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bPlayer.drunkeness <= 100) {
|
if (bPlayer.drunkeness <= 100) {
|
||||||
|
|
||||||
addBrewEffects(brew, player);
|
addBrewEffects(brew, player);
|
||||||
addQualityEffects(brew.getQuality(), brewAlc, player);
|
addQualityEffects(brew.getQuality(), brewAlc, player);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
bPlayer.drinkCap(player);
|
bPlayer.drinkCap(player);
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Player has drunken too much
|
// Player has drunken too much
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ public class Brew {
|
|||||||
private float wood;
|
private float wood;
|
||||||
private BRecipe currentRecipe;
|
private BRecipe currentRecipe;
|
||||||
private boolean unlabeled;
|
private boolean unlabeled;
|
||||||
|
private boolean persistent;
|
||||||
|
|
||||||
public Brew(int uid, BIngredients ingredients) {
|
public Brew(int uid, BIngredients ingredients) {
|
||||||
this.ingredients = ingredients;
|
this.ingredients = ingredients;
|
||||||
@@ -42,7 +43,7 @@ public class Brew {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// loading from file
|
// loading from file
|
||||||
public Brew(int uid, BIngredients ingredients, int quality, int distillRuns, float ageTime, float wood, String recipe, Boolean unlabeled) {
|
public Brew(int uid, BIngredients ingredients, int quality, int distillRuns, float ageTime, float wood, String recipe, boolean unlabeled, boolean persistent) {
|
||||||
potions.put(uid, this);
|
potions.put(uid, this);
|
||||||
this.ingredients = ingredients;
|
this.ingredients = ingredients;
|
||||||
this.quality = quality;
|
this.quality = quality;
|
||||||
@@ -50,6 +51,7 @@ public class Brew {
|
|||||||
this.ageTime = ageTime;
|
this.ageTime = ageTime;
|
||||||
this.wood = wood;
|
this.wood = wood;
|
||||||
this.unlabeled = unlabeled;
|
this.unlabeled = unlabeled;
|
||||||
|
this.persistent = persistent;
|
||||||
setRecipeFromString(recipe);
|
setRecipeFromString(recipe);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,11 +104,6 @@ public class Brew {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove potion from file (drinking, despawning, combusting, cmdDeleting, should be more!)
|
|
||||||
public static void remove(ItemStack item) {
|
|
||||||
potions.remove(getUID(item));
|
|
||||||
}
|
|
||||||
|
|
||||||
// generate an UID
|
// generate an UID
|
||||||
public static int generateUID() {
|
public static int generateUID() {
|
||||||
int uid = -2;
|
int uid = -2;
|
||||||
@@ -168,6 +165,13 @@ public class Brew {
|
|||||||
return brew;
|
return brew;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remove potion from file (drinking, despawning, combusting, cmdDeleting, should be more!)
|
||||||
|
public void remove(ItemStack item) {
|
||||||
|
if (!persistent) {
|
||||||
|
potions.remove(getUID(item));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// calculate alcohol from recipe
|
// calculate alcohol from recipe
|
||||||
public int calcAlcohol() {
|
public int calcAlcohol() {
|
||||||
if (quality == 0) {
|
if (quality == 0) {
|
||||||
@@ -259,6 +263,20 @@ public class Brew {
|
|||||||
unlabeled = true;
|
unlabeled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isPersistent() {
|
||||||
|
return persistent;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make a potion persistent to not delete it when drinking it
|
||||||
|
public void makePersistent() {
|
||||||
|
persistent = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove the Persistence Flag from a brew, so it will be normally deleted when drinking it
|
||||||
|
public void removePersistence() {
|
||||||
|
persistent = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Distilling section ---------------
|
// Distilling section ---------------
|
||||||
|
|
||||||
// distill all custom potions in the brewer
|
// distill all custom potions in the brewer
|
||||||
@@ -572,6 +590,9 @@ public class Brew {
|
|||||||
if (brew.unlabeled) {
|
if (brew.unlabeled) {
|
||||||
idConfig.set("unlabeled", true);
|
idConfig.set("unlabeled", true);
|
||||||
}
|
}
|
||||||
|
if (brew.persistent) {
|
||||||
|
idConfig.set("persist", true);
|
||||||
|
}
|
||||||
// save the ingredients
|
// save the ingredients
|
||||||
idConfig.set("ingId", brew.ingredients.save(config.getParent()));
|
idConfig.set("ingId", brew.ingredients.save(config.getParent()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,11 +82,15 @@ public class LanguageReader {
|
|||||||
defaults.put("CMD_Info_NotDrunk", "&v1 is not drunk");
|
defaults.put("CMD_Info_NotDrunk", "&v1 is not drunk");
|
||||||
defaults.put("CMD_Info_Drunk", "&v1 is &6&v2% &fdrunk, with a quality of &6&v3");
|
defaults.put("CMD_Info_Drunk", "&v1 is &6&v2% &fdrunk, with a quality of &6&v3");
|
||||||
defaults.put("CMD_UnLabel", "&aLabel removed!");
|
defaults.put("CMD_UnLabel", "&aLabel removed!");
|
||||||
|
defaults.put("CMD_Persistent", "&aPotion is now Persistent and may be copied like any other item. You can remove the persistence with the same command.");
|
||||||
|
defaults.put("CMD_PersistRemove", "&cThis Brew is Persistent. Deleting it would render every copy of it not made with '/brew copy' useless. To proceed, remove the persistence before deleting.");
|
||||||
|
defaults.put("CMD_UnPersist", "&aPersistence Removed. &eEvery Potential copy not made with '/brew copy' could become useless now!");
|
||||||
defaults.put("CMD_Copy_Error", "&6&v1 &cPotions did not fit into your inventory");
|
defaults.put("CMD_Copy_Error", "&6&v1 &cPotions did not fit into your inventory");
|
||||||
|
defaults.put("CMD_CopyNotPersistent", "&eThese copies of this Brew will not be persistent!");
|
||||||
|
|
||||||
/* Error */
|
/* Error */
|
||||||
defaults.put("Error_UnknownCommand", "Unknown Command");
|
defaults.put("Error_UnknownCommand", "Unknown Command");
|
||||||
defaults.put("Error_ShowHelp", "Use &6/br help &fto display the help");
|
defaults.put("Error_ShowHelp", "Use &6/brew help &fto display the help");
|
||||||
defaults.put("Error_PlayerCommand", "&cThis command can only be executed as a player!");
|
defaults.put("Error_PlayerCommand", "&cThis command can only be executed as a player!");
|
||||||
defaults.put("Error_ItemNotPotion", "&cThe item in your hand could not be identified as a potion!");
|
defaults.put("Error_ItemNotPotion", "&cThe item in your hand could not be identified as a potion!");
|
||||||
defaults.put("Error_Recipeload", "&cNot all recipes could be restored: More information in the server log!");
|
defaults.put("Error_Recipeload", "&cNot all recipes could be restored: More information in the server log!");
|
||||||
@@ -102,20 +106,21 @@ public class LanguageReader {
|
|||||||
defaults.put("Perms_NoCauldronFill", "&cYou don't have permissions to fill bottles from this cauldron!");
|
defaults.put("Perms_NoCauldronFill", "&cYou don't have permissions to fill bottles from this cauldron!");
|
||||||
|
|
||||||
/* Help */
|
/* Help */
|
||||||
defaults.put("Help_Help", "&6/br help <Page> &9Shows a specific help-page");
|
defaults.put("Help_Help", "&6/brew help <Page> &9Shows a specific help-page");
|
||||||
defaults.put("Help_Player", "&6/br <Player> <%Drunkeness> <Quality>&9 Sets Drunkeness (and Quality) of a Player");
|
defaults.put("Help_Player", "&6/brew <Player> <%Drunkeness> <Quality>&9 Sets Drunkeness (and Quality) of a Player");
|
||||||
defaults.put("Help_Info", "&6/br info&9 Displays your current Drunkeness and Quality");
|
defaults.put("Help_Info", "&6/brew info&9 Displays your current Drunkeness and Quality");
|
||||||
defaults.put("Help_UnLabel", "&6/br unlabel &9Removes the detailled label of a potion");
|
defaults.put("Help_UnLabel", "&6/brew unlabel &9Removes the detailled label of a potion");
|
||||||
defaults.put("Help_Copy", "&6/br copy <Quanitiy>&9 Copies the potion in your hand");
|
defaults.put("Help_Copy", "&6/brew copy <Quanitiy>&9 Copies the potion in your hand");
|
||||||
defaults.put("Help_Delete", "&6/br delete &9Deletes the potion in your hand");
|
defaults.put("Help_Delete", "&6/brew delete &9Deletes the potion in your hand");
|
||||||
defaults.put("Help_InfoOther", "&6/br info <Player>&9 Displays the current Drunkeness and Quality of <Player>");
|
defaults.put("Help_InfoOther", "&6/brew info <Player>&9 Displays the current Drunkeness and Quality of <Player>");
|
||||||
defaults.put("Help_Wakeup", "&6/br wakeup list <Page>&9 Lists all wakeup points");
|
defaults.put("Help_Wakeup", "&6/brew wakeup list <Page>&9 Lists all wakeup points");
|
||||||
defaults.put("Help_WakeupList", "&6/br wakeup list <Page> <World>&9 Lists all wakeup points of <world>");
|
defaults.put("Help_WakeupList", "&6/brew wakeup list <Page> <World>&9 Lists all wakeup points of <world>");
|
||||||
defaults.put("Help_WakeupCheck", "&6/br wakeup check &9Teleports to all wakeup points");
|
defaults.put("Help_WakeupCheck", "&6/brew wakeup check &9Teleports to all wakeup points");
|
||||||
defaults.put("Help_WakeupCheckSpecific", "&6/br wakeup check <id> &9Teleports to the wakeup point with <id>");
|
defaults.put("Help_WakeupCheckSpecific", "&6/brew wakeup check <id> &9Teleports to the wakeup point with <id>");
|
||||||
defaults.put("Help_WakeupAdd", "&6/br wakeup add &9Adds a wakeup point at your current position");
|
defaults.put("Help_WakeupAdd", "&6/brew wakeup add &9Adds a wakeup point at your current position");
|
||||||
defaults.put("Help_WakeupRemove", "&6/br wakeup remove <id> &9Removes the wakeup point with <id>");
|
defaults.put("Help_WakeupRemove", "&6/brew wakeup remove <id> &9Removes the wakeup point with <id>");
|
||||||
defaults.put("Help_Reload", "&6/br reload &9Reload config");
|
defaults.put("Help_Reload", "&6/brew reload &9Reload config");
|
||||||
|
defaults.put("Help_Persist", "&6/brew persist &9Make Brew persistent -> copyable by any plugin and technique");
|
||||||
|
|
||||||
/* Etc. */
|
/* Etc. */
|
||||||
defaults.put("Etc_Usage", "Usage:");
|
defaults.put("Etc_Usage", "Usage:");
|
||||||
|
|||||||
@@ -307,9 +307,10 @@ public class P extends JavaPlugin {
|
|||||||
float ageTime = (float) section.getDouble(uid + ".ageTime", 0.0);
|
float ageTime = (float) section.getDouble(uid + ".ageTime", 0.0);
|
||||||
float wood = (float) section.getDouble(uid + ".wood", -1.0);
|
float wood = (float) section.getDouble(uid + ".wood", -1.0);
|
||||||
String recipe = section.getString(uid + ".recipe", null);
|
String recipe = section.getString(uid + ".recipe", null);
|
||||||
Boolean unlabeled = section.getBoolean(uid + ".unlabeled", false);
|
boolean unlabeled = section.getBoolean(uid + ".unlabeled", false);
|
||||||
|
boolean persistent = section.getBoolean(uid + ".persist", false);
|
||||||
|
|
||||||
new Brew(parseInt(uid), ingredients, quality, distillRuns, ageTime, wood, recipe, unlabeled);
|
new Brew(parseInt(uid), ingredients, quality, distillRuns, ageTime, wood, recipe, unlabeled, persistent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -86,6 +86,14 @@ public class CommandListener implements CommandExecutor {
|
|||||||
p.msg(sender, p.languageReader.get("Error_NoPermissions"));
|
p.msg(sender, p.languageReader.get("Error_NoPermissions"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else if (cmd.equalsIgnoreCase("persist") || cmd.equalsIgnoreCase("persistent")) {
|
||||||
|
|
||||||
|
if (sender.hasPermission("brewery.cmd.persist")) {
|
||||||
|
cmdPersist(sender);
|
||||||
|
} else {
|
||||||
|
p.msg(sender, p.languageReader.get("Error_NoPermissions"));
|
||||||
|
}
|
||||||
|
|
||||||
} else if (cmd.equalsIgnoreCase("unlabel")) {
|
} else if (cmd.equalsIgnoreCase("unlabel")) {
|
||||||
|
|
||||||
if (sender.hasPermission("brewery.cmd.unlabel")) {
|
if (sender.hasPermission("brewery.cmd.unlabel")) {
|
||||||
@@ -180,6 +188,10 @@ public class CommandListener implements CommandExecutor {
|
|||||||
cmds.add(p.languageReader.get("Help_Reload"));
|
cmds.add(p.languageReader.get("Help_Reload"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sender.hasPermission("brewery.cmd.persist")) {
|
||||||
|
cmds.add(p.languageReader.get("Help_Persist"));
|
||||||
|
}
|
||||||
|
|
||||||
return cmds;
|
return cmds;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,6 +338,9 @@ public class CommandListener implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
count--;
|
count--;
|
||||||
}
|
}
|
||||||
|
if (brew.isPersistent()) {
|
||||||
|
p.msg(sender, p.languageReader.get("CMD_CopyNotPersistent"));
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -344,9 +359,39 @@ public class CommandListener implements CommandExecutor {
|
|||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
ItemStack hand = player.getItemInHand();
|
ItemStack hand = player.getItemInHand();
|
||||||
if (hand != null) {
|
if (hand != null) {
|
||||||
if (Brew.get(hand) != null) {
|
Brew brew = Brew.get(hand);
|
||||||
Brew.remove(hand);
|
if (brew != null) {
|
||||||
player.setItemInHand(new ItemStack(0));
|
if (brew.isPersistent()) {
|
||||||
|
p.msg(sender, p.languageReader.get("CMD_PersistRemove"));
|
||||||
|
} else {
|
||||||
|
brew.remove(hand);
|
||||||
|
player.setItemInHand(new ItemStack(0));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p.msg(sender, p.languageReader.get("Error_ItemNotPotion"));
|
||||||
|
} else {
|
||||||
|
p.msg(sender, p.languageReader.get("Error_PlayerCommand"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cmdPersist(CommandSender sender) {
|
||||||
|
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
ItemStack hand = player.getItemInHand();
|
||||||
|
if (hand != null) {
|
||||||
|
Brew brew = Brew.get(hand);
|
||||||
|
if (brew != null) {
|
||||||
|
if (brew.isPersistent()) {
|
||||||
|
brew.removePersistence();
|
||||||
|
p.msg(sender, p.languageReader.get("CMD_UnPersist"));
|
||||||
|
} else {
|
||||||
|
brew.makePersistent();
|
||||||
|
p.msg(sender, p.languageReader.get("CMD_Persistent"));
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,10 @@ public class EntityListener implements Listener {
|
|||||||
public void onItemDespawn(ItemDespawnEvent event) {
|
public void onItemDespawn(ItemDespawnEvent event) {
|
||||||
ItemStack item = event.getEntity().getItemStack();
|
ItemStack item = event.getEntity().getItemStack();
|
||||||
if (item.getTypeId() == 373) {
|
if (item.getTypeId() == 373) {
|
||||||
Brew.remove(item);
|
Brew brew = Brew.get(item);
|
||||||
|
if (brew != null) {
|
||||||
|
brew.remove(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,7 +40,10 @@ public class EntityListener implements Listener {
|
|||||||
if (entity instanceof Item) {
|
if (entity instanceof Item) {
|
||||||
ItemStack item = ((Item) entity).getItemStack();
|
ItemStack item = ((Item) entity).getItemStack();
|
||||||
if (item.getTypeId() == 373) {
|
if (item.getTypeId() == 373) {
|
||||||
Brew.remove(item);
|
Brew brew = Brew.get(item);
|
||||||
|
if (brew != null) {
|
||||||
|
brew.remove(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,11 +155,11 @@ public class PlayerListener implements Listener {
|
|||||||
ItemStack item = event.getItem();
|
ItemStack item = event.getItem();
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
if (item.getType() == Material.POTION) {
|
if (item.getType() == Material.POTION) {
|
||||||
if (item.hasItemMeta()) {
|
Brew brew = Brew.get(item);
|
||||||
if (BPlayer.drink(Brew.getUID(item), player)) {
|
if (brew != null) {
|
||||||
if (player.getGameMode() != org.bukkit.GameMode.CREATIVE) {
|
BPlayer.drink(brew, player);
|
||||||
Brew.remove(item);
|
if (player.getGameMode() != org.bukkit.GameMode.CREATIVE) {
|
||||||
}
|
brew.remove(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (BPlayer.drainItems.containsKey(item.getType())) {
|
} else if (BPlayer.drainItems.containsKey(item.getType())) {
|
||||||
|
|||||||
Reference in New Issue
Block a user