Skip to content

Commit 7f97fd0

Browse files
authored
Add files via upload
1 parent 4f46699 commit 7f97fd0

File tree

5 files changed

+194
-0
lines changed

5 files changed

+194
-0
lines changed

advancedcommands.iml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module version="4">
3+
<component name="FacetManager">
4+
<facet type="minecraft" name="Minecraft">
5+
<configuration>
6+
<autoDetectTypes>
7+
<platformType>SPIGOT</platformType>
8+
</autoDetectTypes>
9+
</configuration>
10+
</facet>
11+
</component>
12+
</module>

pom.xml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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>iumproject</groupId>
8+
<artifactId>advancedcommands</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
<packaging>jar</packaging>
11+
12+
<name>advancedcommands</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+
<repository>
65+
<id>jitpack.io</id>
66+
<url>https://jitpack.io</url>
67+
</repository>
68+
</repositories>
69+
70+
<dependencies>
71+
<dependency>
72+
<groupId>com.github.Revxrsal.Lamp</groupId>
73+
<artifactId>common</artifactId>
74+
<version>3.1.5</version>
75+
</dependency>
76+
<dependency>
77+
<groupId>org.spigotmc</groupId>
78+
<artifactId>spigot-api</artifactId>
79+
<version>1.19.2-R0.1-SNAPSHOT</version>
80+
<scope>provided</scope>
81+
</dependency>
82+
</dependencies>
83+
</project>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package iumproject.advancedcommands;
2+
3+
import org.bukkit.configuration.ConfigurationSection;
4+
import org.bukkit.configuration.file.FileConfiguration;
5+
import org.bukkit.configuration.file.YamlConfiguration;
6+
import org.bukkit.entity.Player;
7+
import org.bukkit.event.EventHandler;
8+
import org.bukkit.event.Listener;
9+
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
10+
import org.bukkit.plugin.java.JavaPlugin;
11+
12+
import java.io.File;
13+
import java.util.HashMap;
14+
import java.util.List;
15+
import java.util.Map;
16+
17+
public final class Advancedcommands extends JavaPlugin implements Listener {
18+
private FileConfiguration config;
19+
private Map<String, ConfigurationSection> commandMap;
20+
21+
@Override
22+
public void onEnable() {
23+
commandMap = new HashMap<>();
24+
loadConfig();
25+
getServer().getPluginManager().registerEvents(this, this);
26+
}
27+
28+
private void loadConfig() {
29+
File configFile = new File(getDataFolder(), "config.yml");
30+
if (!configFile.exists()) {
31+
saveResource("config.yml", false);
32+
}
33+
34+
config = YamlConfiguration.loadConfiguration(configFile);
35+
ConfigurationSection commandsSection = config.getConfigurationSection("commands");
36+
if (commandsSection != null) {
37+
for (String key : commandsSection.getKeys(false)) {
38+
ConfigurationSection section = commandsSection.getConfigurationSection(key);
39+
commandMap.put(section.getString("name"), section);
40+
}
41+
}
42+
43+
}
44+
45+
@EventHandler
46+
private void onCommand(PlayerCommandPreprocessEvent event) {
47+
String[] message = event.getMessage().split(" ");
48+
String command = message[0].substring(1);
49+
Player player = event.getPlayer();
50+
ConfigurationSection section = commandMap.get(command);
51+
if (section != null) {
52+
String permissions = section.getString("permissions", "iumadvancedCommands");
53+
String sendMessage = section.getString("message");
54+
String permError = section.getString("error_message", "Bu komutu kullanmak için yetkiniz bulunmuyor.");
55+
List<String> commands = section.getStringList("commands");
56+
boolean useConsole = section.getBoolean("usedConsole", false);
57+
if (!player.hasPermission(permissions)) player.sendMessage(permError);
58+
else {
59+
if (message != null) player.sendMessage(sendMessage);
60+
commands.forEach(cmd -> {
61+
cmd = cmd.replace("%player%", player.getName());
62+
if (useConsole) {
63+
getServer().dispatchCommand(getServer().getConsoleSender(), cmd);
64+
} else {
65+
player.performCommand(cmd);
66+
}
67+
});
68+
}
69+
}
70+
event.setCancelled(true);
71+
}
72+
73+
@Override
74+
public void onDisable() {
75+
// Plugin shutdown logic
76+
}
77+
}

src/main/resources/config.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
commands:
2+
1:
3+
name: "test"
4+
permissions: "test.permission"
5+
error_message: "Permission Error!"
6+
message: "hello world!"
7+
commands:
8+
- "give %player% diamond 1"
9+
usedConsole: true
10+
2:
11+
name: "test2"
12+
permissions: "test.permission2"
13+
error_message: "Permission Error!"
14+
message: "hello world!"
15+
commands:
16+
- "give %player% diamond 2"
17+
usedConsole: true

src/main/resources/plugin.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name: advancedcommands
2+
version: '${project.version}'
3+
main: iumproject.advancedcommands.Advancedcommands
4+
api-version: '1.19'
5+
author: iamnullman

0 commit comments

Comments
 (0)