First Commit

This commit is contained in:
spaffel
2022-06-14 01:23:43 +02:00
parent 3aff526e17
commit 1dce758f3c
9 changed files with 825 additions and 0 deletions

113
.gitignore vendored Normal file
View File

@@ -0,0 +1,113 @@
# User-specific stuff
.idea/
*.iml
*.ipr
*.iws
# IntelliJ
out/
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
*~
# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*
# KDE directory preferences
.directory
# Linux trash folder which might appear on any partition or disk
.Trash-*
# .nfs files are created when an open file is removed but is still being accessed
.nfs*
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar
.flattened-pom.xml
# Common working directory
run/

99
pom.xml Normal file
View File

@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>de.spaffel</groupId>
<artifactId>Clans</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Clans</name>
<description>A Simple Clans-Plugin by Spaffel</description>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<url>spaffel.de</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<repositories>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.19-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20220320</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>net.luckperms</groupId>
<artifactId>api</artifactId>
<version>5.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,122 @@
package de.spaffel.clans;
import net.luckperms.api.LuckPerms;
import net.luckperms.api.model.user.User;
import net.luckperms.api.event.EventBus;
import net.luckperms.api.event.log.LogPublishEvent;
import net.luckperms.api.event.user.UserLoadEvent;
import net.luckperms.api.event.user.track.UserPromoteEvent;
import de.spaffel.clans.commands.test;
import de.spaffel.clans.commands.newclan;
import de.spaffel.clans.commands.leaveclan;
import de.spaffel.clans.commands.joinclan;
import de.spaffel.clans.commands.utils.jsonutil;
import org.bukkit.entity.Player;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import java.io.IOException;
import org.json.simple.JSONObject;
import java.io.File;
import java.util.Set;
import java.util.stream.Collectors;
import net.luckperms.api.LuckPermsProvider;
import net.luckperms.api.model.user.User;
import net.luckperms.api.node.Node;
import net.luckperms.api.node.NodeType;
import net.luckperms.api.node.types.ChatMetaNode;
import net.luckperms.api.node.types.InheritanceNode;
import net.luckperms.api.node.types.PrefixNode;
import org.bukkit.Bukkit;
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.PlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.Plugin;
public final class Clans extends JavaPlugin implements Listener {
public LuckPerms lp;
@Override
public void onEnable() {
// Plugin startup logic
getServer().getPluginManager().registerEvents(this, this);
File file = new File("plugins/Clans/playerdata/");
boolean dirCreated = file.mkdirs();
file = new File("plugins/Clans/clandata/");
dirCreated = file.mkdirs();
file = new File("plugins/Clans/uuids/");
dirCreated = file.mkdirs();
file = new File("plugins/Clans/clannames/");
dirCreated = file.mkdirs();
getCommand("test").setExecutor(new test());
getCommand("newclan").setExecutor(new newclan());
getCommand("leaveclan").setExecutor(new leaveclan());
getCommand("joinclan").setExecutor(new joinclan());
}
@Override
public void onDisable() {
// Plugin shutdown logic
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "say Helllooow!" + event.getPlayer().getName());
jsonutil.createPlayer(toString().valueOf(event.getPlayer().getUniqueId()));
jsonutil.createuuidentry(toString().valueOf(event.getPlayer().getUniqueId()), event.getPlayer().getName());
}
public void ChatFormat(LuckPerms lp) {
this.lp = lp;
}
@EventHandler
public void onChat(AsyncPlayerChatEvent e) {
User user = LuckPermsProvider.get().getPlayerAdapter(Player.class).getUser(e.getPlayer());
Set<String> groups = (Set<String>)user.getNodes(NodeType.INHERITANCE).stream().map(InheritanceNode::getGroupName)
.collect(Collectors.toSet());
String prefix2 = user.getCachedData().getMetaData().getPrefix().replace("&", "§");
String suffix = user.getCachedData().getMetaData().getSuffix().replace("&", "§");
Player p = e.getPlayer();
if (user.getCachedData().getMetaData().getPrefix() == null){
return;
}else{
Player pli = e.getPlayer();
System.out.println(prefix2);
String prefix = jsonutil.getPrefix(String.valueOf(e.getPlayer().getUniqueId()));
e.setFormat(prefix2 + "" + prefix + e.getPlayer().getName() + " §7➢ §r" + e.getMessage());
}
}
}

View File

