Started the plugin.yml, registered the event listener class and made it

so when the iron axe is used it logs a position.
This commit is contained in:
sekwah41 2013-10-08 20:03:30 +01:00
parent ddfd213b69
commit 0ea77dcec7
3 changed files with 42 additions and 6 deletions

View File

@ -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!");
}

View File

@ -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;
}
}
}

View File

@ -0,0 +1,5 @@
main: com.sekwah.advancedportals.AdvancedPortalsPlugin
name: AdvancedPortals
version: 0.0.1
author: SEKWAH41
description: An advanced portals plugin for bukkit.