Skip to content

Commit

Permalink
[3.1.0]小修改+一滴血事件,对应BluestarGameAPI[3.1]
Browse files Browse the repository at this point in the history
  • Loading branch information
nullaqua committed May 6, 2022
1 parent 1ae3788 commit 4d16645
Show file tree
Hide file tree
Showing 11 changed files with 277 additions and 120 deletions.
6 changes: 3 additions & 3 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.0.1</version>
<version>3.1.0</version>
<packaging>jar</packaging>

<name>BluestarGame</name>
Expand Down Expand Up @@ -92,7 +92,7 @@
<dependency>
<groupId>com.github.lanzhi6</groupId>
<artifactId>BluestarAPI</artifactId>
<version>2.0.0</version>
<version>2.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -104,7 +104,7 @@
<dependency>
<groupId>com.github.lanzhi6</groupId>
<artifactId>BluestarGameAPI</artifactId>
<version>1.1.0</version>
<version>3.1</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/me/lanzhi/bluestargame/BluestarGamePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import me.lanzhi.bluestargame.Type.CompressedCoal;
import me.lanzhi.bluestargame.Type.Elevator;
import me.lanzhi.bluestargame.Type.SuperSponge;
import me.lanzhi.bluestargame.managers.BluestarGameManager;
import me.lanzhi.bluestargame.listener.breakBedrockListener;
import me.lanzhi.bluestargame.managers.BluestarGameManager;
import me.lanzhi.bluestargame.register.CommandRegister;
import me.lanzhi.bluestargame.register.ListenersRegister;
import me.lanzhi.bluestargame.register.RecipeRegister;
Expand All @@ -31,11 +31,11 @@ public final class BluestarGamePlugin extends JavaPlugin implements BluestarGame
private final File PlayerData;
private final YamlFile PlayerMap;
private final YamlFile Data;
private Economy econ;
private final String messageHead=ChatColor.GOLD+"["+ChatColor.DARK_AQUA+"BluestarGame"+ChatColor.GOLD+"]";
private final String errorMessageHead=messageHead+ChatColor.RED;
private final SimpleDateFormat BluestarDateFormat;
private final NumberFormat BluestarNF;
private Economy econ;
private BluestarGameManager bluestarGameManager;
private CommandRegister commandRegister;
private ListenersRegister listenersRegister;
Expand Down Expand Up @@ -150,11 +150,13 @@ public YamlFile getConfig()
{
return config;
}

@Override
public void reloadConfig()
{
config.reload();
}

