gestion plus propre des grades dans le plugin

This commit is contained in:
Marc Baloup 2015-02-05 02:23:27 -05:00
parent 1a8a911a12
commit 9a45dbf44b
16 changed files with 101 additions and 74 deletions

View File

@ -103,7 +103,6 @@ permissions:
pandacraft.me:
description: Utiliser la commande me
default: true
# à ajouter ###############
pandacraft.me.color:
description: Utiliser la commande me avec des couleurs
default: op
@ -135,17 +134,14 @@ permissions:
description: Ne pas être auto AFK
default: false
# à ajouter ######################
pandacraft.broadcast:
description: Utiliser la commande broadcast et broadcastperm
default: op
# à ajouter ######################
pandacraft.automessager:
description: Utiliser la commande automessager
default: op
# à ajouter ######################
pandacraft.admin:
description: Utiliser la commande admin
default: op
@ -156,27 +152,3 @@ permissions:
default: op
pandacraft.grade.default:
description: Représente le grade Visiteur
default: false
pandacraft.grade.users:
description: Représente le grade Membre
default: false
pandacraft.grade.premium:
description: Représente le grade Premium
default: false
pandacraft.grade.ultimate:
description: Représente le grade Premium plus
default: false
pandacraft.grade.modos:
description: Représente le grade Modos
default: false
pandacraft.grade.admins:
description: Représente le grade Admins
default: false
pandacraft.grade.not_default:
description: Représente tout les joueurs inscrits
default: false
pandacraft.grade.staff:
description: Représente tout le staff
default: false

View File

