renamed permissions, added toggle onjoin command, deleted unused class (was already split up)
This commit is contained in:
parent
2d3e98560f
commit
d76681400d
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -43,7 +43,6 @@ public class DiscoParty {
|
|||||||
private HashMap<String, Integer> guestNumbers = new HashMap<String, Integer>();
|
private HashMap<String, Integer> guestNumbers = new HashMap<String, Integer>();
|
||||||
private static HashMap<String, Integer> defaultGuestNumbers = new HashMap<String, Integer>();
|
private static HashMap<String, Integer> defaultGuestNumbers = new HashMap<String, Integer>();
|
||||||
private static HashMap<String, Integer> maxGuestNumbers = new HashMap<String, Integer>();
|
private static HashMap<String, Integer> maxGuestNumbers = new HashMap<String, Integer>();
|
||||||
static boolean partyOnJoin = true;
|
|
||||||
private boolean doFireworks = false;
|
private boolean doFireworks = false;
|
||||||
private boolean doJump = true;
|
private boolean doJump = true;
|
||||||
private int duration, period, radius, sheep;
|
private int duration, period, radius, sheep;
|
||||||
|
@ -12,17 +12,19 @@ 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 GlobalEvents globalEvents = new GlobalEvents(this);
|
private GlobalEvents globalEvents = new GlobalEvents(this);
|
||||||
|
|
||||||
@ -31,7 +33,7 @@ public final class DiscoSheep extends JavaPlugin {
|
|||||||
getCommand("ds").setExecutor(new DiscoSheepCommandExecutor(this));
|
getCommand("ds").setExecutor(new DiscoSheepCommandExecutor(this));
|
||||||
getServer().getPluginManager().registerEvents(globalEvents, 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.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));
|
||||||
@ -69,7 +71,7 @@ public final class DiscoSheep extends JavaPlugin {
|
|||||||
getConfig().options().copyDefaults(true);
|
getConfig().options().copyDefaults(true);
|
||||||
saveConfig();
|
saveConfig();
|
||||||
|
|
||||||
DiscoParty.partyOnJoin = getConfig().getBoolean("party-on-join.enabled");
|
partyOnJoin = getConfig().getBoolean("party-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"));
|
||||||
@ -252,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,11 +151,11 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
|
|||||||
if (!sender.hasPermission(DiscoSheep.PERMISSION_SPAWNGUESTS)) {
|
if (!sender.hasPermission(DiscoSheep.PERMISSION_SPAWNGUESTS)) {
|
||||||
return parent.noPermsMessage(sender, DiscoSheep.PERMISSION_SPAWNGUESTS);
|
return parent.noPermsMessage(sender, DiscoSheep.PERMISSION_SPAWNGUESTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parseNextArg(args, i, "none")) {
|
if (parseNextArg(args, i, "none")) {
|
||||||
return parent.zeroGuests(mainParty);
|
return parent.zeroGuests(mainParty);
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] guests = getNextArgs(args, i + 1);
|
String[] guests = getNextArgs(args, i + 1);
|
||||||
int j = 0;
|
int j = 0;
|
||||||
while (j < guests.length - 1) {
|
while (j < guests.length - 1) {
|
||||||
|
@ -24,7 +24,6 @@ public class GlobalEvents implements Listener {
|
|||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@EventHandler (priority = EventPriority.MONITOR)
|
@EventHandler (priority = EventPriority.MONITOR)
|
||||||
public void onPlayerQuitEvent(PlayerQuitEvent e) {
|
public void onPlayerQuitEvent(PlayerQuitEvent e) {
|
||||||
String name = e.getPlayer().getName();
|
String name = e.getPlayer().getName();
|
||||||
|
@ -17,10 +17,11 @@ public class PartyEvents implements Listener {
|
|||||||
DiscoSheep parent;
|
DiscoSheep parent;
|
||||||
DiscoParty party;
|
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.
|
* and each instance will only listen for its own party.
|
||||||
* That way, we don't have multiple instances iterating through
|
* 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) {
|
public PartyEvents(DiscoSheep parent, DiscoParty party) {
|
||||||
@ -52,8 +53,6 @@ public class PartyEvents implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (party.getGuestList().contains(e.getEntity())) {
|
if (party.getGuestList().contains(e.getEntity())) {
|
||||||
party.jump(e.getEntity());
|
party.jump(e.getEntity());
|
||||||
e.setCancelled(true);
|
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
|
||||||
|
discosheep.admin.toggleonjoin:
|
||||||
|
description: Allow a player to toggle party-on-join functionality (force disable)
|
||||||
default: op
|
default: op
|
Loading…
Reference in New Issue
Block a user