Initial commit
This commit is contained in:
commit
818ab95078
23 files changed
+498
No files matched your search
@@ -0,0 +1,2 @@
|
||||
# Auto detect text files and perform LF normalization
|
||||
* text=auto
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# 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*
|
||||
replay_pid*
|
||||
Generated
+3
@@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
Generated
+8
@@ -0,0 +1,8 @@
|
||||
<component name="ArtifactManager">
|
||||
<artifact type="jar" name="SpawnTP">
|
||||
<output-path>$PROJECT_DIR$/out/artifacts/SpawnTP</output-path>
|
||||
<root id="archive" name="SpawnTP.jar">
|
||||
<element id="module-output" name="SpawnTP" />
|
||||
</root>
|
||||
</artifact>
|
||||
</component>
|
||||
Generated
+14
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile default="true" name="Default" enabled="true" />
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="SpawnTP" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
||||
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
+35
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="OnARandomBox" />
|
||||
<option name="name" value="OnARandomBox" />
|
||||
<option name="url" value="https://repo.onarandombox.com/content/groups/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="papermc-repo" />
|
||||
<option name="name" value="papermc-repo" />
|
||||
<option name="url" value="https://repo.papermc.io/repository/maven-public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="parzival-space" />
|
||||
<option name="name" value="parzival-space" />
|
||||
<option name="url" value="https://nexus.parzival.space/repository/maven-public/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
||||
Generated
+17
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="EntryPointsManager">
|
||||
<list size="1">
|
||||
<item index="0" class="java.lang.String" itemvalue="org.bukkit.event.EventHandler" />
|
||||
</list>
|
||||
</component>
|
||||
<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_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK" />
|
||||
</project>
|
||||
Generated
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/SpawnTP.iml" filepath="$PROJECT_DIR$/SpawnTP.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 I Putu Ananda Kasuma
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="minecraft" name="Minecraft">
|
||||
<configuration>
|
||||
<autoDetectTypes>
|
||||
<platformType>PAPER</platformType>
|
||||
<platformType>ADVENTURE</platformType>
|
||||
</autoDetectTypes>
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
</module>
|
||||
@@ -0,0 +1,77 @@
|
||||
<?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>net.kasumadps.spawntp</groupId>
|
||||
<artifactId>SpawnTP</artifactId>
|
||||
<version>latest</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>SpawnTP</name>
|
||||
<description>A Minecraft Plugin simplifies teleporting to the spawn location.</description>
|
||||
<url>https://github.com/kasumabalidps</url>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>./src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<!-- Paper Api -->
|
||||
<dependency>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.19.3-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.26</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<repositories>
|
||||
<!-- https://nexus.parzival.space/ -->
|
||||
<repository>
|
||||
<id>parzival-space</id>
|
||||
<url>https://nexus.parzival.space/repository/maven-public/</url>
|
||||
</repository>
|
||||
<!-- https://repo.onarandombox.com/ -->
|
||||
<repository>
|
||||
<id>OnARandomBox</id>
|
||||
<url>https://repo.onarandombox.com/content/groups/public/</url>
|
||||
</repository>
|
||||
<!-- https://repo.papermc.io/ -->
|
||||
<repository>
|
||||
<id>papermc-repo</id>
|
||||
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>parzival-space</id>
|
||||
<url>https://nexus.parzival.space/repository/maven-releases/</url>
|
||||
</repository>
|
||||
<snapshotRepository>
|
||||
<id>parzival-space</id>
|
||||
<url>https://nexus.parzival.space/repository/maven-snapshots/</url>
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
</project>
|
||||
@@ -0,0 +1,33 @@
|
||||
package net.kasumadps.spawntp;
|
||||
|
||||
import net.kasumadps.spawntp.commands.SpawnCommand;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.kasumadps.spawntp.commands.SetSpawnCommand;
|
||||
|
||||
@Slf4j
|
||||
public final class SpawnTP extends JavaPlugin implements Listener {
|
||||
@Getter
|
||||
private static SpawnTP instance;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
|
||||
saveDefaultConfig();
|
||||
|
||||
getCommand("spawn").setPermission("spawntp.teleport");
|
||||
getCommand("spawn").setExecutor(new SpawnCommand());
|
||||
|
||||
getCommand("setspawn").setPermission("spawntp.admin");
|
||||
getCommand("setspawn").setExecutor(new SetSpawnCommand());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
log.info("Plugin disabled.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package net.kasumadps.spawntp.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.management.openmbean.InvalidOpenTypeException;
|
||||
|
||||
import net.kasumadps.spawntp.SpawnTP;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class SetSpawnCommand implements CommandExecutor, TabCompleter {
|
||||
private final JavaPlugin plugin = SpawnTP.getInstance();
|
||||
private final FileConfiguration config = this.plugin.getConfig();
|
||||
|
||||
private static String locationPath = "general.location";
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String commandLabel, @NotNull String[] args) {
|
||||
// only allow commands from players
|
||||
if (!(sender instanceof Player)) return false;
|
||||
Player player = (Player) sender;
|
||||
List<String> argsList = Arrays.asList(args);
|
||||
|
||||
// permission check
|
||||
if (!player.hasPermission(command.getPermission())) {
|
||||
player.sendMessage(this.config.getString("locale.missingPermission", "You are lacking the required permissions."));
|
||||
return true;
|
||||
}
|
||||
|
||||
// if unset
|
||||
if (argsList.contains("unset")) { // NOSONAR - intended
|
||||
this.config.set(locationPath, null);
|
||||
this.plugin.saveConfig();
|
||||
player.sendMessage(this.config.getString("locale.spawnSet", "Spawn location updated."));
|
||||
return true;
|
||||
}
|
||||
|
||||
// get location
|
||||
Location location = player.getLocation();
|
||||
|
||||
// normalize view if necessary
|
||||
if (argsList.contains("normalize-view")) {
|
||||
location.setYaw((float)this.getClosestDegree(location.getYaw(), new double[] { -180, -90, 0, 90, 180 }));
|
||||
location.setPitch((float)this.getClosestDegree(location.getPitch(), new double[] { -180, -90, 0, 90, 180 }));
|
||||
}
|
||||
|
||||
// normalize position if necessary
|
||||
if (argsList.contains("normalize-position")) {
|
||||
location.setX(location.getX() > location.blockX() ? location.blockX() + .5 : location.blockX() - .5);
|
||||
location.setZ(location.getZ() > location.blockZ() ? location.blockZ() + .5 : location.blockZ() - .5);
|
||||
location.setY(location.blockY()); // no normalizing needed
|
||||
}
|
||||
|
||||
// store location
|
||||
this.config.set(locationPath, location);
|
||||
this.plugin.saveConfig();
|
||||
player.sendMessage(this.config.getString("locale.spawnSet", "Spawn location updated."));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String commandLabel, @NotNull String[] args) {
|
||||
List<String> completes = new ArrayList<>();
|
||||
List<String> argsList = Arrays.asList(args);
|
||||
|
||||
if (argsList.contains("unset")) return completes;
|
||||
|
||||
completes.add("normalize-view");
|
||||
completes.add("normalize-position");
|
||||
completes.add("unset");
|
||||
|
||||
return completes.stream().filter(c -> !argsList.contains(c)).toList();
|
||||
}
|
||||
|
||||
private double getClosestDegree(double degree, double[] possibleDegrees) {
|
||||
if (possibleDegrees.length == 0) throw new InvalidOpenTypeException("You need to specify at least one possible degree");
|
||||
|
||||
return Arrays.stream(possibleDegrees).boxed()
|
||||
.min(Comparator.comparing(d -> Math.abs(d - degree)))
|
||||
.orElse(possibleDegrees[0]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package net.kasumadps.spawntp.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import net.kasumadps.spawntp.SpawnTP;
|
||||
|
||||
public class SpawnCommand implements CommandExecutor, TabCompleter {
|
||||
private final FileConfiguration config = SpawnTP.getInstance().getConfig();
|
||||
|
||||
private static String locationPath = "general.location";
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String commandLabel, @NotNull String[] args) {
|
||||
// only allow commands from players
|
||||
if (!(sender instanceof Player)) return false;
|
||||
Player player = (Player) sender;
|
||||
|
||||
// permission check
|
||||
if (!player.hasPermission(command.getPermission())) {
|
||||
player.sendMessage(this.config.getString("locale.missingPermission", "You are lacking the required permissions."));
|
||||
return true;
|
||||
}
|
||||
|
||||
// get location
|
||||
Location location = this.config.getLocation(locationPath);
|
||||
if (location == null) {
|
||||
player.sendMessage(this.config.getString("locale.spawnNotSet", "Server spawn not set."));
|
||||
return true;
|
||||
}
|
||||
|
||||
// teleport
|
||||
player.teleport(location, TeleportCause.COMMAND);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String commandLabel, @NotNull String[] args) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
general:
|
||||
location:
|
||||
|
||||
locale:
|
||||
missingPermission: "You dont have required permission"
|
||||
spawnNotSet: "Spawn not set"
|
||||
spawnSet: "Spawn location set-up."
|
||||
@@ -0,0 +1,31 @@
|
||||
name: SpawnTP
|
||||
description: A Minecraft Plugin simplifies teleporting to the spawn location.
|
||||
version: '${project.version}'
|
||||
|
||||
author: kasumabalidps
|
||||
website: https://github.com/kasumabalidps
|
||||
|
||||
main: net.kasumadps.spawntp.SpawnTP
|
||||
api-version: 1.19
|
||||
|
||||
commands:
|
||||
spawn:
|
||||
description: Teleport to the Server spawn.
|
||||
usage: /spawn
|
||||
setspawn:
|
||||
description: Set/Unset the Server spawn.
|
||||
usage: /setspawn [ unset, [ normalize-view, normalize-position ]]
|
||||
|
||||
permissions:
|
||||
spawntp.*:
|
||||
description: Gives full access to the plugin.
|
||||
default: op;
|
||||
children:
|
||||
spawntp.teleport: true
|
||||
spawntp.admin: true
|
||||
spawntp.teleport:
|
||||
description: Teleport to the Server spawn.
|
||||
default: true
|
||||
spawntp.admin:
|
||||
description: Set the Server spawn.
|
||||
default: op
|
||||
@@ -0,0 +1,7 @@
|
||||
general:
|
||||
location:
|
||||
|
||||
locale:
|
||||
missingPermission: "You dont have required permission"
|
||||
spawnNotSet: "Spawn not set"
|
||||
spawnSet: "Spawn location set-up."
|
||||
@@ -0,0 +1,31 @@
|
||||
name: SpawnTP
|
||||
description: A Minecraft Plugin simplifies teleporting to the spawn location.
|
||||
version: 'latest'
|
||||
|
||||
author: kasumabalidps
|
||||
website: https://github.com/kasumabalidps
|
||||
|
||||
main: net.kasumadps.spawntp.SpawnTP
|
||||
api-version: 1.19
|
||||
|
||||
commands:
|
||||
spawn:
|
||||
description: Teleport to the Server spawn.
|
||||
usage: /spawn
|
||||
setspawn:
|
||||
description: Set/Unset the Server spawn.
|
||||
usage: /setspawn [ unset, [ normalize-view, normalize-position ]]
|
||||
|
||||
permissions:
|
||||
spawntp.*:
|
||||
description: Gives full access to the plugin.
|
||||
default: op;
|
||||
children:
|
||||
spawntp.teleport: true
|
||||
spawntp.admin: true
|
||||
spawntp.teleport:
|
||||
description: Teleport to the Server spawn.
|
||||
default: true
|
||||
spawntp.admin:
|
||||
description: Set the Server spawn.
|
||||
default: op
|
||||
@@ -0,0 +1,5 @@
|
||||
#Generated by Maven
|
||||
#Sat Jun 24 21:17:16 SGT 2023
|
||||
groupId=net.kasumadps.spawntp
|
||||
artifactId=SpawnTP
|
||||
version=latest
|
||||
Whitespace-only changes.
@@ -0,0 +1,3 @@
|
||||
C:\Users\panda\OneDrive\Desktop\SpawnTP\src\main\java\net\kasumadps\spawntp\commands\SpawnCommand.java
|
||||
C:\Users\panda\OneDrive\Desktop\SpawnTP\src\main\java\net\kasumadps\spawntp\SpawnTP.java
|
||||
C:\Users\panda\OneDrive\Desktop\SpawnTP\src\main\java\net\kasumadps\spawntp\commands\SetSpawnCommand.java
|
||||
Reference in new issue
Block a user