Switch to Kotlin, Gradle and Stickynote by Syrent

This commit is contained in:
2025-04-08 20:51:51 -07:00
parent 896ac716b9
commit df4243b7df
48 changed files with 1069 additions and 770 deletions

30
.gitignore vendored
View File

@@ -7,6 +7,11 @@
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Compiled class file
*.class
@@ -95,19 +100,22 @@ $RECYCLE.BIN/
# Windows shortcuts
*.lnk
target/
.gradle
build/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
# Ignore Gradle GUI config
gradle-app.setting
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar
.flattened-pom.xml
# Cache of project
.gradletasknamecache
**/build/
# Common working directory
run/
runs/
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar
bin/

View File

@@ -1,6 +1,6 @@
MIT License
Copyright (c) 2024 Lncvrt
Copyright (c) 2025 Lncvrt
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

5
README.md Normal file
View File

@@ -0,0 +1,5 @@
# GalaxyTab
Static MiniMessage based tablist plugin for servers like Auth and Limbo in Galaxy Network!
Placeholders are now supported, you can choose to enable or disable that though

108
build.gradle.kts Normal file
View File

@@ -0,0 +1,108 @@
import org.sayandev.plugin.StickyNoteModules
plugins {
java
kotlin("jvm") version "2.1.20"
id("xyz.jpenilla.run-paper") version "2.3.1"
id("de.eldoria.plugin-yml.bukkit") version "0.7.1"
id("org.sayandev.stickynote.project")
}
val slug = rootProject.name.lowercase()
group = "xyz.lncvrt"
version = "1.0.0"
stickynote {
modules(StickyNoteModules.BUKKIT)
}
repositories {
mavenCentral()
mavenLocal()
maven("https://repo.sayandev.org/snapshots")
maven("https://repo.sayandev.org/releases")
maven("https://repo.sayandev.org/private")
maven("https://repo.extendedclip.com/releases/")
maven("https://jitpack.io")
maven("https://ci.frostcast.net/plugin/repository/everything")
}
dependencies {
compileOnly("io.papermc.paper:paper-api:1.21.4-R0.1-SNAPSHOT")
compileOnly("me.clip:placeholderapi:2.11.6")
compileOnly("com.github.booksaw:BetterTeams:4.11.0")
compileOnly("me.confuser.banmanager:BanManagerCommon:7.9.0")
}
tasks {
jar {
manifest {
attributes["paperweight-mappings-namespace"] = "mojang"
}
}
shadowJar {
archiveFileName.set("${rootProject.name}-${version}.jar")
archiveClassifier.set(null as String?)
destinationDirectory.set(file(rootProject.projectDir.path + "/bin"))
manifest {
attributes["paperweight-mappings-namespace"] = "mojang"
}
}
runServer {
minecraftVersion("1.21.4")
jvmArgs()
}
compileJava {
options.encoding = Charsets.UTF_8.name()
}
configurations {
create("compileOnlyApiResolved") {
isCanBeResolved = true
extendsFrom(configurations.getByName("compileOnlyApi"))
}
}
build {
dependsOn(shadowJar)
}
processResources {
filesMatching(listOf("**plugin.yml", "**plugin.json")) {
expand(
"version" to project.version as String,
"slug" to slug,
"name" to rootProject.name,
"description" to project.description
)
}
}
}
bukkit {
main = "$group.${slug}.${rootProject.name}Plugin"
version = rootProject.version.toString()
website = "lncvrt.xyz"
apiVersion = "1.13"
depend = listOf()
authors = listOf("Lncvrt")
prefix = rootProject.name
}
java {
disableAutoTargetJvm()
if (gradle.startParameter.getTaskNames().any { it.startsWith("runServer") || it.startsWith("runFolia") || it.startsWith("runVelocity") }) {
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
} else {
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
}
}

BIN
gradle/wrapper/gradle-wrapper.jar vendored Normal file

Binary file not shown.

View File

@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

251
gradlew vendored Normal file
View File

@@ -0,0 +1,251 @@
#!/bin/sh
#
# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#
##############################################################################
#
# Gradle start up script for POSIX generated by Gradle.
#
# Important for running:
#
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
# noncompliant, but you have some other compliant shell such as ksh or
# bash, then to run this script, type that shell name before the whole
# command line, like:
#
# ksh Gradle
#
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
# (2) This script targets any POSIX shell, so it avoids extensions provided
# by Bash, Ksh, etc; in particular arrays are avoided.
#
# The "traditional" practice of packing multiple parameters into a
# space-separated string is a well documented source of bugs and security
# problems, so this is (mostly) avoided, by progressively accumulating
# options in "$@", and eventually passing that to Java.
#
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
# see the in-line comments for details.
#
# There are tweaks for specific operating systems such as AIX, CygWin,
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
#
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
app_path=$0
# Need this for daisy-chained symlinks.
while
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
[ -h "$app_path" ]
do
ls=$( ls -ld "$app_path" )
link=${ls#*' -> '}
case $link in #(
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
warn () {
echo "$*"
} >&2
die () {
echo
echo "$*"
echo
exit 1
} >&2
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "$( uname )" in #(
CYGWIN* ) cygwin=true ;; #(
Darwin* ) darwin=true ;; #(
MSYS* | MINGW* ) msys=true ;; #(
NONSTOP* ) nonstop=true ;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD=$JAVA_HOME/jre/sh/java
else
JAVACMD=$JAVA_HOME/bin/java
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD=java
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
fi
# Collect all arguments for the java command, stacking in reverse order:
# * args from the command line
# * the main class name
# * -classpath
# * -D...appname settings
# * --module-path (only if needed)
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
JAVACMD=$( cygpath --unix "$JAVACMD" )
# Now convert the arguments - kludge to limit ourselves to /bin/sh
for arg do
if
case $arg in #(
-*) false ;; # don't mess with options #(
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
[ -e "$t" ] ;; #(
*) false ;;
esac
then
arg=$( cygpath --path --ignore --mixed "$arg" )
fi
# Roll the args list around exactly as many times as the number of
# args, so each arg winds up back in the position where it started, but
# possibly modified.
#
# NB: a `for` loop captures its iteration list before it begins, so
# changing the positional parameters here affects neither the number of
# iterations, nor the values presented in `arg`.
shift # remove old arg
set -- "$@" "$arg" # push replacement arg
done
fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
"$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
#
# In Bash we could simply go:
#
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
# set -- "${ARGS[@]}" "$@"
#
# but POSIX shell has neither arrays nor command substitution, so instead we
# post-process each arg (as a line of input to sed) to backslash-escape any
# character that might be a shell metacharacter, then use eval to reverse
# that process (while maintaining the separation between arguments), and wrap
# the whole thing up as a single "set" statement.
#
# This will of course break if any of these variables contains a newline or
# an unmatched quote.
#
eval "set -- $(
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
xargs -n1 |
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
tr '\n' ' '
)" '"$@"'
exec "$JAVACMD" "$@"

