Added the off on command

This commit is contained in:
cnaude 2013-01-01 18:35:17 -07:00
parent d29b5e195a
commit 311f090934
5 changed files with 172 additions and 30 deletions

View File

@ -11,8 +11,6 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permission;
@ -21,7 +19,7 @@ import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
public class Chairs extends JavaPlugin {
private static Chairs instance = null;
public List<Material> allowedBlocks = new ArrayList<Material>();
public boolean sneaking, autoRotate, signCheck, permissions, notifyplayer, opsOverridePerms;
public boolean invertedStairCheck, seatOccupiedCheck, invertedStepCheck, perItemPerms;
@ -35,9 +33,12 @@ public class Chairs extends JavaPlugin {
public static final String LOG_HEADER = "[" + PLUGIN_NAME + "]";
static final Logger log = Logger.getLogger("Minecraft");
public PluginManager pm;
public static ChairsIgnoreList ignoreList;
@Override
public void onEnable() {
instance = this;
ignoreList = new ChairsIgnoreList();
pm = this.getServer().getPluginManager();
pluginFolder = getDataFolder();
configFile = new File(pluginFolder, "config.yml");
@ -45,12 +46,13 @@ public class Chairs extends JavaPlugin {
this.getConfig().options().copyDefaults(true);
saveConfig();
loadConfig();
EventListener eventListener = new EventListener(this);
getServer().getPluginManager().registerEvents(eventListener, this);
getServer().getPluginManager().registerEvents(new EventListener(this, ignoreList), this);
getCommand("chairs").setExecutor(new ChairsCommand(this, ignoreList));
}
@Override
public void onDisable() {
ignoreList.save();
}
private void createConfig() {
@ -71,7 +73,7 @@ public class Chairs extends JavaPlugin {
}
}
private void loadConfig() {
public void loadConfig() {
autoRotate = getConfig().getBoolean("auto-rotate");
sneaking = getConfig().getBoolean("sneaking");
signCheck = getConfig().getBoolean("sign-check");
@ -109,25 +111,6 @@ public class Chairs extends JavaPlugin {
}
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (command.getName().equalsIgnoreCase("chairs")) {
if (sender instanceof Player && !((Player) sender).hasPermission("chairs.reload")) {
return true;
}
if (args.length > 0 && args[0].equalsIgnoreCase("reload")) {
reloadConfig();
loadConfig();
sender.sendMessage("Chairs configuration file reloaded.");
} else {
sender.sendMessage("Use '/chairs reload' to reload the configuration file.");
}
}
return true;
}
// Send sit packet to all online players
public void sendSit(Player p) {
Packet40EntityMetadata packet = new Packet40EntityMetadata(p.getPlayer().getEntityId(), new ChairWatcher((byte) 4), false);
@ -169,4 +152,8 @@ public class Chairs extends JavaPlugin {
log.log(Level.SEVERE, String.format("%s %s", LOG_HEADER, _message));
}
public static Chairs get() {
return instance;
}
}

View File

@ -0,0 +1,62 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package net.spoothie.chairs;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
*
* @author cnaude
*/
public class ChairsCommand implements CommandExecutor {
private final Chairs plugin;
public ChairsIgnoreList ignoreList;
public ChairsCommand(Chairs instance, ChairsIgnoreList ignoreList) {
this.plugin = instance;
this.ignoreList = ignoreList;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length == 0) {
return false;
}
if (args[0].equalsIgnoreCase("reload")) {
if (sender.hasPermission("chairs.reload")) {
plugin.reloadConfig();
plugin.loadConfig();
sender.sendMessage("Chairs configuration file reloaded.");
} else {
sender.sendMessage(ChatColor.GRAY + "No permission to do this!");
}
}
if (sender instanceof Player) {
Player p = (Player) sender;
if (args[0].equalsIgnoreCase("on")) {
if (p.hasPermission("chairs.self")) {
ignoreList.removePlayer(p.getName());
p.sendMessage(ChatColor.GRAY + "You have enabled chairs for yourself!");
} else {
p.sendMessage(ChatColor.GRAY + "No permission to do this!");
}
}
if (args[0].equalsIgnoreCase("off")) {
if (p.hasPermission("chairs.self")) {
ignoreList.addPlayer(p.getName());
p.sendMessage(ChatColor.GRAY + "You have disabled chairs for yourself!");
} else {
p.sendMessage(ChatColor.GRAY + "No permission to do this!");
}
}
}
return true;
}
}

View File

@ -0,0 +1,77 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package net.spoothie.chairs;
import java.io.*;
import java.util.ArrayList;
/**
*
* @author naudec
*/
@SuppressWarnings("serial")
public class ChairsIgnoreList implements Serializable{
private static ArrayList<String> ignoreList = new ArrayList<String>();
private static final String IGNORE_FILE = "plugins/Chairs/ignores.ser";
public void ChairsIgnoreList() {
this.load();
}
@SuppressWarnings("unchecked")
public void load() {
File file = new File(IGNORE_FILE);
if (!file.exists()) {
Chairs.get().logInfo("Ignore file '"+file.getAbsolutePath()+"' does not exist.");
return;
}
try {
FileInputStream f_in = new FileInputStream(file);
ObjectInputStream obj_in = new ObjectInputStream (f_in);
ignoreList = (ArrayList<String>) obj_in.readObject();
obj_in.close();
Chairs.get().logInfo("Loaded ignore list. (Count = "+ignoreList.size()+")");
}
catch(Exception e) {
Chairs.get().logError(e.getMessage());
}
}
public void save() {
try {
File file = new File(IGNORE_FILE);
FileOutputStream f_out = new FileOutputStream (file);
ObjectOutputStream obj_out = new ObjectOutputStream (f_out);
obj_out.writeObject (ignoreList);
obj_out.close();
Chairs.get().logInfo("Saved ignore list. (Count = "+ignoreList.size()+")");
}
catch(Exception e) {
Chairs.get().logError(e.getMessage());
}
}
public void addPlayer(String s) {
if (ignoreList.contains(s)) {
return;
}
Chairs.get().logInfo("Adding " + s + " to ignore list.");
ignoreList.add(s);
}
public void removePlayer(String s) {
Chairs.get().logInfo("Removing " + s + " from ignore list.");
ignoreList.remove(s);
}
public boolean isIgnored(String s) {
if (ignoreList.contains(s)) {
return true;
}
else {
return false;
}
}
}

View File

@ -27,9 +27,11 @@ import org.bukkit.permissions.PermissionDefault;
public class EventListener implements Listener {
public Chairs plugin;
public ChairsIgnoreList ignoreList;
public EventListener(Chairs plugin) {
public EventListener(Chairs plugin, ChairsIgnoreList ignoreList) {
this.plugin = plugin;
this.ignoreList = ignoreList;
}
@EventHandler
@ -96,6 +98,7 @@ public class EventListener implements Listener {
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.hasBlock() && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
Block block = event.getClickedBlock();
Stairs stairs = null;
Step step = null;
@ -108,6 +111,9 @@ public class EventListener implements Listener {
sh += 1.0;
}
Player player = event.getPlayer();
if (ignoreList.isIgnored(player.getName())) {
return;
}
// Permissions Check
if (plugin.permissions) {
if (!player.hasPermission("chairs.sit")) {

View File

@ -1,5 +1,5 @@
name: Chairs
version: 1.13.5
version: 1.15.0
description: Let players sit on blocks.
authors:
- spoothie
@ -7,5 +7,15 @@ authors:
main: net.spoothie.chairs.Chairs
commands:
chairs:
description: Reloads the Chairs configuration file.
usage: /chairs reload
description: Various commands for Chairs.
usage: |
/<command> reload - reloads the configuration
/<command> off - disable chairs for self
/<command> on - enable chairs for self
permissions:
chairs.reload:
description: Reload configuration
default: op
chairs.self:
description: Allow player to turn chairs off and on
default: false