use of com.sk89q.worldguard.bukkit.WorldGuardPlugin in project AreaShop by NLthijs48.
the class WorldGuardRegionFlagsFeature method updateRegionFlags.
/**
* Set the region flags/options to the values of a ConfigurationSection.
* @param region The region to update the flags for
* @param flags The flags to apply
* @return true if the flags have been set correctly, otherwise false
*/
private boolean updateRegionFlags(GeneralRegion region, ConfigurationSection flags) {
boolean result = true;
Set<String> flagNames = flags.getKeys(false);
WorldGuardPlugin worldGuard = plugin.getWorldGuard();
// Get the region
ProtectedRegion worldguardRegion = region.getRegion();
if (worldguardRegion == null) {
AreaShop.debug("Region '" + region.getName() + "' does not exist, setting flags failed");
return false;
}
// Loop through all flags that are set in the config
for (String flagName : flagNames) {
String value = Message.fromString(flags.getString(flagName)).replacements(region).getPlain();
// In the config normal Bukkit color codes are used, those only need to be translated on 5.X WorldGuard versions
if (plugin.getWorldGuard().getDescription().getVersion().startsWith("5.")) {
value = translateBukkitToWorldGuardColors(value);
}
if (flagName.equalsIgnoreCase("members")) {
plugin.getWorldGuardHandler().setMembers(worldguardRegion, parseAccessSet(value));
// AreaShop.debug(" Flag " + flagName + " set: " + members.toUserFriendlyString());
} else if (flagName.equalsIgnoreCase("owners")) {
plugin.getWorldGuardHandler().setOwners(worldguardRegion, parseAccessSet(value));
// AreaShop.debug(" Flag " + flagName + " set: " + owners.toUserFriendlyString());
} else if (flagName.equalsIgnoreCase("priority")) {
try {
int priority = Integer.parseInt(value);
if (worldguardRegion.getPriority() != priority) {
worldguardRegion.setPriority(priority);
}
// AreaShop.debug(" Flag " + flagName + " set: " + value);
} catch (NumberFormatException e) {
AreaShop.warn("The value of flag " + flagName + " is not a number");
result = false;
}
} else if (flagName.equalsIgnoreCase("parent")) {
if (region.getWorld() == null || worldGuard.getRegionManager(region.getWorld()) == null) {
continue;
}
ProtectedRegion parentRegion = worldGuard.getRegionManager(region.getWorld()).getRegion(value);
if (parentRegion != null) {
if (!parentRegion.equals(worldguardRegion.getParent())) {
try {
worldguardRegion.setParent(parentRegion);
// AreaShop.debug(" Flag " + flagName + " set: " + value);
} catch (ProtectedRegion.CircularInheritanceException e) {
AreaShop.warn("The parent set in the config is not correct (circular inheritance)");
}
}
} else {
AreaShop.warn("The parent set in the config is not correct (region does not exist)");
}
} else {
// Parse all other normal flags (groups are also handled)
String flagSetting = null;
com.sk89q.worldguard.protection.flags.RegionGroup groupValue = null;
Flag<?> foundFlag = plugin.getWorldGuardHandler().fuzzyMatchFlag(flagName);
if (foundFlag == null) {
AreaShop.warn("Found wrong flag in flagProfiles section: " + flagName + ", check if that is the correct WorldGuard flag");
continue;
}
RegionGroupFlag groupFlag = foundFlag.getRegionGroupFlag();
if (value == null || value.isEmpty()) {
if (worldguardRegion.getFlag(foundFlag) != null) {
worldguardRegion.setFlag(foundFlag, null);
}
if (groupFlag != null && worldguardRegion.getFlag(groupFlag) != null) {
worldguardRegion.setFlag(groupFlag, null);
}
// AreaShop.debug(" Flag " + flagName + " reset (+ possible group of flag)");
} else {
if (groupFlag == null) {
flagSetting = value;
} else {
for (String part : value.split(" ")) {
if (part.startsWith("g:")) {
if (part.length() > 2) {
try {
groupValue = plugin.getWorldGuardHandler().parseFlagGroupInput(groupFlag, part.substring(2));
} catch (InvalidFlagFormat e) {
AreaShop.warn("Found wrong group value for flag " + flagName);
}
}
} else {
if (flagSetting == null) {
flagSetting = part;
} else {
flagSetting += " " + part;
}
}
}
}
if (flagSetting != null) {
try {
setFlag(worldguardRegion, foundFlag, flagSetting);
// AreaShop.debug(" Flag " + flagName + " set: " + flagSetting);
} catch (InvalidFlagFormat e) {
AreaShop.warn("Found wrong value for flag " + flagName);
}
}
if (groupValue != null) {
if (groupValue == groupFlag.getDefault()) {
worldguardRegion.setFlag(groupFlag, null);
// AreaShop.debug(" Group of flag " + flagName + " set to default: " + groupValue);
} else {
worldguardRegion.setFlag(groupFlag, groupValue);
// AreaShop.debug(" Group of flag " + flagName + " set: " + groupValue);
}
}
}
}
}
// Indicate that the regions needs to be saved
// TODO do we still need this? maybe only for old WorldGuard?
plugin.getFileManager().saveIsRequiredForRegionWorld(region.getWorldName());
return result;
}
use of com.sk89q.worldguard.bukkit.WorldGuardPlugin in project TriggerReactor by wysohn.
the class WorldguardSupport method init.
@Override
public void init() throws APISupportException {
Plugin plugin = Bukkit.getPluginManager().getPlugin("WorldGuard");
if (plugin == null || !(plugin instanceof WorldGuardPlugin)) {
return;
}
wg = (WorldGuardPlugin) plugin;
}
use of com.sk89q.worldguard.bukkit.WorldGuardPlugin in project AreaShop by NLthijs48.
the class AreaShop method onEnable.
/**
* Called on start or reload of the server.
*/
public void onEnable() {
AreaShop.instance = this;
Do.init(this);
managers = new HashSet<>();
boolean error = false;
// Check if WorldGuard is present
String wgVersion = null;
String rawVersion = null;
int major = 0;
int minor = 0;
int fixes = 0;
Integer build = null;
Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
if (plugin == null || !(plugin instanceof WorldGuardPlugin) || !plugin.isEnabled()) {
error("WorldGuard plugin is not present or has not loaded correctly");
error = true;
} else {
worldGuard = (WorldGuardPlugin) plugin;
// Get correct WorldGuardInterface (handles things that changed version to version)
try {
rawVersion = worldGuard.getDescription().getVersion();
if (rawVersion.contains("-SNAPSHOT;")) {
String buildNumber = rawVersion.substring(rawVersion.indexOf("-SNAPSHOT;") + 10, rawVersion.length());
if (buildNumber.contains("-")) {
buildNumber = buildNumber.substring(0, buildNumber.indexOf("-"));
try {
build = Integer.parseInt(buildNumber);
} catch (NumberFormatException e) {
warn("Could not correctly parse the build of WorldGuard, raw version: " + rawVersion + ", buildNumber: " + buildNumber);
}
}
}
// Clear stuff from the version string that is not a number
String[] versionParts = rawVersion.split("\\.");
for (int i = 0; i < versionParts.length; i++) {
Pattern pattern = Pattern.compile("^\\d+");
Matcher matcher = pattern.matcher(versionParts[i]);
if (matcher.find()) {
versionParts[i] = matcher.group();
}
}
// Find major, minor and fix numbers
try {
if (versionParts.length > 0) {
major = Integer.parseInt(versionParts[0]);
}
if (versionParts.length > 1) {
minor = Integer.parseInt(versionParts[1]);
}
if (versionParts.length > 2) {
fixes = Integer.parseInt(versionParts[2]);
}
} catch (NumberFormatException e) {
warn("Something went wrong while parsing WorldGuard version number: " + rawVersion);
}
// Determine correct implementation to use
if (worldGuard.getDescription().getVersion().startsWith("5.")) {
wgVersion = "5";
} else if (major == 6 && minor == 1 && fixes < 3) {
wgVersion = "6";
} else {
if (build != null && build == 1672) {
error = true;
error("Build 1672 of WorldGuard is broken, update to a later build or a stable version!");
} else if (build != null && build < 1672) {
wgVersion = "6";
} else {
wgVersion = "6_1_3";
}
}
} catch (Exception e) {
// If version detection fails, at least try to load the latest version
wgVersion = "6_1_3";
}
// Load chosen implementation
try {
final Class<?> clazz = Class.forName("me.wiefferink.areashop.handlers.WorldGuardHandler" + wgVersion);
// Check if we have a NMSHandler class at that location.
if (WorldGuardInterface.class.isAssignableFrom(clazz)) {
// Make sure it actually implements WorldGuardInterface
// Set our handler
worldGuardInterface = (WorldGuardInterface) clazz.getConstructor(AreaShopInterface.class).newInstance(this);
}
} catch (final Exception e) {
error("Could not load the handler for WorldGuard (tried to load " + wgVersion + "), report this problem to the author:" + ExceptionUtils.getStackTrace(e));
error = true;
wgVersion = null;
}
}
// Check if WorldEdit is present
String weVersion = null;
plugin = getServer().getPluginManager().getPlugin("WorldEdit");
if (plugin == null || !(plugin instanceof WorldEditPlugin) || !plugin.isEnabled()) {
error("WorldEdit plugin is not present or has not loaded correctly");
error = true;
} else {
worldEdit = (WorldEditPlugin) plugin;
// Get correct WorldEditInterface (handles things that changed version to version)
if (worldEdit.getDescription().getVersion().startsWith("5.")) {
weVersion = "5";
} else {
weVersion = "6";
}
try {
final Class<?> clazz = Class.forName("me.wiefferink.areashop.handlers.WorldEditHandler" + weVersion);
// Check if we have a NMSHandler class at that location.
if (WorldEditInterface.class.isAssignableFrom(clazz)) {
// Make sure it actually implements WorldEditInterface
// Set our handler
worldEditInterface = (WorldEditInterface) clazz.getConstructor(AreaShopInterface.class).newInstance(this);
}
} catch (final Exception e) {
error("Could not load the handler for WorldEdit (tried to load " + weVersion + "), report this problem to the author: " + ExceptionUtils.getStackTrace(e));
error = true;
weVersion = null;
}
}
// Check if Vault is present
if (getServer().getPluginManager().getPlugin("Vault") == null) {
error("Vault plugin is not present or has not loaded correctly");
error = true;
}
// Load all data from files and check versions
fileManager = new FileManager();
managers.add(fileManager);
error = error | !fileManager.loadFiles(false);
// Print loaded version of WG and WE in debug
if (wgVersion != null) {
AreaShop.debug("Loaded WorldGuardHandler" + wgVersion + " (raw version: " + rawVersion + ", major:" + major + ", minor:" + minor + ", fixes:" + fixes + ", build:" + build + ")");
}
if (weVersion != null) {
AreaShop.debug("Loaded WorldEditHandler" + weVersion);
}
setupLanguageManager();
if (error) {
error("The plugin has not started, fix the errors listed above");
} else {
featureManager = new FeatureManager();
managers.add(featureManager);
// Register the event listeners
getServer().getPluginManager().registerEvents(new PlayerLoginLogoutListener(this), this);
setupTasks();
// Startup the CommandManager (registers itself for the command)
commandManager = new CommandManager();
managers.add(commandManager);
// Create a signLinkerManager
signLinkerManager = new SignLinkerManager();
managers.add(signLinkerManager);
// Enable Metrics if config allows it
if (getConfig().getBoolean("sendStats")) {
Analytics.start();
}
// Register dynamic permission (things declared in config)
registerDynamicPermissions();
// Don't initialize the updatechecker if disabled in the config
if (getConfig().getBoolean("checkForUpdates")) {
githubUpdateCheck = new GithubUpdateCheck(AreaShop.getInstance(), "NLThijs48", "AreaShop").withVersionComparator((latestVersion, currentVersion) -> !cleanVersion(latestVersion).equals(cleanVersion(currentVersion))).checkUpdate((result) -> {
AreaShop.debug("Update check result:", result);
if (!result.hasUpdate()) {
return;
}
AreaShop.info("Update from AreaShop V" + cleanVersion(result.getCurrentVersion()) + " to AreaShop V" + cleanVersion(result.getLatestVersion()) + " available, get the latest version at https://www.spigotmc.org/resources/areashop.2991/");
for (Player player : Utils.getOnlinePlayers()) {
notifyUpdate(player);
}
});
}
}
}
use of com.sk89q.worldguard.bukkit.WorldGuardPlugin in project MyMaid2 by jaoafa.
the class Cmd_ChuoCity method Command_Land.
/*
* コマンド実行時メソッド
*/
private void Command_Land(CommandSender sender, Command cmd, String commandLabel, String[] args) {
Player player = (Player) sender;
WorldGuardPlugin wg = MyMaid2.getWorldGuard();
Location loc = player.getLocation();
Vector v = new Vector(loc.getX(), loc.getY(), loc.getZ());
RegionManager rm = wg.getRegionManager(player.getWorld());
List<String> regionlist = rm.getApplicableRegionsIDs(v);
if (regionlist.size() == 0) {
SendMessage(sender, cmd, "この場所は登録されていません。");
return;
}
List<ProtectedRegion> inheritance = new LinkedList<ProtectedRegion>();
ProtectedRegion lastregion = null;
for (String region : regionlist) {
ProtectedRegion r = rm.getRegion(region);
if (lastregion == null) {
lastregion = r;
}
inheritance.add(r);
}
Collections.reverse(inheritance);
ListIterator<ProtectedRegion> it = inheritance.listIterator(inheritance.size());
int indent = 0;
while (it.hasPrevious()) {
ProtectedRegion cur = it.previous();
String msg = "";
// Put symbol for child
if (indent != 0) {
for (int i = 0; i < indent; i++) {
msg += " ";
}
msg += "\u2517";
}
// Put name
SendMessage(sender, cmd, msg + cur.getId());
indent++;
}
SendMessage(sender, cmd, "Owners: " + String.join(", ", lastregion.getOwners().getPlayers()));
SendMessage(sender, cmd, "Members: " + String.join(", ", lastregion.getMembers().getPlayers()));
}
use of com.sk89q.worldguard.bukkit.WorldGuardPlugin in project MyMaid2 by jaoafa.
the class Cmd_City method onCommand.
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
Plugin dynmap = plugin.getServer().getPluginManager().getPlugin("dynmap");
if (dynmap == null || !dynmap.isEnabled()) {
SendMessage(sender, cmd, "Dynmapプラグインが停止中、もしくは存在しないため、このコマンドを利用できません。");
return true;
}
if (!(sender instanceof Player)) {
SendMessage(sender, cmd, "このコマンドはサーバ内から実行可能です。");
return true;
}
Player player = (Player) sender;
DynmapAPI dynmapapi = (DynmapAPI) dynmap;
MarkerAPI markerapi = dynmapapi.getMarkerAPI();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
if (args.length >= 1 && args[0].equalsIgnoreCase("help")) {
SendUsageMessage(sender, cmd);
return true;
}
if (markerapi.getMarkerSet("towns") == null) {
Bukkit.getLogger().info("エリア情報を保管するDynmapSets「towns」が存在しないため、作成します。");
markerapi.createMarkerSet("towns", "Towns", null, true);
}
if (args.length == 1) {
if (args[0].equalsIgnoreCase("addcorner")) {
// /city addcorner - コーナーを追加
Set<Location> corner = new LinkedHashSet<Location>();
if (Corner.containsKey(player.getName())) {
corner.addAll(Corner.get(player.getName()));
}
Location loc = player.getLocation();
corner.add(loc);
Corner.put(player.getName(), corner);
SendMessage(sender, cmd, "次の地点をコーナーキューに追加しました: #" + corner.size() + " X: " + loc.getBlockX() + " Z: " + loc.getBlockZ());
return true;
} else if (args[0].equalsIgnoreCase("clearcorner")) {
// /city clearcorner - コーナーを削除
if (Corner.containsKey(player.getName())) {
Corner.remove(player.getName());
SendMessage(sender, cmd, "削除に成功しました。");
return true;
} else {
SendMessage(sender, cmd, "削除に失敗しました。");
return true;
}
} else if (args[0].equalsIgnoreCase("undocorner")) {
// /city undocorner - ひとつ前に追加したコーナーを削除
if (Corner.containsKey(player.getName())) {
Set<Location> corner = new LinkedHashSet<Location>();
int now = 0;
Location loc = null;
for (Location one : Corner.get(player.getName())) {
if (now == (Corner.get(player.getName()).size() - 1)) {
loc = one;
break;
}
corner.add(one);
now++;
}
if (loc == null) {
SendMessage(sender, cmd, "ひとつ前のコーナーの削除に失敗しました。");
return true;
}
Corner.put(player.getName(), corner);
SendMessage(sender, cmd, "ひとつ前のコーナー(X: " + loc.getBlockX() + " / Z: " + loc.getBlockZ() + ")の削除に成功しました。");
return true;
} else {
SendMessage(sender, cmd, "ひとつ前のコーナーの削除に失敗しました。");
return true;
}
} else if (args[0].equalsIgnoreCase("show")) {
// /city show [エリア名] - エリアの情報を表示。エリア名を設定しないといまいるところのエリア情報を表示(できるかどうか)
WorldGuardPlugin wg = MyMaid2.getWorldGuard();
Location loc = player.getLocation();
Vector v = new Vector(loc.getX(), loc.getY(), loc.getZ());
RegionManager rm = wg.getRegionManager(player.getWorld());
List<String> regionlist = rm.getApplicableRegionsIDs(v);
if (regionlist.size() == 0) {
SendMessage(sender, cmd, "この場所は登録されていません。");
return true;
}
List<ProtectedRegion> inheritance = new LinkedList<ProtectedRegion>();
ProtectedRegion lastregion = null;
for (String region : regionlist) {
ProtectedRegion r = rm.getRegion(region);
if (lastregion == null) {
lastregion = r;
}
inheritance.add(r);
}
Collections.reverse(inheritance);
ListIterator<ProtectedRegion> it = inheritance.listIterator(inheritance.size());
int indent = 0;
while (it.hasPrevious()) {
ProtectedRegion cur = it.previous();
String msg = "";
// Put symbol for child
if (indent != 0) {
for (int i = 0; i < indent; i++) {
msg += " ";
}
msg += "\u2517";
}
// Put name
SendMessage(sender, cmd, msg + cur.getId());
indent++;
}
SendMessage(sender, cmd, "Owners: " + String.join(", ", lastregion.getOwners().getPlayers()));
SendMessage(sender, cmd, "Members: " + String.join(", ", lastregion.getMembers().getPlayers()));
return true;
/*
long start = System.currentTimeMillis();
Location now = player.getLocation();
MarkerSet markerset = markerapi.getMarkerSet("towns");
boolean bool = true;
for(AreaMarker areamarker : markerset.getAreaMarkers()){
List<Location> locs = new ArrayList<>();
for(int i = 0; i < areamarker.getCornerCount(); i++){
Location loc = new Location(Bukkit.getWorld(areamarker.getWorld()), areamarker.getCornerX(i), -114514, areamarker.getCornerZ(i));
locs.add(loc);
}
if(inArea(now, locs)){
SendMessage(sender, cmd, "この場所は「" + areamarker.getLabel() + "」という名前のエリアです。");
SendMessage(sender, cmd, "説明: " + areamarker.getDescription());
bool = true;
}
}
if(bool) SendMessage(sender, cmd, "この場所はエリア登録されていません。");
if(DebugMode){
long end = System.currentTimeMillis();
System.out.println("処理時間: " + (end - start) + "ms");
}
*/
/*
MarkerSet markerset = markerapi.getMarkerSet("towns");
for(AreaMarker areamarker : markerset.getAreaMarkers()){
// @param XorZ Xならtrue, Zならfalse
// @param isMaxMaxならtrue, Minならfalse
int maxX = getMaxOrMin(areamarker, true, true);
int maxZ = getMaxOrMin(areamarker, false, true);
int minX = getMaxOrMin(areamarker, true, false);
int minZ = getMaxOrMin(areamarker, false, false);
if(DebugMode) System.out.println("最大最小" + maxX + ", " + maxZ + ", " + minX + ", " + minZ);
ocation playerloc = player.getLocation();
if(playerloc.getX() < minX || playerloc.getZ() > maxX){
double x = playerloc.getX();
double z = playerloc.getZ();
int count = getCorners(areamarker, (int) x, (int) z);
if(DebugMode) System.out.println("Count: " + count);
if(count % 2 != 0){
// 範囲内
SendMessage(sender, cmd, "この場所は「" + areamarker.getLabel() + "」という名前のエリアです。");
SendMessage(sender, cmd, "説明: " + areamarker.getDescription());
if(DebugMode){
long end = System.currentTimeMillis();
System.out.println("処理時間: " + (end - start) + "ms");
}
return true;
}
}
}
SendMessage(sender, cmd, "この場所はエリア登録されていません。");
if(DebugMode){
long end = System.currentTimeMillis();
System.out.println("処理時間: " + (end - start) + "ms");
}
return true;
*/
/*
double minX = 0;
double maxX = 0;
boolean bool = true;
int c = 0;
MarkerSet markerset = markerapi.getMarkerSet("towns");
for(AreaMarker areamarker : markerset.getAreaMarkers()){
for(int i = 0; i < areamarker.getCornerCount(); i++){
double x = areamarker.getCornerX(i);
if(minX > x){
minX = x;
}
if(maxX < x){
maxX = x;
}
c++;
}
}
SendMessage(sender, cmd, "minX: " + minX);
SendMessage(sender, cmd, "maxX: " + maxX);
SendMessage(sender, cmd, "Count: " + c);
if(minX < player.getLocation().getX() && maxX < player.getLocation().getX()){
SendMessage(sender, cmd, "この場所はエリア登録されていません。");
}else if(minX > player.getLocation().getX() && maxX > player.getLocation().getX()){
SendMessage(sender, cmd, "+1");
}else if(minX < player.getLocation().getX() && maxX > player.getLocation().getX()){
SendMessage(sender, cmd, "線分より右にいるのか左にいるのかを判定し、結果次第");
}
*/
}
} else if (args.length == 2) {
if (args[0].equalsIgnoreCase("del")) {
String cityName = args[1];
MarkerSet markerset = markerapi.getMarkerSet("towns");
for (AreaMarker areamarker : markerset.getAreaMarkers()) {
if (areamarker.getLabel().equals(cityName)) {
areamarker.deleteMarker();
SendMessage(sender, cmd, "指定されたエリア名のエリアを削除しました。");
DiscordSend("254166905852657675", "::cityscape:**Cityデータが削除されました。(" + sdf.format(new Date()) + ")**\n" + "プレイヤー: `" + player.getName() + "`\n" + "市名: `" + areamarker.getLabel() + "`");
return true;
}
}
SendMessage(sender, cmd, "指定されたエリア名のエリアは見つかりませんでした。");
return true;
} else if (args[0].equalsIgnoreCase("show")) {
String cityName = args[1];
AreaMarker select = null;
MarkerSet markerset = markerapi.getMarkerSet("towns");
for (AreaMarker areamarker : markerset.getAreaMarkers()) {
if (areamarker.getLabel().equals(cityName)) {
select = areamarker;
}
}
if (select == null) {
SendMessage(sender, cmd, "指定されたエリア名のエリアは見つかりませんでした。");
return true;
}
String label = select.getLabel();
String desc = select.getDescription();
SendMessage(sender, cmd, "--- " + label + " ---");
SendMessage(sender, cmd, "説明: " + desc);
return true;
} else if (args[0].equalsIgnoreCase("addcorner")) {
String cityName = args[1];
AreaMarker select = null;
MarkerSet markerset = markerapi.getMarkerSet("towns");
for (AreaMarker areamarker : markerset.getAreaMarkers()) {
if (areamarker.getLabel().equals(cityName)) {
select = areamarker;
}
}
if (select == null) {
SendMessage(sender, cmd, "指定されたエリア名のエリアは見つかりませんでした。");
return true;
}
List<Double> Xs = new LinkedList<>();
List<Double> Zs = new LinkedList<>();
for (int i = 0; i < select.getCornerCount(); i++) {
Xs.add(select.getCornerX(i));
Zs.add(select.getCornerZ(i));
}
Location loc = player.getLocation();
Xs.add(loc.getBlockX() + 0.5);
Zs.add(loc.getBlockZ() + 0.5);
double[] ArrXs = Xs.stream().mapToDouble(Double::doubleValue).toArray();
double[] ArrZs = Zs.stream().mapToDouble(Double::doubleValue).toArray();
select.setCornerLocations(ArrXs, ArrZs);
SendMessage(sender, cmd, "エリア「" + select.getLabel() + "」に新しいコーナーを追加しました。");
SendMessage(sender, cmd, "順番を変更したりする場合は、「/city editcorner <Name>」コマンドをお使いください。");
return true;
} else if (args[0].equalsIgnoreCase("editcorner")) {
SendMessage(sender, cmd, "システム障害が多くみられるため、一時的にeditcornerの使用を停止しています。");
return true;
/*
String cityName = args[1];
AreaMarker select = null;
MarkerSet markerset = markerapi.getMarkerSet("towns");
for(AreaMarker areamarker : markerset.getAreaMarkers()){
if(areamarker.getLabel().equals(cityName)){
select = areamarker;
}
}
if(select == null){
SendMessage(sender, cmd, "指定されたエリア名のエリアは見つかりませんでした。");
return true;
}
new _OpenGUI(player, select).runTaskLater(plugin, 1);
return true;
*/
}
} else if (args.length == 3) {
if (args[0].equalsIgnoreCase("add")) {
// /city add <Name> <Color> - エリアの範囲を設定(Dynmapに表示)
if (!Corner.containsKey(player.getName())) {
// コーナー未登録
SendMessage(sender, cmd, "コーナーが未登録です。/city addcornerを使用してコーナーを登録してください。");
return true;
}
Set<Location> corner = Corner.get(player.getName());
if (corner.size() < 2) {
// コーナー数が2つ未満
SendMessage(sender, cmd, "コーナー数が足りません。/city addcornerを使用してコーナーを登録してください。");
return true;
}
String cityName = args[1];
String color = args[2];
for (MarkerSet markerset : markerapi.getMarkerSets()) {
for (AreaMarker areamarker : markerset.getAreaMarkers()) {
if (areamarker.getLabel().equals(cityName)) {
SendMessage(sender, cmd, "登録しようとしたエリア名は既に存在します。再登録する場合は削除してください。");
return true;
}
}
}
MarkerSet set = markerapi.getMarkerSet("towns");
List<Double> Xs = new LinkedList<>();
List<Double> Zs = new LinkedList<>();
for (Location loc : corner) {
Xs.add(new Double(loc.getBlockX()) + 0.5);
Zs.add(new Double(loc.getBlockZ()) + 0.5);
}
double[] ArrXs = Xs.stream().mapToDouble(Double::doubleValue).toArray();
double[] ArrZs = Zs.stream().mapToDouble(Double::doubleValue).toArray();
AreaMarker area = set.createAreaMarker(null, cityName, false, player.getWorld().getName(), ArrXs, ArrZs, true);
if (area == null) {
SendMessage(sender, cmd, "登録に失敗しました。");
return true;
}
area.setFillStyle(area.getFillOpacity(), 0x808080);
int colorint;
try {
colorint = Integer.parseInt(color, 16);
} catch (NumberFormatException e) {
SendMessage(sender, cmd, "登録に失敗しました。");
SendMessage(sender, cmd, "色の指定が不正です。");
return true;
}
area.setLineStyle(area.getLineWeight(), area.getLineOpacity(), colorint);
SendMessage(sender, cmd, "登録に成功しました。");
Corner.remove(player.getName());
DiscordSend("254166905852657675", "::cityscape:**Cityデータが追加されました。(" + sdf.format(new Date()) + ")**\n" + "プレイヤー: `" + player.getName() + "`\n" + "市名: `" + area.getLabel() + "`\n" + "市色: " + color + " (16進数: " + colorint + ")");
return true;
} else if (args[0].equalsIgnoreCase("setcolor")) {
// /city color <Name> <Color> - エリアの色を変更
String cityName = args[1];
String color = args[2];
AreaMarker select = null;
MarkerSet markerset = markerapi.getMarkerSet("towns");
for (AreaMarker areamarker : markerset.getAreaMarkers()) {
if (areamarker.getLabel().equals(cityName)) {
select = areamarker;
}
}
if (select == null) {
SendMessage(sender, cmd, "指定されたエリア名のエリアは見つかりませんでした。");
return true;
}
int newcolorint;
try {
newcolorint = Integer.parseInt(color, 16);
} catch (NumberFormatException e) {
SendMessage(sender, cmd, "登録に失敗しました。");
SendMessage(sender, cmd, "色の指定が不正です。");
return true;
}
select.setLineStyle(select.getLineWeight(), select.getLineOpacity(), newcolorint);
SendMessage(sender, cmd, "エリア色の変更に成功しました。");
DiscordSend("254166905852657675", "::cityscape:**Cityデータが変更されました。(" + sdf.format(new Date()) + ") - SETCOLOR**\n" + "プレイヤー: `" + player.getName() + "`\n" + "市名: `" + select.getLabel() + "`\n" + "新市色: " + color + " (16進数: " + newcolorint + ")");
return true;
} else if (args[0].equalsIgnoreCase("setdesc")) {
String cityName = args[1];
String desc = "";
int c = 2;
while (args.length > c) {
desc += args[c] + " ";
c++;
}
AreaMarker select = null;
MarkerSet markerset = markerapi.getMarkerSet("towns");
for (AreaMarker areamarker : markerset.getAreaMarkers()) {
if (areamarker.getLabel().equals(cityName)) {
select = areamarker;
}
}
if (select == null) {
SendMessage(sender, cmd, "指定されたエリア名のエリアは見つかりませんでした。");
return true;
}
desc = htmlspecialchars(desc);
select.setDescription("<b>" + select.getLabel() + "</b><br />" + desc);
SendMessage(sender, cmd, "指定されたエリア名のエリアへ説明文を追加しました。");
DiscordSend("254166905852657675", "::cityscape:**Cityデータが変更されました。(" + sdf.format(new Date()) + ") - SETDESC**\n" + "プレイヤー: `" + player.getName() + "`\n" + "市名: `" + select.getLabel() + "`\n" + "新説明: " + desc);
return true;
}
} else if (args.length >= 3 && args[0].equalsIgnoreCase("setdesc")) {
String cityName = args[1];
String desc = "";
int c = 2;
while (args.length > c) {
desc += args[c] + " ";
c++;
}
AreaMarker select = null;
MarkerSet markerset = markerapi.getMarkerSet("towns");
for (AreaMarker areamarker : markerset.getAreaMarkers()) {
if (areamarker.getLabel().equals(cityName)) {
select = areamarker;
}
}
if (select == null) {
SendMessage(sender, cmd, "指定されたエリア名のエリアは見つかりませんでした。");
return true;
}
desc = htmlspecialchars(desc);
select.setDescription("<b>" + select.getLabel() + "</b><br />" + desc);
SendMessage(sender, cmd, "指定されたエリア名のエリアへ説明文を追加しました。");
DiscordSend("254166905852657675", "::cityscape:**Cityデータが変更されました。(" + sdf.format(new Date()) + ") - SETDESC**\n" + "プレイヤー: `" + player.getName() + "`\n" + "市名: `" + select.getLabel() + "`\n" + "新説明: " + desc);
return true;
}
SendUsageMessage(sender, cmd);
return true;
}
Aggregations