Created a Player Proximity Task
This commit is contained in:
parent
d872ca7406
commit
21bb3a03f9
7 changed files with 146 additions and 12 deletions
|
@ -57,3 +57,5 @@ commands:
|
|||
description: starts an ultrahardcore timer
|
||||
powerall:
|
||||
description: activate every player's power
|
||||
setproximitylocation:
|
||||
description: sets one of two proximity blocks to create a space that players can change their flairs with using flairportals. Ask ali XD
|
|
@ -1,15 +1,27 @@
|
|||
package alisolarflare.components.flairdoor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import alisolarflare.components.Component;
|
||||
import alisolarflare.components.flairdoor.commands.FlairMe;
|
||||
import alisolarflare.components.flairdoor.commands.SetProximityLocation;
|
||||
import alisolarflare.components.flairdoor.listeners.PlayerProximityTaskLauncher;
|
||||
import alisolarflare.components.flairdoor.listeners.PortalListener;
|
||||
|
||||
public class FlairDoorComponent extends Component {
|
||||
public List<Player> playersToBeFlaired = new ArrayList<Player>();
|
||||
public Location startLocation = null;
|
||||
public Location endLocation = null;
|
||||
@Override
|
||||
public void register(JavaPlugin plugin) {
|
||||
registerCommand(plugin, new FlairMe());
|
||||
registerListener(plugin, new PortalListener(plugin));
|
||||
registerCommand(plugin, new FlairMe(this));
|
||||
registerCommand(plugin, new SetProximityLocation(this));
|
||||
registerListener(plugin, new PortalListener(plugin, this));
|
||||
registerListener(plugin, new PlayerProximityTaskLauncher(plugin, this));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,13 +4,17 @@ import org.bukkit.command.CommandSender;
|
|||
import org.bukkit.entity.Player;
|
||||
|
||||
import alisolarflare.components.PlayerCommand;
|
||||
import alisolarflare.components.flairdoor.listeners.PortalListener;
|
||||
import alisolarflare.components.flairdoor.FlairDoorComponent;
|
||||
|
||||
public class FlairMe extends PlayerCommand {
|
||||
|
||||
private FlairDoorComponent component;
|
||||
public FlairMe(FlairDoorComponent flairDoorComponent) {
|
||||
this.component = flairDoorComponent;
|
||||
}
|
||||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String label, String[] args) {
|
||||
PortalListener.playersToBeFlaired.add((Player) sender);
|
||||
component.playersToBeFlaired.add((Player) sender);
|
||||
sender.sendMessage("Setup Successful! Walk through a portal to get your flair");
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
package alisolarflare.components.flairdoor.commands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import alisolarflare.components.ModCommand;
|
||||
import alisolarflare.components.flairdoor.FlairDoorComponent;
|
||||
|
||||
public class SetProximityLocation extends ModCommand{
|
||||
|
||||
private FlairDoorComponent component;
|
||||
|
||||
public SetProximityLocation(FlairDoorComponent flairDoorComponent) {
|
||||
this.component = flairDoorComponent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
||||
if (args.length < 1){
|
||||
sender.sendMessage("You must enter an argument");
|
||||
return false;
|
||||
}
|
||||
|
||||
Player player = (Player) sender;
|
||||
String firstChar = args[0].substring(0, 1);
|
||||
|
||||
switch(firstChar){
|
||||
case "s":
|
||||
case "0":
|
||||
component.startLocation = player.getLocation();
|
||||
return true;
|
||||
case "e":
|
||||
case "1":
|
||||
component.endLocation = player.getLocation();
|
||||
return true;
|
||||
default:
|
||||
player.sendMessage("You must provide a vaild argument!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public String[] GetHelpText(String alias){
|
||||
return new String[] {
|
||||
"Usage: /SetProximityLocation <start/end/0/1>",
|
||||
"Use this command to set a proximity space: all players",
|
||||
"within this space will become flair-able, and portals will",
|
||||
"change their colour state."
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package alisolarflare.components.flairdoor.listeners;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import alisolarflare.components.flairdoor.FlairDoorComponent;
|
||||
|
||||
public class PlayerProximityTask extends BukkitRunnable{
|
||||
private JavaPlugin plugin;
|
||||
private FlairDoorComponent component;
|
||||
private Location startLocation;
|
||||
private Location endLocation;
|
||||
|
||||
public PlayerProximityTask(JavaPlugin plugin, FlairDoorComponent component) {
|
||||
this.plugin = plugin;
|
||||
this.component = component;
|
||||
this.startLocation = component.startLocation;
|
||||
this.endLocation = component.endLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (startLocation == null || endLocation == null){
|
||||
return;
|
||||
}
|
||||
int sX = startLocation.getBlockX();
|
||||
int sY = startLocation.getBlockY();
|
||||
int sZ = startLocation.getBlockZ();
|
||||
int eX = endLocation.getBlockX();
|
||||
int eY = endLocation.getBlockY();
|
||||
int eZ = endLocation.getBlockZ();
|
||||
int playerX;
|
||||
int playerY;
|
||||
int playerZ;
|
||||
for (Player player : plugin.getServer().getOnlinePlayers()){
|
||||
playerX = player.getLocation().getBlockX();
|
||||
playerY = player.getLocation().getBlockY();
|
||||
playerZ = player.getLocation().getBlockZ();
|
||||
if(player.getLocation().getWorld() != startLocation.getWorld())
|
||||
continue;
|
||||
if((playerX < sX && playerX < eX) ||(playerX > sX && playerX > eX))
|
||||
continue;
|
||||
if((playerY < sY && playerY < eY) ||(playerY > sY && playerY > eY))
|
||||
continue;
|
||||
if((playerZ < sZ && playerZ < eZ) ||(playerZ > sZ && playerZ > eZ))
|
||||
continue;
|
||||
component.playersToBeFlaired.add(player);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package alisolarflare.components.flairdoor.listeners;
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import alisolarflare.components.flairdoor.FlairDoorComponent;
|
||||
|
||||
public class PlayerProximityTaskLauncher implements Listener{
|
||||
public PlayerProximityTaskLauncher(JavaPlugin plugin, FlairDoorComponent component){
|
||||
new PlayerProximityTask(plugin, component).runTaskTimer(plugin, 0, 20);
|
||||
}
|
||||
}
|
|
@ -1,8 +1,5 @@
|
|||
package alisolarflare.components.flairdoor.listeners;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
|
@ -17,14 +14,18 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.User;
|
||||
|
||||
import alisolarflare.components.flairdoor.FlairDoorComponent;
|
||||
|
||||
public class PortalListener implements Listener{
|
||||
public static List<Player> playersToBeFlaired = new ArrayList<Player>();
|
||||
public JavaPlugin plugin;
|
||||
|
||||
Essentials essentials;
|
||||
|
||||
public PortalListener(JavaPlugin plugin) {
|
||||
private FlairDoorComponent component;
|
||||
|
||||
public PortalListener(JavaPlugin plugin, FlairDoorComponent component) {
|
||||
this.plugin = plugin;
|
||||
this.component = component;
|
||||
this.essentials = ((Essentials) Bukkit.getPluginManager().getPlugin("Essentials"));
|
||||
}
|
||||
@EventHandler
|
||||
|
@ -35,7 +36,7 @@ public class PortalListener implements Listener{
|
|||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if(!(playersToBeFlaired.contains(player))){
|
||||
if(!(component.playersToBeFlaired.contains(player))){
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -128,6 +129,6 @@ public class PortalListener implements Listener{
|
|||
player.sendMessage("Adding the colour " + colourChanger + dyecolour.name() + "§f!");
|
||||
player.sendMessage("Your name is now: " + user.getNickname() +"!");
|
||||
|
||||
playersToBeFlaired.remove(player.getName());
|
||||
component.playersToBeFlaired.remove(player.getName());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue