Add files via upload

This commit is contained in:
ImproperIssues
2023-01-15 03:03:38 -08:00
committed by GitHub
parent 1576d6efb1
commit 9b84b6d1e2
42 changed files with 1266 additions and 0 deletions

9
ExplosionsControl.iml Normal file
View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

47
build.gradle Normal file
View File

@@ -0,0 +1,47 @@
plugins {
id 'java'
}
group = 'me.improper'
version = '3.0'
repositories {
mavenCentral()
maven {
name = 'spigotmc-repo'
url = 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/'
}
maven {
name = 'sonatype'
url = 'https://oss.sonatype.org/content/groups/public/'
}
}
dependencies {
compileOnly 'org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT'
}
def targetJavaVersion = 16
java {
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
if (JavaVersion.current() < javaVersion) {
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
}
}
tasks.withType(JavaCompile).configureEach {
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
options.release = targetJavaVersion
}
}
processResources {
def props = [version: version]
inputs.properties props
filteringCharset 'UTF-8'
filesMatching('plugin.yml') {
expand props
}
}

Binary file not shown.

View File

@@ -0,0 +1,18 @@
#
#
# This is ExplosionsControl by ImproperIssues
#
# Please note that all the explosions configurations have been moved to
# "plugins/ExplosionsControl/worldconfigurations" and are no longer
# configured through this config!
#
#
#
# If you do enjoy this plugin, please star it on github!
# Visit and star https://github.com/ItziSpyder/ExplosionsControl
#
#
config:
plugin:
prefix: '§7[§eExplosions§6Control§7] §'

View File

@@ -0,0 +1,16 @@
name: ExplosionsControl
version: '3.0'
main: me.improper.explosionscontrol.ExplosionsControl
api-version: 1.17
authors: [ ImproperIssues ]
description: Manager server explosions with just a few simple clicks!
website: github.com/ItziSpyder
commands:
explosions:
description: Opens up the explosions toggle menu
usage: /explosions
permission: explosionscontrol.commands.explosions
loadworlds:
description: Loads in all the configuration files in case they didn't load
usage: /loadworlds
permission: explosionscontrol.commands.loadworlds

Binary file not shown.

View File

@@ -0,0 +1,2 @@
Manifest-Version: 1.0

0
gradle.properties Normal file
View File

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

Binary file not shown.

View File

@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

234
gradlew vendored Normal file
View File

@@ -0,0 +1,234 @@
#!/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.
#
##############################################################################
#
# 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/master/subprojects/plugins/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
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
APP_NAME="Gradle"
APP_BASE_NAME=${0##*/}
# 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"'
# 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
which java >/dev/null 2>&1 || 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
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
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
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
"$@"
# 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" "$@"

89
gradlew.bat vendored Normal file
View File

@@ -0,0 +1,89 @@
@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
@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=.
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%" == "0" goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
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%"=="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!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

1
settings.gradle Normal file
View File

@@ -0,0 +1 @@
rootProject.name = 'ExplosionsControl'

View File

@@ -0,0 +1,43 @@
package me.improper.explosionscontrol;
import me.improper.explosionscontrol.commands.Commands;
import me.improper.explosionscontrol.commands.Tabs;
import me.improper.explosionscontrol.data.ExplosionConfigFile;
import me.improper.explosionscontrol.data.ExplosionToggle;
import me.improper.explosionscontrol.events.OnExplode;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
public final class ExplosionsControl extends JavaPlugin {
@Override
public void onEnable() {
// Plugin startup logic
Bukkit.broadcastMessage("");
ExplosionConfigFile.setup();
ExplosionToggle.setup();
// Files
getConfig().options().copyDefaults();
saveDefaultConfig();
// Events
Bukkit.getPluginManager().registerEvents(new OnExplode(),this);
// Commands
getCommand("explosions").setExecutor(new Commands());
getCommand("explosions").setTabCompleter(new Tabs());
getCommand("loadworlds").setExecutor(new Commands());
getCommand("loadworlds").setTabCompleter(new Tabs());
}
@Override
public void onDisable() {
// Plugin shutdown logic
}
public static Plugin getInstance() {
return Bukkit.getPluginManager().getPlugin("ExplosionsControl");
}
}

View File

@@ -0,0 +1,38 @@
package me.improper.explosionscontrol.commands;
import me.improper.explosionscontrol.data.ExplosionConfigFile;
import me.improper.explosionscontrol.data.ExplosionToggle;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class Commands implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
String commandName = command.getName().toLowerCase().trim();
try {
switch (commandName) {
case "explosions" -> {
((Player) sender).openInventory(ExplosionToggle.EXPLOSIONMENU);
return true;
}
case "loadworlds" -> {
ExplosionConfigFile.setup();
return true;
}
}
} catch (Exception exception) {
String message = ChatColor.DARK_RED + "Command error: " + ChatColor.RED;
if (exception instanceof NullPointerException) message += "Command contains a null value!";
else if (exception instanceof IndexOutOfBoundsException) message += "Incomplete command! Not enough information was provided!";
else message += exception.getMessage();
sender.sendMessage(message);
return true;
}
return false;
}
}

