Skip to content

Commit 0440dd3

Browse files
authored
Add files via upload
0 parents  commit 0440dd3

File tree

4 files changed

+135
-0
lines changed

4 files changed

+135
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package me.johns.tntspawner;
2+
3+
import org.bukkit.Bukkit;
4+
import org.bukkit.entity.EntityType;
5+
import org.bukkit.entity.Player;
6+
7+
public class TntTask implements Runnable{
8+
9+
private static final TntTask instance = new TntTask();
10+
11+
private static boolean enabled = false;
12+
13+
private TntTask() {
14+
}
15+
16+
@Override
17+
public void run() {
18+
19+
if (enabled) {
20+
for (Player player : Bukkit.getOnlinePlayers()) {
21+
22+
player.getWorld().spawnEntity(player.getLocation(), EntityType.TNT);
23+
}
24+
}
25+
}
26+
27+
public static void enableSpawns() {
28+
enabled = true;
29+
}
30+
31+
public static void disableSpawns() {
32+
enabled = false;
33+
}
34+
35+
public static boolean isEnabled() {
36+
return enabled;
37+
}
38+
39+
public static TntTask getInstance() {
40+
return instance;
41+
}
42+
43+
44+
}
45+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package me.johns.tntspawner;
2+
3+
import org.bukkit.plugin.java.JavaPlugin;
4+
import org.bukkit.scheduler.BukkitTask;
5+
6+
public final class Tntspawner extends JavaPlugin {
7+
8+
private BukkitTask task;
9+
10+
@Override
11+
public void onEnable() {
12+
// Plugin startup logic
13+
getLogger().info("TNT Spawner is running");
14+
15+
getCommand("tnt").setExecutor(new TntspawnerCommand());
16+
17+
task = getServer().getScheduler().runTaskTimer(this, TntTask.getInstance(), 0, 20 * 6);
18+
19+
}
20+
21+
@Override
22+
public void onDisable() {
23+
// Plugin shutdown logic
24+
TntTask.disableSpawns();
25+
26+
getLogger().info("TNT Spawner has stopped");
27+
}
28+
29+
public static Tntspawner getInstance() {
30+
return getPlugin(Tntspawner.class);
31+
}
32+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package me.johns.tntspawner;
2+
3+
import org.bukkit.command.Command;
4+
import org.bukkit.command.CommandExecutor;
5+
import org.bukkit.command.CommandSender;
6+
import org.bukkit.command.TabExecutor;
7+
import org.bukkit.entity.Player;
8+
import org.jetbrains.annotations.NotNull;
9+
import org.jetbrains.annotations.Nullable;
10+
11+
import java.util.List;
12+
13+
public class TntspawnerCommand implements CommandExecutor, TabExecutor {
14+
15+
@Override
16+
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
17+
18+
if (!(sender instanceof Player)) {
19+
sender.sendMessage("Only a player can use this command");
20+
21+
return false;
22+
}
23+
24+
if (args.length > 1) {
25+
sender.sendMessage("There are no arguments for this command");
26+
27+
return false;
28+
}
29+
30+
if (TntTask.isEnabled()) {
31+
TntTask.disableSpawns();
32+
sender.sendMessage("TNT Spawning disabled");
33+
}
34+
else {
35+
TntTask.enableSpawns();
36+
sender.sendMessage("TNT Spawning enabled");
37+
}
38+
39+
return true;
40+
}
41+
42+
@Override
43+
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
44+
return List.of();
45+
}
46+
}

src/main/resources/plugin.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: tntspawner
2+
version: '1.0.0'
3+
main: me.johns.tntspawner.Tntspawner
4+
api-version: '1.21'
5+
6+
commands:
7+
tnt:
8+
description: "enable/disable tnt spawning"
9+
usage: "/tnt"
10+
aliases:
11+
permission: cowcannon.command.cow
12+
permission-message: "You do not have permission to use this command"

0 commit comments

Comments
 (0)