-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
360 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
136
src/main/java/me/lanzhi/bluestargame/commands/elevatorCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.