SteamWar/BauSystem2.0
Archiviert
12
0

Merge remote-tracking branch 'origin/master'

Dieser Commit ist enthalten in:
Chaoscaot 2021-05-24 11:42:35 +02:00
Commit ec6ceb7c1e
5 geänderte Dateien mit 81 neuen und 12 gelöschten Zeilen

Datei anzeigen

@ -27,6 +27,7 @@ import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.region.RegionUtils;
import de.steamwar.bausystem.region.utils.RegionExtensionType;
import de.steamwar.bausystem.region.utils.RegionType;
import de.steamwar.bausystem.utils.ItemUtils;
import de.steamwar.inventory.SWItem;
import lombok.Getter;
import org.bukkit.Material;
@ -47,7 +48,9 @@ import java.util.Map;
public class AutostartListener implements Listener {
public static ItemStack getWandItem(Player player) {
return new SWItem(Material.FIREWORK_STAR, BauSystem.MESSAGE.parse("AUTOSTART_ITEM_NAME", player), Arrays.asList(BauSystem.MESSAGE.parse("AUTOSTART_ITEM_LORE", player)), false, null).getItemStack();
ItemStack itemStack = new SWItem(Material.FIREWORK_STAR, BauSystem.MESSAGE.parse("AUTOSTART_ITEM_NAME", player), Arrays.asList(BauSystem.MESSAGE.parse("AUTOSTART_ITEM_LORE", player)), false, null).getItemStack();
ItemUtils.setItem(itemStack, "autostart");
return itemStack;
}
@Getter
@ -55,7 +58,7 @@ public class AutostartListener implements Listener {
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if (!AutostartListener.getWandItem(event.getPlayer()).isSimilar(event.getItem())) {
if (!ItemUtils.isItem(event.getItem(), "autostart")) {
return;
}
if (event.getClickedBlock() == null) {

Datei anzeigen

@ -20,30 +20,33 @@
package de.steamwar.bausystem.features.countingwand;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.config.ColorConfig;
import de.steamwar.bausystem.region.Point;
import de.steamwar.bausystem.shared.Pair;
import de.steamwar.bausystem.utils.ItemUtils;
import de.steamwar.inventory.SWItem;
import java.util.*;
import de.steamwar.message.Message;
import lombok.experimental.UtilityClass;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@UtilityClass
public class Countingwand {
public static ItemStack getWandItem(Player player) {
return new SWItem(Material.STICK, BauSystem.MESSAGE.parse("COUNTINGWAND_ITEM_NAME", player), Arrays.asList(BauSystem.MESSAGE.parse("COUNTINGWAND_ITEM_LORE1", player), BauSystem.MESSAGE.parse("COUNTINGWAND_ITEM_LORE2", player)), false, null).getItemStack();
ItemStack itemStack = new SWItem(Material.STICK, BauSystem.MESSAGE.parse("COUNTINGWAND_ITEM_NAME", player), Arrays.asList(BauSystem.MESSAGE.parse("COUNTINGWAND_ITEM_LORE1", player), BauSystem.MESSAGE.parse("COUNTINGWAND_ITEM_LORE2", player)), false, null).getItemStack();
ItemUtils.setItem(itemStack, "countingwand");
return itemStack;
}
private final Map<String, Pair<Point, Point>> selections = new HashMap<>();
public boolean isCountingwand(Player player, ItemStack itemStack) {
return getWandItem(player).isSimilar(itemStack);
public boolean isCountingwand(ItemStack itemStack) {
return ItemUtils.isItem(itemStack, "countingwand");
}
public void checkSelection(final Point point, final boolean pos1, final Player p) {

Datei anzeigen

@ -22,7 +22,6 @@ package de.steamwar.bausystem.features.countingwand;
import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked;
import de.steamwar.bausystem.region.Point;
import java.util.Objects;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
@ -30,13 +29,15 @@ import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import java.util.Objects;
@Linked(LinkageType.LISTENER)
public class CountingwandListener implements Listener {
@EventHandler
public void onBlockBreak(final BlockBreakEvent event) {
if (!Countingwand.isCountingwand(event.getPlayer(), event.getPlayer().getInventory().getItemInMainHand())) {
if (!Countingwand.isCountingwand(event.getPlayer().getInventory().getItemInMainHand())) {
return;
}
@ -46,7 +47,7 @@ public class CountingwandListener implements Listener {
@EventHandler
public void onPlayerInteract(final PlayerInteractEvent event) {
if (!Countingwand.isCountingwand(event.getPlayer(), event.getItem())) {
if (!Countingwand.isCountingwand(event.getItem())) {
return;
}

Datei anzeigen

@ -0,0 +1,62 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 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.utils;
import de.steamwar.bausystem.SWUtils;
import lombok.experimental.UtilityClass;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
@UtilityClass
public class ItemUtils {
private final NamespacedKey ITEM_KEY = SWUtils.getNamespaceKey("bau_item");
public boolean isItem(ItemStack itemStack, String tag) {
if (itemStack == null) {
return false;
}
ItemMeta meta = itemStack.getItemMeta();
if (meta == null) {
return false;
}
PersistentDataContainer container = meta.getPersistentDataContainer();
if (!container.has(ITEM_KEY, PersistentDataType.STRING)) {
return false;
}
return tag.equals(container.get(ITEM_KEY, PersistentDataType.STRING));
}
public void setItem(ItemStack itemStack, String tag) {
if (itemStack == null) {
return;
}
ItemMeta meta = itemStack.getItemMeta();
if (meta == null) {
return;
}
meta.getPersistentDataContainer().set(ITEM_KEY, PersistentDataType.STRING, tag);
itemStack.setItemMeta(meta);
}
}