94
gradlew.bat vendored Normal file
View File

@@ -0,0 +1,94 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

78
pom.xml
View File

@@ -1,78 +0,0 @@
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>xyz.lncvrt</groupId>
<artifactId>GalaxyBoxPvP</artifactId>
<name>GalaxyBoxPvP</name>
<version>1.0.0</version>
<build>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>papermc-repo</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
<repository>
<id>placeholderapi-repo</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>confuser-repo</id>
<url>https://ci.frostcast.net/plugin/repository/everything</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>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.booksaw</groupId>
<artifactId>BetterTeams</artifactId>
<version>4.11.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.confuser.banmanager</groupId>
<artifactId>BanManagerCommon</artifactId>
<version>7.9.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<java.version>21</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

15
settings.gradle.kts Normal file
View File

@@ -0,0 +1,15 @@
pluginManagement {
repositories {
gradlePluginPortal()
mavenLocal()
maven("https://repo.papermc.io/repository/maven-public/")
maven("https://repo.sayandev.org/snapshots")
}
}
plugins {
id("org.sayandev.stickynote.settings") version "1.9.0.5"
}
rootProject.name = "GalaxyBoxPvP"

View File

@@ -1,194 +0,0 @@
package xyz.lncvrt.galaxyboxpvp;
import me.confuser.banmanager.common.BanManagerPlugin;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import xyz.lncvrt.galaxyboxpvp.commands.Autocompress;
import xyz.lncvrt.galaxyboxpvp.commands.Sky;
import xyz.lncvrt.galaxyboxpvp.commands.Skyrtp;
import xyz.lncvrt.galaxyboxpvp.events.*;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.logging.Level;
public final class GalaxyBoxPvP extends JavaPlugin implements TabExecutor {
public final Map<UUID, Boolean> autoCompressStatus = new HashMap<>();
public final Map<UUID, Long> skyRTPDelays = new HashMap<>();
private final PlaceholderAPIExpansion placeholderAPIExpansion = new PlaceholderAPIExpansion();
public final MiniMessage miniMessage = MiniMessage.miniMessage();
@Override
public void onEnable() {
if (placeholderAPIExpansion.register()) {
getLogger().info("Successfully registered PlaceholderAPIExpansion!");
} else {
getLogger().warning("Failed to register PlaceholderAPIExpansion. Disabling plugin.");
getServer().getPluginManager().disablePlugin(this);
return;
}
registerEvents();
registerCommands();
loadAutoCompressStatus();
}
@Override
public void onDisable() {
placeholderAPIExpansion.unregister();
saveAutoCompressStatus();
}
private void registerEvents() {
PluginManager pluginManager = getServer().getPluginManager();
pluginManager.registerEvents(new BlockBreakListener(this), this);
pluginManager.registerEvents(new BlockPlaceListener(this), this);
pluginManager.registerEvents(new CraftItemListener(), this);
pluginManager.registerEvents(new EntityPickupItemListener(this), this);
pluginManager.registerEvents(new EntitySpawnListener(), this);
pluginManager.registerEvents(new FurnaceBurnListener(this), this);
pluginManager.registerEvents(new FurnaceSmeltListener(this), this);
pluginManager.registerEvents(new PlayerDropItemListener(this), this);
pluginManager.registerEvents(new PlayerJoinListener(this), this);
pluginManager.registerEvents(new PlayerMoveListener(), this);
pluginManager.registerEvents(new PrepareAnvilListener(), this);
pluginManager.registerEvents(new PrepareItemEnchantListener(), this);
pluginManager.registerEvents(new SignChangeListener(this), this);
}
private void registerCommands() {
Objects.requireNonNull(getCommand("autocompress")).setExecutor(new Autocompress(this));
Objects.requireNonNull(getCommand("sky")).setExecutor(new Sky());
Objects.requireNonNull(getCommand("skyrtp")).setExecutor(new Skyrtp(this));
}
public boolean isRestrictedMaterial(Material material) {
return material == Material.IRON_ORE || material == Material.RAW_IRON || material == Material.GOLD_ORE || material == Material.RAW_GOLD || material == Material.ANCIENT_DEBRIS || material == Material.SAND;
}
public void convertInventoryItemsPrep(Player player, UUID playerId) {
if (autoCompressStatus.getOrDefault(playerId, false)) {
convertInventoryItems(player, Material.DIAMOND, Material.DIAMOND_BLOCK, 9, 1);
convertInventoryItems(player, Material.LAPIS_LAZULI, Material.LAPIS_BLOCK, 9, 1);
convertInventoryItems(player, Material.REDSTONE, Material.REDSTONE_BLOCK, 9, 1);
convertInventoryItems(player, Material.EMERALD, Material.EMERALD_BLOCK, 9, 1);
convertInventoryItems(player, Material.RAW_GOLD, Material.RAW_GOLD_BLOCK, 9, 1);
convertInventoryItems(player, Material.GOLD_INGOT, Material.GOLD_BLOCK, 9, 1);
convertInventoryItems(player, Material.GOLD_NUGGET, Material.GOLD_INGOT, 9, 1);
convertInventoryItems(player, Material.IRON_ORE, Material.IRON_BLOCK, 9, 1);
convertInventoryItems(player, Material.RAW_IRON, Material.RAW_IRON_BLOCK, 9, 1);
convertInventoryItems(player, Material.COAL, Material.COAL_BLOCK, 9, 1);
convertInventoryItems(player, Material.RAW_COPPER, Material.COPPER_BLOCK, 9, 1);
convertInventoryItems(player, Material.COPPER_INGOT, Material.COPPER_BLOCK, 9, 1);
convertInventoryItems(player, Material.QUARTZ, Material.QUARTZ_BLOCK, 4, 1);
}
}
private void convertInventoryItems(Player player, Material fromMaterial, Material toMaterial, int fromCount, @SuppressWarnings("SameParameterValue") int toCount) {
ItemStack[] inventoryContents = player.getInventory().getContents();
Bukkit.getScheduler().runTask(this, () -> {
for (int i = 0; i < inventoryContents.length; i++) {
ItemStack item = inventoryContents[i];
if (item != null && item.getType() == fromMaterial && item.getAmount() >= fromCount) {
int stacksToConvert = item.getAmount() / fromCount;
int remainingItems = item.getAmount() % fromCount;
if (stacksToConvert > 0) {
item.setAmount(remainingItems);
player.getInventory().setItem(i, item);
ItemStack toMaterialStack = new ItemStack(toMaterial, stacksToConvert * toCount);
HashMap<Integer, ItemStack> remaining = player.getInventory().addItem(toMaterialStack);
if (!remaining.isEmpty()) {
for (ItemStack remainingItem : remaining.values()) {
player.getWorld().dropItem(player.getLocation(), remainingItem);
}
}
}
}
}
mergeInventoryStacks(player.getInventory(), fromMaterial);
});
}
private void mergeInventoryStacks(Inventory inventory, Material material) {
int totalAmount = 0;
for (ItemStack item : inventory.getContents()) {
if (item != null && item.getType() == material) {
totalAmount += item.getAmount();
item.setAmount(0);
}
}
int fullStacks = totalAmount / material.getMaxStackSize();
int remainingItems = totalAmount % material.getMaxStackSize();
for (int i = 0; i < fullStacks; i++) {
inventory.addItem(new ItemStack(material, material.getMaxStackSize()));
}
if (remainingItems > 0) {
inventory.addItem(new ItemStack(material, remainingItems));
}
}
@SuppressWarnings("unchecked")
private void saveAutoCompressStatus() {
File file = new File(getDataFolder(), "autocompress.json");
JSONObject jsonObject = new JSONObject();
for (Map.Entry<UUID, Boolean> entry : autoCompressStatus.entrySet()) {
jsonObject.put(entry.getKey().toString(), entry.getValue());
}
try (FileWriter writer = new FileWriter(file)) {
writer.write(jsonObject.toJSONString());
} catch (IOException e) {
getLogger().log(Level.SEVERE, "Error saving statuses to autocompress.json", e);
}
}
private void loadAutoCompressStatus() {
File file = new File(getDataFolder(), "autocompress.json");
if (!file.exists()) {
return;
}
try (FileReader reader = new FileReader(file)) {
JSONParser parser = new JSONParser();
JSONObject jsonObject = (JSONObject) parser.parse(reader);
for (Object key : jsonObject.keySet()) {
UUID playerId = UUID.fromString((String) key);
Boolean status = (Boolean) jsonObject.get(key);
autoCompressStatus.put(playerId, status);
}
} catch (IOException | ParseException e) {
getLogger().log(Level.SEVERE, "Error loading statuses from autocompress.json", e);
}
}
public boolean isMuted(Player player) {
return BanManagerPlugin.getInstance().getPlayerMuteStorage().isMuted(player.getUniqueId());
}
}

