Skip to content

Commit

Permalink
[3.4.0]更新BluestarAPI版本
Browse files Browse the repository at this point in the history
  • Loading branch information
nullaqua committed Aug 15, 2022
1 parent 1fb9252 commit 9b1d0bc
Show file tree
Hide file tree
Showing 33 changed files with 432 additions and 230 deletions.
15 changes: 4 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.lanzhi</groupId>
<artifactId>BluestarGame</artifactId>
<version>3.3.2</version>
<version>3.4.0</version>
<packaging>jar</packaging>

<name>BluestarGame</name>
Expand Down Expand Up @@ -105,17 +105,10 @@
<version>4.11.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-api-plugin</artifactId>
<version>2.9.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.lanzhi6</groupId>
<artifactId>BluestarAPI</artifactId>
<version>2.6.3</version>
<version>3.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -127,7 +120,7 @@
<dependency>
<groupId>com.github.lanzhi6</groupId>
<artifactId>BluestarGameAPI</artifactId>
<version>3.2.1</version>
<version>3.4.3</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -139,7 +132,7 @@
<dependency>
<groupId>io.github.dreamvoid</groupId>
<artifactId>MiraiMC-Integration</artifactId>
<version>1.7-rc2</version>
<version>1.7</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/me/lanzhi/bluestargame/BluestarGamePlugin.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package me.lanzhi.bluestargame;

import me.lanzhi.bluestarapi.api.Bluestar;
import me.lanzhi.bluestarapi.api.config.AutoSerialize;
import me.lanzhi.bluestarapi.api.config.YamlFile;
import me.lanzhi.api.Bluestar;
import me.lanzhi.api.config.AutoSerialize;
import me.lanzhi.api.config.YamlFile;
import me.lanzhi.bluestargame.Type.CompressedCoal;
import me.lanzhi.bluestargame.Type.Elevator;
import me.lanzhi.bluestargame.Type.SuperSponge;
Expand All @@ -18,8 +18,6 @@
import org.bukkit.ChatColor;
import org.bukkit.command.PluginCommand;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.ServicePriority;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
Expand Down
73 changes: 50 additions & 23 deletions src/main/java/me/lanzhi/bluestargame/Metrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
package me.lanzhi.bluestargame;

import me.lanzhi.bluestarapi.api.config.YamlFile;
import me.lanzhi.api.config.YamlFile;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
Expand Down Expand Up @@ -75,7 +75,19 @@ public Metrics(BluestarGamePlugin plugin,int serviceId)
boolean logErrors=config.getBoolean("bStats.logFailedRequests",false);
boolean logSentData=config.getBoolean("bStats.logSentData",false);
boolean logResponseStatusText=config.getBoolean("bStats.logResponseStatusText",false);
metricsBase=new MetricsBase("bukkit",serverUUID,14294,enabled,this::appendPlatformData,this::appendServiceData,submitDataTask->Bukkit.getScheduler().runTask(plugin,submitDataTask),plugin::isEnabled,(message,error)->this.plugin.getLogger().log(Level.WARNING,message,error),(message)->this.plugin.getLogger().log(Level.INFO,message),logErrors,logSentData,logResponseStatusText);
metricsBase=new MetricsBase("bukkit",
serverUUID,
14294,
enabled,
this::appendPlatformData,
this::appendServiceData,
submitDataTask->Bukkit.getScheduler().runTask(plugin,submitDataTask),
plugin::isEnabled,
(message,error)->this.plugin.getLogger().log(Level.WARNING,message,error),
(message)->this.plugin.getLogger().log(Level.INFO,message),
logErrors,
logSentData,
logResponseStatusText);
}

/**
Expand Down Expand Up @@ -114,7 +126,9 @@ private int getPlayerAmount()
// This fixes java.lang.NoSuchMethodError:
// org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
Method onlinePlayersMethod=Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
return onlinePlayersMethod.getReturnType().equals(Collection.class)?((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size():((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
return onlinePlayersMethod.getReturnType()
.equals(Collection.class)?((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size():((Player[]) onlinePlayersMethod.invoke(
Bukkit.getServer())).length;
}
catch (Exception e)
{
Expand All @@ -131,7 +145,9 @@ public static class MetricsBase
*/
public static final String METRICS_VERSION="3.0.0";

private static final ScheduledExecutorService scheduler=Executors.newScheduledThreadPool(1,task->new Thread(task,"bStats-Metrics"));
private static final ScheduledExecutorService scheduler=Executors.newScheduledThreadPool(1,
task->new Thread(task,
"bStats-Metrics"));

