88 lines
4.1 KiB
Java
88 lines
4.1 KiB
Java
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;
|
|
|
|
// The needed config values will be stored so they are easier to access later
|
|
// an example is in the interact event in this if statement if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("§eP...
|
|
private boolean UseOnlyServerAxe = false;
|
|
|
|
public Listeners(AdvancedPortalsPlugin plugin) {
|
|
this.plugin = plugin;
|
|
|
|
ConfigAccessor config = new ConfigAccessor(plugin, "Config.yml");
|
|
this.UseOnlyServerAxe = config.getConfig().getBoolean("UseOnlyServerMadeAxe");
|
|
|
|
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
|
}
|
|
|
|
@EventHandler
|
|
public void onMoveEvent(PlayerMoveEvent event) {
|
|
// will check if the player is in the portal or not.
|
|
ConfigAccessor portalsconfig = new ConfigAccessor(plugin, "Portals.yml");
|
|
|
|
}
|
|
|
|
@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(player.hasPermission("AdvancedPortals.CreatePortal")){
|
|
|
|
// UseOnlyServerMadeAxe being set to true makes is so only the axe generated by the server can be used so other iron axes can be used normally,
|
|
// by default its false but it is a nice feature in case the user wants to use the axe normally too, such as a admin playing survival or it being used
|
|
// as a weapon.
|
|
if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("§ePortal Region Selector")) && event.getPlayer().getItemInHand().getTypeId() == Material.IRON_AXE.getId()) {
|
|
|
|
// This checks if the action was a left or right click and if it was directly effecting a 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;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|