Skip to content

Commit

Permalink
Implemented /mute command
Browse files Browse the repository at this point in the history
Signed-off-by: Grafe <[email protected]>
  • Loading branch information
Grafe committed Apr 15, 2013
1 parent 31aa9bf commit 810e260
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 21 deletions.
4 changes: 3 additions & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ commands:
kick:
description: Kick a player
kickall:
description: Kick all players
description: Kick all players
mute:
description: Un/Mute a player
6 changes: 6 additions & 0 deletions src/com/dre/managerxl/LanguageReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ private void setDefaults(){
defaults.put("Help_SetHome", "/sethome - Setze dein eigenes Home");
defaults.put("Help_Kick", "/kick <player> [reason] - Kicke einen Spieler");
defaults.put("Help_KickAll", "/kickall [reason] - Kickt alle Spieler");
defaults.put("Help_Mute", "/mute <player> - Muted einen Spieler");

/* Player */
defaults.put("Player_Kick_Ban", "&4Du wurdest gebannt. Grund: &6&v1");
defaults.put("Player_Kick_TimeBan", "&4Du wurdest gebannt für &6&v2&4. Grund: &6&v1");
defaults.put("Player_Muted", "&4Du bist gemuted!");

/* CMDs */
defaults.put("Cmd_Ban_Success", "&6Spieler &4&v1&6 wurde erfolgreich gebannt!");
Expand All @@ -65,6 +67,10 @@ private void setDefaults(){
defaults.put("Cmd_Kick", "&4Du wurdest von &6&v1&4 gekickt! Grund: &6&v2");
defaults.put("Cmd_KickAll_NoReason", "&4Alle Spieler wurden von &6&v1&4 gekickt!");
defaults.put("Cmd_KickAll", "&4Alle Spieler wurden von &6&v1&4 gekickt! Grund: &6&v2");
defaults.put("Cmd_Mute_UnMuted", "&6Spieler &4&v1&6 wurde entmuted!");
defaults.put("Cmd_Mute_TargetUnMuted", "&6Du wurdest von &4&v1&6 entmuted!");
defaults.put("Cmd_Mute_Muted", "&6Spieler &4&v1&6 wurde gemuted!");
defaults.put("Cmd_Mute_TargeMuted", "&4Du wurdest von &6&v1&4 gemuted!");

/* Errors */
defaults.put("Error_NoPermissions","&4Du hast keine Erlaubnis dies zu tun!");
Expand Down
57 changes: 39 additions & 18 deletions src/com/dre/managerxl/MPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,18 @@ public void setBanned(boolean banned){
public Location getHome() {return home;}
public void setHome(Location home) {this.home = home;}

private boolean isMuted;
public boolean isMuted() {return isMuted;}
public void setMuted(boolean isMuted) {this.isMuted = isMuted;}

public MPlayer(String name){
mPlayers.add(this);

this.name = name;

if(Bukkit.getPlayer(name) != null){
this.setOnline(true);
}
}

//Statics
Expand Down Expand Up @@ -106,17 +114,23 @@ public static boolean SaveAsYml(File file){
FileConfiguration ymlFile = new YamlConfiguration();

for(MPlayer player : MPlayer.get()){
/* Ban */
ymlFile.set(player.getName()+".isBanned", player.isBanned());
ymlFile.set(player.getName()+".bannedTime", player.getBannedTime());
ymlFile.set(player.getName()+".bannedReason", player.getBannedReason());
if(player.getBannedReason() != null) ymlFile.set(player.getName()+".bannedReason", player.getBannedReason());

/* Location */
ymlFile.set(player.getName()+".home.x", player.getHome().getX());
ymlFile.set(player.getName()+".home.y", player.getHome().getY());
ymlFile.set(player.getName()+".home.z", player.getHome().getZ());
ymlFile.set(player.getName()+".home.yaw", (int) player.getHome().getYaw());
ymlFile.set(player.getName()+".home.pitch", (int) player.getHome().getPitch());
ymlFile.set(player.getName()+".home.world", player.getHome().getWorld().getName());
/* Mute */
ymlFile.set(player.getName()+".isMuted", player.isMuted());

/* Home */
if(player.getHome() != null){
ymlFile.set(player.getName()+".home.x", player.getHome().getX());
ymlFile.set(player.getName()+".home.y", player.getHome().getY());
ymlFile.set(player.getName()+".home.z", player.getHome().getZ());
ymlFile.set(player.getName()+".home.pitch", (int) player.getHome().getPitch());
ymlFile.set(player.getName()+".home.yaw", (int) player.getHome().getYaw());
ymlFile.set(player.getName()+".home.world", player.getHome().getWorld().getName());
}
}

try {
Expand All @@ -135,21 +149,28 @@ public static boolean LoadAsYml(File file){

for(String name : keys){
MPlayer mPlayer = new MPlayer(name);

/* Ban */
mPlayer.setBanned(ymlFile.getBoolean(name+".isBanned"));
mPlayer.setBannedTime(ymlFile.getInt(name+".bannedTime"));
mPlayer.setBannedReason(ymlFile.getString(name+".bannedReason"));

/* Mute */
mPlayer.setMuted(ymlFile.getBoolean(name+".isMuted"));

/* Location */
World world = Bukkit.getWorld(ymlFile.getString(name+".home.world"));
if(world != null){
Location loc = new Location(
world,
ymlFile.getDouble(name+".home.x"),
ymlFile.getDouble(name+".home.y"),
ymlFile.getDouble(name+".home.z"),
ymlFile.getInt(name+".home.pitch"),
ymlFile.getInt(name+".home.yaw"));
mPlayer.setHome(loc);
if(ymlFile.contains(name+".home")){
World world = Bukkit.getWorld(ymlFile.getString(name+".home.world"));
if(world != null){
Location loc = new Location(
world,
ymlFile.getDouble(name+".home.x"),
ymlFile.getDouble(name+".home.y"),
ymlFile.getDouble(name+".home.z"),
ymlFile.getInt(name+".home.pitch"),
ymlFile.getInt(name+".home.yaw"));
mPlayer.setHome(loc);
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/com/dre/managerxl/commands/MCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.dre.managerxl.commands.player.Home;
import com.dre.managerxl.commands.player.Kick;
import com.dre.managerxl.commands.player.KickAll;
import com.dre.managerxl.commands.player.Mute;
import com.dre.managerxl.commands.player.SetHome;
import com.dre.managerxl.commands.player.TimeBan;
import com.dre.managerxl.commands.player.Unban;
Expand Down Expand Up @@ -79,6 +80,7 @@ public static void initCommands(){
new SetHome();
new Kick();
new KickAll();
new Mute();
}

public static Set<MCommand> get(){
Expand Down
52 changes: 50 additions & 2 deletions src/com/dre/managerxl/commands/player/Mute.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,53 @@
package com.dre.managerxl.commands.player;

public class Mute {
//TODO: Implement Command
import org.bukkit.command.CommandSender;

import com.dre.managerxl.MPlayer;
import com.dre.managerxl.P;
import com.dre.managerxl.commands.MCommand;

public class Mute extends MCommand{

public Mute(){
this.command = "mute";
this.parrent = null;
this.help = P.p.getLanguageReader().get("Help_Mute");
this.permission = "mxl.cmd.player.mute";

this.isConsoleCommand = true;
this.isPlayerCommand = true;

this.init();
}

@Override
public void onExecute(String[] args, CommandSender sender) {
if(args.length > 0){
MPlayer mPlayer = MPlayer.get(args[0]);

if(mPlayer != null){
if(mPlayer.isMuted()){
mPlayer.setMuted(false);
P.p.msg(sender, P.p.getLanguageReader().get("Cmd_Mute_UnMuted", mPlayer.getName()));

if(mPlayer.isOnline()){
P.p.msg(mPlayer.getPlayer(), P.p.getLanguageReader().get("Cmd_Mute_TargetUnMuted", sender.getName()));
}
} else {
mPlayer.setMuted(true);
P.p.msg(sender, P.p.getLanguageReader().get("Cmd_Mute_Muted", mPlayer.getName()));

if(mPlayer.isOnline()){
P.p.msg(mPlayer.getPlayer(), P.p.getLanguageReader().get("Cmd_Mute_TargeMuted", sender.getName()));
}
}

} else {
P.p.msg(sender, P.p.getLanguageReader().get("Error_PlayerNotExist", args[0]));
}

} else {
P.p.msg(sender, this.help);
}
}
}
11 changes: 11 additions & 0 deletions src/com/dre/managerxl/listeners/PlayerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerLoginEvent.Result;
Expand Down Expand Up @@ -50,4 +51,14 @@ public void onPlayerQuit(PlayerQuitEvent event){

player.setOnline(false);
}

@EventHandler()
public void onAsyncPlayerChat(AsyncPlayerChatEvent event){
MPlayer mPlayer = MPlayer.getOrCreate(event.getPlayer().getName());

if(mPlayer.isMuted()){
P.p.msg(event.getPlayer(), P.p.getLanguageReader().get("Player_Muted"));
event.setCancelled(true);
}
}
}

0 comments on commit 810e260

Please sign in to comment.