diff --git a/.vscode/tasks.json b/.vscode/tasks.json index f070ddcc..d519ee2c 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -4,7 +4,7 @@ { "label": "Build plugin", "type": "shell", - "command": "gradle build", + "command": "./gradlew build", "group": "build", "presentation": { "group": "dev" @@ -15,7 +15,7 @@ "type": "shell", "command": "cp", "args": [ - "${workspaceRoot}/target/HCCore.jar", + "${workspaceRoot}/build/libs/HCCore.jar", "$HOME/server/plugins" ], "group": "build", @@ -33,7 +33,8 @@ "group": { "kind": "build", "isDefault": true - } + }, + "problemMatcher": [] }, { "label": "Start server", diff --git a/build.gradle b/build.gradle index 2fe189af..7d947095 100644 --- a/build.gradle +++ b/build.gradle @@ -50,7 +50,7 @@ dependencies { implementation 'de.tr7zw:item-nbt-api:2.8.0' implementation 'net.dv8tion:JDA:4.2.1_265' - compileOnly 'com.comphenix.protocol:ProtocolLib:4.5.1' + implementation 'com.comphenix.protocol:ProtocolLib:4.5.1' compileOnly 'org.spigotmc:spigot-api:1.17-R0.1-SNAPSHOT' compileOnly 'org.spigotmc:spigot:1.17-R0.1-SNAPSHOT' } diff --git a/src/main/java/com/hackclub/hccore/HCCorePlugin.java b/src/main/java/com/hackclub/hccore/HCCorePlugin.java index bcc74085..a04185e1 100644 --- a/src/main/java/com/hackclub/hccore/HCCorePlugin.java +++ b/src/main/java/com/hackclub/hccore/HCCorePlugin.java @@ -10,6 +10,20 @@ import com.comphenix.protocol.events.ListenerPriority; import com.hackclub.hccore.commands.*; import com.hackclub.hccore.discord.DiscordBot; +import com.hackclub.hccore.commands.AFKCommand; +import com.hackclub.hccore.commands.ColorCommand; +import com.hackclub.hccore.commands.DownvoteCommand; + +import com.hackclub.hccore.commands.LocCommand; +import com.hackclub.hccore.commands.NickCommand; +import com.hackclub.hccore.commands.PingCommand; +import com.hackclub.hccore.commands.ShrugCommand; +import com.hackclub.hccore.commands.SpawnCommand; +import com.hackclub.hccore.commands.StatsCommand; +import com.hackclub.hccore.commands.TableflipCommand; +import com.hackclub.hccore.commands.TutorialCommand; + +import com.hackclub.hccore.commands.UpvoteCommand; import com.hackclub.hccore.listeners.AFKListener; import com.hackclub.hccore.listeners.AdvancementListener; import com.hackclub.hccore.listeners.BeehiveInteractionListener; @@ -70,8 +84,10 @@ public void onEnable() { this.getCommand("spawn").setExecutor(new SpawnCommand(this)); this.getCommand("stats").setExecutor(new StatsCommand(this)); this.getCommand("tableflip").setExecutor(new TableflipCommand(this)); + this.getCommand("tutorial").setExecutor(new TutorialCommand(this)); this.getCommand("upvote").setExecutor(new UpvoteCommand(this)); this.getCommand("discord").setExecutor(new DiscordCommand(this)); + this.getCommand("tutorial").setExecutor(new TutorialCommand(this)); // Register event listeners this.getServer().getPluginManager().registerEvents(new AdvancementListener(this), this); diff --git a/src/main/java/com/hackclub/hccore/commands/DiscordCommand.java b/src/main/java/com/hackclub/hccore/commands/DiscordCommand.java index b0b38d0c..77f1723b 100644 --- a/src/main/java/com/hackclub/hccore/commands/DiscordCommand.java +++ b/src/main/java/com/hackclub/hccore/commands/DiscordCommand.java @@ -1,6 +1,10 @@ package com.hackclub.hccore.commands; import com.hackclub.hccore.HCCorePlugin; + +import com.comphenix.protocol.PacketType; +import com.hackclub.hccore.HCCorePlugin; +import com.hackclub.hccore.discord.DiscordBot; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.ChatColor; @@ -8,9 +12,15 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import java.util.List; + public class DiscordCommand implements CommandExecutor { - private HCCorePlugin plugin; + private final HCCorePlugin plugin; public DiscordCommand(HCCorePlugin plugin) { this.plugin = plugin; diff --git a/src/main/java/com/hackclub/hccore/commands/LocCommand.java b/src/main/java/com/hackclub/hccore/commands/LocCommand.java index b578dbc2..bae439ef 100644 --- a/src/main/java/com/hackclub/hccore/commands/LocCommand.java +++ b/src/main/java/com/hackclub/hccore/commands/LocCommand.java @@ -43,7 +43,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String alias, String sender.sendMessage(ChatColor.RED + "Please specify the location name"); break; } - + if (!data.getSavedLocations().containsKey(locationName)) { sender.sendMessage(ChatColor.RED + "No location with that name was found"); break; @@ -54,7 +54,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String alias, String ChatColor.GREEN + "Removed " + locationName + " from saved locations"); break; } - // /loc get + // /loc get case "get": { if (args.length < 2) { sender.sendMessage(ChatColor.RED + "Please specify the location name"); @@ -175,7 +175,8 @@ public boolean onCommand(CommandSender sender, Command cmd, String alias, String ChatColor.GREEN + String.format("%s has shared a location: %s (%s)", player.getName(), locationName, locationString)); recipData.getSavedLocations().put(player.getName() + ":" + locationName, - sendLocation); + sendLocation); + break; } default: diff --git a/src/main/java/com/hackclub/hccore/commands/SpawnCommand.java b/src/main/java/com/hackclub/hccore/commands/SpawnCommand.java index dd35868e..e017d40b 100644 --- a/src/main/java/com/hackclub/hccore/commands/SpawnCommand.java +++ b/src/main/java/com/hackclub/hccore/commands/SpawnCommand.java @@ -36,7 +36,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String alias, String int distanceFromSpawn = (int) player.getLocation().distance(player.getWorld().getSpawnLocation()); int allowedRadius = - this.plugin.getConfig().getInt("settings.spawn-command.allowed-radius");; + this.plugin.getConfig().getInt("settings.spawn-command.allowed-radius"); if (distanceFromSpawn > allowedRadius) { sender.sendMessage(ChatColor.RED + "You need to be within " + allowedRadius + " blocks from spawn to use this command. Currently, you’re " diff --git a/src/main/java/com/hackclub/hccore/commands/StatsCommand.java b/src/main/java/com/hackclub/hccore/commands/StatsCommand.java index be0d626c..f09368a2 100644 --- a/src/main/java/com/hackclub/hccore/commands/StatsCommand.java +++ b/src/main/java/com/hackclub/hccore/commands/StatsCommand.java @@ -143,13 +143,13 @@ private void sendStatistics(CommandSender sender, Player player, Boolean extende if (extended) { sender.sendMessage("- Distance by elytra: " - + toSIPrefix((double) player.getStatistic(Statistic.AVIATE_ONE_CM)) + "m"); + + toSIPrefix(player.getStatistic(Statistic.AVIATE_ONE_CM)) + "m"); sender.sendMessage("- Distance by minecart: " - + toSIPrefix((double) player.getStatistic(Statistic.MINECART_ONE_CM)) + "m"); + + toSIPrefix(player.getStatistic(Statistic.MINECART_ONE_CM)) + "m"); sender.sendMessage("- Distance by horse: " - + toSIPrefix((double) player.getStatistic(Statistic.HORSE_ONE_CM)) + "m"); + + toSIPrefix(player.getStatistic(Statistic.HORSE_ONE_CM)) + "m"); sender.sendMessage("- Distance walked: " - + toSIPrefix((double) player.getStatistic(Statistic.WALK_ONE_CM)) + "m"); + + toSIPrefix(player.getStatistic(Statistic.WALK_ONE_CM)) + "m"); sender.sendMessage("- Damage taken: " + player.getStatistic(Statistic.DAMAGE_TAKEN)); sender.sendMessage("- Damage dealt: " + player.getStatistic(Statistic.DAMAGE_DEALT)); sender.sendMessage("- Times jumped: " + player.getStatistic(Statistic.JUMP)); @@ -162,7 +162,7 @@ private void sendStatistics(CommandSender sender, Player player, Boolean extende // converts numbers to their SI prefix laden counterparts private static String toSIPrefix(double number) { if (number < 100) { - return String.valueOf(number) + " c"; + return number + " c"; } else if (number < 100000) { number = Math.round(number / 100); return String.valueOf(number); diff --git a/src/main/java/com/hackclub/hccore/commands/TutorialCommand.java b/src/main/java/com/hackclub/hccore/commands/TutorialCommand.java new file mode 100644 index 00000000..6b874348 --- /dev/null +++ b/src/main/java/com/hackclub/hccore/commands/TutorialCommand.java @@ -0,0 +1,30 @@ +package com.hackclub.hccore.commands; + +import com.hackclub.hccore.HCCorePlugin; +import com.hackclub.hccore.utils.TutorialUtil; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class TutorialCommand implements CommandExecutor { + + private final HCCorePlugin plugin; + + public TutorialCommand(HCCorePlugin plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String alias, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "You must be a player to use this"); + return true; + } else { + TutorialUtil.send((Player) sender, false); + } + + return true; + } +} diff --git a/src/main/java/com/hackclub/hccore/discord/DiscordBot.java b/src/main/java/com/hackclub/hccore/discord/DiscordBot.java index 71923007..0a153177 100644 --- a/src/main/java/com/hackclub/hccore/discord/DiscordBot.java +++ b/src/main/java/com/hackclub/hccore/discord/DiscordBot.java @@ -17,6 +17,7 @@ import net.md_5.bungee.api.chat.hover.content.Text; import org.bukkit.Bukkit; import org.bukkit.ChatColor; + import org.bukkit.entity.Player; import org.bukkit.event.*; import org.bukkit.event.Event; @@ -35,9 +36,9 @@ public class DiscordBot extends ListenerAdapter implements Listener { private JDA jda; - private HCCorePlugin plugin; + private final HCCorePlugin plugin; private TextChannel channel; - private String prefix; + private final String prefix; public DiscordBot(HCCorePlugin plugin) { this.plugin = plugin; diff --git a/src/main/java/com/hackclub/hccore/events/player/PlayerAFKStatusChangeEvent.java b/src/main/java/com/hackclub/hccore/events/player/PlayerAFKStatusChangeEvent.java index 0a5a2302..c19c0024 100644 --- a/src/main/java/com/hackclub/hccore/events/player/PlayerAFKStatusChangeEvent.java +++ b/src/main/java/com/hackclub/hccore/events/player/PlayerAFKStatusChangeEvent.java @@ -7,7 +7,7 @@ public class PlayerAFKStatusChangeEvent extends PlayerEvent { private static final HandlerList handlers = new HandlerList(); - private boolean isAfk; + private final boolean isAfk; public PlayerAFKStatusChangeEvent(Player player, boolean isAfk) { super(player); diff --git a/src/main/java/com/hackclub/hccore/listeners/PlayerListener.java b/src/main/java/com/hackclub/hccore/listeners/PlayerListener.java index 51f8c8a4..6c3da896 100644 --- a/src/main/java/com/hackclub/hccore/listeners/PlayerListener.java +++ b/src/main/java/com/hackclub/hccore/listeners/PlayerListener.java @@ -2,6 +2,10 @@ import com.hackclub.hccore.HCCorePlugin; import com.hackclub.hccore.PlayerData; +import com.hackclub.hccore.utils.TutorialUtil; +import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -9,14 +13,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerLoginEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.event.player.PlayerRespawnEvent; -import net.md_5.bungee.api.chat.ComponentBuilder; -import net.md_5.bungee.api.chat.HoverEvent; -import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.event.player.*; public class PlayerListener implements Listener { private final HCCorePlugin plugin; @@ -87,6 +84,10 @@ public void onPlayerJoin(final PlayerJoinEvent event) { event.getPlayer().resetTitle(); event.setJoinMessage(ChatColor.YELLOW + ChatColor.stripColor(event.getPlayer().getDisplayName()) + " joined the game"); + + if (!event.getPlayer().hasPlayedBefore()) { + TutorialUtil.send(event.getPlayer(), true); + } } @EventHandler diff --git a/src/main/java/com/hackclub/hccore/utils/TutorialUtil.java b/src/main/java/com/hackclub/hccore/utils/TutorialUtil.java new file mode 100644 index 00000000..fb5a6a7a --- /dev/null +++ b/src/main/java/com/hackclub/hccore/utils/TutorialUtil.java @@ -0,0 +1,18 @@ +package com.hackclub.hccore.utils; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +public class TutorialUtil { + public static final String greeting = ChatColor.RED + "Greetings! Welcome to the Hack Club vanilla Minecraft server!"; + + public static final String[] tutorial = {"Use /nick to set your nick name and /color to set your chat and name colors", ChatColor.RED + "Rules:", "Be nice.", "No griefing or stealing", "No mods that give an unfair advantage", "Follow Hack Club CoC", "If you want to contribute to plugin development head on over to the GitHub: " + ChatColor.RED + "https://github.com/hackclub/HCCore/. ", "Type /tutorial to see this at any time and /discord to join the Discord!" + ChatColor.BLUE + ChatColor.BOLD + "Also check out the modded server - IP: modded-mc.hackclub.com"}; + + public static void send(Player player, boolean withIntro) { + if (withIntro) { + player.sendMessage(ChatColor.YELLOW + ChatColor.BOLD.toString() + greeting); + } + for (String message : tutorial) { + player.sendMessage(ChatColor.YELLOW + ChatColor.BOLD.toString() + message); + } + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 1be3c90d..7b22b428 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -41,3 +41,6 @@ commands: discord: description: Gets the invite link to the Hackclub Minecraft Community Discord server usage: /discord + tutorial: + description: Greets new users to the server + usage: /tutorial