private static final String REPORT_URL="https://bStats.org/api/v2/data/%s";

Expand Down Expand Up @@ -270,29 +286,34 @@ private void submitData()
appendPlatformDataConsumer.accept(baseJsonBuilder);
final JsonObjectBuilder serviceJsonBuilder=new JsonObjectBuilder();
appendServiceDataConsumer.accept(serviceJsonBuilder);
JsonObjectBuilder.JsonObject[] chartData=customCharts.stream().map(customChart->customChart.getRequestJsonObject(errorLogger,logErrors)).filter(Objects::nonNull).toArray(JsonObjectBuilder.JsonObject[]::new);
JsonObjectBuilder.JsonObject[] chartData=customCharts.stream()
.map(customChart->customChart.getRequestJsonObject(
errorLogger,
logErrors))
.filter(Objects::nonNull)
.toArray(JsonObjectBuilder.JsonObject[]::new);
serviceJsonBuilder.appendField("id",serviceId);
serviceJsonBuilder.appendField("customCharts",chartData);
baseJsonBuilder.appendField("service",serviceJsonBuilder.build());
baseJsonBuilder.appendField("serverUUID",serverUuid);
baseJsonBuilder.appendField("metricsVersion",METRICS_VERSION);
JsonObjectBuilder.JsonObject data=baseJsonBuilder.build();
scheduler.execute(()->
{
try
{
// Send the data
sendData(data);
}
catch (Exception e)
{
// Something went wrong! :(
if (logErrors)
{
errorLogger.accept("Could not submit bStats metrics data",e);
}
}
});
{
try
{
// Send the data
sendData(data);
}
catch (Exception e)
{
// Something went wrong! :(
if (logErrors)
{
errorLogger.accept("Could not submit bStats metrics data",e);
}
}
});
}

