SteamWar/BauSystem
Archiviert
13
0

Merge pull request 'Improve ItemGiver' (#200) from ItemGiver into master

Reviewed-by: Chaoscaot <chaoscaot444@gmail.com>
Dieser Commit ist enthalten in:
YoyoNow 2021-02-26 12:45:31 +01:00
Commit c7a9b13bbe
6 geänderte Dateien mit 47 neuen und 11 gelöschten Zeilen

Datei anzeigen

@ -19,6 +19,7 @@
package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.PlayerUtils;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -27,6 +28,6 @@ class CommandDebugStick_15 {
private CommandDebugStick_15(){}
static void giveStick(Player player){
player.getInventory().setItemInMainHand(new ItemStack(Material.DEBUG_STICK));
PlayerUtils.giveItemToPlayer(player, new ItemStack(Material.DEBUG_STICK));
}
}

Datei anzeigen

@ -0,0 +1,36 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2020 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class PlayerUtils {
public static void giveItemToPlayer(Player player, ItemStack itemStack) {
ItemStack current = player.getInventory().getItemInMainHand();
player.getInventory().setItemInMainHand(itemStack);
if (current.getType() != Material.AIR) {
player.getInventory().addItem(current);
}
}
}

Datei anzeigen

@ -21,6 +21,7 @@ package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.PlayerUtils;
import de.steamwar.bausystem.world.Detonator;
import de.steamwar.bausystem.world.Welt;
import org.bukkit.command.Command;
@ -62,7 +63,7 @@ public class CommandDetonator implements CommandExecutor {
case "wand":
case "detonator":
case "item":
player.getInventory().setItemInMainHand(Detonator.WAND);
PlayerUtils.giveItemToPlayer(player, Detonator.WAND);
player.updateInventory();
Detonator.getDetonator(player);
break;

Datei anzeigen

@ -2,6 +2,7 @@ package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.PlayerUtils;
import de.steamwar.bausystem.tracer.record.RecordStateMachine;
import de.steamwar.bausystem.tracer.show.TraceShowManager;
import de.steamwar.bausystem.world.*;
@ -574,13 +575,8 @@ public class CommandGUI implements CommandExecutor, Listener {
if (strings.length == 0) {
openBauGui(player);
OPEN_INVS.add(player);
} else {
if ("item".equalsIgnoreCase(strings[0])) {
if (player.getInventory().getItemInMainHand().getType() == Material.AIR)
player.getInventory().setItemInMainHand(new ItemStack(Material.NETHER_STAR));
else
player.getInventory().addItem(new ItemStack(Material.NETHER_STAR));
}
} else if ("item".equalsIgnoreCase(strings[0])) {
PlayerUtils.giveItemToPlayer(player, new ItemStack(Material.NETHER_STAR));
}
return true;
}

Datei anzeigen

@ -21,6 +21,7 @@
package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.PlayerUtils;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@ -67,7 +68,7 @@ public class CommandScript implements CommandExecutor {
if (!(sender instanceof Player)) {
return false;
}
((Player) sender).getInventory().setItemInMainHand(BOOK);
PlayerUtils.giveItemToPlayer((Player) sender, BOOK);
return false;
}

Datei anzeigen

@ -20,6 +20,7 @@
package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.PlayerUtils;
import de.steamwar.inventory.SWItem;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@ -46,7 +47,7 @@ public class CommandSkull implements CommandExecutor {
assert sm != null;
sm.setDisplayName("§e" + args[0] + "§8s Kopf");
is.setItemMeta(sm);
p.getInventory().setItemInMainHand(is);
PlayerUtils.giveItemToPlayer(p, is);
return false;
}