Archiviert
13
0

Add MaterialCommand

Dieser Commit ist enthalten in:
yoyosource 2021-11-01 16:33:39 +01:00
Ursprung e11584d850
Commit 5d61ea2809
9 geänderte Dateien mit 381 neuen und 12 gelöschten Zeilen

Datei anzeigen

@ -17,18 +17,23 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar;
package de.steamwar.teamserver;
import de.steamwar.command.GamemodeCommand;
import de.steamwar.command.SchemEqualityCommand;
import de.steamwar.command.SpeedCommand;
import de.steamwar.listener.WorldChange;
import de.steamwar.message.Message;
import de.steamwar.teamserver.command.GamemodeCommand;
import de.steamwar.teamserver.command.MaterialCommand;
import de.steamwar.teamserver.command.SchemEqualityCommand;
import de.steamwar.teamserver.command.SpeedCommand;
import de.steamwar.teamserver.listener.WorldChange;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
public final class Teamserver extends JavaPlugin {
// This should be treated as final!
public static Message MESSAGE;
@Getter
private static Teamserver instance;
@ -37,11 +42,16 @@ public final class Teamserver extends JavaPlugin {
// Plugin startup logic
instance = this;
MESSAGE = new Message("de.steamwar.teamserver.Teamserver", getClassLoader());
new GamemodeCommand();
new SpeedCommand();
new SchemEqualityCommand();
Bukkit.getPluginManager().registerEvents(new WorldChange(), this);
MaterialCommand materialCommand = new MaterialCommand();
Bukkit.getPluginManager().registerEvents(materialCommand, this);
}
@Override

Datei anzeigen

@ -0,0 +1,54 @@
#
# 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/>.
#
PREFIX = §eTeam§8Server§8»
TIME = HH:mm:ss
DATE=........
COMMAND_HELP_HEAD=§7---=== (§e{0}§7) ===---
# Material
MATERIAL_INV_NAME=§eMaterial {0}/{1}
MATERIAL_SEARCH=§eSuchen
MATERIAL_BACK=§eZurück
MATERIAL_SEARCH_NAME=§eName
MATERIAL_SEARCH_TRANSPARENT=§eTransparent
MATERIAL_SEARCH_SOLID=§eSolide
MATERIAL_SEARCH_GRAVITY=§eFallend
MATERIAL_SEARCH_OCCLUDING=§eOccluding
MATERIAL_SEARCH_INTERACTEABLE=§eInterargierbar
MATERIAL_SEARCH_FLAMMABLE=§eFlammbar
MATERIAL_SEARCH_WATERLOGGABLE=§eWasserspeicherbar
MATERIAL_SEARCH_BLASTRESISTANCE=§eBlast Resistance
MATERIAL_SEARCH_BLASTRESISTANCE_MIN=§eBlast Resistance mindestens
MATERIAL_SEARCH_BLASTRESISTANCE_MAX=§eBlast Resistance maximal
MATERIAL_SEARCH_BLASTRESISTANCE_EXACT=§eBlast Resistance
MATERIAL_SEARCH_VALUE=§8: §e{0}
MATERIAL_BLAST-RESISTANCE=§8- §eBlast Resistance§8: §7{0}
MATERIAL_HARDNESS=§8- §eHärte§8: §7{0}
MATERIAL_TNT_BREAKABLE=§8- §eZerstörbar durch TNT
MATERIAL_TNT_UNBREAKABLE=§8- §eNicht Zerstörbar durch TNT
MATERIAL_TRANSPARENT=§8- §eTransparenter Block
MATERIAL_SOLID=§8- §eSolider Block
MATERIAL_GRAVITY=§8- §eFallender Block
MATERIAL_OCCLUDING=§8- §eOccluding Block
MATERIAL_INTERACT-ABLE=§8- §eInterargierbarer Block
MATERIAL_FLAMMABLE=§8- §eFlammbarer Block
MATERIAL_WATERLOGGABLE=§8- §eWasserspeicherbarer Block

Datei anzeigen

@ -17,8 +17,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.command;
package de.steamwar.teamserver.command;
import de.steamwar.command.SWCommand;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;

Datei anzeigen

@ -0,0 +1,302 @@
/*
* 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.teamserver.command;
import de.steamwar.command.SWCommand;
import de.steamwar.inventory.SWAnvilInv;
import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem;
import de.steamwar.inventory.SWListInv;
import de.steamwar.teamserver.Teamserver;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Waterlogged;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
public class MaterialCommand extends SWCommand implements Listener {
public MaterialCommand() {
super("material");
}
private List<MaterialData> materialData = new ArrayList<>();
private Map<Player, Search> searchMap = new HashMap<>();
{
for (Material value : Material.values()) {
if (!value.isBlock()) {
continue;
}
if (value.isLegacy()) {
continue;
}
materialData.add(new MaterialData(value));
}
}
private static class MaterialData {
private Material material;
private Material originalMaterial;
private String name;
private double blastResistance;
private double hardness;
private boolean transparent;
private boolean solid;
private boolean gravity;
private boolean occluding;
private boolean interacteable;
private boolean flammable;
private boolean waterloggable;
public MaterialData(Material material) {
this.originalMaterial = material;
name = material.name();
blastResistance = material.getBlastResistance();
hardness = material.getHardness();
transparent = material.isTransparent();
solid = material.isSolid();
gravity = material.hasGravity();
occluding = material.isOccluding();
interacteable = material.isInteractable();
flammable = material.isFlammable();
BlockData blockData = material.createBlockData();
waterloggable = blockData instanceof Waterlogged;
if (material.isItem() && material != Material.AIR) {
this.material = material;
} else {
this.material = Material.GHAST_TEAR;
}
}
public SWListInv.SWListEntry<Material> toSWItem(Player p) {
List<String> lore = new ArrayList<>();
lore.add(Teamserver.MESSAGE.parse("MATERIAL_BLAST-RESISTANCE", p, blastResistance));
lore.add(Teamserver.MESSAGE.parse(blastResistance > 9 ? "MATERIAL_TNT_UNBREAKABLE" : "MATERIAL_TNT_BREAKABLE", p));
lore.add(Teamserver.MESSAGE.parse("MATERIAL_HARDNESS", p, hardness));
if (transparent) {
lore.add(Teamserver.MESSAGE.parse("MATERIAL_TRANSPARENT", p));
}
if (solid) {
lore.add(Teamserver.MESSAGE.parse("MATERIAL_SOLID", p));
}
if (gravity) {
lore.add(Teamserver.MESSAGE.parse("MATERIAL_GRAVITY", p));
}
if (occluding) {
lore.add(Teamserver.MESSAGE.parse("MATERIAL_OCCLUDING", p));
}
if (interacteable) {
lore.add(Teamserver.MESSAGE.parse("MATERIAL_INTERACT-ABLE", p));
}
if (flammable) {
lore.add(Teamserver.MESSAGE.parse("MATERIAL_FLAMMABLE", p));
}
if (waterloggable) {
lore.add(Teamserver.MESSAGE.parse("MATERIAL_WATERLOGGABLE", p));
}
return new SWListInv.SWListEntry<>(new SWItem(material, "§e" + name, lore, false, clickType -> {
}), originalMaterial);
}
public boolean is(Search search) {
boolean result = true;
if (search.transparent) {
result &= transparent;
}
if (search.solid) {
result &= solid;
}
if (search.gravity) {
result &= gravity;
}
if (search.occluding) {
result &= occluding;
}
if (search.interacteable) {
result &= interacteable;
}
if (search.flammable) {
result &= flammable;
}
if (search.waterloggable) {
result &= waterloggable;
}
if (!result) {
return false;
}
if (!(blastResistance >= search.blastResistanceMin && blastResistance < search.blastResistanceMax)) {
return false;
}
if (search.name.isEmpty()) {
return true;
}
return Pattern.compile(".*" + search.name.toLowerCase().replace(' ', '.') + ".*").asPredicate().test(name.toLowerCase());
}
}
@Getter
@Setter
private static class Search {
private boolean transparent = false;
private boolean solid = false;
private boolean gravity = false;
private boolean occluding = false;
private boolean interacteable = false;
private boolean flammable = false;
private boolean waterloggable = false;
private double blastResistanceMin = 0;
private double blastResistanceMax = 5000000;
private String name = "";
}
@Register
public void materialGUI(Player p) {
List<SWListInv.SWListEntry<Material>> swListEntries = new ArrayList<>();
materialData.forEach(data -> {
if (data.is(searchMap.get(p))) {
swListEntries.add(data.toSWItem(p));
}
});
SWListInv<Material> materialSWListInv = new SWListInv<>(p, Teamserver.MESSAGE.parse("MATERIAL_INV_NAME", p, swListEntries.size(), materialData.size()), false, swListEntries, (clickType, material) -> {
});
materialSWListInv.setItem(49, new SWItem(Material.NAME_TAG, Teamserver.MESSAGE.parse("MATERIAL_SEARCH", p), clickType -> {
searchGUI(p);
}));
materialSWListInv.open();
}
private void searchGUI(Player p) {
SWInventory swInventory = new SWInventory(p, 54, Teamserver.MESSAGE.parse("MATERIAL_SEARCH", p));
Search search = searchMap.get(p);
swInventory.setItem(45, new SWItem(Material.ARROW, Teamserver.MESSAGE.parse("MATERIAL_BACK", p), clickType -> {
materialGUI(p);
}));
swInventory.setItem(10, new SWItem(Material.NAME_TAG, Teamserver.MESSAGE.parse("MATERIAL_SEARCH_NAME", p) + Teamserver.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.name), clickType -> {
SWAnvilInv swAnvilInv = new SWAnvilInv(p, Teamserver.MESSAGE.parse("MATERIAL_SEARCH_NAME", p), search.name);
swAnvilInv.setCallback(s -> {
search.name = s;
searchGUI(p);
});
swAnvilInv.open();
}));
swInventory.setItem(19, new SWItem(Material.GLASS, Teamserver.MESSAGE.parse("MATERIAL_SEARCH_TRANSPARENT", p) + Teamserver.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.transparent), clickType -> {
search.transparent = !search.transparent;
searchGUI(p);
}));
swInventory.setItem(20, new SWItem(Material.BRICK, Teamserver.MESSAGE.parse("MATERIAL_SEARCH_SOLID", p) + Teamserver.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.solid), clickType -> {
search.solid = !search.solid;
searchGUI(p);
}));
swInventory.setItem(21, new SWItem(Material.BLACK_CONCRETE_POWDER, Teamserver.MESSAGE.parse("MATERIAL_SEARCH_GRAVITY", p) + Teamserver.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.gravity), clickType -> {
search.gravity = !search.gravity;
searchGUI(p);
}));
swInventory.setItem(22, new SWItem(Material.BIRCH_LOG, Teamserver.MESSAGE.parse("MATERIAL_SEARCH_OCCLUDING", p) + Teamserver.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.occluding), clickType -> {
search.occluding = !search.occluding;
searchGUI(p);
}));
swInventory.setItem(23, new SWItem(Material.OAK_BUTTON, Teamserver.MESSAGE.parse("MATERIAL_SEARCH_INTERACTEABLE", p) + Teamserver.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.interacteable), clickType -> {
search.interacteable = !search.interacteable;
searchGUI(p);
}));
swInventory.setItem(24, new SWItem(Material.FLINT_AND_STEEL, Teamserver.MESSAGE.parse("MATERIAL_SEARCH_FLAMMABLE", p) + Teamserver.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.flammable), clickType -> {
search.flammable = !search.flammable;
searchGUI(p);
}));
swInventory.setItem(25, new SWItem(Material.WATER_BUCKET, Teamserver.MESSAGE.parse("MATERIAL_SEARCH_WATERLOGGABLE", p) + Teamserver.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.waterloggable), clickType -> {
search.waterloggable = !search.waterloggable;
searchGUI(p);
}));
swInventory.setItem(28, new SWItem(Material.FIRE_CHARGE, Teamserver.MESSAGE.parse("MATERIAL_SEARCH_BLASTRESISTANCE_MIN", p) + Teamserver.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.blastResistanceMin), clickType -> {
SWAnvilInv swAnvilInv = new SWAnvilInv(p, Teamserver.MESSAGE.parse("MATERIAL_SEARCH_BLASTRESISTANCE", p), search.blastResistanceMin + "");
swAnvilInv.setCallback(s -> {
try {
search.blastResistanceMin = Double.parseDouble(s);
if (search.blastResistanceMin < 0) search.blastResistanceMin = 0;
if (search.blastResistanceMin > 5000000) search.blastResistanceMin = 5000000;
if (search.blastResistanceMin > search.blastResistanceMax)
search.blastResistanceMin = search.blastResistanceMax;
} catch (NumberFormatException e) {
// Ignored
}
searchGUI(p);
});
swAnvilInv.open();
}));
swInventory.setItem(29, new SWItem(Material.TNT, Teamserver.MESSAGE.parse("MATERIAL_SEARCH_BLASTRESISTANCE_MAX", p) + Teamserver.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.blastResistanceMax), clickType -> {
SWAnvilInv swAnvilInv = new SWAnvilInv(p, Teamserver.MESSAGE.parse("MATERIAL_SEARCH_BLASTRESISTANCE", p), search.blastResistanceMax + "");
swAnvilInv.setCallback(s -> {
try {
search.blastResistanceMax = Double.parseDouble(s);
if (search.blastResistanceMax > 5000000) search.blastResistanceMax = 5000000;
if (search.blastResistanceMax < 0) search.blastResistanceMax = 0;
if (search.blastResistanceMax < search.blastResistanceMin)
search.blastResistanceMax = search.blastResistanceMin;
} catch (NumberFormatException e) {
// Ignored
}
searchGUI(p);
});
swAnvilInv.open();
}));
swInventory.setItem(31, new SWItem(Material.NETHER_BRICK, Teamserver.MESSAGE.parse("MATERIAL_SEARCH_BLASTRESISTANCE_EXACT", p) + Teamserver.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.blastResistanceMin + "-" + search.blastResistanceMax), clickType -> {
SWAnvilInv swAnvilInv = new SWAnvilInv(p, Teamserver.MESSAGE.parse("MATERIAL_SEARCH_BLASTRESISTANCE", p), search.blastResistanceMax + "");
swAnvilInv.setCallback(s -> {
try {
search.blastResistanceMax = Double.parseDouble(s);
if (search.blastResistanceMax > 5000000) search.blastResistanceMax = 5000000;
if (search.blastResistanceMax < 0) search.blastResistanceMax = 0;
search.blastResistanceMin = search.blastResistanceMax;
} catch (NumberFormatException e) {
// Ignored
}
searchGUI(p);
});
swAnvilInv.open();
}));
swInventory.open();
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
searchMap.put(event.getPlayer(), new Search());
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
searchMap.remove(event.getPlayer());
}
}

Datei anzeigen

@ -17,14 +17,15 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.command;
package de.steamwar.teamserver.command;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import de.steamwar.Teamserver;
import de.steamwar.command.SWCommand;
import de.steamwar.teamserver.Teamserver;
import de.steamwar.sql.Schematic;
import de.steamwar.sql.SteamwarUser;
import lombok.AllArgsConstructor;

Datei anzeigen

@ -17,8 +17,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.command;
package de.steamwar.teamserver.command;
import de.steamwar.command.SWCommand;
import org.bukkit.entity.Player;
public class SpeedCommand extends SWCommand {

Datei anzeigen

@ -17,9 +17,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.listener;
package de.steamwar.teamserver.listener;
import de.steamwar.Teamserver;
import de.steamwar.teamserver.Teamserver;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.event.EventHandler;

Datei anzeigen

@ -1,6 +1,6 @@
name: Teamserver
version: 1.0
main: de.steamwar.Teamserver
main: de.steamwar.teamserver.Teamserver
api-version: 1.15
prefix: Teamserver
depend: [ SpigotCore ]