View File

@@ -1,62 +0,0 @@
package xyz.lncvrt.galaxyboxpvp;
import com.booksaw.betterTeams.Team;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.ChatColor;
import org.bukkit.Statistic;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public final class PlaceholderAPIExpansion extends PlaceholderExpansion {
@Override
public @NotNull String getIdentifier() {
return "galaxyboxpvp";
}
@Override
public @NotNull String getAuthor() {
return "Lncvrt";
}
@Override
public @NotNull String getVersion() {
return "1.0.0";
}
@Override
public boolean persist() {
return true;
}
@Override
public boolean canRegister() {
return true;
}
@Override
public @Nullable String onPlaceholderRequest(Player player, @NotNull String identifier) {
switch (identifier) {
case "hearts":
return String.format("%.1f", player.getHealth() / 2);
case "kills":
return String.valueOf(player.getStatistic(Statistic.PLAYER_KILLS));
case "deaths":
return String.valueOf(player.getStatistic(Statistic.DEATHS));
case "kdr":
int kills = player.getStatistic(Statistic.PLAYER_KILLS);
int deaths = player.getStatistic(Statistic.DEATHS);
return deaths == 0 ? String.valueOf(kills) : String.format("%.1f", (double) kills / deaths);
case "team":
Team team1 = Team.getTeam(player);
if (team1 == null) return "";
return ChatColor.translateAlternateColorCodes('&', "%s[%s%s%s%s]%s ".formatted(ChatColor.GRAY, ChatColor.RESET, team1.getDisplayName(), ChatColor.RESET, ChatColor.GRAY, ChatColor.RESET));
case "teamname":
Team team2 = Team.getTeam(player);
if (team2 == null) return "None";
return team2.getName();
default:
return null;
}
}
}

View File

@@ -1,36 +0,0 @@
package xyz.lncvrt.galaxyboxpvp.commands;
import xyz.lncvrt.galaxyboxpvp.GalaxyBoxPvP;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
import static org.bukkit.ChatColor.GREEN;
import static org.bukkit.ChatColor.RED;
public record Autocompress(GalaxyBoxPvP plugin) implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String @NotNull [] args) {
if (!(sender instanceof Player player)) {
sender.sendMessage(RED + "This command can only be executed by a player.");
return true;
}
UUID playerId = player.getUniqueId();
boolean currentStatus = plugin.autoCompressStatus.getOrDefault(playerId, false);
plugin.autoCompressStatus.put(playerId, !currentStatus);
if (!currentStatus) {
player.sendMessage(GREEN + "Auto-compress enabled.");
} else {
player.sendMessage(RED + "Auto-compress disabled.");
}
return true;
}
}

View File

@@ -1,19 +0,0 @@
package xyz.lncvrt.galaxyboxpvp.commands;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class Sky implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String @NotNull [] args) {
if (sender instanceof Player player) {
player.performCommand("warp sky");
player.sendMessage(MiniMessage.miniMessage().deserialize("<green>You can do <b><u><click:suggest_command:'/skyrtp'>/skyrtp</click></u></b> (click the bold text) to randomly teleport around here!"));
}
return true;
}
}

View File

