Skip to content

Commit

Permalink
null
Browse files Browse the repository at this point in the history
  • Loading branch information
nullaqua committed Mar 8, 2022
1 parent 2bb0747 commit 81898b6
Show file tree
Hide file tree
Showing 7 changed files with 270 additions and 55 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.lanzhi</groupId>
<artifactId>BluestarGame</artifactId>
<version>2.1.1</version>
<version>2.2.0</version>
<packaging>jar</packaging>

<name>BluestarGame</name>
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/me/lanzhi/bluestargame/BluestarGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import me.lanzhi.bluestargame.Ctrls.CtrlSponge;
import me.lanzhi.bluestargame.Type.superSponge;
import me.lanzhi.bluestargame.Type.muted;
import me.lanzhi.bluestargame.commands.bluestaritem;
import me.lanzhi.bluestargame.commands.bsgamelist;
import me.lanzhi.bluestargame.commands.chat;
import me.lanzhi.bluestargame.commands.mutedCommand;
Expand All @@ -19,6 +20,7 @@
import me.lanzhi.bluestarapi.Api.YamlFile;

import java.io.File;
import java.util.List;

public final class BluestarGame extends org.bukkit.plugin.java.JavaPlugin
{
Expand All @@ -41,6 +43,7 @@ public void onEnable()
getCommand("bluestargamelist").setExecutor(new bsgamelist());
getCommand("muted").setExecutor(new mutedCommand());
getCommand("chat").setExecutor(new chat());
getCommand("bluestaritem").setExecutor(new bluestaritem());
if (config.getBoolean("auto"))
{
CTRL.runAuto(true);
Expand All @@ -60,7 +63,8 @@ public void onEnable()
lavasponge = lavasponge.shape("a");
lavasponge = lavasponge.setIngredient('a', new RecipeChoice.ExactChoice(superSponge.getSuperSponge().getItem()));
Bukkit.addRecipe(lavasponge);
this.task = new CtrlSponge().ctrlsponge.runTaskTimer(getPlugin(BluestarGame.class), 0L, 2L);
CtrlSponge.set((List<superSponge>) config.getList("superSponges"));
this.task = CtrlSponge.ctrlsponge.runTaskTimer(plugin, 0L, 2L);
System.out.println("BluestarGame已加载");
}

Expand All @@ -71,6 +75,8 @@ public void onDisable()
CTRL.theend();
CTRL.all(false);
Bukkit.clearRecipes();
config.set("superSponges",CtrlSponge.get());
config.save();
System.out.println("BluestarGame已卸载");
}
}
Expand Down
32 changes: 18 additions & 14 deletions src/main/java/me/lanzhi/bluestargame/Ctrls/CtrlSponge.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@

