Skip to content

Commit 9c6b19c

Browse files
committed
Initial commit
0 parents  commit 9c6b19c

File tree

7 files changed

+296
-0
lines changed

7 files changed

+296
-0
lines changed

.gitignore

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# User-specific stuff
2+
.idea/
3+
4+
*.iml
5+
*.ipr
6+
*.iws
7+
8+
# IntelliJ
9+
out/
10+
11+
# Compiled class file
12+
*.class
13+
14+
# Log file
15+
*.log
16+
17+
# BlueJ files
18+
*.ctxt
19+
20+
# Package Files #
21+
*.jar
22+
*.war
23+
*.nar
24+
*.ear
25+
*.zip
26+
*.tar.gz
27+
*.rar
28+
29+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
30+
hs_err_pid*
31+
32+
*~
33+
34+
# temporary files which can be created if a process still has a handle open of a deleted file
35+
.fuse_hidden*
36+
37+
# KDE directory preferences
38+
.directory
39+
40+
# Linux trash folder which might appear on any partition or disk
41+
.Trash-*
42+
43+
# .nfs files are created when an open file is removed but is still being accessed
44+
.nfs*
45+
46+
# General
47+
.DS_Store
48+
.AppleDouble
49+
.LSOverride
50+
51+
# Icon must end with two \r
52+
Icon
53+
54+
# Thumbnails
55+
._*
56+
57+
# Files that might appear in the root of a volume
58+
.DocumentRevisions-V100
59+
.fseventsd
60+
.Spotlight-V100
61+
.TemporaryItems
62+
.Trashes
63+
.VolumeIcon.icns
64+
.com.apple.timemachine.donotpresent
65+
66+
# Directories potentially created on remote AFP share
67+
.AppleDB
68+
.AppleDesktop
69+
Network Trash Folder
70+
Temporary Items
71+
.apdisk
72+
73+
# Windows thumbnail cache files
74+
Thumbs.db
75+
Thumbs.db:encryptable
76+
ehthumbs.db
77+
ehthumbs_vista.db
78+
79+
# Dump file
80+
*.stackdump
81+
82+
# Folder config file
83+
[Dd]esktop.ini
84+
85+
# Recycle Bin used on file shares
86+
$RECYCLE.BIN/
87+
88+
# Windows Installer files
89+
*.cab
90+
*.msi
91+
*.msix
92+
*.msm
93+
*.msp
94+
95+
# Windows shortcuts
96+
*.lnk
97+
98+
target/
99+
100+
pom.xml.tag
101+
pom.xml.releaseBackup
102+
pom.xml.versionsBackup
103+
pom.xml.next
104+
105+
release.properties
106+
dependency-reduced-pom.xml
107+
buildNumber.properties
108+
.mvn/timing.properties
109+
.mvn/wrapper/maven-wrapper.jar
110+
.flattened-pom.xml
111+
112+
# Common working directory
113+
run/