@@ -1,51 +0,0 @@
package xyz.lncvrt.galaxyboxpvp.commands;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import xyz.lncvrt.galaxyboxpvp.GalaxyBoxPvP;
import java.util.concurrent.ThreadLocalRandom;
public class Skyrtp implements CommandExecutor {
private final GalaxyBoxPvP plugin;
public Skyrtp(GalaxyBoxPvP plugin) {
this.plugin = plugin;
}
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String @NotNull [] args) {
if (sender instanceof Player player) {
Long last = plugin.skyRTPDelays.get(player.getUniqueId());
Long time = System.currentTimeMillis();
if (last != null && time - last < 30000) {
Long timeLeft = (30000 - (System.currentTimeMillis() - last)) / 1000;
player.sendMessage(plugin.miniMessage.deserialize("<red>You can't RTP in the sky world so often, please wait %s second(s)!".formatted(timeLeft)));
return true;
}
World world = plugin.getServer().getWorld("sky");
if (world == null) {
player.sendMessage(plugin.miniMessage.deserialize("<red>Failed, please try again!"));
return true;
}
int randomX = ThreadLocalRandom.current().nextInt(100, 15000);
int randomZ = ThreadLocalRandom.current().nextInt(100, 15000);
Location location = new Location(world, randomX, 100, randomZ);
Block block = world.getBlockAt(location);
if (block.getType() == Material.AIR) {
block.setType(Material.GRASS_BLOCK);
}
player.teleport(location.add(0.5f, 1, 0.5f));
player.sendMessage(plugin.miniMessage.deserialize("<green>You have been randomly teleported to <u>%s 100 %s<u>".formatted(randomX, randomZ)));
plugin.skyRTPDelays.put(player.getUniqueId(), time);
}
return true;
}
}

View File

@@ -1,24 +0,0 @@
package xyz.lncvrt.galaxyboxpvp.events;
import xyz.lncvrt.galaxyboxpvp.GalaxyBoxPvP;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
public class BlockBreakListener implements Listener {
private final GalaxyBoxPvP plugin;
public BlockBreakListener(GalaxyBoxPvP plugin) {
this.plugin = plugin;
}
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
Player player = event.getPlayer();
plugin.convertInventoryItemsPrep(player, player.getUniqueId());
if (event.getBlock().getLocation().getY() == 100 && event.getBlock().getWorld().getName().equals("world")) {
event.setCancelled(true);
}
}
}

View File

@@ -1,26 +0,0 @@
package xyz.lncvrt.galaxyboxpvp.events;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import xyz.lncvrt.galaxyboxpvp.GalaxyBoxPvP;
public class BlockPlaceListener implements Listener {
private final GalaxyBoxPvP plugin;
public BlockPlaceListener(GalaxyBoxPvP plugin) {
this.plugin = plugin;
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent event) {
if (event.getBlockPlaced().getType() == Material.POLISHED_BLACKSTONE_BUTTON) {
if (event.getItemInHand().hasItemMeta() && event.getItemInHand().getItemMeta().hasDisplayName()) {
event.setCancelled(true); //temp fix
}
} else if (event.getBlockPlaced().getType() == Material.FURNACE || event.getBlockPlaced().getType() == Material.FURNACE_MINECART || event.getBlockPlaced().getType() == Material.BLAST_FURNACE) {
event.getPlayer().sendMessage(plugin.miniMessage.deserialize("<bold><green>[TIP] </green></bold><green>If you are trying to smelt iron, gold, etc you can use the Smelter Shop. Click <underlined><click:run_command:'/warp smelter'>[HERE]</click></underlined> to teleport to the smelter shop!</green>"));
}
}
}

View File

@@ -1,24 +0,0 @@
package xyz.lncvrt.galaxyboxpvp.events;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
public class CraftItemListener implements Listener {
@EventHandler
public void onCraftItem(CraftItemEvent event) {
if (event.getCurrentItem() != null && event.getCurrentItem().getType() == Material.DIAMOND_PICKAXE) {
ItemStack pickaxe = event.getCurrentItem();
ItemMeta meta = pickaxe.getItemMeta();
if (meta != null) {
meta.setUnbreakable(true);
pickaxe.setItemMeta(meta);
event.setCurrentItem(pickaxe);
}
}
}
}

View File

@@ -1,21 +0,0 @@
package xyz.lncvrt.galaxyboxpvp.events;
import xyz.lncvrt.galaxyboxpvp.GalaxyBoxPvP;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityPickupItemEvent;
public class EntityPickupItemListener implements Listener {
private final GalaxyBoxPvP plugin;
public EntityPickupItemListener(GalaxyBoxPvP plugin) {
this.plugin = plugin;
}
@EventHandler(priority = EventPriority.LOWEST)
public void onItemPickup(EntityPickupItemEvent event) {
if (event.getEntity() instanceof Player player) plugin.convertInventoryItemsPrep(player, player.getUniqueId());
}
}

View File

@@ -1,13 +0,0 @@
package xyz.lncvrt.galaxyboxpvp.events;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntitySpawnEvent;
public class EntitySpawnListener implements Listener {
@EventHandler
public void onEntitySpawnEvent(EntitySpawnEvent event) {
if (event.getEntityType() == EntityType.WITHER) event.setCancelled(true);
}
}

View File

@@ -1,25 +0,0 @@
package xyz.lncvrt.galaxyboxpvp.events;
import xyz.lncvrt.galaxyboxpvp.GalaxyBoxPvP;
import org.bukkit.Material;
import org.bukkit.block.Furnace;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.FurnaceBurnEvent;
import java.util.Objects;
public class FurnaceBurnListener implements Listener {
private final GalaxyBoxPvP plugin;
public FurnaceBurnListener(GalaxyBoxPvP plugin) {
this.plugin = plugin;
}
@EventHandler
public void onFurnaceBurn(FurnaceBurnEvent event) {
Furnace furnace = (Furnace) event.getBlock().getState();
Material smelting = Objects.requireNonNull(furnace.getInventory().getSmelting()).getType();
if (plugin.isRestrictedMaterial(smelting)) event.setCancelled(true);
}
}

View File

@@ -1,21 +0,0 @@
package xyz.lncvrt.galaxyboxpvp.events;
import xyz.lncvrt.galaxyboxpvp.GalaxyBoxPvP;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.FurnaceSmeltEvent;
public class FurnaceSmeltListener implements Listener {
private final GalaxyBoxPvP plugin;
public FurnaceSmeltListener(GalaxyBoxPvP plugin) {
this.plugin = plugin;
}
@EventHandler
public void onFurnaceSmelt(FurnaceSmeltEvent event) {
Material smelted = event.getSource().getType();
if (plugin.isRestrictedMaterial(smelted)) event.setCancelled(true);
}
}

View File

@@ -1,20 +0,0 @@
package xyz.lncvrt.galaxyboxpvp.events;
import xyz.lncvrt.galaxyboxpvp.GalaxyBoxPvP;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerDropItemEvent;
public class PlayerDropItemListener implements Listener {
private final GalaxyBoxPvP plugin;
public PlayerDropItemListener(GalaxyBoxPvP plugin) {
this.plugin = plugin;
}
@EventHandler(priority = EventPriority.LOWEST)
public void onItemDrop(PlayerDropItemEvent event) {
plugin.convertInventoryItemsPrep(event.getPlayer(), event.getPlayer().getUniqueId());
}
}

