mirror of
https://github.com/exituser/Brewery.git
synced 2026-09-17 10:08:54 +00:00
Items can lower Drunkeness when consumed
This commit is contained in:
@@ -9,6 +9,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
@@ -18,6 +19,7 @@ import com.dre.brewery.Brew;
|
||||
|
||||
public class BPlayer {
|
||||
public static Map<String, BPlayer> players = new HashMap<String, BPlayer>();// Players name and BPlayer
|
||||
public static Map<Material, Integer> drainItems = new HashMap<Material, Integer>();// DrainItem Material and Strength
|
||||
private static Map<Player, Integer> pTasks = new HashMap<Player, Integer>();// Player and count
|
||||
private static int taskId;
|
||||
public static int pukeItemId;
|
||||
@@ -121,6 +123,30 @@ public class BPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
// Eat something to drain the drunkeness
|
||||
public void drainByItem(String name, Material mat) {
|
||||
int strength = drainItems.get(mat);
|
||||
if (drain(name, strength)) {
|
||||
players.remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
// drain the drunkeness by amount, returns true when player has to be removed
|
||||
public boolean drain(String name, int amount) {
|
||||
quality -= getQuality() * amount;
|
||||
drunkeness -= amount;
|
||||
if (drunkeness > 0) {
|
||||
if (offlineDrunk == 0) {
|
||||
if (getPlayer(name) == null) {
|
||||
offlineDrunk = drunkeness;
|
||||
}
|
||||
}
|
||||
} else if (drunkeness <= (-1) * offlineDrunk) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// player is drunk
|
||||
public void move(PlayerMoveEvent event) {
|
||||
// has player more alc than 10
|
||||
@@ -400,15 +426,7 @@ public class BPlayer {
|
||||
// Prevent 0 drunkeness
|
||||
soberPerMin++;
|
||||
}
|
||||
bplayer.quality -= bplayer.getQuality() * soberPerMin;
|
||||
bplayer.drunkeness -= soberPerMin;
|
||||
if (bplayer.drunkeness > 0) {
|
||||
if (bplayer.offlineDrunk == 0) {
|
||||
if (getPlayer(name) == null) {
|
||||
bplayer.offlineDrunk = bplayer.drunkeness;
|
||||
}
|
||||
}
|
||||
} else if (bplayer.drunkeness <= (-1) * bplayer.offlineDrunk) {
|
||||
if (bplayer.drain(name, soberPerMin)) {
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,6 @@ public class BRecipe {
|
||||
if (effectStringList != null) {
|
||||
for (String effectString : effectStringList) {
|
||||
String[] effectSplit = effectString.split("/");
|
||||
P.p.log("effekt: " + effectSplit[0]);
|
||||
if (effectSplit.length > 1) {
|
||||
effects.put(effectSplit[0], P.p.parseInt(effectSplit[1]));
|
||||
} else {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.dre.brewery;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.ListIterator;
|
||||
import java.util.HashMap;
|
||||
@@ -101,6 +102,7 @@ public class P extends JavaPlugin {
|
||||
BIngredients.recipes.clear();
|
||||
BIngredients.cookedNames.clear();
|
||||
Words.words.clear();
|
||||
BPlayer.drainItems.clear();
|
||||
|
||||
readConfig();
|
||||
}
|
||||
@@ -154,6 +156,21 @@ public class P extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
// loading drainItems
|
||||
List<String> drainList = config.getStringList("drainItems");
|
||||
if (drainList != null) {
|
||||
for (String drainString : drainList) {
|
||||
String[] drainSplit = drainString.split("/");
|
||||
if (drainSplit.length > 1) {
|
||||
Material mat = Material.matchMaterial(drainSplit[0]);
|
||||
int strength = p.parseInt(drainSplit[1]);
|
||||
if (mat != null && strength > 0) {
|
||||
BPlayer.drainItems.put(mat, strength);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// telling Words the path, it will load it when needed
|
||||
Words.config = config;
|
||||
}
|
||||
|
||||
@@ -107,16 +107,22 @@ public class PlayerListener implements Listener {
|
||||
// player drinks a custom potion
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerItemConsume(PlayerItemConsumeEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
ItemStack item = event.getItem();
|
||||
if (item != null) {
|
||||
if (item.getType() == Material.POTION) {
|
||||
if (item.hasItemMeta()) {
|
||||
if (BPlayer.drink(Brew.getUID(item), event.getPlayer())) {
|
||||
if (event.getPlayer().getGameMode() != org.bukkit.GameMode.CREATIVE) {
|
||||
if (BPlayer.drink(Brew.getUID(item), player)) {
|
||||
if (player.getGameMode() != org.bukkit.GameMode.CREATIVE) {
|
||||
Brew.remove(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (BPlayer.drainItems.containsKey(item.getType())) {
|
||||
BPlayer bplayer = BPlayer.get(player.getName());
|
||||
if (bplayer != null) {
|
||||
bplayer.drainByItem(player.getName(), item.getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user