pom.xml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>in.rs.milivojevic</groupId>
8+
<artifactId>KPManager</artifactId>
9+
<version>1.3-SNAPSHOT</version>
10+
<packaging>jar</packaging>
11+
12+
<name>KPManager</name>
13+
14+
<properties>
15+
<java.version>1.8</java.version>
16+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17+
</properties>
18+
19+
<build>
20+
<plugins>
21+
<plugin>
22+
<groupId>org.apache.maven.plugins</groupId>
23+
<artifactId>maven-compiler-plugin</artifactId>
24+
<version>3.8.1</version>
25+
<configuration>
26+
<source>${java.version}</source>
27+
<target>${java.version}</target>
28+
</configuration>
29+
</plugin>
30+
<plugin>
31+
<groupId>org.apache.maven.plugins</groupId>
32+
<artifactId>maven-shade-plugin</artifactId>
33+
<version>3.2.4</version>
34+
<executions>
35+
<execution>
36+
<phase>package</phase>
37+
<goals>
38+
<goal>shade</goal>
39+
</goals>
40+
<configuration>
41+
<createDependencyReducedPom>false</createDependencyReducedPom>
42+
</configuration>
43+
</execution>
44+
</executions>
45+
</plugin>
46+
</plugins>
47+
<resources>
48+
<resource>
49+
<directory>src/main/resources</directory>
50+
<filtering>true</filtering>
51+
</resource>
52+
</resources>
53+
</build>
54+
55+
<repositories>
56+
<repository>
57+
<id>spigotmc-repo</id>
58+
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
59+
</repository>
60+
<repository>
61+
<id>sonatype</id>
62+
<url>https://oss.sonatype.org/content/groups/public/</url>
63+
</repository>
64+
</repositories>
65+
66+
<dependencies>
67+
<dependency>
68+
<groupId>org.spigotmc</groupId>
69+
<artifactId>spigot-api</artifactId>
70+
<version>1.19.3-R0.1-SNAPSHOT</version>
71+
<scope>provided</scope>
72+
</dependency>
73+
<dependency>
74+
<groupId>com.squareup.okhttp3</groupId>
75+
<artifactId>okhttp</artifactId>
76+
<version>3.14.9</version>
77+
</dependency>
78+
<dependency>
79+
<groupId>org.spigotmc</groupId>
80+
<artifactId>spigot-api</artifactId>
81+
<version>1.13.2-R0.1-SNAPSHOT</version>
82+
</dependency>
83+
<dependency>
84+
<groupId>org.jsoup</groupId>
85+
<artifactId>jsoup</artifactId>
86+
<version>1.14.3</version>
87+
</dependency>
88+
</dependencies>
89+
</project>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package KPManager;
2+
3+
import okhttp3.OkHttpClient;
4+
import okhttp3.Request;
5+
import okhttp3.Response;
6+
import org.bukkit.Bukkit;
7+
import org.bukkit.ChatColor;
8+
import org.bukkit.entity.Player;
9+
import org.bukkit.event.EventHandler;
10+
import org.bukkit.event.Listener;
11+
import org.bukkit.event.player.PlayerJoinEvent;
12+
import org.jsoup.Jsoup;
13+
import org.jsoup.nodes.Document;
14+
import org.jsoup.select.Elements;
15+
16+
import java.io.IOException;
17+
import java.util.Objects;
18+
19+
public final class JoinWelcomer implements Listener {
20+
private final OkHttpClient client = new OkHttpClient();
21+
private final String messagePlayer = ChatColor.AQUA + "Welcome " + ChatColor.GREEN + "{playerName}" + ChatColor.AQUA + " to my server! " + ChatColor.GREEN + "Enjoy your stay!";
22+
private final String messageEveryone = ChatColor.AQUA + "{playerName} joined from " + ChatColor.GREEN + "{country}.";
23+
24+
private String parseCountry(String xml) {
25+
Document doc = Jsoup.parse(xml, "", org.jsoup.parser.Parser.xmlParser());
26+
Elements elements = doc.select("country_name");
27+
return elements.text();
28+
}
29+
30+
@EventHandler
31+
public void onPlayerJoin(PlayerJoinEvent event) {
32+
Player player = event.getPlayer();
33+
String playerIP = Objects.requireNonNull(player.getAddress()).getAddress().getHostAddress();
34+
35+
Request requestIp;
36+
requestIp = new Request.Builder().url("https://ipapi.co/" + playerIP + "/xml/").build();
37+
38+
player.sendMessage(messagePlayer.replace("{playerName}", player.getName()));
39+
40+
try (Response response = client.newCall(requestIp).execute()) {
41+
assert response.body() != null;
42+
String body = response.body().string();
43+
String country = parseCountry(body);
44+
if (country != null && !country.isEmpty()) {
45+
Bukkit.broadcastMessage(messageEveryone.replace("{playerName}", player.getName()).replace("{country}", country));
46+
}
47+
} catch (IOException e) {
48+
e.printStackTrace();
49+
}
50+
}
51+
}
52+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package KPManager;
2+
3+
public final class LoginManager {
4+
5+
}
6+

src/main/java/KPManager/Main.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package KPManager;
2+
3+
import org.bukkit.Bukkit;
4+
import org.bukkit.ChatColor;
5+
import org.bukkit.event.Listener;
6+
import org.bukkit.plugin.java.JavaPlugin;
7+
8+
public final class Main extends JavaPlugin implements Listener {
9+
10+
@Override
11+
public void onEnable() {
12+
getLogger().info(ChatColor.translateAlternateColorCodes('&', "&bStarting!"));
13+
getLogger().info(ChatColor.translateAlternateColorCodes('&', "&bThis plugin is made by Kamey_"));
14+
Bukkit.getServer().getPluginManager().registerEvents(new JoinWelcomer(), this);
15+
}
16+
17+
18+
@Override
19+
public void onDisable() {
20+
Bukkit.getServer().getPluginManager().disablePlugin(this);
21+
}
22+
}

src/main/resources/config.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
language:
2+
prefix: '&2[KPManager]'
3+
spawn-set: '&aSpawn set!'
4+
error: '&cThere was an error, please do: /setjoinspawn'
5+
no-permission: '&cNo Permission'
6+
not-a-player: '&cOnly Players can run these commands!'
7+
spawn-not-set: '&bThe spawn point is not set, to set spawn do: /setjoinspawn'
8+
teleporting: '&bTeleporting...'

src/main/resources/plugin.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name: KPManager
2+
api-version: 1.19
3+
version: 1.3
4+
main: in.rs.milivojevic.welcomerbykamey.Main
5+
author: Kamey_
6+
description: This plugin displays a welcome message to players when they join the server, including their name.

0 commit comments

Comments
 (0)