mirror of
https://github.com/ApfelTeeSaft/JailPlugin.git
synced 2026-08-26 19:23:38 +00:00
Initial Commit
This commit is contained in:
+38
@@ -0,0 +1,38 @@
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/libraries/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
||||
Generated
+3
@@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
Generated
+7
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DiscordProjectSettings">
|
||||
<option name="show" value="PROJECT_FILES" />
|
||||
<option name="description" value="" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+7
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+14
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_22" default="true" project-jdk-name="22" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,67 @@
|
||||
<?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>com.example</groupId>
|
||||
<artifactId>jailplugin</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>papermc</id>
|
||||
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.21.4-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<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>
|
||||
</project>
|
||||
@@ -0,0 +1,238 @@
|
||||
package com.example.jailplugin;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class JailPlugin extends JavaPlugin {
|
||||
private Location jailLocation;
|
||||
private Location unjailLocation;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
saveDefaultConfig();
|
||||
loadLocations();
|
||||
getLogger().info("JailPlugin has been enabled!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
saveLocations();
|
||||
getLogger().info("JailPlugin has been disabled!");
|
||||
}
|
||||
|
||||
private void loadLocations() {
|
||||
if (getConfig().contains("jail")) {
|
||||
World world = getServer().getWorld(getConfig().getString("jail.world"));
|
||||
double x = getConfig().getDouble("jail.x");
|
||||
double y = getConfig().getDouble("jail.y");
|
||||
double z = getConfig().getDouble("jail.z");
|
||||
float yaw = (float) getConfig().getDouble("jail.yaw");
|
||||
float pitch = (float) getConfig().getDouble("jail.pitch");
|
||||
jailLocation = new Location(world, x, y, z, yaw, pitch);
|
||||
}
|
||||
|
||||
if (getConfig().contains("unjail")) {
|
||||
World world = getServer().getWorld(getConfig().getString("unjail.world"));
|
||||
double x = getConfig().getDouble("unjail.x");
|
||||
double y = getConfig().getDouble("unjail.y");
|
||||
double z = getConfig().getDouble("unjail.z");
|
||||
float yaw = (float) getConfig().getDouble("unjail.yaw");
|
||||
float pitch = (float) getConfig().getDouble("unjail.pitch");
|
||||
unjailLocation = new Location(world, x, y, z, yaw, pitch);
|
||||
}
|
||||
}
|
||||
|
||||
private void saveLocations() {
|
||||
if (jailLocation != null) {
|
||||
getConfig().set("jail.world", jailLocation.getWorld().getName());
|
||||
getConfig().set("jail.x", jailLocation.getX());
|
||||
getConfig().set("jail.y", jailLocation.getY());
|
||||
getConfig().set("jail.z", jailLocation.getZ());
|
||||
getConfig().set("jail.yaw", jailLocation.getYaw());
|
||||
getConfig().set("jail.pitch", jailLocation.getPitch());
|
||||
}
|
||||
|
||||
if (unjailLocation != null) {
|
||||
getConfig().set("unjail.world", unjailLocation.getWorld().getName());
|
||||
getConfig().set("unjail.x", unjailLocation.getX());
|
||||
getConfig().set("unjail.y", unjailLocation.getY());
|
||||
getConfig().set("unjail.z", unjailLocation.getZ());
|
||||
getConfig().set("unjail.yaw", unjailLocation.getYaw());
|
||||
getConfig().set("unjail.pitch", unjailLocation.getPitch());
|
||||
}
|
||||
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
switch (cmd.getName().toLowerCase()) {
|
||||
case "setjail":
|
||||
return handleSetJail(sender, args);
|
||||
case "setunjail":
|
||||
return handleSetUnjail(sender, args);
|
||||
case "jail":
|
||||
return handleJail(sender, args);
|
||||
case "unjail":
|
||||
return handleUnjail(sender, args);
|
||||
case "jailreload":
|
||||
return handleReload(sender);
|
||||
case "jailhelp":
|
||||
return handleHelp(sender);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean handleSetJail(CommandSender sender, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.RED + "This command can only be used by players!");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) sender;
|
||||
if (!player.hasPermission("jailplugin.setjail")) {
|
||||
player.sendMessage(ChatColor.RED + "You don't have permission to use this command!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 3) {
|
||||
try {
|
||||
double x = Double.parseDouble(args[0]);
|
||||
double y = Double.parseDouble(args[1]);
|
||||
double z = Double.parseDouble(args[2]);
|
||||
jailLocation = new Location(player.getWorld(), x, y, z);
|
||||
} catch (NumberFormatException e) {
|
||||
player.sendMessage(ChatColor.RED + "Invalid coordinates! Use: /setjail <x> <y> <z>");
|
||||
return true;
|
||||
}
|
||||
} else if (args.length == 0) {
|
||||
jailLocation = player.getLocation();
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED + "Usage: /setjail or /setjail <x> <y> <z>");
|
||||
return true;
|
||||
}
|
||||
|
||||
saveLocations();
|
||||
player.sendMessage(ChatColor.GREEN + "Jail location has been set!");
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean handleSetUnjail(CommandSender sender, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.RED + "This command can only be used by players!");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) sender;
|
||||
if (!player.hasPermission("jailplugin.setunjail")) {
|
||||
player.sendMessage(ChatColor.RED + "You don't have permission to use this command!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 3) {
|
||||
try {
|
||||
double x = Double.parseDouble(args[0]);
|
||||
double y = Double.parseDouble(args[1]);
|
||||
double z = Double.parseDouble(args[2]);
|
||||
unjailLocation = new Location(player.getWorld(), x, y, z);
|
||||
} catch (NumberFormatException e) {
|
||||
player.sendMessage(ChatColor.RED + "Invalid coordinates! Use: /setunjail <x> <y> <z>");
|
||||
return true;
|
||||
}
|
||||
} else if (args.length == 0) {
|
||||
unjailLocation = player.getLocation();
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED + "Usage: /setunjail or /setunjail <x> <y> <z>");
|
||||
return true;
|
||||
}
|
||||
|
||||
saveLocations();
|
||||
player.sendMessage(ChatColor.GREEN + "Unjail location has been set!");
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean handleJail(CommandSender sender, String[] args) {
|
||||
if (!sender.hasPermission("jailplugin.jail")) {
|
||||
sender.sendMessage(ChatColor.RED + "You don't have permission to use this command!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (jailLocation == null) {
|
||||
sender.sendMessage(ChatColor.RED + "Jail location has not been set! Use /setjail first.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length != 1) {
|
||||
sender.sendMessage(ChatColor.RED + "Usage: /jail <player>");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player target = getServer().getPlayer(args[0]);
|
||||
if (target == null) {
|
||||
sender.sendMessage(ChatColor.RED + "Player not found!");
|
||||
return true;
|
||||
}
|
||||
|
||||
target.teleport(jailLocation);
|
||||
target.sendMessage(ChatColor.RED + "You have been jailed!");
|
||||
sender.sendMessage(ChatColor.GREEN + "Player " + target.getName() + " has been jailed!");
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean handleUnjail(CommandSender sender, String[] args) {
|
||||
if (!sender.hasPermission("jailplugin.unjail")) {
|
||||
sender.sendMessage(ChatColor.RED + "You don't have permission to use this command!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (unjailLocation == null) {
|
||||
sender.sendMessage(ChatColor.RED + "Unjail location has not been set! Use /setunjail first.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length != 1) {
|
||||
sender.sendMessage(ChatColor.RED + "Usage: /unjail <player>");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player target = getServer().getPlayer(args[0]);
|
||||
if (target == null) {
|
||||
sender.sendMessage(ChatColor.RED + "Player not found!");
|
||||
return true;
|
||||
}
|
||||
|
||||
target.teleport(unjailLocation);
|
||||
target.sendMessage(ChatColor.GREEN + "You have been released from jail!");
|
||||
sender.sendMessage(ChatColor.GREEN + "Player " + target.getName() + " has been released from jail!");
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean handleReload(CommandSender sender) {
|
||||
if (!sender.hasPermission("jailplugin.reload")) {
|
||||
sender.sendMessage(ChatColor.RED + "You don't have permission to reload the configuration!");
|
||||
return true;
|
||||
}
|
||||
|
||||
reloadConfig();
|
||||
loadLocations();
|
||||
sender.sendMessage(ChatColor.GREEN + "JailPlugin configuration reloaded!");
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean handleHelp(CommandSender sender) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "JailPlugin Commands:");
|
||||
sender.sendMessage(ChatColor.GREEN + "/setjail [x y z]" + ChatColor.WHITE + " - Set the jail location.");
|
||||
sender.sendMessage(ChatColor.GREEN + "/setunjail [x y z]" + ChatColor.WHITE + " - Set the unjail location.");
|
||||
sender.sendMessage(ChatColor.GREEN + "/jail <player>" + ChatColor.WHITE + " - Jail a player.");
|
||||
sender.sendMessage(ChatColor.GREEN + "/unjail <player>" + ChatColor.WHITE + " - Unjail a player.");
|
||||
sender.sendMessage(ChatColor.GREEN + "/jailreload" + ChatColor.WHITE + " - Reload the plugin configuration.");
|
||||
sender.sendMessage(ChatColor.GREEN + "/jailhelp" + ChatColor.WHITE + " - Show this help message.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
jail:
|
||||
world: world
|
||||
x: 0.0
|
||||
y: 64.0
|
||||
z: 0.0
|
||||
yaw: 0.0
|
||||
pitch: 0.0
|
||||
|
||||
unjail:
|
||||
world: world
|
||||
x: 0.0
|
||||
y: 64.0
|
||||
z: 0.0
|
||||
yaw: 0.0
|
||||
pitch: 0.0
|
||||
@@ -0,0 +1,45 @@
|
||||
name: JailPlugin
|
||||
version: '1.0'
|
||||
main: com.example.jailplugin.JailPlugin
|
||||
api-version: '1.21'
|
||||
commands:
|
||||
setjail:
|
||||
description: Set the jail location
|
||||
usage: /<command> [x y z]
|
||||
permission: jailplugin.setjail
|
||||
setunjail:
|
||||
description: Set the unjail location
|
||||
usage: /<command> [x y z]
|
||||
permission: jailplugin.setunjail
|
||||
jail:
|
||||
description: Teleport a player to jail
|
||||
usage: /<command> <player>
|
||||
permission: jailplugin.jail
|
||||
unjail:
|
||||
description: Release a player from jail
|
||||
usage: /<command> <player>
|
||||
permission: jailplugin.unjail
|
||||
jailreload:
|
||||
description: Reload the JailPlugin configuration
|
||||
usage: /<command>
|
||||
permission: jailplugin.reload
|
||||
jailhelp:
|
||||
description: Display help for JailPlugin commands
|
||||
usage: /<command>
|
||||
|
||||
permissions:
|
||||
jailplugin.setjail:
|
||||
description: Allows setting the jail location
|
||||
default: op
|
||||
jailplugin.setunjail:
|
||||
description: Allows setting the unjail location
|
||||
default: op
|
||||
jailplugin.jail:
|
||||
description: Allows jailing other players
|
||||
default: op
|
||||
jailplugin.unjail:
|
||||
description: Allows releasing players from jail
|
||||
default: op
|
||||
jailplugin.reload:
|
||||
description: Allows reloading the plugin configuration
|
||||
default: op
|
||||
Reference in New Issue
Block a user