mirror of
https://github.com/DieReicheErethons/Brewery.git
synced 2024-11-25 12:05:16 +01:00
Added cmd Copy
This commit is contained in:
parent
b7d0b73aa0
commit
925107fdfc
@ -64,6 +64,9 @@ Auch hier können anhand der Erklärungen und Beispiele bestehende "Wörter" ver
|
||||
<tr>
|
||||
<td>/br [Spieler] [Trunkenheit] [Qualität]</td><td>Setzen der Spielerwerte. Trunkenheit in %, Qualität von 1-10.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>/br Copy [Anzahl]</td><td>Kopiert den Trank in der Hand. Optional kann die Anzahl angegeben werden</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>/br Wakeup Add</td><td>Setzen eines neuen Aufwachpunktes an die eigene Position</td>
|
||||
</tr>
|
||||
@ -105,6 +108,9 @@ Auch hier können anhand der Erklärungen und Beispiele bestehende "Wörter" ver
|
||||
<tr>
|
||||
<td>brewery.cmd.wakeup</td><td>Wakeup *</td><td>Setzen, Überprüfen und Entfernen von Aufwachpunkten</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>brewery.cmd.copy</td><td>Copy</td><td>Kopieren von Tränken per Command</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>brewery.cmd.reload</td><td>Reload</td><td>Config neuladen</td>
|
||||
</tr>
|
||||
|
@ -72,16 +72,16 @@ public class Brew {
|
||||
}
|
||||
|
||||
// returns a Brew by ItemStack
|
||||
/* public static Brew get(ItemStack item) {
|
||||
* if (item.getTypeId() == 373) {
|
||||
* if (item.hasItemMeta()) {
|
||||
* PotionMeta potionMeta = (PotionMeta) item.getItemMeta();
|
||||
* return get(potionMeta);
|
||||
* }
|
||||
* }
|
||||
* return null;
|
||||
* }
|
||||
*/
|
||||
public static Brew get(ItemStack item) {
|
||||
if (item.getTypeId() == 373) {
|
||||
if (item.hasItemMeta()) {
|
||||
PotionMeta potionMeta = (PotionMeta) item.getItemMeta();
|
||||
return get(potionMeta);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// returns UID of custom Potion item
|
||||
public static int getUID(ItemStack item) {
|
||||
@ -116,6 +116,26 @@ public class Brew {
|
||||
return uid;
|
||||
}
|
||||
|
||||
|
||||
// Copy a Brew with a new unique ID and return its item
|
||||
public ItemStack copy(ItemStack item) {
|
||||
ItemStack copy = item.clone();
|
||||
int uid = generateUID();
|
||||
clone(uid);
|
||||
PotionMeta meta = (PotionMeta) copy.getItemMeta();
|
||||
meta.addCustomEffect((PotionEffectType.REGENERATION).createEffect((uid * 4), 0), true);
|
||||
copy.setItemMeta(meta);
|
||||
return copy;
|
||||
}
|
||||
|
||||
// Clones this instance with a new unique ID
|
||||
public Brew clone(int uid) {
|
||||
Brew brew = new Brew(uid, quality, currentRecipe, ingredients);
|
||||
brew.distillRuns = distillRuns;
|
||||
brew.ageTime = ageTime;
|
||||
return brew;
|
||||
}
|
||||
|
||||
// calculate alcohol from recipe
|
||||
public int calcAlcohol() {
|
||||
if (currentRecipe != null) {
|
||||
|
@ -6,10 +6,12 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.dre.brewery.P;
|
||||
import com.dre.brewery.Wakeup;
|
||||
import com.dre.brewery.BPlayer;
|
||||
import com.dre.brewery.Brew;
|
||||
|
||||
public class CommandListener implements CommandExecutor {
|
||||
|
||||
@ -64,6 +66,18 @@ public class CommandListener implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
} else if (cmd.equalsIgnoreCase("copy") || cmd.equalsIgnoreCase("cp")) {
|
||||
|
||||
if (p.permission.has(sender, "brewery.cmd.copy")) {
|
||||
if (args.length > 1) {
|
||||
cmdCopy(sender, P.p.parseInt(args[1]));
|
||||
} else {
|
||||
cmdCopy(sender, 1);
|
||||
}
|
||||
} else {
|
||||
p.msg(sender, "&cDu hast keine Rechte dies zu tun!");
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (p.getServer().getPlayerExact(cmd) != null || BPlayer.players.containsKey(cmd)) {
|
||||
@ -113,8 +127,20 @@ public class CommandListener implements CommandExecutor {
|
||||
ArrayList<String> cmds = new ArrayList<String>();
|
||||
cmds.add("&6/br help <Seite> &9Zeigt eine bestimmte Hilfeseite an");
|
||||
|
||||
if (p.permission.has(sender, "brewery.cmd.reload")) {
|
||||
cmds.add("&6/br reload &9Config neuladen");
|
||||
if (p.permission.has(sender, "brewery.cmd.player")) {
|
||||
cmds.add ("&6/br <Spieler> <%Trunkenheit> <Qualität>&9 Setzt Trunkenheit (und Qualität) eines Spielers");
|
||||
}
|
||||
|
||||
if (p.permission.has(sender, "brewery.cmd.info")) {
|
||||
cmds.add ("&6/br Info&9 Zeigt deine aktuelle Trunkenheit und Qualität an");
|
||||
}
|
||||
|
||||
if (p.permission.has(sender, "brewery.cmd.copy")) {
|
||||
cmds.add ("&6/br Copy <Anzahl>&9 Kopiert den Trank in deiner Hand");
|
||||
}
|
||||
|
||||
if (p.permission.has(sender, "brewery.cmd.infoOther")) {
|
||||
cmds.add ("&6/br Info <Spieler>&9 Zeigt die aktuelle Trunkenheit und Qualität von <Spieler> an");
|
||||
}
|
||||
|
||||
if (p.permission.has(sender, "brewery.cmd.wakeup")) {
|
||||
@ -126,16 +152,8 @@ public class CommandListener implements CommandExecutor {
|
||||
cmds.add("&6/br Wakeup Remove <id> &9Entfernt einen Aufwachpunkt");
|
||||
}
|
||||
|
||||
if (p.permission.has(sender, "brewery.cmd.player")) {
|
||||
cmds.add ("&6/br <Spieler> <%Trunkenheit> <Qualität>&9 Setzt Trunkenheit (und Qualität) eines Spielers");
|
||||
}
|
||||
|
||||
if (p.permission.has(sender, "brewery.cmd.info")) {
|
||||
cmds.add ("&6/br Info&9 Zeigt deine aktuelle Trunkenheit und Qualität an");
|
||||
}
|
||||
|
||||
if (p.permission.has(sender, "brewery.cmd.infoOther")) {
|
||||
cmds.add ("&6/br Info <Spieler>&9 Zeigt die aktuelle Trunkenheit und Qualität von <Spieler> an");
|
||||
if (p.permission.has(sender, "brewery.cmd.reload")) {
|
||||
cmds.add("&6/br reload &9Config neuladen");
|
||||
}
|
||||
|
||||
return cmds;
|
||||
@ -253,4 +271,37 @@ public class CommandListener implements CommandExecutor {
|
||||
|
||||
}
|
||||
|
||||
public void cmdCopy(CommandSender sender, int count) {
|
||||
|
||||
if (sender instanceof Player) {
|
||||
if (count < 1 || count > 36) {
|
||||
p.msg(sender, "Benutzung:");
|
||||
p.msg(sender, "&6/br Copy <Anzahl>");
|
||||
return;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
ItemStack hand = player.getItemInHand();
|
||||
if (hand != null) {
|
||||
Brew brew = Brew.get(hand);
|
||||
if (brew != null) {
|
||||
while (count > 0) {
|
||||
ItemStack item = brew.copy(player.getItemInHand());
|
||||
if (!(player.getInventory().addItem(item)).isEmpty()) {
|
||||
P.p.msg(sender, "&6" + count + " &cTränke haben nicht mehr in das Inventar gepasst");
|
||||
return;
|
||||
}
|
||||
count--;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
p.msg(sender, "&cDas Item in deiner Hand konnte nicht als Trank identifiziert werden");
|
||||
|
||||
} else {
|
||||
p.msg(sender, "&cDieser Befehl kann nur als Spieler ausgeführt werden");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user