2011-01-08 11:04:21 +01:00
|
|
|
// $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;
|
|
|
|
|
2011-02-24 11:19:35 +01:00
|
|
|
import com.sk89q.worldguard.protection.dbs.CSVDatabase;
|
|
|
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
|
|
|
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
2011-01-08 11:04:21 +01:00
|
|
|
import java.io.*;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import org.junit.After;
|
|
|
|
import org.junit.Before;
|
|
|
|
import org.junit.Test;
|
|
|
|
import static org.junit.Assert.*;
|
|
|
|
import com.sk89q.worldedit.BlockVector;
|
|
|
|
import com.sk89q.worldguard.domains.DefaultDomain;
|
2011-02-24 11:19:35 +01:00
|
|
|
import com.sk89q.worldguard.protection.regions.AreaFlags;
|
|
|
|
import com.sk89q.worldguard.protection.regions.AreaFlags.State;
|
2011-01-08 11:04:21 +01:00
|
|
|
|
|
|
|
public class CSVDatabaseTest {
|
|
|
|
@Before
|
|
|
|
public void setUp() throws Exception {
|
|
|
|
}
|
|
|
|
|
|
|
|
@After
|
|
|
|
public void tearDown() throws Exception {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testLoadSave() throws Exception {
|
|
|
|
File temp = File.createTempFile("worldguard_csv_test", ".tmp");
|
|
|
|
temp.deleteOnExit();
|
|
|
|
|
|
|
|
Map<String,ProtectedRegion> regions =
|
|
|
|
new HashMap<String,ProtectedRegion>();
|
|
|
|
regions.put("test1", getTestRegion1());
|
|
|
|
regions.put("test2", getTestRegion2());
|
|
|
|
|
|
|
|
CSVDatabase writeDB = new CSVDatabase(temp);
|
|
|
|
writeDB.setRegions(regions);
|
|
|
|
writeDB.save();
|
|
|
|
|
|
|
|
CSVDatabase readDB = new CSVDatabase(temp);
|
|
|
|
readDB.load();
|
|
|
|
|
|
|
|
Map<String,ProtectedRegion> loaded = readDB.getRegions();
|
|
|
|
|
|
|
|
ProtectedRegion region1 = loaded.get("test1");
|
|
|
|
checkTestRegion1(region1);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void checkTestRegion1(ProtectedRegion region) {
|
|
|
|
AreaFlags flags = new AreaFlags();
|
2011-02-25 20:58:48 +01:00
|
|
|
flags.setFlag(AreaFlags.FLAG_FIRE_SPREAD, State.ALLOW);
|
|
|
|
flags.setFlag(AreaFlags.FLAG_PVP, State.DENY);
|
|
|
|
flags.setFlag(AreaFlags.FLAG_LIGHTER, State.DENY);
|
2011-01-08 11:04:21 +01:00
|
|
|
region.setFlags(flags);
|
|
|
|
|
|
|
|
assertEquals(region.getFlags(), flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
private ProtectedRegion getTestRegion1() {
|
|
|
|
BlockVector min = new BlockVector(1, 2, 3);
|
|
|
|
BlockVector max = new BlockVector(4, 5, 6);
|
|
|
|
|
2011-01-22 00:23:11 +01:00
|
|
|
ProtectedRegion region = new ProtectedCuboidRegion("test2", min, max);
|
2011-01-08 11:04:21 +01:00
|
|
|
|
|
|
|
AreaFlags flags = new AreaFlags();
|
2011-02-25 20:58:48 +01:00
|
|
|
flags.setFlag(AreaFlags.FLAG_FIRE_SPREAD, State.ALLOW);
|
|
|
|
flags.setFlag(AreaFlags.FLAG_PVP, State.DENY);
|
|
|
|
flags.setFlag(AreaFlags.FLAG_LIGHTER, State.DENY);
|
2011-01-08 11:04:21 +01:00
|
|
|
region.setFlags(flags);
|
|
|
|
|
|
|
|
DefaultDomain domain = new DefaultDomain();
|
|
|
|
domain.addGroup("members");
|
|
|
|
domain.addGroup("sturmehs");
|
|
|
|
domain.addPlayer("hollie");
|
|
|
|
domain.addPlayer("chad");
|
|
|
|
domain.addPlayer("tetsu");
|
|
|
|
region.setOwners(domain);
|
|
|
|
|
|
|
|
region.setPriority(444);
|
|
|
|
|
|
|
|
return region;
|
|
|
|
}
|
|
|
|
|
|
|
|
private ProtectedRegion getTestRegion2() {
|
|
|
|
BlockVector min = new BlockVector(7, 8, 9);
|
|
|
|
BlockVector max = new BlockVector(10, 11, 12);
|
|
|
|
|
2011-01-22 00:23:11 +01:00
|
|
|
ProtectedRegion region = new ProtectedCuboidRegion("test2", min, max);
|
2011-01-08 11:04:21 +01:00
|
|
|
|
|
|
|
AreaFlags flags = new AreaFlags();
|
2011-02-25 20:58:48 +01:00
|
|
|
flags.setFlag(AreaFlags.FLAG_FIRE_SPREAD, State.ALLOW);
|
|
|
|
flags.setFlag(AreaFlags.FLAG_PVP, State.ALLOW);
|
|
|
|
flags.setFlag(AreaFlags.FLAG_LIGHTER, State.DENY);
|
2011-01-08 11:04:21 +01:00
|
|
|
region.setFlags(flags);
|
|
|
|
|
|
|
|
DefaultDomain domain = new DefaultDomain();
|
|
|
|
domain.addGroup("admins");
|
|
|
|
domain.addPlayer("jon");
|
|
|
|
domain.addPlayer("ester");
|
|
|
|
domain.addPlayer("amy");
|
|
|
|
region.setOwners(domain);
|
2011-02-24 21:10:54 +01:00
|
|
|
|
2011-01-08 11:04:21 +01:00
|
|
|
region.setPriority(555);
|
|
|
|
|
|
|
|
return region;
|
|
|
|
}
|
|
|
|
}
|