Skip to content

Commit

Permalink
Add command executor
Browse files Browse the repository at this point in the history
  • Loading branch information
henry232323 committed Jan 19, 2020
1 parent deec5b0 commit 328c75b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 29 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>henry232323</groupId>
<artifactId>Killstreaks</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.0.1</version>
<packaging>jar</packaging>

<name>Killstreaks</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package henry232323.killstreaks;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;

public class KillstreakCommandExecutor implements CommandExecutor {
Killstreaks plugin;

KillstreakCommandExecutor(Killstreaks plugin) {
this.plugin = plugin;
}


@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
try {
if (args.length != 1) {
String version = plugin.getDescription().getVersion();
sender.sendMessage(ChatColor.GOLD + "Killstreaks Version " + version);
return true;
}
if (args[0].equalsIgnoreCase("reload")) {
plugin.initConfig();
sender.sendMessage(ChatColor.GOLD + "Killstreaks reloaded");
return true;
}

return false;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}
31 changes: 3 additions & 28 deletions src/main/java/henry232323/killstreaks/Killstreaks.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package henry232323.killstreaks;

import com.destroystokyo.paper.Title;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
Expand All @@ -25,7 +22,7 @@ public final class Killstreaks extends JavaPlugin implements Listener {
private HashMap<Integer, String> messages;
private HashMap<Integer, List<String>> commands;

private void initConfig() {
public void initConfig() {
saveDefaultConfig();
FileConfiguration config = getConfig();
worlds = config.getStringList("worlds");
Expand Down Expand Up @@ -63,6 +60,7 @@ private void initConfig() {
public void onEnable() {
// Plugin startup logic
getServer().getPluginManager().registerEvents(this, this);
this.getCommand("killstreaks").setExecutor(new KillstreakCommandExecutor(this));
initConfig();
}

Expand Down Expand Up @@ -118,29 +116,6 @@ public void onPlayerDeath(PlayerDeathEvent event) {
}
}
}
streaks.put(killed, 0);
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
try {
if (command.getName().equalsIgnoreCase("killstreaks")) {
if (args.length != 1) {
String version = getDescription().getVersion();
sender.sendMessage(ChatColor.GOLD + "Killstreaks Version " + version);
return true;
}
if (args[0].equalsIgnoreCase("reload")) {
initConfig();
sender.sendMessage(ChatColor.GOLD + "Killstreaks reloaded");
return true;
}
}

return false;
} catch (Exception e) {
e.printStackTrace();
return false;
}
streaks.remove(killed);
}
}

0 comments on commit 328c75b

Please sign in to comment.