Merge pull request #4 from ORelio/arrow
Save sit disable player preferences between server restarts
This commit is contained in:
commit
deceb53020
@ -41,10 +41,10 @@ public class ChairsCommand implements CommandExecutor {
|
|||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
if (args[0].equalsIgnoreCase("off")) {
|
if (args[0].equalsIgnoreCase("off")) {
|
||||||
plugin.sitDisabled.add(player.getName());
|
plugin.sitDisabled.add(player.getUniqueId());
|
||||||
player.sendMessage(plugin.msgDisabled);
|
player.sendMessage(plugin.msgDisabled);
|
||||||
} else if (args[0].equalsIgnoreCase("on")) {
|
} else if (args[0].equalsIgnoreCase("on")) {
|
||||||
plugin.sitDisabled.remove(player.getName());
|
plugin.sitDisabled.remove(player.getUniqueId());
|
||||||
player.sendMessage(plugin.msgEnabled);
|
player.sendMessage(plugin.msgEnabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
package com.cnaude.chairs.core;
|
package com.cnaude.chairs.core;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@ -26,7 +31,7 @@ import com.cnaude.chairs.vehiclearrow.NMSAccess;
|
|||||||
|
|
||||||
public class Chairs extends JavaPlugin {
|
public class Chairs extends JavaPlugin {
|
||||||
|
|
||||||
public HashSet<String> sitDisabled = new HashSet<String>();
|
public HashSet<UUID> sitDisabled = new HashSet<UUID>();
|
||||||
public ChairEffects chairEffects;
|
public ChairEffects chairEffects;
|
||||||
public List<ChairBlock> allowedBlocks;
|
public List<ChairBlock> allowedBlocks;
|
||||||
public List<Material> validSigns;
|
public List<Material> validSigns;
|
||||||
@ -100,6 +105,7 @@ public class Chairs extends JavaPlugin {
|
|||||||
log = null;
|
log = null;
|
||||||
nmsaccess = null;
|
nmsaccess = null;
|
||||||
psitdata = null;
|
psitdata = null;
|
||||||
|
saveSitDisabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadConfig() {
|
public void loadConfig() {
|
||||||
@ -157,6 +163,40 @@ public class Chairs extends JavaPlugin {
|
|||||||
logError(e.getMessage());
|
logError(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
File sitDisabledFile = new File(getDataFolder(), "sit-disabled.txt");
|
||||||
|
if (sitDisabledFile.exists()) {
|
||||||
|
String line = null;
|
||||||
|
sitDisabled.clear();
|
||||||
|
BufferedReader br = new BufferedReader(new FileReader(sitDisabledFile));
|
||||||
|
while ((line = br.readLine()) != null) {
|
||||||
|
try {
|
||||||
|
sitDisabled.add(UUID.fromString(line));
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
/* Not a UUID */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveSitDisabled() {
|
||||||
|
try {
|
||||||
|
File sitDisabledFile = new File(getDataFolder(), "sit-disabled.txt");
|
||||||
|
if (!sitDisabledFile.exists())
|
||||||
|
sitDisabledFile.createNewFile();
|
||||||
|
PrintWriter writer = new PrintWriter(sitDisabledFile, "UTF-8");
|
||||||
|
writer.println("# The following players disabled Chairs for themselves");
|
||||||
|
for (UUID uuid : sitDisabled)
|
||||||
|
writer.println(uuid.toString());
|
||||||
|
writer.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void logInfo(String _message) {
|
public void logInfo(String _message) {
|
||||||
|
@ -44,7 +44,7 @@ public class TrySitEventListener implements Listener {
|
|||||||
private boolean sitAllowed(Player player, Block block) {
|
private boolean sitAllowed(Player player, Block block) {
|
||||||
|
|
||||||
// Check for sitting disabled
|
// Check for sitting disabled
|
||||||
if (plugin.sitDisabled.contains(player.getName())) {
|
if (plugin.sitDisabled.contains(player.getUniqueId())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user