View File

@@ -0,0 +1,25 @@
package me.improper.explosionscontrol.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import java.util.ArrayList;
import java.util.List;
public class Tabs implements TabCompleter {
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
List<String> list = new ArrayList<>();
String commandName = command.getName().toLowerCase().trim();
switch (commandName) {
case "explosions","loadworlds" -> {
break;
}
}
list.removeIf(i -> !i.toLowerCase().contains(args[args.length - 1].toLowerCase()));
return list;
}
}

View File

@@ -0,0 +1,18 @@
package me.improper.explosionscontrol.data;
import org.bukkit.Bukkit;
import org.bukkit.World;
public class ExplosionConfigFile {
/**
* Creates a configuration for each existing world.
* These are saved to "plugins/ExplosionsControl/worldconfigurations".
*/
public static void setup() {
for (World world : Bukkit.getWorlds()) {
ExplosionConfiguration configuration = new ExplosionConfiguration(world);
configuration.save();
}
}
}

View File

@@ -0,0 +1,139 @@
package me.improper.explosionscontrol.data;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.Serializable;
public class ExplosionConfiguration implements Serializable {
private String world;
private ExplosionMode allowTnt, allowCrystal, allowFireball, allowCreeper, allowMinecart, allowWither, allowBlock;
/**
* Constructs a world configuration for explosions.
* Note that if the data file is null or does not exist it will create
* a new instance of this class instead of loading the data.
*
* @param world World
*/
public ExplosionConfiguration(World world) {
try {
File file = new File("plugins/ExplosionsControl/worldconfigurations/" + world.getName() + ".yml");
if (!file.getParentFile().exists()) file.getParentFile().mkdirs();
if (!file.exists()) {
file.createNewFile();
this.world = world.getName();
this.allowTnt = ExplosionMode.ENABLED;
this.allowCrystal = ExplosionMode.ENABLED;
this.allowFireball = ExplosionMode.ENABLED;
this.allowCreeper = ExplosionMode.ENABLED;
this.allowMinecart = ExplosionMode.ENABLED;
this.allowWither = ExplosionMode.ENABLED;
this.allowBlock = ExplosionMode.ENABLED;
return;
}
FileConfiguration data = YamlConfiguration.loadConfiguration(file);
this.world = data.getString("worldconfig.world");
this.allowTnt = ExplosionMode.valueOf(data.getString("worldconfig.allowTnt").toUpperCase());
this.allowCrystal = ExplosionMode.valueOf(data.getString("worldconfig.allowCrystal").toUpperCase());
this.allowFireball = ExplosionMode.valueOf(data.getString("worldconfig.allowFireball").toUpperCase());
this.allowCreeper = ExplosionMode.valueOf(data.getString("worldconfig.allowCreeper").toUpperCase());
this.allowMinecart = ExplosionMode.valueOf(data.getString("worldconfig.allowMinecart").toUpperCase());
this.allowWither = ExplosionMode.valueOf(data.getString("worldconfig.allowWither").toUpperCase());
this.allowBlock = ExplosionMode.valueOf(data.getString("worldconfig.allowBlock").toUpperCase());
} catch (Exception exception) {
Bukkit.getLogger().warning(exception.toString());
}
}
/**
* Save the current configuration to a file config.
*/
public void save() {
try {
File file = new File("plugins/ExplosionsControl/worldconfigurations/" + world + ".yml");
if (!file.getParentFile().exists()) file.getParentFile().mkdirs();
if (!file.exists()) file.createNewFile();
FileConfiguration data = YamlConfiguration.loadConfiguration(file);
data.set("worldconfig.world",world);
data.set("worldconfig.allowBlock",allowBlock.name());
data.set("worldconfig.allowCreeper",allowCreeper.name());
data.set("worldconfig.allowCrystal",allowCrystal.name());
data.set("worldconfig.allowFireball",allowFireball.name());
data.set("worldconfig.allowMinecart",allowMinecart.name());
data.set("worldconfig.allowTnt",allowTnt.name());
data.set("worldconfig.allowWither",allowWither.name());
data.save(file);
} catch (Exception exception) {
Bukkit.getLogger().warning(exception.toString());
}
}
public void setWorld(String world) {
this.world = world;
}
public void setAllowBlock(ExplosionMode allowBlock) {
this.allowBlock = allowBlock;
}
public void setAllowCreeper(ExplosionMode allowCreeper) {
this.allowCreeper = allowCreeper;
}
public void setAllowCrystal(ExplosionMode allowCrystal) {
this.allowCrystal = allowCrystal;
}
public void setAllowFireball(ExplosionMode allowFireball) {
this.allowFireball = allowFireball;
}
public void setAllowMinecart(ExplosionMode allowMinecart) {
this.allowMinecart = allowMinecart;
}
public void setAllowTnt(ExplosionMode allowTnt) {
this.allowTnt = allowTnt;
}
public void setAllowWither(ExplosionMode allowWither) {
this.allowWither = allowWither;
}
public String getWorld() {
return world;
}
public ExplosionMode getAllowBlock() {
return allowBlock;
}
public ExplosionMode getAllowCreeper() {
return allowCreeper;
}
public ExplosionMode getAllowCrystal() {
return allowCrystal;
}
public ExplosionMode getAllowFireball() {
return allowFireball;
}
public ExplosionMode getAllowMinecart() {
return allowMinecart;
}
public ExplosionMode getAllowTnt() {
return allowTnt;
}
public ExplosionMode getAllowWither() {
return allowWither;
}
}

View File

@@ -0,0 +1,17 @@
package me.improper.explosionscontrol.data;
import java.io.Serializable;
public enum ExplosionMode implements Serializable {
ENABLED(0),
DISABLED(1),
DYNAMIC(2),
NONE(3);
private final int index;
ExplosionMode(int index) {
this.index = index;
}
}

View File

@@ -0,0 +1,35 @@
package me.improper.explosionscontrol.data;
import me.improper.explosionscontrol.other.Item;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
public class ExplosionToggle {
public static Inventory EXPLOSIONMENU;
/**
* This will prepare the ExplosionsControl main toggle menu.
* Server staff members will be able to edit explosion configurations
* through this menu!
*/
public static void setup() {
Inventory menu = Bukkit.createInventory(null,54,"Explosions");
Item reload = new Item(new ItemStack(Material.COMPASS));
reload.setDisplayName(ChatColor.AQUA + "Load Worlds");
menu.setContents(new ItemStack[]{
});
menu.addItem(reload);
EXPLOSIONMENU = menu;
}
}

View File

@@ -0,0 +1,208 @@
package me.improper.explosionscontrol.events;
import me.improper.explosionscontrol.data.ExplosionConfiguration;
import me.improper.explosionscontrol.data.ExplosionMode;
import me.improper.explosionscontrol.other.ServerSound;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockExplodeEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.util.Vector;
public class OnExplode implements Listener {
@EventHandler
public static void EntityExplodeEvent(EntityExplodeEvent e) {
Entity entity = e.getEntity();
Location loc = e.getLocation();
World world = loc.getWorld();
ExplosionConfiguration configuration = new ExplosionConfiguration(world);
ServerSound explosion = new ServerSound(e.getLocation(),Sound.ENTITY_GENERIC_EXPLODE,10,0.7F);
switch (entity.getType()) {
case PRIMED_TNT -> {
switch (configuration.getAllowTnt()) {
case DISABLED -> {
e.setCancelled(true);
explosion.playWithin(5000);
}
case NONE -> {
e.setCancelled(true);
}
case DYNAMIC -> {
for (Block block : e.blockList()) launchBlock(block, loc);
}
}
}
case FIREBALL,DRAGON_FIREBALL,SMALL_FIREBALL -> {
switch (configuration.getAllowFireball()) {
case DISABLED -> {
e.setCancelled(true);
explosion.playWithin(5000);
}
case NONE -> {
e.setCancelled(true);
}
case DYNAMIC -> {
for (Block block : e.blockList()) launchBlock(block, loc);
}
}
}
case CREEPER -> {
switch (configuration.getAllowCreeper()) {
case DISABLED -> {
e.setCancelled(true);
explosion.playWithin(5000);
}
case NONE -> {
e.setCancelled(true);
}
case DYNAMIC -> {
for (Block block : e.blockList()) launchBlock(block, loc);
}
}
}
case ENDER_CRYSTAL -> {
switch (configuration.getAllowCrystal()) {
case DISABLED -> {
e.setCancelled(true);
explosion.playWithin(5000);
}
case NONE -> {
e.setCancelled(true);
}
case DYNAMIC -> {
for (Block block : e.blockList()) launchBlock(block, loc);
}
}
}
case MINECART_TNT -> {
switch (configuration.getAllowMinecart()) {
case DISABLED -> {
e.setCancelled(true);
explosion.playWithin(5000);
}
case NONE -> {
e.setCancelled(true);
}
case DYNAMIC -> {
for (Block block : e.blockList()) launchBlock(block, loc);
}
}
}
case WITHER_SKULL -> {
switch (configuration.getAllowWither()) {
case DISABLED -> {
e.setCancelled(true);
explosion.playWithin(5000);
}
case NONE -> {
e.setCancelled(true);
}
case DYNAMIC -> {
for (Block block : e.blockList()) launchBlock(block, loc);
}
}
}
}
}
@EventHandler
public static void BlockExplodeEvent(BlockExplodeEvent e) {
Block block = e.getBlock();
Location loc = block.getLocation();
World world = loc.getWorld();
ExplosionConfiguration configuration = new ExplosionConfiguration(world);
ServerSound explosion = new ServerSound(block.getLocation(),Sound.ENTITY_GENERIC_EXPLODE,10,0.7F);
switch (configuration.getAllowBlock()) {
case DISABLED -> {
e.setCancelled(true);
explosion.playWithin(5000);
}
case NONE -> {
e.setCancelled(true);
}
case DYNAMIC -> {
for (Block b : e.blockList()) launchBlock(b, loc);
}
}
}
@EventHandler
public static void EntityDamageByEntityEvent(EntityDamageByEntityEvent e) {
try {
Entity damager = e.getDamager();
Location loc = e.getDamager().getLocation();
World world = loc.getWorld();
ExplosionConfiguration configuration = new ExplosionConfiguration(world);
switch (damager.getType()) {
case PRIMED_TNT -> {
if (configuration.getAllowTnt().equals(ExplosionMode.NONE)) e.setCancelled(true);
}
case FIREBALL,DRAGON_FIREBALL,SMALL_FIREBALL -> {
if (configuration.getAllowFireball().equals(ExplosionMode.NONE)) e.setCancelled(true);
}
case CREEPER -> {
if (configuration.getAllowCreeper().equals(ExplosionMode.NONE)) e.setCancelled(true);
}
case ENDER_CRYSTAL -> {
if (configuration.getAllowCrystal().equals(ExplosionMode.NONE)) e.setCancelled(true);
}
case MINECART_TNT -> {
if (configuration.getAllowMinecart().equals(ExplosionMode.NONE)) e.setCancelled(true);
}
case WITHER_SKULL -> {
if (configuration.getAllowWither().equals(ExplosionMode.NONE)) e.setCancelled(true);
}
}
} catch (Exception exception) {}
}
@EventHandler
public static void EntityDamageEvent(EntityDamageEvent e) {
try {
Entity entity = e.getEntity();
Location loc = entity.getLocation();
World world = loc.getWorld();
ExplosionConfiguration configuration = new ExplosionConfiguration(world);
EntityDamageEvent.DamageCause cause = e.getCause();
switch (cause) {
case BLOCK_EXPLOSION -> {
if (configuration.getAllowBlock().equals(ExplosionMode.NONE)) e.setCancelled(true);
}
}
} catch (Exception exception) {}
}
/**
* Attempts to launch a block as a falling block according to its original location
* This feature is in beta, expect many bugs!
*
* @param block Block
* @param origin Location
*/
public static void launchBlock(Block block, Location origin) {
Location loc = block.getLocation();
Vector vector = origin
.toVector()
.subtract(loc.toVector())
.normalize()
.add(new Vector(0,1,0))
.multiply(new Vector(-0.7,0.7,-0.7));
FallingBlock fb = origin.getWorld().spawnFallingBlock(block.getLocation(),block.getBlockData());
fb.setVelocity(vector);
block.setType(Material.AIR);
}
}

