From d76681400d2f0ca52796e815ea646a58c3e7e78a Mon Sep 17 00:00:00 2001 From: Gibstick Date: Sun, 28 Jul 2013 17:59:46 -0400 Subject: [PATCH] renamed permissions, added toggle onjoin command, deleted unused class (was already split up) --- .../discosheep/BaaBaaBlockSheepEvents.java | 90 ------------------- src/ca/gibstick/discosheep/DiscoParty.java | 1 - src/ca/gibstick/discosheep/DiscoSheep.java | 44 ++++++--- .../discosheep/DiscoSheepCommandExecutor.java | 6 +- src/ca/gibstick/discosheep/GlobalEvents.java | 1 - src/ca/gibstick/discosheep/PartyEvents.java | 7 +- src/plugin.yml | 55 ++++++------ 7 files changed, 68 insertions(+), 136 deletions(-) delete mode 100644 src/ca/gibstick/discosheep/BaaBaaBlockSheepEvents.java diff --git a/src/ca/gibstick/discosheep/BaaBaaBlockSheepEvents.java b/src/ca/gibstick/discosheep/BaaBaaBlockSheepEvents.java deleted file mode 100644 index 0ae93e0..0000000 --- a/src/ca/gibstick/discosheep/BaaBaaBlockSheepEvents.java +++ /dev/null @@ -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); - } -} diff --git a/src/ca/gibstick/discosheep/DiscoParty.java b/src/ca/gibstick/discosheep/DiscoParty.java index 3d47ed2..62528f5 100644 --- a/src/ca/gibstick/discosheep/DiscoParty.java +++ b/src/ca/gibstick/discosheep/DiscoParty.java @@ -43,7 +43,6 @@ public class DiscoParty { private HashMap guestNumbers = new HashMap(); private static HashMap defaultGuestNumbers = new HashMap(); private static HashMap maxGuestNumbers = new HashMap(); - static boolean partyOnJoin = true; private boolean doFireworks = false; private boolean doJump = true; private int duration, period, radius, sheep; diff --git a/src/ca/gibstick/discosheep/DiscoSheep.java b/src/ca/gibstick/discosheep/DiscoSheep.java index babee07..2d7724d 100644 --- a/src/ca/gibstick/discosheep/DiscoSheep.java +++ b/src/ca/gibstick/discosheep/DiscoSheep.java @@ -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 parties = new HashMap(); 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(); diff --git a/src/ca/gibstick/discosheep/DiscoSheepCommandExecutor.java b/src/ca/gibstick/discosheep/DiscoSheepCommandExecutor.java index b5f3d5e..0ab8a32 100644 --- a/src/ca/gibstick/discosheep/DiscoSheepCommandExecutor.java +++ b/src/ca/gibstick/discosheep/DiscoSheepCommandExecutor.java @@ -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); } } @@ -149,11 +151,11 @@ public class DiscoSheepCommandExecutor implements CommandExecutor { if (!sender.hasPermission(DiscoSheep.PERMISSION_SPAWNGUESTS)) { return parent.noPermsMessage(sender, DiscoSheep.PERMISSION_SPAWNGUESTS); } - + if (parseNextArg(args, i, "none")) { return parent.zeroGuests(mainParty); } - + String[] guests = getNextArgs(args, i + 1); int j = 0; while (j < guests.length - 1) { diff --git a/src/ca/gibstick/discosheep/GlobalEvents.java b/src/ca/gibstick/discosheep/GlobalEvents.java index 026c05a..79e847f 100644 --- a/src/ca/gibstick/discosheep/GlobalEvents.java +++ b/src/ca/gibstick/discosheep/GlobalEvents.java @@ -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(); diff --git a/src/ca/gibstick/discosheep/PartyEvents.java b/src/ca/gibstick/discosheep/PartyEvents.java index 9893e18..1de12b8 100644 --- a/src/ca/gibstick/discosheep/PartyEvents.java +++ b/src/ca/gibstick/discosheep/PartyEvents.java @@ -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); diff --git a/src/plugin.yml b/src/plugin.yml index b003343..ff58069 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -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 \ No newline at end of file