Skip to content

Commit

Permalink
Working version
Browse files Browse the repository at this point in the history
  • Loading branch information
Guerzoniansus committed Jun 19, 2015
0 parents commit a49b1c4
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="lib" path="C:/Users/Ramon/Desktop/Coding/bukkit-1.7.9-R0.2.jar">
<attributes>
<attribute name="javadoc_location" value="http://jd.bukkit.org/apidocs/"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>RoleplayChat</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
11 changes: 11 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
Binary file added bin/nomarthehero/RoleplayChat.class
Binary file not shown.
14 changes: 14 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: RoleplayChat
main: nomarthehero.RoleplayChat
version: 1.0
commands:
roleplay:
description: Enable roleplay chat
usage: /roleplay
permission: roleplay.use
permission-message: Missing permission.
rp:
description: Enable roleplay chat
usage: /roleplay
permission: roleplay.use
permission-message: Missing permission.
130 changes: 130 additions & 0 deletions src/nomarthehero/RoleplayChat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package nomarthehero;
import java.util.ArrayList;
import java.util.HashSet;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
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.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;


public class RoleplayChat extends JavaPlugin implements Listener, CommandExecutor {

//Every 5~10 min "Hey <player>, you know you're still talking in roleplay chat?" (async runnable)

private ArrayList<String> roleplayers = new ArrayList<String>();
private ArrayList<String> staff = new ArrayList<String>();


public void onEnable() {

getCommand("roleplay").setExecutor(this);
getCommand("rp").setExecutor(this);
getServer().getPluginManager().registerEvents(this, this);

}


@Override
public boolean onCommand(CommandSender sender, Command command,
String label, String[] args) {

if (command.getName().equalsIgnoreCase("roleplay") || command.getName().equalsIgnoreCase("rp")) {

Player player = (Player)sender;
String playerName = player.getName();

if (roleplayers.contains(playerName)) {

roleplayers.remove(playerName);
player.sendMessage(ChatColor.YELLOW + "Disabled roleplay chat!");

} else {

roleplayers.add(playerName);
player.sendMessage(ChatColor.YELLOW + "Enabled roleplay chat!");
player.sendMessage(ChatColor.YELLOW + "Roleplayers will have a yellow chat, and their messages " + ChatColor.RED + "won't" + ChatColor.YELLOW + " be sent in global chat.");
player.sendMessage(ChatColor.YELLOW + "To disable it, type /roleplay again.");

}


}

return true;
}

@EventHandler
public void onChat(AsyncPlayerChatEvent e) {

Player player = e.getPlayer();

if (isRoleplayer(player)) {

String message = e.getMessage();
message = ChatColor.YELLOW + message;

e.setCancelled(true);

for (String playerName : roleplayers) {

Bukkit.getPlayer(playerName).sendMessage(ChatColor.YELLOW + "[RP] " + player.getDisplayName() + ChatColor.YELLOW + ": " + message);

}

for (String playerName : staff) {

if (!roleplayers.contains(playerName)) {

Bukkit.getPlayer(playerName).sendMessage(ChatColor.YELLOW + "[RP] " + player.getDisplayName() + ChatColor.YELLOW + ": " + message);

}

}

}

}


@EventHandler
public void onJoin(PlayerJoinEvent e) {

Player player = e.getPlayer();

if (player.hasPermission("roleplay.staff")) {
staff.add(player.getName());
}

}

@EventHandler
public void onLeave(PlayerQuitEvent e) {

roleplayers.remove(e.getPlayer().getName());

}

private boolean isRoleplayer(Player player) {

if (roleplayers.contains(player.getName())) {

return true;

}

return false;

}



}

0 comments on commit a49b1c4

Please sign in to comment.