-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from Niestrat99/spawn-system
Spawn system
- Loading branch information
Showing
16 changed files
with
517 additions
and
355 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
46 changes: 46 additions & 0 deletions
46
...ukkit/src/main/java/io/github/niestrat99/advancedteleport/commands/spawn/MirrorSpawn.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,46 @@ | ||
package io.github.niestrat99.advancedteleport.commands.spawn; | ||
|
||
import io.github.niestrat99.advancedteleport.commands.ATCommand; | ||
import io.github.niestrat99.advancedteleport.config.CustomMessages; | ||
import io.github.niestrat99.advancedteleport.config.NewConfig; | ||
import io.github.niestrat99.advancedteleport.config.Spawn; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class MirrorSpawn implements ATCommand { | ||
|
||
@Override | ||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String s, @NotNull String[] args) { | ||
if (NewConfig.get().USE_SPAWN.get()) { | ||
if (sender.hasPermission("at.admin.mirrorspawn")) { | ||
String fromWorld = ""; | ||
String toWorld = ""; | ||
if (args.length == 0) { | ||
CustomMessages.sendMessage(sender, "Error.mirrorSpawnNoArguments"); | ||
return true; | ||
} | ||
|
||
if (args.length == 1) { | ||
toWorld = args[0]; | ||
if (sender instanceof Player) { | ||
fromWorld = ((Player) sender).getWorld().getName(); | ||
} else { | ||
CustomMessages.sendMessage(sender, "Error.mirrorSpawnLackOfArguments"); | ||
return false; | ||
} | ||
} | ||
|
||
if (args.length >= 2) { | ||
fromWorld = args[0]; | ||
toWorld = args[1]; | ||
} | ||
|
||
CustomMessages.sendMessage(sender, Spawn.get().mirrorSpawn(fromWorld, toWorld), "{spawn}", toWorld, "{from}", fromWorld); | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...ukkit/src/main/java/io/github/niestrat99/advancedteleport/commands/spawn/RemoveSpawn.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,56 @@ | ||
package io.github.niestrat99.advancedteleport.commands.spawn; | ||
|
||
import io.github.niestrat99.advancedteleport.commands.ATCommand; | ||
import io.github.niestrat99.advancedteleport.config.CustomMessages; | ||
import io.github.niestrat99.advancedteleport.config.NewConfig; | ||
import io.github.niestrat99.advancedteleport.config.Spawn; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.util.StringUtil; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class RemoveSpawn implements ATCommand { | ||
|
||
@Override | ||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String s, @NotNull String[] args) { | ||
if (NewConfig.get().USE_SPAWN.get()) { | ||
if (sender.hasPermission("at.admin.removespawn")) { | ||
String removingSpawn = ""; | ||
if (args.length == 0) { | ||
if (sender instanceof Player) { | ||
removingSpawn = ((Player) sender).getWorld().getName(); | ||
} else { | ||
CustomMessages.sendMessage(sender, "Error.removeSpawnNoArgs"); | ||
return true; | ||
} | ||
} | ||
|
||
if (args.length > 0) { | ||
removingSpawn = args[0]; | ||
} | ||
if (!Spawn.get().doesSpawnExist(removingSpawn)) { | ||
CustomMessages.sendMessage(sender, "Error.noSuchSpawn", "{spawn}", removingSpawn); | ||
return true; | ||
} | ||
CustomMessages.sendMessage(sender, Spawn.get().removeSpawn(removingSpawn)); | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) { | ||
if (sender.hasPermission("at.admin.removespawn") && sender instanceof Player && args.length == 1) { | ||
List<String> spawns = new ArrayList<>(); | ||
StringUtil.copyPartialMatches(args[0], Spawn.get().getSpawns(), spawns); | ||
return spawns; | ||
} | ||
return null; | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...kkit/src/main/java/io/github/niestrat99/advancedteleport/commands/spawn/SetMainSpawn.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,74 @@ | ||
package io.github.niestrat99.advancedteleport.commands.spawn; | ||
|
||
import io.github.niestrat99.advancedteleport.commands.ATCommand; | ||
import io.github.niestrat99.advancedteleport.config.CustomMessages; | ||
import io.github.niestrat99.advancedteleport.config.NewConfig; | ||
import io.github.niestrat99.advancedteleport.config.Spawn; | ||
import org.bukkit.Location; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.util.StringUtil; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class SetMainSpawn implements ATCommand { | ||
|
||
@Override | ||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String s, @NotNull String[] args) { | ||
if (NewConfig.get().USE_SPAWN.get()) { | ||
if (sender.hasPermission("at.admin.setmainspawn")) { | ||
String id; | ||
boolean world = true; | ||
if (args.length > 0) { | ||
if (!args[0].matches("^[0-9A-Za-z\\-_]+$")) { | ||
CustomMessages.sendMessage(sender, "Error.nonAlphanumericSpawn"); | ||
return true; | ||
} | ||
id = args[0]; | ||
world = false; | ||
} else if (sender instanceof Player) { | ||
id = ((Player) sender).getWorld().getName(); | ||
} else { | ||
CustomMessages.sendMessage(sender, "Error.cannotSetMainSpawnConsole"); | ||
return true; | ||
} | ||
|
||
Location loc; | ||
if (!Spawn.get().doesSpawnExist(id)) { | ||
if (sender instanceof Player) { | ||
if (sender.hasPermission("at.member.setspawn") | ||
&& (world || sender.hasPermission("at.member.setspawn.other"))) { | ||
loc = ((Player) sender).getLocation(); | ||
Spawn.get().setSpawn(loc, id); | ||
} else { | ||
CustomMessages.sendMessage(sender, "Error.cannotSetMainSpawn"); | ||
return true; | ||
} | ||
} else { | ||
CustomMessages.sendMessage(sender, "Error.cannotSetMainSpawnConsole"); | ||
return true; | ||
} | ||
} else { | ||
loc = Spawn.get().getSpawn(id); | ||
} | ||
CustomMessages.sendMessage(sender, Spawn.get().setMainSpawn(id, loc), "{spawn}", id); | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) { | ||
if (sender.hasPermission("at.admin.setmainspawn") && sender instanceof Player && args.length == 1) { | ||
List<String> spawns = new ArrayList<>(); | ||
StringUtil.copyPartialMatches(args[0], Spawn.get().getSpawns(), spawns); | ||
return spawns; | ||
} | ||
return null; | ||
} | ||
} |
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
Oops, something went wrong.