Initial commit to Gitea
commit
8ad681d9f7
|
@ -0,0 +1,4 @@
|
|||
.idea/
|
||||
*.iml
|
||||
target/
|
||||
dependency-reduced-pom.xml
|
|
@ -0,0 +1,156 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>xyz.etztech</groupId>
|
||||
<artifactId>DeluxeGroups</artifactId>
|
||||
<!-- Version is used in plugin.yml -->
|
||||
<version>1.1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<!-- Plugin Information -->
|
||||
<!-- Name, Description, and URL are used in plugin.yml -->
|
||||
<name>DeluxeGroups</name>
|
||||
<description>A plugin used to add group channels to DeluxeChat. (or any chat plugin, really)</description>
|
||||
<url>http://www.etztech.xyz</url>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>Zlib License</name>
|
||||
<url>http://opensource.org/licenses/Zlib</url>
|
||||
<comments>Copyright (c) 2017 EtzTech
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.</comments>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
<name>EtzTech</name>
|
||||
<url>http://www.etztech.xyz</url>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
<properties>
|
||||
<!-- Author and MainClass are used in plugin.yml -->
|
||||
<author>EtzTech</author>
|
||||
<mainClass>xyz.etztech.deluxegroups.DeluxeGroups</mainClass>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.13.1-R0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.dynmap</groupId>
|
||||
<artifactId>DynmapCoreAPI</artifactId>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>xyz.etztech</groupId>
|
||||
<artifactId>EtzCore</artifactId>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
<version>2.6</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>dynmap-repo</id>
|
||||
<url>http://repo.mikeprimm.com</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>etztech-repo</id>
|
||||
<url>http://repo.etztech.xyz</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>mvn-repo</id>
|
||||
<url>https://mvnrepository.com/artifact/</url>
|
||||
</repository>
|
||||
<repository> <!-- This repo fixes issues with transitive dependencies -->
|
||||
<id>jcenter</id>
|
||||
<url>http://jcenter.bintray.com</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<defaultGoal>clean install</defaultGoal>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<!-- Keeping filtering at true here reduces plugin.yml redundancy! -->
|
||||
<filtering>true</filtering>
|
||||
<includes>
|
||||
<include>plugin.yml</include>
|
||||
<include>config.yml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<!-- Keep filtering at false for other resources to prevent bad magic -->
|
||||
<filtering>false</filtering>
|
||||
<excludes>
|
||||
<exclude>**/*.java</exclude>
|
||||
<exclude>plugin.yml</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<!-- Build an executable JAR -->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.0.2</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addClasspath>true</addClasspath>
|
||||
<classpathPrefix>lib/</classpathPrefix>
|
||||
<mainClass>xyz.etztech.deluxegroups.DeluxeGroups</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,139 @@
|
|||
package xyz.etztech.deluxegroups;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.FileWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DeluxeGroup {
|
||||
|
||||
private String name;
|
||||
private String password;
|
||||
private boolean permanent;
|
||||
private ArrayList<OfflinePlayer> groupList;
|
||||
private FileWriter file;
|
||||
private PrintWriter log;
|
||||
|
||||
public DeluxeGroup() {
|
||||
this.name = "";
|
||||
this.password = "";
|
||||
this.permanent = false;
|
||||
this.groupList = new ArrayList<>();
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
try {
|
||||
this.file = new FileWriter(DeluxeGroups.getInstance().getDataFolder().getAbsolutePath()+"/logs/"+name.toLowerCase()+".log", true);
|
||||
this.log = new PrintWriter(this.file);
|
||||
} catch (Exception e) {
|
||||
DeluxeGroups.getInstance().log("Could not connect to group log for " + name + ".");
|
||||
}
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public boolean getPermanent() {
|
||||
return permanent;
|
||||
}
|
||||
|
||||
public void setPermanent(boolean permanent) {
|
||||
this.permanent = permanent;
|
||||
}
|
||||
|
||||
public ArrayList<OfflinePlayer> getGroupList() {
|
||||
return groupList;
|
||||
}
|
||||
|
||||
public void setGroupList(ArrayList<OfflinePlayer> groupList) {
|
||||
this.groupList = groupList;
|
||||
}
|
||||
|
||||
public boolean hasPassword() {
|
||||
return StringUtils.isNotBlank(this.password);
|
||||
}
|
||||
|
||||
public void add(Player player) {
|
||||
this.groupList.add(player);
|
||||
}
|
||||
|
||||
public void remove(Player player) {
|
||||
for (int i = 0; i < this.groupList.size(); i++) {
|
||||
if (this.groupList.get(i).getUniqueId().toString().equals(player.getUniqueId().toString())) {
|
||||
this.groupList.remove(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(String uuid) {
|
||||
for (int i = 0; i < this.groupList.size(); i++) {
|
||||
if (this.groupList.get(i).getUniqueId().toString().equals(uuid)) {
|
||||
this.groupList.remove(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean contains(Player player) {
|
||||
return this.groupList.contains(player);
|
||||
}
|
||||
|
||||
public ArrayList<OfflinePlayer> getOnline() {
|
||||
ArrayList<OfflinePlayer> onlineList = new ArrayList();
|
||||
for (OfflinePlayer player : this.groupList) {
|
||||
if (player.isOnline()) {
|
||||
onlineList.add(player);
|
||||
}
|
||||
}
|
||||
return onlineList;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return this.groupList.size();
|
||||
}
|
||||
|
||||
public List<String> getUUIDList() {
|
||||
ArrayList<String> uuidList = new ArrayList<>();
|
||||
for (OfflinePlayer player : this.groupList) {
|
||||
uuidList.add(player.getUniqueId().toString());
|
||||
}
|
||||
return uuidList;
|
||||
}
|
||||
|
||||
public void sendMessage(String message) {
|
||||
//DeluxeUtil.log(this.log, message);
|
||||
Player on;
|
||||
for (OfflinePlayer player : this.groupList) {
|
||||
if (player.isOnline()) {
|
||||
on = Bukkit.getPlayer(player.getName());
|
||||
on.sendMessage(ChatColor.AQUA + message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void log(String player, String chat) {
|
||||
String message = player + ": " + chat;
|
||||
DeluxeUtil.log(this.log, message, false);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,237 @@
|
|||
package xyz.etztech.deluxegroups;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.dynmap.DynmapCommonAPI;
|
||||
import xyz.etztech.core.api.IMinecraftManager;
|
||||
import xyz.etztech.deluxegroups.command.CommandGroup;
|
||||
import xyz.etztech.deluxegroups.command.CommandMain;
|
||||
import xyz.etztech.deluxegroups.listeners.AsyncPlayerChatListener;
|
||||
import xyz.etztech.deluxegroups.listeners.SessionListener;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.*;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class DeluxeGroups extends JavaPlugin {
|
||||
|
||||
private static DeluxeGroups instance;
|
||||
|
||||
public static FileConfiguration config;
|
||||
public static FileConfiguration groupConfig;
|
||||
private Logger log = Logger.getLogger( "Minecraft" );
|
||||
|
||||
protected static Map<String, String> inGroup = new HashMap();
|
||||
protected static Map<String, DeluxeGroup> groups = new HashMap();
|
||||
|
||||
// Objects that can be reloaded
|
||||
AsyncPlayerChatListener chatListener;
|
||||
|
||||
// Dynmap API
|
||||
private static DynmapCommonAPI dynmap = null;
|
||||
|
||||
// MinecraftManager API
|
||||
private static IMinecraftManager minecraftManager = null;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
instance = this;
|
||||
saveDefaultConfig();
|
||||
reloadConfig();
|
||||
|
||||
try {
|
||||
File logs = new File(getDataFolder().getAbsolutePath()+"/logs/");
|
||||
logs.mkdir();
|
||||
} catch (Exception e) {}
|
||||
|
||||
|
||||
if (isEnabled()) {
|
||||
|
||||
// Dynmap integration
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("dynmap")) {
|
||||
dynmap = (DynmapCommonAPI) Bukkit.getPluginManager().getPlugin("dynmap");
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "IMPORTANT: Disabling Dynmap Game->Web Chat. All web chat will be handled by DeluxeGroups.");
|
||||
dynmap.setDisableChatToWebProcessing(true);
|
||||
getServer().getPluginManager().registerEvents(new SessionListener(), this);
|
||||
}
|
||||
|
||||
// MCM integration
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("MinecraftManager")) {
|
||||
minecraftManager = (IMinecraftManager) Bukkit.getPluginManager().getPlugin("MinecraftManager");
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "IMPORTANT: Disabling MinecraftManager global logging. All global logging will be handled by DeluxeGroups.");
|
||||
minecraftManager.logOverride(true);
|
||||
}
|
||||
|
||||
// Add Commands
|
||||
CommandMain cmdMain = new CommandMain(this);
|
||||
this.getCommand("deluxegroups").setExecutor(cmdMain);
|
||||
CommandGroup cmdGroup = new CommandGroup(this);
|
||||
this.getCommand("group").setExecutor(cmdGroup);
|
||||
|
||||
|
||||
|
||||
// Add Listeners
|
||||
chatListener = new AsyncPlayerChatListener(this);
|
||||
getServer().getPluginManager().registerEvents(chatListener, this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
log("Saving groups.");
|
||||
String root;
|
||||
for (DeluxeGroup group : groups.values()) {
|
||||
root = group.getName().toLowerCase();
|
||||
groupConfig.createSection(root);
|
||||
groupConfig.set(root + ".name", group.getName());
|
||||
groupConfig.set(root + ".password", group.getPassword());
|
||||
groupConfig.set(root + ".permanent", group.getPermanent());
|
||||
groupConfig.set(root + ".players", group.getSize() > 0 ? group.getUUIDList() : null);
|
||||
}
|
||||
File groupf = new File(getDataFolder(), "groups.yml");
|
||||
try {
|
||||
PrintWriter pw = new PrintWriter(groupf);
|
||||
pw.write("# This is a file for saving all your groups\n" +
|
||||
"# Do not manually edit this file!\n\n");
|
||||
pw.close();
|
||||
} catch (Exception ex) {}
|
||||
try {
|
||||
groupf.createNewFile();
|
||||
groupConfig.save(groupf);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void loadConfig() {
|
||||
config = Bukkit.getPluginManager().getPlugin("DeluxeGroups").getConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reloadConfig() {
|
||||
super.reloadConfig();
|
||||
loadConfig();
|
||||
loadGroupConfig();
|
||||
if (chatListener != null) {
|
||||
chatListener.reload();
|
||||
}
|
||||
}
|
||||
public void loadGroupConfig() {
|
||||
File groupf = new File(getDataFolder(), "groups.yml");
|
||||
|
||||
if (!groupf.exists()) {
|
||||
groupf.getParentFile().mkdirs();
|
||||
saveResource("groups.yml", false);
|
||||
}
|
||||
groupConfig = new YamlConfiguration();
|
||||
|
||||
try {
|
||||
groupConfig.load(groupf);
|
||||
int loaded = 0;
|
||||
OfflinePlayer offlinePlayer;
|
||||
DeluxeGroup group;
|
||||
for (String key : groupConfig.getKeys(false)) {
|
||||
group = new DeluxeGroup();
|
||||
group.setName(groupConfig.getString(key + ".name"));
|
||||
group.setPassword(groupConfig.getString(key + ".password"));
|
||||
group.setPermanent(groupConfig.getBoolean(key + ".permanent"));
|
||||
ArrayList<OfflinePlayer> playerList = new ArrayList<>();
|
||||
for (String uuid : groupConfig.getStringList(key + ".players")) {
|
||||
offlinePlayer = Bukkit.getOfflinePlayer(UUID.fromString(uuid));
|
||||
playerList.add(offlinePlayer);
|
||||
setInGroup(uuid, group.getName());
|
||||
}
|
||||
group.setGroupList(playerList);
|
||||
addGroup(group);
|
||||
loaded++;
|
||||
}
|
||||
log("Loaded " + loaded + " groups!");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void log(String message) {
|
||||
log.info( "[DeluxeGroups]: " + message );
|
||||
}
|
||||
|
||||
public static DeluxeGroups getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static Collection<DeluxeGroup> getGroups() {
|
||||
return groups.values();
|
||||
}
|
||||
|
||||
public static void addGroup(DeluxeGroup group) {
|
||||
groups.put(group.getName().toLowerCase(), group);
|
||||
}
|
||||
|
||||
public static void removeGroup(DeluxeGroup group) {
|
||||
groups.remove(group.getName().toLowerCase());
|
||||
}
|
||||
|
||||
public static DeluxeGroup getGroup(String name) {
|
||||
name = name.toLowerCase();
|
||||
if (groups.containsKey(name)) {
|
||||
return groups.get(name);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void setInGroup(String uuid, String group) {
|
||||
inGroup.put(uuid, group.toLowerCase());
|
||||
}
|
||||
|
||||
public static void removeFromInGroup(String uuid) {
|
||||
inGroup.remove(uuid);
|
||||
}
|
||||
|
||||
public static String getInGroup(String uuid) {
|
||||
if (inGroup.containsKey(uuid)) {
|
||||
return inGroup.get(uuid);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void addToGroup(Player uuid, String group) {
|
||||
group = group.toLowerCase();
|
||||
if (groups.containsKey(group)) {
|
||||
groups.get(group).add(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeFromGroup(Player player, String group) {
|
||||
group = group.toLowerCase();
|
||||
if (groups.containsKey(group)) {
|
||||
groups.get(group).remove(player);
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeFromGroup(OfflinePlayer player, String group) {
|
||||
group = group.toLowerCase();
|
||||
if (groups.containsKey(group)) {
|
||||
groups.get(group).remove(player.getUniqueId().toString());
|
||||
}
|
||||
}
|
||||
|
||||
public static DynmapCommonAPI getDynmap() {
|
||||
return dynmap;
|
||||
}
|
||||
|
||||
public static IMinecraftManager getMinecraftManager() {
|
||||
return minecraftManager;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package xyz.etztech.deluxegroups;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
public class DeluxeUtil {
|
||||
|
||||
public static void sms(Player player, String message) {
|
||||
player.sendMessage(message);
|
||||
}
|
||||
|
||||
public static UUID asUUID(String uuid) {
|
||||
try {
|
||||
if (uuid.contains("-") && uuid.length() == 36) {
|
||||
return UUID.fromString(uuid);
|
||||
} else if (uuid.length() == 32) {
|
||||
return UUID.fromString(uuid.substring(0, 8) + "-" + uuid.substring(8, 12) + "-" + uuid.substring(12, 16)
|
||||
+ "-" + uuid.substring(16, 20) + "-" + uuid.substring(20, 32));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void log(PrintWriter logger, String message, boolean sendToConsole) {
|
||||
if (sendToConsole) {
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(message);
|
||||
}
|
||||
Date date = new Date();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("M/d/yy h:m a");
|
||||
String text = "[" + sdf.format(date) + "] " + message;
|
||||
logger.append(text + "\n");
|
||||
logger.flush();
|
||||
}
|
||||
|
||||
public static Boolean resolveBoolean(String text) {
|
||||
List<String> yes = new ArrayList<>(Arrays.asList("yes", "true", "1"));
|
||||
List<String> no = new ArrayList<>(Arrays.asList("no", "false", "0"));
|
||||
return yes.contains(text) ? true : no.contains(text) ? false : null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,372 @@
|
|||
package xyz.etztech.deluxegroups.command;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import xyz.etztech.deluxegroups.DeluxeGroup;
|
||||
import xyz.etztech.deluxegroups.DeluxeGroups;
|
||||
import xyz.etztech.deluxegroups.DeluxeUtil;
|
||||
|
||||
public class CommandGroup
|
||||
implements CommandExecutor
|
||||
{
|
||||
DeluxeGroups plugin;
|
||||
|
||||
public CommandGroup(DeluxeGroups paramDeluxeGroups)
|
||||
{
|
||||
this.plugin = paramDeluxeGroups;
|
||||
}
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command command, String base, String[] args)
|
||||
{
|
||||
if (!(sender instanceof Player))
|
||||
{
|
||||
sender.sendMessage("This command is not supported in console yet!");
|
||||
return true;
|
||||
}
|
||||
Player localPlayer1 = (Player)sender;
|
||||
|
||||
if (args.length == 0) {
|
||||
if (DeluxeGroups.getInGroup(localPlayer1.getUniqueId().toString()) != null) {
|
||||
DeluxeGroup deluxeGroup = DeluxeGroups.getGroup(DeluxeGroups.getInGroup(localPlayer1.getUniqueId().toString()));
|
||||
DeluxeUtil.sms(localPlayer1, ChatColor.AQUA + "You are in group " + deluxeGroup.getName());
|
||||
} else {
|
||||
DeluxeUtil.sms(localPlayer1, ChatColor.RED + "You are not in a group!");
|
||||
}
|
||||
} else {
|
||||
String subcommand = args[0];
|
||||
if ("create".equals(subcommand.toLowerCase())) {
|
||||
createGroup(localPlayer1, args);
|
||||
} else if ("join".equals(subcommand.toLowerCase())) {
|
||||
joinGroup(localPlayer1, args);
|
||||
} else if ("leave".equals(subcommand.toLowerCase())) {
|
||||
leaveGroup(localPlayer1, args, false);
|
||||
} else if ("list".equals(subcommand.toLowerCase())) {
|
||||
listGroup(localPlayer1, args);
|
||||
} else if ("password".equals(subcommand.toLowerCase())) {
|
||||
modifyPassword(localPlayer1, args);
|
||||
} else if ("permanent".equals(subcommand.toLowerCase())) {
|
||||
modifyPermanent(localPlayer1, args);
|
||||
} else if ("kick".equals(subcommand.toLowerCase())) {
|
||||
kick(localPlayer1, args);
|
||||
} else {
|
||||
help(localPlayer1);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean groupExists(String groupName) {
|
||||
for (DeluxeGroup group : DeluxeGroups.getGroups()) {
|
||||
if (group.getName().toLowerCase().equals(groupName.toLowerCase())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void createGroup(Player player, String[] args) {
|
||||
if (args.length < 2) {
|
||||
DeluxeUtil.sms(player, ChatColor.RED + Usage.CREATE.getFullUsage(player));
|
||||
return;
|
||||
}
|
||||
if (DeluxeGroups.getInGroup(player.getUniqueId().toString()) != null) {
|
||||
DeluxeUtil.sms(player, ChatColor.RED + "You are already in a group! Leave it first to create a new one.");
|
||||
return;
|
||||
}
|
||||
DeluxeGroup cg = new DeluxeGroup();
|
||||
if (!groupExists(args[1])) {
|
||||
cg.setName(args[1]);
|
||||
if (args.length == 2) {
|
||||
DeluxeUtil.sms(player, ChatColor.AQUA + "Creating " + args[1] + " with no password.");
|
||||
} else if ( args.length == 3) {
|
||||
DeluxeUtil.sms(player, ChatColor.RED + "You didn't confirm your password.");
|
||||
return;
|
||||
} else if (args.length == 4) {
|
||||
String password1 = args[2];
|
||||
String password2 = args[3];
|
||||
if (password1.equals(password2)) {
|
||||
cg.setPassword(args[2]);
|
||||
DeluxeUtil.sms(player, ChatColor.AQUA + "Creating " + args[1] + " with password " + args[2] + ".");
|
||||
} else {
|
||||
DeluxeUtil.sms(player, ChatColor.RED + "Your passwords did not match!");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
DeluxeUtil.sms(player, ChatColor.RED + "Too many parameters!");
|
||||
return;
|
||||
}
|
||||
cg.add(player);
|
||||
DeluxeGroups.setInGroup(player.getUniqueId().toString(), args[1]);
|
||||
DeluxeGroups.addGroup(cg);
|
||||
} else {
|
||||
DeluxeUtil.sms(player, ChatColor.RED + "A group with that name already exists!");
|
||||
}
|
||||
}
|
||||
|
||||
private void joinGroup(Player player, String[] args) {
|
||||
if (args.length < 2) {
|
||||
DeluxeUtil.sms(player, ChatColor.RED + Usage.JOIN.getFullUsage(player));
|
||||
return;
|
||||
}
|
||||
if (groupExists(args[1])) {
|
||||
if (DeluxeGroups.getInGroup(player.getUniqueId().toString()) != null) {
|
||||
if (args[1].toLowerCase().equals(DeluxeGroups.getInGroup(player.getUniqueId().toString()).toLowerCase())) {
|
||||
DeluxeUtil.sms(player, ChatColor.RED + "You are already in "
|
||||
+ DeluxeGroups.getInGroup(player.getUniqueId().toString()));
|
||||
return;
|
||||
}
|
||||
leaveGroup(player, args, true);
|
||||
}
|
||||
DeluxeGroup group = DeluxeGroups.getGroup(args[1]);
|
||||
if (args.length == 2) {
|
||||
if (!group.hasPassword()) {
|
||||
group.sendMessage(player.getName() + " has joined the group!");
|
||||
DeluxeUtil.sms(player, ChatColor.AQUA + "You have joined " + group.getName() + "!");
|
||||
DeluxeGroups.setInGroup(player.getUniqueId().toString(), group.getName());
|
||||
DeluxeGroups.addToGroup(player, group.getName());
|
||||
} else {
|
||||
DeluxeUtil.sms(player, ChatColor.RED + group.getName() + " is password protected.");
|
||||
}
|
||||
} else if ( args.length == 3) {
|
||||
if (group.hasPassword() && args[2].equals(group.getPassword())) {
|
||||
group.sendMessage(player.getName() + " has joined the group!");
|
||||
DeluxeUtil.sms(player, ChatColor.AQUA + "You have joined " + group.getName() + "!");
|
||||
DeluxeGroups.setInGroup(player.getUniqueId().toString(), group.getName());
|
||||
DeluxeGroups.addToGroup(player, group.getName());
|
||||
} else if (!group.hasPassword()) {
|
||||
group.sendMessage(player.getName() + " has joined the group!");
|
||||
DeluxeUtil.sms(player, ChatColor.AQUA + "You have joined " + group.getName() + "!");
|
||||
DeluxeGroups.setInGroup(player.getUniqueId().toString(), group.getName());
|
||||
DeluxeGroups.addToGroup(player, group.getName());
|
||||
} else {
|
||||
DeluxeUtil.sms(player, ChatColor.RED + "Incorrect password.");
|
||||
}
|
||||
} else {
|
||||
DeluxeUtil.sms(player, ChatColor.RED + "Too many parameters!");
|
||||
}
|
||||
} else {
|
||||
DeluxeUtil.sms(player, ChatColor.RED + "A group with that name does not exist!");
|
||||
}
|
||||
}
|
||||
|
||||
private void listGroup(Player player, String[] args) {
|
||||
if (args.length == 1) {
|
||||
if (DeluxeGroups.getInGroup(player.getUniqueId().toString()) != null) {
|
||||
DeluxeGroup deluxeGroup = DeluxeGroups.getGroup(DeluxeGroups.getInGroup(player.getUniqueId().toString()));
|
||||
StringBuilder message = new StringBuilder(ChatColor.DARK_AQUA + "===== " + deluxeGroup.getName() + " =====");
|
||||
for (OfflinePlayer groupPlayer : deluxeGroup.getGroupList()) {
|
||||
if (groupPlayer.isOnline()) {
|
||||
message.append("\n" + ChatColor.AQUA + groupPlayer.getName() + " (" + ChatColor.GREEN + "online" + ChatColor.AQUA + ")");
|
||||
} else {
|
||||
message.append("\n" + ChatColor.AQUA + groupPlayer.getName() + " (" + ChatColor.RED + "offline" + ChatColor.AQUA + ")");
|
||||
}
|
||||
}
|
||||
DeluxeUtil.sms(player, message.toString());
|
||||
} else {
|
||||
DeluxeUtil.sms(player, ChatColor.RED + "You are not in a group!");
|
||||
}
|
||||
} else if (args.length == 2) {
|
||||
if (player.hasPermission("deluxegroups.admin")) {
|
||||
DeluxeGroup carrotGroup = DeluxeGroups.getGroup(args[1]);
|
||||
if (carrotGroup != null) {
|
||||
StringBuilder message = new StringBuilder(ChatColor.DARK_AQUA + "===== " + carrotGroup.getName() + " =====");
|
||||
for (OfflinePlayer groupPlayer : carrotGroup.getGroupList()) {
|
||||
if (groupPlayer.isOnline()) {
|
||||
message.append("\n" + ChatColor.AQUA + groupPlayer.getName() + " (" + ChatColor.GREEN + "online" + ChatColor.AQUA + ")");
|
||||
} else {
|
||||
message.append("\n" + ChatColor.AQUA + groupPlayer.getName() + " (" + ChatColor.RED + "offline" + ChatColor.AQUA + ")");
|
||||
}
|
||||
}
|
||||
DeluxeUtil.sms(player, message.toString());
|
||||
} else {
|
||||
DeluxeUtil.sms(player, ChatColor.RED + "There is no group with that name!");
|
||||
}
|
||||
} else {
|
||||
DeluxeUtil.sms(player, ChatColor.RED + "You do not have permission to use this command!");
|
||||
}
|
||||
} else {
|
||||
DeluxeUtil.sms(player, ChatColor.RED + Usage.LIST.getFullUsage(player));
|
||||
}
|
||||
}
|
||||
|
||||
private void leaveGroup(Player player, String[] args, boolean fromJoin) {
|
||||
if (DeluxeGroups.getInGroup(player.getUniqueId().toString()) != null) {
|
||||
DeluxeGroups.removeFromGroup(player, DeluxeGroups.getInGroup(player.getUniqueId().toString()));
|
||||
DeluxeGroup leaveGroup = DeluxeGroups.getGroup(DeluxeGroups.getInGroup(player.getUniqueId().toString()));
|
||||
DeluxeGroups.removeFromInGroup(player.getUniqueId().toString());
|
||||
DeluxeUtil.sms(player, ChatColor.AQUA + "You have left " + leaveGroup.getName());
|
||||
leaveGroup.sendMessage(ChatColor.AQUA + player.getName() + " has left the group.");
|
||||
if (leaveGroup.getSize() < 1 && !leaveGroup.getPermanent()) {
|
||||
// Disband
|
||||
DeluxeGroups.removeGroup(leaveGroup);
|
||||
}
|
||||
} else if (!fromJoin){
|
||||
DeluxeUtil.sms(player, ChatColor.RED + "You are not in a group!");
|
||||
}
|
||||
}
|
||||
|
||||
private void modifyPassword(Player player, String[] args) {
|
||||
if (!player.hasPermission("deluxegroups.admin")) {
|
||||
DeluxeUtil.sms(player, ChatColor.RED + "You do not have permission to use this command!");
|
||||
return;
|
||||
}
|
||||
if (args.length < 4) {
|
||||
DeluxeUtil.sms(player, ChatColor.RED + Usage.PASSWORD.getFullUsage(player));
|
||||
return;
|
||||
}
|
||||
DeluxeGroup group = DeluxeGroups.getGroup(args[1]);
|
||||
if (group != null) {
|
||||
if (args[2].equals(args[3])) {
|
||||
DeluxeGroups.getGroup(args[1]).setPassword(args[2]);
|
||||
DeluxeUtil.sms(player, ChatColor.GREEN + "Password for " + group.getName() + " changed to '" + group.getPassword() + "'.");
|
||||
} else {
|
||||
DeluxeUtil.sms(player, ChatColor.RED + "Passwords did not match.");
|
||||
}
|
||||
} else {
|
||||
DeluxeUtil.sms(player, ChatColor.RED + "Group '" + args[1] + "' does not exist.");
|
||||
}
|
||||
}
|
||||
|
||||
private void modifyPermanent(Player player, String[] args) {
|
||||
if (!player.hasPermission("deluxegroups.admin")) {
|
||||
DeluxeUtil.sms(player, ChatColor.RED + "You do not have permission to use this command!");
|
||||
return;
|
||||
}
|
||||
if (args.length < 3) {
|
||||
DeluxeUtil.sms(player, ChatColor.RED + Usage.PERMANENT.getFullUsage(player));
|
||||
return;
|
||||
}
|
||||
DeluxeGroup group = DeluxeGroups.getGroup(args[1]);
|
||||
if (group != null) {
|
||||
Boolean perm = DeluxeUtil.resolveBoolean(args[2]);
|
||||
if (perm != null) {
|
||||
DeluxeGroups.getGroup(args[1]).setPermanent(perm);
|
||||
DeluxeUtil.sms(player, ChatColor.GREEN + group.getName() + " is " + (group.getPermanent() ? "now" : "no longer") + " permanent.");
|
||||
if (!group.getPermanent() && group.getSize() < 1) {
|
||||
// Disband
|
||||
DeluxeGroups.removeGroup(group);
|
||||
}
|
||||
} else {
|
||||
DeluxeUtil.sms(player, ChatColor.RED + Usage.PERMANENT.getFullUsage(player));
|
||||
}
|
||||
} else {
|
||||
DeluxeUtil.sms(player, ChatColor.RED + "Group '" + args[1] + "' does not exist.");
|
||||
}
|
||||
}
|
||||
|
||||
private void kick(Player player, String[] args) {
|
||||
if (!player.hasPermission("deluxegroups.admin")) {
|
||||
DeluxeUtil.sms(player, ChatColor.RED + "You do not have permission to use this command!");
|
||||
return;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
DeluxeUtil.sms(player, ChatColor.RED + Usage.KICK.getFullUsage(player));
|
||||
return;
|
||||
}
|
||||
Player argPlayer = Bukkit.getPlayer(args[1]);
|
||||
if (argPlayer != null) {
|
||||
if (DeluxeGroups.getInGroup(argPlayer.getUniqueId().toString()) != null) {
|
||||
DeluxeGroup group = DeluxeGroups.getGroup(DeluxeGroups.getInGroup(argPlayer.getUniqueId().toString()));
|
||||
DeluxeGroups.removeFromGroup(argPlayer, group.getName());
|
||||
//group.remove(argPlayer.getUniqueId().toString());
|
||||
DeluxeGroups.removeFromInGroup(argPlayer.getUniqueId().toString());
|
||||
DeluxeUtil.sms(player, ChatColor.GREEN + argPlayer.getName() + " was kicked from " + group.getName() + ".");
|
||||
DeluxeUtil.sms(argPlayer, ChatColor.RED + "You were kicked from " + group.getName() + ".");
|
||||
} else {
|
||||
DeluxeUtil.sms(player, ChatColor.RED + argPlayer.getName() + " is not in a group.");
|
||||
}
|
||||
} else {
|
||||
OfflinePlayer offPlayer;
|
||||
try {
|
||||
offPlayer = Bukkit.getOfflinePlayer(DeluxeUtil.asUUID(args[1]));
|
||||
} catch (Exception ex) {
|
||||
offPlayer = null;
|
||||
}
|
||||
if (offPlayer != null) {
|
||||
if (DeluxeGroups.getInGroup(offPlayer.getUniqueId().toString()) != null) {
|
||||
DeluxeGroup group = DeluxeGroups.getGroup(DeluxeGroups.getInGroup(offPlayer.getUniqueId().toString()));
|
||||
DeluxeGroups.removeFromGroup(offPlayer, group.getName());
|
||||
DeluxeGroups.removeFromInGroup(offPlayer.getUniqueId().toString());
|
||||
DeluxeUtil.sms(player, ChatColor.GREEN + offPlayer.getName() + " was kicked from " + group.getName() + ".");
|
||||
if (offPlayer.isOnline()) {
|
||||
Player onPlayer = Bukkit.getPlayer(offPlayer.getUniqueId());
|
||||
DeluxeUtil.sms(onPlayer, ChatColor.RED + "You were kicked from " + group.getName() + ".");
|
||||
}
|
||||
} else {
|
||||
DeluxeUtil.sms(player, ChatColor.RED + offPlayer.getName() + " is not in a group.");
|
||||
}
|
||||
} else {
|
||||
DeluxeUtil.sms(player, ChatColor.RED + "Player not found.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void help(Player player) {
|
||||
StringBuilder message = new StringBuilder(ChatColor.GOLD + "===== Group Help =====");
|
||||
for (Usage usage : Usage.values()) {
|
||||
if (usage.canUse(player)) {
|
||||
message.append("\n" + ChatColor.GREEN + usage.getFullUsage(player));
|
||||
}
|
||||
}
|
||||
DeluxeUtil.sms(player, message.toString());
|
||||
}
|
||||
|
||||
enum Usage {
|
||||
|
||||
CREATE("/group create <group name> [<password> <confirm password>]"),
|
||||
JOIN("/group join <group name> [<password>]"),
|
||||
LEAVE("/group leave"),
|
||||
LIST("/group list [<group name>]", "deluxegroups.admin", "/group list"),
|
||||
PASSWORD("/group password <group name> [<new password> <confirm password>]", "deluxegroups.admin"),
|
||||
PERMANENT("/group permanent <group name> <true|false>", "deluxegroups.admin"),
|
||||
KICK("/group kick <player name or UUID>", "deluxegroups.admin");
|
||||
|
||||
private String usage;
|
||||
private String permission;
|
||||
private String alternate;
|
||||
|
||||
Usage(String usage) {
|
||||
this.usage = usage;
|
||||
this.permission = null;
|
||||
this.alternate = null;
|
||||
}
|
||||
|
||||
Usage(String usage, String permission) {
|
||||
this.usage = usage;
|
||||
this.permission = permission;
|
||||
this.alternate = null;
|
||||
}
|
||||
|
||||
Usage(String usage, String permission, String alternate) {
|
||||
this.usage = usage;
|
||||
this.permission = permission;
|
||||
this.alternate = alternate;
|
||||
}
|
||||
|
||||
public String getUsage() {
|
||||
return usage;
|
||||
}
|
||||
|
||||
public String getPermission() {
|
||||
return permission;
|
||||
}
|
||||
|
||||
public String getAlternate() {
|
||||
return alternate;
|
||||
}
|
||||
|
||||
public boolean canUse(Player player) {
|
||||
return (permission != null && player.hasPermission(permission)) || alternate != null;
|
||||
}
|
||||
|
||||
public String getFullUsage(Player player) {
|
||||
return (permission == null || player.hasPermission(permission)) ? usage : alternate;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
package xyz.etztech.deluxegroups.command;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import xyz.etztech.deluxegroups.DeluxeGroups;
|
||||
|
||||
public class CommandMain implements CommandExecutor {
|
||||
|
||||
DeluxeGroups plugin;
|
||||
|
||||
|
||||
public CommandMain(DeluxeGroups plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String base, String[] args) {
|
||||
if (args.length == 0) {
|
||||
other(sender);
|
||||
} else if (args.length == 1) {
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "help":
|
||||
sender.sendMessage(ChatColor.GOLD + "----- DeluxeGroups Commands -----");
|
||||
sender.sendMessage(ChatColor.YELLOW + "/dg reload - Reload the config");
|
||||
sender.sendMessage(ChatColor.GOLD + "----- DeluxeGroups Group Commands -----");
|
||||
sender.sendMessage(ChatColor.YELLOW + "/group - Display your group");
|
||||
sender.sendMessage(ChatColor.YELLOW + "/group create - Create a new group.");
|
||||
sender.sendMessage(ChatColor.YELLOW + "/group join - Join a group");
|
||||
sender.sendMessage(ChatColor.YELLOW + "/group leave - Leave a group");
|
||||
sender.sendMessage(ChatColor.YELLOW + "/group list - List the players in a group");
|
||||
sender.sendMessage(ChatColor.YELLOW + "/group password - Modify the password for your group");
|
||||
sender.sendMessage(ChatColor.YELLOW + "/group kick - Kick a player from the group");
|
||||
break;
|
||||
case "reload":
|
||||
reload(sender);
|
||||
break;
|
||||
default:
|
||||
other(sender);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void other(CommandSender sender) {
|
||||
String version = Bukkit.getPluginManager().getPlugin("DeluxeGroups").getDescription().getVersion();
|
||||
sender.sendMessage(ChatColor.GOLD + "----- DeluxeGroups v" + version + " -----");
|
||||
sender.sendMessage(ChatColor.YELLOW + "Developed by EtzTech");
|
||||
sender.sendMessage(ChatColor.YELLOW + "Use \"/dg help\" for help.");
|
||||
}
|
||||
|
||||
|
||||
private void reload(CommandSender sender) {
|
||||
if (!sender.hasPermission("deluxegroups.admin")) {
|
||||
sender.sendMessage(ChatColor.RED + "You do not have permission to use this command.");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
sender.sendMessage("Reloading DeluxeGroups...");
|
||||
this.plugin.reloadConfig();
|
||||
sender.sendMessage("DeluxeGroups reloaded.");
|
||||
} catch (Exception ex) {
|
||||
sender.sendMessage("DeluxeGroups reload was interrupted.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,125 @@
|
|||
package xyz.etztech.deluxegroups.listeners;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.dynmap.DynmapCommonAPI;
|
||||
import xyz.etztech.core.api.IMinecraftManager;
|
||||
import xyz.etztech.deluxegroups.DeluxeGroup;
|
||||
import xyz.etztech.deluxegroups.DeluxeGroups;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class AsyncPlayerChatListener implements Listener {
|
||||
|
||||
private DeluxeGroups plugin;
|
||||
private List<String> groupPrefixes;
|
||||
|
||||
public AsyncPlayerChatListener(DeluxeGroups deluxeGroups) {
|
||||
this.plugin = deluxeGroups;
|
||||
reload();
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
this.groupPrefixes = new ArrayList<>();
|
||||
this.groupPrefixes.addAll(trimmed(this.plugin.getConfig().getStringList("prefix")));
|
||||
}
|
||||
|
||||
@EventHandler(priority=EventPriority.HIGH)
|
||||
public void onChat(AsyncPlayerChatEvent event) {
|
||||
|
||||
Player sender = event.getPlayer();
|
||||
String chat = event.getMessage();
|
||||
|
||||
if (!sender.hasPermission("deluxegroups.group.chat")) {
|
||||
return;
|
||||
}
|
||||
|
||||
DynmapCommonAPI dynmap = DeluxeGroups.getDynmap();
|
||||
IMinecraftManager minecraftManager = DeluxeGroups.getMinecraftManager();
|
||||
|
||||
|
||||
if (DeluxeGroups.getInGroup(sender.getUniqueId().toString()) != null) {
|
||||
boolean groupChat = false;
|
||||
for (String prefix : this.groupPrefixes) {
|
||||
// If chat starts with 1 prefix, it is group chat.
|
||||
if (chat.startsWith(prefix)) {
|
||||
groupChat = true;
|
||||
chat = chat.substring(1);
|
||||
// If chat still starts with the prefix, it means there were two and we are delegating to normal chat
|
||||
if (chat.startsWith(prefix)) {
|
||||
event.setMessage(chat);
|
||||
|
||||
// Normal chat
|
||||
if (!event.isCancelled()) {
|
||||
if (dynmap != null) {
|
||||
dynmap.postPlayerMessageToWeb(sender.getName(), sender.getName(), chat);
|
||||
//dynmap.sendBroadcastToWeb(sender.getName(), chat);
|
||||
}
|
||||
if (minecraftManager != null) {
|
||||
minecraftManager.globalLog(sender, chat);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (groupChat) {
|
||||
String groupName = DeluxeGroups.getInGroup(sender.getUniqueId().toString());
|
||||
DeluxeGroup group = DeluxeGroups.getGroup(groupName);
|
||||
group.log(sender.getPlayer().getName(), chat);
|
||||
|
||||
String format = plugin.getConfig().getString("format.custom");
|
||||
if (StringUtils.isNotBlank(format)) {
|
||||
chat = format.replace("<group>", group.getName()).replace("<message>", chat);
|
||||
}
|
||||
String color = plugin.getConfig().getString("format.color");
|
||||
if (StringUtils.isNotBlank(color)) {
|
||||
chat = ChatColor.getByChar(color.replace("&", "")) + chat;
|
||||
}
|
||||
|
||||
List<String> uuids = group.getUUIDList();
|
||||
|
||||
Iterator recipients = event.getRecipients().iterator();
|
||||
while (recipients.hasNext()) {
|
||||
Player player = (Player) recipients.next();
|
||||
if (!uuids.contains(player.getUniqueId().toString())) {
|
||||
recipients.remove();
|
||||
}
|
||||
}
|
||||
event.setMessage(chat);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Normal chat
|
||||
if (!event.isCancelled()) {
|
||||
if (dynmap != null) {
|
||||
dynmap.postPlayerMessageToWeb(sender.getName(), sender.getName(), chat);
|
||||
//dynmap.sendBroadcastToWeb(sender.getName(), chat);
|
||||
}
|
||||
if (minecraftManager != null) {
|
||||
minecraftManager.globalLog(sender, chat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> trimmed(List<String> list) {
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
list.set(i, list.get(i).trim());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package xyz.etztech.deluxegroups.listeners;
|
||||
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.dynmap.DynmapCommonAPI;
|
||||
import xyz.etztech.deluxegroups.DeluxeGroups;
|
||||
|
||||
public class SessionListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onLogin(PlayerLoginEvent event) {
|
||||
handleEvent(event.getPlayer(), true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onLogout(PlayerQuitEvent event) {
|
||||
handleEvent(event.getPlayer(), false);
|
||||
}
|
||||
|
||||
private void handleEvent(Player player, boolean loggedIn) {
|
||||
DynmapCommonAPI dynmap = DeluxeGroups.getDynmap();
|
||||
if (dynmap != null) {
|
||||
dynmap.postPlayerJoinQuitToWeb(player.getName(), player.getName(), loggedIn);
|
||||
//dynmap.sendBroadcastToWeb("", player.getName() + " " + (loggedIn ? "joined" : "left") + " the server");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
# A list of prefixes that can be used to initiate group chat
|
||||
prefix:
|
||||
- "$"
|
||||
- "`"
|
||||
|
||||
# To avoid messing up other chat plugins, DG can really only alter the message safely
|
||||
# So, we have a few options to make players aware of group chat vs global chat
|
||||
# If you don't want anything, leave these as-is
|
||||
format:
|
||||
color: ''
|
||||
# Custom format. The variables <group> and <message> are available and will be
|
||||
# replaced by the group name and chat message respectively
|
||||
custom: ''
|
|
@ -0,0 +1,2 @@
|
|||
# This is a file for saving all your groups
|
||||
# Do not manually edit this file!
|
|
@ -0,0 +1,40 @@
|
|||
name: ${name}
|
||||
version: ${version}
|
||||
description: ${description}
|
||||
author: ${author}
|
||||
website: ${url}
|
||||
main: ${mainClass}
|
||||
softdepend: [dynmap, MinecraftManager]
|
||||
commands:
|
||||
deluxegroups:
|
||||
description: Base DeluxeGroups command
|
||||
aliases: [deluxegroup, dg]
|
||||
group:
|
||||
description: Group commands
|
||||
aliases: []
|
||||
permissions:
|
||||
deluxegroups.admin:
|
||||
description: Allows use of DeluxeGroups admin commands
|
||||
default: op
|
||||
deluxegroups.group.create:
|
||||
description: Allows players to create a group.
|
||||
default: op
|
||||
deluxegroups.group.join:
|
||||
description: Allows players to join (or leave) a group.
|
||||
default: op
|
||||
deluxegroups.group.chat:
|
||||
description: Allows players to chat in a group.
|
||||
default: op
|
||||
deluxegroups.group.*:
|
||||
description: Wildcard permission for DeluxeGroups group commands
|
||||
default: op
|
||||
children:
|
||||
deluxegroups.group.create: true
|
||||
deluxegroups.group.join: true
|
||||
deluxegroups.group.chat: true
|
||||
deluxegroups.*:
|
||||
description: Wildcard permission for DeluxeGroups
|
||||
default: op
|
||||
children:
|
||||
deluxegroups.admin: true
|
||||
deluxegroups.group.*: true
|
Loading…
Reference in New Issue