Skip to content

Commit

Permalink
Added signs
Browse files Browse the repository at this point in the history
You can now create signs to tp you to a hub.
  • Loading branch information
Voltstro committed May 31, 2019
1 parent 69bbaf1 commit 2314500
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="D:/Servers/Test Plugin Server/spigot-1.14.jar"/>
<classpathentry kind="lib" path="D:/Projects/Minecraft/Jars/spigot-1.14.2.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
22 changes: 18 additions & 4 deletions config.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
# BasicUtils - Created by AustraliaCraft/Creepysin 2019
# https://github.com/AustraliaCraft/Basicutils

# The list of commands to add
# HubManager - Created by Creepysin 2019
# https://github.com/Creepysin/HubManager
#
#
commands:
- hub

# Do you want to out a log everytime a cmd is added?
outputAddedCmds: true

# The interactable signs
signs:
# Are they enabled?
enabled: true

# If each of the remaining lines, can have a maxium of up to four since the top one is for the tag.
# You can use %hubname% to put the hub name in it
messages:
- 'Click to be'
- 'teleported.'

# For you tp messages you can use '%name%' to say the hubs name and you can also use '%line%' for the next line.
3 changes: 2 additions & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: HubManager
main: me.creepysin.hubmanager.Main
version: 1.1
version: 1.2
api-version: 1.14
author: Creepysin
website: https://github.com/Creepysin/HubManager
description: Provides the ablity to add hubs using commands such as '/hub'
commands:
sethub:
description: Sets the hub
Expand Down
35 changes: 4 additions & 31 deletions src/me/creepysin/hubmanager/HubCommand.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
package me.creepysin.hubmanager;

import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;

public class HubCommand extends BukkitCommand {

private String hubCmd;
private Main plugin;
private HubTeleport hubTeleport;

protected HubCommand(String name, Main _main) {
protected HubCommand(String name, HubTeleport _hubTele) {
super(name);
this.description = "Goes to a hub";
this.usageMessage = "/<Command>";
this.setPermission("hubmanager.hubs." + name);

hubCmd = name;
plugin = _main;
hubTeleport = _hubTele;
}

@Override
Expand All @@ -37,31 +34,7 @@ public boolean execute(CommandSender sender, String label, String[] args) {

Player player = (Player) sender;

World w = Bukkit.getServer().getWorld(plugin.getConfig().getString(hubCmd + ".world"));

//If the world equals null, then don't teleport and put a warning in the console.
if(w == null) {
player.sendMessage(ChatColor.RED + "That hub hasn't been set yet!");
plugin.getLogger().warning(ChatColor.RED + "The hub '" + hubCmd + "' hasn't been set! When in game do '/sethub " + hubCmd + "' to set the hub!");
return true;
}

double x = plugin.getConfig().getDouble(hubCmd + ".x");
double y = plugin.getConfig().getDouble(hubCmd + ".y");
double z = plugin.getConfig().getDouble(hubCmd + ".z");

if(w.getName().equalsIgnoreCase("")) {
player.sendMessage("That hub hasn't been set yet!");
return true;
}
else {
player.teleport(new Location(w, x, y, z));

// Send the player the formated message.
String formatMessage = plugin.getConfig().getString(hubCmd + ".message").replace("%name%", hubCmd).replace("%line%", "\n");
if(!formatMessage.equalsIgnoreCase(""))
player.sendMessage(formatMessage);
}
hubTeleport.TeleportPlayer(player, hubCmd);
}

return true;
Expand Down
8 changes: 3 additions & 5 deletions src/me/creepysin/hubmanager/HubManagerCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
if(sender instanceof Player) {
Player player = (Player) sender;
if(player.hasPermission("hubmanager.reload")) {
plugin.Reload(sender);
plugin.reload(sender);
}
}
else {
plugin.Reload(sender);
plugin.reload(sender);
}
}
else if(args[0].equalsIgnoreCase("about")) {
Expand Down Expand Up @@ -64,8 +64,6 @@ public List<String> onTabComplete(CommandSender sender, Command cmd, String labe
subCmds.add("reload");
}

return subCmds;

return subCmds;
}

}
50 changes: 50 additions & 0 deletions src/me/creepysin/hubmanager/HubSignListeners.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package me.creepysin.hubmanager;

import org.bukkit.block.Sign;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.player.PlayerInteractEvent;