@@ -0,0 +1,38 @@
package de.spaffel.clans.commands;
import de.spaffel.clans.commands.utils.jsonutil;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
public class joinclan implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length == 2){
String name = toString().valueOf(args[0]);
String password = toString().valueOf(args[1]);
String playername = sender.getName();
String playeruuid = String.valueOf(jsonutil.getUUID(playername));
String ans = jsonutil.JoinClan(name, password, playeruuid);
System.out.println(ans);
if (ans == "done"){
sender.sendMessage(ChatColor.GREEN + "You have joined the Clan " + name + "!");
}else{
sender.sendMessage(ChatColor.RED + "Wrong Password");
}
return true;
}else {
sender.sendMessage(ChatColor.RED + "You need to write /joinclan clanname password");
}
return false;
}
}

View File

@@ -0,0 +1,19 @@
package de.spaffel.clans.commands;
import de.spaffel.clans.commands.utils.jsonutil;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
public class leaveclan implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
String playername = sender.getName();
String leaderuuid = String.valueOf(jsonutil.getUUID(playername));
String uuid = leaderuuid;
jsonutil.setClanId(uuid, "0");
sender.sendMessage(ChatColor.GREEN + "You have left the Clan!");
return false;
}
}

View File

@@ -0,0 +1,42 @@
package de.spaffel.clans.commands;
import java.io.IOException;
import java.net.URL;
import de.spaffel.clans.commands.utils.jsonutil;
import org.bukkit.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
public class newclan implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length == 2){
String name = toString().valueOf(args[0]);
String password = toString().valueOf(args[1]);
String playername = sender.getName();
String leaderuuid = String.valueOf(jsonutil.getUUID(playername));
String ans = jsonutil.createClan(name, password, leaderuuid);
if (ans == "done"){
sender.sendMessage(ChatColor.GREEN + "You have created the Clan " + name + "!");
return true;
}else{
sender.sendMessage(ChatColor.RED + "Clanname is already in Use");
}
}else {
sender.sendMessage(ChatColor.RED + "You need to write /newclan clanname password");
}
return false;
}
}

View File

@@ -0,0 +1,13 @@
package de.spaffel.clans.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
public class test implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
sender.sendMessage("That is a Test");
return false;
}
}

View File

