Skip to content

Commit 3d375d2

Browse files
committed
Added /bonusblocks reload command
1 parent 74ca0c2 commit 3d375d2

7 files changed

Lines changed: 51 additions & 12 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>io.alerium</groupId>
88
<artifactId>BonusBlocks</artifactId>
9-
<version>1.0-SNAPSHOT</version>
9+
<version>1.1-SNAPSHOT</version>
1010

1111
<build>
1212
<plugins>

src/main/java/io/alerium/bonusblocks/BonusBlocksPlugin.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import io.alerium.bonusblocks.blocks.listeners.BonusBlockListener;
77
import io.alerium.bonusblocks.commands.AddBlockCommand;
88
import io.alerium.bonusblocks.commands.ListCommand;
9+
import io.alerium.bonusblocks.commands.ReloadCommand;
910
import io.alerium.bonusblocks.commands.RemoveBlockCommand;
1011
import io.alerium.bonusblocks.integrations.PlaceholderAPI;
1112
import io.alerium.bonusblocks.playerdata.PlayerDataManager;
@@ -78,7 +79,12 @@ private void registerListeners() {
7879
}
7980

8081
private void registerCommands() {
81-
getCommand("bonusblocks").setExecutor(new Command(messages.getMessage("commands.help").format(), Arrays.asList(new ListCommand(), new AddBlockCommand(), new RemoveBlockCommand())));
82+
getCommand("bonusblocks").setExecutor(new Command(Arrays.asList(
83+
new ListCommand(),
84+
new AddBlockCommand(),
85+
new RemoveBlockCommand(),
86+
new ReloadCommand()
87+
)));
8288
}
8389

8490
private void registerIntegrations() {

src/main/java/io/alerium/bonusblocks/blocks/BonusBlockManager.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,25 @@ public class BonusBlockManager {
2929
* This method enables the BonusBlockManager
3030
*/
3131
public void enable() {
32-
minTime = (int) new TimeAPI(plugin.getConfiguration().getConfig().getString("change-block-range.min")).getMilliseconds();
33-
maxTime = (int) new TimeAPI(plugin.getConfiguration().getConfig().getString("change-block-range.max")).getMilliseconds();
34-
amount = plugin.getConfiguration().getConfig().getInt("change-block-range.amount");
32+
reload();
3533

36-
loadBlocks();
37-
3834
new ParticleTask().runTaskTimer(plugin, 10, 10);
3935
new BlockSpawnTask().runTaskTimer(plugin, 20*60, 20*60);
4036
}
4137

38+
/**
39+
* This plugin reloads all the information from the config
40+
*/
41+
public void reload() {
42+
minTime = (int) new TimeAPI(plugin.getConfiguration().getConfig().getString("change-block-range.min")).getMilliseconds();
43+
maxTime = (int) new TimeAPI(plugin.getConfiguration().getConfig().getString("change-block-range.max")).getMilliseconds();
44+
amount = plugin.getConfiguration().getConfig().getInt("change-block-range.amount");
45+
46+
despawnAll();
47+
blocks.clear();
48+
loadBlocks();
49+
}
50+
4251
/**
4352
* This method despawns all the BonusBlock(s)
4453
*/
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package io.alerium.bonusblocks.commands;
2+
3+
import io.alerium.bonusblocks.BonusBlocksPlugin;
4+
import io.alerium.bonusblocks.utils.commands.SubCommand;
5+
import org.bukkit.command.CommandSender;
6+
7+
public class ReloadCommand extends SubCommand {
8+
9+
private final BonusBlocksPlugin plugin = BonusBlocksPlugin.getInstance();
10+
11+
public ReloadCommand() {
12+
super("reload", "bonusblocks.command.reload", false);
13+
}
14+
15+
@Override
16+
public void execute(CommandSender sender, String[] args) {
17+
plugin.getConfiguration().reload();
18+
plugin.getMessages().reload();
19+
20+
plugin.getBonusBlockManager().reload();
21+
plugin.getMessages().getMessage("commands.reload").format().send(sender);
22+
}
23+
24+
}

src/main/java/io/alerium/bonusblocks/utils/commands/Command.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.alerium.bonusblocks.utils.commands;
22

33
import io.alerium.bonusblocks.BonusBlocksPlugin;
4-
import io.alerium.bonusblocks.utils.configuration.Message;
54
import lombok.RequiredArgsConstructor;
65
import org.bukkit.command.CommandExecutor;
76
import org.bukkit.command.CommandSender;
@@ -15,13 +14,12 @@ public class Command implements CommandExecutor {
1514

1615
private final BonusBlocksPlugin plugin = BonusBlocksPlugin.getInstance();
1716

18-
private final Message helpMessage;
1917
private final List<SubCommand> commands;
2018

2119
@Override
2220
public boolean onCommand(CommandSender sender, org.bukkit.command.Command command, String label, String[] args) {
2321
if (args.length == 0) {
24-
helpMessage.send(sender);
22+
plugin.getMessages().getMessage("commands.help").format().send(sender);
2523
return true;
2624
}
2725

src/main/resources/messages.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ commands:
66
- '&a/bonusblocks add'
77
- '&a/bonusblocks remove'
88
- '&a/bonusblocks list'
9+
- '&a/bonusblocks reload'
910
add:
1011
alreadyBonusBlock: '&cThis block is already a bonus block'
1112
noBonusBlockType: '&cThis block doesn''t have the right block type'
@@ -17,4 +18,5 @@ commands:
1718
usage: '&cUsage: /bonusblocks list <radius>'
1819
radiusNotValid: '&cRadius is not valid'
1920
noBlocksFound: '&cThere aren''t bonus blocks near you'
20-
blockFound: '&a%x %y %z'
21+
blockFound: '&a%x %y %z'
22+
reload: '&aPlugin reloaded'

src/main/resources/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: BonusBlocks
22
author: xQuickGlare
3-
version: 1.0
3+
version: 1.1
44
depend: [HolographicDisplays, PlaceholderAPI]
55
main: io.alerium.bonusblocks.BonusBlocksPlugin
66
api-version: 1.15

0 commit comments

Comments
 (0)