- Přepsání regionů na používání PermissionGroupregion-rework
parent
64850aaf45
commit
87e7962028
22 changed files with 465 additions and 194 deletions
@ -1,89 +0,0 @@ |
||||
package xyz.soukup.ecoCraftCore.database; |
||||
|
||||
import com.j256.ormlite.dao.Dao; |
||||
import xyz.soukup.ecoCraftCore.database.objects.*; |
||||
import xyz.soukup.ecoCraftCore.database.objects.VirtualChest; |
||||
|
||||
public class DaoRegistry { |
||||
private static Dao<Shop, Integer> shopDao; |
||||
private static Dao<Transaction, Integer> transactionDao; |
||||
private static Dao<VirtualChest, Integer> virtualChestDao; |
||||
private static Dao<Account, Integer> accountDao; |
||||
private static Dao<Island, Integer> islandDao; |
||||
private static Dao<TeleportRequest, Integer> teleportRequestsDao; |
||||
private static Dao<ActiveServer, Integer> activeServerDao; |
||||
private static Dao<Region, Integer> regionDao; |
||||
private static Dao<RegionMember, Integer> regionMemberDao; |
||||
|
||||
public static Dao<RegionMember, Integer> getRegionMemberDao() { |
||||
return regionMemberDao; |
||||
} |
||||
|
||||
public static void setRegionMemberDao(Dao<RegionMember, Integer> regionMemberDao) { |
||||
DaoRegistry.regionMemberDao = regionMemberDao; |
||||
} |
||||
|
||||
public static Dao<Region, Integer> getRegionDao() { |
||||
return regionDao; |
||||
} |
||||
|
||||
public static void setRegionDao(Dao<Region, Integer> regionDao) { |
||||
DaoRegistry.regionDao = regionDao; |
||||
} |
||||
|
||||
public static Dao<TeleportRequest, Integer> getTeleportRequestsDao() { |
||||
return teleportRequestsDao; |
||||
} |
||||
|
||||
public static void setTeleportRequestsDao(Dao<TeleportRequest, Integer> teleportRequestsDao) { |
||||
DaoRegistry.teleportRequestsDao = teleportRequestsDao; |
||||
} |
||||
|
||||
public static Dao<ActiveServer, Integer> getActiveServerDao() { |
||||
return activeServerDao; |
||||
} |
||||
|
||||
public static void setActiveServerDao(Dao<ActiveServer, Integer> activeServerDao) { |
||||
DaoRegistry.activeServerDao = activeServerDao; |
||||
} |
||||
|
||||
public static Dao<Shop, Integer> getShopDao() { |
||||
return shopDao; |
||||
} |
||||
|
||||
public static void setShopDao(Dao<Shop, Integer> shopDao) { |
||||
DaoRegistry.shopDao = shopDao; |
||||
} |
||||
|
||||
public static Dao<Transaction, Integer> getTransactionDao() { |
||||
return transactionDao; |
||||
} |
||||
|
||||
public static void setTransactionDao(Dao<Transaction, Integer> transactionDao) { |
||||
DaoRegistry.transactionDao = transactionDao; |
||||
} |
||||
|
||||
public static Dao<VirtualChest, Integer> getVirtualChestDao() { |
||||
return virtualChestDao; |
||||
} |
||||
|
||||
public static void setVirtualChestDao(Dao<VirtualChest, Integer> virtualChestDao) { |
||||
DaoRegistry.virtualChestDao = virtualChestDao; |
||||
} |
||||
|
||||
public static Dao<Account, Integer> getAccountDao() { |
||||
return accountDao; |
||||
} |
||||
|
||||
public static void setAccountDao(Dao<Account, Integer> accountDao) { |
||||
DaoRegistry.accountDao = accountDao; |
||||
} |
||||
|
||||
public static Dao<Island, Integer> getIslandDao() { |
||||
return islandDao; |
||||
} |
||||
|
||||
public static void setIslandDaoo(Dao<Island, Integer> islandDao) { |
||||
DaoRegistry.islandDao = islandDao; |
||||
} |
||||
} |
||||
@ -0,0 +1,34 @@ |
||||
package xyz.soukup.ecoCraftCore.database.objects; |
||||
|
||||
public enum Permission { |
||||
PLACE(1), |
||||
BREAK(2), |
||||
REDSTONE_INTERACT(3), |
||||
ENTITY_INTERACT(4), |
||||
VEHICLE_INTERACT(5), |
||||
ENTER(6), |
||||
EXIT(7), |
||||
MANAGE_MEMBERS(8), |
||||
MANAGE_GROUPS(9), |
||||
MANAGE_REGIONS(10), |
||||
TRANSFER_OWNERSHIP(11), |
||||
USE_HOPPER(12), |
||||
HARVEST(13), |
||||
PLANT(14), |
||||
PICKUP_ITEMS(15), |
||||
DROP_ITEMS(16), |
||||
PLOUGH(17), |
||||
SIT(18), |
||||
SHOP_INTERACT(19), |
||||
HARM_ENTITIES(20), |
||||
HARM_PLAYERS(21); |
||||
|
||||
private final int bit; |
||||
Permission(int bit) { |
||||
this.bit = bit; |
||||
} |
||||
|
||||
public int getBit() { |
||||
return bit; |
||||
} |
||||
} |
||||
@ -0,0 +1,158 @@ |
||||
package xyz.soukup.ecoCraftCore.database.objects; |
||||
|
||||
import com.j256.ormlite.dao.Dao; |
||||
import com.j256.ormlite.field.DatabaseField; |
||||
import com.j256.ormlite.table.DatabaseTable; |
||||
import org.bukkit.Material; |
||||
|
||||
import java.security.Permissions; |
||||
import java.sql.SQLException; |
||||
|
||||
@DatabaseTable(tableName = "permission_groups") |
||||
public class PermissionGroup { |
||||
|
||||
public static Dao<PermissionGroup, Integer> dao; |
||||
|
||||
public static void setDao(Dao<PermissionGroup, Integer> dao) { |
||||
PermissionGroup.dao = dao; |
||||
} |
||||
|
||||
public static Dao<PermissionGroup, Integer> getDao() { |
||||
return dao; |
||||
} |
||||
|
||||
@DatabaseField(generatedId = true) |
||||
private int id; |
||||
|
||||
@DatabaseField(foreign = true, foreignAutoRefresh = true, uniqueCombo = true) |
||||
private Region region; |
||||
|
||||
@DatabaseField(canBeNull = false, uniqueCombo = true) |
||||
private String name; |
||||
|
||||
@DatabaseField(canBeNull = false, columnName = "display_name") |
||||
private String displayName; |
||||
|
||||
@DatabaseField() |
||||
private String description; |
||||
|
||||
@DatabaseField(canBeNull = false) |
||||
private Material icon; |
||||
|
||||
@DatabaseField(canBeNull = false, defaultValue = "0") |
||||
private int weight; |
||||
|
||||
@DatabaseField(canBeNull = false, defaultValue = "true") |
||||
private Boolean editable; |
||||
|
||||
@DatabaseField(canBeNull = false, defaultValue = "true") |
||||
private Boolean deletable; |
||||
|
||||
@DatabaseField(canBeNull = false, defaultValue = "0", columnName = "permissions_number") |
||||
private int permissionsNumber; |
||||
|
||||
public PermissionGroup(){ |
||||
|
||||
} |
||||
|
||||
public PermissionGroup(Region region, String name, String displayName, String description, Material icon){ |
||||
this.region = region; |
||||
this.name = name; |
||||
this.displayName = displayName; |
||||
this.description = description; |
||||
this.icon = icon; |
||||
this.editable = true; |
||||
this.deletable = true; |
||||
this.permissionsNumber = 0; |
||||
this.weight = 0; |
||||
} |
||||
|
||||
public PermissionGroup(Region region, String name, String displayName, String description, Material icon, Boolean editable, Boolean deletable, int weight,int permissions){ |
||||
this.region = region; |
||||
this.name = name; |
||||
this.displayName = displayName; |
||||
this.description = description; |
||||
this.icon = icon; |
||||
this.editable = editable; |
||||
this.deletable = deletable; |
||||
this.permissionsNumber = permissions; |
||||
this.weight = weight; |
||||
} |
||||
|
||||
public PermissionGroup(Region region, String name, String displayName, String description, Material icon, Boolean editable, Boolean deletable, int weight, Permission... permissions) { |
||||
this.region = region; |
||||
this.name = name; |
||||
this.displayName = displayName; |
||||
this.description = description; |
||||
this.icon = icon; |
||||
this.editable = editable; |
||||
this.deletable = deletable; |
||||
this.permissionsNumber = 0; |
||||
this.weight = 0; |
||||
for (Permission permission : permissions) { |
||||
this.permissionsNumber |= permission.getBit(); |
||||
} |
||||
} |
||||
|
||||
public boolean hasPermission(Permission permission) { |
||||
return (this.permissionsNumber & permission.getBit()) != 0; |
||||
} |
||||
|
||||
public void addPermission(Permission... permissions) { |
||||
for (Permission permission : permissions){ |
||||
this.permissionsNumber |= permission.getBit(); |
||||
} |
||||
} |
||||
|
||||
public void removePermission(Permission permission) { |
||||
this.permissionsNumber &= ~permission.getBit(); |
||||
} |
||||
|
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
public void setName(String name) { |
||||
this.name = name; |
||||
} |
||||
|
||||
public String getDisplayName() { |
||||
return displayName; |
||||
} |
||||
|
||||
public void setDisplayName(String displayName) { |
||||
this.displayName = displayName; |
||||
} |
||||
|
||||
public Material getIcon() { |
||||
return icon; |
||||
} |
||||
|
||||
public void setIcon(Material icon) { |
||||
this.icon = icon; |
||||
} |
||||
|
||||
public int getWeight() { |
||||
return weight; |
||||
} |
||||
|
||||
public void setWeight(int weight) { |
||||
this.weight = weight; |
||||
} |
||||
|
||||
public void save(){ |
||||
try { |
||||
getDao().createOrUpdate(this); |
||||
} catch (SQLException e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
} |
||||
|
||||
public static PermissionGroup getPermissionGroup(Region region, String name){ |
||||
try { |
||||
return getDao().queryBuilder().where().eq("region", region).and().eq("name", name).queryForFirst(); |
||||
} catch (SQLException e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue