Signed-off-by: Chaoscaot <chaoscaot@zohomail.eu>
Dieser Commit ist enthalten in:
Ursprung
23fba7074d
Commit
b59a4a637e
@ -0,0 +1,130 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.features.script.lua.libs;
|
||||||
|
|
||||||
|
import de.steamwar.linkage.Linked;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.boss.BarColor;
|
||||||
|
import org.bukkit.boss.BarFlag;
|
||||||
|
import org.bukkit.boss.BarStyle;
|
||||||
|
import org.bukkit.boss.BossBar;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.luaj.vm2.LuaError;
|
||||||
|
import org.luaj.vm2.LuaTable;
|
||||||
|
import org.luaj.vm2.LuaValue;
|
||||||
|
import org.luaj.vm2.lib.OneArgFunction;
|
||||||
|
import org.luaj.vm2.lib.ThreeArgFunction;
|
||||||
|
import org.luaj.vm2.lib.ZeroArgFunction;
|
||||||
|
|
||||||
|
@Linked
|
||||||
|
public class BossbarLib implements LuaLib {
|
||||||
|
@Override
|
||||||
|
public String name() {
|
||||||
|
return "bossbar";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LuaTable get(Player player) {
|
||||||
|
LuaTable table = new LuaTable();
|
||||||
|
|
||||||
|
table.set("create", new ThreeArgFunction() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LuaValue call(LuaValue arg1, LuaValue arg2, LuaValue arg3) {
|
||||||
|
String title = arg1.checkjstring();
|
||||||
|
BarStyle style;
|
||||||
|
BarColor color;
|
||||||
|
try {
|
||||||
|
color = BarColor.valueOf(arg2.checkjstring());
|
||||||
|
style = BarStyle.valueOf(arg3.checkjstring());
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
throw new LuaError("Invalid color or style");
|
||||||
|
}
|
||||||
|
BossBar bossBar = Bukkit.createBossBar(title, color, style);
|
||||||
|
bossBar.addPlayer(player);
|
||||||
|
|
||||||
|
LuaTable bbTable = new LuaTable();
|
||||||
|
|
||||||
|
bbTable.set("title", getterAndSetter("title", bossBar::getTitle, bossBar::setTitle));
|
||||||
|
bbTable.set("style", getterAndSetter("style", () -> bossBar.getStyle().name(), s -> {
|
||||||
|
try {
|
||||||
|
bossBar.setStyle(BarStyle.valueOf(s));
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
throw new LuaError("Invalid style");
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
bbTable.set("color", getterAndSetter("color", () -> bossBar.getColor().name(), s -> {
|
||||||
|
try {
|
||||||
|
bossBar.setColor(BarColor.valueOf(s));
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
throw new LuaError("Invalid color");
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
bbTable.set("progress", getterAndSetter("progress", bossBar::getProgress, bossBar::setProgress));
|
||||||
|
bbTable.set("visible", getterAndSetter("visible", bossBar::isVisible, bossBar::setVisible));
|
||||||
|
bbTable.set("hasFlag", new OneArgFunction() {
|
||||||
|
@Override
|
||||||
|
public LuaValue call(LuaValue arg) {
|
||||||
|
try {
|
||||||
|
return LuaValue.valueOf(bossBar.hasFlag(BarFlag.valueOf(arg.checkjstring())));
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
throw new LuaError("Invalid flag");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
bbTable.set("addFlag", new OneArgFunction() {
|
||||||
|
@Override
|
||||||
|
public LuaValue call(LuaValue arg) {
|
||||||
|
try {
|
||||||
|
bossBar.addFlag(BarFlag.valueOf(arg.checkjstring()));
|
||||||
|
return LuaValue.TRUE;
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
throw new LuaError("Invalid flag");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
bbTable.set("removeFlag", new OneArgFunction() {
|
||||||
|
@Override
|
||||||
|
public LuaValue call(LuaValue arg) {
|
||||||
|
try {
|
||||||
|
bossBar.removeFlag(BarFlag.valueOf(arg.checkjstring()));
|
||||||
|
return LuaValue.TRUE;
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
throw new LuaError("Invalid flag");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
bbTable.set("destroy", new ZeroArgFunction() {
|
||||||
|
@Override
|
||||||
|
public LuaValue call() {
|
||||||
|
bossBar.removeAll();
|
||||||
|
return LuaValue.NIL;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return table;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -23,6 +23,7 @@ import de.steamwar.bausystem.features.loader.Loader;
|
|||||||
import de.steamwar.bausystem.features.tracer.record.ActiveTracer;
|
import de.steamwar.bausystem.features.tracer.record.ActiveTracer;
|
||||||
import de.steamwar.bausystem.features.tracer.record.AutoTraceRecorder;
|
import de.steamwar.bausystem.features.tracer.record.AutoTraceRecorder;
|
||||||
import de.steamwar.bausystem.features.tracer.record.Recorder;
|
import de.steamwar.bausystem.features.tracer.record.Recorder;
|
||||||
|
import de.steamwar.bausystem.region.GlobalRegion;
|
||||||
import de.steamwar.bausystem.region.Region;
|
import de.steamwar.bausystem.region.Region;
|
||||||
import de.steamwar.bausystem.region.flags.Flag;
|
import de.steamwar.bausystem.region.flags.Flag;
|
||||||
import de.steamwar.bausystem.region.flags.flagvalues.FireMode;
|
import de.steamwar.bausystem.region.flags.flagvalues.FireMode;
|
||||||
@ -49,7 +50,14 @@ public class RegionLib implements LuaLib {
|
|||||||
LuaTable table = LuaValue.tableOf();
|
LuaTable table = LuaValue.tableOf();
|
||||||
|
|
||||||
table.set("name", getter(() -> region.get().getName()));
|
table.set("name", getter(() -> region.get().getName()));
|
||||||
table.set("type", getter(() -> region.get().getPrototype().getName()));
|
table.set("type", getter(() -> {
|
||||||
|
Region region1 = region.get();
|
||||||
|
if (region1 instanceof GlobalRegion) {
|
||||||
|
return "global";
|
||||||
|
} else {
|
||||||
|
return region1.getPrototype().getName();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
LuaValue tntLib = LuaValue.tableOf();
|
LuaValue tntLib = LuaValue.tableOf();
|
||||||
tntLib.set("mode", getter(() -> region.get().getPlain(Flag.TNT, TNTMode.class).name()));
|
tntLib.set("mode", getter(() -> region.get().getPlain(Flag.TNT, TNTMode.class).name()));
|
||||||
@ -87,7 +95,7 @@ public class RegionLib implements LuaLib {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
table.set("list", getter(() -> LuaValue.listOf(Region.getREGION_MAP().values().stream().map(region -> create(() -> region, player)).toArray(LuaValue[]::new))));
|
table.set("list", getter(() -> LuaValue.listOf(Region.getREGION_MAP().values().stream().map(region -> create(() -> region, player)).toArray(LuaTable[]::new))));
|
||||||
|
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
51
sw.def.lua
51
sw.def.lua
@ -344,3 +344,54 @@ function command(command, handler) end
|
|||||||
---@param handler fun(pressed: boolean): void
|
---@param handler fun(pressed: boolean): void
|
||||||
---@return void
|
---@return void
|
||||||
function hotkey(trigger, handler) end
|
function hotkey(trigger, handler) end
|
||||||
|
|
||||||
|
---@class bossbar
|
||||||
|
bossbar = {}
|
||||||
|
|
||||||
|
---@alias BossBarColor 'PINK' | 'BLUE' | 'RED' | 'GREEN' | 'YELLOW' | 'PURPLE' | 'WHITE'
|
||||||
|
---@alias BossBarStyle 'SEGMENTED_6' | 'SEGMENTED_10' | 'SEGMENTED_12' | 'SEGMENTED_20' | 'SOLID'
|
||||||
|
---@alias BossBarFlag 'DARKEN_SKY' | 'PLAY_BOSS_MUSIC' | 'CREATE_FOG'
|
||||||
|
|
||||||
|
---@class BossBar
|
||||||
|
local BossBar = {}
|
||||||
|
|
||||||
|
---@param title string
|
||||||
|
---@param color BossBarColor
|
||||||
|
---@param style BossBarStyle
|
||||||
|
---@return BossBar
|
||||||
|
function bossbar.create(title, color, style) return nil end
|
||||||
|
|
||||||
|
---@return string
|
||||||
|
---@overload fun(title: string): void
|
||||||
|
function BossBar.title() end
|
||||||
|
|
||||||
|
---@return BossBarColor
|
||||||
|
---@overload fun(color: BossBarColor): void
|
||||||
|
function BossBar.color() end
|
||||||
|
|
||||||
|
---@return BossBarStyle
|
||||||
|
---@overload fun(style: BossBarStyle): void
|
||||||
|
function BossBar.style() end
|
||||||
|
|
||||||
|
---@return number
|
||||||
|
---@overload fun(progress: number): void
|
||||||
|
function BossBar.progress() end
|
||||||
|
|
||||||
|
---@return boolean
|
||||||
|
---@overload fun(visible: boolean): void
|
||||||
|
function BossBar.visible() end
|
||||||
|
|
||||||
|
---@return boolean
|
||||||
|
---@param flag BossBarFlag
|
||||||
|
function BossBar.hasFlag(flag) return nil end
|
||||||
|
|
||||||
|
---@return void
|
||||||
|
---@param flag BossBarFlag
|
||||||
|
function BossBar.addFlag(flag) end
|
||||||
|
|
||||||
|
---@return boolean
|
||||||
|
---@param flag BossBarFlag
|
||||||
|
function BossBar.removeFlag(flag) return nil end
|
||||||
|
|
||||||
|
---@return void
|
||||||
|
function BossBar.destroy() end
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren