Compare commits

...

12 Commits

21 changed files with 47 additions and 41 deletions

5
.gitignore vendored Normal file

@ -0,0 +1,5 @@
build
.idea
.gradle
gradle
.gradle/

Binary file not shown.

Binary file not shown.

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings"> <component name="GradleSettings">
<option name="linkedExternalProjectsSettings"> <option name="linkedExternalProjectsSettings">
<GradleProjectSettings> <GradleProjectSettings>

@ -3,7 +3,7 @@ plugins {
} }
group = 'org.twipnetwork' group = 'org.twipnetwork'
version = '1.0-SNAPSHOT' version = '1.6-1.21'
repositories { repositories {
mavenCentral() mavenCentral()

@ -4,6 +4,3 @@ boostPower: 4.0
# damageShooter defines whether the shooter gets damages by their own fireworks (default: false) # damageShooter defines whether the shooter gets damages by their own fireworks (default: false)
damageShooter: false damageShooter: false
# damageOthers defines whether other people (excluding the shooter) get damaged (default: true)
damageOthers: true

@ -1,4 +0,0 @@
name: RocketJumping
version: '1.0-SNAPSHOT'
main: org.twipnetwork.rocketJumping.RocketJumping
api-version: '1.21'

@ -1,6 +1,7 @@
package org.twipnetwork.rocketJumping; package org.twipnetwork.rocketJumping;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.*;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -12,19 +13,17 @@ import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.Objects;
public final class RocketJumping extends JavaPlugin implements Listener { public final class RocketJumping extends JavaPlugin implements Listener {
private double boostPower; private double boostPower;
private boolean damageShooter; private boolean damageShooter;
private boolean damageOthers;
@Override @Override
public void onEnable() { public void onEnable() {
saveDefaultConfig(); saveDefaultConfig();
FileConfiguration config = getConfig(); loadConfigValues();
boostPower = config.getDouble("boostPower", 4.0);
damageShooter = config.getBoolean("damageShooter", false);
damageOthers = config.getBoolean("damageOthers", true);
Bukkit.getPluginManager().registerEvents(this, this); Bukkit.getPluginManager().registerEvents(this, this);
} }
@ -32,36 +31,41 @@ public final class RocketJumping extends JavaPlugin implements Listener {
public void onDisable() { public void onDisable() {
} }
private void loadConfigValues() {
FileConfiguration config = getConfig();
boostPower = config.getDouble("boostPower", 4.0);
damageShooter = config.getBoolean("damageShooter", false);
}
@EventHandler @EventHandler
public void onProjectileHit(ProjectileHitEvent event) { public void onProjectileHit(ProjectileHitEvent event) {
Projectile projectile = event.getEntity(); Projectile projectile = event.getEntity();
if (projectile instanceof Firework) { if (projectile instanceof Firework firework) {
Firework firework = (Firework) projectile;
Entity shooter = (Entity) firework.getShooter(); Entity shooter = (Entity) firework.getShooter();
for (Entity entity : firework.getNearbyEntities(5, 5, 5)) { for (Entity entity : firework.getNearbyEntities(5, 5, 5)) {
if (entity instanceof Player) {
Player player = (Player) entity;
Vector boostDirection = player.getLocation().toVector().subtract(firework.getLocation().toVector()).normalize();
player.setVelocity(player.getVelocity().add(boostDirection.multiply(boostPower)));
if (!damageShooter && player.equals(shooter)) {
player.setNoDamageTicks(1);
}
} else {
Vector boostDirection = entity.getLocation().toVector().subtract(firework.getLocation().toVector()).normalize(); Vector boostDirection = entity.getLocation().toVector().subtract(firework.getLocation().toVector()).normalize();
entity.setVelocity(entity.getVelocity().add(boostDirection.multiply(boostPower))); entity.setVelocity(entity.getVelocity().add(boostDirection.multiply(boostPower)));
if (entity instanceof Player player && !damageShooter && player.equals(shooter)) {
player.setNoDamageTicks(1);
}
}
} }
} }
if (!damageOthers) { @Override
for (Entity entity : firework.getNearbyEntities(5, 5, 5)) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(entity instanceof Player && entity.equals(shooter))) { if (command.getName().equalsIgnoreCase("rocketjumping")) {
((Player) entity).setNoDamageTicks(1); if (args.length > 0 && args[0].equalsIgnoreCase("reload")) {
} reloadConfig();
} loadConfigValues();
sender.sendMessage("§aRocketJumping config reloaded!");
return true;
} }
} }
return false;
} }
} }

@ -4,6 +4,3 @@ boostPower: 4.0
# damageShooter defines whether the shooter gets damages by their own fireworks (default: false) # damageShooter defines whether the shooter gets damages by their own fireworks (default: false)
damageShooter: false damageShooter: false
# damageOthers defines whether other people (excluding the shooter) get damaged (default: true)
damageOthers: true

@ -1,4 +0,0 @@
name: RocketJumping
version: '1.0-SNAPSHOT'
main: org.twipnetwork.rocketJumping.RocketJumping
api-version: '1.21'

@ -0,0 +1,10 @@
name: RocketJumping
version: '1.6-1.21'
main: org.twipnetwork.rocketJumping.RocketJumping
api-version: 1.21
commands:
rocketjumping:
description: Reloads the RocketJumping configuration.
usage: /<command> reload
permission: rocketjumpingo.reload
permission-message: You do not have permission to execute this command.