Skip to content
This repository has been archived by the owner on Feb 7, 2019. It is now read-only.

Commit

Permalink
Added commands, modified how the lang file is handled to better handl…
Browse files Browse the repository at this point in the history
…e errors.

New:
/value - query value of current main hand held block from bentobox level addon block value list.

/stoneores debug - puts stoneores into debug mode so you can see where a process is failing in the code. (As we didn't want to spam console when their was an error)

/stoneores query <string/int> <yaml standard path> - Queries config to pull specific value.
example usage:
/stoneores query string language
/stoneores query int worlds.Example_world.blocktypes.default.COBBLESTONE

Modified:

/stoneores reload - Now also reloads lang file.
  • Loading branch information
ShakeforProtein committed Nov 26, 2018
1 parent a53a795 commit 71d88a6
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 107 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.ShakeforProtein</groupId>
<artifactId>StoneOres</artifactId>
<version>0.11.2</version>
<version>0.11.3</version>
<packaging>jar</packaging>

<name>StoneOres</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
package me.shakeforprotein.stoneores;


import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.World;
import org.bukkit.entity.Player;

import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockFromToEvent;
import world.bentobox.bentobox.BentoBox;


import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class PlayerListener implements Listener {
Expand Down
208 changes: 110 additions & 98 deletions src/main/java/me/shakeforprotein/stoneores/StoneOres.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,130 +52,142 @@ public void onDisable() {

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {

String Language = getConfig().getString("language");
String mp = Language + ".messages.";
api = BentoBox.getInstance();
Player player = (Player) sender;
Player p = player;
int islandLevel = 0;
String currentWorld = player.getLocation().getWorld().getName();
String effWorld2 = currentWorld;
effWorld2.replace("_the_end", "_world").replace("_nether", "_world");

if (cmd.getName().equalsIgnoreCase("value")) {
HumanEntity hE = (HumanEntity) sender;
Integer itemValue = -1;
Integer itemLimit = -1;
String blockLimit = "";
String itemInHand = hE.getInventory().getItemInMainHand().getType().toString();
try {
itemValue = api.getAddonsManager().getAddonByName("Level").get().getConfig().getInt("blocks." + itemInHand);
itemLimit = api.getAddonsManager().getAddonByName("Level").get().getConfig().getInt("limits." + itemInHand);
if (itemLimit > 0) {
blockLimit = " but is worth nothing after " + itemLimit + " blocks of " + itemInHand + " are on your island";
}
} catch (NullPointerException e) {
}
if (itemValue < 1) {
itemValue = 0;
}
p.sendMessage(itemInHand + " has a value of " + itemValue + blockLimit);

} else if ((cmd.getName().equalsIgnoreCase("stoneores")) || (cmd.getName().equalsIgnoreCase("ores"))) {
if (args.length == 3 && args[0].equalsIgnoreCase("query")) {
if (p.hasPermission("stoneores.reload")) {
if (args[1].equalsIgnoreCase("int")) {
p.sendMessage("" + getConfig().getInt("" + args[2]));
} else if (args[1].equalsIgnoreCase("string")) {
p.sendMessage(getConfig().getString(args[2]));
if (sender instanceof Player) {
Player player = (Player) sender;
Player p = player;
int islandLevel = 0;
String currentWorld = player.getLocation().getWorld().getName();
String effWorld2 = currentWorld;
effWorld2.replace("_the_end", "_world").replace("_nether", "_world");

if (cmd.getName().equalsIgnoreCase("value")) {
HumanEntity hE = (HumanEntity) sender;
Integer itemValue = -1;
Integer itemLimit = -1;
String blockLimit = "";
String itemInHand = hE.getInventory().getItemInMainHand().getType().toString();
try {
itemValue = api.getAddonsManager().getAddonByName("Level").get().getConfig().getInt("blocks." + itemInHand);
itemLimit = api.getAddonsManager().getAddonByName("Level").get().getConfig().getInt("limits." + itemInHand);
if (itemLimit > 0) {
blockLimit = " but is worth nothing after " + itemLimit + " blocks of " + itemInHand + " are on your island";
}
} catch (NullPointerException e) {
}
}
if (args.length == 1) {
if (args[0].equalsIgnoreCase("all")) {
getAllGeneratorGroups(player);
} else if (args[0].equalsIgnoreCase("reload")) {
if (player.hasPermission("stoneores.reload")) {
try {
lang.load(langConfig);
} catch (InvalidConfigurationException | IOException e) {
if (itemValue < 1) {
itemValue = 0;
}
p.sendMessage(itemInHand + " has a value of " + itemValue + blockLimit);

} else if ((cmd.getName().equalsIgnoreCase("stoneores")) || (cmd.getName().equalsIgnoreCase("ores"))) {
if (args.length == 3 && args[0].equalsIgnoreCase("query")) {
if (p.hasPermission("stoneores.reload")) {
if (args[1].equalsIgnoreCase("int")) {
p.sendMessage("" + getConfig().getInt("" + args[2]));
} else if (args[1].equalsIgnoreCase("string")) {
p.sendMessage(getConfig().getString(args[2]));
}
reloadConfig();
player.sendMessage(getLang().getString(mp + "configReloaded").replace('&', '§'));
} else {
player.sendMessage(getLang().getString(mp + "noPermission").replace('&', '§'));
}
} else if (args[0].equalsIgnoreCase("debug")) {
if (player.hasPermission("stoneores.reload")) {
if (getConfig().get("debug") == "false") {
getConfig().set("debug", "true");
p.sendMessage("debug enabled");
}
if (args.length == 1) {
if (args[0].equalsIgnoreCase("all")) {
getAllGeneratorGroups(player);
} else if (args[0].equalsIgnoreCase("reload")) {
if (player.hasPermission("stoneores.reload")) {
try {
lang.load(langConfig);
} catch (InvalidConfigurationException | IOException e) {
}
reloadConfig();
player.sendMessage(getLang().getString(mp + "configReloaded").replace('&', '§'));
} else {
getConfig().set("debug", "false");
p.sendMessage("debug Disabled");
player.sendMessage(getLang().getString(mp + "noPermission").replace('&', '§'));
}
} else if (args[0].equalsIgnoreCase("debug")) {
if (player.hasPermission("stoneores.reload")) {
if (getConfig().get("debug") == "false") {
getConfig().set("debug", "true");
p.sendMessage("debug enabled");
} else {
getConfig().set("debug", "false");
p.sendMessage("debug Disabled");
}
}
} else if (args[0].equalsIgnoreCase("version")) {
p.sendMessage("StoneOres - " + this.getDescription().getVersion());
}
} else if (args[0].equalsIgnoreCase("version")) {
p.sendMessage("StoneOres - " + this.getDescription().getVersion());
}
} else {
bentoCallLevel(player.getWorld(), player);
// to set a delay while it runs the level command
getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
public void run() {
Debug("Debug mode enabled", p);
String generatorGroup = "default";
Debug("Generator group = " + generatorGroup, p);
UUID thisIslandOwner = api.getIslands().getIslandAt(player.getLocation()).get().getOwner();
Debug("thisIslandOwner = " + thisIslandOwner, p);
} else {
bentoCallLevel(player.getWorld(), player);
// to set a delay while it runs the level command
getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
public void run() {
Debug("Debug mode enabled", p);
String generatorGroup = "default";
Debug("Generator group = " + generatorGroup, p);
UUID thisIslandOwner = api.getIslands().getIslandAt(player.getLocation()).get().getOwner();
Debug("thisIslandOwner = " + thisIslandOwner, p);

generatorGroup = getGeneratorGroup(player.getWorld(), readPlayerLevelYaml(thisIslandOwner, player.getWorld()));
Debug("Calculated generator group is " + generatorGroup, p);
String[] blocksList = getBlockList(player.getWorld(), generatorGroup);
Debug("Blockslist is " + blocksList, p);
generatorGroup = getGeneratorGroup(player.getWorld(), readPlayerLevelYaml(thisIslandOwner, player.getWorld()));
Debug("Calculated generator group is " + generatorGroup, p);
String[] blocksList = getBlockList(player.getWorld(), generatorGroup);
Debug("Blockslist is " + blocksList, p);


if (getConfig().getConfigurationSection("world." + currentWorld) != null) {
if (getConfig().getConfigurationSection("world." + currentWorld) != null) {


int percentCalc = 0, arrayId = 0, i = 0;
String[] blocktypes = new String[blocksList.length];
String[] cases = new String[50000];
int percentCalc = 0, arrayId = 0, i = 0;
String[] blocktypes = new String[blocksList.length];
String[] cases = new String[50000];


for (String item : blocksList) {
percentCalc += getConfig().getInt("world." + currentWorld + ".blocktypes." + generatorGroup + "." + item);
blocktypes[arrayId] = item;
arrayId++;
for (String item : blocksList) {
percentCalc += getConfig().getInt("world." + currentWorld + ".blocktypes." + generatorGroup + "." + item);
blocktypes[arrayId] = item;
arrayId++;

while (i < percentCalc) {
cases[i] = item;
i++;
while (i < percentCalc) {
cases[i] = item;
i++;
}
}
}


String hasPermission = null;
int percent = 0;
String hasPermission = null;
int percent = 0;


if (generatorGroup != null) {
Debug("Generator permission granted", p);
player.sendMessage(getLang().getString(mp + "hasTier").replace("{permission}", generatorGroup).replace('&', '§'));
player.sendMessage(getLang().getString(mp + "rates").replace('&', '§'));
if (generatorGroup != null) {
Debug("Generator permission granted", p);
player.sendMessage(getLang().getString(mp + "hasTier").replace("{permission}", generatorGroup).replace('&', '§'));
player.sendMessage(getLang().getString(mp + "rates").replace('&', '§'));

}
for (String item : getConfig().getConfigurationSection("world." + currentWorld + ".blocktypes." + generatorGroup).getKeys(false)) {
percent = getConfig().getInt("world." + currentWorld + ".blocktypes." + generatorGroup + "." + item);
double percentDouble = ((double) percent);
player.sendMessage("§3" + item + ": §f" + Math.rint((percentDouble / percentCalc) * 100) + "%");
}
for (String item : getConfig().getConfigurationSection("world." + currentWorld + ".blocktypes." + generatorGroup).getKeys(false)) {
percent = getConfig().getInt("world." + currentWorld + ".blocktypes." + generatorGroup + "." + item);
double percentDouble = ((double) percent);
player.sendMessage("§3" + item + ": §f" + Math.rint((percentDouble / percentCalc) * 100) + "%");
}
}
}
}
}, 40L);
}, 40L);
}
} else {
player.sendMessage("§3 Sorry, that command does not work in this world");
}


} else if (((cmd.getName().equalsIgnoreCase("ores")) || cmd.getName().equalsIgnoreCase("stoneores")) && (args.length == 1) && (args[0].equalsIgnoreCase("reload"))) {
try {
lang.load(langConfig);
} catch (InvalidConfigurationException | IOException e) {
}
} else {
player.sendMessage("§3 Sorry, that command does not work in this world");
reloadConfig();
System.out.println(getLang().getString(mp + "configReloaded").replace('&', '§'));
}

return true;
Expand Down Expand Up @@ -231,7 +243,7 @@ public int readPlayerLevelYaml(UUID ownerID, World world) {
} catch (InvalidConfigurationException | IOException e) {
}

int islandLevel = getPlayerYaml().getInt("levels." + world.getName(), 0);
int islandLevel = getPlayerYaml().getInt("levels." + world.getName().replace("_the_end", "").replace("_nether", ""), 0);
if (islandLevel < 1) {
islandLevel = 0;
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
yamlCreatedInVersion: '0.11.3'

world:
BSkyBlock_world_the_end:
lvlcommand: 'is level'
Expand Down

0 comments on commit 71d88a6

Please sign in to comment.