View File

@@ -1,28 +0,0 @@
package xyz.lncvrt.galaxyboxpvp.events;
import xyz.lncvrt.galaxyboxpvp.GalaxyBoxPvP;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import java.util.UUID;
import static org.bukkit.ChatColor.GREEN;
public class PlayerJoinListener implements Listener {
private final GalaxyBoxPvP plugin;
public PlayerJoinListener(GalaxyBoxPvP plugin) {
this.plugin = plugin;
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
UUID playerId = player.getUniqueId();
if (!plugin.autoCompressStatus.containsKey(playerId)) plugin.autoCompressStatus.put(playerId, false);
player.sendMessage("%sWelcome to LncvrtBox, %s! This is a PvP arena gamemode that was originally called LncvrtBox, and is almost a year old! We reset the server for GalaxyNetwork and a fresh start".formatted(GREEN, player.getName()));
}
}

View File

@@ -1,20 +0,0 @@
package xyz.lncvrt.galaxyboxpvp.events;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
public class PlayerMoveListener implements Listener {
@EventHandler
private void onSignPlace(PlayerMoveEvent event) {
Player player = event.getPlayer();
int maxY = player.getWorld().getMaxHeight();
if (player.getLocation().getY() >= maxY) {
Location newLocation = player.getLocation().clone();
newLocation.setY(maxY - 1);
player.teleport(newLocation);
}
}
}

View File

@@ -1,22 +0,0 @@
package xyz.lncvrt.galaxyboxpvp.events;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.PrepareAnvilEvent;
import org.bukkit.inventory.ItemStack;
public class PrepareAnvilListener implements Listener {
@EventHandler
public void onPrepareAnvil(PrepareAnvilEvent event) {
ItemStack left = event.getInventory().getItem(0);
ItemStack right = event.getInventory().getItem(1);
if (left != null && (left.getType() == Material.DIAMOND_PICKAXE || left.getType() == Material.NETHERITE_PICKAXE)) {
event.setResult(null);
}
if (right != null && (right.getType() == Material.DIAMOND_PICKAXE || right.getType() == Material.NETHERITE_PICKAXE)) {
event.setResult(null);
}
}
}

View File

@@ -1,15 +0,0 @@
package xyz.lncvrt.galaxyboxpvp.events;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.enchantment.PrepareItemEnchantEvent;
import org.bukkit.inventory.ItemStack;
public class PrepareItemEnchantListener implements Listener {
@EventHandler
public void onPrepareItemEnchant(PrepareItemEnchantEvent event) {
ItemStack item = event.getItem();
if (item.getType() == Material.DIAMOND_PICKAXE || item.getType() == Material.NETHERITE_PICKAXE) event.setCancelled(true);
}
}

View File

@@ -1,21 +0,0 @@
package xyz.lncvrt.galaxyboxpvp.events;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.projectiles.ProjectileSource;
public class ProjectileHitListener implements Listener {
@EventHandler
public void onProjectileHit(ProjectileHitEvent event) {
Projectile projectile = event.getEntity();
if (projectile.getType() == EntityType.WITHER_SKULL) {
ProjectileSource shooter = projectile.getShooter();
if (shooter instanceof org.bukkit.entity.Wither) {
event.getEntity().remove();
}
}
}
}

View File

@@ -1,19 +0,0 @@
package xyz.lncvrt.galaxyboxpvp.events;
import xyz.lncvrt.galaxyboxpvp.GalaxyBoxPvP;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.SignChangeEvent;
public class SignChangeListener implements Listener {
private final GalaxyBoxPvP plugin;
public SignChangeListener(GalaxyBoxPvP plugin) {
this.plugin = plugin;
}
@EventHandler
private void onSignPlace(SignChangeEvent event) {
if (plugin.isMuted(event.getPlayer())) event.setCancelled(true);
}
}

View File