private void sendData(JsonObjectBuilder.JsonObject data) throws Exception
Expand Down Expand Up @@ -338,15 +359,19 @@ private void sendData(JsonObjectBuilder.JsonObject data) throws Exception
private void checkRelocation()
{
// You can use the property to disable the check in your test environment
if (System.getProperty("bstats.relocatecheck")==null||!System.getProperty("bstats.relocatecheck").equals("false"))
if (System.getProperty("bstats.relocatecheck")==null||!System.getProperty("bstats.relocatecheck")
.equals("false"))
{
// Maven's Relocate is clever and changes strings, too. So we have to use this little
// "trick" ... :D
final String defaultPackage=new String(new byte[]{'o','r','g','.','b','s','t','a','t','s'});
final String examplePackage=new String(new byte[]{'y','o','u','r','.','p','a','c','k','a','g','e'});
// We want to make sure no one just copy & pastes the example and uses the wrong package
// names
if (MetricsBase.class.getPackage().getName().startsWith(defaultPackage)||MetricsBase.class.getPackage().getName().startsWith(examplePackage))
if (MetricsBase.class.getPackage().getName().startsWith(defaultPackage)||MetricsBase.class.getPackage()
.getName()
.startsWith(
examplePackage))
{
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
}
Expand Down Expand Up @@ -813,7 +838,9 @@ public JsonObjectBuilder appendField(String key,String[] values)
{
throw new IllegalArgumentException("JSON values must not be null");
}
String escapedValues=Arrays.stream(values).map(value->"\""+escape(value)+"\"").collect(Collectors.joining(","));
String escapedValues=Arrays.stream(values)
.map(value->"\""+escape(value)+"\"")
.collect(Collectors.joining(","));
appendFieldUnescaped(key,"["+escapedValues+"]");
return this;
}
Expand Down
31 changes: 19 additions & 12 deletions src/main/java/me/lanzhi/bluestargame/Type/CompressedCoal.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.lanzhi.bluestargame.Type;

import de.tr7zw.nbtapi.NBTCompound;
import de.tr7zw.nbtapi.NBTItem;
import me.lanzhi.api.nbt.NBTCompound;
import me.lanzhi.api.nbt.NBTItem;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
Expand Down Expand Up @@ -41,34 +41,41 @@ public enum CompressedCoal implements ConfigurationSerializable
ItemMeta meta=itemm.getItemMeta();
switch (id)
{
case 1 -> {
case 1 ->
{
meta.setDisplayName(ChatColor.GOLD+"烧制煤炭");
allowRecipe=Collections.singletonList(
new NamespacedKey(Bukkit.getPluginManager().getPlugin("BluestarGame"),"compressed_coal"));
allowRecipe=Collections.singletonList(new NamespacedKey(Bukkit.getPluginManager()
.getPlugin("BluestarGame"),
"compressed_coal"));
itemm.setItemMeta(meta);
item=new NBTItem(itemm);
item.addCompound("BluestarGame").setInteger("coal",id);
this.id=id;
}
case 2 -> {
case 2 ->
{
meta.setDisplayName(ChatColor.GOLD+"压缩煤炭");
allowRecipe=Collections.singletonList(
new NamespacedKey(Bukkit.getPluginManager().getPlugin("BluestarGame"),"fired_compressed_coal"));
allowRecipe=Collections.singletonList(new NamespacedKey(Bukkit.getPluginManager()
.getPlugin("BluestarGame"),
"fired_compressed_coal"));
itemm.setItemMeta(meta);
item=new NBTItem(itemm);
item.addCompound("BluestarGame").setInteger("coal",id);
this.id=id;
}
case 3 -> {
case 3 ->
{
meta.setDisplayName(ChatColor.GOLD+"烧制压缩煤炭");
allowRecipe=Collections.singletonList(
new NamespacedKey(Bukkit.getPluginManager().getPlugin("BluestarGame"),"coal_diamond"));
allowRecipe=Collections.singletonList(new NamespacedKey(Bukkit.getPluginManager()
.getPlugin("BluestarGame"),
"coal_diamond"));
itemm.setItemMeta(meta);
item=new NBTItem(itemm);
item.addCompound("BluestarGame").setInteger("coal",id);
this.id=id;
}
default -> {
default ->
{
this.allowRecipe=null;
this.id=0;
this.item=null;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/me/lanzhi/bluestargame/Type/Elevator.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package me.lanzhi.bluestargame.Type;

import me.lanzhi.bluestarapi.api.config.AutoSerializeInterface;
import me.lanzhi.bluestarapi.api.config.SerializeAs;
import me.lanzhi.bluestarapi.api.config.SpecialSerialize;
import me.lanzhi.api.config.AutoSerializeInterface;
import me.lanzhi.api.config.SerializeAs;
import me.lanzhi.api.config.SpecialSerialize;
import org.bukkit.Bukkit;
import org.bukkit.World;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/me/lanzhi/bluestargame/Type/SuperSponge.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.lanzhi.bluestargame.Type;

import me.lanzhi.bluestarapi.api.config.AutoSerializeInterface;
import me.lanzhi.bluestarapi.api.config.SerializeAs;
import me.lanzhi.api.config.AutoSerializeInterface;
import me.lanzhi.api.config.SerializeAs;
import org.bukkit.Location;

@SerializeAs("BluestarGame.SuperSponge")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ public boolean onCommand(@NotNull CommandSender sender,@NotNull Command command,
}
player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(Double.parseDouble(args[2]));
}
else if (args.length==2&&sender instanceof Player)
else if (args.length==2&&sender instanceof Player player)
{
Player player=(Player) sender;
player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(Double.parseDouble(args[1]));
}
else
Expand Down Expand Up @@ -341,8 +340,9 @@ else if (args.length==2&&sender instanceof Player)
r=Integer.parseInt(args[1]);
Location locc=((Player) (sender)).getLocation();
Location loc=new Location(locc.getWorld(),locc.getBlockX(),locc.getBlockY(),locc.getBlockZ());
plugin.getBluestarGameManager().getSuperSpongeManager().add(
new SuperSponge(r,loc,sender.getName(),true,true));
plugin.getBluestarGameManager()
.getSuperSpongeManager()
.add(new SuperSponge(r,loc,sender.getName(),true,true));
return true;
}
if ("makeboom".equals(args[0]))
Expand Down Expand Up @@ -401,11 +401,23 @@ public List<String> onTabComplete(CommandSender sender,Command command,String al
{
if (args.length==1)
{
List<String> tablist=new ArrayList<>(
Arrays.asList("randdamage","randchat","randsheep","24","morediamond","morecoal","morecopper",
"moreiron","moregold","moreemerald","morelapis","respawn","all","auto","spongeR",
"boom","onehealth"
));
List<String> tablist=new ArrayList<>(Arrays.asList("randdamage",
"randchat",
"randsheep",
"24",
"morediamond",
"morecoal",
"morecopper",
"moreiron",
"moregold",
"moreemerald",
"morelapis",
"respawn",
"all",
"auto",
"spongeR",
"boom",
"onehealth"));
if (sender.hasPermission("bluestargame.lanzhi"))
{
tablist.add("newsponge");
Expand Down
Loading

0 comments on commit 9b1d0bc

Please sign in to comment.