Added ability to define matrial for each gate seperatly.
This commit is contained in:
parent
4c7f1201bd
commit
465533f4fe
@ -71,19 +71,16 @@ public class CommandInfo extends BaseCommand {
|
||||
sendMessage(TextUtil.titleSize("Information about closest gate: '" + ChatColor.WHITE + gate.getId() + ChatColor.YELLOW + "'"));
|
||||
}
|
||||
|
||||
String openHiddenMessage = ChatColor.DARK_AQUA + "This gate is";
|
||||
String openMessage = ChatColor.DARK_AQUA + "This gate is";
|
||||
|
||||
if (gate.isOpen())
|
||||
openHiddenMessage += ChatColor.AQUA + " open";
|
||||
openMessage += ChatColor.AQUA + " open";
|
||||
else
|
||||
openHiddenMessage += ChatColor.AQUA + " closed";
|
||||
openMessage += ChatColor.AQUA + " closed";
|
||||
|
||||
if (gate.isHidden())
|
||||
openHiddenMessage += ChatColor.DARK_AQUA + " and" + ChatColor.AQUA + " hidden";
|
||||
openMessage += ".\n";
|
||||
|
||||
openHiddenMessage += ".\n";
|
||||
|
||||
sendMessage(openHiddenMessage);
|
||||
sendMessage(openMessage);
|
||||
|
||||
if (gate.getLocation() != null)
|
||||
sendMessage(ChatColor.DARK_AQUA + "location: " + ChatColor.AQUA + "( " + (int) gate.getLocation().getX() +
|
||||
@ -103,6 +100,8 @@ public class CommandInfo extends BaseCommand {
|
||||
if (gate.getAllowsVehicles())
|
||||
sendMessage(ChatColor.DARK_AQUA + "You can ride through this gate.");
|
||||
|
||||
sendMessage(ChatColor.DARK_AQUA + "This gate is made of "
|
||||
+ ChatColor.AQUA + gate.getMaterial() + ChatColor.DARK_AQUA + ".");
|
||||
|
||||
if (this.sender instanceof Player) {
|
||||
HashSet<Gate> set = new HashSet<>();
|
||||
|
@ -1,6 +1,11 @@
|
||||
package de.craftinc.gates.commands;
|
||||
|
||||
import de.craftinc.gates.controllers.PermissionController;
|
||||
import de.craftinc.gates.models.GateMaterial;
|
||||
import de.craftinc.gates.util.GateBlockChangeSender;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
|
||||
public class CommandMaterial extends BaseCommand {
|
||||
|
||||
@ -9,6 +14,7 @@ public class CommandMaterial extends BaseCommand {
|
||||
aliases.add("m");
|
||||
|
||||
requiredParameters.add("id");
|
||||
requiredParameters.add("material");
|
||||
|
||||
senderMustBePlayer = false;
|
||||
hasGateParam = true;
|
||||
@ -19,5 +25,21 @@ public class CommandMaterial extends BaseCommand {
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
GateMaterial material;
|
||||
try {
|
||||
material = new GateMaterial(parameters.get(1));
|
||||
} catch (InvalidParameterException e) {
|
||||
sendMessage(ChatColor.RED + "Invalid material!");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
gate.setMaterial(material);
|
||||
} catch (Exception e) {
|
||||
sendMessage(ChatColor.RED + "Frame invalid. Gate is now closed!");
|
||||
}
|
||||
|
||||
GateBlockChangeSender.updateGateBlocks(gate);
|
||||
sendMessage(ChatColor.GREEN + "Gate " + gate.getId() + " uses now " + material.toString() + " as material.");
|
||||
}
|
||||
}
|
||||
|
@ -42,11 +42,11 @@ public class CommandTriggerOpen extends BaseCommand {
|
||||
sendMessage(ChatColor.GREEN + "The exit of gate '" + gate.getId() + "' is now where you stand.");
|
||||
}
|
||||
|
||||
gate.setOpen(gate.isOpen());
|
||||
gate.setOpen(!gate.isOpen());
|
||||
|
||||
GateBlockChangeSender.updateGateBlocks(gate);
|
||||
gatesManager.handleGateLocationChange(gate, null, null, null);
|
||||
sendMessage(ChatColor.GREEN + "The gate was opened.");
|
||||
sendMessage(ChatColor.GREEN + "The gate is now " + (gate.isOpen() ? "open." : "closed."));
|
||||
} catch (Exception e) {
|
||||
sendMessage(ChatColor.RED + e.getMessage());
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ package de.craftinc.gates.listeners;
|
||||
import de.craftinc.gates.models.Gate;
|
||||
import de.craftinc.gates.Plugin;
|
||||
import de.craftinc.gates.util.GateBlockChangeSender;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -34,7 +35,7 @@ public class BlockBreakListener implements Listener {
|
||||
|
||||
Gate gate = Plugin.getPlugin().getGatesManager().getGateAtFrameLocation(event.getBlock().getLocation());
|
||||
|
||||
if (gate != null && !gate.isHidden()) {
|
||||
if (gate != null && gate.getMaterial().getMaterial() != Material.AIR) {
|
||||
try {
|
||||
gate.setOpen(false);
|
||||
} catch (Exception ignored) {}
|
||||
|
@ -34,10 +34,10 @@ public class Gate implements ConfigurationSerializable {
|
||||
private Set<Location> gateBlockLocations = new HashSet<>(); /* Locations of the blocks inside the gate */
|
||||
private Set<Block> gateFrameBlocks = new HashSet<>();
|
||||
private Location exit;
|
||||
private boolean isHidden = false;
|
||||
private boolean isOpen = false;
|
||||
private boolean allowsVehicles = true;
|
||||
private String id;
|
||||
private GateMaterial material = new GateMaterial(Material.PORTAL);
|
||||
|
||||
/**
|
||||
* You should never create two gates with the same 'id'. Also see 'setId(String id)'.
|
||||
@ -64,6 +64,15 @@ public class Gate implements ConfigurationSerializable {
|
||||
}
|
||||
}
|
||||
|
||||
public GateMaterial getMaterial() {
|
||||
return material;
|
||||
}
|
||||
|
||||
public void setMaterial(GateMaterial material) throws Exception {
|
||||
this.material = material;
|
||||
validate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return This method might return a 'null' data.
|
||||
*/
|
||||
@ -128,15 +137,6 @@ public class Gate implements ConfigurationSerializable {
|
||||
this.id = id.toLowerCase();
|
||||
}
|
||||
|
||||
public boolean isHidden() {
|
||||
return isHidden;
|
||||
}
|
||||
|
||||
public void setHidden(boolean isHidden) throws Exception {
|
||||
this.isHidden = isHidden;
|
||||
this.validate();
|
||||
}
|
||||
|
||||
public boolean isOpen() {
|
||||
return isOpen;
|
||||
}
|
||||
@ -217,22 +217,29 @@ public class Gate implements ConfigurationSerializable {
|
||||
throw new Exception("Gate got closed. The frame is missing or broken. (no gate blocks)");
|
||||
}
|
||||
|
||||
if (!isHidden() && Plugin.getPlugin().getConfig().getBoolean(ConfigurationUtil.confCheckForBrokenGateFramesKey)) {
|
||||
validateFrame();
|
||||
}
|
||||
|
||||
for (Block b : gateFrameBlocks) {
|
||||
private void validateFrame() throws Exception {
|
||||
boolean isAir = material.getMaterial() == Material.AIR;
|
||||
boolean ignore = !Plugin.getPlugin().getConfig().getBoolean(ConfigurationUtil.confCheckForBrokenGateFramesKey);
|
||||
|
||||
if (b.getType() == Material.AIR) {
|
||||
isOpen = false;
|
||||
this.gateBlockLocations = new HashSet<>();
|
||||
this.gateFrameBlocks = new HashSet<>();
|
||||
if (isAir || ignore) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Exception("Gate got closed. The frame is missing or broken. (missing frame block(s))");
|
||||
}
|
||||
for (Block b : gateFrameBlocks) {
|
||||
|
||||
if (b.getType() == Material.AIR) {
|
||||
isOpen = false;
|
||||
this.gateBlockLocations = new HashSet<>();
|
||||
this.gateFrameBlocks = new HashSet<>();
|
||||
|
||||
throw new Exception("Gate got closed. The frame is missing or broken. (missing frame block(s))");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* INTERFACE: ConfigurationSerializable
|
||||
*/
|
||||
@ -240,7 +247,7 @@ public class Gate implements ConfigurationSerializable {
|
||||
static private String locationKey = "location";
|
||||
static private String gateBlocksKey = "gateBlocks";
|
||||
static private String exitKey = "exit";
|
||||
static private String isHiddenKey = "hidden";
|
||||
static private String materialKey = "material";
|
||||
static private String isOpenKey = "open";
|
||||
static private String locationYawKey = "locationYaw";
|
||||
static private String locationPitchKey = "locationPitch";
|
||||
@ -254,11 +261,11 @@ public class Gate implements ConfigurationSerializable {
|
||||
try {
|
||||
id = map.get(idKey).toString().toLowerCase();
|
||||
|
||||
isHidden = (Boolean) map.get(isHiddenKey);
|
||||
isOpen = (Boolean) map.get(isOpenKey);
|
||||
|
||||
location = LocationUtil.deserializeLocation((Map<String, Object>) map.get(locationKey));
|
||||
exit = LocationUtil.deserializeLocation((Map<String, Object>) map.get(exitKey));
|
||||
material = new GateMaterial((String)map.get(materialKey));
|
||||
|
||||
if (map.containsKey(exitPitchKey)) {
|
||||
exit.setPitch(((Number) map.get(exitPitchKey)).floatValue());
|
||||
@ -303,9 +310,9 @@ public class Gate implements ConfigurationSerializable {
|
||||
retVal.put(idKey, id);
|
||||
retVal.put(locationKey, LocationUtil.serializeLocation(location));
|
||||
retVal.put(exitKey, LocationUtil.serializeLocation(exit));
|
||||
retVal.put(isHiddenKey, isHidden);
|
||||
retVal.put(isOpenKey, isOpen);
|
||||
retVal.put(allowsVehiclesKey, allowsVehicles);
|
||||
retVal.put(materialKey, material.toString());
|
||||
|
||||
if (exit != null) {
|
||||
retVal.put(exitPitchKey, exit.getPitch());
|
||||
|
@ -5,13 +5,19 @@ import org.bukkit.Material;
|
||||
import java.security.InvalidParameterException;
|
||||
|
||||
public class GateMaterial {
|
||||
|
||||
private Material material;
|
||||
|
||||
GateMaterial(Material material) {
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
public GateMaterial(String materialString) throws InvalidParameterException {
|
||||
Material material;
|
||||
|
||||
switch (materialString) {
|
||||
case "air":
|
||||
material = Material.AIR;
|
||||
break;
|
||||
case "sapling":
|
||||
material = Material.SAPLING;
|
||||
break;
|
||||
@ -85,6 +91,60 @@ public class GateMaterial {
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
switch (material) {
|
||||
case AIR:
|
||||
return "air";
|
||||
case SAPLING:
|
||||
return "sapling";
|
||||
case STATIONARY_WATER:
|
||||
return "water";
|
||||
case STATIONARY_LAVA:
|
||||
return "lava";
|
||||
case WEB:
|
||||
return "cobweb";
|
||||
case LONG_GRASS:
|
||||
return "grass";
|
||||
case DEAD_BUSH:
|
||||
return "dead bush";
|
||||
case YELLOW_FLOWER:
|
||||
return "dandelion";
|
||||
case RED_ROSE:
|
||||
return "poppy";
|
||||
case BROWN_MUSHROOM:
|
||||
return "brown mushroom";
|
||||
case RED_MUSHROOM:
|
||||
return "red mushroom";
|
||||
case TORCH:
|
||||
return "torch";
|
||||
case REDSTONE_TORCH_OFF:
|
||||
return "redstone torch (off)";
|
||||
case REDSTONE_TORCH_ON:
|
||||
return "redstone torch (on)";
|
||||
case FENCE:
|
||||
return "fence";
|
||||
case PORTAL:
|
||||
return "nether portal";
|
||||
case IRON_FENCE:
|
||||
return "iron bars";
|
||||
case THIN_GLASS:
|
||||
return "glass pane";
|
||||
case FENCE_GATE:
|
||||
return "fence gate";
|
||||
case NETHER_FENCE:
|
||||
return "nether brick fence";
|
||||
case NETHER_WARTS:
|
||||
return "nether wart";
|
||||
case ENDER_PORTAL:
|
||||
return "end portal";
|
||||
case COBBLE_WALL:
|
||||
return "cobblestone wall";
|
||||
default:
|
||||
return "nether portal";
|
||||
}
|
||||
}
|
||||
|
||||
public Material getMaterial() {
|
||||
return material;
|
||||
}
|
||||
|
@ -16,12 +16,6 @@
|
||||
*/
|
||||
package de.craftinc.gates.util;
|
||||
|
||||
import de.craftinc.gates.Plugin;
|
||||
import de.craftinc.gates.models.GateMaterial;
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class ConfigurationUtil {
|
||||
public static final String confMaxGateBlocksKey = "maxGateBlocks";
|
||||
public static final String confPlayerGateBlockUpdateRadiusKey = "playerGateBlockUpdateRadius";
|
||||
@ -33,17 +27,4 @@ public class ConfigurationUtil {
|
||||
public static final String confShowTeleportNoPermissionMessageKey = "showTeleportNoPermissionMessage";
|
||||
public static final String confSaveOnChangesKey = "saveOnChanges";
|
||||
public static final String confHighlightDurationKey = "highlightDuration";
|
||||
public static final String confGateMaterialKey = "gateMaterial";
|
||||
|
||||
|
||||
static GateMaterial getPortalMaterial() {
|
||||
String materialString = Plugin.getPlugin().getConfig().getString(confGateMaterialKey);
|
||||
|
||||
try {
|
||||
return new GateMaterial(materialString);
|
||||
} catch (InvalidParameterException ignored) {
|
||||
Plugin.log(Level.WARNING, "Gate material invalid! Please check and correct your configuration file!");
|
||||
return new GateMaterial("nether portal");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ public class GateBlockChangeSender {
|
||||
}
|
||||
|
||||
for (Gate g : gatesNearby) {
|
||||
if (!g.isOpen() || g.isHidden()) {
|
||||
if (!g.isOpen()) {
|
||||
continue;
|
||||
}
|
||||
sendGateBlockChanges(g, true, player);
|
||||
@ -124,7 +124,7 @@ public class GateBlockChangeSender {
|
||||
}
|
||||
}
|
||||
|
||||
boolean isVisible = gate.isOpen() && !gate.isHidden() && !remove;
|
||||
boolean isVisible = gate.isOpen() && !remove;
|
||||
for (Player p : playersNearby) {
|
||||
sendGateBlockChanges(gate, isVisible, p);
|
||||
}
|
||||
@ -157,7 +157,7 @@ public class GateBlockChangeSender {
|
||||
Material material;
|
||||
|
||||
if (isVisible) {
|
||||
GateMaterial gm = getPortalMaterial();
|
||||
GateMaterial gm = gate.getMaterial();
|
||||
data = gm.getData(gate.getDirection());
|
||||
material = gm.getMaterial();
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user