#40 Added per player toggling

This commit is contained in:
Daniel Saukel 2016-06-05 13:42:10 +02:00
parent 758a9f03cd
commit b05fd66fb7
6 changed files with 107 additions and 5 deletions

View File

@ -81,7 +81,7 @@
<dependency> <dependency>
<groupId>io.github.dre2n</groupId> <groupId>io.github.dre2n</groupId>
<artifactId>commons</artifactId> <artifactId>commons</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.github.dre2n</groupId> <groupId>io.github.dre2n</groupId>

View File

@ -83,7 +83,6 @@ public class LeaveCommand extends BRCommand {
} }
MessageUtil.sendMessage(player, DMessages.CMD_LEAVE_SUCCESS.getMessage()); MessageUtil.sendMessage(player, DMessages.CMD_LEAVE_SUCCESS.getMessage());
} }
} }

View File

@ -39,6 +39,7 @@ public class DGlobalPlayer {
private boolean breakMode; private boolean breakMode;
private boolean chatSpyMode; private boolean chatSpyMode;
private DPortal creatingPortal; private DPortal creatingPortal;
private boolean announcerEnabled;
private ItemStack[] respawnInventory; private ItemStack[] respawnInventory;
private ItemStack[] respawnArmor; private ItemStack[] respawnArmor;
@ -55,6 +56,7 @@ public class DGlobalPlayer {
breakMode = dPlayer.isInBreakMode(); breakMode = dPlayer.isInBreakMode();
chatSpyMode = dPlayer.isInChatSpyMode(); chatSpyMode = dPlayer.isInChatSpyMode();
creatingPortal = dPlayer.getPortal(); creatingPortal = dPlayer.getPortal();
announcerEnabled = dPlayer.isAnnouncerEnabled();
respawnInventory = dPlayer.getRespawnInventory(); respawnInventory = dPlayer.getRespawnInventory();
respawnArmor = dPlayer.getRespawnArmor(); respawnArmor = dPlayer.getRespawnArmor();
@ -134,6 +136,21 @@ public class DGlobalPlayer {
creatingPortal = dPortal; creatingPortal = dPortal;
} }
/**
* @return if the players receives announcer messages
*/
public boolean isAnnouncerEnabled() {
return announcerEnabled;
}
/**
* @param enabled
* set if the players receives announcer messages
*/
public void setAnnouncerEnabled(boolean enabled) {
announcerEnabled = enabled;
}
/** /**
* @return the respawnInventory * @return the respawnInventory
*/ */

View File

@ -93,6 +93,12 @@ public abstract class DInstancePlayer extends DGlobalPlayer {
this.inDungeonChat = inDungeonChat; this.inDungeonChat = inDungeonChat;
} }
// Players in dungeons never get announcer messages
@Override
public boolean isAnnouncerEnabled() {
return false;
}
/* Actions */ /* Actions */
/** /**
* Clear the player's inventory, potion effects etc. * Clear the player's inventory, potion effects etc.

View File

@ -19,7 +19,6 @@ package io.github.dre2n.dungeonsxl.task;
import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.announcer.Announcer; import io.github.dre2n.dungeonsxl.announcer.Announcer;
import io.github.dre2n.dungeonsxl.announcer.Announcers; import io.github.dre2n.dungeonsxl.announcer.Announcers;
import io.github.dre2n.dungeonsxl.player.DInstancePlayer;
import java.util.List; import java.util.List;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -33,7 +32,7 @@ public class AnnouncerTask extends BukkitRunnable {
DungeonsXL plugin = DungeonsXL.getInstance(); DungeonsXL plugin = DungeonsXL.getInstance();
private List<Announcer> announcers; private List<Announcer> announcers;
int index; private int index;
public AnnouncerTask(Announcers announcers) { public AnnouncerTask(Announcers announcers) {
this.announcers = announcers.getAnnouncers(); this.announcers = announcers.getAnnouncers();
@ -45,7 +44,7 @@ public class AnnouncerTask extends BukkitRunnable {
Announcer announcer = announcers.get(index); Announcer announcer = announcers.get(index);
List<String> worlds = announcer.getWorlds(); List<String> worlds = announcer.getWorlds();
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
if (!(plugin.getDPlayers().getByPlayer(player) instanceof DInstancePlayer)) { if (plugin.getDPlayers().getByPlayer(player).isAnnouncerEnabled()) {
if (worlds.isEmpty() || worlds.contains(player.getWorld().getName())) { if (worlds.isEmpty() || worlds.contains(player.getWorld().getName())) {
announcer.send(player); announcer.send(player);
} }

View File

@ -0,0 +1,81 @@
/*
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.dre2n.dungeonsxl.util;
import io.github.dre2n.commons.util.messageutil.MessageUtil;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
/**
* @author Daniel Saukel
*/
public class ProgressBar extends BukkitRunnable {
public static final String BAR = "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588";
private Set<Player> players = new HashSet<>();
private int seconds;
private int secondsLeft;
public ProgressBar(Set<Player> players, int seconds) {
this.players = players;
this.seconds = seconds;
this.secondsLeft = seconds;
}
public ProgressBar(Player player, int seconds) {
this.players.add(player);
this.seconds = seconds;
this.secondsLeft = seconds;
}
@Override
public void run() {
int i = (int) Math.round(((double) secondsLeft / (double) seconds) * 10);
StringBuilder bar = new StringBuilder(BAR);
bar.insert(10 - i, ChatColor.DARK_RED.toString());
for (Player player : players) {
MessageUtil.sendActionBarMessage(player, ChatColor.GREEN.toString() + bar.toString());
}
if (secondsLeft == 0) {
cancel();
} else {
secondsLeft--;
}
}
/**
* Send the progress bar to a player
*/
public static BukkitTask sendProgressBar(Player player, int seconds) {
return new ProgressBar(player, seconds).runTaskTimer(DungeonsXL.getInstance(), 0, 20);
}
/**
* Send the progress bar to multiple players
*/
public static BukkitTask sendProgressBar(Set<Player> players, int seconds) {
return new ProgressBar(players, seconds).runTaskTimer(DungeonsXL.getInstance(), 0, 20);
}
}