mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-18 08:35:53 +01:00
Completed marshalling implementations for all the flags and changed the LocationFlag to a VectorFlag.
This commit is contained in:
parent
8ffc42d349
commit
b75ab68e7a
@ -44,9 +44,9 @@ public final class DefaultFlag {
|
||||
public static final StringFlag DENY_SPAWN = new StringFlag("deny-spawn");
|
||||
public static final IntegerFlag HEAL_DELAY = new IntegerFlag("heal-delay");
|
||||
public static final IntegerFlag HEAL_AMOUNT = new IntegerFlag("heal-amount");
|
||||
public static final LocationFlag TELE_LOC = new LocationFlag("teleport-loc");
|
||||
public static final VectorFlag TELE_LOC = new VectorFlag("teleport-loc");
|
||||
public static final RegionGroupFlag TELE_PERM = new RegionGroupFlag("teleport-groups");
|
||||
public static final LocationFlag SPAWN_LOC = new LocationFlag("teleport-location");
|
||||
public static final VectorFlag SPAWN_LOC = new VectorFlag("teleport-location");
|
||||
public static final RegionGroupFlag SPAWN_PERM = new RegionGroupFlag("spawn-groups");
|
||||
public static final BooleanFlag BUYABLE = new BooleanFlag("buyable");
|
||||
public static final DoubleFlag PRICE = new DoubleFlag("price");
|
||||
|
@ -1,61 +0,0 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.sk89q.worldguard.protection.flags;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class LocationFlag extends Flag<Location> {
|
||||
|
||||
public LocationFlag(String name, char legacyCode) {
|
||||
super(name, legacyCode);
|
||||
}
|
||||
|
||||
public LocationFlag(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location parseInput(WorldGuardPlugin plugin, CommandSender sender,
|
||||
String input) throws InvalidFlagFormat {
|
||||
input = input.trim();
|
||||
|
||||
try {
|
||||
return plugin.checkPlayer(sender).getLocation();
|
||||
} catch (CommandException e) {
|
||||
throw new InvalidFlagFormat(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location unmarshal(Object o) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object marshal(Location o) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -18,6 +18,9 @@
|
||||
*/
|
||||
package com.sk89q.worldguard.protection.flags;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
@ -26,7 +29,7 @@
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class RegionGroupFlag extends Flag<String> {
|
||||
public class RegionGroupFlag extends Flag<Set<String>> {
|
||||
|
||||
public RegionGroupFlag(String name, char legacyCode) {
|
||||
super(name, legacyCode);
|
||||
@ -37,18 +40,35 @@ public RegionGroupFlag(String name) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parseInput(WorldGuardPlugin plugin, CommandSender sender,
|
||||
public Set<String> parseInput(WorldGuardPlugin plugin, CommandSender sender,
|
||||
String input) throws InvalidFlagFormat {
|
||||
return "";
|
||||
Set<String> list = new HashSet<String>();
|
||||
|
||||
for (String i : input.split(",")) {
|
||||
list.add(i.toLowerCase());
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String unmarshal(Object o) {
|
||||
public Set<String> unmarshal(Object o) {
|
||||
if (o instanceof List) {
|
||||
List<?> raw = (List<?>) o;
|
||||
Set<String> list = new HashSet<String>();
|
||||
|
||||
for (Object i : raw) {
|
||||
list.add(i.toString().toLowerCase());
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object marshal(String o) {
|
||||
public Object marshal(Set<String> o) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
96
src/com/sk89q/worldguard/protection/flags/VectorFlag.java
Normal file
96
src/com/sk89q/worldguard/protection/flags/VectorFlag.java
Normal file
@ -0,0 +1,96 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.sk89q.worldguard.protection.flags;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldguard.bukkit.BukkitUtil;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class VectorFlag extends Flag<Vector> {
|
||||
|
||||
public VectorFlag(String name, char legacyCode) {
|
||||
super(name, legacyCode);
|
||||
}
|
||||
|
||||
public VectorFlag(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector parseInput(WorldGuardPlugin plugin, CommandSender sender,
|
||||
String input) throws InvalidFlagFormat {
|
||||
input = input.trim();
|
||||
|
||||
try {
|
||||
return BukkitUtil.toVector(plugin.checkPlayer(sender).getLocation());
|
||||
} catch (CommandException e) {
|
||||
throw new InvalidFlagFormat(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector unmarshal(Object o) {
|
||||
if (o instanceof Map) {
|
||||
Map<?, ?> map = (Map<?, ?>) o;
|
||||
|
||||
Object rawX = map.get("x");
|
||||
Object rawY = map.get("y");
|
||||
Object rawZ = map.get("z");
|
||||
|
||||
if (rawX == null || rawY == null || rawZ == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Vector(toNumber(rawX), toNumber(rawY), toNumber(rawZ));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object marshal(Vector o) {
|
||||
Map<String, Object> vec = new HashMap<String, Object>();
|
||||
vec.put("x", o.getX());
|
||||
vec.put("y", o.getY());
|
||||
vec.put("z", o.getZ());
|
||||
return vec;
|
||||
}
|
||||
|
||||
private double toNumber(Object o) {
|
||||
if (o instanceof Integer) {
|
||||
return (Integer) o;
|
||||
} else if (o instanceof Long) {
|
||||
return (Long) o;
|
||||
} else if (o instanceof Float) {
|
||||
return (Float) o;
|
||||
} else if (o instanceof Double) {
|
||||
return (Double) o;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user