Skip to content

Commit

Permalink
Re-organised the project, added sign break permission
Browse files Browse the repository at this point in the history
  • Loading branch information
Voltstro committed Jun 1, 2019
1 parent 2314500 commit a2a5cd0
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 57 deletions.
2 changes: 2 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ signs:
- 'Click to be'
- 'teleported.'

signHubColor: '§b'

# For you tp messages you can use '%name%' to say the hubs name and you can also use '%line%' for the next line.
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: HubManager
main: me.creepysin.hubmanager.Main
version: 1.2
version: 1.3
api-version: 1.14
author: Creepysin
website: https://github.com/Creepysin/HubManager
Expand Down
50 changes: 0 additions & 50 deletions src/me/creepysin/hubmanager/HubSignListeners.java

This file was deleted.

11 changes: 10 additions & 1 deletion src/me/creepysin/hubmanager/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@

import java.util.List;

import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
import org.bukkit.permissions.Permission;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;

import me.creepysin.hubmanager.cmds.AllHubsCommand;
import me.creepysin.hubmanager.cmds.HubCommand;
import me.creepysin.hubmanager.cmds.HubManagerCommands;
import me.creepysin.hubmanager.cmds.SetHubCommand;
import me.creepysin.hubmanager.listeners.HubSignListeners;

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

Expand All @@ -23,12 +30,14 @@ public void onEnable() {
Permission reloadPerm = new Permission("hubmanager.reload");
Permission signsCreatePerm = new Permission("hubmanager.signs.create");
Permission signsInteractPerm = new Permission("hubmanager.signs.interact");
Permission signsBreakPerm = new Permission("hubmanager.signs.break");

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

// Add commands
getCommand("sethub").setExecutor(new SetHubCommand(this));
Expand All @@ -39,7 +48,7 @@ public void onEnable() {
getServer().getPluginManager().registerEvents(new HubSignListeners(this, hubTele), this);
}

getLogger().info("HubManger has been loaded!");
getLogger().info(ChatColor.GREEN + "HubManager is now enabled!");

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.creepysin.hubmanager;
package me.creepysin.hubmanager.cmds;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package me.creepysin.hubmanager;
package me.creepysin.hubmanager.cmds;

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

import me.creepysin.hubmanager.HubTeleport;

import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.ChatColor;

Expand All @@ -10,7 +13,7 @@ public class HubCommand extends BukkitCommand {
private String hubCmd;
private HubTeleport hubTeleport;

protected HubCommand(String name, HubTeleport _hubTele) {
public HubCommand(String name, HubTeleport _hubTele) {
super(name);
this.description = "Goes to a hub";
this.usageMessage = "/<Command>";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.creepysin.hubmanager;
package me.creepysin.hubmanager.cmds;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -9,6 +9,8 @@
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;

import me.creepysin.hubmanager.Main;

public class HubManagerCommands implements CommandExecutor, TabCompleter {

private Main plugin;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.creepysin.hubmanager;
package me.creepysin.hubmanager.cmds;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -10,6 +10,8 @@
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;

import me.creepysin.hubmanager.Main;

public class SetHubCommand implements CommandExecutor, TabCompleter {

private Main plugin;
Expand Down
85 changes: 85 additions & 0 deletions src/me/creepysin/hubmanager/listeners/HubSignListeners.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package me.creepysin.hubmanager.listeners;

import org.bukkit.ChatColor;
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.BlockBreakEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.player.PlayerInteractEvent;

import me.creepysin.hubmanager.HubTeleport;
import me.creepysin.hubmanager.Main;

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 onBlockBreak(BlockBreakEvent e) {
// Check to see if it is a hub sign, and if it is then check to see if the player has the right permissions
if(e.getBlock().getState() instanceof Sign) {
Sign sign = (Sign) e.getBlock().getState();

if(sign.getLine(0).equalsIgnoreCase("[hub]")) {
if(!e.getPlayer().hasPermission("hubmanager.signs.break")) {
e.setCancelled(true);
e.getPlayer().sendMessage(ChatColor.RED + "You do not have permission to break hub signs!");
}
}
}
}

@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")) {
e.setLine(0, "[§4Hub§0]");
e.setLine(1, "");

e.getPlayer().sendMessage(ChatColor.RED + "You do not have permission to create hub signs!");
return;
}

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

e.setLine(1, plugin.getConfig().getString("signs.signHubColor") + e.getLine(1));

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(!e.getPlayer().hasPermission("hubmanager.signs.interact")) {
if(!sign.getLine(0).equalsIgnoreCase("[hub]")) return;

e.getPlayer().sendMessage(ChatColor.RED + "You do not have permission to interact with hub signs!");
return;
}

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

}

0 comments on commit a2a5cd0

Please sign in to comment.