Skip to content

Commit

Permalink
Force skip command + 1.6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
nkomarn committed Sep 29, 2020
1 parent c5d76a7 commit 4d15887
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 46 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>xyz.nkomarn</groupId>
<artifactId>Harbor</artifactId>
<version>1.6.2-SNAPSHOT</version>
<version>1.6.2</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/xyz/nkomarn/harbor/Harbor.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import xyz.nkomarn.harbor.command.ForceSkipCommand;
import xyz.nkomarn.harbor.command.HarborCommand;
import xyz.nkomarn.harbor.listener.BedListener;
import xyz.nkomarn.harbor.listener.PlayerListener;
Expand Down Expand Up @@ -44,6 +45,7 @@ public void onEnable() {
).forEach(listener -> pluginManager.registerEvents(listener, this));

getCommand("harbor").setExecutor(new HarborCommand(this));
getCommand("forceskip").setExecutor(new ForceSkipCommand(this));

if (essentials == null) {
getLogger().info("Essentials not present- registering fallback AFK detection system.");
Expand Down
43 changes: 43 additions & 0 deletions src/main/java/xyz/nkomarn/harbor/command/ForceSkipCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package xyz.nkomarn.harbor.command;

import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import xyz.nkomarn.harbor.Harbor;
import xyz.nkomarn.harbor.task.Checker;
import xyz.nkomarn.harbor.util.Config;

public class ForceSkipCommand implements CommandExecutor {

private final Harbor harbor;
private final Config config;

public ForceSkipCommand(@NotNull Harbor harbor) {
this.harbor = harbor;
this.config = harbor.getConfiguration();
}

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(config.getPrefix() + "This command can only be used by a player.");
return true;
}

Player player = (Player) sender;
World world = player.getWorld();
Checker checker = harbor.getChecker();

if (checker.isSkipping(world)) {
sender.sendMessage(config.getPrefix() + "This world's time is already being accelerated.");
} else {
sender.sendMessage(config.getPrefix() + "Forcing night skip in your world.");
checker.forceSkip(world);
}

return true;
}
}
39 changes: 7 additions & 32 deletions src/main/java/xyz/nkomarn/harbor/command/HarborCommand.java
Original file line number Diff line number Diff line change
@@ -1,64 +1,39 @@
package xyz.nkomarn.harbor.command;

import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import xyz.nkomarn.harbor.Harbor;
import xyz.nkomarn.harbor.task.Checker;
import xyz.nkomarn.harbor.util.Config;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class HarborCommand implements TabExecutor {

private final Harbor harbor;
private final Config config;

public HarborCommand(@NotNull Harbor harbor) {
this.harbor = harbor;
this.config = harbor.getConfiguration();
}

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
Config config = harbor.getConfiguration();
String prefix = ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.chat-prefix"));

if (args.length < 1 || !sender.hasPermission("harbor.admin")) {
sender.sendMessage(prefix + "Harbor " + harbor.getVersion() + " by TechToolbox (@nkomarn).");
sender.sendMessage(config.getPrefix() + "Harbor " + harbor.getVersion() + " by TechToolbox (@nkomarn).");
return true;
}

if (args[0].equalsIgnoreCase("reload")) {
config.reload();
sender.sendMessage(prefix + "Reloaded configuration.");
return true;
}

if (args[0].equalsIgnoreCase("forceskip")) {
if (!(sender instanceof Player)) {
sender.sendMessage(prefix + "This command can only be used by a player.");
return true;
}

Player player = (Player) sender;
World world = player.getWorld();
Checker checker = harbor.getChecker();

if (checker.isSkipping(world)) {
sender.sendMessage(prefix + "This world's time is already being accelerated.");
} else {
sender.sendMessage(prefix + "Forcing night skip in your world.");
checker.forceSkip(world);
}

sender.sendMessage(config.getPrefix() + "Reloaded configuration.");
return true;
}

sender.sendMessage(prefix + config.getString("messages.miscellaneous.unrecognized-command"));
sender.sendMessage(config.getPrefix() + config.getString("messages.miscellaneous.unrecognized-command"));
return true;
}

Expand All @@ -72,6 +47,6 @@ public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Comman
return null;
}

return Arrays.asList("forceskip", "reload");
return Collections.singletonList("reload");
}
}
10 changes: 10 additions & 0 deletions src/main/java/xyz/nkomarn/harbor/util/Config.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package xyz.nkomarn.harbor.util;

import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import org.jetbrains.annotations.NotNull;
import xyz.nkomarn.harbor.Harbor;
Expand Down Expand Up @@ -32,6 +33,15 @@ public void reload() {
harbor.reloadConfig();
}

/**
* Returns the prefix for Harbor messages.
* @return Harbor message prefix.
*/
@NotNull
public String getPrefix() {
return ChatColor.translateAlternateColorCodes('&', getString("messages.miscellaneous.chat-prefix"));
}

/**
* Fetches a boolean from the configuration
* if location is not found, false is returned
Expand Down
34 changes: 21 additions & 13 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
name: Harbor
description: Harbor is a Spigot plugin that redefines how sleep works in your server, making it easier for all the online players to get in bed quickly and skip through the night!
main: xyz.nkomarn.harbor.Harbor
version: 1.6.2-SNAPSHOT
author: TechToolbox (@nkomarn)
website: https://nkomarn.xyz
softdepend: [Essentials]
api-version: 1.14
name: "Harbor"
description: "Harbor redefines how sleep works in your server, making it easier for all the online players to get in bed quickly and skip through the night!"
main: "xyz.nkomarn.harbor.Harbor"
author: "TechToolbox (@nkomarn)"
website: "https://nkomarn.xyz"
version: "1.6.2"
api-version: "1.14"

softdepend:
- "Essentials"

commands:
harbor:
description: "Base command for Harbor!"
usage: "/harbor [subcommand]"
description: "Base command for Harbor."
usage: "/harbor <subcommand>"
forceskip:
description: "Allows players to accelerate the night of their current world."
permission: "harbor.forceskip"

permissions:
harbor.ignored:
default: false
harbor.admin:
default: op
default: op
harbor.forceskip:
description: "Permits usage of the /forceskip command."
default: op
harbor.ignored:
default: false

0 comments on commit 4d15887

Please sign in to comment.