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_OCCLUDING=§eOccluding
MATERIAL_SEARCH_INTERACTEABLE=§eInterargierbar MATERIAL_SEARCH_INTERACTEABLE=§eInterargierbar
MATERIAL_SEARCH_FLAMMABLE=§eFlammbar MATERIAL_SEARCH_FLAMMABLE=§eFlammbar
MATERIAL_SEARCH_WATERLOGGABLE=§eWasserspeicherbar
MATERIAL_SEARCH_BLASTRESISTANCE=§eBlast Resistance MATERIAL_SEARCH_BLASTRESISTANCE=§eBlast Resistance
MATERIAL_SEARCH_BLASTRESISTANCE_MIN=§eBlast Resistance mindestens MATERIAL_SEARCH_BLASTRESISTANCE_MIN=§eBlast Resistance mindestens
MATERIAL_SEARCH_BLASTRESISTANCE_MAX=§eBlast Resistance maximal MATERIAL_SEARCH_BLASTRESISTANCE_MAX=§eBlast Resistance maximal
MATERIAL_SEARCH_BLASTRESISTANCE_EXACT=§eBlast Resistance MATERIAL_SEARCH_BLASTRESISTANCE_EXACT=§eBlast Resistance
MATERIAL_SEARCH_VALUE=§8: §e{0} MATERIAL_SEARCH_VALUE=§8: §e{0}
MATERIAL_BLAST-RESISTANCE=§8- §eBlast Resistance§8: §7{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_BREAKABLE=§8- §eZerstörbar durch TNT
MATERIAL_TNT_UNBREAKABLE=§8- §eNicht Zerstörbar durch TNT MATERIAL_TNT_UNBREAKABLE=§8- §eNicht Zerstörbar durch TNT
MATERIAL_TRANSPARENT=§8- §eTransparenter Block MATERIAL_TRANSPARENT=§8- §eTransparenter Block
@ -404,6 +406,7 @@ MATERIAL_GRAVITY=§8- §eFallender Block
MATERIAL_OCCLUDING=§8- §eOccluding Block MATERIAL_OCCLUDING=§8- §eOccluding Block
MATERIAL_INTERACT-ABLE=§8- §eInterargierbarer Block MATERIAL_INTERACT-ABLE=§8- §eInterargierbarer Block
MATERIAL_FLAMMABLE=§8- §eFlammbarer Block MATERIAL_FLAMMABLE=§8- §eFlammbarer Block
MATERIAL_WATERLOGGABLE=§8- §eWasserspeicherbarer Block
# Redstonetester # Redstonetester
RT_HELP_1=§8/§eredstonetester §8-§7 Gibt den RedstoneTester RT_HELP_1=§8/§eredstonetester §8-§7 Gibt den RedstoneTester
RT_GIVEN=§7Messe die Zeit zwischen der Aktivierung zweier Redstone Komponenten 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.Getter;
import lombok.Setter; import lombok.Setter;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Waterlogged;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -40,6 +42,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.regex.Pattern;
@Linked(LinkageType.COMMAND) @Linked(LinkageType.COMMAND)
@Linked(LinkageType.LISTENER) @Linked(LinkageType.LISTENER)
@ -70,24 +73,29 @@ public class MaterialCommand extends SWCommand implements Listener {
private String name; private String name;
private double blastResistance; private double blastResistance;
private double hardness;
private boolean transparent; private boolean transparent;
private boolean solid; private boolean solid;
private boolean gravity; private boolean gravity;
private boolean occluding; private boolean occluding;
private boolean interacteable; private boolean interacteable;
private boolean flammable; private boolean flammable;
private boolean waterloggable;
public MaterialData(Material material) { public MaterialData(Material material) {
this.originalMaterial = material; this.originalMaterial = material;
name = material.name(); name = material.name();
blastResistance = material.getBlastResistance(); blastResistance = material.getBlastResistance();
hardness = material.getHardness();
transparent = material.isTransparent(); transparent = material.isTransparent();
solid = material.isSolid(); solid = material.isSolid();
gravity = material.hasGravity(); gravity = material.hasGravity();
occluding = material.isOccluding(); occluding = material.isOccluding();
interacteable = material.isInteractable(); interacteable = material.isInteractable();
flammable = material.isFlammable(); flammable = material.isFlammable();
BlockData blockData = material.createBlockData();
waterloggable = blockData instanceof Waterlogged;
if (material.isItem() && material != Material.AIR) { if (material.isItem() && material != Material.AIR) {
this.material = material; this.material = material;
@ -100,6 +108,7 @@ public class MaterialCommand extends SWCommand implements Listener {
List<String> lore = new ArrayList<>(); List<String> lore = new ArrayList<>();
lore.add(BauSystem.MESSAGE.parse("MATERIAL_BLAST-RESISTANCE", p, blastResistance)); 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(blastResistance > 9 ? "MATERIAL_TNT_UNBREAKABLE" : "MATERIAL_TNT_BREAKABLE", p));
lore.add(BauSystem.MESSAGE.parse("MATERIAL_HARDNESS", p, hardness));
if (transparent) { if (transparent) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_TRANSPARENT", p)); lore.add(BauSystem.MESSAGE.parse("MATERIAL_TRANSPARENT", p));
} }
@ -118,7 +127,11 @@ public class MaterialCommand extends SWCommand implements Listener {
if (flammable) { if (flammable) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_FLAMMABLE", p)); 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) { public boolean is(Search search) {
@ -141,6 +154,9 @@ public class MaterialCommand extends SWCommand implements Listener {
if (search.flammable) { if (search.flammable) {
result &= flammable; result &= flammable;
} }
if (search.waterloggable) {
result &= waterloggable;
}
if (!result) { if (!result) {
return false; return false;
} }
@ -150,10 +166,7 @@ public class MaterialCommand extends SWCommand implements Listener {
if (search.name.isEmpty()) { if (search.name.isEmpty()) {
return true; return true;
} }
if (!name.toLowerCase().contains(search.name.toLowerCase())) { return Pattern.compile(".*" + search.name.toLowerCase().replace(' ', '.') + ".*").asPredicate().test(name.toLowerCase());
return false;
}
return true;
} }
} }
@ -166,6 +179,7 @@ public class MaterialCommand extends SWCommand implements Listener {
private boolean occluding = false; private boolean occluding = false;
private boolean interacteable = false; private boolean interacteable = false;
private boolean flammable = false; private boolean flammable = false;
private boolean waterloggable = false;
private double blastResistanceMin = 0; private double blastResistanceMin = 0;
private double blastResistanceMax = 5000000; private double blastResistanceMax = 5000000;
@ -180,7 +194,8 @@ public class MaterialCommand extends SWCommand implements Listener {
swListEntries.add(data.toSWItem(p)); 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 -> { materialSWListInv.setItem(49, new SWItem(Material.NAME_TAG, BauSystem.MESSAGE.parse("MATERIAL_SEARCH", p), clickType -> {
searchGUI(p); searchGUI(p);
})); }));
@ -225,6 +240,10 @@ public class MaterialCommand extends SWCommand implements Listener {
search.flammable = !search.flammable; search.flammable = !search.flammable;
searchGUI(p); 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 -> { 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 swAnvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_BLASTRESISTANCE", p), search.blastResistanceMin + "");
swAnvilInv.setCallback(s -> { swAnvilInv.setCallback(s -> {
@ -232,7 +251,8 @@ public class MaterialCommand extends SWCommand implements Listener {
search.blastResistanceMin = Double.parseDouble(s); search.blastResistanceMin = Double.parseDouble(s);
if (search.blastResistanceMin < 0) search.blastResistanceMin = 0; if (search.blastResistanceMin < 0) search.blastResistanceMin = 0;
if (search.blastResistanceMin > 5000000) search.blastResistanceMin = 5000000; 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) { } catch (NumberFormatException e) {
// Ignored // Ignored
} }
@ -247,7 +267,8 @@ public class MaterialCommand extends SWCommand implements Listener {
search.blastResistanceMax = Double.parseDouble(s); search.blastResistanceMax = Double.parseDouble(s);
if (search.blastResistanceMax > 5000000) search.blastResistanceMax = 5000000; if (search.blastResistanceMax > 5000000) search.blastResistanceMax = 5000000;
if (search.blastResistanceMax < 0) search.blastResistanceMax = 0; 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) { } catch (NumberFormatException e) {
// Ignored // Ignored
} }