@ -186,7 +186,7 @@ public class ConfigManager {
message = new HashMap<String, String>();
message.put("message", ChatColor.BLUE+"Bienvenue sur Pandacraft ! :) Pour pouvoir jouer, n'oubliez pas de vous inscrire en cliquant sur le lien en dessous%n &ahttps://www.mc-pandacraft.net/?p=inscription");
message.put("permissions", "pandacraft.grade.default");
message.put("permissions", "group.default");
Automessages_messages.add(message);
message = new HashMap<String, String>();
@ -316,19 +316,19 @@ public class ConfigManager {
alias = new HashMap<String, String>();
alias.put("initialCommand", "/day");
alias.put("replaceWith", "/ptime day");
alias.put("permissions", "pandacraft.grade.users"); // multiple permission separated with semicolumn
alias.put("permissions", "group.users"); // multiple permission separated with semicolumn
CommandAlias_alias.add(alias);
alias = new HashMap<String, String>();
alias.put("initialCommand", "/night");
alias.put("replaceWith", "/ptime night");
alias.put("permissions", "pandacraft.grade.users");
alias.put("permissions", "group.users");
CommandAlias_alias.add(alias);
alias = new HashMap<String, String>();
alias.put("initialCommand", "/time");
alias.put("replaceWith", "/ptime");
alias.put("permissions", "pandacraft.grade.users");
alias.put("permissions", "group.users");
CommandAlias_alias.add(alias);
alias = new HashMap<String, String>();
@ -358,7 +358,7 @@ public class ConfigManager {
alias = new HashMap<String, String>();
alias.put("initialCommand", "/inscription");
alias.put("replaceWith", "/mail send marcbal Inscription");
alias.put("permissions", "pandacraft.grade.not_default");
alias.put("permissions", "group.users");
CommandAlias_alias.add(alias);
/*
Map<String, String> alias = new HashMap<String, String>();

View File

@ -67,7 +67,7 @@ public class CommandAfk extends AbstractCommandExecutor {
if (execute_self)
{
Player p = (Player)sender;
OnlinePlayer ap = OnlinePlayerManager.getInstance().get(p);
OnlinePlayer ap = OnlinePlayerManager.get(p);
if (ap == null)
plugin.getLogger().severe("Cant find AfkPlayer with name "+p.getName()+" when performing command /afk");
else
@ -76,7 +76,7 @@ public class CommandAfk extends AbstractCommandExecutor {
}
else if (execute_other && other_player != null)
{
OnlinePlayer ap = OnlinePlayerManager.getInstance().get(other_player);
OnlinePlayer ap = OnlinePlayerManager.get(other_player);
if (ap == null)
plugin.getLogger().severe("Cant find AfkPlayer with name "+other_player.getName()+" when performing command /afk <player>");
ap.adminToggleAfk();

View File

@ -41,7 +41,6 @@ public class CommandAutomessager extends AbstractCommandExecutor {
}
OnlinePlayerManager
.getInstance()
.get((Player)sender)
.sendMessageFromServer(messages.get(id).getMessage());

View File

@ -158,7 +158,7 @@ public class CommandList extends AbstractCommandExecutor {
{
try
{
int vl = OnlinePlayerManager.getInstance().get(p).getVL();
int vl = OnlinePlayerManager.get(p).getVL();
int max_vl = ConfigManager.getInstance().ChatAnalysis_maxViolationLevel;
aff_list.add("§f"+name+"§r - §7"+vl+"/"+max_vl);
@ -170,7 +170,7 @@ public class CommandList extends AbstractCommandExecutor {
}
else if (args.length > 0 && args[0].toLowerCase().equals("afk"))
{
OnlinePlayer op = OnlinePlayerManager.getInstance().get(p);
OnlinePlayer op = OnlinePlayerManager.get(p);
boolean afk = (op != null && op.isAfk());
double afk_time = (op != null)?op.getDurationSinceLastAction():-1;
String afkTime;
@ -191,7 +191,7 @@ public class CommandList extends AbstractCommandExecutor {
:(p.getGameMode() == GameMode.CREATIVE)?"§bCréa§r"
:(p.getGameMode() == GameMode.ADVENTURE)?("§8Aventure§r;vie:§7"+health+"§r;faim:§7"+eat+"§r"+((flyMode)?";§7canFly":""))
:"§oInconnu";
String afk = (OnlinePlayerManager.getInstance().get(p) != null && OnlinePlayerManager.getInstance().get(p).isAfk())?" §c(Afk)§r":"";
String afk = (OnlinePlayerManager.get(p) != null && OnlinePlayerManager.get(p).isAfk())?" §c(Afk)§r":"";
aff_list.add("§f"+name+"§r"+afk+" - §7"+world+"§r - "+gm);
}
else

View File

@ -4,6 +4,7 @@ import java.util.Date;
import net.mc_pandacraft.java.plugin.pandacraftutils.modules.StaffQueueManager;
import net.mc_pandacraft.java.plugin.pandacraftutils.modules.StaffQueueManager.WaitingPlayer;
import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayerManager;
import net.mc_pandacraft.java.util.TimeUtil;
import org.apache.commons.lang.StringUtils;
@ -25,7 +26,7 @@ public class CommandStaff extends AbstractCommandExecutor {
StaffQueueManager staffManager = plugin.staffQueueManager;
if (sender instanceof Player && !((Player)sender).hasPermission("pandacraft.grade.staff"))
if (sender instanceof Player && !OnlinePlayerManager.get((Player)sender).isInStaff())
{ // un joueur qui n'est pas du staff
// le joueur est-il déjà en file d'attente ?

View File

@ -36,7 +36,7 @@ public class Command_Selection extends AbstractCommandExecutor {
}
Player p = (Player) sender;
OnlinePlayer op = OnlinePlayerManager.getInstance().get(p);
OnlinePlayer op = OnlinePlayerManager.get(p);
Player otherP = null;

View File

@ -53,7 +53,7 @@ public class AfkManager extends BukkitRunnable implements Listener {
@Override
public void run() {
// methode exécutée toute les secondes
Collection<OnlinePlayer> oPlayers = OnlinePlayerManager.getInstance().getAll();
Collection<OnlinePlayer> oPlayers = OnlinePlayerManager.getAll();
for (OnlinePlayer ap : oPlayers.toArray(new OnlinePlayer[oPlayers.size()]))
{ // parcours de tout les joueurs
if (ap == null)
@ -97,7 +97,7 @@ public class AfkManager extends BukkitRunnable implements Listener {
if ( (from.getPitch() == to.getPitch() && from.getYaw() == to.getYaw())
|| (from.getX() == to.getX() && from.getY() == to.getY() && from.getZ() == to.getZ()))
return;
OnlinePlayerManager.getInstance().get(event.getPlayer()).isDoingAction();
OnlinePlayerManager.get(event.getPlayer()).isDoingAction();
}
@ -127,7 +127,7 @@ public class AfkManager extends BukkitRunnable implements Listener {
return;
OnlinePlayerManager.getInstance().get(event.getPlayer()).isDoingAction();
OnlinePlayerManager.get(event.getPlayer()).isDoingAction();
}
@EventHandler
@ -135,7 +135,7 @@ public class AfkManager extends BukkitRunnable implements Listener {
{
try
{
OnlinePlayerManager.getInstance().get(event.getPlayer()).isDoingAction();
OnlinePlayerManager.get(event.getPlayer()).isDoingAction();
}
catch (NullPointerException e) { }
}
@ -145,7 +145,7 @@ public class AfkManager extends BukkitRunnable implements Listener {
{
try
{
OnlinePlayerManager.getInstance().get(event.getPlayer()).isDoingAction();
OnlinePlayerManager.get(event.getPlayer()).isDoingAction();
}
catch (NullPointerException e) { }
}
@ -160,7 +160,7 @@ public class AfkManager extends BukkitRunnable implements Listener {
// car un piston "téléporte" le joueur (techniquement parlant, dans le jeu) à 1 bloc de distance
if (event.getFrom().getWorld() != event.getTo().getWorld()
|| event.getFrom().distanceSquared(event.getTo()) > 2*2)
OnlinePlayerManager.getInstance().get(event.getPlayer()).isDoingAction();
OnlinePlayerManager.get(event.getPlayer()).isDoingAction();
}
catch (NullPointerException e) { }
}
@ -170,7 +170,7 @@ public class AfkManager extends BukkitRunnable implements Listener {
{
try
{
OnlinePlayerManager.getInstance().get(event.getPlayer()).isDoingAction();
OnlinePlayerManager.get(event.getPlayer()).isDoingAction();
}
catch (NullPointerException e) { }
}
@ -179,7 +179,7 @@ public class AfkManager extends BukkitRunnable implements Listener {
{
try
{
OnlinePlayerManager.getInstance().get(event.getPlayer()).isDoingAction();
OnlinePlayerManager.get(event.getPlayer()).isDoingAction();
}
catch (NullPointerException e) { }
}
@ -188,7 +188,7 @@ public class AfkManager extends BukkitRunnable implements Listener {
{
try
{
OnlinePlayerManager.getInstance().get(event.getPlayer()).isDoingAction();
OnlinePlayerManager.get(event.getPlayer()).isDoingAction();
}
catch (NullPointerException e) { }
}
@ -198,7 +198,7 @@ public class AfkManager extends BukkitRunnable implements Listener {
{
try
{
OnlinePlayerManager.getInstance().get(event.getPlayer()).isDoingAction();
OnlinePlayerManager.get(event.getPlayer()).isDoingAction();
}
catch (NullPointerException e) { }
}
@ -208,7 +208,7 @@ public class AfkManager extends BukkitRunnable implements Listener {
{
try
{
OnlinePlayerManager.getInstance().get(event.getPlayer()).isDoingAction();
OnlinePlayerManager.get(event.getPlayer()).isDoingAction();
}
catch (NullPointerException e) { }
}
@ -218,7 +218,7 @@ public class AfkManager extends BukkitRunnable implements Listener {
{
try
{
OnlinePlayerManager.getInstance().get(event.getPlayer()).isDoingAction();
OnlinePlayerManager.get(event.getPlayer()).isDoingAction();
}
catch (NullPointerException e) { }
}

View File

@ -37,12 +37,12 @@ public class AutoMessagesManager extends BukkitRunnable {
// message
// permissions
Collection<OnlinePlayer> oPlayers = OnlinePlayerManager.getInstance().getAll();
Collection<OnlinePlayer> oPlayers = OnlinePlayerManager.getAll();
for (OnlinePlayer op : oPlayers) {
int interval_sec = op.getPlayer().hasPermission("pandacraft.grade.default") ? interval_default : interval_players;
int interval_sec = op.isGuest() ? interval_default : interval_players;
op.firstAutomessageCkeck(interval_sec);

View File

@ -34,7 +34,7 @@ public class CalculatorManager implements Listener {
if (!message.startsWith("="))
return;
OnlinePlayer op = OnlinePlayerManager.getInstance().get(event.getPlayer());
OnlinePlayer op = OnlinePlayerManager.get(event.getPlayer());
List<HistoryElement> history = op.getCalculator_history();
if (message.length() == 1)

View File

@ -27,7 +27,7 @@ public class ChatAnalysisManager implements Listener {
public void onAsyncPlayerChat(AsyncPlayerChatEvent event)
{
try {
OnlinePlayer op = OnlinePlayerManager.getInstance().get(event.getPlayer());
OnlinePlayer op = OnlinePlayerManager.get(event.getPlayer());
if (event.getPlayer().hasPermission("pandacraft.antispam.exempt"))
return;
String message = event.getMessage();
@ -75,7 +75,7 @@ public class ChatAnalysisManager implements Listener {
public void onPlayerCommandPreprocess (PlayerCommandPreprocessEvent event)
{
try {
OnlinePlayer op = OnlinePlayerManager.getInstance().get(event.getPlayer());
OnlinePlayer op = OnlinePlayerManager.get(event.getPlayer());
if (event.getPlayer().hasPermission("pandacraft.antispam.exempt"))
return;
String command_line = event.getMessage();

View File

@ -16,6 +16,8 @@ import com.comphenix.protocol.wrappers.WrappedGameProfile;
import net.mc_pandacraft.java.plugin.pandacraftutils.ConfigManager;
import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils;
import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayer;
import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayerManager;
import net.mc_pandacraft.java.plugin.pandacraftutils.plugin_interface.EssentialsInterface;
public class PacketOutServerInfoListener {
@ -43,7 +45,7 @@ public class PacketOutServerInfoListener {
List<Player> plAdmin = new ArrayList<Player>();
List<Player> plModo = new ArrayList<Player>();
List<Player> plStaff = new ArrayList<Player>();
List<Player> plPlayerUltimate = new ArrayList<Player>();
List<Player> plPlayerPremium = new ArrayList<Player>();
List<Player> plPlayer = new ArrayList<Player>();
@ -55,13 +57,15 @@ public class PacketOutServerInfoListener {
// on passe si le joueur est vanish
if(EssentialsInterface.isPlayerVanished(p)) continue;
if (p.hasPermission("pandacraft.grade.admins"))
OnlinePlayer op = OnlinePlayerManager.get(p);
if (op.isInGroup("admins"))
plAdmin.add(p);
else if (p.hasPermission("pandacraft.grade.modos"))
plModo.add(p);
else if (p.hasPermission("pandacraft.grade.ultimate"))
else if (op.isInStaff())
plStaff.add(p);
else if (op.isInGroup("ultimate"))
plPlayerUltimate.add(p);
else if (p.hasPermission("pandacraft.grade.premium"))
else if (op.isInGroup("premium"))
plPlayerPremium.add(p);
else
plPlayer.add(p);
@ -73,14 +77,14 @@ public class PacketOutServerInfoListener {
List<WrappedGameProfile> list = new ArrayList<WrappedGameProfile>();
if (!plAdmin.isEmpty() || !plModo.isEmpty())
if (!plAdmin.isEmpty() || !plStaff.isEmpty())
{
list.add(new WrappedGameProfile("", "§cStaff connecté :"));
for (Player p : plAdmin)
{
list.add(new WrappedGameProfile("", "§7 - "+p.getDisplayName()));
}
for (Player p : plModo)
for (Player p : plStaff)
{
list.add(new WrappedGameProfile("", "§7 - "+p.getDisplayName()));
}

View File

@ -6,6 +6,7 @@ import java.util.LinkedList;
import java.util.Queue;
import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils;
import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayerManager;
import net.mc_pandacraft.java.util.ScoreBoardUtil;
import net.mc_pandacraft.java.util.TimeUtil;
@ -191,7 +192,7 @@ public class StaffQueueManager implements Listener {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player p = event.getPlayer();
if (p.hasPermission("pandacraft.grade.staff"))
if (OnlinePlayerManager.get(p).isInStaff())
p.setScoreboard(scoreboardPlayerQueue);
plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {
@Override public void run() { updateScoreBoardWaitingList(); }

View File

@ -36,7 +36,7 @@ public class WESelectionDisplayManager extends BukkitRunnable {
try
{
for (OnlinePlayer op : OnlinePlayerManager.getInstance().getAll())
for (OnlinePlayer op : OnlinePlayerManager.getAll())
{
Player p = op.getPlayer();
// on vérifie que le joueur soit en ligne

View File

@ -16,6 +16,8 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import ru.tehkode.permissions.bukkit.PermissionsEx;
public class OnlinePlayer {
private final Player player;
private final PandacraftUtils plugin = PandacraftUtils.getInstance();
@ -242,4 +244,52 @@ public class OnlinePlayer {
public void sendMessageFromServer(String message) {
player.sendMessage(ConfigManager.getInstance().ServerMessages_prefix + message);
}
/*
* Grades
*/
/**
* Indique si le joueur est dans le groupe Spécifié
* @param group Le groupe par rapport au plugin de permission
* @return <i>true</i> si le joueur est dans le groupe spécifié, <i>false</i> sinon
*/
public boolean isInGroup(String group) {
if (group == null) return false;
return PermissionsEx.getUser(player).inGroup(group);
}
/**
* Indique si le joueur est un nouveau joueur (si il ne s'est pas inscrit sur le site)
* @return <i>true</i> si le joueur n'est pas inscrit, <i>false</i> sinon
*/
public boolean isGuest() {
return isInGroup("default");
}
/**
* Indique si le joueur s'est inscrit sur le site
* @return <i>true</i> si c'est le cas, <i>false</i> sinon
*/
public boolean isRegistered() {
return !isGuest();
}
/**
* Indique si le joueur fait parti du staff
* @return <i>true</i> si c'est le cas, <i>false</i> sinon
*/
public boolean isInStaff() {
return isInGroup("admins") ||
isInGroup("devs") ||
isInGroup("modos") ||
isInGroup("archis") ||
isInGroup("guides");
}
}

View File

@ -75,17 +75,17 @@ public final class OnlinePlayerManager implements Listener {
public OnlinePlayer get(Player p) {
return players.get(p);
public static OnlinePlayer get(Player p) {
return getInstance().players.get(p);
}
public Collection<OnlinePlayer> getAll() {
return players.values();
public static Collection<OnlinePlayer> getAll() {
return getInstance().players.values();
}
public boolean contains(Player p) {
return players.containsKey(p);
public static boolean contains(Player p) {
return getInstance().players.containsKey(p);
}
}