after a big rewrite and tons of new features, rc1 for 0.3
This commit is contained in:
51
src/main/java/us/camin/regions/commands/MoveinCommand.java
Normal file
51
src/main/java/us/camin/regions/commands/MoveinCommand.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package us.camin.regions.commands;
|
||||
|
||||
/**
|
||||
* This file is part of Regions
|
||||
*
|
||||
* Regions is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Regions is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Regions. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.entity.Player;
|
||||
import us.camin.regions.Plugin;
|
||||
import us.camin.regions.Region;
|
||||
|
||||
public class MoveinCommand implements CommandExecutor {
|
||||
|
||||
Plugin m_plugin;
|
||||
|
||||
public MoveinCommand(Plugin p) {
|
||||
m_plugin = p;
|
||||
}
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] split) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage("Region command is only available to players.");
|
||||
return true;
|
||||
}
|
||||
Player p = (Player)sender;
|
||||
Region nearest = m_plugin.regionManager().nearestRegion(p.getLocation());
|
||||
if (nearest != null) {
|
||||
m_plugin.regionManager().setHomeRegion(p, nearest);
|
||||
sender.sendMessage("Your home region has been set to "+nearest.name());
|
||||
} else {
|
||||
sender.sendMessage("There are no regions in this world.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
122
src/main/java/us/camin/regions/commands/RegionCommand.java
Normal file
122
src/main/java/us/camin/regions/commands/RegionCommand.java
Normal file
@@ -0,0 +1,122 @@
|
||||
package us.camin.regions.commands;
|
||||
|
||||
/**
|
||||
* This file is part of Regions
|
||||
*
|
||||
* Regions is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Regions is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Regions. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import us.camin.regions.Plugin;
|
||||
import us.camin.regions.Region;
|
||||
import us.camin.regions.ui.RegionPostBuilder;
|
||||
|
||||
public class RegionCommand implements CommandExecutor, TabCompleter {
|
||||
|
||||
Plugin m_plugin;
|
||||
|
||||
public RegionCommand(Plugin p) {
|
||||
m_plugin = p;
|
||||
}
|
||||
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
List<String> ret = new ArrayList<String>();
|
||||
if (args.length <= 1) {
|
||||
ret.add("create");
|
||||
ret.add("remove");
|
||||
ret.add("regen");
|
||||
ret.add("regenall");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] split) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage("Region command is only available to players.");
|
||||
return true;
|
||||
}
|
||||
Player p = (Player)sender;
|
||||
if (split.length == 0) {
|
||||
Region r = m_plugin.regionManager().nearestRegion(p.getLocation());
|
||||
if (r == null) {
|
||||
p.sendMessage("There are no regions in this world.");
|
||||
return true;
|
||||
}
|
||||
p.sendMessage("Current region: "+r.coloredName());
|
||||
p.sendMessage("Players in region:");
|
||||
for(Player neighbor : m_plugin.playerWatcher().playersInRegion(r)) {
|
||||
p.sendMessage(neighbor.getName());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
String subCommand = split[0];
|
||||
if (subCommand.equals("create") && p.hasPermission("regions.create")) {
|
||||
if (split.length <= 1) {
|
||||
p.sendMessage("Must specify a region name");
|
||||
return true;
|
||||
}
|
||||
StringBuilder regionName = new StringBuilder();
|
||||
for(int i = 1;i<split.length-1;i++) {
|
||||
regionName.append(split[i]);
|
||||
regionName.append(" ");
|
||||
}
|
||||
regionName.append(split[split.length-1]);
|
||||
Region r = new Region(regionName.toString(), p.getLocation());
|
||||
p.teleport(r.teleportLocation());
|
||||
m_plugin.regionManager().addRegion(r);
|
||||
m_plugin.saveRegions();
|
||||
} else if (subCommand.equals("remove") && p.hasPermission("regions.remove")) {
|
||||
Region r = m_plugin.regionManager().nearestRegion(p.getLocation());
|
||||
if (r == null) {
|
||||
p.sendMessage("There are no regions in this world.");
|
||||
return true;
|
||||
}
|
||||
m_plugin.regionManager().removeRegion(r);
|
||||
p.sendMessage("Deleted region " + r.coloredName());
|
||||
m_plugin.saveRegions();
|
||||
} else if (subCommand.equals("regen") && p.hasPermission("regions.regen")) {
|
||||
Region r = m_plugin.regionManager().nearestRegion(p.getLocation());
|
||||
if (r == null) {
|
||||
p.sendMessage("There are no regions in this world.");
|
||||
} else {
|
||||
p.sendMessage("Regenerating region post...");
|
||||
m_plugin.getServer().getScheduler().runTask(m_plugin, () -> {
|
||||
RegionPostBuilder builder = new RegionPostBuilder(r, m_plugin);
|
||||
builder.build();
|
||||
p.sendMessage("Region post regenerated.");
|
||||
});
|
||||
}
|
||||
} else if (subCommand.equals("regenall") && p.hasPermission("regions.regen.all")) {
|
||||
for(Region r : m_plugin.regionManager().regionsForWorld(p.getLocation().getWorld())) {
|
||||
m_plugin.getServer().getScheduler().runTask(m_plugin, () -> {
|
||||
RegionPostBuilder builder = new RegionPostBuilder(r, m_plugin);
|
||||
builder.build();
|
||||
});
|
||||
}
|
||||
p.sendMessage("Region posts will be regenerated");
|
||||
} else {
|
||||
p.sendMessage("Unknown operation. Options are: create, remove, regen.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
99
src/main/java/us/camin/regions/commands/RegionOpCommand.java
Normal file
99
src/main/java/us/camin/regions/commands/RegionOpCommand.java
Normal file
@@ -0,0 +1,99 @@
|
||||
package us.camin.regions.commands;
|
||||
|
||||
/**
|
||||
* This file is part of Regions
|
||||
*
|
||||
* Regions is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Regions is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Regions. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import us.camin.regions.Plugin;
|
||||
import us.camin.regions.RegionPostItemWatcher;
|
||||
|
||||
public class RegionOpCommand implements CommandExecutor, TabCompleter {
|
||||
Plugin m_plugin;
|
||||
|
||||
public RegionOpCommand(Plugin p) {
|
||||
m_plugin = p;
|
||||
}
|
||||
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
List<String> ret = new ArrayList<String>();
|
||||
ret.add("save");
|
||||
ret.add("load");
|
||||
ret.add("item");
|
||||
ret.add("compass");
|
||||
ret.add("chargeitem");
|
||||
return ret;
|
||||
}
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] split) {
|
||||
String subCommand = split[0];
|
||||
if (subCommand.equals("save") && sender.hasPermission("regions.create")) {
|
||||
m_plugin.saveRegions();
|
||||
sender.sendMessage("Regions saved.");
|
||||
} else if (subCommand.equals("load") && sender.hasPermission("regions.create")) {
|
||||
sender.sendMessage("Reloading regions...");
|
||||
m_plugin.getServer().getScheduler().runTask(m_plugin, () -> {
|
||||
m_plugin.loadRegions();
|
||||
sender.sendMessage("Regions loaded.");
|
||||
});
|
||||
} else if (subCommand.equals("compass") && sender.hasPermission("regions.give-items.compass")) {
|
||||
Player player = (Player)sender;
|
||||
ItemStack compassItem = RegionPostItemWatcher.createCreateItem();
|
||||
if (split.length > 1) {
|
||||
compassItem.setAmount(Integer.parseInt(split[1]));
|
||||
}
|
||||
HashMap<Integer, ItemStack> rejected = player.getInventory().addItem(compassItem);
|
||||
for(ItemStack item : rejected.values()) {
|
||||
player.getLocation().getWorld().dropItem(player.getLocation(), item);
|
||||
}
|
||||
} else if (subCommand.equals("item") && sender.hasPermission("regions.give-items.creator")) {
|
||||
Player player = (Player)sender;
|
||||
ItemStack createItem = RegionPostItemWatcher.createCreateItem();
|
||||
if (split.length > 1) {
|
||||
createItem.setAmount(Integer.parseInt(split[1]));
|
||||
}
|
||||
HashMap<Integer, ItemStack> rejected = player.getInventory().addItem(createItem);
|
||||
for(ItemStack item : rejected.values()) {
|
||||
player.getLocation().getWorld().dropItem(player.getLocation(), item);
|
||||
}
|
||||
} else if (subCommand.equals("chargeitem") && sender.hasPermission("regions.give-items.charge")) {
|
||||
Player player = (Player)sender;
|
||||
ItemStack chargeItem = RegionPostItemWatcher.createChargeItem();
|
||||
if (split.length > 1) {
|
||||
chargeItem.setAmount(Integer.parseInt(split[1]));
|
||||
}
|
||||
HashMap<Integer, ItemStack> rejected = player.getInventory().addItem(chargeItem);
|
||||
for(ItemStack item : rejected.values()) {
|
||||
player.getLocation().getWorld().dropItem(player.getLocation(), item);
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("Unknown operation. Options are save, load, item, compass.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package us.camin.regions.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import us.camin.regions.Plugin;
|
||||
import us.camin.regions.Region;
|
||||
|
||||
public class RegionTabComplete implements TabCompleter {
|
||||
private Plugin m_plugin;
|
||||
|
||||
public RegionTabComplete(Plugin plugin) {
|
||||
m_plugin = plugin;
|
||||
}
|
||||
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return new ArrayList<String>();
|
||||
}
|
||||
Player p = (Player)sender;
|
||||
String fullName = String.join(" ", args);
|
||||
|
||||
ArrayList<String> ret = new ArrayList<String>();
|
||||
Collection<Region> regions = m_plugin.regionManager().regionsForWorld(p.getLocation().getWorld());
|
||||
for (Region r : regions) {
|
||||
if (r.name().startsWith(fullName)) {
|
||||
ret.add(r.name());
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
70
src/main/java/us/camin/regions/commands/RegionsCommand.java
Normal file
70
src/main/java/us/camin/regions/commands/RegionsCommand.java
Normal file
@@ -0,0 +1,70 @@
|
||||
package us.camin.regions.commands;
|
||||
|
||||
/**
|
||||
* This file is part of Regions
|
||||
*
|
||||
* Regions is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Regions is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Regions. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import us.camin.regions.Plugin;
|
||||
import us.camin.regions.Region;
|
||||
|
||||
public class RegionsCommand implements CommandExecutor, TabCompleter {
|
||||
Plugin m_plugin;
|
||||
|
||||
public RegionsCommand(Plugin p) {
|
||||
m_plugin = p;
|
||||
}
|
||||
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
List<String> ret = new ArrayList<String>();
|
||||
for(World w : m_plugin.getServer().getWorlds()) {
|
||||
ret.add(w.getName());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] split) {
|
||||
World world = null;
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player)sender;
|
||||
world = p.getLocation().getWorld();
|
||||
}
|
||||
if (split.length >= 0) {
|
||||
world = m_plugin.getServer().getWorld(String.join(" ", split));
|
||||
}
|
||||
|
||||
if (world == null) {
|
||||
sender.sendMessage("Please specify a world.");
|
||||
return true;
|
||||
}
|
||||
|
||||
sender.sendMessage("Regions in this world:");
|
||||
for (Region r : m_plugin.regionManager().regionsForWorld(world)) {
|
||||
sender.sendMessage(r.coloredName());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user