renamed permissions, added toggle onjoin command, deleted unused class (was already split up)

This commit is contained in:
Gibstick 2013-07-28 17:59:46 -04:00
parent 2d3e98560f
commit d76681400d
7 changed files with 68 additions and 136 deletions

View File

@ -1,90 +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.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;
static DiscoSheepCommandExecutor CommExec;
public BaaBaaBlockSheepEvents(DiscoSheep parent) {
this.parent = parent;
}
// prevent sheep shearing
@EventHandler
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
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
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
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
public void onPlayerJoinEvent(PlayerJoinEvent e) {
Player player = e.getPlayer();
DiscoParty party = new DiscoParty(parent, player);
parent.partyOnJoin(player);
}
}

View File

@ -43,7 +43,6 @@ public class DiscoParty {
private HashMap<String, Integer> guestNumbers = new HashMap<String, Integer>();
private static HashMap<String, Integer> defaultGuestNumbers = new HashMap<String, Integer>();
private static HashMap<String, Integer> maxGuestNumbers = new HashMap<String, Integer>();
static boolean partyOnJoin = true;
private boolean doFireworks = false;
private boolean doJump = true;
private int duration, period, radius, sheep;

View File

@ -12,17 +12,19 @@ import org.bukkit.plugin.java.JavaPlugin;
public final class DiscoSheep extends JavaPlugin {
static final String PERMISSION_PARTY = "discosheep.party";
static final String PERMISSION_ALL = "discosheep.partyall";
static final String PERMISSION_FIREWORKS = "discosheep.fireworks";
static final String PERMISSION_STOPALL = "discosheep.stopall";
static final String PERMISSION_RELOAD = "discosheep.reload";
static final String PERMISSION_OTHER = "discosheep.other";
static final String PERMISSION_CHANGEPERIOD = "discosheep.changeperiod";
static final String PERMISSION_CHANGEDEFAULTS = "discosheep.changedefaults";
static final String PERMISSION_SAVECONFIG = "discosheep.saveconfig";
static final String PERMISSION_ONJOIN = "discosheep.onjoin";
static final String PERMISSION_SPAWNGUESTS = "discosheep.spawnguests";
static final String PERMISSION_PARTY = "discosheep.party.me";
static final String PERMISSION_ALL = "discosheep.party.all";
static final String PERMISSION_FIREWORKS = "discosheep.party.fireworks";
static final String PERMISSION_STOPALL = "discosheep.admin.stopall";
static final String PERMISSION_RELOAD = "discosheep.admin.reload";
static final String PERMISSION_OTHER = "discosheep.party.other";
static final String PERMISSION_CHANGEPERIOD = "discosheep.party.changeperiod";
static final String PERMISSION_CHANGEDEFAULTS = "discosheep.admin.changedefaults";
static final String PERMISSION_SAVECONFIG = "discosheep.admin.saveconfig";
static final String PERMISSION_ONJOIN = "discosheep.party.onjoin";
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>();
private GlobalEvents globalEvents = new GlobalEvents(this);
@ -31,7 +33,7 @@ public final class DiscoSheep extends JavaPlugin {
getCommand("ds").setExecutor(new DiscoSheepCommandExecutor(this));
getServer().getPluginManager().registerEvents(globalEvents, this);
getConfig().addDefault("party-on-join.enabled", DiscoParty.partyOnJoin);
getConfig().addDefault("party-on-join.enabled", partyOnJoin);
getConfig().addDefault("max.sheep", DiscoParty.maxSheep);
getConfig().addDefault("max.radius", DiscoParty.maxRadius);
getConfig().addDefault("max.duration", toSeconds_i(DiscoParty.maxDuration));
@ -69,7 +71,7 @@ public final class DiscoSheep extends JavaPlugin {
getConfig().options().copyDefaults(true);
saveConfig();
DiscoParty.partyOnJoin = getConfig().getBoolean("party-on-join.enabled");
partyOnJoin = getConfig().getBoolean("party-on-join.enabled");
DiscoParty.maxSheep = getConfig().getInt("max.sheep");
DiscoParty.maxRadius = getConfig().getInt("max.radius");
DiscoParty.maxDuration = toTicks(getConfig().getInt("max.duration"));
@ -252,12 +254,28 @@ public final class DiscoSheep extends JavaPlugin {
}
void partyOnJoin(Player player) {
if (!partyOnJoin) {
return;
}
if (player.hasPermission(PERMISSION_ONJOIN)) {
DiscoParty party = new DiscoParty(this, player);
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) {
if (sender.hasPermission(PERMISSION_CHANGEDEFAULTS)) {
party.setDefaultsFromCurrent();

View File

@ -89,6 +89,8 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
return parent.reloadCommand(sender);
} else if (args[0].equalsIgnoreCase("save") || args[0].equalsIgnoreCase("saveconfig")) {
return parent.saveConfigCommand(sender);
} else if (args[0].equalsIgnoreCase("togglejoin")) {
return parent.togglePartyOnJoinCommand(sender);
}
}

View File

@ -24,7 +24,6 @@ public class GlobalEvents implements Listener {
this.parent = parent;
}
@EventHandler (priority = EventPriority.MONITOR)
public void onPlayerQuitEvent(PlayerQuitEvent e) {
String name = e.getPlayer().getName();

View File

@ -17,10 +17,11 @@ public class PartyEvents implements Listener {
DiscoSheep parent;
DiscoParty party;
/*
* There will be multiple isntances of PartyEvents,
* 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 redunandtly
* the entire parties hashmap redundantly, yet we can still
* unregister the listeners when no parties are running.
*/
public PartyEvents(DiscoSheep parent, DiscoParty party) {
@ -52,8 +53,6 @@ public class PartyEvents implements Listener {
}
}
if (party.getGuestList().contains(e.getEntity())) {
party.jump(e.getEntity());
e.setCancelled(true);

View File

@ -16,55 +16,60 @@ permissions:
default: op
children:
discosheep.party: true
discosheep.partyall: true
discosheep.fireworks: true
discosheep.stopall: true
discosheep.reload: true
discosheep.other: true
discosheep.changeperiod: true
discosheep.changedefaults: true
discosheep.saveconfig: true
discosheep.spawnguests: true
discosheep.admin: true
discosheep.party:
description: All permissions related to parties
defualt: op
children:
discosheep.party.me: true
discosheep.party.all: true
discosheep.party.fireworks: true
discosheep.party.other: true
discosheep.party.changeperiod: true
discosheep.party.spawnguests: true
discosheep.admin:
description: Suggested permissions for administrators
default: op
children:
discosheep.stopall: true
discosheep.reload: true
discosheep.changedefaults: true
discosheep.saveconfig: true
discosheep.party:
discosheep.admin.stopall: true
discosheep.admin.reload: true
discosheep.admin.changedefaults: true
discosheep.admin.saveconfig: true
discosheep.party.me:
description: Allows a player to have a party of one
default: op
discosheep.partyall:
discosheep.party.all:
description: Allows a player to call a server-wide party
default: op
discosheep.stopall:
discosheep.admin.stopall:
description: Allows a player to stop all parties on the server
default: op
discosheep.fireworks:
discosheep.party.fireworks:
description: Allows a player to enable have parties with fireworks
default: op
discosheep.reload:
discosheep.admin.reload:
description: Allows a player to reload settings from config.yml
default: op
discosheep.other:
discosheep.party.other:
description: Allows a player to call parties for other people, including themselves.
default: op
children:
discosheep.party: true
discosheep.changeperiod:
discosheep.party.me: true
discosheep.party.changeperiod:
description: Allows a player to use the -p switch
default: op
discosheep.changedefaults:
discosheep.admin.changedefaults:
description: Allows a player to change the default settings
default: op
discosheep.saveconfig:
discosheep.admin.saveconfig:
description: Allows a player to save the config with current values set in memory
default: op
discosheep.partyonjoin:
discosheep.party.onjoin:
description: Gives a player a disco party on join
default: false
discosheep.spawnguests:
discosheep.party.spawnguests:
description: Allow a player to spawn other mobs
default: op
discosheep.admin.toggleonjoin:
description: Allow a player to toggle party-on-join functionality (force disable)
default: op