mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2024-11-22 02:25:49 +01:00
Added a command to get a portal region selector and started making the
config for the plugin so you can change what you want such as being able to still use the normal axe if wanted or needed.
This commit is contained in:
parent
b8bfc12962
commit
18f8c8463a
7
Advanced Portals/src/Config.yml
Normal file
7
Advanced Portals/src/Config.yml
Normal file
@ -0,0 +1,7 @@
|
||||
# Advanced Portals Config
|
||||
|
||||
# To set this file back to its default state just delete it and reload the server or restart it!
|
||||
|
||||
# Set to true if you want the normal axes to work normally but the ones gived with /portals selector or wand will still work though
|
||||
|
||||
UseOnlyServerMadeAxe: false
|
@ -0,0 +1,54 @@
|
||||
package com.sekwah.advancedportals;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public class AdvancedPortalsCommand implements CommandExecutor {
|
||||
|
||||
private AdvancedPortalsPlugin plugin;
|
||||
|
||||
public AdvancedPortalsCommand(AdvancedPortalsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args) {
|
||||
Player player = (Player)sender;
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "Config.yml");
|
||||
if(args.length > 0){
|
||||
if(args[0].toLowerCase().equals("wand") || args[0].toLowerCase().equals("selector")){
|
||||
if(sender.hasPermission("AdvancedPortals.create")){
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
|
||||
ItemStack shopitem = new ItemStack(Material.IRON_AXE);
|
||||
ItemMeta shopname = shopitem.getItemMeta();
|
||||
shopname.setDisplayName("§ePortal Region Selector");
|
||||
shopname.setLore(Arrays.asList("§rThis iron axe with has the power to help"
|
||||
, "§r create portals bistowed upon it!"));
|
||||
shopitem.setItemMeta(shopname);
|
||||
|
||||
inventory.addItem(shopitem);
|
||||
sender.sendMessage("§a[§7AdvancedPortals§a] You have been given a §ePortal Region Selector§a!");
|
||||
}
|
||||
else{
|
||||
sender.sendMessage("§c[§7AdvancedPortals§c] You do not have permission to create portals so you cannot give yourself a §ePortal Region Selector§c!");
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
sender.sendMessage("§c[§7AdvancedPortals§c] You need to type something after /" + command + "\n"
|
||||
+ "if you do not know what you can put or would like some help with the commands please type /" + command + " help");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,11 +1,19 @@
|
||||
package com.sekwah.advancedportals;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class AdvancedPortalsPlugin extends JavaPlugin {
|
||||
|
||||
public void onEnable() {
|
||||
|
||||
// thanks to the new config accessor code the config.saveDefaultConfig(); will now
|
||||
// only copy the file if it doesnt exist!
|
||||
ConfigAccessor config = new ConfigAccessor(this, "Config.yml");
|
||||
config.saveDefaultConfig();
|
||||
|
||||
getCommand("advancedportals").setExecutor(new AdvancedPortalsCommand(this));
|
||||
new Listeners(this);
|
||||
|
||||
this.getServer().getConsoleSender().sendMessage("§aAdvanced portals have been sucsessfully enabled!");
|
||||
|
@ -62,10 +62,21 @@ public class ConfigAccessor {
|
||||
}
|
||||
|
||||
// Saves
|
||||
public void saveDefaultConfig() {
|
||||
/**public void saveDefaultConfig() {
|
||||
if (!configFile.exists()) {
|
||||
this.plugin.saveResource(fileName, false);
|
||||
}
|
||||
}*/
|
||||
|
||||
// New save default config saving code, it checks if the needed config is in the jar file before
|
||||
// overriding it.
|
||||
public void saveDefaultConfig() {
|
||||
if (configFile == null) {
|
||||
configFile = new File(plugin.getDataFolder(), fileName);
|
||||
}
|
||||
if (!configFile.exists()) {
|
||||
plugin.saveResource(fileName, false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -24,7 +24,7 @@ public class Listeners implements Listener {
|
||||
@EventHandler
|
||||
public void onMoveEvent(PlayerMoveEvent event) {
|
||||
// will check if the player is in the portal or not.
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "Portals.yml");
|
||||
ConfigAccessor portalsconfig = new ConfigAccessor(plugin, "Portals.yml");
|
||||
|
||||
}
|
||||
|
||||
@ -35,34 +35,46 @@ public class Listeners implements Listener {
|
||||
// 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) {
|
||||
// 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());
|
||||
if(player.hasPermission("AdvancedPortals.create")){
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "Config.yml");
|
||||
|
||||
// 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((!config.getConfig().getBoolean("UseOnlyServerMadeAxe") || event.getItem().getItemMeta().getDisplayName().equals("§ePortal Region Selector")) && event.getPlayer().getItemInHand().getTypeId() == Material.IRON_AXE.getId()) {
|
||||
|
||||
// Stops the event so the block is not damaged
|
||||
event.setCancelled(true);
|
||||
// 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;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,4 +2,9 @@ main: com.sekwah.advancedportals.AdvancedPortalsPlugin
|
||||
name: AdvancedPortals
|
||||
version: 0.0.1
|
||||
author: SEKWAH41
|
||||
description: An advanced portals plugin for bukkit.
|
||||
description: An advanced portals plugin for bukkit.
|
||||
commands:
|
||||
advancedportals:
|
||||
description: The main command for the advanced portals
|
||||
aliases: [portals, aportals]
|
||||
usage: /<command>
|
Loading…
Reference in New Issue
Block a user