@@ -0,0 +1,207 @@
package xyz.lncvrt.galaxyboxpvp
import me.confuser.banmanager.common.BanManagerPlugin
import org.bukkit.Bukkit
import org.bukkit.Material
import org.bukkit.command.TabExecutor
import org.bukkit.entity.Player
import org.bukkit.inventory.Inventory
import org.bukkit.inventory.ItemStack
import org.bukkit.plugin.java.JavaPlugin
import org.json.simple.JSONObject
import org.json.simple.parser.JSONParser
import org.sayandev.stickynote.loader.bukkit.StickyNoteBukkitLoader
import xyz.lncvrt.galaxyboxpvp.commands.Autocompress
import xyz.lncvrt.galaxyboxpvp.commands.Sky
import xyz.lncvrt.galaxyboxpvp.commands.Skyrtp
import xyz.lncvrt.galaxyboxpvp.events.*
import java.io.File
import java.io.FileReader
import java.io.FileWriter
import java.io.IOException
import java.text.ParseException
import java.util.*
class GalaxyBoxPvPPlugin : JavaPlugin(), TabExecutor {
internal val autoCompressStatus: MutableMap<UUID?, Boolean?> = HashMap<UUID?, Boolean?>()
internal val skyRTPDelays: MutableMap<UUID?, Long?> = HashMap<UUID?, Long?>()
private val placeholderAPIExpansion: PlaceholderAPIExpansion = PlaceholderAPIExpansion()
override fun onEnable() {
StickyNoteBukkitLoader(this)
instance = this
if (placeholderAPIExpansion.register()) {
logger.info("Successfully registered PlaceholderAPIExpansion!")
} else {
logger.warning("Failed to register PlaceholderAPIExpansion. Disabling plugin.")
server.pluginManager.disablePlugin(this)
return
}
registerEvents()
registerCommands()
loadAutoCompressStatus()
}
override fun onDisable() {
placeholderAPIExpansion.unregister()
saveAutoCompressStatus()
}
private fun registerEvents() {
val pluginManager = server.pluginManager
pluginManager.registerEvents(BlockBreakListener(this), this)
pluginManager.registerEvents(BlockPlaceListener(), this)
pluginManager.registerEvents(CraftItemListener(), this)
pluginManager.registerEvents(EntityPickupItemListener(this), this)
pluginManager.registerEvents(EntitySpawnListener(), this)
pluginManager.registerEvents(FurnaceBurnListener(this), this)
pluginManager.registerEvents(FurnaceSmeltListener(this), this)
pluginManager.registerEvents(PlayerDropItemListener(this), this)
pluginManager.registerEvents(PlayerJoinListener(this), this)
pluginManager.registerEvents(PlayerMoveListener(), this)
pluginManager.registerEvents(PrepareAnvilListener(), this)
pluginManager.registerEvents(PrepareItemEnchantListener(), this)
pluginManager.registerEvents(SignChangeListener(this), this)
}
private fun registerCommands() {
Autocompress
Sky
Skyrtp
}
internal fun isRestrictedMaterial(material: Material?): Boolean {
return material == Material.IRON_ORE || material == Material.RAW_IRON || material == Material.GOLD_ORE || material == Material.RAW_GOLD || material == Material.ANCIENT_DEBRIS || material == Material.SAND
}
internal fun convertInventoryItemsPrep(player: Player, playerId: UUID?) {
if (autoCompressStatus.getOrDefault(playerId, false) == true) {
convertInventoryItems(player, Material.DIAMOND, Material.DIAMOND_BLOCK, 9, 1)
convertInventoryItems(player, Material.LAPIS_LAZULI, Material.LAPIS_BLOCK, 9, 1)
convertInventoryItems(player, Material.REDSTONE, Material.REDSTONE_BLOCK, 9, 1)
convertInventoryItems(player, Material.EMERALD, Material.EMERALD_BLOCK, 9, 1)
convertInventoryItems(player, Material.RAW_GOLD, Material.RAW_GOLD_BLOCK, 9, 1)
convertInventoryItems(player, Material.GOLD_INGOT, Material.GOLD_BLOCK, 9, 1)
convertInventoryItems(player, Material.GOLD_NUGGET, Material.GOLD_INGOT, 9, 1)
convertInventoryItems(player, Material.IRON_ORE, Material.IRON_BLOCK, 9, 1)
convertInventoryItems(player, Material.RAW_IRON, Material.RAW_IRON_BLOCK, 9, 1)
convertInventoryItems(player, Material.COAL, Material.COAL_BLOCK, 9, 1)
convertInventoryItems(player, Material.RAW_COPPER, Material.COPPER_BLOCK, 9, 1)
convertInventoryItems(player, Material.COPPER_INGOT, Material.COPPER_BLOCK, 9, 1)
convertInventoryItems(player, Material.QUARTZ, Material.QUARTZ_BLOCK, 4, 1)
}
}
private fun convertInventoryItems(
player: Player,
fromMaterial: Material,
toMaterial: Material,
fromCount: Int,
toCount: Int
) {
val inventoryContents = player.inventory.contents
Bukkit.getScheduler().runTask(this, Runnable {
for (i in inventoryContents.indices) {
val item = inventoryContents[i]
if (item != null && item.type == fromMaterial && item.amount >= fromCount) {
val stacksToConvert = item.amount / fromCount
val remainingItems = item.amount % fromCount
if (stacksToConvert > 0) {
item.amount = remainingItems
player.inventory.setItem(i, item)
val toMaterialStack = ItemStack(toMaterial, stacksToConvert * toCount)
val remaining = player.inventory.addItem(toMaterialStack)
if (!remaining.isEmpty()) {
for (remainingItem in remaining.values) {
player.world.dropItem(player.location, remainingItem)
}
}
}
}
}
mergeInventoryStacks(player.inventory, fromMaterial)
})
}
private fun mergeInventoryStacks(inventory: Inventory, material: Material) {
var totalAmount = 0
for (item in inventory.contents) {
if (item != null && item.type == material) {
totalAmount += item.amount
item.amount = 0
}
}
val fullStacks = totalAmount / material.maxStackSize
val remainingItems = totalAmount % material.maxStackSize
for (i in 0..<fullStacks) {
inventory.addItem(ItemStack(material, material.maxStackSize))
}
if (remainingItems > 0) {
inventory.addItem(ItemStack(material, remainingItems))
}
}
private fun saveAutoCompressStatus() {
val file = File(dataFolder, "autocompress.json")
val jsonObject = JSONObject()
for (entry in autoCompressStatus.entries) {
jsonObject.put(entry.key.toString(), entry.value)
}
try {
FileWriter(file).use { writer ->
writer.write(jsonObject.toJSONString())
}
} catch (e: IOException) {
e.printStackTrace()
}
}
private fun loadAutoCompressStatus() {
val file = File(dataFolder, "autocompress.json")
if (!file.exists()) {
return
}
try {
FileReader(file).use { reader ->
val parser = JSONParser()
val jsonObject = parser.parse(reader) as JSONObject
for (key in jsonObject.keys) {
val playerId = UUID.fromString(key as String?)
val status = jsonObject.get(key) as Boolean?
autoCompressStatus.put(playerId, status)
}
}
} catch (e: IOException) {
e.printStackTrace()
} catch (e: ParseException) {
e.printStackTrace()
}
}
internal fun isMuted(player: Player): Boolean {
return BanManagerPlugin.getInstance().playerMuteStorage.isMuted(player.uniqueId)
}
companion object {
private lateinit var instance: GalaxyBoxPvPPlugin
fun getInstance(): GalaxyBoxPvPPlugin {
return instance
}
}
}

View File

@@ -0,0 +1,55 @@
package xyz.lncvrt.galaxyboxpvp
import com.booksaw.betterTeams.Team
import me.clip.placeholderapi.expansion.PlaceholderExpansion
import org.bukkit.ChatColor
import org.bukkit.Statistic
import org.bukkit.entity.Player
import javax.annotation.Nullable
class PlaceholderAPIExpansion : PlaceholderExpansion() {
override fun getIdentifier(): String {
return "galaxyboxpvp"
}
override fun getAuthor(): String {
return "Lncvrt"
}
override fun getVersion(): String {
return "1.0.0"
}
override fun persist(): Boolean {
return true
}
override fun canRegister(): Boolean {
return true
}
@Nullable
override fun onPlaceholderRequest(player: Player, identifier: String): String? {
when (identifier) {
"hearts" -> return String.format("%.1f", player.health / 2)
"kills" -> return player.getStatistic(Statistic.PLAYER_KILLS).toString()
"deaths" -> return player.getStatistic(Statistic.DEATHS).toString()
"kdr" -> {
val kills = player.getStatistic(Statistic.PLAYER_KILLS)
val deaths = player.getStatistic(Statistic.DEATHS)
return if (deaths == 0) kills.toString() else String.format("%.1f", kills.toDouble() / deaths)
}
"team" -> {
val team1: Team? = Team.getTeam(player)
if (team1 == null) return ""
return "%s[%s%s%s%s]%s ".format(ChatColor.GRAY, ChatColor.RESET, team1.displayName, ChatColor.RESET, ChatColor.GRAY, ChatColor.RESET)
}
"teamname" -> {
val team2: Team? = Team.getTeam(player)
if (team2 == null) return "None"
return team2.name
}
else -> return null
}
}
}