public class HubSignListeners implements Listener {

private Main plugin;
private HubTeleport hubTele;

public HubSignListeners(Main _main, HubTeleport _hubtele) {
plugin = _main;
hubTele = _hubtele;

plugin.getLogger().info("Added events.");
}

@EventHandler
public void onSignChange(SignChangeEvent e) {
if(e.getLine(0).equalsIgnoreCase("[hub]")) {

// Check to see if the player has the right permissions
if(!e.getPlayer().hasPermission("hubmanager.signs.create")) return;

e.setLine(0, "[Hub]");

for (int i = 0; i < 2; i++ ) {
e.setLine(i + 2, plugin.getConfig().getList("signs.messages").get(i).toString());
}
}
}

@EventHandler
public void onPlayerInteract(PlayerInteractEvent e) {
if(!(e.getAction() == Action.RIGHT_CLICK_BLOCK)) return;

if(e.getClickedBlock().getState() instanceof Sign) {
Sign sign = (Sign) e.getClickedBlock().getState();

if(sign.getLine(0).equalsIgnoreCase("[hub]")) {
hubTele.TeleportPlayer(e.getPlayer(), sign.getLine(1));
}
}
}

}
50 changes: 50 additions & 0 deletions src/me/creepysin/hubmanager/HubTeleport.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package me.creepysin.hubmanager;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;

public class HubTeleport {

private Main plugin;

public HubTeleport(Main _main) {
plugin = _main;
}

public void TeleportPlayer(Player player, String hubCmd) {
// Check to see if the hub actually exist!
if(plugin.getConfig().getString(hubCmd + ".world") == null) {
player.sendMessage(ChatColor.RED + "That hub doesn't exist!");
return;
}

World w = Bukkit.getServer().getWorld(plugin.getConfig().getString(hubCmd + ".world"));

// If the world equals null, then don't teleport and put a warning in the console.
if(w == null) {
player.sendMessage(ChatColor.RED + "That hub hasn't been set yet!");
plugin.getLogger().warning(ChatColor.RED + "The hub '" + hubCmd + "' hasn't been set! When in game do '/sethub " + hubCmd + "' to set the hub!");
return;
}

double x = plugin.getConfig().getDouble(hubCmd + ".x");
double y = plugin.getConfig().getDouble(hubCmd + ".y");
double z = plugin.getConfig().getDouble(hubCmd + ".z");

if(w.getName().equalsIgnoreCase("")) {
player.sendMessage(ChatColor.RED + "That hub hasn't been set yet!");
return;
}
else {
player.teleport(new Location(w, x, y, z));

// Send the player the formated message.
String formatMessage = plugin.getConfig().getString(hubCmd + ".message").replace("%name%", hubCmd).replace("%line%", "\n");
if(!formatMessage.equalsIgnoreCase(""))
player.sendMessage(formatMessage);
}
}
}
31 changes: 24 additions & 7 deletions src/me/creepysin/hubmanager/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,37 @@

public class Main extends JavaPlugin {
public List<?> baseCommands;

private HubTeleport hubTele;

public void onEnable() {
hubTele = new HubTeleport(this);

loadConfig();

// Add the permissions
Permission sethubPerm = new Permission("hubmanager.sethubs");
Permission reloadPerm = new Permission("hubmanager.reload");
Permission signsCreatePerm = new Permission("hubmanager.signs.create");
Permission signsInteractPerm = new Permission("hubmanager.signs.interact");

PluginManager pm = getServer().getPluginManager();
pm.addPermission(sethubPerm);
pm.addPermission(reloadPerm);
pm.addPermission(signsCreatePerm);
pm.addPermission(signsInteractPerm);

// Add commands
getCommand("sethub").setExecutor(new SetHubCommand(this));
getCommand("hubmanager").setExecutor(new HubManagerCommands(this));

// Register events
if(getConfig().getBoolean("signs.enabled")) {
getServer().getPluginManager().registerEvents(new HubSignListeners(this, hubTele), this);
}

getLogger().info("HubManger has been loaded!");

}

public void loadConfig() {
Expand All @@ -33,7 +50,6 @@ public void loadConfig() {

// Load in each command
for (int i = 0; i < baseCommands.size(); i++ ) {

String cmd = baseCommands.get(i).toString();

getConfig().addDefault(cmd + ".message", "\u00A76You have been teleported to \u00A7c%name%\u00A76!%line%You can change this message in the config.");
Expand All @@ -42,11 +58,13 @@ public void loadConfig() {
getConfig().addDefault(cmd + ".y", 0);
getConfig().addDefault(cmd + ".z", 0);

((CraftServer) this.getServer()).getCommandMap().register(cmd, new HubCommand(cmd, this));
((CraftServer) this.getServer()).getCommandMap().register(cmd, new HubCommand(cmd, hubTele));

getLogger().info("Added the command `" + baseCommands.get(i) + "`.");
}

if(getConfig().getBoolean("outputAddedCmds") == true) {
getLogger().info("Added the command `" + baseCommands.get(i) + "`.");
}
}

getConfig().options().copyDefaults(true);
saveConfig();

Expand All @@ -55,10 +73,9 @@ public void loadConfig() {
getLogger().info("The config has been loaded!");
}

public void Reload(CommandSender sender) {
public void reload(CommandSender sender) {
sender.sendMessage("Reloading...");
this.reloadConfig();
sender.sendMessage("Reloaded config! Any new commands added will require the server to resart.");
}

}

0 comments on commit 2314500

Please sign in to comment.