Faster chair block check
This commit is contained in:
parent
655d7f1645
commit
dd4fcb9af6
@ -6,6 +6,7 @@ import java.io.FileReader;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -31,10 +32,10 @@ import com.cnaude.chairs.vehiclearrow.NMSAccess;
|
|||||||
|
|
||||||
public class Chairs extends JavaPlugin {
|
public class Chairs extends JavaPlugin {
|
||||||
|
|
||||||
public HashSet<UUID> sitDisabled = new HashSet<UUID>();
|
public final HashSet<UUID> sitDisabled = new HashSet<>();
|
||||||
public ChairEffects chairEffects;
|
public final HashMap<Material, Double> validChairs = new HashMap<>();
|
||||||
public List<ChairBlock> allowedBlocks;
|
public final List<Material> validSigns = new ArrayList<Material>();
|
||||||
public List<Material> validSigns;
|
public final HashSet<String> sitDisabledCommands = new HashSet<>();
|
||||||
public boolean autoRotate, signCheck, notifyplayer;
|
public boolean autoRotate, signCheck, notifyplayer;
|
||||||
public boolean ignoreIfBlockInHand;
|
public boolean ignoreIfBlockInHand;
|
||||||
public double distance;
|
public double distance;
|
||||||
@ -45,8 +46,6 @@ public class Chairs extends JavaPlugin {
|
|||||||
public int sitHealInterval;
|
public int sitHealInterval;
|
||||||
public boolean sitPickupEnabled;
|
public boolean sitPickupEnabled;
|
||||||
public boolean sitDisableAllCommands = false;
|
public boolean sitDisableAllCommands = false;
|
||||||
public HashSet<String> sitDisabledCommands = new HashSet<String>();
|
|
||||||
private Logger log;
|
|
||||||
public String msgSitting, msgStanding, msgOccupied, msgNoPerm, msgReloaded, msgDisabled, msgEnabled, msgCommandRestricted;
|
public String msgSitting, msgStanding, msgOccupied, msgNoPerm, msgReloaded, msgDisabled, msgEnabled, msgCommandRestricted;
|
||||||
|
|
||||||
|
|
||||||
@ -59,6 +58,9 @@ public class Chairs extends JavaPlugin {
|
|||||||
return nmsaccess;
|
return nmsaccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ChairEffects chairEffects;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
log = this.getLogger();
|
log = this.getLogger();
|
||||||
@ -125,7 +127,8 @@ public class Chairs extends JavaPlugin {
|
|||||||
sitPickupEnabled = config.getBoolean("sit-effects.itempickup.enabled", false);
|
sitPickupEnabled = config.getBoolean("sit-effects.itempickup.enabled", false);
|
||||||
|
|
||||||
sitDisableAllCommands = config.getBoolean("sit-restrictions.commands.all");
|
sitDisableAllCommands = config.getBoolean("sit-restrictions.commands.all");
|
||||||
sitDisabledCommands = new HashSet<String>(config.getStringList("sit-restrictions.commands.list"));
|
sitDisabledCommands.clear();
|
||||||
|
sitDisabledCommands.addAll(config.getStringList("sit-restrictions.commands.list"));
|
||||||
|
|
||||||
msgSitting = ChatColor.translateAlternateColorCodes('&',config.getString("messages.sitting"));
|
msgSitting = ChatColor.translateAlternateColorCodes('&',config.getString("messages.sitting"));
|
||||||
msgStanding = ChatColor.translateAlternateColorCodes('&',config.getString("messages.standing"));
|
msgStanding = ChatColor.translateAlternateColorCodes('&',config.getString("messages.standing"));
|
||||||
@ -136,7 +139,7 @@ public class Chairs extends JavaPlugin {
|
|||||||
msgReloaded = ChatColor.translateAlternateColorCodes('&',config.getString("messages.reloaded"));
|
msgReloaded = ChatColor.translateAlternateColorCodes('&',config.getString("messages.reloaded"));
|
||||||
msgCommandRestricted = ChatColor.translateAlternateColorCodes('&',config.getString("messages.command-restricted"));
|
msgCommandRestricted = ChatColor.translateAlternateColorCodes('&',config.getString("messages.command-restricted"));
|
||||||
|
|
||||||
allowedBlocks = new ArrayList<ChairBlock>();
|
validChairs.clear();
|
||||||
for (String s : config.getStringList("sit-blocks")) {
|
for (String s : config.getStringList("sit-blocks")) {
|
||||||
String type;
|
String type;
|
||||||
double sh = 0.7;
|
double sh = 0.7;
|
||||||
@ -148,18 +151,17 @@ public class Chairs extends JavaPlugin {
|
|||||||
Material mat = Material.matchMaterial(type);
|
Material mat = Material.matchMaterial(type);
|
||||||
if (mat != null) {
|
if (mat != null) {
|
||||||
logInfo("Allowed block: " + mat.toString() + " => " + sh);
|
logInfo("Allowed block: " + mat.toString() + " => " + sh);
|
||||||
allowedBlocks.add(new ChairBlock(mat,sh));
|
validChairs.put(mat, sh);
|
||||||
} else {
|
} else {
|
||||||
logError("Invalid block: " + type);
|
logError("Invalid block: " + type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
validSigns = new ArrayList<Material>();
|
validSigns.clear();
|
||||||
for (String type : config.getStringList("valid-signs")) {
|
for (String type : config.getStringList("valid-signs")) {
|
||||||
try {
|
try {
|
||||||
validSigns.add(Material.matchMaterial(type));
|
validSigns.add(Material.matchMaterial(type));
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
logError(e.getMessage());
|
logError(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -199,6 +201,8 @@ public class Chairs extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Logger log;
|
||||||
|
|
||||||
public void logInfo(String _message) {
|
public void logInfo(String _message) {
|
||||||
log.log(Level.INFO, _message);
|
log.log(Level.INFO, _message);
|
||||||
}
|
}
|
||||||
|
@ -156,13 +156,10 @@ public class TrySitEventListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Location getSitLocation(Block block, Float playerYaw) {
|
private Location getSitLocation(Block block, Float playerYaw) {
|
||||||
double sh = 0.7;
|
|
||||||
|
|
||||||
for (ChairBlock cb : plugin.allowedBlocks) {
|
Double sh = plugin.validChairs.get(block.getType());
|
||||||
if (cb.getMat().equals(block.getType())) {
|
if (sh == null) {
|
||||||
sh = cb.getSitHeight();
|
sh = 0.7;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Stairs stairs = null;
|
Stairs stairs = null;
|
||||||
@ -204,12 +201,7 @@ public class TrySitEventListener implements Listener {
|
|||||||
|
|
||||||
|
|
||||||
private boolean isValidChair(Block block) {
|
private boolean isValidChair(Block block) {
|
||||||
for (ChairBlock cb : plugin.allowedBlocks) {
|
return plugin.validChairs.containsKey(block.getType());
|
||||||
if (cb.getMat().equals(block.getType())) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isSitting(Player player) {
|
private boolean isSitting(Player player) {
|
||||||
|
Loading…
Reference in New Issue
Block a user