View File

@@ -0,0 +1,26 @@
package xyz.lncvrt.galaxyboxpvp.commands
import org.incendo.cloud.kotlin.MutableCommandBuilder
import org.sayandev.stickynote.bukkit.command.BukkitCommand
import org.sayandev.stickynote.bukkit.command.BukkitSender
import org.sayandev.stickynote.bukkit.extension.sendComponent
import xyz.lncvrt.galaxyboxpvp.GalaxyBoxPvPPlugin
object Autocompress : BukkitCommand("autocompress") {
override fun rootBuilder(builder: MutableCommandBuilder<BukkitSender>) {
builder.handler { context ->
val player = context.sender().player() ?: return@handler
val playerId = player.uniqueId
val instance = GalaxyBoxPvPPlugin.getInstance()
val currentStatus = instance.autoCompressStatus.getOrDefault(playerId, false) ?: return@handler
instance.autoCompressStatus.put(playerId, !currentStatus)
if (!currentStatus) {
player.sendComponent("<green>Auto-compress enabled.")
} else {
player.sendComponent("<red>Auto-compress disabled.")
}
}
}
}

View File

@@ -0,0 +1,17 @@
package xyz.lncvrt.galaxyboxpvp.commands
import org.incendo.cloud.kotlin.MutableCommandBuilder
import org.sayandev.stickynote.bukkit.command.BukkitCommand
import org.sayandev.stickynote.bukkit.command.BukkitSender
import org.sayandev.stickynote.bukkit.extension.sendComponent
object Sky : BukkitCommand("sky") {
override fun rootBuilder(builder: MutableCommandBuilder<BukkitSender>) {
builder.handler { context ->
val player = context.sender().player() ?: return@handler
player.performCommand("warp sky")
player.sendComponent("<green>You can do <b><u><click:suggest_command:'/skyrtp'>/skyrtp</click></u></b> (click the bold text) to randomly teleport around here!")
}
}
}

View File

@@ -0,0 +1,44 @@
package xyz.lncvrt.galaxyboxpvp.commands
import org.bukkit.Location
import org.bukkit.Material
import org.bukkit.World
import org.bukkit.block.Block
import org.incendo.cloud.kotlin.MutableCommandBuilder
import org.sayandev.stickynote.bukkit.command.BukkitCommand
import org.sayandev.stickynote.bukkit.command.BukkitSender
import org.sayandev.stickynote.bukkit.extension.sendComponent
import xyz.lncvrt.galaxyboxpvp.GalaxyBoxPvPPlugin
import java.util.concurrent.ThreadLocalRandom
object Skyrtp : BukkitCommand("skyrtp") {
override fun rootBuilder(builder: MutableCommandBuilder<BukkitSender>) {
builder.handler { context ->
val player = context.sender().player() ?: return@handler
val instance = GalaxyBoxPvPPlugin.getInstance()
val last: Long? = instance.skyRTPDelays.get(player.uniqueId)
val time = System.currentTimeMillis()
if (last != null && time - last < 30000) {
val timeLeft = (30000 - (System.currentTimeMillis() - last)) / 1000
player.sendComponent("<red>You can't RTP in the sky world so often, please wait $timeLeft second(s)!")
return@handler
}
val world: World? = instance.server.getWorld("sky")
if (world == null) {
player.sendComponent("<red>Failed, please try again!")
return@handler
}
val randomX = ThreadLocalRandom.current().nextInt(100, 15000)
val randomZ = ThreadLocalRandom.current().nextInt(100, 15000)
val location = Location(world, randomX.toDouble(), 100.0, randomZ.toDouble())
val block: Block = world.getBlockAt(location)
if (block.type === Material.AIR) {
block.type = Material.GRASS_BLOCK
}
player.teleport(location.add(0.5, 1.0, 0.5))
player.sendComponent("<green>You have been randomly teleported to <u>$randomX 100 $randomZ<u>")
instance.skyRTPDelays.put(player.uniqueId, time)
}
}
}

View File

@@ -0,0 +1,17 @@
package xyz.lncvrt.galaxyboxpvp.events
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.block.BlockBreakEvent
import xyz.lncvrt.galaxyboxpvp.GalaxyBoxPvPPlugin
class BlockBreakListener(private val plugin: GalaxyBoxPvPPlugin) : Listener {
@EventHandler
fun onBlockBreak(event: BlockBreakEvent) {
val player = event.player
plugin.convertInventoryItemsPrep(player, player.uniqueId)
if (event.getBlock().location.y == 100.0 && event.getBlock().world.name == "world") {
event.isCancelled = true
}
}
}

View File

@@ -0,0 +1,20 @@
package xyz.lncvrt.galaxyboxpvp.events
import org.bukkit.Material
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.block.BlockPlaceEvent
import org.sayandev.stickynote.bukkit.extension.sendComponent
class BlockPlaceListener() : Listener {
@EventHandler
fun onBlockPlace(event: BlockPlaceEvent) {
if (event.blockPlaced.type == Material.POLISHED_BLACKSTONE_BUTTON) {
if (event.getItemInHand().hasItemMeta() && event.getItemInHand().itemMeta.hasDisplayName()) {
event.isCancelled = true //temp fix
}
} else if (event.blockPlaced.type == Material.FURNACE || event.blockPlaced.type == Material.FURNACE_MINECART || event.blockPlaced.type == Material.BLAST_FURNACE) {
event.getPlayer().sendComponent("<bold><green>[TIP] </green></bold><green>If you are trying to smelt iron, gold, etc you can use the Smelter Shop. Click <underlined><click:run_command:'/warp smelter'>[HERE]</click></underlined> to teleport to the smelter shop!</green>")
}
}
}

View File

@@ -0,0 +1,22 @@
package xyz.lncvrt.galaxyboxpvp.events
import org.bukkit.Material
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.inventory.CraftItemEvent
class CraftItemListener : Listener {
@EventHandler
fun onCraftItem(event: CraftItemEvent) {
if (event.currentItem != null && event.currentItem!!.type == Material.DIAMOND_PICKAXE) {
val pickaxe = event.currentItem
val meta = pickaxe!!.itemMeta
if (meta != null) {
meta.isUnbreakable = true
pickaxe.setItemMeta(meta)
event.currentItem = pickaxe
}
}
}
}