public class CtrlSponge
{
private List<superSponge> nextSponges = new ArrayList();
public org.bukkit.scheduler.BukkitRunnable ctrlsponge = new org.bukkit.scheduler.BukkitRunnable()
private static List<superSponge> nextSponges = new ArrayList<>();
private static List<superSponge> sponges = new ArrayList<>();
public static org.bukkit.scheduler.BukkitRunnable ctrlsponge = new org.bukkit.scheduler.BukkitRunnable()
{
@Override
public void run()
{
List<superSponge> sponges=(List<superSponge>)BluestarGame.config.getList("superSponges");
if ((sponges == null) || (sponges.isEmpty()))
{
return;
}
CtrlSponge.this.nextSponges = new ArrayList();
nextSponges = new ArrayList();
for (superSponge sponge : sponges)
{
Location loc = sponge.getLocation();
Expand All @@ -33,29 +33,33 @@ public void run()
boolean islava=sponge.getIslava();
if (age>1)
{
CtrlSponge.this.decide(new Location(loc.getWorld(), loc.getX() + 1.0D, loc.getY(), loc.getZ()), age, sponge.getPlayer(),iswater,islava);
CtrlSponge.this.decide(new Location(loc.getWorld(), loc.getX() - 1.0D, loc.getY(), loc.getZ()), age, sponge.getPlayer(),iswater,islava);
CtrlSponge.this.decide(new Location(loc.getWorld(), loc.getX(), loc.getY() + 1.0D, loc.getZ()), age, sponge.getPlayer(),iswater,islava);
CtrlSponge.this.decide(new Location(loc.getWorld(), loc.getX(), loc.getY() - 1.0D, loc.getZ()), age, sponge.getPlayer(),iswater,islava);
CtrlSponge.this.decide(new Location(loc.getWorld(), loc.getX(), loc.getY(), loc.getZ() + 1.0D), age, sponge.getPlayer(),iswater,islava);
CtrlSponge.this.decide(new Location(loc.getWorld(), loc.getX(), loc.getY(), loc.getZ() - 1.0D), age, sponge.getPlayer(),iswater,islava);
decide(new Location(loc.getWorld(), loc.getX() + 1.0D, loc.getY(), loc.getZ()), age, sponge.getPlayer(),iswater,islava);
decide(new Location(loc.getWorld(), loc.getX() - 1.0D, loc.getY(), loc.getZ()), age, sponge.getPlayer(),iswater,islava);
decide(new Location(loc.getWorld(), loc.getX(), loc.getY() + 1.0D, loc.getZ()), age, sponge.getPlayer(),iswater,islava);
decide(new Location(loc.getWorld(), loc.getX(), loc.getY() - 1.0D, loc.getZ()), age, sponge.getPlayer(),iswater,islava);
decide(new Location(loc.getWorld(), loc.getX(), loc.getY(), loc.getZ() + 1.0D), age, sponge.getPlayer(),iswater,islava);
decide(new Location(loc.getWorld(), loc.getX(), loc.getY(), loc.getZ() - 1.0D), age, sponge.getPlayer(),iswater,islava);
}
}
BluestarGame.config.set("superSponges", CtrlSponge.this.nextSponges);
sponges=nextSponges;
}
};

private void decide(Location loc, int age, Player player,boolean iswater,boolean islava)
public static void add(superSponge sponge){sponges.add(sponge);}
public static void set(List<superSponge> spongess){sponges=spongess;}
public static List<superSponge> get(){return sponges;}

private static void decide(Location loc, int age, Player player,boolean iswater,boolean islava)
{
if (loc.getBlock().getType()==Material.WATER&&iswater)
{
Bluestar.setBlock(loc, Material.END_STONE, player.getName());
this.nextSponges.add(new superSponge(age-1,loc,player,islava,true));
nextSponges.add(new superSponge(age-1,loc,player,islava,true));
}
if(loc.getBlock().getType()==Material.LAVA&&islava)
{
Bluestar.setBlock(loc, Material.OBSIDIAN, player.getName());
this.nextSponges.add(new superSponge(age-1,loc,player,true,iswater));
nextSponges.add(new superSponge(age-1,loc,player,true,iswater));
}
}
}
Expand Down
90 changes: 90 additions & 0 deletions src/main/java/me/lanzhi/bluestargame/commands/bluestaritem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package me.lanzhi.bluestargame.commands;

import de.tr7zw.nbtapi.NBTItem;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;

public class bluestaritem implements CommandExecutor, TabExecutor
{
String messagehead = ChatColor.GOLD+"[BluestarGame]";
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args)
{
if (!(sender instanceof Player))
{
sender.sendMessage(ChatColor.RED + "此命令仅允许玩家输入!");
return false;
}
Player player=(Player) sender;
if ("watersponge".equals(args[0]))
{
if (player.getInventory().getItemInMainHand().getType().isAir())
{
player.sendMessage(messagehead+ChatColor.RED + "请手持任意物品");
return false;
}
if (!player.getInventory().getItemInMainHand().getType().isBlock())
{
player.sendMessage(messagehead+ChatColor.RED + "检测到您手持的物品不是方块,可能无法放置使得超级海绵生效");
}
NBTItem item = new NBTItem(player.getInventory().getItemInMainHand());
item.addCompound("BluestarGame").setBoolean("waterSponge",true);
player.getInventory().setItemInMainHand(item.getItem());
player.sendMessage(messagehead+ChatColor.GREEN+"已为您手持的物品添加\"超级海绵\"属性");
return true;
}
if ("lavasponge".equals(args[0]))
{
if (player.getInventory().getItemInMainHand().getType().isAir())
{
player.sendMessage(messagehead+ChatColor.RED + "请手持任意物品");
return false;
}
if (!player.getInventory().getItemInMainHand().getType().isBlock())
{
player.sendMessage(messagehead+ChatColor.RED + "检测到您手持的物品不是方块,可能无法放置使得超级海绵生效");
}
NBTItem item = new NBTItem(player.getInventory().getItemInMainHand());
item.addCompound("BluestarGame").setBoolean("lavasponge",true);
player.getInventory().setItemInMainHand(item.getItem());
player.sendMessage(messagehead+ChatColor.GREEN+"已为您手持的物品添加\"岩浆海绵\"属性");
return true;
}
if ("sword".equals(args[0]))
{
if (player.getInventory().getItemInMainHand().getType().isAir())
{
player.sendMessage(messagehead+ChatColor.RED + "请手持任意物品");
return false;
}
NBTItem item = new NBTItem(player.getInventory().getItemInMainHand());
item.addCompound("BluestarGame").setBoolean("sword",true);
player.getInventory().setItemInMainHand(item.getItem());
player.sendMessage(messagehead+ChatColor.GREEN+"已为您手持的物品添加\"op剑\"属性");
return true;
}
sender.sendMessage(ChatColor.RED +"格式错误!");
return false;
}

