Merge remote-tracking branch 'origin/derp'
Conflicts: src/ca/gibstick/discosheep/BaaBaaBlockSheepEvents.java
This commit is contained in:
commit
a7f9b4358a
@ -1,89 +0,0 @@
|
|||||||
/*
|
|
||||||
* BaaBaaBlockSheep have you any wool?
|
|
||||||
* Nope, event got cancelled.
|
|
||||||
* Also listens to other events, not just sheep events
|
|
||||||
*/
|
|
||||||
package ca.gibstick.discosheep;
|
|
||||||
|
|
||||||
import org.bukkit.entity.LivingEntity;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.entity.Sheep;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.entity.EntityDamageEvent;
|
|
||||||
import org.bukkit.event.entity.EntityTargetEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
import org.bukkit.event.player.PlayerShearEntityEvent;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Mauve
|
|
||||||
*/
|
|
||||||
public class BaaBaaBlockSheepEvents implements Listener {
|
|
||||||
|
|
||||||
DiscoSheep parent;
|
|
||||||
|
|
||||||
public BaaBaaBlockSheepEvents(DiscoSheep parent) {
|
|
||||||
this.parent = parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
// prevent sheep shearing
|
|
||||||
@EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
|
||||||
public void onPlayerShear(PlayerShearEntityEvent e) {
|
|
||||||
if (e.getEntity() instanceof Sheep) {
|
|
||||||
for (DiscoParty party : parent.getParties()) {
|
|
||||||
if (party.getSheepList().contains((Sheep) e.getEntity())) {
|
|
||||||
e.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// actually make sheep and other guests invincible
|
|
||||||
@EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
|
||||||
public void onLivingEntityDamageEvent(EntityDamageEvent e) {
|
|
||||||
if (e.getEntity() instanceof Sheep) {
|
|
||||||
for (DiscoParty party : parent.getParties()) {
|
|
||||||
if (party.getSheepList().contains((Sheep) e.getEntity())) {
|
|
||||||
{
|
|
||||||
party.jump((LivingEntity) e.getEntity()); // for kicks
|
|
||||||
e.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (DiscoParty party : parent.getParties()) {
|
|
||||||
if (party.getGuestList().contains(e.getEntity())) {
|
|
||||||
party.jump((LivingEntity) e.getEntity());
|
|
||||||
e.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// prevent uninvited guests from targetting players
|
|
||||||
@EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
|
||||||
public void onEntityTargetLivingEntityEvent(EntityTargetEvent e) {
|
|
||||||
for (DiscoParty party : parent.getParties()) {
|
|
||||||
if (party.getGuestList().contains(e.getEntity())) { // safe; event is only triggered by LivingEntity targetting LivingEntity
|
|
||||||
e.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler (priority = EventPriority.MONITOR)
|
|
||||||
public void onPlayerQuitEvent(PlayerQuitEvent e) {
|
|
||||||
String name = e.getPlayer().getName();
|
|
||||||
parent.stopParty(name);
|
|
||||||
// stop party on player quit or else it will CONTINUE FOR ETERNITY
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler (priority = EventPriority.MONITOR)
|
|
||||||
public void onPlayerJoinEvent(PlayerJoinEvent e) {
|
|
||||||
Player player = e.getPlayer();
|
|
||||||
parent.partyOnJoin(player);
|
|
||||||
}
|
|
||||||
}
|
|
@ -15,7 +15,8 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.entity.Sheep;
|
import org.bukkit.entity.Sheep;
|
||||||
import org.bukkit.FireworkEffect;
|
import org.bukkit.FireworkEffect;
|
||||||
import org.bukkit.FireworkEffect.Builder;
|
import org.bukkit.FireworkEffect.Builder;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.inventory.meta.FireworkMeta;
|
import org.bukkit.inventory.meta.FireworkMeta;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
@ -25,10 +26,10 @@ import org.bukkit.util.Vector;
|
|||||||
*/
|
*/
|
||||||
public class DiscoParty {
|
public class DiscoParty {
|
||||||
|
|
||||||
private DiscoSheep ds;
|
private DiscoSheep parent;
|
||||||
private Player player;
|
private Player player;
|
||||||
private ArrayList<Sheep> sheepList = new ArrayList<Sheep>();
|
private ArrayList<Sheep> sheepList = new ArrayList<Sheep>();
|
||||||
private ArrayList<LivingEntity> guestList = new ArrayList<LivingEntity>();
|
private ArrayList<Entity> guestList = new ArrayList<Entity>();
|
||||||
static int defaultDuration = 300; // ticks for entire party
|
static int defaultDuration = 300; // ticks for entire party
|
||||||
static int defaultPeriod = 10; // ticks per state change
|
static int defaultPeriod = 10; // ticks per state change
|
||||||
static int defaultRadius = 5;
|
static int defaultRadius = 5;
|
||||||
@ -63,32 +64,34 @@ public class DiscoParty {
|
|||||||
DyeColor.WHITE
|
DyeColor.WHITE
|
||||||
};
|
};
|
||||||
private Random r;
|
private Random r;
|
||||||
|
private PartyEvents partyEvents;
|
||||||
|
|
||||||
public DiscoParty(DiscoSheep parent, Player player) {
|
public DiscoParty(DiscoSheep parent, Player player) {
|
||||||
this.ds = parent;
|
this.parent = parent;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.duration = DiscoParty.defaultDuration;
|
this.duration = DiscoParty.defaultDuration;
|
||||||
this.period = DiscoParty.defaultPeriod;
|
this.period = DiscoParty.defaultPeriod;
|
||||||
this.radius = DiscoParty.defaultRadius;
|
this.radius = DiscoParty.defaultRadius;
|
||||||
this.sheep = DiscoParty.defaultSheep;
|
this.sheep = DiscoParty.defaultSheep;
|
||||||
this.guestNumbers = (HashMap) DiscoParty.getDefaultGuestNumbers().clone();
|
this.guestNumbers = new HashMap<String, Integer>(DiscoParty.defaultGuestNumbers);
|
||||||
r = new Random();
|
r = new Random();
|
||||||
}
|
}
|
||||||
|
|
||||||
public DiscoParty(DiscoSheep parent) {
|
public DiscoParty(DiscoSheep parent) {
|
||||||
this.ds = parent;
|
this.parent = parent;
|
||||||
this.duration = DiscoParty.defaultDuration;
|
this.duration = DiscoParty.defaultDuration;
|
||||||
this.period = DiscoParty.defaultPeriod;
|
this.period = DiscoParty.defaultPeriod;
|
||||||
this.radius = DiscoParty.defaultRadius;
|
this.radius = DiscoParty.defaultRadius;
|
||||||
this.sheep = DiscoParty.defaultSheep;
|
this.sheep = DiscoParty.defaultSheep;
|
||||||
this.guestNumbers = (HashMap) DiscoParty.getDefaultGuestNumbers().clone();
|
this.guestNumbers = new HashMap<String, Integer>(DiscoParty.defaultGuestNumbers);
|
||||||
r = new Random();
|
r = new Random();
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy but with new player
|
// copy but with new player
|
||||||
// used for /ds other and /ds all
|
// used for /ds other and /ds all
|
||||||
public DiscoParty DiscoParty(Player player) {
|
public DiscoParty DiscoParty(Player player) {
|
||||||
DiscoParty newParty = new DiscoParty(this.ds, player);
|
DiscoParty newParty;
|
||||||
|
newParty = new DiscoParty(this.parent, player);
|
||||||
newParty.doFireworks = this.doFireworks;
|
newParty.doFireworks = this.doFireworks;
|
||||||
newParty.duration = this.duration;
|
newParty.duration = this.duration;
|
||||||
newParty.period = this.period;
|
newParty.period = this.period;
|
||||||
@ -103,7 +106,7 @@ public class DiscoParty {
|
|||||||
return sheepList;
|
return sheepList;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<LivingEntity> getGuestList() {
|
ArrayList<Entity> getGuestList() {
|
||||||
return guestList;
|
return guestList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,7 +206,7 @@ public class DiscoParty {
|
|||||||
DiscoParty.defaultPeriod = this.period;
|
DiscoParty.defaultPeriod = this.period;
|
||||||
DiscoParty.defaultRadius = this.radius;
|
DiscoParty.defaultRadius = this.radius;
|
||||||
DiscoParty.defaultSheep = this.sheep;
|
DiscoParty.defaultSheep = this.sheep;
|
||||||
DiscoParty.defaultGuestNumbers = (HashMap) this.getGuestNumbers().clone();
|
DiscoParty.defaultGuestNumbers = new HashMap<String, Integer>(this.getGuestNumbers());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,7 +266,7 @@ public class DiscoParty {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void spawnGuest(World world, Location loc, EntityType type) {
|
void spawnGuest(World world, Location loc, EntityType type) {
|
||||||
LivingEntity newGuest = (LivingEntity) world.spawnEntity(loc, type);
|
Entity newGuest = world.spawnEntity(loc, type);
|
||||||
getGuestList().add(newGuest);
|
getGuestList().add(newGuest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,7 +275,7 @@ public class DiscoParty {
|
|||||||
for (Sheep sheeple : getSheepList()) {
|
for (Sheep sheeple : getSheepList()) {
|
||||||
sheeple.remove();
|
sheeple.remove();
|
||||||
}
|
}
|
||||||
for (LivingEntity guest : getGuestList()) {
|
for (Entity guest : getGuestList()) {
|
||||||
guest.remove();
|
guest.remove();
|
||||||
}
|
}
|
||||||
getSheepList().clear();
|
getSheepList().clear();
|
||||||
@ -284,7 +287,7 @@ public class DiscoParty {
|
|||||||
sheep.setColor(discoColours[(r.nextInt(discoColours.length))]);
|
sheep.setColor(discoColours[(r.nextInt(discoColours.length))]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void jump(LivingEntity entity) {
|
void jump(Entity entity) {
|
||||||
Vector orgVel = entity.getVelocity();
|
Vector orgVel = entity.getVelocity();
|
||||||
Vector newVel = (new Vector()).copy(orgVel);
|
Vector newVel = (new Vector()).copy(orgVel);
|
||||||
newVel.add(new Vector(0, defaultSheepJump, 0));
|
newVel.add(new Vector(0, defaultSheepJump, 0));
|
||||||
@ -366,7 +369,7 @@ public class DiscoParty {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (LivingEntity guest : getGuestList()) {
|
for (Entity guest : getGuestList()) {
|
||||||
if (doJump) {
|
if (doJump) {
|
||||||
if (state % 2 == 0 && r.nextDouble() < 0.5) {
|
if (state % 2 == 0 && r.nextDouble() < 0.5) {
|
||||||
jump(guest);
|
jump(guest);
|
||||||
@ -435,7 +438,7 @@ public class DiscoParty {
|
|||||||
|
|
||||||
void scheduleUpdate() {
|
void scheduleUpdate() {
|
||||||
updater = new DiscoUpdater(this);
|
updater = new DiscoUpdater(this);
|
||||||
updater.runTaskLater(ds, this.period);
|
updater.runTaskLater(parent, this.period);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@ -448,13 +451,16 @@ public class DiscoParty {
|
|||||||
this.period = period;
|
this.period = period;
|
||||||
this.duration = duration;
|
this.duration = duration;
|
||||||
this.scheduleUpdate();
|
this.scheduleUpdate();
|
||||||
ds.getPartyMap().put(this.player.getName(), this);
|
parent.getPartyMap().put(this.player.getName(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void startDisco() {
|
void startDisco() {
|
||||||
this.spawnAll(sheep, radius);
|
this.spawnAll(sheep, radius);
|
||||||
this.scheduleUpdate();
|
this.scheduleUpdate();
|
||||||
ds.getPartyMap().put(this.player.getName(), this);
|
parent.getPartyMap().put(this.player.getName(), this);
|
||||||
|
// start listening
|
||||||
|
this.partyEvents = new PartyEvents(this.parent, this);
|
||||||
|
parent.getServer().getPluginManager().registerEvents(this.partyEvents, this.parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void stopDisco() {
|
void stopDisco() {
|
||||||
@ -464,6 +470,8 @@ public class DiscoParty {
|
|||||||
updater.cancel();
|
updater.cancel();
|
||||||
}
|
}
|
||||||
updater = null;
|
updater = null;
|
||||||
ds.getPartyMap().remove(this.player.getName());
|
parent.getPartyMap().remove(this.player.getName());
|
||||||
|
// stop listening
|
||||||
|
HandlerList.unregisterAll(this.partyEvents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,25 +12,27 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
|
|
||||||
public final class DiscoSheep extends JavaPlugin {
|
public final class DiscoSheep extends JavaPlugin {
|
||||||
|
|
||||||
static final String PERMISSION_PARTY = "discosheep.party";
|
static final String PERMISSION_PARTY = "discosheep.party.me";
|
||||||
static final String PERMISSION_ALL = "discosheep.partyall";
|
static final String PERMISSION_ALL = "discosheep.party.all";
|
||||||
static final String PERMISSION_FIREWORKS = "discosheep.fireworks";
|
static final String PERMISSION_FIREWORKS = "discosheep.party.fireworks";
|
||||||
static final String PERMISSION_STOPALL = "discosheep.stopall";
|
static final String PERMISSION_STOPALL = "discosheep.admin.stopall";
|
||||||
static final String PERMISSION_RELOAD = "discosheep.reload";
|
static final String PERMISSION_RELOAD = "discosheep.admin.reload";
|
||||||
static final String PERMISSION_OTHER = "discosheep.other";
|
static final String PERMISSION_OTHER = "discosheep.party.other";
|
||||||
static final String PERMISSION_CHANGEPERIOD = "discosheep.changeperiod";
|
static final String PERMISSION_CHANGEPERIOD = "discosheep.party.changeperiod";
|
||||||
static final String PERMISSION_CHANGEDEFAULTS = "discosheep.changedefaults";
|
static final String PERMISSION_CHANGEDEFAULTS = "discosheep.admin.changedefaults";
|
||||||
static final String PERMISSION_SAVECONFIG = "discosheep.saveconfig";
|
static final String PERMISSION_SAVECONFIG = "discosheep.admin.saveconfig";
|
||||||
static final String PERMISSION_ONJOIN = "discosheep.onjoin";
|
static final String PERMISSION_ONJOIN = "discosheep.party.onjoin";
|
||||||
static final String PERMISSION_SPAWNGUESTS = "discosheep.spawnguests";
|
static final String PERMISSION_SPAWNGUESTS = "discosheep.party.spawnguests";
|
||||||
|
static final String PERMISSION_TOGGLEPARTYONJOIN = "discosheep.admin.toggleonjoin";
|
||||||
|
static boolean partyOnJoin = true;
|
||||||
Map<String, DiscoParty> parties = new HashMap<String, DiscoParty>();
|
Map<String, DiscoParty> parties = new HashMap<String, DiscoParty>();
|
||||||
private BaaBaaBlockSheepEvents blockEvents = new BaaBaaBlockSheepEvents(this);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
getCommand("ds").setExecutor(new DiscoSheepCommandExecutor(this));
|
getCommand("ds").setExecutor(new DiscoSheepCommandExecutor(this));
|
||||||
getServer().getPluginManager().registerEvents(blockEvents, this);
|
getServer().getPluginManager().registerEvents(new GlobalEvents(this), this);
|
||||||
|
|
||||||
|
getConfig().addDefault("on-join.enabled", partyOnJoin);
|
||||||
getConfig().addDefault("max.sheep", DiscoParty.maxSheep);
|
getConfig().addDefault("max.sheep", DiscoParty.maxSheep);
|
||||||
getConfig().addDefault("max.radius", DiscoParty.maxRadius);
|
getConfig().addDefault("max.radius", DiscoParty.maxRadius);
|
||||||
getConfig().addDefault("max.duration", toSeconds_i(DiscoParty.maxDuration));
|
getConfig().addDefault("max.duration", toSeconds_i(DiscoParty.maxDuration));
|
||||||
@ -43,15 +45,18 @@ public final class DiscoSheep extends JavaPlugin {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Iterate through all live entities and create default configuration values for them
|
* Iterate through all live entities and create default configuration values for them
|
||||||
* excludes bosses and pigmen since they throw NPE for some reason
|
* excludes bosses and other mobs that throw NPE
|
||||||
* excludes horses for 1.5.2 compatibility (also NPE)
|
|
||||||
*/
|
*/
|
||||||
for (EntityType ent : EntityType.values()) {
|
for (EntityType ent : EntityType.values()) {
|
||||||
if (ent.isAlive()
|
if (ent.isAlive()
|
||||||
&& !ent.equals(EntityType.ENDER_DRAGON)
|
&& !ent.equals(EntityType.ENDER_DRAGON)
|
||||||
&& !ent.equals(EntityType.WITHER)
|
&& !ent.equals(EntityType.WITHER)
|
||||||
&& !ent.equals(EntityType.PIG_ZOMBIE)
|
&& !ent.equals(EntityType.PIG_ZOMBIE)
|
||||||
&& !ent.equals(EntityType.HORSE)
|
&& !ent.equals(EntityType.OCELOT)
|
||||||
|
&& !ent.equals(EntityType.CAVE_SPIDER)
|
||||||
|
&& !ent.equals(EntityType.MAGMA_CUBE)
|
||||||
|
&& !ent.equals(EntityType.MUSHROOM_COW)
|
||||||
|
&& !ent.equals(EntityType.IRON_GOLEM)
|
||||||
&& !ent.equals(EntityType.PLAYER)) {
|
&& !ent.equals(EntityType.PLAYER)) {
|
||||||
getConfig().addDefault("default.guests." + ent.toString(), 0);
|
getConfig().addDefault("default.guests." + ent.toString(), 0);
|
||||||
getConfig().addDefault("max.guests." + ent.toString(), 0);
|
getConfig().addDefault("max.guests." + ent.toString(), 0);
|
||||||
@ -65,6 +70,7 @@ public final class DiscoSheep extends JavaPlugin {
|
|||||||
getConfig().options().copyDefaults(true);
|
getConfig().options().copyDefaults(true);
|
||||||
saveConfig();
|
saveConfig();
|
||||||
|
|
||||||
|
partyOnJoin = getConfig().getBoolean("on-join.enabled");
|
||||||
DiscoParty.maxSheep = getConfig().getInt("max.sheep");
|
DiscoParty.maxSheep = getConfig().getInt("max.sheep");
|
||||||
DiscoParty.maxRadius = getConfig().getInt("max.radius");
|
DiscoParty.maxRadius = getConfig().getInt("max.radius");
|
||||||
DiscoParty.maxDuration = toTicks(getConfig().getInt("max.duration"));
|
DiscoParty.maxDuration = toTicks(getConfig().getInt("max.duration"));
|
||||||
@ -91,6 +97,7 @@ public final class DiscoSheep extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void saveConfigToDisk() {
|
void saveConfigToDisk() {
|
||||||
|
getConfig().set("on-join.enabled", partyOnJoin);
|
||||||
getConfig().set("default.sheep", DiscoParty.defaultSheep);
|
getConfig().set("default.sheep", DiscoParty.defaultSheep);
|
||||||
getConfig().set("default.radius", DiscoParty.defaultRadius);
|
getConfig().set("default.radius", DiscoParty.defaultRadius);
|
||||||
getConfig().set("default.duration", toSeconds_i(DiscoParty.defaultDuration));
|
getConfig().set("default.duration", toSeconds_i(DiscoParty.defaultDuration));
|
||||||
@ -125,7 +132,7 @@ public final class DiscoSheep extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized ArrayList<DiscoParty> getParties() {
|
public synchronized ArrayList<DiscoParty> getParties() {
|
||||||
return new ArrayList(this.getPartyMap().values());
|
return new ArrayList<DiscoParty>(this.getPartyMap().values());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopParty(String name) {
|
public void stopParty(String name) {
|
||||||
@ -237,7 +244,7 @@ public final class DiscoSheep extends JavaPlugin {
|
|||||||
if (!hasParty(p.getName())) {
|
if (!hasParty(p.getName())) {
|
||||||
DiscoParty individualParty = party.DiscoParty(p);
|
DiscoParty individualParty = party.DiscoParty(p);
|
||||||
individualParty.startDisco();
|
individualParty.startDisco();
|
||||||
p.sendMessage(ChatColor.RED + "LET'S DISCO!");
|
p.sendMessage(ChatColor.RED + "LET'S DISCO!!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -247,12 +254,28 @@ public final class DiscoSheep extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void partyOnJoin(Player player) {
|
void partyOnJoin(Player player) {
|
||||||
|
if (!partyOnJoin) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (player.hasPermission(PERMISSION_ONJOIN)) {
|
if (player.hasPermission(PERMISSION_ONJOIN)) {
|
||||||
DiscoParty party = new DiscoParty(this, player);
|
DiscoParty party = new DiscoParty(this, player);
|
||||||
party.startDisco();
|
party.startDisco();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean togglePartyOnJoinCommand(CommandSender sender) {
|
||||||
|
if (!sender.hasPermission(PERMISSION_TOGGLEPARTYONJOIN)) {
|
||||||
|
return noPermsMessage(sender, PERMISSION_TOGGLEPARTYONJOIN);
|
||||||
|
}
|
||||||
|
partyOnJoin = !partyOnJoin;
|
||||||
|
if (partyOnJoin) {
|
||||||
|
sender.sendMessage(ChatColor.GREEN + "DiscoSheep party on join functionality enabled.");
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(ChatColor.GREEN + "DiscoSheep party on join functionality disabled.");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
boolean setDefaultsCommand(CommandSender sender, DiscoParty party) {
|
boolean setDefaultsCommand(CommandSender sender, DiscoParty party) {
|
||||||
if (sender.hasPermission(PERMISSION_CHANGEDEFAULTS)) {
|
if (sender.hasPermission(PERMISSION_CHANGEDEFAULTS)) {
|
||||||
party.setDefaultsFromCurrent();
|
party.setDefaultsFromCurrent();
|
||||||
|
@ -89,6 +89,8 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
|
|||||||
return parent.reloadCommand(sender);
|
return parent.reloadCommand(sender);
|
||||||
} else if (args[0].equalsIgnoreCase("save") || args[0].equalsIgnoreCase("saveconfig")) {
|
} else if (args[0].equalsIgnoreCase("save") || args[0].equalsIgnoreCase("saveconfig")) {
|
||||||
return parent.saveConfigCommand(sender);
|
return parent.saveConfigCommand(sender);
|
||||||
|
} else if (args[0].equalsIgnoreCase("togglejoin")) {
|
||||||
|
return parent.togglePartyOnJoinCommand(sender);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,7 +158,7 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
|
|||||||
|
|
||||||
String[] guests = getNextArgs(args, i + 1);
|
String[] guests = getNextArgs(args, i + 1);
|
||||||
int j = 0;
|
int j = 0;
|
||||||
while (j < guests.length) {
|
while (j < guests.length - 1) {
|
||||||
try {
|
try {
|
||||||
mainParty.setGuestNumber(guests[j], getNextIntArg(guests, j));
|
mainParty.setGuestNumber(guests[j], getNextIntArg(guests, j));
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
39
src/ca/gibstick/discosheep/GlobalEvents.java
Normal file
39
src/ca/gibstick/discosheep/GlobalEvents.java
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* BaaBaaBlockSheep have you any wool?
|
||||||
|
* Nope, event got cancelled.
|
||||||
|
* Also listens to other events, not just sheep events
|
||||||
|
*/
|
||||||
|
package ca.gibstick.discosheep;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Mauve
|
||||||
|
*/
|
||||||
|
public class GlobalEvents implements Listener {
|
||||||
|
|
||||||
|
DiscoSheep parent;
|
||||||
|
|
||||||
|
public GlobalEvents(DiscoSheep parent) {
|
||||||
|
this.parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler (priority = EventPriority.MONITOR)
|
||||||
|
public void onPlayerQuitEvent(PlayerQuitEvent e) {
|
||||||
|
String name = e.getPlayer().getName();
|
||||||
|
parent.stopParty(name);
|
||||||
|
// stop party on player quit or else it will CONTINUE FOR ETERNITY
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler (priority = EventPriority.MONITOR)
|
||||||
|
public void onPlayerJoinEvent(PlayerJoinEvent e) {
|
||||||
|
Player player = e.getPlayer();
|
||||||
|
parent.partyOnJoin(player);
|
||||||
|
}
|
||||||
|
}
|
71
src/ca/gibstick/discosheep/PartyEvents.java
Normal file
71
src/ca/gibstick/discosheep/PartyEvents.java
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
package ca.gibstick.discosheep;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Sheep;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
|
import org.bukkit.event.entity.EntityTargetEvent;
|
||||||
|
import org.bukkit.event.player.PlayerShearEntityEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Charlie
|
||||||
|
*/
|
||||||
|
public class PartyEvents implements Listener {
|
||||||
|
|
||||||
|
DiscoSheep parent;
|
||||||
|
DiscoParty party;
|
||||||
|
/*
|
||||||
|
* There will be multiple instances of PartyEvents,
|
||||||
|
* and each instance will only listen for its own party.
|
||||||
|
* That way, we don't have multiple instances iterating through
|
||||||
|
* the entire parties hashmap redundantly, yet we can still
|
||||||
|
* unregister the listeners when no parties are running.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public PartyEvents(DiscoSheep parent, DiscoParty party) {
|
||||||
|
this.parent = parent;
|
||||||
|
this.party = party;
|
||||||
|
}
|
||||||
|
|
||||||
|
// prevent sheep shearing
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onPlayerShear(PlayerShearEntityEvent e) {
|
||||||
|
if (e.getEntity() instanceof Sheep) {
|
||||||
|
|
||||||
|
if (party.getSheepList().contains((Sheep) e.getEntity())) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// actually make sheep and other guests invincible
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onLivingEntityDamageEvent(EntityDamageEvent e) {
|
||||||
|
if (e.getEntity() instanceof Sheep) {
|
||||||
|
if (party.getSheepList().contains((Sheep) e.getEntity())) {
|
||||||
|
{
|
||||||
|
party.jump(e.getEntity()); // for kicks
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (party.getGuestList().contains(e.getEntity())) {
|
||||||
|
party.jump(e.getEntity());
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// prevent uninvited guests from targetting players
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onEntityTargetLivingEntityEvent(EntityTargetEvent e) {
|
||||||
|
|
||||||
|
if (party.getGuestList().contains(e.getEntity())) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -16,55 +16,60 @@ permissions:
|
|||||||
default: op
|
default: op
|
||||||
children:
|
children:
|
||||||
discosheep.party: true
|
discosheep.party: true
|
||||||
discosheep.partyall: true
|
discosheep.admin: true
|
||||||
discosheep.fireworks: true
|
discosheep.party:
|
||||||
discosheep.stopall: true
|
description: All permissions related to parties
|
||||||
discosheep.reload: true
|
defualt: op
|
||||||
discosheep.other: true
|
children:
|
||||||
discosheep.changeperiod: true
|
discosheep.party.me: true
|
||||||
discosheep.changedefaults: true
|
discosheep.party.all: true
|
||||||
discosheep.saveconfig: true
|
discosheep.party.fireworks: true
|
||||||
discosheep.spawnguests: true
|
discosheep.party.other: true
|
||||||
|
discosheep.party.changeperiod: true
|
||||||
|
discosheep.party.spawnguests: true
|
||||||
discosheep.admin:
|
discosheep.admin:
|
||||||
description: Suggested permissions for administrators
|
description: Suggested permissions for administrators
|
||||||
default: op
|
default: op
|
||||||
children:
|
children:
|
||||||
discosheep.stopall: true
|
discosheep.admin.stopall: true
|
||||||
discosheep.reload: true
|
discosheep.admin.reload: true
|
||||||
discosheep.changedefaults: true
|
discosheep.admin.changedefaults: true
|
||||||
discosheep.saveconfig: true
|
discosheep.admin.saveconfig: true
|
||||||
discosheep.party:
|
discosheep.party.me:
|
||||||
description: Allows a player to have a party of one
|
description: Allows a player to have a party of one
|
||||||
default: op
|
default: op
|
||||||
discosheep.partyall:
|
discosheep.party.all:
|
||||||
description: Allows a player to call a server-wide party
|
description: Allows a player to call a server-wide party
|
||||||
default: op
|
default: op
|
||||||
discosheep.stopall:
|
discosheep.admin.stopall:
|
||||||
description: Allows a player to stop all parties on the server
|
description: Allows a player to stop all parties on the server
|
||||||
default: op
|
default: op
|
||||||
discosheep.fireworks:
|
discosheep.party.fireworks:
|
||||||
description: Allows a player to enable have parties with fireworks
|
description: Allows a player to enable have parties with fireworks
|
||||||
default: op
|
default: op
|
||||||
discosheep.reload:
|
discosheep.admin.reload:
|
||||||
description: Allows a player to reload settings from config.yml
|
description: Allows a player to reload settings from config.yml
|
||||||
default: op
|
default: op
|
||||||
discosheep.other:
|
discosheep.party.other:
|
||||||
description: Allows a player to call parties for other people, including themselves.
|
description: Allows a player to call parties for other people, including themselves.
|
||||||
default: op
|
default: op
|
||||||
children:
|
children:
|
||||||
discosheep.party: true
|
discosheep.party.me: true
|
||||||
discosheep.changeperiod:
|
discosheep.party.changeperiod:
|
||||||
description: Allows a player to use the -p switch
|
description: Allows a player to use the -p switch
|
||||||
default: op
|
default: op
|
||||||
discosheep.changedefaults:
|
discosheep.admin.changedefaults:
|
||||||
description: Allows a player to change the default settings
|
description: Allows a player to change the default settings
|
||||||
default: op
|
default: op
|
||||||
discosheep.saveconfig:
|
discosheep.admin.saveconfig:
|
||||||
description: Allows a player to save the config with current values set in memory
|
description: Allows a player to save the config with current values set in memory
|
||||||
default: op
|
default: op
|
||||||
discosheep.partyonjoin:
|
discosheep.party.onjoin:
|
||||||
description: Gives a player a disco party on join
|
description: Gives a player a disco party on join
|
||||||
default: false
|
default: false
|
||||||
discosheep.spawnguests:
|
discosheep.party.spawnguests:
|
||||||
description: Allow a player to spawn other mobs
|
description: Allow a player to spawn other mobs
|
||||||
default: op
|
default: op
|
||||||
|
discosheep.admin.toggleonjoin:
|
||||||
|
description: Allow a player to toggle party-on-join functionality (force disable)
|
||||||
|
default: op
|
Loading…
Reference in New Issue
Block a user