Add custom buttons for gates (Closes #7)
This commit is contained in:
parent
457d004abd
commit
2628553627
@ -13,6 +13,7 @@ import java.util.Scanner;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Tag;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,6 +54,7 @@ public class Gate {
|
|||||||
private final HashMap<RelativeBlockVector, Integer> exits = new HashMap<>();
|
private final HashMap<RelativeBlockVector, Integer> exits = new HashMap<>();
|
||||||
private Material portalBlockOpen = Material.NETHER_PORTAL;
|
private Material portalBlockOpen = Material.NETHER_PORTAL;
|
||||||
private Material portalBlockClosed = Material.AIR;
|
private Material portalBlockClosed = Material.AIR;
|
||||||
|
private Material button = Material.STONE_BUTTON;
|
||||||
|
|
||||||
// Economy information
|
// Economy information
|
||||||
private int useCost = -1;
|
private int useCost = -1;
|
||||||
@ -120,6 +122,7 @@ public class Gate {
|
|||||||
|
|
||||||
writeConfig(bw, "portal-open", portalBlockOpen.name());
|
writeConfig(bw, "portal-open", portalBlockOpen.name());
|
||||||
writeConfig(bw, "portal-closed", portalBlockClosed.name());
|
writeConfig(bw, "portal-closed", portalBlockClosed.name());
|
||||||
|
writeConfig(bw, "button", button.name());
|
||||||
if (useCost != -1)
|
if (useCost != -1)
|
||||||
writeConfig(bw, "usecost", useCost);
|
writeConfig(bw, "usecost", useCost);
|
||||||
if (createCost != -1)
|
if (createCost != -1)
|
||||||
@ -224,7 +227,11 @@ public class Gate {
|
|||||||
public void setPortalBlockClosed(Material type) {
|
public void setPortalBlockClosed(Material type) {
|
||||||
portalBlockClosed = type;
|
portalBlockClosed = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Material getButton() {
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
public int getUseCost() {
|
public int getUseCost() {
|
||||||
if (useCost < 0) return EconomyHandler.useCost;
|
if (useCost < 0) return EconomyHandler.useCost;
|
||||||
return useCost;
|
return useCost;
|
||||||
@ -379,6 +386,7 @@ public class Gate {
|
|||||||
|
|
||||||
gate.portalBlockOpen = readConfig(config, gate, file, "portal-open", gate.portalBlockOpen);
|
gate.portalBlockOpen = readConfig(config, gate, file, "portal-open", gate.portalBlockOpen);
|
||||||
gate.portalBlockClosed = readConfig(config, gate, file, "portal-closed", gate.portalBlockClosed);
|
gate.portalBlockClosed = readConfig(config, gate, file, "portal-closed", gate.portalBlockClosed);
|
||||||
|
gate.button = readConfig(config, gate, file, "button", gate.button);
|
||||||
gate.useCost = readConfig(config, gate, file, "usecost", -1);
|
gate.useCost = readConfig(config, gate, file, "usecost", -1);
|
||||||
gate.destroyCost = readConfig(config, gate, file, "destroycost", -1);
|
gate.destroyCost = readConfig(config, gate, file, "destroycost", -1);
|
||||||
gate.createCost = readConfig(config, gate, file, "createcost", -1);
|
gate.createCost = readConfig(config, gate, file, "createcost", -1);
|
||||||
@ -388,6 +396,11 @@ public class Gate {
|
|||||||
Stargate.log.log(Level.SEVERE, "Could not load Gate " + file.getName() + " - Gates must have exactly 2 control points.");
|
Stargate.log.log(Level.SEVERE, "Could not load Gate " + file.getName() + " - Gates must have exactly 2 control points.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!Tag.BUTTONS.isTagged(gate.button)) {
|
||||||
|
Stargate.log.log(Level.SEVERE, "Could not load Gate " + file.getName() + " - Gate button must be a type of button.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// Merge frame types, add open mat to list
|
// Merge frame types, add open mat to list
|
||||||
frameBlocks.addAll(frameTypes);
|
frameBlocks.addAll(frameTypes);
|
||||||
|
@ -1154,8 +1154,7 @@ public class Portal {
|
|||||||
// No button on an always-open gate.
|
// No button on an always-open gate.
|
||||||
if (!alwaysOn) {
|
if (!alwaysOn) {
|
||||||
button = topleft.modRelative(buttonVector.getRight(), buttonVector.getDepth(), buttonVector.getDistance() + 1, modX, 1, modZ);
|
button = topleft.modRelative(buttonVector.getRight(), buttonVector.getDepth(), buttonVector.getDistance() + 1, modX, 1, modZ);
|
||||||
button.setType(Material.STONE_BUTTON);
|
Directional buttondata = (Directional) Bukkit.createBlockData(gate.getButton());
|
||||||
Directional buttondata = (Directional) button.getBlock().getBlockData();
|
|
||||||
buttondata.setFacing(buttonfacing);
|
buttondata.setFacing(buttonfacing);
|
||||||
button.getBlock().setBlockData(buttondata);
|
button.getBlock().setBlockData(buttondata);
|
||||||
portal.setButton(button);
|
portal.setButton(button);
|
||||||
|
@ -24,6 +24,7 @@ import org.bukkit.ChatColor;
|
|||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.Tag;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.EndGateway;
|
import org.bukkit.block.EndGateway;
|
||||||
@ -926,7 +927,7 @@ public class Stargate extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Implement right-click to toggle a stargate, gets around spawn protection problem.
|
// Implement right-click to toggle a stargate, gets around spawn protection problem.
|
||||||
if ((block.getType() == Material.STONE_BUTTON)) {
|
if (Tag.BUTTONS.isTagged(block.getType())) {
|
||||||
Portal portal = Portal.getByBlock(block);
|
Portal portal = Portal.getByBlock(block);
|
||||||
if (portal == null) return;
|
if (portal == null) return;
|
||||||
|
|
||||||
@ -1072,7 +1073,7 @@ public class Stargate extends JavaPlugin {
|
|||||||
// Handle keeping portal material and buttons around
|
// Handle keeping portal material and buttons around
|
||||||
if (block.getType() == Material.NETHER_PORTAL) {
|
if (block.getType() == Material.NETHER_PORTAL) {
|
||||||
portal = Portal.getByEntrance(block);
|
portal = Portal.getByEntrance(block);
|
||||||
} else if (block.getType() == Material.STONE_BUTTON) {
|
} else if (Tag.BUTTONS.isTagged(block.getType())) {
|
||||||
portal = Portal.getByControl(block);
|
portal = Portal.getByControl(block);
|
||||||
}
|
}
|
||||||
if (portal != null) event.setCancelled(true);
|
if (portal != null) event.setCancelled(true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user