Refactored the Gate class: removed the fill and empty methods.
This commit is contained in:
parent
3cac4e70cc
commit
30d15c141e
@ -1,26 +1,16 @@
|
||||
package de.craftinc.gates;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
|
||||
import de.craftinc.gates.util.FloodUtil;
|
||||
import de.craftinc.gates.util.LocationUtil;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class Gate implements ConfigurationSerializable
|
||||
{
|
||||
/*
|
||||
* ATTRIBUTES
|
||||
*/
|
||||
protected Location location; /* saving both location and gateBlockLocations is redundant but makes it easy to allow players to reshape gates */
|
||||
protected Set<Location> gateBlockLocations = new HashSet<Location>(); /* Locations of the blocks inside the gate */
|
||||
|
||||
@ -73,7 +63,7 @@ public class Gate implements ConfigurationSerializable
|
||||
this.location = location;
|
||||
|
||||
if (isOpen) {
|
||||
fillGate();
|
||||
findPortalBlocks();
|
||||
validate();
|
||||
}
|
||||
}
|
||||
@ -137,15 +127,7 @@ public class Gate implements ConfigurationSerializable
|
||||
public void setHidden(boolean isHidden) throws Exception
|
||||
{
|
||||
this.isHidden = isHidden;
|
||||
|
||||
if (isHidden) {
|
||||
emptyGate();
|
||||
}
|
||||
else if (isOpen()) {
|
||||
fillGate();
|
||||
}
|
||||
|
||||
validate();
|
||||
this.validate();
|
||||
}
|
||||
|
||||
|
||||
@ -159,20 +141,13 @@ public class Gate implements ConfigurationSerializable
|
||||
{
|
||||
if (isOpen && !this.isOpen) {
|
||||
findPortalBlocks();
|
||||
|
||||
if (!isHidden) {
|
||||
fillGate();
|
||||
}
|
||||
}
|
||||
else if (!isOpen && this.isOpen) {
|
||||
emptyGate();
|
||||
}
|
||||
|
||||
this.isOpen = isOpen;
|
||||
|
||||
validate();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Will never return 'null' but might return an empty Set.
|
||||
@ -183,37 +158,6 @@ public class Gate implements ConfigurationSerializable
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* GATE BLOCK HANDLING
|
||||
*/
|
||||
|
||||
protected void fillGate()
|
||||
{
|
||||
emptyGate();
|
||||
findPortalBlocks();
|
||||
|
||||
// This is not to do an effect
|
||||
// It is to stop portal blocks from destroying themself as they cant rely on non created blocks :P
|
||||
for (Location l : gateBlockLocations) {
|
||||
l.getBlock().setType(Material.GLOWSTONE);
|
||||
}
|
||||
|
||||
for (Location l : gateBlockLocations) {
|
||||
l.getBlock().setType(Material.PORTAL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void emptyGate()
|
||||
{
|
||||
for (Location l : gateBlockLocations) {
|
||||
if (l.getBlock().getType() == Material.PORTAL) {
|
||||
l.getBlock().setType(Material.AIR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void findPortalBlocks()
|
||||
{
|
||||
gateBlockLocations = new HashSet<Location>();
|
||||
@ -227,10 +171,6 @@ public class Gate implements ConfigurationSerializable
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* VALIDATION
|
||||
*/
|
||||
|
||||
/**
|
||||
* Checks if values attributes do add up; will close gate on wrong values.
|
||||
*/
|
||||
@ -250,20 +190,16 @@ public class Gate implements ConfigurationSerializable
|
||||
throw new Exception("Gate got closed. It has no exit.");
|
||||
}
|
||||
|
||||
if (!isHidden) {
|
||||
findPortalBlocks();
|
||||
}
|
||||
|
||||
if (gateBlockLocations.size() == 0) {
|
||||
setOpen(false);
|
||||
throw new Exception("Gate got closed. The frame is missing or broken.");
|
||||
}
|
||||
|
||||
|
||||
if (!isHidden) {
|
||||
for (Location l : gateBlockLocations) {
|
||||
if (l.getBlock().getType() == Material.AIR) {
|
||||
setOpen(false);
|
||||
throw new Exception("Gate got closed. The frame is missing or broken.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user