Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
roh1th-s committed Jul 29, 2021
0 parents commit ad4f106
Show file tree
Hide file tree
Showing 12 changed files with 204 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
lib/spigot-1.16.5.jar
.vscode/settings.json
Manhunt plugin.jar
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Manhunt

A simple manhunt plugin for Spigot Mc 1.16
Binary file added bin/me/rohith/manhunt/Main.class
Binary file not shown.
Binary file added bin/me/rohith/manhunt/commands/HuntCommand.class
Binary file not shown.
Binary file added bin/me/rohith/manhunt/commands/TrackCommand.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
25 changes: 25 additions & 0 deletions src/me/rohith/manhunt/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package me.rohith.manhunt;

import java.util.ArrayList;

import org.bukkit.plugin.java.JavaPlugin;

import me.rohith.manhunt.commands.*;
import me.rohith.manhunt.listeners.*;

public class Main extends JavaPlugin {

public ArrayList<String> Speedrunners = new ArrayList<String>();

@Override
public void onEnable() {
//Commands
new HuntCommand(this);
new TrackCommand(this);

//Listeners
new RespawnListener(this);
new CompassClickListener(this);
}
}

44 changes: 44 additions & 0 deletions src/me/rohith/manhunt/commands/HuntCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package me.rohith.manhunt.commands;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import me.rohith.manhunt.Main;

public class HuntCommand implements CommandExecutor {

private Main plugin;

public HuntCommand(Main plugin) {
this.plugin = plugin;
plugin.getCommand("hunt").setExecutor(this);
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {

Player plr = sender.getServer().getPlayer(args[0]);
if (plr == null) return false;

if (!this.plugin.Speedrunners.contains(args[0])) {

this.plugin.Speedrunners.add(args[0]);
plr.setGlowing(true);
Bukkit.broadcastMessage(args[0] + " is now marked as a speedrunner!");

}
else {

this.plugin.Speedrunners.remove(args[0]);
plr.setGlowing(false);
Bukkit.broadcastMessage(args[0] + " is no longer a speedrunner!");
}


return false;
}


}
36 changes: 36 additions & 0 deletions src/me/rohith/manhunt/commands/TrackCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package me.rohith.manhunt.commands;

import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import me.rohith.manhunt.Main;

public class TrackCommand implements CommandExecutor {

//private Main plugin;

public TrackCommand(Main plugin) {
//this.plugin = plugin;
plugin.getCommand("track").setExecutor(this);
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {

Player plr = (Player) sender;
Player speedrunner = sender.getServer().getPlayer(args[0]);

if (speedrunner == null) {
plr.sendMessage("Something went wrong - that player doesn't exist!");
return false;
}

plr.setCompassTarget(speedrunner.getLocation());
sender.sendMessage("You are currently tracking : " + speedrunner.getDisplayName());

return false;
}


}
61 changes: 61 additions & 0 deletions src/me/rohith/manhunt/listeners/CompassClickListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package me.rohith.manhunt.listeners;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;

import me.rohith.manhunt.Main;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent;

public class CompassClickListener implements Listener {

private Main plugin;

public CompassClickListener(Main plugin) {
this.plugin = plugin;
System.out.println(this.plugin);
Bukkit.getPluginManager().registerEvents(this, plugin);
}

@EventHandler
public void CompassClick(PlayerInteractEvent event) {
Player p = event.getPlayer();
ItemStack stack = event.getItem();
if (stack == null) return;
Material item = stack.getType();
Action action = event.getAction();


if (
!(this.plugin.Speedrunners.contains(p.getName()))
&& item == Material.COMPASS
&& (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK)
)
{
if (this.plugin.Speedrunners.isEmpty()) {
p.sendMessage("There is no one to track! Use the hunt command to track somebody");
return;
}

TextComponent message = new TextComponent("Click on the speedrunner you wanna track : \n");

this.plugin.Speedrunners.forEach(plrName -> {
TextComponent name = new TextComponent(plrName);
name.setBold(true);
name.setColor(ChatColor.AQUA);
name.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/track " + plrName));
message.addExtra(name);
});

p.spigot().sendMessage(message);
}

}
}
32 changes: 32 additions & 0 deletions src/me/rohith/manhunt/listeners/RespawnListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package me.rohith.manhunt.listeners;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.inventory.ItemStack;

import me.rohith.manhunt.Main;

public class RespawnListener implements Listener {

private Main plugin;

public RespawnListener(Main plugin) {
this.plugin = plugin;

Bukkit.getPluginManager().registerEvents(this, plugin);
}

@EventHandler
public void PlayerRespawn(PlayerRespawnEvent event) {
Player p = event.getPlayer();
if (p == null) return;

if (this.plugin.Speedrunners.contains(p.getName())) return;

p.getInventory().addItem(new ItemStack(Material.COMPASS));
}
}

0 comments on commit ad4f106

Please sign in to comment.