-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
You can now create signs to tp you to a hub.
- Loading branch information
Showing
8 changed files
with
152 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters