Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds no-enderpearl regions using flag "-p" #242

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.mctourney.autoreferee.listeners;

import org.bukkit.Location;
import org.bukkit.entity.EnderPearl;
import org.bukkit.entity.Entity;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.mctourney.autoreferee.AutoRefMatch;
import org.mctourney.autoreferee.regions.AutoRefRegion.Flag;

public class EnderpearlTask extends BukkitRunnable {

private final EnderPearl enderpearl;
private final AutoRefMatch match;

public EnderpearlTask(EnderPearl e, AutoRefMatch m) {
this.enderpearl = e;
this.match = m;
}

@Override
public void run() {
//get enderpearl location
Location loc = enderpearl.getLocation();
//if the enderpearl is in a no enderpearl region
if(match.hasFlag(loc, Flag.NO_ENDERPEARL)){
//remove it from existance
enderpearl.remove();
//stop running tasks on a removed entity
this.cancel();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.EnderPearl;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Minecart;
Expand Down Expand Up @@ -38,6 +39,7 @@
import org.bukkit.event.vehicle.VehicleEnterEvent;
import org.bukkit.event.weather.WeatherChangeEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitTask;
import org.mctourney.autoreferee.AutoRefMatch;
import org.mctourney.autoreferee.AutoRefPlayer;
import org.mctourney.autoreferee.AutoRefTeam;
Expand Down Expand Up @@ -164,15 +166,21 @@ public void enderpearlThrow(ProjectileLaunchEvent event)
if (match == null || match.getCurrentState() == MatchStatus.NONE) return;

if (event.getEntityType() == EntityType.ENDER_PEARL)
{
{
Player player = (Player) event.getEntity().getShooter();
AutoRefPlayer apl = match.getPlayer(player);

if (apl != null && apl.getTeam().hasFlag(player.getLocation(), Flag.NO_ENTRY))
{
String msg = ChatColor.DARK_GRAY + apl.getDisplayName() +
ChatColor.DARK_GRAY + " has thrown an enderpearl while out of bounds.";
for (Player ref : match.getReferees()) ref.sendMessage(msg);
if (apl != null){
if(apl.getTeam().hasFlag(player.getLocation(), Flag.NO_ENTRY)){
String msg = ChatColor.DARK_GRAY + apl.getDisplayName() +
ChatColor.DARK_GRAY + " has thrown an enderpearl while out of bounds.";
for (Player ref : match.getReferees()) ref.sendMessage(msg);
}

if(match.getCurrentState().inProgress()){
EnderPearl enderpearl = (EnderPearl) event.getEntity();
BukkitTask task = new EnderpearlTask(enderpearl, apl.getMatch()).runTaskTimer(AutoReferee.getInstance(), 0, 20);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ public static enum Flag
NO_ACCESS (1 << 4, false, 'a', "noaccess"),
NO_TELEPORT (1 << 5, false, 't', "noteleport"),
SPAWNERS_ONLY (1 << 6, false, 'w', "spawnersonly"),
NO_FLOW (1 << 7, true, 'f', "noflow");
NO_FLOW (1 << 7, true, 'f', "noflow"),
NO_ENDERPEARL (1 << 8, false, 'p', "noenderpearl");

// generated from above values
public static final String OPTIONS = "abenstwf";
public static final String OPTIONS = "abenstwfp";

private int value;
private String name;
Expand Down