View File

@@ -0,0 +1,110 @@
package me.improper.explosionscontrol.other;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.List;
import java.util.Set;
public class Item extends ItemStack {
private ItemMeta meta = super.getItemMeta();
/**
* This creates in instance of this class, which is an extension
* or the ItemStack class, aiming to simplify the process of
* modifying an item's item meta.
*
* @param itemStack ItemStack
*/
public Item(ItemStack itemStack) {
super(itemStack);
}
/**
* Set the display name of an item.
*
* @param displayName String
*/
public void setDisplayName(String displayName) {
meta.setDisplayName(displayName);
super.setItemMeta(meta);
}
/**
* Set the lore of an item.
*
* @param lore List<String></String>
*/
public void setLore(List<String> lore) {
meta.setLore(lore);
super.setItemMeta(meta);
}
/**
* Adds item flags to an item.
*
* @param flag ItemFlag...
*/
public void addItemFlags(ItemFlag... flag) {
meta.addItemFlags(flag);
super.setItemMeta(meta);
}
/**
* Sets the unbreakable state of an item.
*
* @param unbreakable boolean
*/
public void setUnbreakable(boolean unbreakable) {
meta.setUnbreakable(unbreakable);
super.setItemMeta(meta);
}
/**
* Sets the custom model data of an item.
*
* @param customModelData String
*/
public void setCustomModelData(int customModelData) {
meta.setCustomModelData(customModelData);
super.setItemMeta(meta);
}
/**
* Returns the display name of the item.
*
* @return A string as the display name.
*/
public String getDisplayName() {
return meta.getDisplayName();
}
/**
* Returns the lore of the item.
*
* @return A string array as the lore.
*/
public List<String> getLore() {
return meta.getLore();
}
/**
* Returns an array of the items flags of the item.
*
* @return An array of the item flags.
*/
public Set<ItemFlag> getItemFlags() {
return meta.getItemFlags();
}
/**
* Returns the custom model data of the item.
*
* @return The custom model data of the item.
*/
public int getCustomModelData() {
return meta.getCustomModelData();
}
}

