mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-09 12:20:30 +01:00
#40 Added per player toggling
This commit is contained in:
parent
758a9f03cd
commit
b05fd66fb7
2
pom.xml
2
pom.xml
@ -81,7 +81,7 @@
|
||||
<dependency>
|
||||
<groupId>io.github.dre2n</groupId>
|
||||
<artifactId>commons</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.dre2n</groupId>
|
||||
|
@ -83,7 +83,6 @@ public class LeaveCommand extends BRCommand {
|
||||
}
|
||||
|
||||
MessageUtil.sendMessage(player, DMessages.CMD_LEAVE_SUCCESS.getMessage());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ public class DGlobalPlayer {
|
||||
private boolean breakMode;
|
||||
private boolean chatSpyMode;
|
||||
private DPortal creatingPortal;
|
||||
private boolean announcerEnabled;
|
||||
|
||||
private ItemStack[] respawnInventory;
|
||||
private ItemStack[] respawnArmor;
|
||||
@ -55,6 +56,7 @@ public class DGlobalPlayer {
|
||||
breakMode = dPlayer.isInBreakMode();
|
||||
chatSpyMode = dPlayer.isInChatSpyMode();
|
||||
creatingPortal = dPlayer.getPortal();
|
||||
announcerEnabled = dPlayer.isAnnouncerEnabled();
|
||||
respawnInventory = dPlayer.getRespawnInventory();
|
||||
respawnArmor = dPlayer.getRespawnArmor();
|
||||
|
||||
@ -134,6 +136,21 @@ public class DGlobalPlayer {
|
||||
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
|
||||
*/
|
||||
|
@ -93,6 +93,12 @@ public abstract class DInstancePlayer extends DGlobalPlayer {
|
||||
this.inDungeonChat = inDungeonChat;
|
||||
}
|
||||
|
||||
// Players in dungeons never get announcer messages
|
||||
@Override
|
||||
public boolean isAnnouncerEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Actions */
|
||||
/**
|
||||
* Clear the player's inventory, potion effects etc.
|
||||
|
@ -19,7 +19,6 @@ package io.github.dre2n.dungeonsxl.task;
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.announcer.Announcer;
|
||||
import io.github.dre2n.dungeonsxl.announcer.Announcers;
|
||||
import io.github.dre2n.dungeonsxl.player.DInstancePlayer;
|
||||
import java.util.List;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -33,7 +32,7 @@ public class AnnouncerTask extends BukkitRunnable {
|
||||
DungeonsXL plugin = DungeonsXL.getInstance();
|
||||
|
||||
private List<Announcer> announcers;
|
||||
int index;
|
||||
private int index;
|
||||
|
||||
public AnnouncerTask(Announcers announcers) {
|
||||
this.announcers = announcers.getAnnouncers();
|
||||
@ -45,7 +44,7 @@ public class AnnouncerTask extends BukkitRunnable {
|
||||
Announcer announcer = announcers.get(index);
|
||||
List<String> worlds = announcer.getWorlds();
|
||||
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())) {
|
||||
announcer.send(player);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user