@Override
public void saveConfig()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ else if (args.length==2&&sender instanceof Player)
sender.sendMessage(plugin.getMessageHead()+ChatColor.RED+"格式错误!");
return false;
}
if (args[0].equals("onehealth"))
{
if (args[1].equals("true"))
{
randomEventManger.oneHealth(true);
sender.sendMessage(plugin.getMessageHead()+ChatColor.GREEN+"已设置为true");
}
else
{
randomEventManger.oneHealth(false);
sender.sendMessage(plugin.getMessageHead()+ChatColor.GREEN+"已设置为false");
}
return true;
}
if (args[0].equals("randdamage"))
{
if (args[1].equals("true"))
Expand Down Expand Up @@ -402,6 +416,7 @@ public List<String> onTabComplete(CommandSender sender,Command command,String al
tablist.add("auto");
tablist.add("spongeR");
tablist.add("boom");
tablist.add("onehealth");
if (sender.hasPermission("bluestargame.lanzhi"))
{
tablist.add("newsponge");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,21 @@

public final class BluestarItemCommand implements CommandExecutor, TabExecutor
{
private static List<String> entityType=new ArrayList<>();

static
{
try
{
for (EntityType i: EntityType.values())
{
if (i.getName()==null)
{
continue;
}
entityType.add(i.getName());
}
}
catch (Throwable e)
{
System.out.println("错误在初始化");
}
}
private final List<String> entityType=new ArrayList<>();

private final BluestarGamePlugin plugin;

public BluestarItemCommand(BluestarGamePlugin plugin)
{
this.plugin=plugin;
for (EntityType i: EntityType.values())
{
if (i.getName()==null)
{
continue;
}
entityType.add(i.getName());
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.scheduler.BukkitRunnable;
Expand All @@ -17,43 +18,37 @@
public final class HealthFixListener implements Listener
{
private final BluestarGamePlugin plugin;
private final RandomEventManger randomEventManger;

public HealthFixListener(BluestarGamePlugin plugin)
{
this.plugin=plugin;
randomEventManger=plugin.getBluestarGameManager().getRandomEventManger();
}

@EventHandler(priority=EventPriority.HIGHEST)
public void onPlayerJoin(PlayerLoginEvent event)
@EventHandler(priority=EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event)
{
Player player=event.getPlayer();
player.setHealthScaled(false);
YamlFile playerdata=new YamlFile(new File(plugin.getPlayerData(),player.getUniqueId()+".yml"));
if (playerdata.getDouble("maxhealth")!=0)
YamlFile playerData=YamlFile.loadYamlFile(new File(plugin.getPlayerData(),event.getPlayer().getUniqueId()+".yml"));
double health=playerData.getDouble("health");
double maxHealth=playerData.getDouble("maxhealth");
if (maxHealth!=0)
{
player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(playerdata.getDouble("maxhealth"));
player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(maxHealth);
}
if (playerdata.getDouble("health")!=0)
if (health!=0)
{
player.setHealth(playerdata.getDouble("health"));
player.setHealth(health);
}
new BukkitRunnable()
{
@Override
public void run()
{
Player player=event.getPlayer();
player.setHealthScaled(false);
YamlFile playerdata=new YamlFile(new File(plugin.getPlayerData(),player.getUniqueId()+".yml"));
if (playerdata.getDouble("maxhealth")!=0)
{
player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(playerdata.getDouble("maxhealth"));
}
if (playerdata.getDouble("health")!=0)
if (maxHealth!=0)
{
player.setHealth(playerdata.getDouble("health"));
player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(maxHealth);
}
}
}.runTaskLater(plugin,70);
Expand All @@ -62,8 +57,12 @@ public void run()
@EventHandler(priority=EventPriority.HIGHEST)
public void onPlayerQuit(PlayerQuitEvent event)
{
YamlFile playerData=new YamlFile(new File(plugin.getPlayerData(),event.getPlayer().getUniqueId()+".yml"));
YamlFile playerData=YamlFile.loadYamlFile(new File(plugin.getPlayerData(),event.getPlayer().getUniqueId()+".yml"));
double maxhealth=event.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
if (plugin.getBluestarGameManager().getRandomEventManger().oneHealth())
{
maxhealth=plugin.getBluestarGameManager().getRandomEventManger().oneHealth_playerHealth.get(event.getPlayer());
}
playerData.set("health",Math.min(event.getPlayer().getHealth(),maxhealth));
playerData.set("maxhealth",maxhealth);
playerData.save();
Expand Down
68 changes: 49 additions & 19 deletions src/main/java/me/lanzhi/bluestargame/listener/elevatorListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.scheduler.BukkitRunnable;

public final class elevatorListener implements Listener
{
Expand All @@ -30,24 +33,28 @@ public void onPlayerMove(PlayerMoveEvent event)
return;
}
Location loc=event.getPlayer().getLocation();
Elevator ele=plugin.getBluestarGameManager().getElevator(loc);
if (ele!=null)
Player player=event.getPlayer();
new BukkitRunnable()
{
for (long y=loc.getBlockY()+1;y<=ele.getMaxY();y++)
@Override
public void run()
{
Location locc=loc.clone();
locc.setY(y);
Location loccc=loc.clone();
loccc.setY(y-1);
if ((!locc.getBlock().getType().isSolid()||locc.getBlock().getType().name().endsWith("SIGN"))&&(loccc.getBlock().getType().isSolid()&&!loccc.getBlock().getType().name().endsWith("SIGN")))
Location to=getTeleportLocation(loc,1);
if (to!=null)
{
event.getPlayer().teleport(locc);
event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR,new TextComponent(ChatColor.GREEN+"UP UPP UPPP!"));
event.getPlayer().playSound(event.getPlayer().getLocation(),Sound.ENTITY_PLAYER_LEVELUP,1,1);
return;
new BukkitRunnable()
{
@Override
public void run()
{
player.teleport(to,PlayerTeleportEvent.TeleportCause.CHORUS_FRUIT);
event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR,new TextComponent(ChatColor.GREEN+"UP UPP UPPP!"));
event.getPlayer().playSound(event.getPlayer().getLocation(),Sound.ENTITY_PLAYER_LEVELUP,1,1);
}
}.runTask(plugin);
}
}
}
}.runTaskAsynchronously(plugin);
}

@EventHandler(priority=EventPriority.MONITOR)
Expand All @@ -58,24 +65,47 @@ public void onPlayerSneak(PlayerToggleSneakEvent event)
return;
}
Location loc=event.getPlayer().getLocation();
Player player=event.getPlayer();
new BukkitRunnable()
{
@Override
public void run()
{
Location to=getTeleportLocation(loc,-1);
if (to!=null)
{
new BukkitRunnable()
{
@Override
public void run()
{
player.teleport(to,PlayerTeleportEvent.TeleportCause.CHORUS_FRUIT);
event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR,new TextComponent(ChatColor.GREEN+"DOWN DOWWN DOWWWN!"));
event.getPlayer().playSound(event.getPlayer().getLocation(),Sound.ENTITY_PLAYER_LEVELUP,1,1);
}
}.runTask(plugin);
}
}
}.runTaskAsynchronously(plugin);
}

private Location getTeleportLocation(Location loc,long cnt)
{
Elevator ele=plugin.getBluestarGameManager().getElevator(loc);
if (ele!=null)
{
for (long y=loc.getBlockY()-1;y>=ele.getMinY();y--)
for (long y=loc.getBlockY()+cnt;y<=ele.getMaxY()&&y>=ele.getMinY();y+=cnt)
{
Location locc=loc.clone();
locc.setY(y);
Location loccc=loc.clone();
loccc.setY(y-1);
if ((!locc.getBlock().getType().isSolid()||locc.getBlock().getType().name().endsWith("SIGN"))&&(loccc.getBlock().getType().isSolid()&&!loccc.getBlock().getType().name().endsWith("SIGN")))
{
event.getPlayer().teleport(locc);
event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR,new TextComponent(ChatColor.GREEN+"DOWN DOWWN DOWWWN!"));
event.getPlayer().playSound(event.getPlayer().getLocation(),Sound.ENTITY_PLAYER_LEVELUP,1,1);
return;
return locc;
}
}
}
return null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package me.lanzhi.bluestargame.listener.randoms;

import me.lanzhi.bluestarapi.Api.config.YamlFile;
import me.lanzhi.bluestargame.BluestarGamePlugin;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;

import java.io.File;

public final class oneHealthListener implements Listener
{
private final BluestarGamePlugin plugin;

public oneHealthListener(BluestarGamePlugin plugin)
{
this.plugin=plugin;
}

@EventHandler
public void onPlayerJoin(PlayerJoinEvent event)
{
if (!plugin.getBluestarGameManager().getRandomEventManger().oneHealth())
{
return;
}
double maxHealth=YamlFile.loadYamlFile(new File(plugin.getPlayerData(),event.getPlayer().getUniqueId()+".yml")).getDouble("maxhealth");
plugin.getBluestarGameManager().getRandomEventManger().oneHealth_playerHealth.put(event.getPlayer(),maxHealth!=0?maxHealth:20);
}

@EventHandler
public void onPlayerQuit(PlayerQuitEvent event)
{
if (!plugin.getBluestarGameManager().getRandomEventManger().oneHealth())
{
return;
}
plugin.getBluestarGameManager().getRandomEventManger().oneHealth_playerHealth.remove(event.getPlayer());
}
}
Loading

0 comments on commit 4d16645

Please sign in to comment.