Added the off on command
This commit is contained in:
parent
d29b5e195a
commit
311f090934
@ -11,8 +11,6 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
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.craftbukkit.v1_4_6.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.permissions.Permission;
|
import org.bukkit.permissions.Permission;
|
||||||
@ -21,7 +19,7 @@ import org.bukkit.plugin.PluginManager;
|
|||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
public class Chairs extends JavaPlugin {
|
public class Chairs extends JavaPlugin {
|
||||||
|
private static Chairs instance = null;
|
||||||
public List<Material> allowedBlocks = new ArrayList<Material>();
|
public List<Material> allowedBlocks = new ArrayList<Material>();
|
||||||
public boolean sneaking, autoRotate, signCheck, permissions, notifyplayer, opsOverridePerms;
|
public boolean sneaking, autoRotate, signCheck, permissions, notifyplayer, opsOverridePerms;
|
||||||
public boolean invertedStairCheck, seatOccupiedCheck, invertedStepCheck, perItemPerms;
|
public boolean invertedStairCheck, seatOccupiedCheck, invertedStepCheck, perItemPerms;
|
||||||
@ -35,9 +33,12 @@ public class Chairs extends JavaPlugin {
|
|||||||
public static final String LOG_HEADER = "[" + PLUGIN_NAME + "]";
|
public static final String LOG_HEADER = "[" + PLUGIN_NAME + "]";
|
||||||
static final Logger log = Logger.getLogger("Minecraft");
|
static final Logger log = Logger.getLogger("Minecraft");
|
||||||
public PluginManager pm;
|
public PluginManager pm;
|
||||||
|
public static ChairsIgnoreList ignoreList;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
instance = this;
|
||||||
|
ignoreList = new ChairsIgnoreList();
|
||||||
pm = this.getServer().getPluginManager();
|
pm = this.getServer().getPluginManager();
|
||||||
pluginFolder = getDataFolder();
|
pluginFolder = getDataFolder();
|
||||||
configFile = new File(pluginFolder, "config.yml");
|
configFile = new File(pluginFolder, "config.yml");
|
||||||
@ -45,12 +46,13 @@ public class Chairs extends JavaPlugin {
|
|||||||
this.getConfig().options().copyDefaults(true);
|
this.getConfig().options().copyDefaults(true);
|
||||||
saveConfig();
|
saveConfig();
|
||||||
loadConfig();
|
loadConfig();
|
||||||
EventListener eventListener = new EventListener(this);
|
getServer().getPluginManager().registerEvents(new EventListener(this, ignoreList), this);
|
||||||
getServer().getPluginManager().registerEvents(eventListener, this);
|
getCommand("chairs").setExecutor(new ChairsCommand(this, ignoreList));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
ignoreList.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createConfig() {
|
private void createConfig() {
|
||||||
@ -71,7 +73,7 @@ public class Chairs extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadConfig() {
|
public void loadConfig() {
|
||||||
autoRotate = getConfig().getBoolean("auto-rotate");
|
autoRotate = getConfig().getBoolean("auto-rotate");
|
||||||
sneaking = getConfig().getBoolean("sneaking");
|
sneaking = getConfig().getBoolean("sneaking");
|
||||||
signCheck = getConfig().getBoolean("sign-check");
|
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
|
// Send sit packet to all online players
|
||||||
public void sendSit(Player p) {
|
public void sendSit(Player p) {
|
||||||
Packet40EntityMetadata packet = new Packet40EntityMetadata(p.getPlayer().getEntityId(), new ChairWatcher((byte) 4), false);
|
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));
|
log.log(Level.SEVERE, String.format("%s %s", LOG_HEADER, _message));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Chairs get() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
62
src/net/spoothie/chairs/ChairsCommand.java
Normal file
62
src/net/spoothie/chairs/ChairsCommand.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
77
src/net/spoothie/chairs/ChairsIgnoreList.java
Normal file
77
src/net/spoothie/chairs/ChairsIgnoreList.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -27,9 +27,11 @@ import org.bukkit.permissions.PermissionDefault;
|
|||||||
public class EventListener implements Listener {
|
public class EventListener implements Listener {
|
||||||
|
|
||||||
public Chairs plugin;
|
public Chairs plugin;
|
||||||
|
public ChairsIgnoreList ignoreList;
|
||||||
|
|
||||||
public EventListener(Chairs plugin) {
|
public EventListener(Chairs plugin, ChairsIgnoreList ignoreList) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
this.ignoreList = ignoreList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -96,6 +98,7 @@ public class EventListener implements Listener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
if (event.hasBlock() && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
if (event.hasBlock() && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||||
|
|
||||||
Block block = event.getClickedBlock();
|
Block block = event.getClickedBlock();
|
||||||
Stairs stairs = null;
|
Stairs stairs = null;
|
||||||
Step step = null;
|
Step step = null;
|
||||||
@ -108,6 +111,9 @@ public class EventListener implements Listener {
|
|||||||
sh += 1.0;
|
sh += 1.0;
|
||||||
}
|
}
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
if (ignoreList.isIgnored(player.getName())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Permissions Check
|
// Permissions Check
|
||||||
if (plugin.permissions) {
|
if (plugin.permissions) {
|
||||||
if (!player.hasPermission("chairs.sit")) {
|
if (!player.hasPermission("chairs.sit")) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name: Chairs
|
name: Chairs
|
||||||
version: 1.13.5
|
version: 1.15.0
|
||||||
description: Let players sit on blocks.
|
description: Let players sit on blocks.
|
||||||
authors:
|
authors:
|
||||||
- spoothie
|
- spoothie
|
||||||
@ -7,5 +7,15 @@ authors:
|
|||||||
main: net.spoothie.chairs.Chairs
|
main: net.spoothie.chairs.Chairs
|
||||||
commands:
|
commands:
|
||||||
chairs:
|
chairs:
|
||||||
description: Reloads the Chairs configuration file.
|
description: Various commands for Chairs.
|
||||||
usage: /chairs reload
|
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
|
Loading…
Reference in New Issue
Block a user