Skip to content

Commit

Permalink
null
Browse files Browse the repository at this point in the history
  • Loading branch information
nullaqua committed Mar 14, 2022
1 parent 87851bc commit 4ec1137
Show file tree
Hide file tree
Showing 9 changed files with 360 additions and 23 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.2.1</version>
<version>2.3.0</version>
<packaging>jar</packaging>

<name>BluestarGame</name>
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/me/lanzhi/bluestargame/BluestarGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@

import me.lanzhi.bluestargame.Ctrls.CTRL;
import me.lanzhi.bluestargame.Ctrls.CtrlSponge;
import me.lanzhi.bluestargame.Type.Public;
import me.lanzhi.bluestargame.Type.elevator;
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;
import me.lanzhi.bluestargame.commands.*;
import me.lanzhi.bluestargame.listener.HealthFix;
import org.bukkit.Bukkit;
import org.bukkit.Material;
Expand All @@ -29,19 +28,23 @@ public final class BluestarGame extends org.bukkit.plugin.java.JavaPlugin
public static YamlFile config;
public static File PlayerData;
public static YamlFile PlayerMap;
public static YamlFile Data;
BukkitTask task;

@Override
public void onEnable()
{
ConfigurationSerialization.registerClass(muted.class);
ConfigurationSerialization.registerClass(superSponge.class);
ConfigurationSerialization.registerClass(elevator.class);
ConfigurationSerialization.registerClass(Public.class);

saveDefaultConfig();

plugin = this;
config = new YamlFile(new File(plugin.getDataFolder(),"config.yml"));
PlayerMap=new YamlFile(new File(plugin.getDataFolder(),"playerMap.yml"));
PlayerMap = new YamlFile(new File(plugin.getDataFolder(),"playerMap.yml"));
Data = new YamlFile(new File(plugin.getDataFolder(),"data.yml"));
PlayerData = new File(plugin.getDataFolder(),"PlayerData");
PlayerData.mkdirs();

Expand All @@ -55,6 +58,7 @@ public void onEnable()
getCommand("muted").setExecutor(new mutedCommand());
getCommand("chat").setExecutor(new chat());
getCommand("bluestaritem").setExecutor(new bluestaritem());
getCommand("elevator").setExecutor(new elevatorCommand());

if (config.getBoolean("auto"))
{
Expand Down Expand Up @@ -90,6 +94,7 @@ public void onDisable()
config.set("superSponges",CtrlSponge.get());
config.save();
PlayerMap.save();
Data.save();
System.out.println("BluestarGame已卸载");
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/me/lanzhi/bluestargame/RegisterListeners.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package me.lanzhi.bluestargame;

import me.lanzhi.bluestargame.listener.DoMute;
import me.lanzhi.bluestargame.listener.HealthFix;
import me.lanzhi.bluestargame.listener.PlaceSponge;
import me.lanzhi.bluestargame.listener.Sword;
import me.lanzhi.bluestargame.listener.*;
import me.lanzhi.bluestargame.listener.randoms.*;
import org.bukkit.Bukkit;
import org.bukkit.event.Listener;
Expand All @@ -28,6 +25,7 @@ public static void registerListeners()
registerlistener(new RandSheepColor());
registerlistener(new Respawn());
registerlistener(new The24Point());
registerlistener(new Elevator());
}
private static void registerlistener(Listener listener)
{
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/me/lanzhi/bluestargame/Type/Public.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package me.lanzhi.bluestargame.Type;

import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.jetbrains.annotations.NotNull;

import java.util.HashMap;
import java.util.Map;

public class Public implements ConfigurationSerializable
{
public Map<String, Object>map;
public Public(Map<String,Object> map)
{
this.map = map;
if (map == null)this.map = new HashMap<>();
}
@NotNull
@Override
public Map<String,Object> serialize()
{
return map;
}
}
92 changes: 92 additions & 0 deletions src/main/java/me/lanzhi/bluestargame/Type/elevator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package me.lanzhi.bluestargame.Type;

import org.bukkit.Location;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import static me.lanzhi.bluestargame.BluestarGame.Data;

public class elevator implements ConfigurationSerializable
{
private final long minX,maxX,minZ,maxZ,maxY,minY;
public elevator(long minX,long maxX,long minZ,long maxZ,long minY,long maxY)
{
this.minX = minX;
this.maxX = maxX;
this.minZ = minZ;
this.maxZ = maxZ;
this.minY = minY;
this.maxY = maxY;
}
public long getMinX() {
return minX;
}
public long getMaxX() {
return maxX;
}
public long getMinZ() {
return minZ;
}
public long getMaxZ() {
return maxZ;
}
public long getMaxY() {
return maxY;
}
public long getMinY() {
return minY;
}

public elevator(Map<String,Object> map)
{
this.minX = (int)map.get("minX");
this.maxX = (int)map.get("maxX");
this.minZ = (int)map.get("minZ");
this.maxZ = (int)map.get("maxZ");
this.minY = (int)map.get("minY");
this.maxY = (int)map.get("maxY");
}
@NotNull
@Override
public Map<String,Object> serialize()
{
Map<String,Object> map=new HashMap<>();
map.put("minY",getMinY());
map.put("maxY",getMaxY());
map.put("minX",getMinX());
map.put("maxX",getMaxX());
map.put("minZ",getMinZ());
map.put("maxZ",getMaxZ());
return map;
}
@Nullable
public static elevator getElevator(Location loc)
{
Public test=((Public)Data.get("elevators"));
if(test==null)return null;
Map<String,Object> elevators=(test.map);
if (elevators==null)
{
return null;
}
Set<String> keys=elevators.keySet();
for (String s:keys)
{
if (!(elevators.get(s) instanceof elevator))continue;
elevator ss=(elevator) elevators.get(s);
if (ss.getMaxX()>=loc.getBlockX()&&ss.getMinX()<=loc.getBlockX()&&
ss.getMaxZ()>=loc.getBlockZ()&&ss.getMinZ()<=loc.getBlockZ()&&
ss.getMaxY()>=loc.getBlockY()&&ss.getMinY()<=loc.getBlockY())
{
return ss;
}
}
return null;
}
}
136 changes: 136 additions & 0 deletions src/main/java/me/lanzhi/bluestargame/commands/elevatorCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package me.lanzhi.bluestargame.commands;

import me.lanzhi.bluestargame.Type.Public;
import me.lanzhi.bluestargame.Type.elevator;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.*;

import static me.lanzhi.bluestargame.BluestarGame.Data;

public class elevatorCommand implements CommandExecutor, TabExecutor
{

@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;
}
if (args.length==0){sender.sendMessage(ChatColor.RED+"格式错误");return false;}
if (args[0].equals("add"))
{
if (args.length!=8)
{
sender.sendMessage(ChatColor.RED+"格式错误!");
return false;
}
Map<String,Object> ele=new HashMap<>();
try
{
ele.put("minX",Integer.parseInt(args[2]));
ele.put("maxX",Integer.parseInt(args[3]));
ele.put("minZ",Integer.parseInt(args[4]));
ele.put("maxZ",Integer.parseInt(args[5]));
ele.put("minY",Integer.parseInt(args[6]));
ele.put("maxY",Integer.parseInt(args[7]));
}
catch (NumberFormatException e)
{
sender.sendMessage(ChatColor.RED+"错误!X,Z,Y应均为整数");
return false;
}
Public test=(Public) Data.get("elevators");
if (test==null)test=new Public(null);
test.map.put(args[1],new elevator(ele));
Data.set("elevators",test);
sender.sendMessage(ChatColor.RED+"添加成功");
return true;
}
if (args[0].equals("list"))
{
Public test=(Public) Data.get("elevators");
if (test==null){sender.sendMessage(ChatColor.RED+"没有电梯");return false;}
Set<String>elevators=test.map.keySet();
sender.sendMessage(ChatColor.GOLD+"电梯列表:");
for (String s:elevators)
{
sender.sendMessage(ChatColor.WHITE+s);
}
return true;
}
if (args[0].equals("remove"))
{
if(args.length<2)
{
sender.sendMessage(ChatColor.RED+"格式错误");return false;
}
Public test=(Public) Data.get("elevators");
if (test==null)test=new Public(null);
test.map.remove(args[1]);
Data.set("elevators",test);
sender.sendMessage(ChatColor.RED+"已删除");
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)
{
if (args.length == 1)
{
return Arrays.asList("add","remove","list");
}
if (args[0].equals("add"))
{
if (args.length==2)
{
return Arrays.asList("电梯名称");
}
if (args.length==3)
{
return Arrays.asList("minX",((Player)sender).getLocation().getBlockX()+"");
}
if (args.length==4)
{
return Arrays.asList("maxX",((Player)sender).getLocation().getBlockX()+"");
}
if (args.length==5)
{
return Arrays.asList("minZ",((Player)sender).getLocation().getBlockZ()+"");
}
if (args.length==6)
{
return Arrays.asList("maxZ",((Player)sender).getLocation().getBlockZ()+"");
}
if (args.length==7)
{
return Arrays.asList("minY",((Player)sender).getLocation().getBlockY()+"");
}
if (args.length==8)
{
return Arrays.asList("maxY",((Player)sender).getLocation().getBlockY()+"");
}
}
if (args[0].equals("remove"))
{
if (args.length==2)
{
return Arrays.asList("电梯名称");
}
}
return null;
}
}
Loading

0 comments on commit 4ec1137

Please sign in to comment.