@Nullable
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args)
{
List<String>tablist =new ArrayList<>();
tablist.add("watersponge");
tablist.add("lavasponge");
tablist.add("sword");
return tablist;
}
}
46 changes: 25 additions & 21 deletions src/main/java/me/lanzhi/bluestargame/commands/maincommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import java.util.ArrayList;
import java.util.List;
import me.lanzhi.bluestargame.Ctrls.CTRL;
import me.lanzhi.bluestargame.Ctrls.CtrlSponge;
import me.lanzhi.bluestargame.Type.superSponge;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.attribute.Attribute;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -242,41 +246,39 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
sender.sendMessage(ChatColor.GREEN + "设置成功");
return true;
}
if (args[0].equals("test"))
if (args[0].equals("newsponge")&&sender.hasPermission("bluestargame.lanzhi"))
{
int r = 0;
int r;
r=Integer.parseInt(args[1]);
Location locc=((Player)(sender)).getLocation();
Location loc=new Location(locc.getWorld(),locc.getBlockX(),locc.getBlockY(),locc.getBlockZ());
CtrlSponge.add(new superSponge(r,loc,(Player)sender,true,true));
return true;
}
if ("boom".equals(args[0])&&sender.hasPermission("bluestargame.lanzhi"))
{
Location location=((Player)sender).getLocation();
try
{
r = Integer.valueOf(args[1]).intValue();
location.getWorld().createExplosion(location,Integer.parseInt(args[1]),true,true);
}
catch (NumberFormatException e)
{
sender.sendMessage(ChatColor.RED + "错误!");
return false;
}
if (r > 100)
{
sender.sendMessage(ChatColor.RED + "范围不能大于100");
return false;
}
Player player = (Player)sender;
player.getLocation().getWorld().createExplosion(player.getLocation(), r, true, true);
return true;
}
if (args[0].equals("newsponge")&&sender.hasPermission("bluestargame.lanzhi"))
if ("health".equals(args[0])&&sender.hasPermission("bluestargame.lanzhi"))
{
List<superSponge> sponges = (List<superSponge>)config.getList("superSponges");
int r;
r=Integer.parseInt(args[1]);
Location locc=((Player)(sender)).getLocation();
Location loc=new Location(locc.getWorld(),locc.getBlockX(),locc.getBlockY(),locc.getBlockZ());
sponges.add(new superSponge(r,loc,(Player)sender,true,true));
Player player=(Player)sender;
player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(Long.parseLong(args[1]));
player.setHealthScaled(false);
return true;
}
if ("boom".equals(args[0])&&sender.hasPermission("bluestargame.lanzhi"))
if ("test".equals(args[0])&&sender.hasPermission("bluestargame.lanzhi"))
{
Location location=((Player)sender).getLocation();
location.getWorld().createExplosion(location,Integer.parseInt(args[1]),true,true);
Player player=(Player)sender;
player.setHealthScaled(!player.isHealthScaled());
return true;
}
sender.sendMessage(ChatColor.RED + "格式错误!");
Expand Down Expand Up @@ -309,6 +311,8 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
{
tablist.add("newsponge");
tablist.add("boom");
tablist.add("health");
tablist.add("reload");
}
return tablist;
}
Expand Down
Loading

0 comments on commit 81898b6

Please sign in to comment.