View File

@@ -0,0 +1,178 @@
package me.improper.explosionscontrol.other;
import me.improper.explosionscontrol.ExplosionsControl;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
public class ServerSound {
private Location location;
private Sound sound;
private float volume;
private float pitch;
public ServerSound(Location location, Sound sound, float volume, float pitch) {
this.location = location;
this.sound = sound;
this.pitch = pitch;
this.volume = volume;
}
public void play(Player player) {
player.playSound(this.location,this.sound,this.volume,this.pitch);
}
public void playAt(Player player) {
player.playSound(player.getLocation(),this.sound,this.volume,this.pitch);
}
public void playWithin(double distance) {
for (Player p : Bukkit.getOnlinePlayers()) {
if (p != null && p.getWorld() == this.location.getWorld() && p.getLocation().distanceSquared(this.location) < distance) {
p.playSound(this.location,this.sound,this.volume,this.pitch);
}
}
}
public void playWithinAt(double distance) {
for (Player p : Bukkit.getOnlinePlayers()) {
if (p != null && p.getWorld() == this.location.getWorld() && p.getLocation().distanceSquared(this.location) < distance) {
p.playSound(p.getLocation(),this.sound,this.volume,this.pitch);
}
}
}
public void playAll() {
for (Player p : Bukkit.getOnlinePlayers()) p.playSound(this.location,this.sound,this.volume,this.pitch);
}
public void playAllAt() {
for (Player p : Bukkit.getOnlinePlayers()) p.playSound(p.getLocation(),this.sound,this.volume,this.pitch);
}
public void repeat(Player player, int times, int tickDelay) {
new BukkitRunnable() {
int i = 0;
@Override
public void run() {
if (i < times) {
play(player);
i ++;
} else {
this.cancel();
}
}
}.runTaskTimer(ExplosionsControl.getInstance(),0,tickDelay);
}
public void repeatAt(Player player, int times, int tickDelay) {
new BukkitRunnable() {
int i = 0;
@Override
public void run() {
if (i < times) {
playAt(player);
i ++;
} else {
this.cancel();
}
}
}.runTaskTimer(ExplosionsControl.getInstance(),0,tickDelay);
}
public void repeatAll(int times, int tickDelay) {
new BukkitRunnable() {
int i = 0;
@Override
public void run() {
if (i < times) {
playAll();
i ++;
} else {
this.cancel();
}
}
}.runTaskTimer(ExplosionsControl.getInstance(),0,tickDelay);
}
public void repeatAllAt(int times, int tickDelay) {
new BukkitRunnable() {
int i = 0;
@Override
public void run() {
if (i < times) {
playAllAt();
i ++;
} else {
this.cancel();
}
}
}.runTaskTimer(ExplosionsControl.getInstance(),0,tickDelay);
}
public void repeatAll(double radius,int times, int tickDelay) {
new BukkitRunnable() {
int i = 0;
@Override
public void run() {
if (i < times) {
playWithin(radius);
i ++;
} else {
this.cancel();
}
}
}.runTaskTimer(ExplosionsControl.getInstance(),0,tickDelay);
}
public void repeatAllAt(double distance, int times, int tickDelay) {
new BukkitRunnable() {
int i = 0;
@Override
public void run() {
if (i < times) {
playWithinAt(distance);
i ++;
} else {
this.cancel();
}
}
}.runTaskTimer(ExplosionsControl.getInstance(),0,tickDelay);
}
public Sound getSound() {
return sound;
}
public float getPitch() {
return pitch;
}
public float getVolume() {
return volume;
}
public Location getLocation() {
return location;
}
public void setPitch(float pitch) {
this.pitch = pitch;
}
public void setVolume(float volume) {
this.volume = volume;
}
public void setSound(Sound sound) {
this.sound = sound;
}
public void setLocation(Location location) {
this.location = location;
}
}

View File

@@ -0,0 +1,18 @@
#
#
# This is ExplosionsControl by ImproperIssues
#
# Please note that all the explosions configurations have been moved to
# "plugins/ExplosionsControl/worldconfigurations" and are no longer
# configured through this config!
#
#
#
# If you do enjoy this plugin, please star it on github!
# Visit and star https://github.com/ItziSpyder/ExplosionsControl
#
#
config:
plugin:
prefix: '§7[§eExplosions§6Control§7] §'

View File

@@ -0,0 +1,16 @@
name: ExplosionsControl
version: '${version}'
main: me.improper.explosionscontrol.ExplosionsControl
api-version: 1.17
authors: [ ImproperIssues ]
description: Manager server explosions with just a few simple clicks!
website: github.com/ItziSpyder
commands:
explosions:
description: Opens up the explosions toggle menu
usage: /explosions
permission: explosionscontrol.commands.explosions
loadworlds:
description: Loads in all the configuration files in case they didn't load
usage: /loadworlds
permission: explosionscontrol.commands.loadworlds