Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathanael2611 committed Jul 19, 2019
0 parents commit 409f07e
Show file tree
Hide file tree
Showing 74 changed files with 9,274 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
6 changes: 6 additions & 0 deletions .idea/artifacts/RolePlay_Chat_2_1.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/libraries/Spigot_API_1_12_2_79a30d7_20190219_1130.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

578 changes: 578 additions & 0 deletions .idea/workspace.xml

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions RolePlayChat-PLUGIN.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Spigot-API-1.12.2-79a30d7-20190219-1130" level="project" />
</component>
</module>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
9 changes: 9 additions & 0 deletions out/production/RolePlayChat-PLUGIN/plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: RolePlayChat
version: 1.0
author: Nathanael2611
main: fr.nathanael2611.roleplaychat.plugin.RolePlayChat
commands:
roleplaychat:
description: RolePlayChat command
rpname:
description: NameRP
67 changes: 67 additions & 0 deletions src/fr/nathanael2611/roleplaychat/plugin/RolePlayChat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package fr.nathanael2611.roleplaychat.plugin;

import fr.nathanael2611.roleplaychat.plugin.command.CommandRPName;
import fr.nathanael2611.roleplaychat.plugin.core.ChatConfig;
import fr.nathanael2611.roleplaychat.plugin.event.ChatHandler;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class RolePlayChat extends JavaPlugin {

private static ChatConfig chatConfig;
private static File roleplayNames;

@Override
public void onEnable() {
super.onEnable();
new ChatHandler(this);
getDataFolder().mkdir();
File file = new File(getDataFolder(), "config.properties");
roleplayNames = new File(getDataFolder(), "roleplaynames.json");
if(!file.exists()) {
try {
file.createNewFile();
} catch (IOException ex) {
ex.printStackTrace();
}
}
if(!roleplayNames.exists()) {
try {
roleplayNames.createNewFile();
} catch (IOException ex) {
ex.printStackTrace();
}
}
try {
chatConfig = new ChatConfig(file);
} catch (Exception ex) {
ex.printStackTrace();
}
this.getCommand("rpname").setExecutor(new CommandRPName());
this.getCommand("rpname").setTabCompleter((commandSender, command, s, strings) -> {
List<String> list = new ArrayList<>();
for(Player player : Bukkit.getServer().getOnlinePlayers()){
list.add(player.getName());
}
return list;
});
}

public static ChatConfig getChatConfig() {
return chatConfig;
}

public static File getRoleplayNamesFile() {
return roleplayNames;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package fr.nathanael2611.roleplaychat.plugin.command;

import fr.nathanael2611.roleplaychat.plugin.RolePlayChat;
import fr.nathanael2611.roleplaychat.plugin.core.EnumMessages;
import fr.nathanael2611.roleplaychat.plugin.core.RolePlayNames;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.List;

public class CommandRPName implements CommandExecutor {
@Override
public boolean onCommand(final CommandSender sender, final Command command, final String s, final String[] args) {
if (args.length >= 1) {
List<String> players = new ArrayList<>();
for (Player online : Bukkit.getServer().getOnlinePlayers()) {
players.add(online.getName());
}



if (players.contains(args[0]) && args.length > 1) {
if (sender.hasPermission("roleplaychat.setrpname.other")) {
StringBuilder builder = new StringBuilder();
for(int i = 1; i < args.length; i++){
builder.append(" ").append(args[i]);
}
String rpName = builder.toString().substring(1);
RolePlayNames.setRPName(args[0], rpName);
String result = RolePlayChat.getChatConfig().getMessageTemplate(EnumMessages.SETRPNAMEOTHER);
if (result.contains("{player}")) result = result.replace("{player}", args[0]);
if (result.contains("{rpname}")) result = result.replace("{rpname}", rpName);
sender.sendMessage(result);
} else {
sender.sendMessage(RolePlayChat.getChatConfig().getMessageTemplate(EnumMessages.NOPERM));
}
}else{
StringBuilder builder = new StringBuilder();
for(String str : args){
builder.append(" ").append(str);
}
String rpName = builder.toString().substring(1);
RolePlayNames.setRPName(sender.getName(), rpName);
String result = RolePlayChat.getChatConfig().getMessageTemplate(EnumMessages.SETRPNAME);
if (result.contains("{player}")) result = result.replace("{player}", sender.getName());
if (result.contains("{rpname}")) result = result.replace("{rpname}", rpName);
sender.sendMessage(result);
}
} else {
sender.sendMessage("§cCorrect usage: /rpname <rpname> OR /rpname <player> <rpname>");
}
return false;
}

}
132 changes: 132 additions & 0 deletions src/fr/nathanael2611/roleplaychat/plugin/core/ChatConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package fr.nathanael2611.roleplaychat.plugin.core;

import com.sun.org.apache.bcel.internal.generic.NOP;
import fr.nathanael2611.roleplaychat.plugin.RolePlayChat;

import java.io.*;
import java.nio.charset.Charset;
import java.util.Properties;

public class ChatConfig {

private ChatType hrp;
private ChatType normal;
private ChatType shout;
private ChatType whisp;
private ChatType action;

private String noperm_template;
private String setrpname_template;
private String setrpname_other_template;

private ChatType[] chatTypes;

private final File configFile;

private Properties properties = new Properties();

private FileInputStream input;

public ChatConfig(File configFile) throws Exception {
this.configFile = configFile;
reload();
chatTypes = new ChatType[]{
hrp, normal, shout, whisp, action
};
}

public void reload() throws Exception {
input = new FileInputStream(configFile);
properties.load(
new InputStreamReader(input, Charset.forName("UTF-8"))
);

createPropertyIfNull("prefix.hrp", "(");
createPropertyIfNull("prefix.normal", "");
createPropertyIfNull("prefix.shout", "!");
createPropertyIfNull("prefix.whisp", "$");
createPropertyIfNull("prefix.action", "*");

createPropertyIfNull("distance.hrp", "0");
createPropertyIfNull("distance.normal", "15");
createPropertyIfNull("distance.shout", "30");
createPropertyIfNull("distance.whisp", "2");
createPropertyIfNull("distance.action", "15");

createPropertyIfNull("format.hrp", "§7[HRP] {player} ({rpname}) : {message}");
createPropertyIfNull("format.normal", "[RP] {rpname} : {message}");
createPropertyIfNull("format.shout", "§c[RP-SHOUT] {rpname} : {message}");
createPropertyIfNull("format.whisp", "§2[RP-WHISP] {rpname} : {message}");
createPropertyIfNull("format.action", "§a1§o{rpname} {message}");

createPropertyIfNull("message.nopermission", "§cVous n'avez pas la permission.");
createPropertyIfNull("message.setrpname", "§aVotre nom rp a été défini à {rpname}");
createPropertyIfNull("message.setrpname.other", "§aLe nom rp de {player] a été défini à {rpname}");

hrp = new ChatType(
properties.getProperty("prefix.hrp"),
Integer.parseInt(properties.getProperty("distance.hrp")),
properties.getProperty("format.hrp")
);
normal = new ChatType(
properties.getProperty("prefix.normal"),
Integer.parseInt(properties.getProperty("distance.normal")),
properties.getProperty("format.normal")
);
shout = new ChatType(
properties.getProperty("prefix.shout"),
Integer.parseInt(properties.getProperty("distance.shout")),
properties.getProperty("format.shout")
);
whisp = new ChatType(
properties.getProperty("prefix.whisp"),
Integer.parseInt(properties.getProperty("distance.whisp")),
properties.getProperty("format.whisp")
);
action = new ChatType(
properties.getProperty("prefix.action"),
Integer.parseInt(properties.getProperty("distance.action")),
properties.getProperty("format.action")
);

noperm_template = properties.getProperty("message.nopermission");
setrpname_template = properties.getProperty("message.setrpname");
setrpname_other_template = properties.getProperty("message.setrpname.other");

properties.store(new OutputStreamWriter(new FileOutputStream(configFile), "UTF-8"), "");
input.close();
}

public void createPropertyIfNull(String key, String value) {
if(properties.getProperty(key) == null){
properties.setProperty(key, value);
}
}

public ChatType getChatType(EnumCHatTypes type){
switch (type){
case HRP: return hrp;
case SHOUT: return shout;
case WISPH: return whisp;
case ACTION: return action;
case NORMAL: return normal;
}
return normal;
}

public String getMessageTemplate(EnumMessages msgTemplate){
switch (msgTemplate){
case NOPERM:return noperm_template;
case SETRPNAME:return setrpname_template;
case SETRPNAMEOTHER:return setrpname_other_template;



}
return "";
}

public ChatType[] getChatTypes() {
return chatTypes;
}
}
26 changes: 26 additions & 0 deletions src/fr/nathanael2611/roleplaychat/plugin/core/ChatType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package fr.nathanael2611.roleplaychat.plugin.core;

public class ChatType {

private String prefix;
private int distance;
private String format;

public ChatType(String prefix, int distance, String format) {
this.prefix = prefix;
this.distance = distance;
this.format = format;
}

public String getPrefix() {
return prefix;
}

public int getDistance() {
return distance;
}

public String getFormat() {
return format;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package fr.nathanael2611.roleplaychat.plugin.core;

public enum EnumCHatTypes {
HRP, NORMAL, SHOUT, WISPH,ACTION
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package fr.nathanael2611.roleplaychat.plugin.core;

public enum EnumMessages {
SETRPNAME, SETRPNAMEOTHER, NOPERM
}

0 comments on commit 409f07e

Please sign in to comment.