forked from Upstream/CommandPanels
v3.14.4.3
This commit is contained in:
parent
6a82798728
commit
f630b180fb
@ -1,4 +1,4 @@
|
|||||||
version: 3.14.4.2
|
version: 3.14.4.3
|
||||||
main: me.rockyhawk.commandpanels.CommandPanels
|
main: me.rockyhawk.commandpanels.CommandPanels
|
||||||
name: CommandPanels
|
name: CommandPanels
|
||||||
author: RockyHawk
|
author: RockyHawk
|
||||||
|
@ -4,6 +4,7 @@ import org.bukkit.configuration.ConfigurationSection;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.inventory.ClickType;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.event.inventory.InventoryType;
|
import org.bukkit.event.inventory.InventoryType;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@ -20,7 +21,7 @@ public class Utils implements Listener {
|
|||||||
//when clicked on a panel
|
//when clicked on a panel
|
||||||
Player p = (Player)e.getWhoClicked();
|
Player p = (Player)e.getWhoClicked();
|
||||||
ItemStack clicked = e.getCurrentItem();
|
ItemStack clicked = e.getCurrentItem();
|
||||||
if(!plugin.openPanels.hasPanelOpen(p.getName()) || e.getSlotType() == InventoryType.SlotType.OUTSIDE){
|
if(!plugin.openPanels.hasPanelOpen(p.getName()) || e.getSlotType() == InventoryType.SlotType.OUTSIDE || e.getClick() == ClickType.DOUBLE_CLICK){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ConfigurationSection cf = plugin.openPanels.getOpenPanel(p.getName()); //this is the panel cf section
|
ConfigurationSection cf = plugin.openPanels.getOpenPanel(p.getName()); //this is the panel cf section
|
||||||
|
@ -51,11 +51,27 @@ public class CommandTags {
|
|||||||
plugin.panelData.setUserData(p.getUniqueId(),command.split("\\s")[1],command.split("\\s")[2],false);
|
plugin.panelData.setUserData(p.getUniqueId(),command.split("\\s")[1],command.split("\\s")[2],false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "math-data=":{
|
||||||
|
//only works if data is number, goes math-data= [data point] [operator:number] eg, math-data= -1 OR /3
|
||||||
|
plugin.panelData.doDataMath(p.getUniqueId(),command.split("\\s")[1],command.split("\\s")[2]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "clear-data=":{
|
||||||
|
//will clear all data for player clear-data= [playerName]
|
||||||
|
plugin.panelData.clearData(p.getUniqueId());
|
||||||
|
break;
|
||||||
|
}
|
||||||
case "del-data=":{
|
case "del-data=":{
|
||||||
//this will remove data. del-data= [data point]
|
//this will remove data. del-data= [data point]
|
||||||
plugin.panelData.delUserData(p.getUniqueId(),command.split("\\s")[1]);
|
plugin.panelData.delUserData(p.getUniqueId(),command.split("\\s")[1]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "give-item=":{
|
||||||
|
//this will remove data. give-item= [custom item]
|
||||||
|
ItemStack itm = plugin.itemCreate.makeItemFromConfig(plugin.openPanels.getOpenPanel(p.getName()).getConfigurationSection("custom-item." + command.split("\\s")[1]), p, true, true, false);
|
||||||
|
p.getInventory().addItem(itm);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case "open=":{
|
case "open=":{
|
||||||
//if player uses open= it will open the panel, with the option to add custom placeholders
|
//if player uses open= it will open the panel, with the option to add custom placeholders
|
||||||
String panelName = commandRAW.split("\\s")[1];
|
String panelName = commandRAW.split("\\s")[1];
|
||||||
|
@ -5,7 +5,10 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.BigInteger;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class PanelDataLoader {
|
public class PanelDataLoader {
|
||||||
CommandPanels plugin;
|
CommandPanels plugin;
|
||||||
@ -19,9 +22,18 @@ public class PanelDataLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setUserData(UUID playerUUID, String dataPoint, String dataValue, boolean overwrite){
|
public void setUserData(UUID playerUUID, String dataPoint, String dataValue, boolean overwrite){
|
||||||
|
//if it exists no overwriting
|
||||||
if(!overwrite && dataConfig.isSet("playerData." + playerUUID + "." + dataPoint)){
|
if(!overwrite && dataConfig.isSet("playerData." + playerUUID + "." + dataPoint)){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//check if string is numeric
|
||||||
|
Pattern pattern = Pattern.compile("-?\\d+(\\.\\d+)?");
|
||||||
|
if(pattern.matcher(dataValue).matches()){
|
||||||
|
doDataMath(playerUUID, dataPoint, dataValue);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
dataConfig.set("playerData." + playerUUID + "." + dataPoint, dataValue);
|
dataConfig.set("playerData." + playerUUID + "." + dataPoint, dataValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,6 +41,10 @@ public class PanelDataLoader {
|
|||||||
dataConfig.set("playerData." + playerUUID + "." + dataPoint, null);
|
dataConfig.set("playerData." + playerUUID + "." + dataPoint, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clearData(UUID playerUUID){
|
||||||
|
dataConfig.set("playerData." + playerUUID, null);
|
||||||
|
}
|
||||||
|
|
||||||
public void saveDataFile(){
|
public void saveDataFile(){
|
||||||
try {
|
try {
|
||||||
dataConfig.save(plugin.getDataFolder() + File.separator + "data.yml");
|
dataConfig.save(plugin.getDataFolder() + File.separator + "data.yml");
|
||||||
@ -37,4 +53,56 @@ public class PanelDataLoader {
|
|||||||
plugin.debug(s);
|
plugin.debug(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void doDataMath(UUID playerUUID, String dataPoint, String dataValue){
|
||||||
|
BigDecimal originalValue;
|
||||||
|
BigDecimal newValue;
|
||||||
|
try {
|
||||||
|
originalValue = new BigDecimal(dataConfig.getString("playerData." + playerUUID + "." + dataPoint));
|
||||||
|
}catch(Exception ex){
|
||||||
|
plugin.debug(ex);
|
||||||
|
originalValue = BigDecimal.ONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
BigDecimal output;
|
||||||
|
switch(dataValue.charAt(0)){
|
||||||
|
case '+':{
|
||||||
|
newValue = new BigDecimal(dataValue.substring(1));
|
||||||
|
output = originalValue.add(newValue);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case '-':{
|
||||||
|
newValue = new BigDecimal(dataValue.substring(1));
|
||||||
|
output = originalValue.subtract(newValue);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case '*':{
|
||||||
|
newValue = new BigDecimal(dataValue.substring(1));
|
||||||
|
output = originalValue.multiply(newValue);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case '/':{
|
||||||
|
newValue = new BigDecimal(dataValue.substring(1));
|
||||||
|
try {
|
||||||
|
output = originalValue.divide(newValue);
|
||||||
|
}catch (ArithmeticException ex){
|
||||||
|
plugin.debug(ex);
|
||||||
|
output = originalValue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:{
|
||||||
|
newValue = new BigDecimal(dataValue);
|
||||||
|
output = newValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//if number is integer
|
||||||
|
if(output.stripTrailingZeros().scale() <= 0){
|
||||||
|
dataConfig.set("playerData." + playerUUID + "." + dataPoint, output.stripTrailingZeros().toPlainString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dataConfig.set("playerData." + playerUUID + "." + dataPoint, output.toPlainString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user