Start sign based accessing of Vaults
This commit is contained in:
@@ -3,8 +3,10 @@ package com.drtshock.playervaults;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.Sign;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -23,6 +25,7 @@ import org.bukkit.inventory.Inventory;
|
|||||||
import com.drtshock.playervaults.commands.Commands;
|
import com.drtshock.playervaults.commands.Commands;
|
||||||
import com.drtshock.playervaults.commands.VaultViewInfo;
|
import com.drtshock.playervaults.commands.VaultViewInfo;
|
||||||
import com.drtshock.playervaults.util.DropOnDeath;
|
import com.drtshock.playervaults.util.DropOnDeath;
|
||||||
|
import com.drtshock.playervaults.util.Lang;
|
||||||
import com.drtshock.playervaults.util.VaultManager;
|
import com.drtshock.playervaults.util.VaultManager;
|
||||||
|
|
||||||
public class Listeners implements Listener {
|
public class Listeners implements Listener {
|
||||||
@@ -101,20 +104,46 @@ public class Listeners implements Listener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onInteract(PlayerInteractEvent event) {
|
public void onInteract(PlayerInteractEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if(Commands.IN_VAULT.containsKey(player.getName()) && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||||
Block block = event.getClickedBlock();
|
if(Commands.IN_VAULT.containsKey(player.getName())) {
|
||||||
|
Block block = event.getClickedBlock();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Different inventories that
|
* Different inventories that
|
||||||
* we don't want the player to open.
|
* we don't want the player to open.
|
||||||
*/
|
*/
|
||||||
if(block.getType() == Material.CHEST
|
if(block.getType() == Material.CHEST
|
||||||
|| block.getType() == Material.ENDER_CHEST
|
|| block.getType() == Material.ENDER_CHEST
|
||||||
|| block.getType() == Material.FURNACE
|
|| block.getType() == Material.FURNACE
|
||||||
|| block.getType() == Material.BURNING_FURNACE
|
|| block.getType() == Material.BURNING_FURNACE
|
||||||
|| block.getType() == Material.BREWING_STAND
|
|| block.getType() == Material.BREWING_STAND
|
||||||
|| block.getType() == Material.BEACON) {
|
|| block.getType() == Material.BEACON) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(Commands.SET_SIGN.containsKey(player.getName())) {
|
||||||
|
int i = Commands.SET_SIGN.get(player.getName()).getChest();
|
||||||
|
String owner = Commands.SET_SIGN.get(player.getName()).getOwner();
|
||||||
|
Commands.SET_SIGN.remove(player.getName());
|
||||||
|
event.setCancelled(true);
|
||||||
|
if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||||
|
if(event.getClickedBlock().getType() == Material.WALL_SIGN || event.getClickedBlock().getType() == Material.SIGN_POST) {
|
||||||
|
Sign s = (Sign) event.getClickedBlock().getState();
|
||||||
|
Location l = s.getLocation();
|
||||||
|
String world = l.getWorld().getName();
|
||||||
|
int x = l.getBlockX();
|
||||||
|
int y = l.getBlockY();
|
||||||
|
int z = l.getBlockZ();
|
||||||
|
PlayerVaults.SIGNS.set(world + ";;" + x + ";;" + y + ";;" + z + ".owner", owner);
|
||||||
|
PlayerVaults.SIGNS.set(world + ";;" + x + ";;" + y + ";;" + z + ".chest", i);
|
||||||
|
plugin.saveSigns();
|
||||||
|
player.sendMessage(Lang.TITLE.toString() + Lang.SET_SIGN);
|
||||||
|
} else {
|
||||||
|
player.sendMessage(Lang.TITLE.toString() + Lang.NOT_A_SIGN);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
player.sendMessage(Lang.TITLE.toString() + Lang.NOT_A_SIGN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ public class PlayerVaults extends JavaPlugin {
|
|||||||
public static boolean USE_VAULT = false;
|
public static boolean USE_VAULT = false;
|
||||||
public static YamlConfiguration LANG;
|
public static YamlConfiguration LANG;
|
||||||
public static File LANG_FILE;
|
public static File LANG_FILE;
|
||||||
|
public static YamlConfiguration SIGNS;
|
||||||
|
public static File SIGNS_FILE;
|
||||||
public static String DIRECTORY = "plugins" + File.separator + "PlayerVaults" + File.separator + "vaults";
|
public static String DIRECTORY = "plugins" + File.separator + "PlayerVaults" + File.separator + "vaults";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -38,6 +40,7 @@ public class PlayerVaults extends JavaPlugin {
|
|||||||
log = getServer().getLogger();
|
log = getServer().getLogger();
|
||||||
getServer().getPluginManager().registerEvents(new Listeners(this), this);
|
getServer().getPluginManager().registerEvents(new Listeners(this), this);
|
||||||
loadConfig();
|
loadConfig();
|
||||||
|
loadSigns();
|
||||||
startMetrics();
|
startMetrics();
|
||||||
Updater u = new Updater(getDescription().getVersion());
|
Updater u = new Updater(getDescription().getVersion());
|
||||||
if(getConfig().getBoolean("check-update")) {
|
if(getConfig().getBoolean("check-update")) {
|
||||||
@@ -56,6 +59,7 @@ public class PlayerVaults extends JavaPlugin {
|
|||||||
commands = new Commands();
|
commands = new Commands();
|
||||||
getCommand("pv").setExecutor(commands);
|
getCommand("pv").setExecutor(commands);
|
||||||
getCommand("pvdel").setExecutor(commands);
|
getCommand("pvdel").setExecutor(commands);
|
||||||
|
getCommand("pvsign").setExecutor(commands);
|
||||||
getCommand("workbench").setExecutor(commands);
|
getCommand("workbench").setExecutor(commands);
|
||||||
setupEconomy();
|
setupEconomy();
|
||||||
|
|
||||||
@@ -99,6 +103,35 @@ public class PlayerVaults extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void loadSigns() {
|
||||||
|
File signs = new File(getDataFolder(), "signs.yml");
|
||||||
|
if(!signs.exists()) {
|
||||||
|
try {
|
||||||
|
signs.createNewFile();
|
||||||
|
} catch(IOException e) {
|
||||||
|
log.severe("PlayerVaults has encountered a fatal error trying to load the signs file.");
|
||||||
|
log.severe("Please report this error to drtshock and gomeow.");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PlayerVaults.SIGNS_FILE = signs;
|
||||||
|
PlayerVaults.SIGNS = YamlConfiguration.loadConfiguration(signs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public YamlConfiguration getSigns() {
|
||||||
|
return PlayerVaults.SIGNS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveSigns() {
|
||||||
|
try {
|
||||||
|
PlayerVaults.SIGNS.save(PlayerVaults.SIGNS_FILE);
|
||||||
|
} catch(IOException e) {
|
||||||
|
log.severe("PlayerVaults has encountered an error trying to save the signs file.");
|
||||||
|
log.severe("Please report this error to drtshock and gomeow.");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void updateConfig() {
|
public void updateConfig() {
|
||||||
boolean checkUpdate = getConfig().getBoolean("check-update", true);
|
boolean checkUpdate = getConfig().getBoolean("check-update", true);
|
||||||
boolean ecoEnabled = getConfig().getBoolean("economy.enabled", false);
|
boolean ecoEnabled = getConfig().getBoolean("economy.enabled", false);
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import com.drtshock.playervaults.util.Lang;
|
|||||||
public class Commands implements CommandExecutor {
|
public class Commands implements CommandExecutor {
|
||||||
|
|
||||||
public static HashMap<String, VaultViewInfo> IN_VAULT = new HashMap<String, VaultViewInfo>();
|
public static HashMap<String, VaultViewInfo> IN_VAULT = new HashMap<String, VaultViewInfo>();
|
||||||
|
public static HashMap<String, SignSetInfo> SET_SIGN = new HashMap<String, SignSetInfo>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
@@ -65,6 +66,29 @@ public class Commands implements CommandExecutor {
|
|||||||
} else {
|
} else {
|
||||||
sender.sendMessage(Lang.TITLE.toString() + Lang.NO_PERMS);
|
sender.sendMessage(Lang.TITLE.toString() + Lang.NO_PERMS);
|
||||||
}
|
}
|
||||||
|
} else if(cmd.getName().equalsIgnoreCase("pvsign")) {
|
||||||
|
if(sender.hasPermission("playervaults.setsign")) {
|
||||||
|
if(sender instanceof Player) {
|
||||||
|
if(args.length >= 2) {
|
||||||
|
int i = 0;
|
||||||
|
try {
|
||||||
|
i = Integer.parseInt(args[1]);
|
||||||
|
} catch(NumberFormatException nfe) {
|
||||||
|
sender.sendMessage(Lang.TITLE.toString() + Lang.MUST_BE_NUMBER);
|
||||||
|
sender.sendMessage(Lang.TITLE.toString() + "Usage: /" + label + " <owner> <#>");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
SET_SIGN.put(sender.getName(), new SignSetInfo(args[0], i));
|
||||||
|
sender.sendMessage(Lang.TITLE.toString() + Lang.CLICK_A_SIGN);
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(Lang.TITLE.toString() + Lang.INVALID_ARGS);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(Lang.TITLE.toString() + Lang.PLAYER_ONLY);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(Lang.TITLE.toString() + Lang.NO_PERMS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.drtshock.playervaults.commands;
|
||||||
|
|
||||||
|
public class SignSetInfo {
|
||||||
|
|
||||||
|
private String o;
|
||||||
|
private int i;
|
||||||
|
|
||||||
|
public SignSetInfo(String o, int i) {
|
||||||
|
this.o = o;
|
||||||
|
this.i = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOwner() {
|
||||||
|
return this.o;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getChest() {
|
||||||
|
return this.i;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -19,7 +19,10 @@ public enum Lang {
|
|||||||
REFUND_AMOUNT("refund-amount", "&fYou were refunded &a%price &ffor deleting that vault."),
|
REFUND_AMOUNT("refund-amount", "&fYou were refunded &a%price &ffor deleting that vault."),
|
||||||
COST_TO_CREATE("cost-to-create", "&fYou were charged &c%price &ffor creating a vault."),
|
COST_TO_CREATE("cost-to-create", "&fYou were charged &c%price &ffor creating a vault."),
|
||||||
COST_TO_OPEN("cost-to-open", "&fYou were charged &c%price &ffor opening that vault."),
|
COST_TO_OPEN("cost-to-open", "&fYou were charged &c%price &ffor opening that vault."),
|
||||||
VAULT_DOES_NOT_EXIST("vault-does-not-exist", "&cThat vault does not exist!");
|
VAULT_DOES_NOT_EXIST("vault-does-not-exist", "&cThat vault does not exist!"),
|
||||||
|
CLICK_A_SIGN("click-a-sign", "&fNow click a sign!"),
|
||||||
|
NOT_A_SIGN("not-a-sign","&cYou must click a sign!"),
|
||||||
|
SET_SIGN("set-sign-success", "&fYou have successfully set a PlayerVault access sign!");
|
||||||
|
|
||||||
private String path;
|
private String path;
|
||||||
private String def; // Default string
|
private String def; // Default string
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name: PlayerVaults
|
name: PlayerVaults
|
||||||
main: com.drtshock.playervaults.Main
|
main: com.drtshock.playervaults.PlayerVaults
|
||||||
authors: [drtshock, gomeow, Chester]
|
authors: [drtshock, gomeow, Chester]
|
||||||
version: 3.0.0
|
version: 3.0.0
|
||||||
website: http://dev.bukkit.org/server-mods/PlayerVaults
|
website: http://dev.bukkit.org/server-mods/PlayerVaults
|
||||||
@@ -11,5 +11,8 @@ commands:
|
|||||||
pvdel:
|
pvdel:
|
||||||
description: Delete a vault.
|
description: Delete a vault.
|
||||||
aliases: [vaultdel]
|
aliases: [vaultdel]
|
||||||
|
pvsign:
|
||||||
|
description: Delete a vault.
|
||||||
|
aliases: [vaultsign]
|
||||||
workbench:
|
workbench:
|
||||||
description: Opens a workbench.
|
description: Opens a workbench.
|
||||||
Reference in New Issue
Block a user