View File

@@ -0,0 +1,18 @@
package xyz.lncvrt.galaxyboxpvp.events
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
import org.bukkit.event.Listener
import org.bukkit.event.entity.EntityPickupItemEvent
import xyz.lncvrt.galaxyboxpvp.GalaxyBoxPvPPlugin
class EntityPickupItemListener(private val plugin: GalaxyBoxPvPPlugin) : Listener {
@EventHandler(priority = EventPriority.LOWEST)
fun onItemPickup(event: EntityPickupItemEvent) {
if (event.getEntity() is Player) {
val player = event.entity as Player
plugin.convertInventoryItemsPrep(player, player.uniqueId)
}
}
}

View File

@@ -0,0 +1,13 @@
package xyz.lncvrt.galaxyboxpvp.events
import org.bukkit.entity.EntityType
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.entity.EntitySpawnEvent
class EntitySpawnListener : Listener {
@EventHandler
fun onEntitySpawnEvent(event: EntitySpawnEvent) {
if (event.entityType == EntityType.WITHER) event.isCancelled = true
}
}

View File

@@ -0,0 +1,17 @@
package xyz.lncvrt.galaxyboxpvp.events
import org.bukkit.Material
import org.bukkit.block.Furnace
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.inventory.FurnaceBurnEvent
import xyz.lncvrt.galaxyboxpvp.GalaxyBoxPvPPlugin
class FurnaceBurnListener(private val plugin: GalaxyBoxPvPPlugin) : Listener {
@EventHandler
fun onFurnaceBurn(event: FurnaceBurnEvent) {
val furnace: Furnace = event.getBlock().state as Furnace
val smelting: Material? = furnace.inventory.smelting?.type
if (plugin.isRestrictedMaterial(smelting)) event.isCancelled = true
}
}

View File

@@ -0,0 +1,14 @@
package xyz.lncvrt.galaxyboxpvp.events
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.inventory.FurnaceSmeltEvent
import xyz.lncvrt.galaxyboxpvp.GalaxyBoxPvPPlugin
class FurnaceSmeltListener(private val plugin: GalaxyBoxPvPPlugin) : Listener {
@EventHandler
fun onFurnaceSmelt(event: FurnaceSmeltEvent) {
val smelted = event.source.type
if (plugin.isRestrictedMaterial(smelted)) event.isCancelled = true
}
}

View File

@@ -0,0 +1,14 @@
package xyz.lncvrt.galaxyboxpvp.events
import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
import org.bukkit.event.Listener
import org.bukkit.event.player.PlayerDropItemEvent
import xyz.lncvrt.galaxyboxpvp.GalaxyBoxPvPPlugin
class PlayerDropItemListener(private val plugin: GalaxyBoxPvPPlugin) : Listener {
@EventHandler(priority = EventPriority.LOWEST)
fun onItemDrop(event: PlayerDropItemEvent) {
plugin.convertInventoryItemsPrep(event.getPlayer(), event.getPlayer().uniqueId)
}
}

View File

@@ -0,0 +1,18 @@
package xyz.lncvrt.galaxyboxpvp.events
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.player.PlayerJoinEvent
import org.sayandev.stickynote.bukkit.extension.sendComponent
import xyz.lncvrt.galaxyboxpvp.GalaxyBoxPvPPlugin
class PlayerJoinListener(private val plugin: GalaxyBoxPvPPlugin) : Listener {
@EventHandler
fun onPlayerJoin(event: PlayerJoinEvent) {
val player = event.getPlayer()
val playerId = player.uniqueId
if (!plugin.autoCompressStatus.containsKey(playerId)) plugin.autoCompressStatus.put(playerId, false)
player.sendComponent("<green>Welcome to LncvrtBox, ${player.name}! This is a PvP arena gamemode that was originally called LncvrtBox, and is almost a year old! We reset the server for GalaxyNetwork and a fresh start</green>")
}
}

View File

@@ -0,0 +1,18 @@
package xyz.lncvrt.galaxyboxpvp.events
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.player.PlayerMoveEvent
class PlayerMoveListener : Listener {
@EventHandler
private fun onSignPlace(event: PlayerMoveEvent) {
val player = event.getPlayer()
val maxY = player.world.maxHeight
if (player.location.y >= maxY) {
val newLocation = player.location.clone()
newLocation.y = (maxY - 1).toDouble()
player.teleport(newLocation)
}
}
}

View File

@@ -0,0 +1,21 @@
package xyz.lncvrt.galaxyboxpvp.events
import org.bukkit.Material
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.inventory.PrepareAnvilEvent
class PrepareAnvilListener : Listener {
@EventHandler
fun onPrepareAnvil(event: PrepareAnvilEvent) {
val left = event.inventory.getItem(0)
val right = event.inventory.getItem(1)
if (left != null && (left.type == Material.DIAMOND_PICKAXE || left.type == Material.NETHERITE_PICKAXE)) {
event.result = null
}
if (right != null && (right.type == Material.DIAMOND_PICKAXE || right.type == Material.NETHERITE_PICKAXE)) {
event.result = null
}
}
}

View File

@@ -0,0 +1,14 @@
package xyz.lncvrt.galaxyboxpvp.events
import org.bukkit.Material
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.enchantment.PrepareItemEnchantEvent
class PrepareItemEnchantListener : Listener {
@EventHandler
fun onPrepareItemEnchant(event: PrepareItemEnchantEvent) {
val item = event.item
if (item.type == Material.DIAMOND_PICKAXE || item.type == Material.NETHERITE_PICKAXE) event.isCancelled = true
}
}

View File

@@ -0,0 +1,13 @@
package xyz.lncvrt.galaxyboxpvp.events
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.block.SignChangeEvent
import xyz.lncvrt.galaxyboxpvp.GalaxyBoxPvPPlugin
class SignChangeListener(private val plugin: GalaxyBoxPvPPlugin) : Listener {
@EventHandler
private fun onSignPlace(event: SignChangeEvent) {
if (plugin.isMuted(event.player)) event.isCancelled = true
}
}

View File

@@ -1,18 +0,0 @@
name: GalaxyBoxPvP
version: '${version}'
main: xyz.lncvrt.galaxyboxpvp.GalaxyBoxPvP
api-version: '1.21'
depend:
- PlaceholderAPI
- Essentials
- BetterTeams
commands:
autocompress:
description: Auto compressor
usage: /autocompress
sky:
description: Teleports you to sky world
usage: /sky
skyrtp:
description: Teleports you to a random location in sky world
usage: /sky