diff --git a/Advanced Portals/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java b/Advanced Portals/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java index 0975b5b..cab6ff1 100644 --- a/Advanced Portals/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java +++ b/Advanced Portals/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java @@ -5,12 +5,14 @@ import org.bukkit.plugin.java.JavaPlugin; public class AdvancedPortalsPlugin extends JavaPlugin { public void onEnable() { - getLogger().info("\n\nAdvanced portals are being enabled!\n\n"); + + new Listeners(this); + this.getServer().getConsoleSender().sendMessage("§aAdvanced portals have been sucsessfully enabled!"); } public void onDisable() { - getLogger().info("\n\nAdvanced portals are being disabled!\n\n"); + this.getServer().getConsoleSender().sendMessage("§cAdvanced portals are being disabled!"); } diff --git a/Advanced Portals/src/com/sekwah/advancedportals/Listeners.java b/Advanced Portals/src/com/sekwah/advancedportals/Listeners.java index 584261c..a6e1a63 100644 --- a/Advanced Portals/src/com/sekwah/advancedportals/Listeners.java +++ b/Advanced Portals/src/com/sekwah/advancedportals/Listeners.java @@ -1,34 +1,63 @@ package com.sekwah.advancedportals; +import org.bukkit.Location; 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.event.player.PlayerMoveEvent; +import org.bukkit.metadata.FixedMetadataValue; public class Listeners implements Listener { + private final AdvancedPortalsPlugin plugin; + + public Listeners(AdvancedPortalsPlugin plugin) { + this.plugin = plugin; + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + @EventHandler public void onMoveEvent(PlayerMoveEvent event) { // will check if the player is in the portal or not. } - - - @SuppressWarnings("deprecation") @EventHandler public void oniteminteract(PlayerInteractEvent event) { // will detect if the player is using an axe so the points of a portal can be set // also any other detections such as sign interaction or basic block protection + Player player = event.getPlayer(); + Location blockloc = event.getClickedBlock().getLocation(); if(event.getPlayer().getItemInHand().getTypeId() == Material.IRON_AXE.getId()) { - if(event.getAction() == Action.LEFT_CLICK_BLOCK){ + if(event.getAction() == Action.LEFT_CLICK_BLOCK) { + // stores the selection as metadata on the character so then it isn't saved anywhere, if the player logs out it will + // have to be selected again if the player joins, also it does not affect any other players. + player.setMetadata("Pos1X", new FixedMetadataValue(plugin, blockloc.getBlockX())); + player.setMetadata("Pos1Y", new FixedMetadataValue(plugin, blockloc.getBlockY())); + player.setMetadata("Pos1Z", new FixedMetadataValue(plugin, blockloc.getBlockZ())); + player.sendMessage("§eYou have selected pos1! X:" + blockloc.getBlockX() + " Y:" + blockloc.getBlockY() + " Z:" + blockloc.getBlockZ()); + // Stops the event so the block is not damaged + event.setCancelled(true); + + // Returns the event so no more code is executed(stops unnecessary code being executed) + return; } else if(event.getAction() == Action.RIGHT_CLICK_BLOCK) { + player.setMetadata("Pos2X", new FixedMetadataValue(plugin, blockloc.getBlockX())); + player.setMetadata("Pos2Y", new FixedMetadataValue(plugin, blockloc.getBlockY())); + player.setMetadata("Pos2Z", new FixedMetadataValue(plugin, blockloc.getBlockZ())); + player.sendMessage("§eYou have selected pos2! X:" + blockloc.getBlockX() + " Y:" + blockloc.getBlockY() + " Z:" + blockloc.getBlockZ()); + // Stops the event so the block is not interacted with + event.setCancelled(true); + + // Returns the event so no more code is executed(stops unnecessary code being executed) + return; } } } diff --git a/Advanced Portals/src/plugin.yml b/Advanced Portals/src/plugin.yml index e69de29..521aac2 100644 --- a/Advanced Portals/src/plugin.yml +++ b/Advanced Portals/src/plugin.yml @@ -0,0 +1,5 @@ +main: com.sekwah.advancedportals.AdvancedPortalsPlugin +name: AdvancedPortals +version: 0.0.1 +author: SEKWAH41 +description: An advanced portals plugin for bukkit. \ No newline at end of file