Create wand command, and make it work.

This commit is contained in:
Steffion 2013-07-30 20:43:06 +02:00
parent 303cd6b63a
commit cd68ccf261
7 changed files with 156 additions and 6 deletions

View File

@ -1,5 +1,6 @@
package nl.Steffion.BlockHunt;
import nl.Steffion.BlockHunt.Listeners.PlayerListener;
import nl.Steffion.BlockHunt.Managers.CommandC;
import nl.Steffion.BlockHunt.Managers.ConfigC;
import nl.Steffion.BlockHunt.Managers.MessageM;
@ -18,9 +19,8 @@ public class BlockHunt extends JavaPlugin implements Listener {
public void onEnable() {
W.newFiles();
getServer().getPluginManager().registerEvents(this, this);
// getServer().getPluginManager().registerEvents(new
// PlayerListener(this),
// this);
getServer().getPluginManager().registerEvents(new PlayerListener(),
this);
MessageM.sendFMessage(null, ConfigC.log_Enabled, true, "name-"
+ W.pluginName, "version-" + W.pluginVersion, "autors-"
+ W.pluginAutors);

View File

@ -0,0 +1,54 @@
package nl.Steffion.BlockHunt.Commands;
import java.util.ArrayList;
import java.util.List;
import nl.Steffion.BlockHunt.W;
import nl.Steffion.BlockHunt.Managers.ConfigC;
import nl.Steffion.BlockHunt.Managers.MessageM;
import nl.Steffion.BlockHunt.Managers.PlayerM;
import nl.Steffion.BlockHunt.Managers.PlayerM.PermsC;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.command.Command;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
public class CMDwand extends DefaultCMD {
@Override
public boolean exectue(Player player, Command cmd, String label,
String[] args) {
if (PlayerM.hasPerm(player, PermsC.create, true)) {
if (player != null) {
ItemStack wand = new ItemStack(
Material.getMaterial((Integer) W.config
.get(ConfigC.wandID)));
ItemMeta im = wand.getItemMeta();
im.setDisplayName(MessageM.replaceAll((String) W.config
.get(ConfigC.wandName)));
W.config.load();
List<String> lores = W.config.getFile().getStringList(
ConfigC.wandDescription.getLocation());
List<String> lores2 = new ArrayList<String>();
for (String lore : lores) {
lores2.add(MessageM.replaceAll(lore));
}
im.setLore(lores2);
wand.setItemMeta(im);
player.getInventory().addItem(wand);
player.playSound(player.getLocation(), Sound.ORB_PICKUP, 5, 0);
MessageM.sendFMessage(player, ConfigC.normal_gaveWand, true,
"type-"
+ wand.getType().toString()
.replaceAll("_", " ").toLowerCase());
} else {
MessageM.sendFMessage(player, ConfigC.error_onlyIngame, true);
}
}
return true;
}
}

View File

@ -1,6 +1,20 @@
package nl.Steffion.BlockHunt.Listeners;
import nl.Steffion.BlockHunt.W;
import nl.Steffion.BlockHunt.Managers.ConfigC;
import nl.Steffion.BlockHunt.Managers.MessageM;
import nl.Steffion.BlockHunt.Managers.PlayerM;
import nl.Steffion.BlockHunt.Managers.PlayerM.PermsC;
import nl.Steffion.BlockHunt.Serializables.LocationSerializable;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
public class PlayerListener implements Listener {
@ -10,6 +24,59 @@ public class PlayerListener implements Listener {
// this.plugin = plugin;
// }
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerInteractEvent(PlayerInteractEvent event) {
Player player = event.getPlayer();
if (PlayerM.hasPerm(player, PermsC.create, false)) {
ItemStack item = player.getItemInHand();
if (item.getItemMeta().hasDisplayName()) {
ItemMeta im = item.getItemMeta();
if (im.getDisplayName().equals(
MessageM.replaceAll((String) W.config
.get(ConfigC.wandName)))) {
Action action = event.getAction();
if (event.hasBlock()) {
LocationSerializable location = new LocationSerializable(
event.getClickedBlock().getLocation());
if (action.equals(Action.LEFT_CLICK_BLOCK)) {
event.setCancelled(true);
if (W.pos1.get(player) == null
|| !W.pos1.get(player).equals(location)) {
MessageM.sendFMessage(
player,
ConfigC.normal_setPosition,
true,
"number-1",
"pos-%N(%A" + location.getBlockX()
+ "%N, %A"
+ location.getBlockY()
+ "%N, %A"
+ location.getBlockZ() + "%N)");
W.pos1.put(player, location);
}
} else if (action.equals(Action.RIGHT_CLICK_BLOCK)) {
event.setCancelled(true);
if (W.pos2.get(player) == null
|| !W.pos2.get(player).equals(location)) {
MessageM.sendFMessage(
player,
ConfigC.normal_setPosition,
true,
"number-2",
"pos-%N(%A" + location.getBlockX()
+ "%N, %A"
+ location.getBlockY()
+ "%N, %A"
+ location.getBlockZ() + "%N)");
W.pos2.put(player, location);
}
}
}
}
}
}
}
// @EventHandler(priority = EventPriority.MONITOR)
// public void onPlayerTeleportEvent(final PlayerTeleportEvent event) {
// final Player player = event.getPlayer();

View File

@ -42,6 +42,14 @@ public enum CommandC {
ConfigC.help_reload,
1,
W.pluginName + " <reload|r>"),
WAND ("BlockHunt%wand_",
"BlockHunt%w_",
new CMDwand(),
ConfigC.commandEnabled_wand,
PermsC.create,
ConfigC.help_wand,
1,
W.pluginName + " <wand|w>"),
NOT_FOUND ("%_",
"%_",
new CMDnotfound(),

View File

@ -18,6 +18,16 @@ public enum ConfigC {
commandEnabled_info (true, W.config),
commandEnabled_help (true, W.config),
commandEnabled_reload (true, W.config),
commandEnabled_wand (true, W.config),
wandID (280, W.config),
wandName ("%A&l" + W.pluginName + "%N's selection wand", W.config),
wandDescription (new String[] {
"%NUse this item to select an arena for your arena.",
"%ALeft-Click%N to select point #1.",
"%ARight-Click%N to select point #2.",
"%NUse the create command to define your arena.",
"%A/" + W.pluginName + " <help|h>" }, W.config),
log_Enabled ("%N%name%&a&k + %N%version% is now Enabled. Made by %A%autors%%N.",
W.messages),
@ -27,8 +37,13 @@ public enum ConfigC {
help_info ("%NDisplays the plugin's info.", W.messages),
help_help ("%NShows a list of commands.", W.messages),
help_reload ("%NReloads all configs.", W.messages),
help_wand ("%NGives you the wand selection tool.", W.messages),
normal_reloadedConfigs ("&aReloaded all configs!", W.messages),
normal_gaveWand ("%NHere you go ;)! &o(Use the %A&o%type%%N&o!)",
W.messages),
normal_setPosition ("%NSet position %A#%number%%N to location: %pos%.",
W.messages),
error_noPermission ("%EYou don't have the permissions to do that!",
W.messages),
@ -37,7 +52,8 @@ public enum ConfigC {
+ W.pluginName + " help %Efor more info.", W.messages),
error_notEnoughArguments ("%EYou're missing arguments, correct syntax: %A/%syntax%",
W.messages),
error_noArena ("%ENo arena found with the name '%A%name%%E'.", W.messages);
error_noArena ("%ENo arena found with the name '%A%name%%E'.", W.messages),
error_onlyIngame ("%EThis is an only in-game command!", W.messages);
Object value;
ConfigM config;

View File

@ -19,8 +19,7 @@ public class PlayerM {
info (main + "info", PType.ALL),
help (main + "help", PType.ALL),
reload (main + "reload", PType.MODERATOR),
list (main + "list", PType.MODERATOR),
preview (main + "preview", PType.ADMIN);
create (main + "create", PType.ADMIN);
public String perm;
public PType type;

View File

@ -1,9 +1,13 @@
package nl.Steffion.BlockHunt;
import java.util.ArrayList;
import java.util.HashMap;
import org.bukkit.entity.Player;
import nl.Steffion.BlockHunt.Managers.ConfigM;
import nl.Steffion.BlockHunt.Managers.MessageM;
import nl.Steffion.BlockHunt.Serializables.LocationSerializable;
public class W {
/*
@ -17,6 +21,8 @@ public class W {
public static String pluginMainPermission = pluginName + ".";
public static ArrayList<String> newFiles = new ArrayList<String>();
public static HashMap<Player, LocationSerializable> pos1 = new HashMap<Player, LocationSerializable>();
public static HashMap<Player, LocationSerializable> pos2 = new HashMap<Player, LocationSerializable>();
public static ConfigM config = new ConfigM("config", "");
public static ConfigM messages = new ConfigM("messages", "");