Fixed NPE with a SHIT TON OF STATIC

This commit is contained in:
alisolarflare 2016-12-01 16:46:42 -05:00
parent 850169533a
commit e01e9d3f3e
3 changed files with 50 additions and 62 deletions

View file

@ -1,27 +1,24 @@
package alisolarflare.components.flairdoor; package alisolarflare.components.flairdoor;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.bukkit.Location; import org.bukkit.entity.Player;
import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.java.JavaPlugin;
import alisolarflare.architecture.Component;
import alisolarflare.architecture.Component; import alisolarflare.components.flairdoor.flairme.FlairMe;
import alisolarflare.components.flairdoor.flairme.FlairMe; import alisolarflare.components.flairdoor.listeners.PortalListener;
import alisolarflare.components.flairdoor.listeners.PortalListener; import alisolarflare.components.flairdoor.proximitydetector.PlayerProximityLoop;
import alisolarflare.components.flairdoor.proximitydetector.PlayerProximityLoop; import alisolarflare.components.flairdoor.proximitydetector.SetProximityLocation;
import alisolarflare.components.flairdoor.proximitydetector.SetProximityLocation;
public class FlairDoorComponent extends Component {
public class FlairDoorComponent extends Component { public List<Player> playersToBeFlaired = new ArrayList<Player>();
public List<Player> playersToBeFlaired = new ArrayList<Player>(); @Override
public Location startLocation = null; public void register(JavaPlugin plugin) {
public Location endLocation = null; registerCommand(plugin, new FlairMe(this));
@Override registerCommand(plugin, new SetProximityLocation());
public void register(JavaPlugin plugin) { registerListener(plugin, new PortalListener(plugin, this));
registerCommand(plugin, new FlairMe(this)); registerListener(plugin, new PlayerProximityLoop(plugin, this));
registerCommand(plugin, new SetProximityLocation(this)); }
registerListener(plugin, new PortalListener(plugin, this)); }
registerListener(plugin, new PlayerProximityLoop(plugin, this));
}
}

View file

@ -9,38 +9,36 @@ import org.bukkit.scheduler.BukkitRunnable;
import alisolarflare.components.flairdoor.FlairDoorComponent; import alisolarflare.components.flairdoor.FlairDoorComponent;
public class PlayerProximityLoop extends BukkitRunnable implements Listener{ public class PlayerProximityLoop extends BukkitRunnable implements Listener{
private JavaPlugin plugin; private static JavaPlugin plugin;
private FlairDoorComponent component; private static FlairDoorComponent component;
private Location startLocation; private static Location startLocation;
private Location endLocation; private static Location endLocation;
private int sX; private static int sX;
private int sY; private static int sY;
private int sZ; private static int sZ;
private int eX; private static int eX;
private int eY; private static int eY;
private int eZ; private static int eZ;
public PlayerProximityLoop(JavaPlugin plugin, FlairDoorComponent component) { public PlayerProximityLoop(JavaPlugin plugin, FlairDoorComponent component) {
this.plugin = plugin; PlayerProximityLoop.plugin = plugin;
this.component = component; PlayerProximityLoop.component = component;
setStartLocation(component.startLocation);
setEndLocation(component.endLocation);
this.runTaskTimer(plugin, 0, 20); this.runTaskTimer(plugin, 0, 20);
} }
public void setStartLocation(Location location){ public static void setStartLocation(Location location){
this.sX = startLocation.getBlockX(); PlayerProximityLoop.sX = location.getBlockX();
this.sY = startLocation.getBlockY(); PlayerProximityLoop.sY = location.getBlockY();
this.sZ = startLocation.getBlockZ(); PlayerProximityLoop.sZ = location.getBlockZ();
this.startLocation = location; PlayerProximityLoop.startLocation = location;
this.endLocation.setWorld(location.getWorld()); PlayerProximityLoop.endLocation.setWorld(location.getWorld());
} }
public void setEndLocation(Location location){ public static void setEndLocation(Location location){
this.eX = startLocation.getBlockX(); PlayerProximityLoop.eX = location.getBlockX();
this.eY = startLocation.getBlockY(); PlayerProximityLoop.eY = location.getBlockY();
this.eZ = startLocation.getBlockZ(); PlayerProximityLoop.eZ = location.getBlockZ();
this.endLocation = location; PlayerProximityLoop.startLocation.setWorld(location.getWorld());
this.startLocation.setWorld(location.getWorld()); PlayerProximityLoop.endLocation = location;
} }
@Override @Override

View file

@ -3,16 +3,9 @@ package alisolarflare.components.flairdoor.proximitydetector;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import alisolarflare.architecture.commands.ModCommand; import alisolarflare.architecture.commands.ModCommand;
import alisolarflare.components.flairdoor.FlairDoorComponent;
public class SetProximityLocation extends ModCommand{ public class SetProximityLocation extends ModCommand{
private FlairDoorComponent component;
public SetProximityLocation(FlairDoorComponent flairDoorComponent) {
this.component = flairDoorComponent;
}
@Override @Override
public boolean OnCommand(Player player, String alias, String[] args) { public boolean OnCommand(Player player, String alias, String[] args) {
if (args.length < 1){ if (args.length < 1){
@ -24,11 +17,11 @@ public class SetProximityLocation extends ModCommand{
switch(firstChar){ switch(firstChar){
case "s": case "s":
case "0": case "0":
component.startLocation = player.getLocation(); PlayerProximityLoop.setStartLocation(player.getLocation());
return true; return true;
case "e": case "e":
case "1": case "1":
component.endLocation = player.getLocation(); PlayerProximityLoop.setEndLocation(player.getLocation());
return true; return true;
default: default:
player.sendMessage("You must provide a vaild argument!"); player.sendMessage("You must provide a vaild argument!");