SteamWar/BauSystem2.0
Archiviert
12
0

Update MaterialCommand

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2021-10-03 12:56:05 +02:00
Ursprung 9666d1e61c
Commit 85f87cf32b
2 geänderte Dateien mit 32 neuen und 8 gelöschten Zeilen

Datei anzeigen

@ -390,12 +390,14 @@ 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
@ -404,6 +406,7 @@ 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
# Redstonetester
RT_HELP_1=§8/§eredstonetester §8-§7 Gibt den RedstoneTester
RT_GIVEN=§7Messe die Zeit zwischen der Aktivierung zweier Redstone Komponenten

Datei anzeigen

@ -30,6 +30,8 @@ import de.steamwar.inventory.SWListInv;
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;
@ -40,6 +42,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
@Linked(LinkageType.COMMAND)
@Linked(LinkageType.LISTENER)
@ -70,24 +73,29 @@ public class MaterialCommand extends SWCommand implements Listener {
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;
@ -100,6 +108,7 @@ public class MaterialCommand extends SWCommand implements Listener {
List<String> lore = new ArrayList<>();
lore.add(BauSystem.MESSAGE.parse("MATERIAL_BLAST-RESISTANCE", p, blastResistance));
lore.add(BauSystem.MESSAGE.parse(blastResistance > 9 ? "MATERIAL_TNT_UNBREAKABLE" : "MATERIAL_TNT_BREAKABLE", p));
lore.add(BauSystem.MESSAGE.parse("MATERIAL_HARDNESS", p, hardness));
if (transparent) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_TRANSPARENT", p));
}
@ -118,7 +127,11 @@ public class MaterialCommand extends SWCommand implements Listener {
if (flammable) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_FLAMMABLE", p));
}
return new SWListInv.SWListEntry<>(new SWItem(material, "§e" + name, lore, false, clickType -> {}), originalMaterial);
if (waterloggable) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_WATTERLOGGABLE", p));
}
return new SWListInv.SWListEntry<>(new SWItem(material, "§e" + name, lore, false, clickType -> {
}), originalMaterial);
}
public boolean is(Search search) {
@ -141,6 +154,9 @@ public class MaterialCommand extends SWCommand implements Listener {
if (search.flammable) {
result &= flammable;
}
if (search.waterloggable) {
result &= waterloggable;
}
if (!result) {
return false;
}
@ -150,10 +166,7 @@ public class MaterialCommand extends SWCommand implements Listener {
if (search.name.isEmpty()) {
return true;
}
if (!name.toLowerCase().contains(search.name.toLowerCase())) {
return false;
}
return true;
return Pattern.compile(".*" + search.name.toLowerCase().replace(' ', '.') + ".*").asPredicate().test(name.toLowerCase());
}
}
@ -166,6 +179,7 @@ public class MaterialCommand extends SWCommand implements Listener {
private boolean occluding = false;
private boolean interacteable = false;
private boolean flammable = false;
private boolean waterloggable = false;
private double blastResistanceMin = 0;
private double blastResistanceMax = 5000000;
@ -180,7 +194,8 @@ public class MaterialCommand extends SWCommand implements Listener {
swListEntries.add(data.toSWItem(p));
}
});
SWListInv<Material> materialSWListInv = new SWListInv<>(p, BauSystem.MESSAGE.parse("MATERIAL_INV_NAME", p, swListEntries.size(), materialData.size()), false, swListEntries, (clickType, material) -> {});
SWListInv<Material> materialSWListInv = new SWListInv<>(p, BauSystem.MESSAGE.parse("MATERIAL_INV_NAME", p, swListEntries.size(), materialData.size()), false, swListEntries, (clickType, material) -> {
});
materialSWListInv.setItem(49, new SWItem(Material.NAME_TAG, BauSystem.MESSAGE.parse("MATERIAL_SEARCH", p), clickType -> {
searchGUI(p);
}));
@ -225,6 +240,10 @@ public class MaterialCommand extends SWCommand implements Listener {
search.flammable = !search.flammable;
searchGUI(p);
}));
swInventory.setItem(25, new SWItem(Material.WATER_BUCKET, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_WATERLOGGABLE", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.waterloggable), clickType -> {
search.waterloggable = !search.waterloggable;
searchGUI(p);
}));
swInventory.setItem(28, new SWItem(Material.FIRE_CHARGE, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_BLASTRESISTANCE_MIN", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.blastResistanceMin), clickType -> {
SWAnvilInv swAnvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_BLASTRESISTANCE", p), search.blastResistanceMin + "");
swAnvilInv.setCallback(s -> {
@ -232,7 +251,8 @@ public class MaterialCommand extends SWCommand implements Listener {
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;
if (search.blastResistanceMin > search.blastResistanceMax)
search.blastResistanceMin = search.blastResistanceMax;
} catch (NumberFormatException e) {
// Ignored
}
@ -247,7 +267,8 @@ public class MaterialCommand extends SWCommand implements Listener {
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;
if (search.blastResistanceMax < search.blastResistanceMin)
search.blastResistanceMax = search.blastResistanceMin;
} catch (NumberFormatException e) {
// Ignored
}