Skip to content

Commit

Permalink
• Added experimental config for thrown TNT velocity—more to come!
Browse files Browse the repository at this point in the history
  • Loading branch information
CoocooFroggy committed Aug 5, 2020
1 parent 9703917 commit 2fd9a4e
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 12 deletions.
Binary file modified out/artifacts/Bomb_Lobbers_jar/Bomb Lobbers.jar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 0 additions & 1 deletion out/production/Bomb Lobbers/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ api-version: 1.13
commands:
bomblobbers:
description: Commands for the Bomb Lobbers plugin
usage: /bomblobbers [enable/disable, start/stop]
aliases: bl
47 changes: 42 additions & 5 deletions src/com/CoocooFroggy/bomblobbers/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public class Main extends JavaPlugin {

@Override
public void onEnable() {
//Set plugin
plugin = this;

//config.yml
plugin.saveDefaultConfig();

getServer().getPluginManager().registerEvents(new RightClickListener(), this);
getServer().getPluginManager().registerEvents(new DeathListener(), this);
getServer().getPluginManager().registerEvents(new WaterListener(), this);
Expand All @@ -44,9 +50,6 @@ public void onEnable() {
DeathListener.teamsAndAlive.put("red", new ArrayList<>());
DeathListener.teamsAndAlive.put("green", new ArrayList<>());

//Set plugin
plugin = this;

super.onEnable();
}

Expand Down Expand Up @@ -120,9 +123,43 @@ public void run() {
mainSwitch = true;
sender.sendMessage(ChatColor.GREEN + "Enabled Bomb Lobbers debug plugin!");
return true;
} else if (args[0].equalsIgnoreCase("config")) {
//MARK: Config
if (args.length < 2) {
//If "/bl config"
sender.sendMessage(ChatColor.RED + "Specify what to config. Options are: " + ChatColor.GOLD + "velocity");
return false;
}
if (args[1].equalsIgnoreCase("velocity")) {
if (args.length < 3) {
//If "/bl config velocity"
sender.sendMessage(ChatColor.RED + "Specify the amount as an integer.");
return false;
}
//If "/bl config velocity _"
float newVelocity;
try {
//If "/bl config velocity [int]"
newVelocity = Float.parseFloat(args[2]);
} catch (Exception e) {
//If "/bl config velocity [Not an int]"
sender.sendMessage(ChatColor.RED + "That is not a number. Please specify a number for the velocity.");
getLogger().info("[Bomb Lobbers] Error: " + e);
return false;
}
//If "/bl config velocity [int]"
plugin.getConfig().set("throw-velocity.current", newVelocity);
plugin.saveConfig();
sender.sendMessage(ChatColor.GREEN + "Successfully set the new velocity to " + newVelocity + "!");
return true;
} else {
//If "/bl config ____"
sender.sendMessage(ChatColor.RED + "That is not a valid config. Options are: " + ChatColor.GOLD + "velocity");
return false;
}
} else {
//Sender didn't type "enable" or "disable"
sender.sendMessage(ChatColor.RED + "Syntax: /bomblobbers [enable/disable, start/stop]");
//Sender didn't type a valid arg
sender.sendMessage(ChatColor.RED + "Syntax: /bomblobbers [enable/disable, start/stop, changeteam, config]");
return true;
}
} else {
Expand Down
8 changes: 5 additions & 3 deletions src/com/CoocooFroggy/bomblobbers/RightClickListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Collection;
import java.util.List;

import static com.CoocooFroggy.bomblobbers.Main.plugin;
import static org.bukkit.Bukkit.getLogger;

public class RightClickListener implements Listener {
Expand Down Expand Up @@ -54,11 +55,12 @@ public boolean onRightClick(PlayerInteractEvent event) {
Entity newTNT = player.getWorld().spawnEntity(player.getEyeLocation(), EntityType.PRIMED_TNT);

//Make TNT go brrr
newTNT.setVelocity(player.getEyeLocation().getDirection().multiply(1.5));
float throwVelocity = plugin.getConfig().getInt("throw-velocity.current");
newTNT.setVelocity(player.getEyeLocation().getDirection().multiply(throwVelocity));

//Start trackng the TNT
DirectHitChecker nonStaticDirectHitTracker = new DirectHitChecker();
Bukkit.getScheduler().runTaskAsynchronously(Main.plugin, new Runnable() {
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
nonStaticDirectHitTracker.trackTNT(newTNT, player);
Expand All @@ -67,7 +69,7 @@ public void run() {

//Set cooldown
cooldown.add(player);
Bukkit.getScheduler().runTaskLater(Main.plugin, new Runnable() {
Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
@Override
public void run() {
cooldown.remove(player);
Expand Down
10 changes: 8 additions & 2 deletions src/com/CoocooFroggy/bomblobbers/TabCompleter.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@
import java.util.Arrays;
import java.util.List;

import static org.bukkit.Bukkit.getLogger;

public class TabCompleter implements org.bukkit.command.TabCompleter {
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
if (label.equalsIgnoreCase("bomblobbers") || label.equalsIgnoreCase("bl")) {
if (args.length > 0) {
return Arrays.asList("enable", "disable", "start", "stop", "changeteam");
if (args.length == 1) {
return Arrays.asList("enable", "disable", "start", "stop", "changeteam", "config");
} else if (args.length == 2) {
if (args[0].contains("config")) {
return Arrays.asList("velocity");
}
}
}
return null;
Expand Down
3 changes: 3 additions & 0 deletions src/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
throw-velocity:
default: 1.5
current:
1 change: 0 additions & 1 deletion src/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ api-version: 1.13
commands:
bomblobbers:
description: Commands for the Bomb Lobbers plugin
usage: /bomblobbers [enable/disable, start/stop]
aliases: bl

0 comments on commit 2fd9a4e

Please sign in to comment.