@@ -0,0 +1,366 @@
package de.spaffel.clans.commands.utils;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.FileReader;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.Random;
import java.io.IOException;
import org.json.simple.JSONObject;
import java.io.File;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import java.util.concurrent.ThreadLocalRandom;
import java.lang.Math;
public class jsonutil extends JavaPlugin{
private static String datafolder;
public void setDatafolder(){
datafolder = getDataFolder().getAbsolutePath();
}
public void jsonutil(){
setDatafolder();
}
public static String getPass(String Clanid){
String path = "plugins/Clans/clandata/" + Clanid + ".json";
String ans = checkFile(path);
if (ans == "exists"){
JSONParser jsonParser = new JSONParser();
try {
JSONObject jsonObject = (JSONObject) jsonParser.parse(new FileReader(path));
String password = (String) jsonObject.get("password");
System.out.println("`" + password + "`");
return password;
}catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
}
return "ne diggi";
}
public static String getClanName(String ClanId) {
String path = "plugins/Clans/clandata/" + ClanId + ".json";
String ans = checkFile(path);
if (ans == "exists") {
JSONParser jsonParser = new JSONParser();
try {
JSONObject jsonObject = (JSONObject) jsonParser.parse(new FileReader(path));
String clanname = (String) jsonObject.get("name");
return clanname;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
}
return "nix";
}
public static String getPrefix(String uuid) {
String path = "plugins/Clans/playerdata/" + uuid + ".json";
String ans = checkFile(path);
if (ans == "exists") {
JSONParser jsonParser = new JSONParser();
try {
JSONObject jsonObject = (JSONObject) jsonParser.parse(new FileReader(path));
String Clanid = (String) jsonObject.get("ClanId");
if (Clanid.equals("0")){
String prefix = "";
return prefix;
}else{
String Clanname = getClanName(Clanid);
String prefix = "§a§l[" + Clanname + "-Clan] §f§r";
return prefix;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
}
return "knecht";
}
public static String JoinClan(String clanname, String Password, String UUID){
String Clanid = getClanId(clanname);
String Orgpass = getPass(Clanid);
System.out.println("`"+ Password +"`");
if (Orgpass.equals(Password)){
setClanId(UUID,Clanid);
return "done";
}else{
return "incorrect";
}
}
public static void createFile(String path){
String ans = checkFile(path);
if (ans == "not"){
JSONObject jsonObject = new JSONObject();
try {
File myObj = new File(path);
if (myObj.createNewFile()) {
FileWriter file = new FileWriter(path);
file.write(jsonObject.toJSONString());
file.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static String checkFile(String filePathString) {
File f = new File(filePathString);
if (f.exists() && !f.isDirectory()) {
return "exists";
} else {
return "not";
}
}
public static void setClanId(String uuid, String Clanid){
String path = "plugins/Clans/playerdata/" + uuid + ".json";
String ans = checkFile(path);
if (ans == "exists"){
JSONParser jsonParser = new JSONParser();
try {
JSONObject jsonObject = (JSONObject) jsonParser.parse(new FileReader(path));
jsonObject.put("ClanId", Clanid);
FileWriter file = new FileWriter(path);
file.write(jsonObject.toJSONString());
file.close();
System.out.println("Saved ClanId");
}catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
}else{
System.out.println("Couldnt save Clan id because file does not exist");
}
}
public static void createPlayer(String uuid){
String path = "plugins/Clans/playerdata/" + uuid + ".json";
String ans = checkFile(path);
if (ans == "not"){
createFile(path);
setClanId(uuid, "0");
}
}
public static void setClanParams(String name, String Clanid, String password, String leaderuuid){
String path = "plugins/Clans/clandata/" + Clanid + ".json";
String ans = checkFile(path);
if (ans == "exists"){
JSONParser jsonParser = new JSONParser();
try {
JSONObject jsonObject = (JSONObject) jsonParser.parse(new FileReader(path));
jsonObject.put("ClanId", Clanid);
jsonObject.put("name", name);
jsonObject.put("password", password);
jsonObject.put("leader", leaderuuid);
FileWriter file = new FileWriter(path);
file.write(jsonObject.toJSONString());
file.close();
System.out.println("Saved ClanParams");
}catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
}else{
System.out.println("Couldnt save ClanParams id because file does not exist");
}
}
public static void saveClanName(String Clanname, String ClanId){
String path = "plugins/Clans/clannames/" + Clanname + ".json";
String ans = checkFile(path);
if (ans == "not"){
createFile(path);
JSONParser jsonParser = new JSONParser();
try {
JSONObject jsonObject = (JSONObject) jsonParser.parse(new FileReader(path));
jsonObject.put("Clanid", ClanId);
FileWriter file = new FileWriter(path);
file.write(jsonObject.toJSONString());
file.close();
System.out.println("Saved Clanid");
}catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
}
}
public static String getClanId(String Clanname){
String path = "plugins/Clans/clannames/" + Clanname + ".json";
String ans = checkFile(path);
if (ans == "exists"){
JSONParser jsonParser = new JSONParser();
try {
JSONObject jsonObject = (JSONObject) jsonParser.parse(new FileReader(path));
String Clanid = (String) jsonObject.get("Clanid");
return Clanid;
}catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
}
return "0";
}
public static String createClan(String name, String password, String leaderuuid){
System.out.println("createclan läuft");
Random rand = new Random();
String Clanid = String.valueOf(rand.nextInt(999999999));
String path1 = "plugins/Clans/clandata/" + Clanid + ".json";
String ans = checkFile(path1);
if (ans == "not"){
String path = "plugins/Clans/clannames/" + name + ".json";
ans = checkFile(path);
if (ans == "not") {
createFile(path1);
setClanParams(name, Clanid, password, leaderuuid);
setClanId(leaderuuid, Clanid);
saveClanName(name, Clanid);
System.out.println("kurz davor done zu returnen");
return "done";
} else {
return "already";
}
}
return "error";
}
public static void createuuidentry(String uuid, String playername){
String path = "plugins/Clans/uuids/" + playername + ".json";
String ans = checkFile(path);
if (ans == "not"){
createFile(path);
JSONParser jsonParser = new JSONParser();
try {
JSONObject jsonObject = (JSONObject) jsonParser.parse(new FileReader(path));
jsonObject.put("uuid", uuid);
FileWriter file = new FileWriter(path);
file.write(jsonObject.toJSONString());
file.close();
System.out.println("Saved UUID");
}catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
}
}
public static String getUUID(String playername){
String path = "plugins/Clans/uuids/" + playername + ".json";
String ans = checkFile(path);
if (ans == "exists"){
JSONParser jsonParser = new JSONParser();
try {
JSONObject jsonObject = (JSONObject) jsonParser.parse(new FileReader(path));
String uuid = (String) jsonObject.get("uuid");
return uuid;
}catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
}
return "ne diggi";
}
}

View File

@@ -0,0 +1,13 @@
name: Clans
version: '${project.version}'
main: de.spaffel.clans.Clans
api-version: 1.18
prefix: Clans by Spaffel
authors: [ Spaffel ]
description: A Simple Clans-Plugin by Spaffel
website: spaffel.de
commands:
test:
newclan:
leaveclan:
joinclan: